OMCompiler/SimulationRuntime/cpp/SimCoreFactory/Policies/SolverSettingsOMCFactory.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 | #include <Core/Solver/ISolver.h> | ||
| 35 | |||
| 36 | /* | ||
| 37 | Policy class to create solver settings object | ||
| 38 | */ | ||
| 39 | template <class CreationPolicy> | ||
| 40 | struct SolverSettingsOMCFactory : public ObjectFactory<CreationPolicy> | ||
| 41 | { | ||
| 42 | |||
| 43 | public: | ||
| 44 | 40 | SolverSettingsOMCFactory(PATH library_path,PATH modelicasystem_path,PATH config_path) | |
| 45 |
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) |
| 46 | { | ||
| 47 | |||
| 48 |
1/1✓ Branch 1 taken 40 times.
|
40 | _solver_type_map = new type_map(); |
| 49 | 40 | } | |
| 50 | |||
| 51 | void loadGlobalSettings( shared_ptr<IGlobalSettings> global_settings) | ||
| 52 | { | ||
| 53 | |||
| 54 | } | ||
| 55 | |||
| 56 | 40 | virtual ~SolverSettingsOMCFactory() | |
| 57 | { | ||
| 58 | 40 | delete _solver_type_map; | |
| 59 | 40 | ObjectFactory<CreationPolicy>::_factory->UnloadAllLibs(); | |
| 60 | |||
| 61 | 80 | } | |
| 62 | |||
| 63 | 40 | virtual shared_ptr<ISolverSettings> createSolverSettings(string solvername,shared_ptr<IGlobalSettings> globalSettings) | |
| 64 | { | ||
| 65 | |||
| 66 | string solver_settings_key; | ||
| 67 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
|
40 | if(solvername.compare("idas")==0) |
| 68 | { | ||
| 69 | ✗ | solver_settings_key.assign("extension_export_idas"); | |
| 70 | } | ||
| 71 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 39 times.
|
40 | else if(solvername.compare("ida")==0) |
| 72 | { | ||
| 73 |
1/1✓ Branch 1 taken 1 time.
|
1 | fs::path ida_path = ObjectFactory<CreationPolicy>::_library_path; |
| 74 |
1/1✓ Branch 1 taken 1 time.
|
1 | fs::path ida_name(IDA_LIB); |
| 75 |
1/1✓ Branch 1 taken 1 time.
|
1 | ida_path/=ida_name; |
| 76 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
2 | LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(ida_name.string(),*_solver_type_map); |
| 77 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | if (result != LOADER_SUCCESS) |
| 78 | { | ||
| 79 | ✗ | throw std::runtime_error("Failed loading IDA solver library!"); | |
| 80 | } | ||
| 81 |
1/1✓ Branch 1 taken 1 time.
|
1 | solver_settings_key.assign("extension_export_ida"); |
| 82 | 1 | } | |
| 83 |
2/4✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 39 times.
✗ Branch 5 not taken.
|
39 | else if((solvername.compare("cvode")==0)||(solvername.compare("dassl")==0)) |
| 84 | { | ||
| 85 | solvername = "cvode"; //workound for dassl, using cvode instead | ||
| 86 |
1/1✓ Branch 1 taken 39 times.
|
39 | fs::path cvode_path = ObjectFactory<CreationPolicy>::_library_path; |
| 87 |
1/1✓ Branch 1 taken 39 times.
|
39 | fs::path cvode_name(CVODE_LIB); |
| 88 |
1/1✓ Branch 1 taken 39 times.
|
39 | cvode_path/=cvode_name; |
| 89 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
78 | LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(cvode_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 CVode solver library!"); | |
| 93 | } | ||
| 94 |
1/1✓ Branch 1 taken 39 times.
|
39 | solver_settings_key.assign("extension_export_cvode"); |
| 95 | 39 | } | |
| 96 | else | ||
| 97 | ✗ | throw ModelicaSimulationError(MODEL_FACTORY,"Selected Solver is not available"); | |
| 98 | |||
| 99 | |||
| 100 |
1/1✓ Branch 1 taken 40 times.
|
40 | string settings = solvername.append("Settings"); |
| 101 | std::map<std::string, factory<ISolverSettings, IGlobalSettings* > >::iterator iter; | ||
| 102 |
1/1✓ Branch 1 taken 40 times.
|
40 | std::map<std::string, factory<ISolverSettings, IGlobalSettings* > >& factories(_solver_type_map->get()); |
| 103 | iter = factories.find(settings); | ||
| 104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | if (iter ==factories.end()) |
| 105 | { | ||
| 106 | ✗ | std::string factoryStr = ""; std::cerr << "Available solverfactories:" << std::endl; | |
| 107 | ✗ | for(std::map<std::string, factory<ISolverSettings, IGlobalSettings* > >::iterator iter = factories.begin(); iter != factories.end(); iter++) | |
| 108 | { | ||
| 109 | ✗ | factoryStr += iter->first + " "; | |
| 110 | } | ||
| 111 | |||
| 112 | ✗ | throw ModelicaSimulationError(MODEL_FACTORY,"No such Solver " + solvername + ". Available solver factories:" + factoryStr ); | |
| 113 | } | ||
| 114 | shared_ptr<ISolverSettings> solver_settings = shared_ptr<ISolverSettings>(iter->second.create(globalSettings.get())); | ||
| 115 | |||
| 116 | |||
| 117 | 40 | return solver_settings; | |
| 118 | |||
| 119 | } | ||
| 120 | private: | ||
| 121 | type_map* _solver_type_map; | ||
| 122 | |||
| 123 | }; | ||
| 124 | /** @} */ // end of simcorefactoriesPolicies | ||
| 125 |