OMCompiler/SimulationRuntime/cpp/SimCoreFactory/Policies/StaticNonLinSolverOMCFactory.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 | |||
| 36 | shared_ptr<INonLinSolverSettings> createNewtonSettings(); | ||
| 37 | shared_ptr<INonLinSolverSettings> createKinsolSettings(); | ||
| 38 | shared_ptr<INonLinearAlgLoopSolver> createNewtonSolver(shared_ptr<INonLinSolverSettings> solver_settings,shared_ptr<INonLinearAlgLoop> algLoop); | ||
| 39 | shared_ptr<INonLinearAlgLoopSolver> createKinsolSolver(shared_ptr<INonLinSolverSettings> solver_settings,shared_ptr<INonLinearAlgLoop> algLoop); | ||
| 40 | template <class CreationPolicy> | ||
| 41 | class StaticNonLinSolverOMCFactory : virtual public ObjectFactory<CreationPolicy> | ||
| 42 | { | ||
| 43 | |||
| 44 | public: | ||
| 45 | StaticNonLinSolverOMCFactory(PATH library_path,PATH modelicasystem_path,PATH config_path) | ||
| 46 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1 | :ObjectFactory<CreationPolicy>(library_path,modelicasystem_path,config_path) |
| 47 | { | ||
| 48 | }; | ||
| 49 | 1 | virtual ~StaticNonLinSolverOMCFactory(){}; | |
| 50 | |||
| 51 | 2 | virtual shared_ptr<INonLinSolverSettings> createNonLinSolverSettings(string nonlin_solver) | |
| 52 | { | ||
| 53 | string nonlin_solver_key; | ||
| 54 | |||
| 55 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if(nonlin_solver.compare("newton")==0) |
| 56 | { | ||
| 57 |
1/1✓ Branch 1 taken 2 times.
|
2 | shared_ptr<INonLinSolverSettings> settings = createNewtonSettings(); |
| 58 | 2 | return settings; | |
| 59 | } | ||
| 60 | |||
| 61 | #ifdef ENABLE_SUNDIALS_STATIC | ||
| 62 | if(nonlin_solver.compare("kinsol")==0) | ||
| 63 | { | ||
| 64 | shared_ptr<INonLinSolverSettings> settings = createKinsolSettings(); | ||
| 65 | return settings; | ||
| 66 | } | ||
| 67 | #endif //ENABLE_SUNDIALS_STATIC | ||
| 68 | ✗ | throw ModelicaSimulationError(MODEL_FACTORY,"Selected nonlin solver is not available"); | |
| 69 | //return NonLinSolverOMCFactory<CreationPolicy>::createNonLinSolverSettings(nonlin_solver); | ||
| 70 | } | ||
| 71 | 2 | virtual shared_ptr<INonLinearAlgLoopSolver> createNonLinSolver(string solver_name, shared_ptr<INonLinSolverSettings> solver_settings,shared_ptr<INonLinearAlgLoop> algLoop = shared_ptr<INonLinearAlgLoop>()) | |
| 72 | { | ||
| 73 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if(solver_name.compare("newton")==0) |
| 74 | { | ||
| 75 |
2/5✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
6 | shared_ptr<INonLinearAlgLoopSolver> newton = createNewtonSolver(solver_settings,algLoop); |
| 76 | 2 | return newton; | |
| 77 | } | ||
| 78 | |||
| 79 | #ifdef ENABLE_SUNDIALS_STATIC | ||
| 80 | if(solver_name.compare("kinsol")==0) | ||
| 81 | { | ||
| 82 | shared_ptr<INonLinearAlgLoopSolver> kinsol = createKinsolSolver(solver_settings,algLoop); | ||
| 83 | return kinsol; | ||
| 84 | } | ||
| 85 | #endif //ENABLE_SUNDIALS_STATIC | ||
| 86 | ✗ | throw ModelicaSimulationError(MODEL_FACTORY,"Selected nonlin solver is not available"); | |
| 87 | //return NonLinSolverOMCFactory<CreationPolicy>::createNonLinSolver(algLoop, solver_name, solver_settings); | ||
| 88 | } | ||
| 89 | }; | ||
| 90 | /** @} */ // end of simcorefactoriesPolicies | ||
| 91 |