OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment that supports ordinary (i.e., non-delayed) and TLM connections.
SystemWC.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_SYSTEM_WC_H_
33 #define _OMS_SYSTEM_WC_H_
34 
35 #include "ComRef.h"
36 #include "DirectedGraph.h"
37 #include "SignalDerivative.h"
38 #include "StepSizeConfiguration.h"
39 #include "System.h"
40 #include "OMSimulator/Types.h"
41 
42 #include <vector>
43 
44 namespace oms
45 {
46  class Model;
47 
48  class SystemWC : public System
49  {
50  public:
51  ~SystemWC();
52 
54  oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node& node) const;
55  oms_status_enu_t importFromSSD_SimulationInformation(const pugi::xml_node& node, const std::string& sspVersion);
56 
57  oms_status_enu_t instantiate();
58  oms_status_enu_t initialize();
59  oms_status_enu_t terminate();
60  oms_status_enu_t reset();
61  oms_status_enu_t doStep();
62  oms_status_enu_t stepUntil(double stopTime);
63  oms_status_enu_t stepUntilASSC(double stopTime);
64 
65  std::string getSolverName() const;
66  oms_status_enu_t setSolverMethod(std::string);
67  oms_status_enu_t setSolver(oms_solver_enu_t solver) {if (solver > oms_solver_wc_min && solver < oms_solver_wc_max) {solverMethod=solver; return oms_status_ok;} return oms_status_error;}
68 
69  oms_status_enu_t getInputs(DirectedGraph& graph, std::vector<double>& inputs);
70  oms_status_enu_t setInputsDer(oms::DirectedGraph& graph, const std::vector<double>& inputsDer);
71  oms_status_enu_t getInputAndOutput(DirectedGraph& graph, std::vector<double>& inputVect,std::vector<double>& outputVect,std::map<ComRef, Component*> FMUcomponents);
72  oms_status_enu_t updateInputs(DirectedGraph& graph);
73 
74  oms_status_enu_t getRealOutputDerivative(const ComRef& cref, SignalDerivative& der);
75  oms_status_enu_t setRealInputDerivative(const ComRef& cref, const SignalDerivative& der);
76  unsigned int getMaxOutputDerivativeOrder();
77 
78  // Functions for configuring assc
81  oms_status_enu_t addStaticValueIndicator(const ComRef& signal, double lowerBound, double upperBound, double stepSize) {return stepSizeConfiguration.addStaticValueIndicator(signal, lowerBound, upperBound, stepSize);}
82  oms_status_enu_t addDynamicValueIndicator(const ComRef& signal,const ComRef& lower,const ComRef& upper,double stepSize) {return stepSizeConfiguration.addDynamicValueIndicator(signal, lower, upper, stepSize);}
83 
84  oms_status_enu_t registerSignalsForResultFile(ResultWriter& resultFile);
85  oms_status_enu_t updateSignals(ResultWriter& resultFile);
86 
87  protected:
89 
90  // stop the compiler generating methods copying the object
91  SystemWC(SystemWC const& copy);
92  SystemWC& operator=(SystemWC const& copy);
93 
94  private:
96 
97  unsigned int h_id;
98  unsigned int roll_iter_id;
99  unsigned int max_error_id;
100  unsigned int error_id;
101  double stepSize = 1e-4; // Default system stepsize. So first logging step works.
102  double maxError = 0.0;
103  double normError = 0.0;
104  unsigned int rollBackIt = 0;
105 
106  // oms_solver_wc_assc
107  std::vector<std::pair<ComRef, double>> assc_prevDoubleValues;
108  std::vector<std::pair<ComRef, int>> assc_prevIntValues;
109  std::vector<std::pair<ComRef, bool>> assc_prevBoolValues;
110 
111  // oms_solver_wc_ma
112  int masiMax;
113 
114  // oms_solver_wc_mav || oms_solver_wc_mav2
116  std::map<ComRef, Component*> mav_FMUcomponents;
117  std::map<ComRef, Component*> mav_canGetAndSetStateFMUcomponents;
118  };
119 }
120 
121 #endif
oms
Definition: AlgLoop.h:44
System.h
oms::SystemWC::importFromSSD_SimulationInformation
oms_status_enu_t importFromSSD_SimulationInformation(const pugi::xml_node &node, const std::string &sspVersion)
Definition: SystemWC.cpp:132
oms::SignalDerivative
Definition: SignalDerivative.h:41
ComRef.h
oms::SystemWC::stepUntilASSC
oms_status_enu_t stepUntilASSC(double stopTime)
Definition: SystemWC.cpp:876
oms::Model
Definition: Model.h:52
oms::StepSizeConfiguration::addEventIndicator
oms_status_enu_t addEventIndicator(const ComRef &signal)
Definition: StepSizeConfiguration.cpp:3
oms::SystemWC
Definition: SystemWC.h:48
Model.h
oms::SystemWC::setRealInputDerivative
oms_status_enu_t setRealInputDerivative(const ComRef &cref, const SignalDerivative &der)
Definition: SystemWC.cpp:916
oms::ssp::Draft20180219::ssd::system
const char * system
Definition: Tags.cpp:57
oms::Variable::isTypeInteger
bool isTypeInteger() const
Definition: Variable.h:90
oms::SystemWC::instantiate
oms_status_enu_t instantiate()
Definition: SystemWC.cpp:182
oms::ComponentFMUCS
Definition: ComponentFMUCS.h:54
oms::System::parentSystem
System * parentSystem
Definition: System.h:244
oms::ComRef
ComRef - component reference.
Definition: ComRef.h:46
SystemWC.h
oms::SystemWC::roll_iter_id
unsigned int roll_iter_id
Definition: SystemWC.h:98
oms::SystemWC::setSolverMethod
oms_status_enu_t setSolverMethod(std::string)
Definition: SystemWC.cpp:89
oms::SystemWC::stepSize
double stepSize
Definition: SystemWC.h:101
oms::ssp::Draft20180219::ssd::component
const char * component
Definition: Tags.cpp:45
oms::SystemWC::addStaticValueIndicator
oms_status_enu_t addStaticValueIndicator(const ComRef &signal, double lowerBound, double upperBound, double stepSize)
Definition: SystemWC.h:81
oms::SystemWC::getMaxOutputDerivativeOrder
unsigned int getMaxOutputDerivativeOrder()
Definition: SystemWC.cpp:220
oms::SignalType_INT
@ SignalType_INT
Definition: ResultWriter.h:44
Log::ProgressBar
static void ProgressBar(double start, double stop, double value)
Definition: Logging.cpp:294
oms::SystemWC::setSolver
oms_status_enu_t setSolver(oms_solver_enu_t solver)
Definition: SystemWC.h:67
oms::SystemWC::updateSignals
oms_status_enu_t updateSignals(ResultWriter &resultFile)
Definition: SystemWC.cpp:1161
oms::SystemWC::assc_prevIntValues
std::vector< std::pair< ComRef, int > > assc_prevIntValues
Definition: SystemWC.h:108
logError_InternalError
#define logError_InternalError
Definition: Logging.h:132
oms::StepSizeConfiguration::addStaticValueIndicator
oms_status_enu_t addStaticValueIndicator(const ComRef &signal, double lowerBound, double upperBound, double stepSize)
Definition: StepSizeConfiguration.cpp:15
Log::TerminateBar
static void TerminateBar()
Definition: Logging.cpp:324
oms::SignalType_REAL
@ SignalType_REAL
Definition: ResultWriter.h:43
logError_ModelInWrongState
#define logError_ModelInWrongState(cref)
Definition: Logging.h:135
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::SystemWC::maxError
double maxError
Definition: SystemWC.h:102
logInfo
#define logInfo(msg)
Definition: Logging.h:100
oms::Variable::isTypeReal
bool isTypeReal() const
Definition: Variable.h:91
DirectedGraph.h
oms::SystemWC::reset
oms_status_enu_t reset()
Definition: SystemWC.cpp:352
oms::Flags::RealTime
static bool RealTime()
Definition: Flags.h:71
oms::SystemWC::mav_FMUcomponents
std::map< ComRef, Component * > mav_FMUcomponents
Definition: SystemWC.h:116
oms::SystemWC::mav_doDoubleStep
bool mav_doDoubleStep
Definition: SystemWC.h:115
oms::DirectedGraph
Definition: DirectedGraph.h:64
oms::SignalType_BOOL
@ SignalType_BOOL
Definition: ResultWriter.h:45
oms::SystemWC::addEventIndicator
oms_status_enu_t addEventIndicator(const ComRef &signal)
Definition: SystemWC.h:79
oms::DirectedGraph::getSortedConnections
const std::vector< scc_t > & getSortedConnections()
Definition: DirectedGraph.cpp:247
oms::ssp::Draft20180219::ssd::connector
const char * connector
Definition: Tags.cpp:49
SignalDerivative.h
oms::SystemWC::setInputsDer
oms_status_enu_t setInputsDer(oms::DirectedGraph &graph, const std::vector< double > &inputsDer)
Definition: SystemWC.cpp:952
oms::SystemWC::mav_canGetAndSetStateFMUcomponents
std::map< ComRef, Component * > mav_canGetAndSetStateFMUcomponents
Definition: SystemWC.h:117
logDebug
#define logDebug(msg)
Definition: Logging.h:109
oms::SystemWC::addDynamicValueIndicator
oms_status_enu_t addDynamicValueIndicator(const ComRef &signal, const ComRef &lower, const ComRef &upper, double stepSize)
Definition: SystemWC.h:82
oms::Flags::ProgressBar
static bool ProgressBar()
Definition: Flags.h:70
oms::SignalValue_t
Definition: ResultWriter.h:48
oms::SystemWC::getInputAndOutput
oms_status_enu_t getInputAndOutput(DirectedGraph &graph, std::vector< double > &inputVect, std::vector< double > &outputVect, std::map< ComRef, Component * > FMUcomponents)
Definition: SystemWC.cpp:972
oms::SystemWC::NewSystem
static System * NewSystem(const ComRef &cref, Model *parentModel, System *parentSystem)
Definition: SystemWC.cpp:54
oms::StepSizeConfiguration::addDynamicValueIndicator
oms_status_enu_t addDynamicValueIndicator(const ComRef &signal, const ComRef &lower, const ComRef &upper, double stepSize)
Definition: StepSizeConfiguration.cpp:41
logWarning
#define logWarning(msg)
Definition: Logging.h:101
StepSizeConfiguration.h
oms::SystemWC::getRealOutputDerivative
oms_status_enu_t getRealOutputDerivative(const ComRef &cref, SignalDerivative &der)
Definition: SystemWC.cpp:901
oms::Flags::WallTime
static bool WallTime()
Definition: Flags.h:76
oms::SystemWC::terminate
oms_status_enu_t terminate()
Definition: SystemWC.cpp:339
Component.h
oms::ResultWriter
Definition: ResultWriter.h:68
oms::SystemWC::stepUntil
oms_status_enu_t stepUntil(double stopTime)
Definition: SystemWC.cpp:813
oms::ssp::Draft20180219::ssd::connectors
const char * connectors
Definition: Tags.cpp:51
oms::SystemWC::doStep
oms_status_enu_t doStep()
Definition: SystemWC.cpp:367
oms::Flags::InputExtrapolation
static bool InputExtrapolation()
Definition: Flags.h:69
oms::SystemWC::addTimeIndicator
oms_status_enu_t addTimeIndicator(const ComRef &signal)
Definition: SystemWC.h:80
oms::System
Definition: System.h:65
oms::SystemWC::getSolverName
std::string getSolverName() const
Definition: SystemWC.cpp:72
oms::SystemWC::exportToSSD_SimulationInformation
oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node &node) const
Definition: SystemWC.cpp:105
oms::ssp::Version1_0::simulation_information
const char * simulation_information
Definition: Tags.cpp:62
oms::ssp::Version1_0::FixedStepMaster
const char * FixedStepMaster
Definition: Tags.cpp:63
oms::SystemWC::initialize
oms_status_enu_t initialize()
Definition: SystemWC.cpp:234
oms::SystemWC::operator=
SystemWC & operator=(SystemWC const &copy)
not implemented
oms::StepSizeConfiguration
Definition: StepSizeConfiguration.h:10
oms::ResultWriter::updateSignal
void updateSignal(unsigned int id, SignalValue_t value)
Definition: ResultWriter.cpp:120
oms::SystemWC::registerSignalsForResultFile
oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)
Definition: SystemWC.cpp:1099
logError
#define logError(msg)
Definition: Logging.h:102
oms::SystemWC::max_error_id
unsigned int max_error_id
Definition: SystemWC.h:99
oms::SystemWC::masiMax
int masiMax
Definition: SystemWC.h:112
oms::StepSizeConfiguration::addTimeIndicator
oms_status_enu_t addTimeIndicator(const ComRef &signal)
Definition: StepSizeConfiguration.cpp:9
oms::SystemWC::stepSizeConfiguration
StepSizeConfiguration stepSizeConfiguration
Configuration data structure for assc.
Definition: SystemWC.h:95
oms::ssp::Draft20180219::ssd::connections
const char * connections
Definition: Tags.cpp:48
oms::ResultWriter::addSignal
unsigned int addSignal(const ComRef &name, const std::string &description, SignalType_t type)
Definition: ResultWriter.cpp:50
ComponentFMUCS.h
oms::SignalValue_t::intValue
int intValue
Definition: ResultWriter.h:51
oms::SystemWC::assc_prevDoubleValues
std::vector< std::pair< ComRef, double > > assc_prevDoubleValues
Definition: SystemWC.h:107
oms::SystemWC::rollBackIt
unsigned int rollBackIt
Definition: SystemWC.h:104
oms::System::solverMethod
oms_solver_enu_t solverMethod
Definition: System.h:229
oms::ComRef::pop_front
ComRef pop_front()
returns the first part of the ComRef and removed it from the current object
Definition: ComRef.cpp:184
oms::SystemWC::normError
double normError
Definition: SystemWC.h:103
oms::System::parentModel
Model * parentModel
Definition: System.h:243
oms::Variable
Definition: Variable.h:45
oms::DirectedGraph::getNodes
const std::vector< Connector > & getNodes() const
Definition: DirectedGraph.h:81
Flags.h
oms::Connector
Connector.
Definition: Connector.h:49
oms::SystemWC::updateInputs
oms_status_enu_t updateInputs(DirectedGraph &graph)
Definition: SystemWC.cpp:1028
oms::Flags::SolverStats
static bool SolverStats()
Definition: Flags.h:73
oms::SystemWC::assc_prevBoolValues
std::vector< std::pair< ComRef, bool > > assc_prevBoolValues
Definition: SystemWC.h:109
logError_InvalidIdent
#define logError_InvalidIdent(cref)
Definition: Logging.h:134
oms::ssp::Draft20180219::signal
const char * signal
Definition: Tags.cpp:38
oms::SystemWC::h_id
unsigned int h_id
Definition: SystemWC.h:97
oms::System::cref
ComRef cref
Definition: System.h:241
oms::SystemWC::error_id
unsigned int error_id
Definition: SystemWC.h:100
oms::SignalValue_t::boolValue
bool boolValue
Definition: ResultWriter.h:52
oms::SystemWC::getInputs
oms_status_enu_t getInputs(DirectedGraph &graph, std::vector< double > &inputs)
Definition: SystemWC.cpp:931
oms::ssp::Version1_0::VariableStepMaster
const char * VariableStepMaster
Definition: Tags.cpp:64
oms::SystemWC::~SystemWC
~SystemWC()
Definition: SystemWC.cpp:50
oms::SystemWC::SystemWC
SystemWC(const ComRef &cref, Model *parentModel, System *parentSystem)
Definition: SystemWC.cpp:45
CallClock
Definition: Clock.h:61