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