OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment that supports ordinary (i.e., non-delayed) and TLM connections.
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 "Types.h"
39 
40 #include <map>
41 #include <pugixml.hpp>
42 
43 namespace 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 updateModelDescriptionRealStartValue(const ComRef& cref, double value);
59  void updateModelDescriptionIntegerStartValue(const ComRef& cref, int value);
60  void updateModelDescriptionBooleanStartValue(const ComRef& cref, bool value);
61  void updateModelDescriptionStringStartValue(const ComRef& cref, std::string value);
62 
63  void updateModelDescriptionVariableUnit(const ComRef& cref, const std::string& value);
65 
66  oms_status_enu_t getBoolean(const ComRef& cref, bool& value);
67  oms_status_enu_t getInteger(const ComRef& cref, int& value);
68  oms_status_enu_t getReal(const ComRef& cref, double& value);
69  oms_status_enu_t getString(const ComRef& cref, std::string& value);
70 
71  oms_status_enu_t setBooleanResources(const ComRef& cref, bool value, const ComRef& fullCref, bool externalInput, oms_modelState_enu_t modelState);
72  oms_status_enu_t setIntegerResources(const ComRef& cref, int value, const ComRef& fullCref, bool externalInput, oms_modelState_enu_t modelState);
73  oms_status_enu_t setRealResources(const ComRef& cref, double value, const ComRef& fullCref, bool externalInput, oms_modelState_enu_t modelState);
74  oms_status_enu_t setStringResources(const ComRef& cref, const std::string& value, const ComRef& fullCref, bool externalInput, oms_modelState_enu_t modelState);
75  oms_status_enu_t setUnitResources(const ComRef& cref, const std::string& value, const ComRef& fullCref);
76 
77  oms_status_enu_t getBooleanResources(const ComRef& cref, bool& value, bool externalInput, oms_modelState_enu_t modelState);
78  oms_status_enu_t getIntegerResources(const ComRef& cref, int& value, bool externalInput, oms_modelState_enu_t modelState);
79  oms_status_enu_t getRealResources(const ComRef& cref, double& value, bool externalInput, oms_modelState_enu_t modelState);
80  oms_status_enu_t getStringResources(const ComRef& cref, std::string& value, bool externalInput, oms_modelState_enu_t modelState);
81 
82  oms_status_enu_t getBooleanFromModeldescription(const ComRef& cref, bool& value);
84  oms_status_enu_t getRealFromModeldescription(const ComRef& cref, double& value);
85  oms_status_enu_t getStringFromModeldescription(const ComRef& cref, std::string& value);
86 
87  std::string getUnit(ComRef& cref) const;
88  std::string getUnitFromModeldescription(ComRef& cref) const;
89 
90  oms_status_enu_t exportToSSD(pugi::xml_node& node) const;
91  oms_status_enu_t importFromSnapshot(const pugi::xml_node& node, const std::string& sspVersion, const Snapshot& snapshot, std::string variantName);
92  oms_status_enu_t importFromSnapshot(const Snapshot& snapshot, const std::string& ssvFilePath, const std::string& ssmFilename);
94  oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(Values& value, const ComRef& owner, std::vector<std::string>& warningList);
96 
97  oms_status_enu_t deleteReferencesInSSD(const std::string& filename);
98  oms_status_enu_t deleteResourcesInSSP(const std::string& filename);
99 
100  oms_status_enu_t exportToSSV(pugi::xml_node& ssvNode) const;
101 
102  oms_status_enu_t exportUnitDefinitions(Snapshot &snapshot, std::string filename, std::string variantName) const;
103  oms_status_enu_t exportUnitDefinitionsToSSVTemplate(Snapshot &snapshot, std::string filename);
104  void importUnitDefinitions(const pugi::xml_node& node);
105 
106  void exportToSSVTemplate(pugi::xml_node& ssvNode, const ComRef& cref);
107  void exportReduceSSV(pugi::xml_node& ssvNode, const ComRef& cref);
108 
109  oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode, const ComRef& cref);
110 
111  oms_status_enu_t parseModelDescription(const filesystem::path& root, std::string& guid_);
112  oms_status_enu_t rename(const oms::ComRef& oldCref, const oms::ComRef& newCref);
113  oms_status_enu_t renameInResources(const oms::ComRef& oldCref, const oms::ComRef& newCref);
114 
115  void exportParameterBindings(pugi::xml_node& node, Snapshot& snapshot, std::string variantName) const;
116 
117  bool hasResources();
118 
119  private:
120  oms_status_enu_t exportStartValuesHelper(pugi::xml_node& node) const;
121  void exportParameterMappingInline(pugi::xml_node& node) const;
122  void exportParameterMappingToSSM(pugi::xml_node& node) const;
123  oms_status_enu_t importStartValuesHelper(const pugi::xml_node& parameters);
124 
125  void parseModelStructureDependencies(std::string &dependencies, std::vector<int>& dependencyList);
126 
127  void importParameterMapping(const pugi::xml_node& parameterMapping);
128  oms::ComRef getMappedCrefEntry(const ComRef& cref) const;
129  bool isEntryReferencedInSSM(const ComRef& cref) const;
130  bool empty() const;
131 
132  public:
133  std::map<ComRef, bool> booleanStartValues;
134  std::map<ComRef, double> realStartValues;
135  std::map<ComRef, int> integerStartValues;
136  std::map<ComRef, std::string> stringStartValues;
137 
138  std::map<ComRef, bool> booleanValues;
139  std::map<ComRef, double> realValues;
140  std::map<ComRef, int> integerValues;
141  std::map<ComRef, std::string> stringValues;
142 
143  std::map<ComRef, bool> modelDescriptionBooleanStartValues;
144  std::map<ComRef, double> modelDescriptionRealStartValues;
145  std::map<ComRef, int> modelDescriptionIntegerStartValues;
146  std::map<ComRef, std::string> modelDescriptionStringStartValues;
147 
148  std::map<int, std::vector<int>> modelStructureOutputs;
149  std::map<int, std::vector<int>> modelStructureDerivatives;
150  std::map<int, std::vector<int>> modelStructureInitialUnknowns;
151 
152  std::map<ComRef, std::string> modelDescriptionVariableUnits;
153  std::map<ComRef, std::string> variableUnits;
154 
156  {
157  std::string unitName;
158  std::string unitValue;
159  std::map<std::string, std::string> baseUnit;
161  };
162  std::vector<unitDefinitionsToExport> unitDefinitionsToExportInSSP;
163 
164  std::map<std::string, std::map<std::string, std::string>> modeldescriptionUnitDefinitions;
165 
166  std::multimap<ComRef, ComRef> mappedEntry;
167 
168  std::vector<Values> parameterResources;
169  std::map<std::string, Values> allresources;
170  std::string ssmFile = "";
171  bool linkResources = true;
172  };
173 }
174 
175 #endif
std::map< ComRef, std::string > modelDescriptionVariableUnits
variable units read from modeldescription.xml
Definition: Values.h:152
oms_status_enu_t exportUnitDefinitions(Snapshot &snapshot, std::string filename, std::string variantName) const
Definition: Values.cpp:919
std::map< ComRef, std::string > variableUnits
variable units set by user
Definition: Values.h:153
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:1343
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition: Values.cpp:769
std::map< ComRef, bool > modelDescriptionBooleanStartValues
start values read from modelDescription.xml
Definition: Values.h:143
std::map< ComRef, std::string > modelDescriptionStringStartValues
start values read from modelDescription.xml
Definition: Values.h:146
oms_status_enu_t setString(const ComRef &cref, const std::string &value)
Definition: Values.cpp:112
std::map< ComRef, bool > booleanStartValues
parameters and start values defined before instantiating the FMU
Definition: Values.h:133
std::string unitValue
Definition: Values.h:158
std::vector< unitDefinitionsToExport > unitDefinitionsToExportInSSP
list of unitDefinitions to be exported in ssp
Definition: Values.h:162
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:276
std::string getUnitFromModeldescription(ComRef &cref) const
Definition: Values.cpp:567
oms_status_enu_t deleteReferencesInSSD(const std::string &filename)
Definition: Values.cpp:752
oms_status_enu_t getString(const ComRef &cref, std::string &value)
Definition: Values.cpp:202
void updateModelDescriptionRealStartValue(const ComRef &cref, double value)
Definition: Values.cpp:119
std::map< std::string, std::map< std::string, std::string > > modeldescriptionUnitDefinitions
<UnitDefinitions> list read from modeldescription.xml
Definition: Values.h:164
std::string getUnit(ComRef &cref) const
Definition: Values.cpp:557
oms_status_enu_t getStringResources(const ComRef &cref, std::string &value, bool externalInput, oms_modelState_enu_t modelState)
Definition: Values.cpp:502
oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition: Values.cpp:190
oms_status_enu_t deleteStartValueInResources(const ComRef &cref)
Definition: Values.cpp:714
bool empty() const
Definition: Values.cpp:904
std::map< ComRef, double > modelDescriptionRealStartValues
start values read from modelDescription.xml
Definition: Values.h:144
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition: Values.cpp:105
oms_status_enu_t renameInResources(const oms::ComRef &oldCref, const oms::ComRef &newCref)
Definition: Values.cpp:1685
oms_status_enu_t getRealResources(const ComRef &cref, double &value, bool externalInput, oms_modelState_enu_t modelState)
Definition: Values.cpp:415
oms_status_enu_t setUnit(const ComRef &cref, const std::string &value)
Definition: Values.cpp:172
void exportParameterBindings(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const
Definition: Values.cpp:1071
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition: Values.cpp:214
oms_status_enu_t exportUnitDefinitionsToSSVTemplate(Snapshot &snapshot, std::string filename)
Definition: Values.cpp:960
std::map< int, std::vector< int > > modelStructureDerivatives
derivatives and its dependencies from <ModelStructure>
Definition: Values.h:149
std::string ssmFile
mapped ssm files associated with ssv files;
Definition: Values.h:170
std::map< ComRef, bool > booleanValues
input values defined after initialization
Definition: Values.h:138
void copyModelDescriptionUnitToResources(Values &value)
Definition: Values.cpp:160
oms_status_enu_t
Definition: Types.h:43
std::string unitName
Definition: Values.h:157
std::map< ComRef, std::string > stringStartValues
parameters and start values defined before instantiating the FMU
Definition: Values.h:136
std::vector< Values > parameterResources
list of parameter resources provided inline or .ssv files
Definition: Values.h:168
void exportParameterMappingToSSM(pugi::xml_node &node) const
Definition: Values.cpp:1216
void exportReduceSSV(pugi::xml_node &ssvNode, const ComRef &cref)
reduced SSV file which contains only the referenced crefs in parametermapping
Definition: Values.cpp:1274
oms_status_enu_t importStartValuesHelper(const pugi::xml_node &parameters)
Definition: Values.cpp:1376
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition: Values.cpp:54
std::map< ComRef, double > realStartValues
parameters and start values defined before instantiating the FMU
Definition: Values.h:134
oms_status_enu_t exportToSSV(pugi::xml_node &ssvNode) const
Definition: Values.cpp:909
std::map< ComRef, std::string > stringValues
input values defined after initialization
Definition: Values.h:141
oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition: Values.cpp:603
oms_status_enu_t setUnitResources(const ComRef &cref, const std::string &value, const ComRef &fullCref)
Definition: Values.cpp:310
std::map< ComRef, int > integerValues
input values defined after initialization
Definition: Values.h:140
oms_status_enu_t getBooleanFromModeldescription(const ComRef &cref, bool &value)
Definition: Values.cpp:590
oms_modelState_enu_t
Definition: Types.h:52
oms_status_enu_t setIntegerResources(const ComRef &cref, int value, const ComRef &fullCref, bool externalInput, oms_modelState_enu_t modelState)
Definition: Values.cpp:341
Definition: Snapshot.h:46
std::map< std::string, std::string > baseUnit
Definition: Values.h:159
void updateModelDescriptionBooleanStartValue(const ComRef &cref, bool value)
Definition: Values.cpp:135
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition: Values.cpp:98
void parseModelStructureDependencies(std::string &dependencies, std::vector< int > &dependencyList)
Definition: Values.cpp:1595
oms_status_enu_t getRealFromModeldescription(const ComRef &cref, double &value)
Definition: Values.cpp:531
ComRef - component reference.
Definition: ComRef.h:46
std::map< ComRef, int > modelDescriptionIntegerStartValues
start values read from modelDescription.xml
Definition: Values.h:145
const char * parameters
Definition: Tags.cpp:80
void importUnitDefinitions(const pugi::xml_node &node)
Definition: Values.cpp:1456
void updateModelDescriptionVariableUnit(const ComRef &cref, const std::string &value)
Definition: Values.cpp:151
oms_status_enu_t setRealResources(const ComRef &cref, double value, const ComRef &fullCref, bool externalInput, oms_modelState_enu_t modelState)
Definition: Values.cpp:238
oms_status_enu_t getStringFromModeldescription(const ComRef &cref, std::string &value)
Definition: Values.cpp:544
oms_status_enu_t setBooleanResources(const ComRef &cref, bool value, const ComRef &fullCref, bool externalInput, oms_modelState_enu_t modelState)
Definition: Values.cpp:378
oms_status_enu_t getBooleanResources(const ComRef &cref, bool &value, bool externalInput, oms_modelState_enu_t modelState)
Definition: Values.cpp:473
oms_status_enu_t parseModelDescription(const filesystem::path &root, std::string &guid_)
path without the filename, i.e. modelDescription.xml
Definition: Values.cpp:1474
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:166
bool hasResources()
returns if the system or subsystem or submodule have parameter resources either as ssv or inline ...
Definition: Values.cpp:1752
Definition: Values.h:45
~Values()
Definition: Values.cpp:50
std::map< int, std::vector< int > > modelStructureInitialUnknowns
initialUnknowns and its dependencies from <ModelStructure>
Definition: Values.h:150
void setUnitDefinitions(const ComRef &cref)
Definition: Values.cpp:65
oms_status_enu_t getIntegerFromModeldescription(const ComRef &cref, int &value)
Definition: Values.cpp:577
void updateModelDescriptionStringStartValue(const ComRef &cref, std::string value)
Definition: Values.cpp:143
Definition: AlgLoop.h:44
std::map< std::string, Values > allresources
mapped resources either inline or ssv
Definition: Values.h:169
bool isEntryReferencedInSSM(const ComRef &cref) const
Definition: Values.cpp:1185
Values()
Definition: Values.cpp:46
oms_status_enu_t getIntegerResources(const ComRef &cref, int &value, bool externalInput, oms_modelState_enu_t modelState)
Definition: Values.cpp:444
bool exportUnit
Definition: Values.h:160
void importParameterMapping(const pugi::xml_node &parameterMapping)
Definition: Values.cpp:1606
std::map< ComRef, int > integerStartValues
parameters and start values defined before instantiating the FMU
Definition: Values.h:135
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition: Values.cpp:226
oms::ComRef getMappedCrefEntry(const ComRef &cref) const
Definition: Values.cpp:1172
oms_status_enu_t exportStartValuesHelper(pugi::xml_node &node) const
Definition: Values.cpp:1005
void exportParameterMappingInline(pugi::xml_node &node) const
Definition: Values.cpp:1200
void updateModelDescriptionIntegerStartValue(const ComRef &cref, int value)
Definition: Values.cpp:127
oms_status_enu_t rename(const oms::ComRef &oldCref, const oms::ComRef &newCref)
Definition: Values.cpp:1623
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(Values &value, const ComRef &owner, std::vector< std::string > &warningList)
Definition: Values.cpp:635
oms_status_enu_t exportToSSD(pugi::xml_node &node) const
Definition: Values.cpp:787
std::map< ComRef, double > realValues
input values defined after initialization
Definition: Values.h:139
void exportToSSVTemplate(pugi::xml_node &ssvNode, const ComRef &cref)
start values read from modelDescription.xml and creates a ssv template
Definition: Values.cpp:1232
Definition: Values.h:155
void getFilteredUnitDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string >> &unitDefinitions)
Definition: Values.cpp:85
oms_status_enu_t importFromSnapshot(const pugi::xml_node &node, const std::string &sspVersion, const Snapshot &snapshot, std::string variantName)
Definition: Values.cpp:834
bool linkResources
Definition: Values.h:171
std::map< int, std::vector< int > > modelStructureOutputs
output and its dependencies from <ModelStructure>
Definition: Values.h:148