OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment that supports ordinary (i.e., non-delayed) and TLM connections.
SystemSC.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_SC_H_
33 #define _OMS_SYSTEM_SC_H_
34 
35 #include "ComRef.h"
36 #include "System.h"
37 #include "OMSimulator/Types.h"
38 
39 #include <cvode/cvode.h> /* prototypes for CVODE fcts., consts. */
40 #include <nvector/nvector_serial.h> /* serial N_Vector types, fcts., macros */
41 #include <sunlinsol/sunlinsol_dense.h> /* Default dense linear solver */
42 
43 namespace oms
44 {
45  class Model;
46  class ComponentFMUME;
47  int cvode_rhs(realtype t, N_Vector y, N_Vector ydot, void* user_data);
48 
49  class SystemSC : public System
50  {
51  public:
52  ~SystemSC();
53 
55  oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node& node) const;
56  oms_status_enu_t importFromSSD_SimulationInformation(const pugi::xml_node& node, const std::string& sspVersion);
57 
58  oms_status_enu_t instantiate();
59  oms_status_enu_t initialize();
60  oms_status_enu_t terminate();
61  oms_status_enu_t reset();
62  oms_status_enu_t doStep();
63  oms_status_enu_t stepUntil(double stopTime);
64 
65  oms_status_enu_t updateInputs(DirectedGraph& graph);
66 
67  std::string getSolverName() const;
68  oms_status_enu_t setSolverMethod(std::string);
69 
70  oms_status_enu_t setSolver(oms_solver_enu_t solver) {if (solver > oms_solver_sc_min && solver < oms_solver_sc_max) {solverMethod=solver; return oms_status_ok;} return oms_status_error;}
71 
72  protected:
74 
75  // stop the compiler generating methods copying the object
76  SystemSC(SystemSC const& copy);
77  SystemSC& operator=(SystemSC const& copy);
78 
79  private:
80  std::vector<ComponentFMUME*> fmus;
81 
82  std::vector<fmi2Boolean> callEventUpdate;
83  std::vector<fmi2Boolean> terminateSimulation;
84  std::vector<size_t> nStates;
85  std::vector<size_t> nEventIndicators;
86 
87  std::vector<double*> states;
88  std::vector<double*> states_der;
89  std::vector<double*> states_nominal;
90  std::vector<double*> event_indicators;
91  std::vector<double*> event_indicators_prev;
92 
94  {
95  };
96 
98  {
99  void *mem;
100  N_Vector y;
101  SUNLinearSolver linSol; /* linear solver object */
102  SUNMatrix J; /* Matrix used by linear solver */
103  N_Vector liny; /* Vector used by linear solver */
104  N_Vector abstol;
105  };
106 
108  {
111  } solverData;
112 
113  friend int oms::cvode_rhs(realtype t, N_Vector y, N_Vector ydot, void* user_data);
114  };
115 }
116 
117 #endif
oms::SystemSC::nEventIndicators
std::vector< size_t > nEventIndicators
Definition: SystemSC.h:85
oms::SystemSC::SolverDataCVODE_t::y
N_Vector y
Definition: SystemSC.h:100
oms
Definition: AlgLoop.h:44
System.h
oms::SystemSC::fmus
std::vector< ComponentFMUME * > fmus
Definition: SystemSC.h:80
ComRef.h
oms::Model
Definition: Model.h:52
oms::Flags::CVODEMaxNLSFailures
static int CVODEMaxNLSFailures()
Definition: Flags.h:60
oms::SystemSC::doStep
oms_status_enu_t doStep()
Definition: SystemSC.cpp:484
Model.h
oms::ssp::Draft20180219::ssd::system
const char * system
Definition: Tags.cpp:57
oms::System::parentSystem
System * parentSystem
Definition: System.h:244
oms::ComRef
ComRef - component reference.
Definition: ComRef.h:46
oms::SystemSC::SolverDataCVODE_t::J
SUNMatrix J
Definition: SystemSC.h:102
oms::ssp::Draft20180219::ssd::component
const char * component
Definition: Tags.cpp:45
oms::SystemSC::SolverDataCVODE_t
Definition: SystemSC.h:97
oms::SystemSC::SolverData_t::cvode
SolverDataCVODE_t cvode
Definition: SystemSC.h:110
Log::ProgressBar
static void ProgressBar(double start, double stop, double value)
Definition: Logging.cpp:294
oms::SystemSC::~SystemSC
~SystemSC()
Definition: SystemSC.cpp:89
oms::SystemSC::SystemSC
SystemSC(const ComRef &cref, Model *parentModel, System *parentSystem)
Definition: SystemSC.cpp:84
oms::Flags::CVODEMaxErrTestFails
static int CVODEMaxErrTestFails()
Definition: Flags.h:59
SystemSC.h
oms::SystemSC::setSolverMethod
oms_status_enu_t setSolverMethod(std::string)
Definition: SystemSC.cpp:124
oms::ComponentTable
Definition: ComponentTable.h:49
logError_InternalError
#define logError_InternalError
Definition: Logging.h:132
oms::SystemSC::terminate
oms_status_enu_t terminate()
Definition: SystemSC.cpp:375
Log::TerminateBar
static void TerminateBar()
Definition: Logging.cpp:324
oms::SystemSC::nStates
std::vector< size_t > nStates
Definition: SystemSC.h:84
oms::SystemSC::setSolver
oms_status_enu_t setSolver(oms_solver_enu_t solver)
Definition: SystemSC.h:70
oms::ComRef::isValidIdent
static bool isValidIdent(const std::string &ident)
Definition: ComRef.cpp:89
Tags.h
logError_FMUCall
#define logError_FMUCall(call, fmu)
Definition: Logging.h:130
logInfo
#define logInfo(msg)
Definition: Logging.h:100
oms::SystemSC::instantiate
oms_status_enu_t instantiate()
Definition: SystemSC.cpp:187
oms::SystemSC::solverData
union oms::SystemSC::SolverData_t solverData
oms::DirectedGraph
Definition: DirectedGraph.h:64
oms::ssp::Version1_0::VariableStepSolver
const char * VariableStepSolver
Definition: Tags.cpp:65
oms::DirectedGraph::getSortedConnections
const std::vector< scc_t > & getSortedConnections()
Definition: DirectedGraph.cpp:247
oms::SystemSC::NewSystem
static System * NewSystem(const oms::ComRef &cref, Model *parentModel, System *parentSystem)
Definition: SystemSC.cpp:93
oms::SystemSC::stepUntil
oms_status_enu_t stepUntil(double stopTime)
Definition: SystemSC.cpp:646
oms::SystemSC::SolverDataCVODE_t::mem
void * mem
Definition: SystemSC.h:99
logDebug
#define logDebug(msg)
Definition: Logging.h:109
oms::Flags::ProgressBar
static bool ProgressBar()
Definition: Flags.h:70
oms::SystemSC::getSolverName
std::string getSolverName() const
Definition: SystemSC.cpp:111
logWarning
#define logWarning(msg)
Definition: Logging.h:101
oms::Flags::CVODEMaxNLSIterations
static int CVODEMaxNLSIterations()
Definition: Flags.h:61
oms::Flags::CVODEMaxSteps
static int CVODEMaxSteps()
Definition: Flags.h:62
oms::SystemSC
Definition: SystemSC.h:49
oms::SystemSC::SolverData_t::euler
SolverDataEuler_t euler
Definition: SystemSC.h:109
oms::SystemSC::SolverData_t
Definition: SystemSC.h:107
Component.h
oms::SystemSC::states_der
std::vector< double * > states_der
Definition: SystemSC.h:88
oms::SystemSC::states
std::vector< double * > states
Definition: SystemSC.h:87
oms::SystemSC::SolverDataEuler_t
Definition: SystemSC.h:93
oms::cvode_rhs
int cvode_rhs(realtype t, N_Vector y, N_Vector ydot, void *user_data)
Definition: SystemSC.cpp:43
oms::SystemSC::importFromSSD_SimulationInformation
oms_status_enu_t importFromSSD_SimulationInformation(const pugi::xml_node &node, const std::string &sspVersion)
Definition: SystemSC.cpp:159
oms::System
Definition: System.h:65
oms::ssp::Version1_0::simulation_information
const char * simulation_information
Definition: Tags.cpp:62
oms::ComponentFMUME
Definition: ComponentFMUME.h:52
oms::SystemSC::event_indicators_prev
std::vector< double * > event_indicators_prev
Definition: SystemSC.h:91
logError
#define logError(msg)
Definition: Logging.h:102
oms::SystemSC::operator=
SystemSC & operator=(SystemSC const &copy)
not implemented
oms::SystemSC::SolverDataCVODE_t::abstol
N_Vector abstol
Definition: SystemSC.h:104
oms::Flags::ZeroNominal
static bool ZeroNominal()
Definition: Flags.h:77
oms::System::solverMethod
oms_solver_enu_t solverMethod
Definition: System.h:229
oms::ComponentFMUME::getFMU
fmiHandle * getFMU()
Definition: ComponentFMUME.h:115
ComponentTable.h
oms::System::parentModel
Model * parentModel
Definition: System.h:243
oms::DirectedGraph::getNodes
const std::vector< Connector > & getNodes() const
Definition: DirectedGraph.h:81
oms::SystemSC::event_indicators
std::vector< double * > event_indicators
Definition: SystemSC.h:90
Flags.h
oms::SystemSC::SolverDataCVODE_t::liny
N_Vector liny
Definition: SystemSC.h:103
oms::SystemSC::updateInputs
oms_status_enu_t updateInputs(DirectedGraph &graph)
Definition: SystemSC.cpp:670
oms::SystemSC::SolverDataCVODE_t::linSol
SUNLinearSolver linSol
Definition: SystemSC.h:101
oms::SystemSC::terminateSimulation
std::vector< fmi2Boolean > terminateSimulation
Definition: SystemSC.h:83
logError_InvalidIdent
#define logError_InvalidIdent(cref)
Definition: Logging.h:134
oms::SystemSC::exportToSSD_SimulationInformation
oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node &node) const
Definition: SystemSC.cpp:136
oms::SystemSC::states_nominal
std::vector< double * > states_nominal
Definition: SystemSC.h:89
oms::SystemSC::callEventUpdate
std::vector< fmi2Boolean > callEventUpdate
Definition: SystemSC.h:82
oms::System::cref
ComRef cref
Definition: System.h:241
oms::SystemSC::initialize
oms_status_enu_t initialize()
Definition: SystemSC.cpp:236
ComponentFMUME.h
oms::SystemSC::reset
oms_status_enu_t reset()
Definition: SystemSC.cpp:440
CallClock
Definition: Clock.h:61