OMSimulatorLib The OMSimulator project is a FMI-based co-simulation environment.

Loading...
Searching...
No Matches
Component.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_COMPONENT_H_
33#define _OMS_COMPONENT_H_
34
35#include "Clock.h"
36#include "ComRef.h"
37#include "Connector.h"
38#include "DirectedGraph.h"
39#include "Element.h"
40#include "FMUInfo.h"
41#include "Logging.h"
42#include "ResultWriter.h"
43#include "SignalDerivative.h"
44#include "Snapshot.h"
45#include "OMSimulator/Types.h"
46#include "Values.h"
47
48#include <fmi4c.h>
49#include <pugixml.hpp>
50
51 namespace oms
52{
53 class System;
54 class Model;
55 class Variable;
56
57 void fmi2logger(fmi2ComponentEnvironment env, fmi2String instanceName, fmi2Status status, fmi2String category, fmi2String message, ...);
58 void fmi3logger(fmi3InstanceEnvironment env, fmi3Status status, fmi3String category, fmi3String message);
59 class Component
60 {
61 public:
62 virtual ~Component();
63
64 virtual oms_status_enu_t addSignalsToResults(const char* regex) = 0;
65 virtual oms_status_enu_t exportToSSD(pugi::xml_node& node, Snapshot& snapshot, std::string variantName) const = 0;
66 virtual oms_status_enu_t exportToSSV(pugi::xml_node& ssvNode) { return logError_NotImplemented; }
67 virtual void getFilteredUnitDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& unitDefinitions) { return ; }
68 virtual void getFilteredEnumerationDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& enumerationDefinitions) { return ; }
69
70 virtual oms_status_enu_t initialize() = 0;
71 virtual oms_status_enu_t instantiate() = 0;
72 virtual oms_status_enu_t registerSignalsForResultFile(ResultWriter& resultFile) = 0;
73 virtual oms_status_enu_t removeSignalsFromResults(const char* regex) = 0;
74 virtual oms_status_enu_t reset() = 0;
75 virtual oms_status_enu_t terminate() = 0;
76 virtual oms_status_enu_t updateSignals(ResultWriter& resultWriter) = 0;
77 virtual Variable* getVariable(const ComRef& cref) = 0;
78
79 virtual bool getCanGetAndSetState() { return false; }
80 virtual const FMUInfo* getFMUInfo() const { return nullptr; }
81 virtual oms_status_enu_t deleteStartValue(const ComRef& cref) { return oms_status_ok; }
82 virtual std::vector<Values> getValuesResources() { return{}; }
83 virtual Values& getValues() {return values;}
84 virtual oms_status_enu_t setValuesResources(Values& values) { return oms_status_ok; }
85 virtual oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector<std::string> &warningList) { return oms_status_ok; }
86 virtual oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode) { return logError_NotImplemented; }
87 virtual oms_status_enu_t exportToSSVTemplate(pugi::xml_node& ssvNode, Snapshot& snapshot) { return logError_NotImplemented; }
88 virtual oms_status_enu_t freeState() { return logError_NotImplemented; }
89 virtual oms_status_enu_t getBoolean(const ComRef& cref, bool& value) { return logError_NotImplemented; }
90 virtual oms_status_enu_t getInteger(const ComRef& cref, int& value) { return logError_NotImplemented; }
91 virtual oms_status_enu_t getReal(const ComRef& cref, double& value) { return logError_NotImplemented; }
92 virtual oms_status_enu_t getString(const ComRef& cref, std::string& value) { return logError_NotImplemented; }
93 virtual oms_status_enu_t getRealOutputDerivative(const ComRef& cref, SignalDerivative& der) { return logError_NotImplemented; }
94 virtual oms_status_enu_t getDirectionalDerivative(const ComRef& unknownCref, const ComRef& knownCref, double& value) { return logError_NotImplemented; }
95 virtual oms_status_enu_t restoreState() { return logError_NotImplemented; }
96 virtual oms_status_enu_t saveState() { return logError_NotImplemented; }
97 virtual oms_status_enu_t setBoolean(const ComRef& cref, bool value) { return logError_NotImplemented; }
98 virtual oms_status_enu_t setInteger(const ComRef& cref, int value) { return logError_NotImplemented; }
99 virtual oms_status_enu_t setReal(const ComRef& cref, double value) { return logError_NotImplemented; }
100 virtual oms_status_enu_t setString(const ComRef& cref, const std::string& value) { return logError_NotImplemented; }
101 virtual oms_status_enu_t setUnit(const ComRef& cref, const std::string& value) { return logError_NotImplemented; }
102 virtual oms_status_enu_t setRealInputDerivative(const ComRef& cref, const SignalDerivative& der) { return logError_NotImplemented; }
103 virtual oms_status_enu_t stepUntil(double stopTime) { return logError_NotImplemented; }
104 virtual oms_status_enu_t setTime(double time) { return logError_NotImplemented; }
105 virtual oms_status_enu_t setExportName(const std::string & exportName) { return oms_status_ok; }
106 virtual oms_status_enu_t newResources(const std::string& ssvFileName, const std::string& ssmFileName, bool externalResources) { return logError_NotImplemented; }
107 virtual oms_status_enu_t addResources(std::string& filename) { return logError_NotImplemented; }
108 virtual oms_status_enu_t deleteReferencesInSSD(const std::string& filename) {return logError_NotImplemented;}
109 virtual oms_status_enu_t deleteResourcesInSSP(const std::string& filename) {return logError_NotImplemented;}
110
111 const ComRef& getCref() const { return cref; }
112 ComRef getFullCref() const;
113 Element* getElement() { return &element; }
114 Connector* getConnector(const ComRef& cref);
115 Connector** getConnectors() { return &connectors[0]; }
116 oms_status_enu_t deleteConnector(const ComRef& cref);
117 void getAllResources(std::vector<std::string>& resources) const { resources.push_back(path); }
118 const std::string& getPath() const { return path; }
119 const std::string& getTempDir() const { return tempDir; }
120 void setPath(const std::string& newPath) { this->path = newPath; }
121 void setTempDir(const std::string& tempDir) { this->tempDir = tempDir; }
122 oms_component_enu_t getType() const { return type; }
123 System* getParentSystem() const { return parentSystem; }
124 Model& getModel() const;
125 void setGeometry(const ssd::ElementGeometry& geometry) { element.setGeometry(&geometry); }
126
127 const DirectedGraph& getInitialUnknownsGraph() { return initialUnknownsGraph; }
128 const DirectedGraph& getOutputsGraph() { return outputsGraph; }
129
130 oms_status_enu_t rename(const ComRef& newCref);
131
132 virtual void getFilteredSignals(std::vector<Connector>& filteredSignals) const = 0;
133
134 protected:
135 Component(const ComRef& cref, oms_component_enu_t type, System* parentSystem, const std::string& path);
136
137 // stop the compiler generating methods copying the object
138 Component(Component const&);
139 Component& operator=(Component const&);
140
141 virtual oms_status_enu_t renameValues(const ComRef& oldCref, const ComRef& newCref) { return oms_status_ok; }
142
143 protected:
144 DirectedGraph initialUnknownsGraph;
145 DirectedGraph outputsGraph;
146 Element element;
147 std::vector<Connector*> connectors;
148
149 Clock clock;
150 unsigned int clock_id;
151
152 private:
153 System* parentSystem;
154 ComRef cref;
155 oms_component_enu_t type;
156 std::string path;
157 std::string tempDir;
158 Values values;
159 };
160}
161
162#endif
Clock.h
ComRef.h
Connector.h
DirectedGraph.h
Element.h
FMUInfo.h
Logging.h
logError_NotImplemented
#define logError_NotImplemented
Definition Logging.h:107
ResultWriter.h
SignalDerivative.h
Snapshot.h
Values.h
Clock
Definition Clock.h:39
oms::ComRef
ComRef - component reference.
Definition ComRef.h:47
oms::Component
Definition Component.h:60
oms::Component::deleteConnector
oms_status_enu_t deleteConnector(const ComRef &cref)
Definition Component.cpp:158
oms::Component::tempDir
std::string tempDir
unzipped fmu
Definition Component.h:157
oms::Component::setReal
virtual oms_status_enu_t setReal(const ComRef &cref, double value)
Definition Component.h:99
oms::Component::getCref
const ComRef & getCref() const
Definition Component.h:111
oms::Component::setExportName
virtual oms_status_enu_t setExportName(const std::string &exportName)
Definition Component.h:105
oms::Component::element
Element element
Definition Component.h:146
oms::Component::freeState
virtual oms_status_enu_t freeState()
Definition Component.h:88
oms::Component::restoreState
virtual oms_status_enu_t restoreState()
Definition Component.h:95
oms::Component::setString
virtual oms_status_enu_t setString(const ComRef &cref, const std::string &value)
Definition Component.h:100
oms::Component::setValuesResources
virtual oms_status_enu_t setValuesResources(Values &values)
Definition Component.h:84
oms::Component::path
std::string path
resource file (fmu, mat)
Definition Component.h:156
oms::Component::getValuesResources
virtual std::vector< Values > getValuesResources()
Definition Component.h:82
oms::Component::getCanGetAndSetState
virtual bool getCanGetAndSetState()
Definition Component.h:79
oms::Component::deleteStartValue
virtual oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition Component.h:81
oms::Component::connectors
std::vector< Connector * > connectors
Definition Component.h:147
oms::Component::getValues
virtual Values & getValues()
Definition Component.h:83
oms::Component::cref
ComRef cref
Definition Component.h:154
oms::Component::deleteResourcesInSSP
virtual oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition Component.h:109
oms::Component::getDirectionalDerivative
virtual oms_status_enu_t getDirectionalDerivative(const ComRef &unknownCref, const ComRef &knownCref, double &value)
Definition Component.h:94
oms::Component::getFilteredUnitDefinitionsToSSD
virtual void getFilteredUnitDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &unitDefinitions)
Definition Component.h:67
oms::Component::getInteger
virtual oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition Component.h:90
oms::Component::setTempDir
void setTempDir(const std::string &tempDir)
Definition Component.h:121
oms::Component::setTime
virtual oms_status_enu_t setTime(double time)
Definition Component.h:104
oms::Component::getVariable
virtual Variable * getVariable(const ComRef &cref)=0
oms::Component::setPath
void setPath(const std::string &newPath)
Definition Component.h:120
oms::Component::addResources
virtual oms_status_enu_t addResources(std::string &filename)
Definition Component.h:107
oms::Component::getBoolean
virtual oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition Component.h:89
oms::Component::removeSignalsFromResults
virtual oms_status_enu_t removeSignalsFromResults(const char *regex)=0
oms::Component::getString
virtual oms_status_enu_t getString(const ComRef &cref, std::string &value)
Definition Component.h:92
oms::Component::clock_id
unsigned int clock_id
Definition Component.h:150
oms::Component::setInteger
virtual oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition Component.h:98
oms::Component::clock
Clock clock
Definition Component.h:149
oms::Component::initialize
virtual oms_status_enu_t initialize()=0
oms::Component::getType
oms_component_enu_t getType() const
Definition Component.h:122
oms::Component::newResources
virtual oms_status_enu_t newResources(const std::string &ssvFileName, const std::string &ssmFileName, bool externalResources)
Definition Component.h:106
oms::Component::getElement
Element * getElement()
Definition Component.h:113
oms::Component::getOutputsGraph
const DirectedGraph & getOutputsGraph()
Definition Component.h:128
oms::Component::setUnit
virtual oms_status_enu_t setUnit(const ComRef &cref, const std::string &value)
Definition Component.h:101
oms::Component::saveState
virtual oms_status_enu_t saveState()
Definition Component.h:96
oms::Component::exportToSSVTemplate
virtual oms_status_enu_t exportToSSVTemplate(pugi::xml_node &ssvNode, Snapshot &snapshot)
Definition Component.h:87
oms::Component::getInitialUnknownsGraph
const DirectedGraph & getInitialUnknownsGraph()
Definition Component.h:127
oms::Component::getConnector
Connector * getConnector(const ComRef &cref)
Definition Component.cpp:149
oms::Component::terminate
virtual oms_status_enu_t terminate()=0
oms::Component::parentSystem
System * parentSystem
Definition Component.h:153
oms::Component::exportToSSMTemplate
virtual oms_status_enu_t exportToSSMTemplate(pugi::xml_node &ssmNode)
Definition Component.h:86
oms::Component::operator=
Component & operator=(Component const &)
not implemented
oms::Component::values
Values values
Definition Component.h:158
oms::Component::stepUntil
virtual oms_status_enu_t stepUntil(double stopTime)
Definition Component.h:103
oms::Component::addSignalsToResults
virtual oms_status_enu_t addSignalsToResults(const char *regex)=0
oms::Component::deleteReferencesInSSD
virtual oms_status_enu_t deleteReferencesInSSD(const std::string &filename)
Definition Component.h:108
oms::Component::registerSignalsForResultFile
virtual oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)=0
oms::Component::getFullCref
ComRef getFullCref() const
Definition Component.cpp:139
oms::Component::setRealInputDerivative
virtual oms_status_enu_t setRealInputDerivative(const ComRef &cref, const SignalDerivative &der)
Definition Component.h:102
oms::Component::renameValues
virtual oms_status_enu_t renameValues(const ComRef &oldCref, const ComRef &newCref)
Definition Component.h:141
oms::Component::initialUnknownsGraph
DirectedGraph initialUnknownsGraph
Definition Component.h:144
oms::Component::getParentSystem
System * getParentSystem() const
Definition Component.h:123
oms::Component::getFilteredEnumerationDefinitionsToSSD
virtual void getFilteredEnumerationDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &enumerationDefinitions)
Definition Component.h:68
oms::Component::exportToSSD
virtual oms_status_enu_t exportToSSD(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const =0
oms::Component::getReal
virtual oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition Component.h:91
oms::Component::getFilteredSignals
virtual void getFilteredSignals(std::vector< Connector > &filteredSignals) const =0
oms::Component::reset
virtual oms_status_enu_t reset()=0
oms::Component::outputsGraph
DirectedGraph outputsGraph
Definition Component.h:145
oms::Component::rename
oms_status_enu_t rename(const ComRef &newCref)
rename submodules, e.g., fmu:s
Definition Component.cpp:179
oms::Component::getRealOutputDerivative
virtual oms_status_enu_t getRealOutputDerivative(const ComRef &cref, SignalDerivative &der)
Definition Component.h:93
oms::Component::setBoolean
virtual oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition Component.h:97
oms::Component::instantiate
virtual oms_status_enu_t instantiate()=0
oms::Component::updateOrDeleteStartValueInReplacedComponent
virtual oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector< std::string > &warningList)
Definition Component.h:85
oms::Component::getAllResources
void getAllResources(std::vector< std::string > &resources) const
Definition Component.h:117
oms::Component::Component
Component(Component const &)
not implemented
oms::Component::getModel
Model & getModel() const
Definition Component.cpp:144
oms::Component::type
oms_component_enu_t type
Definition Component.h:155
oms::Component::getFMUInfo
virtual const FMUInfo * getFMUInfo() const
Definition Component.h:80
oms::Component::getConnectors
Connector ** getConnectors()
Definition Component.h:115
oms::Component::getPath
const std::string & getPath() const
Definition Component.h:118
oms::Component::setGeometry
void setGeometry(const ssd::ElementGeometry &geometry)
Definition Component.h:125
oms::Component::exportToSSV
virtual oms_status_enu_t exportToSSV(pugi::xml_node &ssvNode)
Definition Component.h:66
oms::Component::getTempDir
const std::string & getTempDir() const
Definition Component.h:119
oms::Component::updateSignals
virtual oms_status_enu_t updateSignals(ResultWriter &resultWriter)=0
oms::Component::~Component
virtual ~Component()
Definition Component.cpp:132
oms::Connector
Connector.
Definition Connector.h:50
oms::DirectedGraph
Definition DirectedGraph.h:65
oms::Element
Element.
Definition Element.h:47
oms::Element::setGeometry
void setGeometry(const oms::ssd::ElementGeometry *newGeometry)
Definition Element.cpp:66
oms::FMUInfo
FMU info.
Definition FMUInfo.h:45
oms::Model
Definition Model.h:53
oms::ResultWriter
Definition ResultWriter.h:69
oms::SignalDerivative
Definition SignalDerivative.h:42
oms::Snapshot
Definition Snapshot.h:47
oms::System
Definition System.h:62
oms::Values
Definition Values.h:46
oms::Variable
Definition Variable.h:46
oms::ssd::ElementGeometry
Definition ElementGeometry.h:46
oms
Definition AlgLoop.h:45
oms::fmi3logger
void fmi3logger(fmi3InstanceEnvironment env, fmi3Status status, fmi3String category, fmi3String message)
Definition Component.cpp:92
oms::fmi2logger
void fmi2logger(fmi2ComponentEnvironment env, fmi2String instanceName, fmi2Status status, fmi2String category, fmi2String message,...)
Definition Component.cpp:42