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 "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 
62  oms_status_enu_t stepUntil(double stopTime, void (*cb)(const char* ident, double time, oms_status_enu_t status));
63 
65 
66  std::string getSolverName() const;
67  oms_status_enu_t setSolverMethod(std::string);
68 
70 
71  protected:
72  SystemSC(const ComRef& cref, Model* parentModel, System* parentSystem);
73 
74  // stop the compiler generating methods copying the object
75  SystemSC(SystemSC const& copy);
76  SystemSC& operator=(SystemSC const& copy);
77 
78  private:
79  std::vector<ComponentFMUME*> fmus;
80 
81  std::vector<fmi2_boolean_t> callEventUpdate;
82  std::vector<fmi2_boolean_t> terminateSimulation;
83  std::vector<size_t> nStates;
84  std::vector<size_t> nEventIndicators;
85 
86  std::vector<double*> states;
87  std::vector<double*> states_der;
88  std::vector<double*> states_nominal;
89  std::vector<double*> event_indicators;
90  std::vector<double*> event_indicators_prev;
91 
93  {
94  };
95 
97  {
98  void *mem;
99  N_Vector y;
100  SUNLinearSolver linSol; /* linear solver object */
101  SUNMatrix J; /* Matrix used by linear solver */
102  N_Vector liny; /* Vector used by linear solver */
103  N_Vector abstol;
104  };
105 
107  {
110  } solverData;
111 
112  friend int oms::cvode_rhs(realtype t, N_Vector y, N_Vector ydot, void* user_data);
113  };
114 }
115 
116 #endif
oms_solver_enu_t
Definition: Types.h:96
Definition: Types.h:44
oms_solver_enu_t solverMethod
Definition: System.h:192
Definition: Model.h:54
std::vector< double * > states
Definition: SystemSC.h:86
std::vector< fmi2_boolean_t > terminateSimulation
Definition: SystemSC.h:82
SolverDataEuler_t euler
Definition: SystemSC.h:108
oms_status_enu_t terminate()
Definition: SystemSC.cpp:354
std::vector< ComponentFMUME * > fmus
Definition: SystemSC.h:79
union oms::SystemSC::SolverData_t solverData
oms_status_enu_t initialize()
Definition: SystemSC.cpp:231
N_Vector abstol
Definition: SystemSC.h:103
SUNMatrix J
Definition: SystemSC.h:101
oms_status_enu_t
Definition: Types.h:43
oms_status_enu_t importFromSSD_SimulationInformation(const pugi::xml_node &node, const std::string &sspVersion)
Definition: SystemSC.cpp:154
std::vector< double * > event_indicators
Definition: SystemSC.h:89
ComRef cref
Definition: System.h:207
std::vector< fmi2_boolean_t > callEventUpdate
Definition: SystemSC.h:81
N_Vector y
Definition: SystemSC.h:99
Definition: Types.h:47
void * mem
Definition: SystemSC.h:98
SUNLinearSolver linSol
Definition: SystemSC.h:100
Definition: SystemSC.h:96
std::vector< double * > event_indicators_prev
Definition: SystemSC.h:90
Definition: Types.h:101
ComRef - component reference.
Definition: ComRef.h:43
static System * NewSystem(const oms::ComRef &cref, Model *parentModel, System *parentSystem)
Definition: SystemSC.cpp:95
oms_status_enu_t stepUntil(double stopTime, void(*cb)(const char *ident, double time, oms_status_enu_t status))
Definition: SystemSC.cpp:463
Definition: SystemSC.h:106
oms_status_enu_t setSolver(oms_solver_enu_t solver)
Definition: SystemSC.h:69
Definition: SystemSC.h:92
oms_status_enu_t updateInputs(DirectedGraph &graph)
Definition: SystemSC.cpp:654
Definition: Types.h:98
int cvode_rhs(realtype t, N_Vector y, N_Vector ydot, void *user_data)
Definition: SystemSC.cpp:45
SystemSC & operator=(SystemSC const &copy)
not implemented
Definition: SystemSC.h:49
Definition: AlgLoop.h:44
SystemSC(const ComRef &cref, Model *parentModel, System *parentSystem)
Definition: SystemSC.cpp:86
oms_status_enu_t reset()
Definition: SystemSC.cpp:419
std::vector< size_t > nEventIndicators
Definition: SystemSC.h:84
double time
Definition: System.h:178
oms_status_enu_t setSolverMethod(std::string)
Definition: SystemSC.cpp:126
oms_status_enu_t instantiate()
Definition: SystemSC.cpp:182
std::vector< size_t > nStates
Definition: SystemSC.h:83
oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node &node) const
Definition: SystemSC.cpp:138
Model * parentModel
Definition: System.h:209
std::vector< double * > states_nominal
Definition: SystemSC.h:88
SolverDataCVODE_t cvode
Definition: SystemSC.h:109
std::vector< double * > states_der
Definition: SystemSC.h:87
N_Vector liny
Definition: SystemSC.h:102
Definition: System.h:67
System * parentSystem
Definition: System.h:210
std::string getSolverName() const
Definition: SystemSC.cpp:113
Definition: DirectedGraph.h:55
~SystemSC()
Definition: SystemSC.cpp:91