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 
63  oms_status_enu_t stepUntil(double stopTime);
64 
66 
67  std::string getSolverName() const;
68  oms_status_enu_t setSolverMethod(std::string);
69 
71 
72  protected:
73  SystemSC(const ComRef& cref, Model* parentModel, System* parentSystem);
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<fmi2_boolean_t> callEventUpdate;
83  std::vector<fmi2_boolean_t> 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_solver_enu_t
Definition: Types.h:96
Definition: Types.h:44
oms_solver_enu_t solverMethod
Definition: System.h:229
Definition: Model.h:56
std::vector< double * > states
Definition: SystemSC.h:87
std::vector< fmi2_boolean_t > terminateSimulation
Definition: SystemSC.h:83
SolverDataEuler_t euler
Definition: SystemSC.h:109
oms_status_enu_t terminate()
Definition: SystemSC.cpp:375
std::vector< ComponentFMUME * > fmus
Definition: SystemSC.h:80
union oms::SystemSC::SolverData_t solverData
oms_status_enu_t initialize()
Definition: SystemSC.cpp:236
N_Vector abstol
Definition: SystemSC.h:104
oms_status_enu_t stepUntil(double stopTime)
Definition: SystemSC.cpp:646
SUNMatrix J
Definition: SystemSC.h:102
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:159
std::vector< double * > event_indicators
Definition: SystemSC.h:90
ComRef cref
Definition: System.h:241
std::vector< fmi2_boolean_t > callEventUpdate
Definition: SystemSC.h:82
N_Vector y
Definition: SystemSC.h:100
Definition: Types.h:47
void * mem
Definition: SystemSC.h:99
SUNLinearSolver linSol
Definition: SystemSC.h:101
Definition: SystemSC.h:97
std::vector< double * > event_indicators_prev
Definition: SystemSC.h:91
Definition: Types.h:101
ComRef - component reference.
Definition: ComRef.h:46
static System * NewSystem(const oms::ComRef &cref, Model *parentModel, System *parentSystem)
Definition: SystemSC.cpp:93
Definition: SystemSC.h:107
oms_status_enu_t setSolver(oms_solver_enu_t solver)
Definition: SystemSC.h:70
Definition: SystemSC.h:93
oms_status_enu_t updateInputs(DirectedGraph &graph)
Definition: SystemSC.cpp:670
Definition: Types.h:98
int cvode_rhs(realtype t, N_Vector y, N_Vector ydot, void *user_data)
Definition: SystemSC.cpp:43
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:84
oms_status_enu_t reset()
Definition: SystemSC.cpp:440
std::vector< size_t > nEventIndicators
Definition: SystemSC.h:85
oms_status_enu_t setSolverMethod(std::string)
Definition: SystemSC.cpp:124
oms_status_enu_t instantiate()
Definition: SystemSC.cpp:187
std::vector< size_t > nStates
Definition: SystemSC.h:84
oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node &node) const
Definition: SystemSC.cpp:136
Model * parentModel
Definition: System.h:243
std::vector< double * > states_nominal
Definition: SystemSC.h:89
oms_status_enu_t doStep()
Definition: SystemSC.cpp:484
SolverDataCVODE_t cvode
Definition: SystemSC.h:110
std::vector< double * > states_der
Definition: SystemSC.h:88
N_Vector liny
Definition: SystemSC.h:103
Definition: System.h:69
System * parentSystem
Definition: System.h:244
std::string getSolverName() const
Definition: SystemSC.cpp:111
Definition: DirectedGraph.h:65
~SystemSC()
Definition: SystemSC.cpp:89