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

Loading...
Searching...
No Matches
Variable.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_VARIABLE_H_
37#define _OMS_VARIABLE_H_
38
39#include "ComRef.h"
40#include "Connector.h"
41#include "OMSimulator/Types.h"
42
43#include <fmi4c.h>
44#include <string>
45#include <vector>
46
47 namespace oms
48{
49 class Variable
50 {
51 public:
52 Variable(fmiHandle * fmi4c, int index, oms_component_enu_t componentType);
53 ~Variable();
54
55 void markAsState(size_t der_index) { is_state = true; this->der_index = der_index; }
56 void markAsContinuousTimeState(size_t der_index) { is_continuous_time_state = true; this->der_index = der_index; }
57 void markAsContinuousTimeDer() { is_continuous_time_der = true; }
58
59 unsigned int getStateIndex() const { return state_index; }
60
61 bool isFmi2() const {return fmi2;}
62 bool isFmi3() const {return fmi3;}
63
64 // causality attribute
65 bool isParameter() const { return isFmi2() ? (fmi2CausalityParameter == fmi2Causality_) : (fmi3CausalityParameter == fmi3Causality_);}
66 bool isCalculatedParameter() const { return isFmi2() ? (fmi2CausalityCalculatedParameter == fmi2Causality_) : (fmi3CausalityCalculatedParameter ==fmi3Causality_);}
67 bool isInput() const { return isFmi2() ? (fmi2CausalityInput == fmi2Causality_) : (fmi3CausalityInput == fmi3Causality_);}
68 bool isOutput() const { return isFmi2() ? (fmi2CausalityOutput == fmi2Causality_) : (fmi3CausalityOutput == fmi3Causality_);}
69 bool isLocal() const { return isFmi2() ? (fmi2CausalityLocal == fmi2Causality_) : (fmi3CausalityLocal == fmi3Causality_);}
70 bool isIndependent() const { return isFmi2() ? (fmi2CausalityIndependent == fmi2Causality_) : (fmi3CausalityIndependent == fmi3Causality_);}
71
72 bool isState() const { return is_state; }
73 bool isDer() const { return is_der; }
74 bool isContinuousTimeState() const { return is_continuous_time_state; }
75 bool isContinuousTimeDer() const { return is_continuous_time_der; }
76
77 // initial attribute
78 bool isExact() const { return isFmi2() ? (fmi2InitialExact == fmi2InitialProperty) : (fmi3InitialExact == fmi3InitialProperty);}
79 bool isApprox() const { return isFmi2() ? (fmi2InitialApprox == fmi2InitialProperty) : (fmi3InitialApprox == fmi3InitialProperty);}
80 bool isCalculated() const { return isFmi2() ? (fmi2InitialCalculated == fmi2InitialProperty) : (fmi3InitialCalculated == fmi3InitialProperty); }
81
82 bool isInitialUnknown() const {
83 return (isOutput() && (isApprox() || isCalculated()))
84 || (isCalculatedParameter())
85 || (isContinuousTimeState() && (isApprox() || isCalculated()))
86 || (isContinuousTimeDer() && (isApprox() || isCalculated()));
87 }
88
89 const ComRef& getCref() const { return cref; }
90 operator std::string() const { return std::string(cref); }
91
92 fmi2ValueReference getValueReference() const { return fmi2Vr; }
93 fmi3ValueReference getValueReferenceFMI3() const { return fmi3Vr; }
94 oms_signal_type_enu_t getType() const { return type; }
95 oms_signal_numeric_type_enu_t getNumericType() const {return numericType;}
96 const std::string& getDescription() const { return description; }
97
98 bool isTypeBoolean() const { return oms_signal_type_boolean == type; }
99 bool isTypeInteger() const { return oms_signal_type_integer == type || oms_signal_type_enum == type; }
100 bool isTypeReal() const { return oms_signal_type_real == type; }
101 bool isTypeString() const { return oms_signal_type_string == type; }
102
103 std::string getCausalityString() const;
104 oms_causality_enu_t getCausality() const;
105
106 unsigned int getIndex() const { return index; }
107 oms::Connector makeConnector(const oms::ComRef& owner) const { return oms::Connector(getCausality(), type, cref, owner); }
108
109 private:
110
111 void configureFMI2Variable(fmiHandle *fmi4c, int index);
112 void configureFMI3Variable(fmiHandle *fmi4c, int index);
113
114 ComRef cref;
115 std::string description;
116 oms_component_enu_t componentType;
117
118 // FMI 2.0 specific members
119 fmi2ValueReference fmi2Vr;
120 fmi2Causality fmi2Causality_;
121 fmi2Variability fmi2Variability_;
122 fmi2Initial fmi2InitialProperty;
123
124 // FMI 3.0 specific members
125 fmi3ValueReference fmi3Vr;
126 fmi3Causality fmi3Causality_;
127 fmi3Variability fmi3Variability_;
128 fmi3Initial fmi3InitialProperty;
129
130 bool is_state;
131 bool is_der;
132 bool is_continuous_time_state;
133 bool is_continuous_time_der;
134 oms_signal_type_enu_t type;
135 oms_signal_numeric_type_enu_t numericType;
136 unsigned int index;
137 size_t state_index;
138 size_t der_index;
139 bool fmi2;
140 bool fmi3;
141 friend bool operator==(const oms::Variable& v1, const oms::Variable& v2);
142 friend bool operator!=(const oms::Variable& v1, const oms::Variable& v2);
143 };
144
145 bool operator==(const oms::Variable& v1, const oms::Variable& v2);
146 bool operator!=(const oms::Variable& v1, const oms::Variable& v2);
147}
148
149#endif
ComRef.h
Connector.h
oms::ComRef
ComRef - component reference.
Definition ComRef.h:51
oms::Connector
Connector.
Definition Connector.h:54
oms::Variable
Definition Variable.h:50
oms::Variable::operator==
friend bool operator==(const oms::Variable &v1, const oms::Variable &v2)
oms::Variable::markAsState
void markAsState(size_t der_index)
Definition Variable.h:55
oms::Variable::getStateIndex
unsigned int getStateIndex() const
Definition Variable.h:59
oms::Variable::isLocal
bool isLocal() const
Definition Variable.h:69
oms::Variable::isFmi2
bool isFmi2() const
Definition Variable.h:61
oms::Variable::getDescription
const std::string & getDescription() const
Definition Variable.h:96
oms::Variable::isDer
bool isDer() const
Definition Variable.h:73
oms::Variable::getCausality
oms_causality_enu_t getCausality() const
Definition Variable.cpp:210
oms::Variable::getIndex
unsigned int getIndex() const
Definition Variable.h:106
oms::Variable::isInitialUnknown
bool isInitialUnknown() const
Definition Variable.h:82
oms::Variable::configureFMI3Variable
void configureFMI3Variable(fmiHandle *fmi4c, int index)
Definition Variable.cpp:117
oms::Variable::type
oms_signal_type_enu_t type
Definition Variable.h:134
oms::Variable::markAsContinuousTimeDer
void markAsContinuousTimeDer()
Definition Variable.h:57
oms::Variable::isTypeBoolean
bool isTypeBoolean() const
Definition Variable.h:98
oms::Variable::fmi3
bool fmi3
Definition Variable.h:140
oms::Variable::is_continuous_time_state
bool is_continuous_time_state
Definition Variable.h:132
oms::Variable::isTypeReal
bool isTypeReal() const
Definition Variable.h:100
oms::Variable::cref
ComRef cref
Definition Variable.h:114
oms::Variable::fmi2Variability_
fmi2Variability fmi2Variability_
Definition Variable.h:121
oms::Variable::fmi2Causality_
fmi2Causality fmi2Causality_
Definition Variable.h:120
oms::Variable::isCalculated
bool isCalculated() const
Definition Variable.h:80
oms::Variable::isCalculatedParameter
bool isCalculatedParameter() const
Definition Variable.h:66
oms::Variable::description
std::string description
Definition Variable.h:115
oms::Variable::configureFMI2Variable
void configureFMI2Variable(fmiHandle *fmi4c, int index)
Definition Variable.cpp:65
oms::Variable::isTypeString
bool isTypeString() const
Definition Variable.h:101
oms::Variable::getNumericType
oms_signal_numeric_type_enu_t getNumericType() const
Definition Variable.h:95
oms::Variable::is_continuous_time_der
bool is_continuous_time_der
Definition Variable.h:133
oms::Variable::getCausalityString
std::string getCausalityString() const
Definition Variable.cpp:256
oms::Variable::is_der
bool is_der
Definition Variable.h:131
oms::Variable::getCref
const ComRef & getCref() const
Definition Variable.h:89
oms::Variable::isState
bool isState() const
Definition Variable.h:72
oms::Variable::getType
oms_signal_type_enu_t getType() const
Definition Variable.h:94
oms::Variable::operator!=
friend bool operator!=(const oms::Variable &v1, const oms::Variable &v2)
oms::Variable::der_index
size_t der_index
index origin = 0
Definition Variable.h:138
oms::Variable::makeConnector
oms::Connector makeConnector(const oms::ComRef &owner) const
Definition Variable.h:107
oms::Variable::isApprox
bool isApprox() const
Definition Variable.h:79
oms::Variable::isContinuousTimeDer
bool isContinuousTimeDer() const
Definition Variable.h:75
oms::Variable::is_state
bool is_state
Definition Variable.h:130
oms::Variable::state_index
size_t state_index
index origin = 0
Definition Variable.h:137
oms::Variable::fmi3Causality_
fmi3Causality fmi3Causality_
Definition Variable.h:126
oms::Variable::index
unsigned int index
index origin = 0
Definition Variable.h:136
oms::Variable::isIndependent
bool isIndependent() const
Definition Variable.h:70
oms::Variable::fmi2Vr
fmi2ValueReference fmi2Vr
Definition Variable.h:119
oms::Variable::componentType
oms_component_enu_t componentType
Definition Variable.h:116
oms::Variable::markAsContinuousTimeState
void markAsContinuousTimeState(size_t der_index)
Definition Variable.h:56
oms::Variable::getValueReference
fmi2ValueReference getValueReference() const
Definition Variable.h:92
oms::Variable::isContinuousTimeState
bool isContinuousTimeState() const
Definition Variable.h:74
oms::Variable::numericType
oms_signal_numeric_type_enu_t numericType
Definition Variable.h:135
oms::Variable::isTypeInteger
bool isTypeInteger() const
Definition Variable.h:99
oms::Variable::fmi3InitialProperty
fmi3Initial fmi3InitialProperty
Definition Variable.h:128
oms::Variable::~Variable
~Variable()
Definition Variable.cpp:206
oms::Variable::fmi3Variability_
fmi3Variability fmi3Variability_
Definition Variable.h:127
oms::Variable::isExact
bool isExact() const
Definition Variable.h:78
oms::Variable::isParameter
bool isParameter() const
Definition Variable.h:65
oms::Variable::isFmi3
bool isFmi3() const
Definition Variable.h:62
oms::Variable::isInput
bool isInput() const
Definition Variable.h:67
oms::Variable::getValueReferenceFMI3
fmi3ValueReference getValueReferenceFMI3() const
Definition Variable.h:93
oms::Variable::isOutput
bool isOutput() const
Definition Variable.h:68
oms::Variable::fmi3Vr
fmi3ValueReference fmi3Vr
Definition Variable.h:125
oms::Variable::fmi2InitialProperty
fmi2Initial fmi2InitialProperty
Definition Variable.h:122
oms::Variable::fmi2
bool fmi2
Definition Variable.h:139
oms
Definition AlgLoop.h:49
oms::operator==
bool operator==(const ComRef &lhs, const ComRef &rhs)
Definition ComRef.cpp:214
oms::operator!=
bool operator!=(const ComRef &lhs, const ComRef &rhs)
Definition ComRef.cpp:219