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-CurrentYear, 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 GPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
14 * ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the Open Source Modelica
17 * Consortium (OSMC) Public License (OSMC-PL) are obtained
18 * from OSMC, either from the above address,
19 * from the URLs: http://www.ida.liu.se/projects/OpenModelica or
20 * http://www.openmodelica.org, and in the OpenModelica distribution.
21 * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
22 *
23 * This program is distributed WITHOUT ANY WARRANTY; without
24 * even the implied warranty of MERCHANTABILITY or FITNESS
25 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
26 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
27 *
28 * See the full OSMC Public License conditions for more details.
29 *
30 */
31
32#ifndef _OMS_VALUES_H_
33#define _OMS_VALUES_H_
34
35#include "ComRef.h"
36#include "OMSFileSystem.h"
37#include "Snapshot.h"
38#include "OMSimulator/Types.h"
39
40#include <map>
41#include <pugixml.hpp>
42
43namespace oms
44{
45 class Values
46 {
47 public:
48 Values();
49 ~Values();
50
51 oms_status_enu_t setBoolean(const ComRef& cref, bool value);
52 oms_status_enu_t setInteger(const ComRef& cref, int value);
53 oms_status_enu_t setReal(const ComRef& cref, double value);
54 oms_status_enu_t setString(const ComRef& cref, const std::string& value);
55 oms_status_enu_t setUnit(const ComRef& cref, const std::string& value);
56 void setUnitDefinitions(const ComRef& cref);
57 void getFilteredUnitDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& unitDefinitions);
58 void getFilteredEnumerationDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& enumerationDefinitions);
59 void updateModelDescriptionRealStartValue(const ComRef& cref, double value);
60 void updateModelDescriptionIntegerStartValue(const ComRef& cref, int value);
61 void updateModelDescriptionBooleanStartValue(const ComRef& cref, bool value);
62 void updateModelDescriptionStringStartValue(const ComRef& cref, std::string value);
63
64 void updateModelDescriptionVariableUnit(const ComRef& cref, const std::string& value);
66
67 oms_status_enu_t getBoolean(const ComRef& cref, bool& value);
68 oms_status_enu_t getInteger(const ComRef& cref, int& value);
69 oms_status_enu_t getReal(const ComRef& cref, double& value);
70 oms_status_enu_t getString(const ComRef& cref, std::string& value);
71
72 oms_status_enu_t setBooleanResources(const ComRef& cref, bool value, const ComRef& fullCref, bool externalInput, oms_modelState_enu_t modelState);
73 oms_status_enu_t setIntegerResources(const ComRef& cref, int value, const ComRef& fullCref, bool externalInput, oms_modelState_enu_t modelState);
74 oms_status_enu_t setRealResources(const ComRef& cref, double value, const ComRef& fullCref, bool externalInput, oms_modelState_enu_t modelState);
75 oms_status_enu_t setStringResources(const ComRef& cref, const std::string& value, const ComRef& fullCref, bool externalInput, oms_modelState_enu_t modelState);
76 oms_status_enu_t setUnitResources(const ComRef& cref, const std::string& value, const ComRef& fullCref);
77
78 oms_status_enu_t getBooleanResources(const ComRef& cref, bool& value, bool externalInput, oms_modelState_enu_t modelState);
79 oms_status_enu_t getIntegerResources(const ComRef& cref, int& value, bool externalInput, oms_modelState_enu_t modelState);
80 oms_status_enu_t getRealResources(const ComRef& cref, double& value, bool externalInput, oms_modelState_enu_t modelState);
81 oms_status_enu_t getStringResources(const ComRef& cref, std::string& value, bool externalInput, oms_modelState_enu_t modelState);
82
83 oms_status_enu_t getBooleanFromModeldescription(const ComRef& cref, bool& value);
84 oms_status_enu_t getIntegerFromModeldescription(const ComRef& cref, int& value);
85 oms_status_enu_t getRealFromModeldescription(const ComRef& cref, double& value);
86 oms_status_enu_t getStringFromModeldescription(const ComRef& cref, std::string& value);
87
88 std::string getUnit(ComRef& cref) const;
89 std::string getUnitFromModeldescription(ComRef& cref) const;
90 std::string getEnumerationTypeFromModeldescription(ComRef& cref) const;
91 oms_status_enu_t exportToSSD(pugi::xml_node& node) const;
92 oms_status_enu_t importFromSnapshot(const pugi::xml_node& node, const std::string& sspVersion, const Snapshot& snapshot, std::string variantName);
93 oms_status_enu_t importFromSnapshot(const Snapshot& snapshot, const std::string& ssvFilePath, const std::string& ssmFilename);
94 oms_status_enu_t deleteStartValue(const ComRef& cref);
95 oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(Values& value, const ComRef& owner, std::vector<std::string>& warningList);
96 oms_status_enu_t deleteStartValueInResources(const ComRef& cref);
97
98 oms_status_enu_t deleteReferencesInSSD(const std::string& filename);
99 oms_status_enu_t deleteResourcesInSSP(const std::string& filename);
100
101 oms_status_enu_t exportToSSV(pugi::xml_node& ssvNode) const;
102
103 oms_status_enu_t exportUnitDefinitions(Snapshot &snapshot, std::string filename, std::string variantName) const;
104 oms_status_enu_t exportUnitDefinitionsToSSVTemplate(Snapshot &snapshot, std::string filename);
105 void importUnitDefinitions(const pugi::xml_node& node);
106 void importEnumerationDefinitions(const pugi::xml_node& node, std::string& enumTypeName);
107
108 void exportToSSVTemplate(pugi::xml_node& ssvNode, const ComRef& cref);
109 void exportReduceSSV(pugi::xml_node& ssvNode, const ComRef& cref);
110
111 oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode, const ComRef& cref);
112
113 oms_status_enu_t parseModelDescription(const filesystem::path& root, std::string& guid_);
114 oms_status_enu_t parseModelDescriptionFmi3(const filesystem::path& root, std::string& guid_);
115
116 oms_status_enu_t rename(const oms::ComRef& oldCref, const oms::ComRef& newCref);
117 oms_status_enu_t renameInResources(const oms::ComRef& oldCref, const oms::ComRef& newCref);
118
119 void exportParameterBindings(pugi::xml_node& node, Snapshot& snapshot, std::string variantName) const;
120
121 bool hasResources();
122
123 private:
124 oms_status_enu_t exportStartValuesHelper(pugi::xml_node& node) const;
125 void exportParameterMappingInline(pugi::xml_node& node) const;
126 void exportParameterMappingToSSM(pugi::xml_node& node) const;
127 oms_status_enu_t importStartValuesHelper(const pugi::xml_node& parameters);
128
129 void parseModelStructureDependencies(std::string &dependencies, std::vector<int>& dependencyList);
130
131 void importParameterMapping(const pugi::xml_node& parameterMapping);
132 oms::ComRef getMappedCrefEntry(const ComRef& cref) const;
133 bool isEntryReferencedInSSM(const ComRef& cref) const;
134 bool empty() const;
135
136 public:
137 std::map<ComRef, bool> booleanStartValues;
138 std::map<ComRef, double> realStartValues;
139 std::map<ComRef, int> integerStartValues;
140 std::map<ComRef, std::string> stringStartValues;
141
142 std::map<ComRef, bool> booleanValues;
143 std::map<ComRef, double> realValues;
144 std::map<ComRef, int> integerValues;
145 std::map<ComRef, std::string> stringValues;
146
147 std::map<ComRef, bool> modelDescriptionBooleanStartValues;
148 std::map<ComRef, double> modelDescriptionRealStartValues;
150 std::map<ComRef, std::string> modelDescriptionStringStartValues;
151
152 std::map<int, std::vector<int>> modelStructureOutputs;
153 std::map<int, std::vector<int>> modelStructureDerivatives;
154 std::map<int, std::vector<int>> modelStructureInitialUnknowns;
155
159
160 std::map<ComRef, std::string> modelDescriptionVariableUnits;
161 std::map<ComRef, std::string> variableUnits;
162
164 {
165 std::string unitName;
166 std::string unitValue;
167 std::map<std::string, std::string> baseUnit;
169 };
170 std::vector<unitDefinitionsToExport> unitDefinitionsToExportInSSP;
171
172 std::map<std::string, std::map<std::string, std::string>> modeldescriptionUnitDefinitions;
173
174 std::map<std::string, std::map<std::string, std::string>> modeldescriptionTypeDefinitions;
175 std::map<std::string, std::string> modeldescriptionEnumeration;
176
177 std::multimap<ComRef, ComRef> mappedEntry;
178
179 std::vector<Values> parameterResources;
180 std::map<std::string, Values> allresources;
181 std::string ssmFile = "";
182 bool linkResources = true;
183 };
184}
185
186#endif
ComRef - component reference.
Definition ComRef.h:47
Definition Snapshot.h:47
Definition Values.h:46
void getFilteredUnitDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &unitDefinitions)
Definition Values.cpp:85
oms_status_enu_t renameInResources(const oms::ComRef &oldCref, const oms::ComRef &newCref)
Definition Values.cpp:1951
oms_status_enu_t setString(const ComRef &cref, const std::string &value)
Definition Values.cpp:125
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition Values.cpp:111
oms_status_enu_t setRealResources(const ComRef &cref, double value, const ComRef &fullCref, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:251
std::map< ComRef, int > integerValues
input values defined after initialization
Definition Values.h:144
oms_status_enu_t exportUnitDefinitions(Snapshot &snapshot, std::string filename, std::string variantName) const
Definition Values.cpp:942
oms_status_enu_t setUnit(const ComRef &cref, const std::string &value)
Definition Values.cpp:185
oms_status_enu_t getString(const ComRef &cref, std::string &value)
Definition Values.cpp:215
void importUnitDefinitions(const pugi::xml_node &node)
Definition Values.cpp:1479
void setUnitDefinitions(const ComRef &cref)
Definition Values.cpp:65
std::string getUnit(ComRef &cref) const
Definition Values.cpp:570
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition Values.cpp:239
void importEnumerationDefinitions(const pugi::xml_node &node, std::string &enumTypeName)
Definition Values.cpp:1497
std::map< std::string, std::string > modeldescriptionEnumeration
enumeration declared type list list read from modeldescription.xml
Definition Values.h:175
std::map< ComRef, double > modelDescriptionRealStartValues
start values read from modelDescription.xml
Definition Values.h:148
void updateModelDescriptionVariableUnit(const ComRef &cref, const std::string &value)
Definition Values.cpp:164
std::string ssmFile
mapped ssm files associated with ssv files;
Definition Values.h:181
std::map< ComRef, std::string > stringValues
input values defined after initialization
Definition Values.h:145
std::map< ComRef, bool > booleanStartValues
parameters and start values defined before instantiating the FMU
Definition Values.h:137
oms_status_enu_t rename(const oms::ComRef &oldCref, const oms::ComRef &newCref)
Definition Values.cpp:1889
std::map< ComRef, std::string > stringStartValues
parameters and start values defined before instantiating the FMU
Definition Values.h:140
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:177
oms_status_enu_t exportUnitDefinitionsToSSVTemplate(Snapshot &snapshot, std::string filename)
Definition Values.cpp:983
oms::ComRef getMappedCrefEntry(const ComRef &cref) const
Definition Values.cpp:1195
void updateModelDescriptionIntegerStartValue(const ComRef &cref, int value)
Definition Values.cpp:140
void updateModelDescriptionBooleanStartValue(const ComRef &cref, bool value)
Definition Values.cpp:148
std::map< ComRef, int > integerStartValues
parameters and start values defined before instantiating the FMU
Definition Values.h:139
std::map< int, bool > modelStructureInitialUnknownsDependencyExist
Definition Values.h:158
std::map< int, bool > modelStructureDerivativesDependencyExist
Definition Values.h:157
void exportReduceSSV(pugi::xml_node &ssvNode, const ComRef &cref)
reduced SSV file which contains only the referenced crefs in parametermapping
Definition Values.cpp:1297
std::map< ComRef, bool > booleanValues
input values defined after initialization
Definition Values.h:142
oms_status_enu_t setIntegerResources(const ComRef &cref, int value, const ComRef &fullCref, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:354
std::map< ComRef, std::string > variableUnits
variable units set by user
Definition Values.h:161
~Values()
Definition Values.cpp:50
oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition Values.cpp:203
std::map< int, std::vector< int > > modelStructureDerivatives
derivatives and its dependencies from <ModelStructure>
Definition Values.h:153
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition Values.cpp:792
oms_status_enu_t getRealFromModeldescription(const ComRef &cref, double &value)
Definition Values.cpp:544
void exportToSSVTemplate(pugi::xml_node &ssvNode, const ComRef &cref)
start values read from modelDescription.xml and creates a ssv template
Definition Values.cpp:1255
std::map< ComRef, double > realStartValues
parameters and start values defined before instantiating the FMU
Definition Values.h:138
std::vector< Values > parameterResources
list of parameter resources provided inline or .ssv files
Definition Values.h:179
void getFilteredEnumerationDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &enumerationDefinitions)
Definition Values.cpp:98
std::map< ComRef, bool > modelDescriptionBooleanStartValues
start values read from modelDescription.xml
Definition Values.h:147
std::string getUnitFromModeldescription(ComRef &cref) const
Definition Values.cpp:580
void importParameterMapping(const pugi::xml_node &parameterMapping)
Definition Values.cpp:1872
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:1366
std::map< std::string, std::map< std::string, std::string > > modeldescriptionTypeDefinitions
<TypeDefinitions> list read from modeldescription.xml
Definition Values.h:174
std::map< int, bool > modelStructureOutputDependencyExist
Definition Values.h:156
std::vector< unitDefinitionsToExport > unitDefinitionsToExportInSSP
list of unitDefinitions to be exported in ssp
Definition Values.h:170
bool hasResources()
returns if the system or subsystem or submodule have parameter resources either as ssv or inline
Definition Values.cpp:2018
void exportParameterMappingToSSM(pugi::xml_node &node) const
Definition Values.cpp:1239
oms_status_enu_t exportStartValuesHelper(pugi::xml_node &node) const
Definition Values.cpp:1028
void exportParameterMappingInline(pugi::xml_node &node) const
Definition Values.cpp:1223
void exportParameterBindings(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const
Definition Values.cpp:1094
oms_status_enu_t importFromSnapshot(const pugi::xml_node &node, const std::string &sspVersion, const Snapshot &snapshot, std::string variantName)
Definition Values.cpp:857
void updateModelDescriptionStringStartValue(const ComRef &cref, std::string value)
Definition Values.cpp:156
oms_status_enu_t setBooleanResources(const ComRef &cref, bool value, const ComRef &fullCref, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:391
oms_status_enu_t getIntegerResources(const ComRef &cref, int &value, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:457
oms_status_enu_t getBooleanResources(const ComRef &cref, bool &value, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:486
oms_status_enu_t getRealResources(const ComRef &cref, double &value, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:428
std::map< std::string, Values > allresources
mapped resources either inline or ssv
Definition Values.h:180
oms_status_enu_t importStartValuesHelper(const pugi::xml_node &parameters)
Definition Values.cpp:1399
std::map< ComRef, double > realValues
input values defined after initialization
Definition Values.h:143
std::map< ComRef, std::string > modelDescriptionStringStartValues
start values read from modelDescription.xml
Definition Values.h:150
oms_status_enu_t setUnitResources(const ComRef &cref, const std::string &value, const ComRef &fullCref)
Definition Values.cpp:323
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition Values.cpp:54
std::map< int, std::vector< int > > modelStructureOutputs
output and its dependencies from <ModelStructure>
Definition Values.h:152
oms_status_enu_t getStringResources(const ComRef &cref, std::string &value, bool externalInput, oms_modelState_enu_t modelState)
Definition Values.cpp:515
bool linkResources
Definition Values.h:182
void updateModelDescriptionRealStartValue(const ComRef &cref, double value)
Definition Values.cpp:132
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(Values &value, const ComRef &owner, std::vector< std::string > &warningList)
Definition Values.cpp:658
std::map< ComRef, std::string > modelDescriptionVariableUnits
variable units read from modeldescription.xml
Definition Values.h:160
oms_status_enu_t getIntegerFromModeldescription(const ComRef &cref, int &value)
Definition Values.cpp:600
oms_status_enu_t getStringFromModeldescription(const ComRef &cref, std::string &value)
Definition Values.cpp:557
oms_status_enu_t exportToSSD(pugi::xml_node &node) const
Definition Values.cpp:810
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:289
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition Values.cpp:227
oms_status_enu_t deleteReferencesInSSD(const std::string &filename)
Definition Values.cpp:775
bool empty() const
Definition Values.cpp:927
oms_status_enu_t parseModelDescription(const filesystem::path &root, std::string &guid_)
path without the filename, i.e. modelDescription.xml
Definition Values.cpp:1520
oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition Values.cpp:626
std::map< ComRef, int > modelDescriptionIntegerStartValues
start values read from modelDescription.xml
Definition Values.h:149
oms_status_enu_t parseModelDescriptionFmi3(const filesystem::path &root, std::string &guid_)
path without the filename, i.e. modelDescription.xml
Definition Values.cpp:1690
void copyModelDescriptionUnitToResources(Values &value)
Definition Values.cpp:173
oms_status_enu_t deleteStartValueInResources(const ComRef &cref)
Definition Values.cpp:737
Values()
Definition Values.cpp:46
void parseModelStructureDependencies(std::string &dependencies, std::vector< int > &dependencyList)
Definition Values.cpp:1861
std::map< int, std::vector< int > > modelStructureInitialUnknowns
initialUnknowns and its dependencies from <ModelStructure>
Definition Values.h:154
oms_status_enu_t exportToSSV(pugi::xml_node &ssvNode) const
Definition Values.cpp:932
std::string getEnumerationTypeFromModeldescription(ComRef &cref) const
Definition Values.cpp:590
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition Values.cpp:118
bool isEntryReferencedInSSM(const ComRef &cref) const
Definition Values.cpp:1208
oms_status_enu_t getBooleanFromModeldescription(const ComRef &cref, bool &value)
Definition Values.cpp:613
std::map< std::string, std::map< std::string, std::string > > modeldescriptionUnitDefinitions
<UnitDefinitions> list read from modeldescription.xml
Definition Values.h:172
Definition AlgLoop.h:45
bool exportUnit
Definition Values.h:168
std::map< std::string, std::string > baseUnit
Definition Values.h:167
std::string unitValue
Definition Values.h:166
std::string unitName
Definition Values.h:165