MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mbdynFMI.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/modules/module-FMU/mbdynFMI.h,v 1.3 2017/01/12 15:20:16 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 /*
33  AUTHOR: Devyesh Tandon <devyeshtandon+mbdyn@gmail.com>
34  Copyright (C) 2016(-2017) all rights reserved.
35  The copyright of this patch is transferred
36  to Pierangelo Masarati and Paolo Mantegazza
37  for use in the software MBDyn as described
38  in the GNU Public License version 2.1
39 
40 */
41 
42 
43 #include <stdlib.h>
44 #include <stdio.h>
45 #include <string>
46 #include <errno.h>
47 #include <fmilib.h>
48 
49 #include "fmi_zip_unzip.h"
50 
51 //#include <JM/jm_types.h>
52 //#include <JM/jm_callbacks.h>
53 //#include <JM/jm_portability.h>
54 
55 #include <FMI2/fmi2_import.h>
56 #include <FMI/fmi_import_context.h>
57 
58 #include "mbconfig.h"
59 #include "stepsol.h"
60 
61 
62 //#include <fmi1_import_impl.h>
63 //#include <fmi1_import_variable_list_impl.h>
64 
65 class fmu {
66  public:
70  };
71 
72  int simType;
73  fmi_import_context_t* context;
74 
75  fmu(fmi_import_context_t* text, int type){
76  context = text;
77  simType = type;
78  }
79 
80  virtual void parseXML(fmi_import_context_t* context, const char* dirPath) = 0;
81  virtual void setCallBackFunction() = 0;
82 
83  virtual void ImportCreateDLL(void) = 0;
84 
85  virtual bool CheckInput(const std::string) = 0;
86 
87  virtual int GetNumOfContinousStates(void) = 0;
88  virtual int GetNumOfEventIndicators(void) = 0;
89  virtual int GetNumOfVar(void) = 0;
90 
91  virtual void Initialize(double dTol, double time, double rTol) = 0;
92  virtual void EventIndicatorInit(void) = 0;
93 
94  virtual void SetRelativeTol(double dTol) = 0; //Not Req
95  virtual void SetTime(double time) = 0;
96  virtual void SetStates(double* states) = 0;
97  virtual void SetValuesByVariable(const std::string, double) = 0;
98 
99  virtual int GetRefValueFromString(const char* s) = 0;
100  virtual double GetStateFromRefValue(unsigned int i) = 0;
101  virtual void GetStateDerivatives(double*) = 0;
102  virtual void GetStates(double*) = 0;
103  virtual void GetDirectionalDerivatives(FullMatrixHandler *,int*, int, double *) = 0;
104  virtual bool SupportsDirectionalDerivatives() = 0;
105 
106  virtual bool CheckInterrupts(double, double*) = 0;
107 
108  virtual void InitializeAsSlave(const char*, double, double) = 0;
109  virtual void CSPropogate(double tcur, double dt) = 0;
110 
111 
112  virtual ~fmu(void);
113 };
114 
115 class fmu1 :public fmu{
116  private:
117  fmi1_callback_functions_t callBackFunctions;
118  fmi1_import_t* fmu;
119 
120  fmi1_status_t fmistatus;
121  jm_status_enu_t jmstatus;
122 
123  fmi1_real_t currTime;
124  fmi1_real_t relativeTolerance;
125  fmi1_event_info_t eventInfo;
126 
128  fmi1_real_t* eventIndicators;
129  fmi1_real_t* eventIndicatorsPrev;
130  fmi1_import_variable_t* v;
131 
133  fmi1_real_t* deriv;
134  fmi1_value_reference_t *vrs;
135 
136  fmi1_boolean_t intermediateResults;
137 
138 
139  public:
140  void parseXML(fmi_import_context_t* context, const char* dirPath);
141  void setCallBackFunction();
142 
143  fmu1(fmi_import_context_t* text, int type):fmu::fmu(text, type){
144  NO_OP;
145  }
146 
147  void ImportCreateDLL(void);
148 
149  bool CheckInput(const std::string);
150 
151  int GetNumOfContinousStates(void);
152  int GetNumOfEventIndicators(void);
153  int GetNumOfVar(void);
154 
155  void Initialize(double dTol, double time, double rTol);
156  void EventIndicatorInit(void);
157 
158  void SetRelativeTol(double dTol);
159  void SetTime(double time);
160  void SetStates(double* states);
161  void SetValuesByVariable(const std::string, double);
162 
163  int GetRefValueFromString(const char* s);
164  double GetStateFromRefValue(unsigned int i);
165  void GetStateDerivatives(double*);
166  void GetStates(double *);
167  void GetDirectionalDerivatives(FullMatrixHandler *, int*, int, double*);
169 
170  bool CheckInterrupts(double, double*);
171 
172  void InitializeAsSlave(const char* location, double tstart, double tend);
173  void CSPropogate(double tcur, double dt);
174 
175  virtual ~fmu1(void);
176 
177 };
178 
179 class fmu2 : public fmu{
180  private:
181  fmi2_callback_functions_t callBackFunctions;
182  fmi2_import_t* fmu;
183 
184  fmi2_status_t fmistatus;
185  jm_status_enu_t jmstatus;
186 
187  fmi2_real_t currTime;
188  fmi2_real_t relativeTolerance;
189  fmi2_event_info_t eventInfo;
190 
192  fmi2_real_t* eventIndicators;
193  fmi2_real_t* eventIndicatorsPrev;
194  fmi2_import_variable_t* v;
195  fmi2_boolean_t callEventUpdate;
196  fmi2_boolean_t terminateSimulation;
197 
199  fmi2_value_reference_t *vrs;
200 
201  fmi2_boolean_t intermediateResults;
202 
203 
204  public:
205  void parseXML(fmi_import_context_t* context, const char* dirPath);
206  void setCallBackFunction();
207 
208  fmu2(fmi_import_context_t* text, int type):fmu::fmu(text, type){
209  NO_OP;
210  }
211 
212  void ImportCreateDLL(void);
213 
214  bool CheckInput(const std::string);
215 
216  int GetNumOfContinousStates(void);
217  int GetNumOfEventIndicators(void);
218  int GetNumOfVar(void);
219 
220  void Initialize(double dTol, double time, double rTol);
221  void EventIndicatorInit(void);
222 
223  void SetRelativeTol(double dTol); //Not Req
224  void SetTime(double time);
225  void SetStates(double* states);
226  void SetValuesByVariable(const std::string, double);
227 
228  int GetRefValueFromString(const char* s);
229  double GetStateFromRefValue(unsigned int i);
230  void GetStateDerivatives(double*);
231  void GetStates(double *);
232  void GetDirectionalDerivatives(FullMatrixHandler *, int*, int, double*);
234 
235  bool CheckInterrupts(double, double*);
236 
237  void InitializeAsSlave(const char* , double, double);
238  void CSPropogate(double tcur, double dt);
239 
240  virtual ~fmu2(void);
241 };
242 
Definition: mbdynFMI.h:115
virtual int GetNumOfEventIndicators(void)=0
fmi1_import_variable_t * v
Definition: mbdynFMI.h:130
void EventIndicatorInit(void)
Definition: mbdynFMI.cc:699
virtual void InitializeAsSlave(const char *, double, double)=0
Definition: mbdynFMI.h:65
SimulationTypes
Definition: mbdynFMI.h:67
virtual void SetValuesByVariable(const std::string, double)=0
size_t nEventIndicators
Definition: mbdynFMI.h:191
void GetStateDerivatives(double *)
Definition: mbdynFMI.cc:360
fmi2_real_t currTime
Definition: mbdynFMI.h:187
virtual void GetStateDerivatives(double *)=0
double GetStateFromRefValue(unsigned int i)
Definition: mbdynFMI.cc:325
virtual void GetStates(double *)=0
virtual bool CheckInterrupts(double, double *)=0
virtual void CSPropogate(double tcur, double dt)=0
int GetNumOfContinousStates(void)
Definition: mbdynFMI.cc:524
void SetStates(double *states)
Definition: mbdynFMI.cc:663
int GetRefValueFromString(const char *s)
Definition: mbdynFMI.cc:646
virtual void SetRelativeTol(double dTol)=0
fmi1_real_t * eventIndicators
Definition: mbdynFMI.h:128
void GetStates(double *)
Definition: mbdynFMI.cc:368
fmu(fmi_import_context_t *text, int type)
Definition: mbdynFMI.h:75
void GetStateDerivatives(double *)
Definition: mbdynFMI.cc:651
void GetStates(double *)
Definition: mbdynFMI.cc:717
int GetNumOfEventIndicators(void)
Definition: mbdynFMI.cc:572
void CSPropogate(double tcur, double dt)
Definition: mbdynFMI.cc:462
fmu1(fmi_import_context_t *text, int type)
Definition: mbdynFMI.h:143
void SetStates(double *states)
Definition: mbdynFMI.cc:299
bool SupportsDirectionalDerivatives()
Definition: mbdynFMI.cc:216
virtual void GetDirectionalDerivatives(FullMatrixHandler *, int *, int, double *)=0
void SetRelativeTol(double dTol)
Definition: mbdynFMI.cc:289
#define NO_OP
Definition: myassert.h:74
void GetDirectionalDerivatives(FullMatrixHandler *, int *, int, double *)
Definition: mbdynFMI.cc:238
fmi1_event_info_t eventInfo
Definition: mbdynFMI.h:125
void Initialize(double dTol, double time, double rTol)
Definition: mbdynFMI.cc:533
void SetTime(double time)
Definition: mbdynFMI.cc:657
void parseXML(fmi_import_context_t *context, const char *dirPath)
Definition: mbdynFMI.cc:500
virtual void EventIndicatorInit(void)=0
virtual void SetTime(double time)=0
fmi2_value_reference_t * vrs
Definition: mbdynFMI.h:199
void CSPropogate(double tcur, double dt)
Definition: mbdynFMI.cc:711
fmi1_real_t * eventIndicatorsPrev
Definition: mbdynFMI.h:129
fmi1_real_t currTime
Definition: mbdynFMI.h:123
virtual ~fmu2(void)
Definition: mbdynFMI.cc:335
void InitializeAsSlave(const char *location, double tstart, double tend)
Definition: mbdynFMI.cc:733
fmu2(fmi_import_context_t *text, int type)
Definition: mbdynFMI.h:208
virtual ~fmu(void)
Definition: mbdynFMI.cc:468
virtual bool SupportsDirectionalDerivatives()=0
fmi2_event_info_t eventInfo
Definition: mbdynFMI.h:189
fmi1_boolean_t intermediateResults
Definition: mbdynFMI.h:136
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
void ImportCreateDLL(void)
Definition: mbdynFMI.cc:517
void SetValuesByVariable(const std::string, double)
Definition: mbdynFMI.cc:610
bool CheckInput(const std::string)
Definition: mbdynFMI.cc:598
virtual int GetRefValueFromString(const char *s)=0
fmi2_status_t fmistatus
Definition: mbdynFMI.h:184
void SetValuesByVariable(const std::string, double)
Definition: mbdynFMI.cc:399
fmi2_real_t * eventIndicators
Definition: mbdynFMI.h:192
void parseXML(fmi_import_context_t *context, const char *dirPath)
Definition: mbdynFMI.cc:131
fmi_import_context_t * context
Definition: mbdynFMI.h:73
int simType
Definition: mbdynFMI.h:72
fmi2_boolean_t callEventUpdate
Definition: mbdynFMI.h:195
virtual double GetStateFromRefValue(unsigned int i)=0
void SetRelativeTol(double dTol)
Definition: mbdynFMI.cc:695
double GetStateFromRefValue(unsigned int i)
Definition: mbdynFMI.cc:672
fmi2_import_t * fmu
Definition: mbdynFMI.h:182
virtual ~fmu1(void)
Definition: mbdynFMI.cc:472
size_t nEventIndicators
Definition: mbdynFMI.h:127
bool CheckInterrupts(double, double *)
Definition: mbdynFMI.cc:373
fmi2_real_t relativeTolerance
Definition: mbdynFMI.h:188
void EventIndicatorInit(void)
Definition: mbdynFMI.cc:276
bool SupportsDirectionalDerivatives()
Definition: mbdynFMI.cc:681
void setCallBackFunction()
Definition: mbdynFMI.cc:510
void ImportCreateDLL(void)
Definition: mbdynFMI.cc:150
virtual void ImportCreateDLL(void)=0
fmi2_callback_functions_t callBackFunctions
Definition: mbdynFMI.h:181
fmi1_import_t * fmu
Definition: mbdynFMI.h:118
fmi2_boolean_t terminateSimulation
Definition: mbdynFMI.h:196
virtual void Initialize(double dTol, double time, double rTol)=0
fmi1_callback_functions_t callBackFunctions
Definition: mbdynFMI.h:117
void SetTime(double time)
Definition: mbdynFMI.cc:293
Definition: mbdynFMI.h:179
void setCallBackFunction()
Definition: mbdynFMI.cc:142
int GetNumOfEventIndicators(void)
Definition: mbdynFMI.cc:177
fmi2_real_t * eventIndicatorsPrev
Definition: mbdynFMI.h:193
int GetNumOfContinousStates(void)
Definition: mbdynFMI.cc:171
bool CheckInput(const std::string)
Definition: mbdynFMI.cc:310
bool CheckInterrupts(double, double *)
Definition: mbdynFMI.cc:576
int GetNumOfVar(void)
Definition: mbdynFMI.cc:689
int GetNumOfVar(void)
Definition: mbdynFMI.cc:181
int GetRefValueFromString(const char *s)
Definition: mbdynFMI.cc:319
fmi1_real_t * deriv
Definition: mbdynFMI.h:133
jm_status_enu_t jmstatus
Definition: mbdynFMI.h:121
virtual bool CheckInput(const std::string)=0
virtual void parseXML(fmi_import_context_t *context, const char *dirPath)=0
fmi1_value_reference_t * vrs
Definition: mbdynFMI.h:134
void GetDirectionalDerivatives(FullMatrixHandler *, int *, int, double *)
Definition: mbdynFMI.cc:685
fmi1_real_t relativeTolerance
Definition: mbdynFMI.h:124
virtual void setCallBackFunction()=0
void InitializeAsSlave(const char *, double, double)
Definition: mbdynFMI.cc:436
fmi2_boolean_t intermediateResults
Definition: mbdynFMI.h:201
void Initialize(double dTol, double time, double rTol)
Definition: mbdynFMI.cc:187
virtual int GetNumOfVar(void)=0
virtual void SetStates(double *states)=0
fmi2_import_variable_t * v
Definition: mbdynFMI.h:194
virtual int GetNumOfContinousStates(void)=0
int numOfContStates
Definition: mbdynFMI.h:132
int numOfContStates
Definition: mbdynFMI.h:198
jm_status_enu_t jmstatus
Definition: mbdynFMI.h:185