OMSimulatorLib The OMSimulator project is a FMI-based co-simulation environment.

Loading...
Searching...
No Matches
SystemSC3.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_SC3_H_
37#define _OMS_SYSTEM_SC3_H_
38
39#include "ComRef.h"
40#include "System.h"
41#include "OMSimulator/Types.h"
42
43#include <cvode/cvode.h> /* prototypes for CVODE fcts., consts. */
44#include <nvector/nvector_serial.h> /* serial N_Vector types, fcts., macros */
45#include <sunlinsol/sunlinsol_dense.h> /* Default dense linear solver */
46
47 namespace oms
48{
49 class Model;
50 class ComponentFMU3ME;
51 class Component;
52 int cvode_rhs3(realtype t, N_Vector y, N_Vector ydot, void* user_data);
53 int cvode_rhs_algebraic3(realtype t, N_Vector y, N_Vector ydot, void* user_data);
54 int cvode_roots3(realtype t, N_Vector y, realtype *gout, void* user_data);
55
56 class SystemSC3 : public System
57 {
58 public:
59 ~SystemSC3();
60
61 static System* NewSystem(const oms::ComRef& cref, Model* parentModel, System* parentSystem);
62 oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node& node) const;
63 oms_status_enu_t importFromSSD_SimulationInformation(const pugi::xml_node& node, const std::string& sspVersion);
64
65 oms_status_enu_t instantiate();
66 oms_status_enu_t initialize();
67 oms_status_enu_t terminate();
68 oms_status_enu_t reset();
69 oms_status_enu_t doStep();
70 oms_status_enu_t stepUntil(double stopTime);
71
72 oms_status_enu_t updateInputs(DirectedGraph& graph);
73
74 std::string getSolverName() const;
75 oms_status_enu_t setSolverMethod(std::string);
76
77 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;}
78 private:
79 oms_status_enu_t doStepEuler();
80 oms_status_enu_t doStepCVODE();
81
82 protected:
83 SystemSC3(const ComRef& cref, Model* parentModel, System* parentSystem);
84
85 // stop the compiler generating methods copying the object
86 SystemSC3(SystemSC3 const& copy);
87 SystemSC3& operator=(SystemSC3 const& copy);
88
89 private:
90 std::vector<ComponentFMU3ME*> fmus;
91 fmi3Boolean* callEventUpdate = new fmi3Boolean[fmus.size()]();
92 fmi3Boolean* terminateSimulation = new fmi3Boolean[fmus.size()]();
93
94 std::vector<size_t> nStates;
95 std::vector<size_t> nEventIndicators;
96
97 std::vector<double*> states;
98 std::vector<double*> states_der;
99 std::vector<double*> states_nominal;
100 std::vector<double*> event_indicators;
101 std::vector<double*> event_indicators_prev;
102
103 bool algebraic = false;
104
105 struct SolverDataEuler_t
106 {
107 };
108
109 struct SolverDataCVODE_t
110 {
111 void *mem;
112 N_Vector y;
113 SUNLinearSolver linSol; /* linear solver object */
114 SUNMatrix J; /* Matrix used by linear solver */
115 N_Vector liny; /* Vector used by linear solver */
116 N_Vector abstol;
117 };
118
119 union SolverData_t
120 {
121 SolverDataEuler_t euler;
122 SolverDataCVODE_t cvode;
123 } solverData;
124
125 friend int oms::cvode_rhs3(realtype t, N_Vector y, N_Vector ydot, void* user_data);
126 friend int oms::cvode_rhs_algebraic3(realtype t, N_Vector y, N_Vector ydot, void* user_data);
127 friend int oms::cvode_roots3(realtype t, N_Vector y, realtype *gout, void* user_data);
128 };
129}
130
131#endif
ComRef.h
System.h
oms::ComRef
ComRef - component reference.
Definition ComRef.h:51
oms::DirectedGraph
Definition DirectedGraph.h:71
oms::Model
Definition Model.h:57
oms::SystemSC3
Definition SystemSC3.h:57
oms::SystemSC3::operator=
SystemSC3 & operator=(SystemSC3 const &copy)
not implemented
oms::SystemSC3::instantiate
oms_status_enu_t instantiate()
Definition SystemSC3.cpp:240
oms::SystemSC3::event_indicators_prev
std::vector< double * > event_indicators_prev
Definition SystemSC3.h:101
oms::SystemSC3::callEventUpdate
fmi3Boolean * callEventUpdate
Definition SystemSC3.h:91
oms::SystemSC3::importFromSSD_SimulationInformation
oms_status_enu_t importFromSSD_SimulationInformation(const pugi::xml_node &node, const std::string &sspVersion)
Definition SystemSC3.cpp:213
oms::SystemSC3::initialize
oms_status_enu_t initialize()
Definition SystemSC3.cpp:263
oms::SystemSC3::doStepCVODE
oms_status_enu_t doStepCVODE()
Definition SystemSC3.cpp:805
oms::SystemSC3::terminateSimulation
fmi3Boolean * terminateSimulation
Definition SystemSC3.h:92
oms::SystemSC3::doStep
oms_status_enu_t doStep()
Definition SystemSC3.cpp:571
oms::SystemSC3::states_der
std::vector< double * > states_der
Definition SystemSC3.h:98
oms::SystemSC3::terminate
oms_status_enu_t terminate()
Definition SystemSC3.cpp:440
oms::SystemSC3::event_indicators
std::vector< double * > event_indicators
Definition SystemSC3.h:100
oms::SystemSC3::states_nominal
std::vector< double * > states_nominal
Definition SystemSC3.h:99
oms::SystemSC3::~SystemSC3
~SystemSC3()
Definition SystemSC3.cpp:145
oms::SystemSC3::nEventIndicators
std::vector< size_t > nEventIndicators
Definition SystemSC3.h:95
oms::SystemSC3::updateInputs
oms_status_enu_t updateInputs(DirectedGraph &graph)
Definition SystemSC3.cpp:994
oms::SystemSC3::setSolver
oms_status_enu_t setSolver(oms_solver_enu_t solver)
Definition SystemSC3.h:77
oms::SystemSC3::algebraic
bool algebraic
Definition SystemSC3.h:103
oms::SystemSC3::NewSystem
static System * NewSystem(const oms::ComRef &cref, Model *parentModel, System *parentSystem)
Definition SystemSC3.cpp:149
oms::SystemSC3::solverData
union oms::SystemSC3::SolverData_t solverData
oms::SystemSC3::nStates
std::vector< size_t > nStates
Definition SystemSC3.h:94
oms::SystemSC3::fmus
std::vector< ComponentFMU3ME * > fmus
Definition SystemSC3.h:90
oms::SystemSC3::SystemSC3
SystemSC3(SystemSC3 const &copy)
not implemented
oms::SystemSC3::reset
oms_status_enu_t reset()
Definition SystemSC3.cpp:505
oms::SystemSC3::exportToSSD_SimulationInformation
oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node &node) const
Definition SystemSC3.cpp:192
oms::SystemSC3::states
std::vector< double * > states
Definition SystemSC3.h:97
oms::SystemSC3::setSolverMethod
oms_status_enu_t setSolverMethod(std::string)
Definition SystemSC3.cpp:180
oms::SystemSC3::doStepEuler
oms_status_enu_t doStepEuler()
Definition SystemSC3.cpp:586
oms::SystemSC3::stepUntil
oms_status_enu_t stepUntil(double stopTime)
Definition SystemSC3.cpp:968
oms::SystemSC3::getSolverName
std::string getSolverName() const
Definition SystemSC3.cpp:167
oms::System
Definition System.h:66
oms::System::cref
ComRef cref
Definition System.h:232
oms::System::solverMethod
oms_solver_enu_t solverMethod
Definition System.h:221
oms::System::parentSystem
System * parentSystem
Definition System.h:235
oms::System::parentModel
Model * parentModel
Definition System.h:234
oms
Definition AlgLoop.h:49
oms::cvode_rhs3
int cvode_rhs3(realtype t, N_Vector y, N_Vector ydot, void *user_data)
Definition SystemSC3.cpp:50
oms::cvode_rhs_algebraic3
int cvode_rhs_algebraic3(realtype t, N_Vector y, N_Vector ydot, void *user_data)
Definition SystemSC3.cpp:97
oms::cvode_roots3
int cvode_roots3(realtype t, N_Vector y, realtype *gout, void *user_data)
Definition SystemSC3.cpp:109
oms::SystemSC3::SolverDataCVODE_t
Definition SystemSC3.h:110
oms::SystemSC3::SolverDataCVODE_t::abstol
N_Vector abstol
Definition SystemSC3.h:116
oms::SystemSC3::SolverDataCVODE_t::linSol
SUNLinearSolver linSol
Definition SystemSC3.h:113
oms::SystemSC3::SolverDataCVODE_t::liny
N_Vector liny
Definition SystemSC3.h:115
oms::SystemSC3::SolverDataCVODE_t::y
N_Vector y
Definition SystemSC3.h:112
oms::SystemSC3::SolverDataCVODE_t::mem
void * mem
Definition SystemSC3.h:111
oms::SystemSC3::SolverDataCVODE_t::J
SUNMatrix J
Definition SystemSC3.h:114
oms::SystemSC3::SolverDataEuler_t
Definition SystemSC3.h:106
oms::SystemSC3::SolverData_t
Definition SystemSC3.h:120
oms::SystemSC3::SolverData_t::euler
SolverDataEuler_t euler
Definition SystemSC3.h:121
oms::SystemSC3::SolverData_t::cvode
SolverDataCVODE_t cvode
Definition SystemSC3.h:122