OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment.
Loading...
Searching...
No Matches
SystemSC.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, 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 AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36#ifndef _OMS_SYSTEM_SC_H_
37#define _OMS_SYSTEM_SC_H_
38
39#include "ComRef.h"
40#include "System.h"
41#include "OMSimulator/Types.h"
42
43#include <memory>
44
45#include <cvode/cvode.h> /* prototypes for CVODE fcts., consts. */
46#include <nvector/nvector_serial.h> /* serial N_Vector types, fcts., macros */
47#include <sunlinsol/sunlinsol_dense.h> /* Default dense linear solver */
48
49namespace oms
50{
51 class Model;
52 class ComponentFMUME;
53 class Component;
54 int cvode_rhs(realtype t, N_Vector y, N_Vector ydot, void* user_data);
55 int cvode_rhs_algebraic(realtype t, N_Vector y, N_Vector ydot, void* user_data);
56 int cvode_roots(realtype t, N_Vector y, realtype *gout, void* user_data);
57
58 class SystemSC : public System
59 {
60 public:
61 ~SystemSC();
62
64 oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node& node) const;
65 oms_status_enu_t importFromSSD_SimulationInformation(const pugi::xml_node& node, const std::string& sspVersion);
66
67 oms_status_enu_t instantiate();
68 oms_status_enu_t initialize();
69 oms_status_enu_t terminate();
70 oms_status_enu_t reset();
71 oms_status_enu_t doStep();
72 oms_status_enu_t stepUntil(double stopTime);
73
74 oms_status_enu_t updateInputs(DirectedGraph& graph);
75
76 std::string getSolverName() const;
77 oms_status_enu_t setSolverMethod(std::string);
78
79 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;}
80
81 private:
82 oms_status_enu_t doStepEuler();
83 oms_status_enu_t doStepCVODE();
84
85 protected:
87
88 // stop the compiler generating methods copying the object
89 SystemSC(SystemSC const& copy);
90 SystemSC& operator=(SystemSC const& copy);
91
92 private:
93 std::vector<Component*> fmus; // use Component Base class to support FMI 2 ME and FMI 3 ME
94
95 // One entry per FMU, allocated by initialize() once fmus is filled.
96 std::unique_ptr<bool[]> callEventUpdate; //initialized with false
97 std::unique_ptr<bool[]> terminateSimulation; //initialized with false
98
99 std::vector<size_t> nStates;
100 std::vector<size_t> nEventIndicators;
101
102 std::vector<double*> states;
103 std::vector<double*> states_der;
104 std::vector<double*> states_nominal;
105 std::vector<double*> event_indicators;
106 std::vector<double*> event_indicators_prev;
107
108 bool algebraic = false;
109
111 {
112 };
113
115 {
116 void *mem;
117 N_Vector y;
118 SUNLinearSolver linSol; /* linear solver object */
119 SUNMatrix J; /* Matrix used by linear solver */
120 N_Vector liny; /* Vector used by linear solver */
121 N_Vector abstol;
122 };
123
129
130 friend int oms::cvode_rhs(realtype t, N_Vector y, N_Vector ydot, void* user_data);
131 friend int oms::cvode_rhs_algebraic(realtype t, N_Vector y, N_Vector ydot, void* user_data);
132 friend int oms::cvode_roots(realtype t, N_Vector y, realtype *gout, void* user_data);
133 };
134}
135
136#endif
ComRef - component reference.
Definition ComRef.h:51
Definition DirectedGraph.h:71
Definition Model.h:57
Definition SystemSC.h:59
std::unique_ptr< bool[]> callEventUpdate
Definition SystemSC.h:96
oms_status_enu_t importFromSSD_SimulationInformation(const pugi::xml_node &node, const std::string &sspVersion)
Definition SystemSC.cpp:229
oms_status_enu_t setSolverMethod(std::string)
Definition SystemSC.cpp:196
oms_status_enu_t doStepEuler()
Definition SystemSC.cpp:615
std::vector< double * > event_indicators
Definition SystemSC.h:105
bool algebraic
Definition SystemSC.h:108
std::string getSolverName() const
Definition SystemSC.cpp:183
oms_status_enu_t terminate()
Definition SystemSC.cpp:467
static System * NewSystem(const oms::ComRef &cref, Model *parentModel, System *parentSystem)
Definition SystemSC.cpp:165
oms_status_enu_t reset()
Definition SystemSC.cpp:532
oms_status_enu_t setSolver(oms_solver_enu_t solver)
Definition SystemSC.h:79
oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node &node) const
Definition SystemSC.cpp:208
union oms::SystemSC::SolverData_t solverData
~SystemSC()
Definition SystemSC.cpp:161
std::vector< double * > event_indicators_prev
Definition SystemSC.h:106
std::vector< size_t > nStates
Definition SystemSC.h:99
std::vector< Component * > fmus
Definition SystemSC.h:93
std::vector< double * > states
Definition SystemSC.h:102
SystemSC(SystemSC const &copy)
not implemented
SystemSC & operator=(SystemSC const &copy)
not implemented
std::unique_ptr< bool[]> terminateSimulation
Definition SystemSC.h:97
oms_status_enu_t doStepCVODE()
Definition SystemSC.cpp:838
oms_status_enu_t initialize()
Definition SystemSC.cpp:279
oms_status_enu_t instantiate()
Definition SystemSC.cpp:256
std::vector< double * > states_nominal
Definition SystemSC.h:104
oms_status_enu_t updateInputs(DirectedGraph &graph)
Definition SystemSC.cpp:1027
oms_status_enu_t stepUntil(double stopTime)
Definition SystemSC.cpp:1001
std::vector< double * > states_der
Definition SystemSC.h:103
oms_status_enu_t doStep()
Definition SystemSC.cpp:600
std::vector< size_t > nEventIndicators
Definition SystemSC.h:100
Definition System.h:66
ComRef cref
Definition System.h:232
oms_solver_enu_t solverMethod
Definition System.h:221
System * parentSystem
Definition System.h:235
Model * parentModel
Definition System.h:234
Definition AlgLoop.h:50
int cvode_rhs_algebraic(realtype t, N_Vector y, N_Vector ydot, void *user_data)
Definition SystemSC.cpp:114
int cvode_roots(realtype t, N_Vector y, realtype *gout, void *user_data)
Definition SystemSC.cpp:126
int cvode_rhs(realtype t, N_Vector y, N_Vector ydot, void *user_data)
Definition SystemSC.cpp:66
Definition SystemSC.h:115
SUNMatrix J
Definition SystemSC.h:119
SUNLinearSolver linSol
Definition SystemSC.h:118
N_Vector y
Definition SystemSC.h:117
N_Vector abstol
Definition SystemSC.h:121
void * mem
Definition SystemSC.h:116
N_Vector liny
Definition SystemSC.h:120
Definition SystemSC.h:111
Definition SystemSC.h:125
SolverDataEuler_t euler
Definition SystemSC.h:126
SolverDataCVODE_t cvode
Definition SystemSC.h:127