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% 28 / 0 / 42
Functions: 100.0% 4 / 0 / 4
Branches: 16.5% 16 / 0 / 97

OMCompiler/SimulationRuntime/cpp/SimCoreFactory/Policies/NonLinSolverOMCFactory.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 nonlin solver object
37 */
38 template <class CreationPolicy>
39 struct NonLinSolverOMCFactory : virtual public ObjectFactory<CreationPolicy>
40 {
41
42 public:
43 40 NonLinSolverOMCFactory(PATH library_path,PATH modelicasystem_path,PATH config_path)
44 :ObjectFactory<CreationPolicy>(library_path,modelicasystem_path,config_path)
45 40 ,_last_selected_solver("empty")
46 {
47
48
1/1
✓ Branch 1 taken 40 times.
40 _non_linsolver_type_map= new type_map();
49 40 }
50 40 virtual ~NonLinSolverOMCFactory()
51 {
52
53 40 delete _non_linsolver_type_map;
54 40 ObjectFactory<CreationPolicy>::_factory->UnloadAllLibs();
55 40 }
56
57 50 virtual shared_ptr<INonLinSolverSettings> createNonLinSolverSettings(string nonlin_solver)
58 {
59 string nonlin_solver_key;
60
61
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 if(nonlin_solver.compare("newton")==0)
62 {
63
64
1/1
✓ Branch 1 taken 50 times.
50 fs::path newton_path = ObjectFactory<CreationPolicy>::_library_path;
65
1/1
✓ Branch 1 taken 50 times.
50 fs::path newton_name(NEWTON_LIB);
66
1/1
✓ Branch 1 taken 50 times.
50 newton_path/=newton_name;
67
2/2
✓ Branch 1 taken 50 times.
✓ Branch 4 taken 50 times.
100 LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(newton_path.string(),*_non_linsolver_type_map);
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (result != LOADER_SUCCESS)
69 {
70
71 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"Failed loading Newton solver library!");
72 }
73
1/1
✓ Branch 1 taken 50 times.
50 nonlin_solver_key.assign("extension_export_newton");
74 50 }
75 ✗ else if(nonlin_solver.compare("kinsol")==0)
76 {
77 ✗ fs::path kinsol_path = ObjectFactory<CreationPolicy>::_library_path;
78 ✗ fs::path kinsol_name(KINSOL_LIB);
79 ✗ kinsol_path/=kinsol_name;
80 ✗ LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(kinsol_path.string(),*_non_linsolver_type_map);
81 ✗ if (result != LOADER_SUCCESS)
82 {
83
84 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"Failed loading Kinsol solver library!");
85 }
86 ✗ nonlin_solver_key.assign("extension_export_kinsol");
87 ✗ }
88 else
89 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"Selected nonlinear solver is not available");
90
1/1
✓ Branch 1 taken 50 times.
50 _last_selected_solver = nonlin_solver;
91
1/1
✓ Branch 1 taken 50 times.
50 string nonlinsolversettings = nonlin_solver.append("Settings");
92 std::map<std::string, factory<INonLinSolverSettings> >::iterator iter;
93
1/1
✓ Branch 1 taken 50 times.
50 std::map<std::string, factory<INonLinSolverSettings> >& nonLinSolversettingsfactory(_non_linsolver_type_map->get());
94 iter = nonLinSolversettingsfactory.find(nonlinsolversettings);
95
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (iter ==nonLinSolversettingsfactory.end())
96 {
97 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No such nonlinear solver Settings");
98 }
99 shared_ptr<INonLinSolverSettings> nonlinsolversetting= shared_ptr<INonLinSolverSettings>(iter->second.create());
100 50 return nonlinsolversetting;
101
102 }
103
104 50 virtual shared_ptr<INonLinearAlgLoopSolver> createNonLinSolver(string solver_name, shared_ptr<INonLinSolverSettings> solver_settings,shared_ptr<INonLinearAlgLoop> algLoop = shared_ptr<INonLinearAlgLoop>())
105 {
106
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 if(_last_selected_solver.compare(solver_name)==0)
107 {
108 std::map<std::string, factory<INonLinearAlgLoopSolver, INonLinSolverSettings*,shared_ptr<INonLinearAlgLoop> > >::iterator iter;
109 50 std::map<std::string, factory<INonLinearAlgLoopSolver, INonLinSolverSettings*,shared_ptr<INonLinearAlgLoop> > >& nonlinSolverFactory(_non_linsolver_type_map->get());
110 iter = nonlinSolverFactory.find(solver_name);
111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (iter ==nonlinSolverFactory.end())
112 {
113 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No such non linear Solver");
114 }
115
1/1
✓ Branch 2 taken 50 times.
100 shared_ptr<INonLinearAlgLoopSolver> solver = shared_ptr<INonLinearAlgLoopSolver>(iter->second.create(solver_settings.get(),algLoop));
116 50 return solver;
117 }
118 else
119 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"Selected nonlinear solver is not available");
120 }
121 protected:
122 string _last_selected_solver;
123 private:
124 type_map* _non_linsolver_type_map;
125 };
126 /** @} */ // end of simcorefactoriesPolicies
127