Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 77.1% 54 / 0 / 70
Functions: 100.0% 5 / 0 / 5
Branches: 25.8% 47 / 0 / 182

OMCompiler/SimulationRuntime/cpp/SimCoreFactory/Policies/SolverOMCFactory.h
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 #pragma once
29 /** @addtogroup simcorefactoriesPolicies
30 *
31 * @{
32 */
33
34 #include <SimCoreFactory/ObjectFactory.h>
35 #include <Core/Solver/ISolver.h>
36 #include <Core/SimulationSettings//ISettingsFactory.h>
37
38 #include <filesystem>
39
40 namespace fs = std::filesystem;
41
42 /*
43 Policy class to create solver object
44 */
45 template <class CreationPolicy>
46 struct SolverOMCFactory : public ObjectFactory<CreationPolicy>
47 {
48
49 public:
50 40 SolverOMCFactory(PATH library_path,PATH modelicasystem_path,PATH config_path)
51
3/9
✓ Branch 2 taken 40 times.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 40 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
160 :ObjectFactory<CreationPolicy>(library_path,modelicasystem_path,config_path)
52 {
53
1/1
✓ Branch 1 taken 40 times.
40 _solver_type_map = new type_map();
54
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
40 _settings_type_map = new type_map();
55 #ifndef RUNTIME_STATIC_LINKING
56
3/9
✓ Branch 1 taken 40 times.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
120 initializeLibraries(library_path,modelicasystem_path,config_path);
57 #endif
58 40 }
59
60 40 virtual ~SolverOMCFactory()
61 {
62 40 delete _solver_type_map;
63
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
80 delete _settings_type_map;
64 40 ObjectFactory<CreationPolicy>::_factory->UnloadAllLibs();
65
66 80 }
67
68 40 virtual shared_ptr<ISettingsFactory> createSettingsFactory()
69 {
70 std::map<std::string, factory<ISettingsFactory,PATH,PATH,PATH> >::iterator iter;
71 40 std::map<std::string, factory<ISettingsFactory,PATH,PATH,PATH> >& factories(_settings_type_map->get());
72
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
80 iter = factories.find("SettingsFactory");
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (iter ==factories.end())
74 {
75 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No such settings library");
76 }
77
3/9
✓ Branch 2 taken 40 times.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 40 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
160 shared_ptr<ISettingsFactory> settings_factory = shared_ptr<ISettingsFactory>(iter->second.create(ObjectFactory<CreationPolicy>::_library_path,ObjectFactory<CreationPolicy>::_modelicasystem_path,ObjectFactory<CreationPolicy>::_config_path));
78
79 40 return settings_factory;
80 }
81
82 40 virtual shared_ptr<ISolver> createSolver(IMixedSystem* system, string solvername, shared_ptr<ISolverSettings> solver_settings)
83 {
84
2/2
✓ Branch 1 taken 39 times.
✓ Branch 2 taken 1 time.
40 if (solvername.compare("dassl") == 0)
85 {
86 39 fs::path dassl_path = ObjectFactory<CreationPolicy>::_library_path;
87
1/1
✓ Branch 1 taken 39 times.
39 fs::path dassl_name(DASSL_LIB);
88
1/1
✓ Branch 1 taken 39 times.
39 dassl_path /= dassl_name;
89
2/2
✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
78 LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(dassl_path.string(), *_solver_type_map);
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
39 if (result != LOADER_SUCCESS)
91 {
92 ✗ throw ModelicaSimulationError(MODEL_FACTORY, "Failed loading DASSL solver library!");
93 }
94 39 }
95
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 else if(solvername.compare("idas")==0)
96 {
97
98 }
99
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 else if(solvername.compare("ida")==0)
100 {
101 solvername = "ida"; //workound for dassl, using cvode instead
102 1 fs::path ida_path = ObjectFactory<CreationPolicy>::_library_path;
103
1/1
✓ Branch 1 taken 1 time.
1 fs::path ida_name(IDA_LIB);
104
1/1
✓ Branch 1 taken 1 time.
1 ida_path/=ida_name;
105
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(ida_path.string(),*_solver_type_map);
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if (result != LOADER_SUCCESS)
107 {
108 ✗ throw std::runtime_error("Failed loading IDA solver library!");
109 }
110 1 }
111 ✗ else if((solvername.compare("cvode")==0)||(solvername.compare("dassl")==0))
112 {
113 solvername = "cvode"; //workound for dassl, using cvode instead
114 ✗ fs::path cvode_path = ObjectFactory<CreationPolicy>::_library_path;
115 ✗ fs::path cvode_name(CVODE_LIB);
116 ✗ cvode_path/=cvode_name;
117 ✗ LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(cvode_path.string(),*_solver_type_map);
118 ✗ if (result != LOADER_SUCCESS)
119 {
120 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"Failed loading CVode solver library!");
121 }
122 ✗ }
123 else
124 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"Selected Solver is not available");
125
126 std::map<std::string, factory<ISolver,IMixedSystem*, ISolverSettings*> >::iterator iter;
127 40 std::map<std::string, factory<ISolver,IMixedSystem*, ISolverSettings*> >& factories(_solver_type_map->get());
128 40 string solver_key = solvername.append("Solver");
129 iter = factories.find(solver_key);
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (iter ==factories.end())
131 {
132 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No such Solver " + solver_key);
133 }
134
135 shared_ptr<ISolver> solver = shared_ptr<ISolver>(iter->second.create(system,solver_settings.get()));
136
137 40 return solver;
138 }
139 protected:
140 40 virtual void initializeLibraries(PATH library_path,PATH modelicasystem_path,PATH config_path)
141 {
142
143 LOADERRESULT result;
144
145 40 fs::path math_path = ObjectFactory<CreationPolicy>::_library_path;
146
1/1
✓ Branch 1 taken 40 times.
40 fs::path math_name(MATH_LIB);
147
1/1
✓ Branch 1 taken 40 times.
40 math_path/=math_name;
148
149
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
80 result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(math_path.string(),*_settings_type_map);
150
151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (result != LOADER_SUCCESS)
152 {
153
154 ✗ throw ModelicaSimulationError(MODEL_FACTORY,string("Failed loading Math library: ") + math_path.string());
155 }
156
157
158
159
1/1
✓ Branch 1 taken 40 times.
40 fs::path settingsfactory_path = ObjectFactory<CreationPolicy>::_library_path;
160
1/1
✓ Branch 1 taken 40 times.
40 fs::path settingsfactory_name(SETTINGSFACTORY_LIB);
161
1/1
✓ Branch 1 taken 40 times.
40 settingsfactory_path/=settingsfactory_name;
162
163
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
80 result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(settingsfactory_path.string(),*_settings_type_map);
164
165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (result != LOADER_SUCCESS)
166 {
167
168 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"Failed loading SimulationSettings library!");
169 }
170
171
1/1
✓ Branch 1 taken 40 times.
40 fs::path solver_path = ObjectFactory<CreationPolicy>::_library_path;
172
1/1
✓ Branch 1 taken 40 times.
40 fs::path solver_name(SOLVER_LIB);
173
1/1
✓ Branch 1 taken 40 times.
40 solver_path/=solver_name;
174
175
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
80 result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(solver_path.string(),*_solver_type_map);
176
177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (result != LOADER_SUCCESS)
178 {
179 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"Failed loading Solver default implementation library!");
180 }
181 40 }
182
183 type_map* _solver_type_map;
184 type_map* _settings_type_map;
185 };
186 /** @} */ // end of simcorefactoriesPolicies
187