OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment that supports ordinary (i.e., non-delayed) and TLM connections.
ComponentTable.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_TABLE_H_
33 #define _OMS_COMPONENT_TABLE_H_
34 
35 #include "Component.h"
36 #include "ComRef.h"
37 #include "ResultReader.h"
38 #include "ResultWriter.h"
39 #include "SignalDerivative.h"
40 #include "Snapshot.h"
41 #include <map>
42 #include <pugixml.hpp>
43 #include <string>
44 #include <unordered_map>
45 #include <vector>
46 
47 namespace oms
48 {
49  class ComponentTable : public Component
50  {
51  public:
53 
54  static Component* NewComponent(const oms::ComRef& cref, System* parentSystem, const std::string& path);
55  static Component* NewComponent(const pugi::xml_node& node, System* parentSystem, const std::string& sspVersion, const Snapshot& snapshot);
56 
57  oms_status_enu_t exportToSSD(pugi::xml_node& node, Snapshot& snapshot, std::string variantName) const;
58  oms_status_enu_t exportToSSVTemplate(pugi::xml_node& ssvNode) {return oms_status_ok;}
59  oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode) {return oms_status_ok;}
60  oms_status_enu_t instantiate();
61  oms_status_enu_t initialize() {return oms_status_ok;}
62  oms_status_enu_t terminate() {return oms_status_ok;}
63  oms_status_enu_t reset();
64 
65  oms_status_enu_t stepUntil(double stopTime) {time = stopTime; return oms_status_ok;}
66 
68  oms_status_enu_t getReal(const ComRef& cref, double& value);
69  oms_status_enu_t getRealOutputDerivative(const ComRef& cref, SignalDerivative& value);
70  oms_status_enu_t getInteger(const ComRef& cref, int& value);
71  oms_status_enu_t getBoolean(const ComRef& cref, bool& value);
72 
73  oms_status_enu_t registerSignalsForResultFile(ResultWriter& resultFile);
74  oms_status_enu_t updateSignals(ResultWriter& resultWriter);
75  oms_status_enu_t addSignalsToResults(const char* regex);
76  oms_status_enu_t removeSignalsFromResults(const char* regex);
77 
78  bool getCanGetAndSetState() {return true;}
79  oms_status_enu_t saveState();
80  oms_status_enu_t freeState();
81  oms_status_enu_t restoreState();
82 
83  void getFilteredSignals(std::vector<Connector>& filteredSignals) const;
84 
85  protected:
86  ComponentTable(const ComRef& cref, System* parentSystem, const std::string& path);
87 
88  // stop the compiler generating methods copying the object
89  ComponentTable(ComponentTable const& copy);
91 
92  private:
94  std::unordered_map<ComRef, ResultReader::Series*> series;
95  std::unordered_map<ComRef, bool> exportSeries;
96  std::unordered_map<unsigned int /*result file var ID*/, unsigned int /*allVariables ID*/> resultFileMapping;
97  double time;
98  double storedTime;
99  size_t lastIndex = 0;
100  };
101 }
102 
103 #endif
oms
Definition: AlgLoop.h:44
System.h
oms::ComponentTable::ComponentTable
ComponentTable(const ComRef &cref, System *parentSystem, const std::string &path)
Definition: ComponentTable.cpp:42
oms::Component::cref
ComRef cref
Definition: Component.h:166
oms::ComponentTable::resultReader
ResultReader * resultReader
Definition: ComponentTable.h:93
oms::SignalDerivative
Definition: SignalDerivative.h:41
ComRef.h
oms::ComponentTable::time
double time
Definition: ComponentTable.h:97
oms::ComponentTable::operator=
ComponentTable & operator=(ComponentTable const &copy)
not implemented
oms::System::getUniqueID
std::string getUniqueID() const
Definition: System.cpp:2902
Model.h
oms::ComponentTable::exportToSSD
oms_status_enu_t exportToSSD(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const
Definition: ComponentTable.cpp:164
oms::ComRef
ComRef - component reference.
Definition: ComRef.h:46
oms::ComponentTable::lastIndex
size_t lastIndex
Definition: ComponentTable.h:99
oms::ResultReader::deleteSeries
static void deleteSeries(Series **series)
Definition: ResultReader.cpp:67
oms::ssp::Draft20180219::ssd::component
const char * component
Definition: Tags.cpp:45
oms::Component::parentSystem
System * parentSystem
Definition: Component.h:165
logError_NotImplemented
#define logError_NotImplemented
Definition: Logging.h:141
oms::ResultReader
Definition: ResultReader.h:40
oms::ComponentTable::series
std::unordered_map< ComRef, ResultReader::Series * > series
Definition: ComponentTable.h:94
Snapshot.h
oms::ComponentTable::resultFileMapping
std::unordered_map< unsigned int, unsigned int > resultFileMapping
Definition: ComponentTable.h:96
oms::ComponentTable
Definition: ComponentTable.h:49
logError_InternalError
#define logError_InternalError
Definition: Logging.h:132
oms::SignalType_REAL
@ SignalType_REAL
Definition: ResultWriter.h:43
oms::ComponentTable::getFilteredSignals
void getFilteredSignals(std::vector< Connector > &filteredSignals) const
Definition: ComponentTable.cpp:435
oms::ComRef::isValidIdent
static bool isValidIdent(const std::string &ident)
Definition: ComRef.cpp:89
Tags.h
oms::SignalValue_t::realValue
double realValue
Definition: ResultWriter.h:50
oms::ComponentTable::updateSignals
oms_status_enu_t updateSignals(ResultWriter &resultWriter)
Definition: ComponentTable.cpp:372
oms::ComponentTable::getInteger
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition: ComponentTable.cpp:235
oms::System::copyResources
bool copyResources()
Definition: System.cpp:1984
oms::ComponentTable::~ComponentTable
~ComponentTable()
Definition: ComponentTable.cpp:47
oms::ComponentTable::removeSignalsFromResults
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition: ComponentTable.cpp:403
oms::ssp::Draft20180219::ssd::connector
const char * connector
Definition: Tags.cpp:49
SignalDerivative.h
oms::ComponentTable::getVariable
Variable * getVariable(const ComRef &cref)
Definition: ComponentTable.h:67
oms_copy_file
void oms_copy_file(const filesystem::path &from, const filesystem::path &to)
Definition: OMSFileSystem.cpp:89
oms::Model::getTempDirectory
std::string getTempDirectory() const
Definition: Model.h:68
oms::Connector::NewConnector
static Connector * NewConnector(const pugi::xml_node &node, const std::string &sspVersion, const oms::ComRef &owner)
Definition: Connector.cpp:124
oms::SignalValue_t
Definition: ResultWriter.h:48
oms::ResultReader::Series
Definition: ResultReader.h:43
oms::Component
Definition: Component.h:59
oms::ComponentTable::getReal
oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition: ComponentTable.cpp:193
oms::ComponentTable::freeState
oms_status_enu_t freeState()
Definition: ComponentTable.cpp:424
oms::ComponentTable::stepUntil
oms_status_enu_t stepUntil(double stopTime)
Definition: ComponentTable.h:65
oms::ResultReader::Series::time
double * time
Definition: ResultReader.h:46
oms::ResultReader::Series::length
unsigned int length
Definition: ResultReader.h:45
oms::ssd::ElementGeometry
Definition: ElementGeometry.h:45
ResultWriter.h
oms::Snapshot
Definition: Snapshot.h:46
oms::ComponentTable::getCanGetAndSetState
bool getCanGetAndSetState()
Definition: ComponentTable.h:78
oms::ComponentTable::registerSignalsForResultFile
oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)
Definition: ComponentTable.cpp:355
Component.h
oms::ResultWriter
Definition: ResultWriter.h:68
oms::System::getModel
Model & getModel()
Definition: System.cpp:1796
oms::ssp::Draft20180219::ssd::connectors
const char * connectors
Definition: Tags.cpp:51
oms::ComponentTable::storedTime
double storedTime
Definition: ComponentTable.h:98
logError_WrongSchema
#define logError_WrongSchema(name)
Definition: Logging.h:156
oms::ComponentTable::addSignalsToResults
oms_status_enu_t addSignalsToResults(const char *regex)
Definition: ComponentTable.cpp:388
oms::ComponentTable::exportToSSMTemplate
oms_status_enu_t exportToSSMTemplate(pugi::xml_node &ssmNode)
Definition: ComponentTable.h:59
oms::System
Definition: System.h:65
oms::ResultWriter::updateSignal
void updateSignal(unsigned int id, SignalValue_t value)
Definition: ResultWriter.cpp:120
oms::ssd::ElementGeometry::importFromSSD
oms_status_enu_t importFromSSD(const pugi::xml_node &node)
Definition: ElementGeometry.cpp:166
oms::ComRef::c_str
const char * c_str() const
Definition: ComRef.h:75
logError
#define logError(msg)
Definition: Logging.h:102
oms::ComponentTable::reset
oms_status_enu_t reset()
Definition: ComponentTable.cpp:187
oms::ComponentTable::getRealOutputDerivative
oms_status_enu_t getRealOutputDerivative(const ComRef &cref, SignalDerivative &value)
Definition: ComponentTable.cpp:317
oms::ResultReader::Series::value
double * value
Definition: ResultReader.h:47
oms::ResultWriter::addSignal
unsigned int addSignal(const ComRef &name, const std::string &description, SignalType_t type)
Definition: ResultWriter.cpp:50
oms::ComponentTable::instantiate
oms_status_enu_t instantiate()
Definition: ComponentTable.cpp:181
oms::ComponentTable::exportSeries
std::unordered_map< ComRef, bool > exportSeries
Definition: ComponentTable.h:95
oms::ComponentTable::saveState
oms_status_enu_t saveState()
Definition: ComponentTable.cpp:418
oms::ComponentTable::NewComponent
static Component * NewComponent(const oms::ComRef &cref, System *parentSystem, const std::string &path)
Definition: ComponentTable.cpp:57
ComponentTable.h
oms::Variable
Definition: Variable.h:45
oms::Connector
Connector.
Definition: Connector.h:49
Logging.h
oms::ComponentTable::getBoolean
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition: ComponentTable.cpp:276
oms::ComponentTable::restoreState
oms_status_enu_t restoreState()
Definition: ComponentTable.cpp:429
oms::ResultReader::newReader
static ResultReader * newReader(const char *filename)
Definition: ResultReader.cpp:50
OMSFileSystem.h
logError_InvalidIdent
#define logError_InvalidIdent(cref)
Definition: Logging.h:134
oms::ssp::Draft20180219::signal
const char * signal
Definition: Tags.cpp:38
ResultReader.h
oms::ComponentTable::exportToSSVTemplate
oms_status_enu_t exportToSSVTemplate(pugi::xml_node &ssvNode)
Definition: ComponentTable.h:58
oms::ComponentTable::terminate
oms_status_enu_t terminate()
Definition: ComponentTable.h:62
oms::ComponentTable::initialize
oms_status_enu_t initialize()
Definition: ComponentTable.h:61
oms::ssp::Draft20180219::ssd::element_geometry
const char * element_geometry
Definition: Tags.cpp:53
oms::Component::path
std::string path
resource file (fmu, mat)
Definition: Component.h:168