OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment.
Loading...
Searching...
No Matches
Values.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36#ifndef _OMS_VALUES_H_
37#define _OMS_VALUES_H_
38
39#include "ComRef.h"
40#include "OMSFileSystem.h"
41#include "Snapshot.h"
42#include "OMSimulator/Types.h"
43
44#include <map>
45#include <pugixml.hpp>
46
47namespace oms
48{
49 class Values
50 {
51 public:
52 Values();
53 ~Values();
54
55 oms_status_enu_t setBoolean(const ComRef& cref, bool value);
56 oms_status_enu_t setInteger(const ComRef& cref, int value);
57 oms_status_enu_t setReal(const ComRef& cref, double value);
58 oms_status_enu_t setString(const ComRef& cref, const std::string& value);
59 oms_status_enu_t setUnit(const ComRef& cref, const std::string& value);
60 void setUnitDefinitions(const ComRef& cref);
61 void getFilteredUnitDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& unitDefinitions);
62 void getFilteredEnumerationDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& enumerationDefinitions);
63 void updateModelDescriptionRealStartValue(const ComRef& cref, double value);
64 void updateModelDescriptionIntegerStartValue(const ComRef& cref, int value);
65 void updateModelDescriptionBooleanStartValue(const ComRef& cref, bool value);
66 void updateModelDescriptionStringStartValue(const ComRef& cref, std::string value);
67
68 void updateModelDescriptionVariableUnit(const ComRef& cref, const std::string& value);
70
71 oms_status_enu_t getBoolean(const ComRef& cref, bool& value);
72 oms_status_enu_t getInteger(const ComRef& cref, int& value);
73 oms_status_enu_t getReal(const ComRef& cref, double& value);
74 oms_status_enu_t getString(const ComRef& cref, std::string& value);
75
76 oms_status_enu_t setBooleanResources(const ComRef& cref, bool value, const ComRef& fullCref, bool externalInput, oms_modelState_enu_t modelState);
77 oms_status_enu_t setIntegerResources(const ComRef& cref, int value, const ComRef& fullCref, bool externalInput, oms_modelState_enu_t modelState);
78 oms_status_enu_t setRealResources(const ComRef& cref, double value, const ComRef& fullCref, bool externalInput, oms_modelState_enu_t modelState);
79 oms_status_enu_t setStringResources(const ComRef& cref, const std::string& value, const ComRef& fullCref, bool externalInput, oms_modelState_enu_t modelState);
80 oms_status_enu_t setUnitResources(const ComRef& cref, const std::string& value, const ComRef& fullCref);
81
82 oms_status_enu_t getBooleanResources(const ComRef& cref, bool& value, bool externalInput, oms_modelState_enu_t modelState);
83 oms_status_enu_t getIntegerResources(const ComRef& cref, int& value, bool externalInput, oms_modelState_enu_t modelState);
84 oms_status_enu_t getRealResources(const ComRef& cref, double& value, bool externalInput, oms_modelState_enu_t modelState);
85 oms_status_enu_t getStringResources(const ComRef& cref, std::string& value, bool externalInput, oms_modelState_enu_t modelState);
86
87 oms_status_enu_t getBooleanFromModeldescription(const ComRef& cref, bool& value);
88 oms_status_enu_t getIntegerFromModeldescription(const ComRef& cref, int& value);
89 oms_status_enu_t getRealFromModeldescription(const ComRef& cref, double& value);
90 oms_status_enu_t getStringFromModeldescription(const ComRef& cref, std::string& value);
91
92 std::string getUnit(ComRef& cref) const;
93 std::string getUnitFromModeldescription(ComRef& cref) const;
94 std::string getEnumerationTypeFromModeldescription(ComRef& cref) const;
95 oms_status_enu_t exportToSSD(pugi::xml_node& node) const;
96 oms_status_enu_t importFromSnapshot(const pugi::xml_node& node, const std::string& sspVersion, const Snapshot& snapshot, std::string variantName);
97 oms_status_enu_t importFromSnapshot(const Snapshot& snapshot, const std::string& ssvFilePath, const std::string& ssmFilename);
98 oms_status_enu_t deleteStartValue(const ComRef& cref);
99 oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(Values& value, const ComRef& owner, std::vector<std::string>& warningList);
100 oms_status_enu_t deleteStartValueInResources(const ComRef& cref);
101
102 oms_status_enu_t deleteReferencesInSSD(const std::string& filename);
103 oms_status_enu_t deleteResourcesInSSP(const std::string& filename);
104
105 oms_status_enu_t exportToSSV(pugi::xml_node& ssvNode) const;
106
107 oms_status_enu_t exportUnitDefinitions(Snapshot &snapshot, std::string filename, std::string variantName) const;
108 oms_status_enu_t exportUnitDefinitionsToSSVTemplate(Snapshot &snapshot, std::string filename);
109 void importUnitDefinitions(const pugi::xml_node& node);
110 void importEnumerationDefinitions(const pugi::xml_node& node, std::string& enumTypeName);
111
112 void exportToSSVTemplate(pugi::xml_node& ssvNode, const ComRef& cref);
113 void exportReduceSSV(pugi::xml_node& ssvNode, const ComRef& cref);
114
115 oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode, const ComRef& cref);
116
117 oms_status_enu_t parseModelDescription(const filesystem::path& root, std::string& guid_);
118 oms_status_enu_t parseModelDescriptionFmi3(const filesystem::path& root, std::string& guid_);
119
120 oms_status_enu_t rename(const oms::ComRef& oldCref, const oms::ComRef& newCref);
121 oms_status_enu_t renameInResources(const oms::ComRef& oldCref, const oms::ComRef& newCref);
122
123 void exportParameterBindings(pugi::xml_node& node, Snapshot& snapshot, std::string variantName) const;
124
125 bool hasResources();
126
127 private:
128 oms_status_enu_t exportStartValuesHelper(pugi::xml_node& node) const;
129 void exportParameterMappingInline(pugi::xml_node& node) const;
130 void exportParameterMappingToSSM(pugi::xml_node& node) const;
131 oms_status_enu_t importStartValuesHelper(const pugi::xml_node& parameters);
132
133 void parseModelStructureDependencies(std::string &dependencies, std::vector<int>& dependencyList);
134
135 void importParameterMapping(const pugi::xml_node& parameterMapping);
136 oms::ComRef getMappedCrefEntry(const ComRef& cref) const;
137 bool isEntryReferencedInSSM(const ComRef& cref) const;
138 bool empty() const;
139
140 public:
141 std::map<ComRef, bool> booleanStartValues;
142 std::map<ComRef, double> realStartValues;
143 std::map<ComRef, int> integerStartValues;
144 std::map<ComRef, std::string> stringStartValues;
145
146 std::map<ComRef, bool> booleanValues;
147 std::map<ComRef, double> realValues;
148 std::map<ComRef, int> integerValues;
149 std::map<ComRef, std::string> stringValues;
150
151 std::map<ComRef, bool> modelDescriptionBooleanStartValues;
152 std::map<ComRef, double> modelDescriptionRealStartValues;
154 std::map<ComRef, std::string> modelDescriptionStringStartValues;
155
156 std::map<int, std::vector<int>> modelStructureOutputs;
157 std::map<int, std::vector<int>> modelStructureDerivatives;
158 std::map<int, std::vector<int>> modelStructureInitialUnknowns;
159
163
164 std::map<ComRef, std::string> modelDescriptionVariableUnits;
165 std::map<ComRef, std::string> variableUnits;
166
168 {
169 std::string unitName;
170 std::string unitValue;
171 std::map<std::string, std::string> baseUnit;
173 };
174 std::vector<unitDefinitionsToExport> unitDefinitionsToExportInSSP;
175
176 std::map<std::string, std::map<std::string, std::string>> modeldescriptionUnitDefinitions;
177
178 std::map<std::string, std::map<std::string, std::string>> modeldescriptionTypeDefinitions;
179 std::map<std::string, std::string> modeldescriptionEnumeration;
180
181 std::multimap<ComRef, ComRef> mappedEntry;
182
183 std::vector<Values> parameterResources;
184 std::map<std::string, Values> allresources;
185 std::string ssmFile = "";
186 bool linkResources = true;
187 };
188}
189
190#endif
ComRef - component reference.
Definition ComRef.h:51
Definition Snapshot.h:51
Definition Values.h:50
void getFilteredUnitDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &unitDefinitions)
Definition Values.cpp:88
oms_status_enu_t renameInResources(const oms::ComRef &oldCref, const oms::ComRef &newCref)
Definition Values.cpp:1954
oms_status_enu_t setString(const ComRef &cref, const std::string &value)
Definition Values.cpp:128
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition Values.cpp:114
oms_status_enu_t setRealResources(const ComRef &cref, double value, const ComRef &fullCref, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:254
std::map< ComRef, int > integerValues
input values defined after initialization
Definition Values.h:148
oms_status_enu_t exportUnitDefinitions(Snapshot &snapshot, std::string filename, std::string variantName) const
Definition Values.cpp:945
oms_status_enu_t setUnit(const ComRef &cref, const std::string &value)
Definition Values.cpp:188
oms_status_enu_t getString(const ComRef &cref, std::string &value)
Definition Values.cpp:218
void importUnitDefinitions(const pugi::xml_node &node)
Definition Values.cpp:1482
void setUnitDefinitions(const ComRef &cref)
Definition Values.cpp:68
std::string getUnit(ComRef &cref) const
Definition Values.cpp:573
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition Values.cpp:242
void importEnumerationDefinitions(const pugi::xml_node &node, std::string &enumTypeName)
Definition Values.cpp:1500
std::map< std::string, std::string > modeldescriptionEnumeration
enumeration declared type list list read from modeldescription.xml
Definition Values.h:179
std::map< ComRef, double > modelDescriptionRealStartValues
start values read from modelDescription.xml
Definition Values.h:152
void updateModelDescriptionVariableUnit(const ComRef &cref, const std::string &value)
Definition Values.cpp:167
std::string ssmFile
mapped ssm files associated with ssv files;
Definition Values.h:185
std::map< ComRef, std::string > stringValues
input values defined after initialization
Definition Values.h:149
std::map< ComRef, bool > booleanStartValues
parameters and start values defined before instantiating the FMU
Definition Values.h:141
oms_status_enu_t rename(const oms::ComRef &oldCref, const oms::ComRef &newCref)
Definition Values.cpp:1892
std::map< ComRef, std::string > stringStartValues
parameters and start values defined before instantiating the FMU
Definition Values.h:144
std::multimap< ComRef, ComRef > mappedEntry
parameter names and values provided in the parameter source are to be mapped to the parameters of the...
Definition Values.h:181
oms_status_enu_t exportUnitDefinitionsToSSVTemplate(Snapshot &snapshot, std::string filename)
Definition Values.cpp:986
oms::ComRef getMappedCrefEntry(const ComRef &cref) const
Definition Values.cpp:1198
void updateModelDescriptionIntegerStartValue(const ComRef &cref, int value)
Definition Values.cpp:143
void updateModelDescriptionBooleanStartValue(const ComRef &cref, bool value)
Definition Values.cpp:151
std::map< ComRef, int > integerStartValues
parameters and start values defined before instantiating the FMU
Definition Values.h:143
std::map< int, bool > modelStructureInitialUnknownsDependencyExist
Definition Values.h:162
std::map< int, bool > modelStructureDerivativesDependencyExist
Definition Values.h:161
void exportReduceSSV(pugi::xml_node &ssvNode, const ComRef &cref)
reduced SSV file which contains only the referenced crefs in parametermapping
Definition Values.cpp:1300
std::map< ComRef, bool > booleanValues
input values defined after initialization
Definition Values.h:146
oms_status_enu_t setIntegerResources(const ComRef &cref, int value, const ComRef &fullCref, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:357
std::map< ComRef, std::string > variableUnits
variable units set by user
Definition Values.h:165
~Values()
Definition Values.cpp:53
oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition Values.cpp:206
std::map< int, std::vector< int > > modelStructureDerivatives
derivatives and its dependencies from <ModelStructure>
Definition Values.h:157
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition Values.cpp:795
oms_status_enu_t getRealFromModeldescription(const ComRef &cref, double &value)
Definition Values.cpp:547
void exportToSSVTemplate(pugi::xml_node &ssvNode, const ComRef &cref)
start values read from modelDescription.xml and creates a ssv template
Definition Values.cpp:1258
std::map< ComRef, double > realStartValues
parameters and start values defined before instantiating the FMU
Definition Values.h:142
std::vector< Values > parameterResources
list of parameter resources provided inline or .ssv files
Definition Values.h:183
void getFilteredEnumerationDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &enumerationDefinitions)
Definition Values.cpp:101
std::map< ComRef, bool > modelDescriptionBooleanStartValues
start values read from modelDescription.xml
Definition Values.h:151
std::string getUnitFromModeldescription(ComRef &cref) const
Definition Values.cpp:583
void importParameterMapping(const pugi::xml_node &parameterMapping)
Definition Values.cpp:1875
oms_status_enu_t exportToSSMTemplate(pugi::xml_node &ssmNode, const ComRef &cref)
start values read from modelDescription.xml and creates a ssm template
Definition Values.cpp:1369
std::map< std::string, std::map< std::string, std::string > > modeldescriptionTypeDefinitions
<TypeDefinitions> list read from modeldescription.xml
Definition Values.h:178
std::map< int, bool > modelStructureOutputDependencyExist
Definition Values.h:160
std::vector< unitDefinitionsToExport > unitDefinitionsToExportInSSP
list of unitDefinitions to be exported in ssp
Definition Values.h:174
bool hasResources()
returns if the system or subsystem or submodule have parameter resources either as ssv or inline
Definition Values.cpp:2021
void exportParameterMappingToSSM(pugi::xml_node &node) const
Definition Values.cpp:1242
oms_status_enu_t exportStartValuesHelper(pugi::xml_node &node) const
Definition Values.cpp:1031
void exportParameterMappingInline(pugi::xml_node &node) const
Definition Values.cpp:1226
void exportParameterBindings(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const
Definition Values.cpp:1097
oms_status_enu_t importFromSnapshot(const pugi::xml_node &node, const std::string &sspVersion, const Snapshot &snapshot, std::string variantName)
Definition Values.cpp:860
void updateModelDescriptionStringStartValue(const ComRef &cref, std::string value)
Definition Values.cpp:159
oms_status_enu_t setBooleanResources(const ComRef &cref, bool value, const ComRef &fullCref, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:394
oms_status_enu_t getIntegerResources(const ComRef &cref, int &value, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:460
oms_status_enu_t getBooleanResources(const ComRef &cref, bool &value, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:489
oms_status_enu_t getRealResources(const ComRef &cref, double &value, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:431
std::map< std::string, Values > allresources
mapped resources either inline or ssv
Definition Values.h:184
oms_status_enu_t importStartValuesHelper(const pugi::xml_node &parameters)
Definition Values.cpp:1402
std::map< ComRef, double > realValues
input values defined after initialization
Definition Values.h:147
std::map< ComRef, std::string > modelDescriptionStringStartValues
start values read from modelDescription.xml
Definition Values.h:154
oms_status_enu_t setUnitResources(const ComRef &cref, const std::string &value, const ComRef &fullCref)
Definition Values.cpp:326
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition Values.cpp:57
std::map< int, std::vector< int > > modelStructureOutputs
output and its dependencies from <ModelStructure>
Definition Values.h:156
oms_status_enu_t getStringResources(const ComRef &cref, std::string &value, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:518
bool linkResources
Definition Values.h:186
void updateModelDescriptionRealStartValue(const ComRef &cref, double value)
Definition Values.cpp:135
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(Values &value, const ComRef &owner, std::vector< std::string > &warningList)
Definition Values.cpp:661
std::map< ComRef, std::string > modelDescriptionVariableUnits
variable units read from modeldescription.xml
Definition Values.h:164
oms_status_enu_t getIntegerFromModeldescription(const ComRef &cref, int &value)
Definition Values.cpp:603
oms_status_enu_t getStringFromModeldescription(const ComRef &cref, std::string &value)
Definition Values.cpp:560
oms_status_enu_t exportToSSD(pugi::xml_node &node) const
Definition Values.cpp:813
oms_status_enu_t setStringResources(const ComRef &cref, const std::string &value, const ComRef &fullCref, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:292
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition Values.cpp:230
oms_status_enu_t deleteReferencesInSSD(const std::string &filename)
Definition Values.cpp:778
bool empty() const
Definition Values.cpp:930
oms_status_enu_t parseModelDescription(const filesystem::path &root, std::string &guid_)
path without the filename, i.e. modelDescription.xml
Definition Values.cpp:1523
oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition Values.cpp:629
std::map< ComRef, int > modelDescriptionIntegerStartValues
start values read from modelDescription.xml
Definition Values.h:153
oms_status_enu_t parseModelDescriptionFmi3(const filesystem::path &root, std::string &guid_)
path without the filename, i.e. modelDescription.xml
Definition Values.cpp:1693
void copyModelDescriptionUnitToResources(Values &value)
Definition Values.cpp:176
oms_status_enu_t deleteStartValueInResources(const ComRef &cref)
Definition Values.cpp:740
Values()
Definition Values.cpp:49
void parseModelStructureDependencies(std::string &dependencies, std::vector< int > &dependencyList)
Definition Values.cpp:1864
std::map< int, std::vector< int > > modelStructureInitialUnknowns
initialUnknowns and its dependencies from <ModelStructure>
Definition Values.h:158
oms_status_enu_t exportToSSV(pugi::xml_node &ssvNode) const
Definition Values.cpp:935
std::string getEnumerationTypeFromModeldescription(ComRef &cref) const
Definition Values.cpp:593
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition Values.cpp:121
bool isEntryReferencedInSSM(const ComRef &cref) const
Definition Values.cpp:1211
oms_status_enu_t getBooleanFromModeldescription(const ComRef &cref, bool &value)
Definition Values.cpp:616
std::map< std::string, std::map< std::string, std::string > > modeldescriptionUnitDefinitions
<UnitDefinitions> list read from modeldescription.xml
Definition Values.h:176
Definition AlgLoop.h:49
bool exportUnit
Definition Values.h:172
std::map< std::string, std::string > baseUnit
Definition Values.h:171
std::string unitValue
Definition Values.h:170
std::string unitName
Definition Values.h:169