Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 45.0% 27 / 0 / 60
Functions: 50.0% 7 / 0 / 14
Branches: 17.9% 17 / 0 / 95

OMCompiler/SimulationRuntime/cpp/Core/SimController/SimObjects.cpp
Line Branch Exec Source
1 /*
2 * This file belongs to the OpenModelica Run-Time System
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), c/o Linköpings
5 * universitet, Department of Computer and Information Science, SE-58183 Linköping, Sweden. All rights
6 * reserved.
7 *
8 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
9 * AGPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. ANY
10 * USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
11 * ACCEPTANCE OF THE BSD NEW LICENSE OR THE OSMC PUBLIC LICENSE OR THE AGPL
12 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
13 *
14 * The OpenModelica software and the OSMC (Open Source Modelica Consortium) Public License
15 * (OSMC-PL) are obtained from OSMC, either from the above address, from the URLs:
16 * http://www.openmodelica.org or https://github.com/OpenModelica/ or
17 * http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica distribution. GNU
18 * AGPL version 3 is obtained from: https://www.gnu.org/licenses/licenses.html#GPL. The BSD NEW
19 * License is obtained from: http://www.opensource.org/licenses/BSD-3-Clause.
20 *
21 * This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY
23 * SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF
24 * OSMC-PL.
25 *
26 */
27
28 /** @addtogroup coreSimcontroller
29 *
30 * @{
31 */
32 #include <Core/ModelicaDefine.h>
33 #include <Core/Modelica.h>
34 #include <Core/SimController/SimObjects.h>
35
36
37 40 SimObjects::SimObjects(PATH library_path, PATH modelicasystem_path,IGlobalSettings* globalSettings)
38 : SimObjectPolicy(library_path, modelicasystem_path, library_path)
39
4/10
✓ Branch 1 taken 40 times.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 40 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
160 ,_globalSettings(globalSettings)
40 {
41
1/1
✓ Branch 1 taken 40 times.
40 _algloopsolverfactory = createAlgLoopSolverFactory(globalSettings);
42 40 }
43
44 ✗ SimObjects::SimObjects(SimObjects& instance) : SimObjectPolicy(instance)
45 {
46 //clone sim_data
47 ✗ for(std::map<string, shared_ptr<ISimData> >::iterator it = instance._sim_data.begin(); it != instance._sim_data.end(); it++)
48 ✗ _sim_data.insert(pair<string, shared_ptr<ISimData> >(it->first, shared_ptr<ISimData>(it->second->clone())));
49
50 //clone sim_vars
51 ✗ for(std::map<string, shared_ptr<ISimVars> >::iterator it = instance._sim_vars.begin(); it != instance._sim_vars.end(); it++)
52 ✗ _sim_vars.insert(pair<string, shared_ptr<ISimVars> >(it->first, shared_ptr<ISimVars>(it->second->clone())));
53
54 ✗ _algloopsolverfactory = instance.getAlgLoopSolverFactory();
55 ✗ _globalSettings = instance.getGlobalSettings();
56 ✗ _write_output = instance.getWriter();
57 ✗ }
58
59
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
80 SimObjects::~SimObjects()
60 {
61
62 80 }
63
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 weak_ptr<ISimData> SimObjects::LoadSimData(string modelKey)
65 {
66 //if the simdata is already loaded
67 std::map<string,shared_ptr<ISimData> > ::iterator iter = _sim_data.find(modelKey);
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if(iter != _sim_data.end())
69 {
70 //destroy system
71 _sim_data.erase(iter);
72 }
73 //create system
74 40 shared_ptr<ISimData> sim_data = createSimData();
75
1/1
✓ Branch 1 taken 40 times.
40 _sim_data[modelKey] = sim_data;
76 40 return sim_data;
77 }
78
79
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 weak_ptr<ISimVars> SimObjects::LoadSimVars(string modelKey, size_t dim_real, size_t dim_int, size_t dim_bool, size_t dim_string, size_t dim_pre_vars, size_t dim_z, size_t z_i)
80 {
81 //if the simdata is already loaded
82 std::map<string,shared_ptr<ISimVars> > ::iterator iter = _sim_vars.find(modelKey);
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if(iter != _sim_vars.end())
84 {
85 //destroy system
86 _sim_vars.erase(iter);
87 }
88 //create system
89 40 shared_ptr<ISimVars> sim_vars = createSimVars(dim_real, dim_int, dim_bool, dim_string, dim_pre_vars, dim_z,z_i);
90
1/1
✓ Branch 1 taken 40 times.
40 _sim_vars[modelKey] = sim_vars;
91 40 return sim_vars;
92 }
93
94 ✗ shared_ptr<ISimData> SimObjects::getSimData(string modelname)
95 {
96 std::map<string,shared_ptr<ISimData> >::iterator iter = _sim_data.find(modelname);
97 ✗ if(iter != _sim_data.end())
98 {
99 ✗ return iter->second;
100 }
101 else
102 {
103 ✗ string error = string("Simulation data not found for model ") + modelname;
104 ✗ throw ModelicaSimulationError(SIMMANAGER, error);
105 }
106 }
107
108
1/2
✓ Branch 0 taken 336644 times.
✗ Branch 1 not taken.
336644 shared_ptr<ISimVars> SimObjects::getSimVars(string modelname)
109 {
110 std::map<string,shared_ptr<ISimVars> >::iterator iter = _sim_vars.find(modelname);
111
1/2
✓ Branch 0 taken 336644 times.
✗ Branch 1 not taken.
336644 if(iter != _sim_vars.end())
112 {
113 336644 return iter->second;
114 }
115 else
116 {
117 ✗ string error = string("Simulation vars not found for model ") + modelname;
118 ✗ throw ModelicaSimulationError(SIMMANAGER, error);
119 }
120 }
121
122 ✗ void SimObjects::eraseSimData(string modelname)
123 {
124 // destroy simdata
125 std::map<string,shared_ptr<ISimData> >::iterator iter = _sim_data.find(modelname);
126 ✗ if(iter != _sim_data.end())
127 {
128 _sim_data.erase(iter);
129 }
130 ✗ }
131
132 ✗ void SimObjects::eraseSimVars(string modelname)
133 {
134
135 // destroy simdata
136 std::map<string,shared_ptr<ISimVars> >::iterator iter = _sim_vars.find(modelname);
137 ✗ if(iter != _sim_vars.end())
138 {
139 _sim_vars.erase(iter);
140 }
141
142 ✗ }
143
144 40 shared_ptr<IAlgLoopSolverFactory> SimObjects::getAlgLoopSolverFactory()
145 {
146 40 return _algloopsolverfactory;
147 }
148
149 40 weak_ptr<IHistory> SimObjects::LoadWriter(size_t dim)
150 {
151
152
2/2
✓ Branch 1 taken 38 times.
✓ Branch 2 taken 2 times.
40 if( _globalSettings->getOutputFormat() == MAT)
153 {
154 76 _write_output = createMatFileWriter(_globalSettings,dim);
155 }
156
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 else if( _globalSettings->getOutputFormat() == CSV)
157 {
158 4 _write_output = createTextFileWriter(_globalSettings,dim);
159 }
160 ✗ else if( _globalSettings->getOutputFormat() == BUFFER)
161 {
162 ✗ _write_output = createBufferReaderWriter(_globalSettings,dim);
163 }
164 ✗ else if( _globalSettings->getOutputFormat() == EMPTY)
165 {
166 ✗ _write_output = createDefaultWriter(_globalSettings,dim);
167 }
168 else
169 {
170 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"output format is not supported");
171 }
172 40 return _write_output;
173 }
174
175 ✗ ISimObjects* SimObjects::clone()
176 {
177 ✗ return new SimObjects(*this);
178 }
179
180 ✗ IGlobalSettings* SimObjects::getGlobalSettings()
181 {
182 ✗ return _globalSettings;
183 }
184
185 ✗ shared_ptr<IHistory> SimObjects::getWriter()
186 {
187 ✗ return _write_output;
188 }
189 /** @} */ // end of coreSimcontroller
190