Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 66.7% 26 / 0 / 39
Functions: 100.0% 4 / 0 / 4
Branches: 13.5% 12 / 0 / 89

OMCompiler/SimulationRuntime/cpp/SimCoreFactory/Policies/LinSolverOMCFactory.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 #include <SimCoreFactory/ObjectFactory.h>
34
35 /*
36 Policy class to create lin solver object
37 */
38 template<class CreationPolicy>
39 struct LinSolverOMCFactory : virtual public ObjectFactory<CreationPolicy>
40 {
41 public:
42 40 LinSolverOMCFactory(PATH library_path, PATH modelicasystem_path, PATH config_path)
43 : ObjectFactory<CreationPolicy>(library_path, modelicasystem_path, config_path)
44 40 , _last_selected_solver("empty")
45 {
46
1/1
✓ Branch 1 taken 40 times.
40 _linsolver_type_map = new type_map();
47 40 }
48
49 40 virtual ~LinSolverOMCFactory()
50 {
51 40 delete _linsolver_type_map;
52 // ObjectFactory<CreationPolicy>::_factory->UnloadAllLibs(); todo solver lib wird in linsolver factory entlanden
53 40 }
54
55 68 virtual shared_ptr<ILinSolverSettings> createLinSolverSettings(string lin_solver)
56 {
57
1/2
✓ Branch 1 taken 68 times.
✗ Branch 2 not taken.
68 if (lin_solver.compare("dgesvSolver") == 0)
58 {
59 // dgesv with dgetc2 (total pivoting) as fallback
60 68 fs::path dgesvSolver_path = ObjectFactory<CreationPolicy>::_library_path;
61
1/1
✓ Branch 1 taken 68 times.
68 fs::path dgesvSolver_name(DGESVSOLVER_LIB);
62
1/1
✓ Branch 1 taken 68 times.
68 dgesvSolver_path /= dgesvSolver_name;
63
2/2
✓ Branch 1 taken 68 times.
✓ Branch 4 taken 68 times.
136 LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(dgesvSolver_path.string(), *_linsolver_type_map);
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 if (result != LOADER_SUCCESS)
65 {
66 ✗ throw ModelicaSimulationError(MODEL_FACTORY, "Failed loading dgesv solver library!");
67 }
68 68 }
69 ✗ else if (lin_solver.compare("linearSolver") == 0)
70 {
71 // dgesv/dgetc2 for dense and klu for sparce Jacobians
72 ✗ fs::path linearSolver_path = ObjectFactory<CreationPolicy>::_library_path;
73 ✗ fs::path linearSolver_name(LINEARSOLVER_LIB);
74 ✗ linearSolver_path/=linearSolver_name;
75 ✗ LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(linearSolver_path.string(), *_linsolver_type_map);
76 ✗ if (result != LOADER_SUCCESS)
77 {
78 ✗ throw ModelicaSimulationError(MODEL_FACTORY, "Failed loading linear solver library!");
79 }
80 ✗ }
81 else
82 ✗ throw ModelicaSimulationError(MODEL_FACTORY, "Selected linear solver is not available");
83
84 68 _last_selected_solver = lin_solver;
85 68 string linsolversettings = lin_solver.append("Settings");
86 std::map<std::string, factory<ILinSolverSettings> >::iterator iter;
87
1/1
✓ Branch 1 taken 68 times.
68 std::map<std::string, factory<ILinSolverSettings> >& linSolversettingsfactory(_linsolver_type_map->get());
88 iter = linSolversettingsfactory.find(linsolversettings);
89
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 if (iter == linSolversettingsfactory.end())
90 {
91 ✗ throw ModelicaSimulationError(MODEL_FACTORY, "No such linear solver Settings");
92 }
93 shared_ptr<ILinSolverSettings> linsolversetting = shared_ptr<ILinSolverSettings>(iter->second.create());
94 68 return linsolversetting;
95 }
96
97 68 virtual shared_ptr<ILinearAlgLoopSolver> createLinSolver(string solver_name, shared_ptr<ILinSolverSettings> solver_settings,shared_ptr<ILinearAlgLoop> algLoop = shared_ptr<ILinearAlgLoop>())
98 {
99
1/2
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
68 if (_last_selected_solver.compare(solver_name) == 0)
100 {
101 std::map<std::string, factory<ILinearAlgLoopSolver, ILinSolverSettings*,shared_ptr<ILinearAlgLoop> > >::iterator iter;
102 68 std::map<std::string, factory<ILinearAlgLoopSolver, ILinSolverSettings*,shared_ptr<ILinearAlgLoop> > >& linSolverFactory(_linsolver_type_map->get());
103 iter = linSolverFactory.find(solver_name);
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 if (iter == linSolverFactory.end())
105 {
106 ✗ throw ModelicaSimulationError(MODEL_FACTORY, "No such linear Solver");
107 }
108
1/1
✓ Branch 2 taken 68 times.
136 shared_ptr<ILinearAlgLoopSolver> solver = shared_ptr<ILinearAlgLoopSolver>(iter->second.create(solver_settings.get(),algLoop));
109
110 68 return solver;
111 }
112 else
113 ✗ throw ModelicaSimulationError(MODEL_FACTORY, "Selected linear solver is not available");
114 }
115
116 protected:
117 string _last_selected_solver;
118
119 private:
120 type_map* _linsolver_type_map;
121 };
122
123 /** @} */ // end of simcorefactoriesPolicies
124