-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmbdynFMI.h
More file actions
211 lines (150 loc) · 5.25 KB
/
mbdynFMI.h
File metadata and controls
211 lines (150 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
AUTHOR: Devyesh Tandon <devyeshtandon+mbdyn@gmail.com>
Copyright (C) 2016(-2016) all rights reserved.
The copyright of this patch is transferred
to Pierangelo Masarati and Paolo Mantegazza
for use in the software MBDyn as described
in the GNU Public License version 2.1
*/
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <errno.h>
#include <fmilib.h>
#include "fmi_zip_unzip.h"
#include <JM/jm_types.h>
#include <JM/jm_callbacks.h>
#include <JM/jm_portability.h>
#include <FMI2/fmi2_import.h>
#include <FMI/fmi_import_context.h>
#include "mbconfig.h"
#include "stepsol.h"
//#include <fmi1_import_impl.h>
//#include <fmi1_import_variable_list_impl.h>
class fmu {
public:
enum SimulationTypes{
IMPORT,
COSIM
};
int simType;
fmi_import_context_t* context;
fmu(fmi_import_context_t* text, int type){
context = text;
simType = type;
}
virtual void parseXML(fmi_import_context_t* context, const char* dirPath) = 0;
virtual void setCallBackFunction() = 0;
virtual void ImportCreateDLL(void) = 0;
virtual bool CheckInput(const std::string) = 0;
virtual int GetNumOfContinousStates(void) = 0;
virtual int GetNumOfEventIndicators(void) = 0;
virtual int GetNumOfVar(void) = 0;
virtual void Initialize(double dTol, double time, double rTol) = 0;
virtual void EventIndicatorInit(void) = 0;
virtual void SetRelativeTol(double dTol) = 0; //Not Req
virtual void SetTime(double time) = 0;
virtual void SetStates(double* states) = 0;
virtual void SetValuesByVariable(const std::string, double) = 0;
virtual int GetRefValueFromString(const char* s) = 0;
virtual double GetStateFromRefValue(unsigned int i) = 0;
virtual void GetStateDerivatives(double*) = 0;
virtual void GetStates(double*) = 0;
virtual void GetDirectionalDerivatives(FullMatrixHandler *,int*, int, double *) = 0;
virtual bool SupportsDirectionalDerivatives() = 0;
virtual bool CheckInterrupts(double, double*) = 0;
virtual void InitializeAsSlave(const char*, double, double) = 0;
virtual void CSPropogate(double tcur, double dt) = 0;
virtual ~fmu(void);
};
class fmu1 :public fmu{
private:
fmi1_callback_functions_t callBackFunctions;
fmi1_import_t* fmu;
fmi1_status_t fmistatus;
jm_status_enu_t jmstatus;
fmi1_real_t currTime;
fmi1_real_t relativeTolerance;
fmi1_event_info_t eventInfo;
size_t nEventIndicators;
fmi1_real_t* eventIndicators;
fmi1_real_t* eventIndicatorsPrev;
fmi1_import_variable_t* v;
int numOfContStates;
fmi1_real_t* deriv;
fmi1_value_reference_t *vrs;
fmi1_boolean_t intermediateResults;
public:
void parseXML(fmi_import_context_t* context, const char* dirPath);
void setCallBackFunction();
fmu1(fmi_import_context_t* text, int type):fmu::fmu(text, type){
NO_OP;
}
void ImportCreateDLL(void);
bool CheckInput(const std::string);
int GetNumOfContinousStates(void);
int GetNumOfEventIndicators(void);
int GetNumOfVar(void);
void Initialize(double dTol, double time, double rTol);
void EventIndicatorInit(void);
void SetRelativeTol(double dTol);
void SetTime(double time);
void SetStates(double* states);
void SetValuesByVariable(const std::string, double);
int GetRefValueFromString(const char* s);
double GetStateFromRefValue(unsigned int i);
void GetStateDerivatives(double*);
void GetStates(double *);
void GetDirectionalDerivatives(FullMatrixHandler *, int*, int, double*);
bool SupportsDirectionalDerivatives();
bool CheckInterrupts(double, double*);
void InitializeAsSlave(const char* location, double tstart, double tend);
void CSPropogate(double tcur, double dt);
virtual ~fmu1(void);
};
class fmu2 : public fmu{
private:
fmi2_callback_functions_t callBackFunctions;
fmi2_import_t* fmu;
fmi2_status_t fmistatus;
jm_status_enu_t jmstatus;
fmi2_real_t currTime;
fmi2_real_t relativeTolerance;
fmi2_event_info_t eventInfo;
size_t nEventIndicators;
fmi2_real_t* eventIndicators;
fmi2_real_t* eventIndicatorsPrev;
fmi2_import_variable_t* v;
fmi2_boolean_t callEventUpdate;
fmi2_boolean_t terminateSimulation;
int numOfContStates;
fmi2_value_reference_t *vrs;
fmi2_boolean_t intermediateResults;
public:
void parseXML(fmi_import_context_t* context, const char* dirPath);
void setCallBackFunction();
fmu2(fmi_import_context_t* text, int type):fmu::fmu(text, type){
NO_OP;
}
void ImportCreateDLL(void);
bool CheckInput(const std::string);
int GetNumOfContinousStates(void);
int GetNumOfEventIndicators(void);
int GetNumOfVar(void);
void Initialize(double dTol, double time, double rTol);
void EventIndicatorInit(void);
void SetRelativeTol(double dTol); //Not Req
void SetTime(double time);
void SetStates(double* states);
void SetValuesByVariable(const std::string, double);
int GetRefValueFromString(const char* s);
double GetStateFromRefValue(unsigned int i);
void GetStateDerivatives(double*);
void GetStates(double *);
void GetDirectionalDerivatives(FullMatrixHandler *, int*, int, double*);
bool SupportsDirectionalDerivatives();
bool CheckInterrupts(double, double*);
void InitializeAsSlave(const char* , double, double);
void CSPropogate(double tcur, double dt);
virtual ~fmu2(void);
};