Marine systems simulation
CIEngine.h
1#pragma once
2
14#include <string>
15#include "SimObject.h"
16#include "CPrintDuringExec.h"
17
19#define MYMAX(x,y) (x) > (y) ? (x) : (y)
20#define MYMIN(x,y) (x) < (y) ? (x) : (y)
21
23static const double gd_PI = 3.14159265358979323846;
24
26//==================================================================================================
27// Structs for model parameters that are read from xml file
28//==================================================================================================
29
30// GP
31typedef struct
32{
33 double cp_air; // Specific heat of air
34 double cv_air; // Specific heat of air
35 double cp_ex; // Specific heat of exhaust
36 double cv_ex; // Specific heat of exhaust
37 double pAmb; // Ambient pressure
38 double TAmb; // Ambient temperature
40
41// CC
42typedef struct
43{
44 double V_d; // Displaced volume 1 cylinder
45 double n_cyl; // Number of cylinders
46 double AFRStoich; // Stoichiometric air to fuel ratio
47 double Q_LHV; // Fuel lower heating value
48 double VolEff; // Volumetric efficiency
49 double CCEff; // Combustion chamber efficiency
50 double CR; // Compression ratio
52
53// InM
54typedef struct
55{
56 double Vol; // manifold volume
58
59// ExM
60typedef struct
61{
62 double Vol; // manifold volume
64
65// CS
66typedef struct
67{
68 double I_eng; // Inertia of crankshaft and flywheel
69 double M_fric_rps; // Friction torque pr rps
71
72// TC
73typedef struct
74{
75 double Inertia; // Inertia of TC and shaft
76 double TrbEff; // Turbine efficiency, should be implemented as map
77 double CmpEff; // Compressor efficiency, should be implemented as map
78 double WGRef; // Wastegate reference pressure
80
81// IC
82typedef struct
83{
84 double Eff; // Intercooler efficiency
86
87// Model parameters
88typedef struct
89{
90 GPModParType m_GP; // Global Parameters
91 CCModParType m_CC; // Combustion Chamber parameters
92 InMModParType m_InM; // Intake manifold parameters
93 ExMModParType m_ExM; // Exhaust manifold parameters
94 CSModParType m_CS; // Crank shaft parameters
95 TCModParType m_TC; // Turbo Charger parameters
96 ICModParType m_IC; // Intercooler parameters
98
100//==================================================================================================
101// Model input structs
102//==================================================================================================
103
104
105typedef struct
106{
107 ISignalPort* m_M_load; // Torque load from prop shaft
108 ISignalPort* m_N_eng_SP; // Engine speed set-point
109 ISignalPort* m_pInM_SP; // Intake manifold pressure setpoint
110 ISignalPort* m_MinLambda_SP;// Minimum allowed lambda setpoint
112
114//==================================================================================================
115// Model variables structs
116//==================================================================================================
117
118// CC
119typedef struct CCMVT
120{
121 double IMEP; // Indicated Mean Effective Pressure
122 double IP; // Indicated Power
123 double M_CC; // Torque to CS
124 double W_InM; // Mass flow intake manifold
125 double T_ExP; // Temperature flow exhaust port
126 double X; // Amount of exhaust gas
127 double W_ExP; // Mass flow exhaust port
128 double W_fuel; // Fuel mass flow
129 double Lambda; // Lambda
130
131 CCMVT()
132 {
133 IMEP = IP = M_CC = W_InM = T_ExP = X = W_ExP = W_fuel = Lambda = 0;
134 }
136
137// InM
138typedef struct InMMVT
139{
140 double p; // Pressure
141 double T; // Temperature
142
143 InMMVT()
144 {
145 p = T = 0;
146 }
148
149// ExM
150typedef struct ExMMVT
151{
152 double p; // Pressure
153 double T; // Temperature
154
155 ExMMVT()
156 {
157 p = T = 0;
158 }
160
161// CS
162typedef struct CSMVT
163{
164 double M_eng; // Engine torque
165 double N_eng; // Engine speed
166 double P_eng; // Engine power
167
168 CSMVT()
169 {
170 M_eng = N_eng = P_eng = 0;
171 }
173
174// TC
175typedef struct TCMVT
176{
177 double W_trb; // Turbine mass flow
178 double T_cmp; // Compressor temperature outlet flow
179 double W_cmp; // Mass flow compressor
180 double M_trb; // Turbine torque
181 double M_cmp; // Compressor torque
182 double N_TC; // TC speed
183 double k; // k in compressor map calc
184 double PR_trb; // Pressure ratio turbine
185 double PR_cmp; // Pressure ratio compressor
186
187 TCMVT()
188 {
189 W_trb = T_cmp = W_cmp = M_trb = M_cmp = N_TC = k = PR_trb = PR_cmp = 1;
190 }
192
193// IC
194typedef struct ICMVT
195{
196 double T_IC; // Temperature IC outlet
197
198 ICMVT()
199 {
200 T_IC = 1;
201 }
203
204// ECU
205typedef struct ECUMVT
206{
207 double FuelPrCycle; // Injected fuel pr combustion cycle
208 double WGOpening; // Waste gate opening setpoint
209 double MaxFuelPrCycle; // Max allowed fuel pr cycle
210
211 ECUMVT()
212 {
213 WGOpening = 1;
214 MaxFuelPrCycle = FuelPrCycle = 1e-3;
215 }
217
218// Model variables
219typedef struct
220{
221 CCModVarType m_CC;
222 InMModVarType m_InM;
223 ExMModVarType m_ExM;
224 CSModVarType m_CS;
225 TCModVarType m_TC;
226 ICModVarType m_IC;
227 ECUModVarType m_ECU;
229
231//==================================================================================================
232// Integrator anti windup type
233//==================================================================================================
234typedef struct
235{
236 double Lower; // Lower saturation limit
237 double Upper; // Upper saturation limit
239
241//==================================================================================================
242// State definition
243//==================================================================================================
244typedef struct
245{
246 int mI_SIndex; // The index of the state
247 IAWSatLimitType m_AWL; // Integrator anti windup saturation limit
248 //double *pd_VarPtr; // Pointer to model variable for this state
249}StateType;
250
252//==================================================================================================
253// PI controller definition
254//==================================================================================================
255typedef struct
256{
257 double e; // Deviation
258 double Kp; // Proortional gain
259 double Ti; // Integral time
260 IAWSatLimitType PIOutSatLim;// PI controller output saturation limits
261}PIType;
262
264//==================================================================================================
265// Class definition
266//==================================================================================================
267
268class CCIEngine : public SimObject
269{
270public:
272 CCIEngine(const string& simobjectname, ISimObjectCreator* const creator);
273
275 // CC
276 const double* out_CC_IMEP(const double T, const double* const X);
277 const double* out_CC_IP(const double T, const double* const X);
278 const double* out_CC_Lambda(const double T, const double* const X);
279 const double* out_CC_M_CC(const double T, const double* const X);
280 const double* out_CC_T_ExP(const double T, const double* const X);
281 const double* out_CC_W_ExP(const double T, const double* const X);
282 const double* out_CC_W_fuel(const double T, const double* const X);
283 const double* out_CC_W_InM(const double T, const double* const X);
284 const double* out_CC_X(const double T, const double* const X);
285
286 // InM
287 const double* out_InM_p(const double T, const double* const X);
288
289 // ExM
290 const double* out_ExM_p(const double T, const double* const X);
291
292 // CS
293 const double* out_CS_M_eng(const double T, const double* const X);
294 const double* out_CS_N_eng(const double T, const double* const X);
295 const double* out_CS_P_eng(const double T, const double* const X);
296
297 // TC
298 const double* out_TC_K_cmp(const double T, const double* const X);
299 const double* out_TC_M_trb(const double T, const double* const X);
300 const double* out_TC_M_cmp(const double T, const double* const X);
301 const double* out_TC_PR_cmp(const double T, const double* const X);
302 const double* out_TC_PR_trb(const double T, const double* const X);
303 const double* out_TC_T_cmp(const double T, const double* const X);
304 const double* out_TC_W_cmp(const double T, const double* const X);
305 const double* out_TC_W_trb(const double T, const double* const X);
306 const double* out_TC_N_TC(const double T, const double* const X);
307
308 // IC
309 const double* out_IC_T_IC(const double T, const double* const X);
310
311 // ECU
312 const double* out_ECU_FuelPrCyc(const double T, const double* const X);
313 const double* out_ECU_MaxFuelPrCyc(const double T, const double* const X);
314 const double* out_ECU_WGOpening(const double T, const double* const X);
315
317 void OdeFcn(const double T, const double *const X, double *const XDot, const bool bIsMajorTimeStep);
318
319#ifdef FH_VISUALIZATION
320
322 virtual void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator);
323
325 virtual void RenderUpdate(const double T, const double* const X);
326#endif
327
328protected:
330 bool LoadParameterFile(ISimObjectCreator* creator);
331
332 // Integrator anti windup
333 double IntegratorAntiWindup(const double* const adX, StateType *p_StateInfo, double Dot);
334
335 double CalcInM(); // Inlet manifold calculations
336 void CalcCC(); // Combustion chamber calculations
337 double CalcExM(); // Exhaust manifold calculations
338 double CalcTC(); // Turbo charger calculations
339 double CalcCS(const double T, const double* const X); // Crank shaft calculations
340 void CalcIC(); // Intercooler calculations
341 double CalcECUWG(const double T, const double* const X); // ECU wastegate control
342 double CalcECUMaxFuelPrCycle(const double T, const double* const X); // ECU Max allowed fuel pr cycle control
343 double CalcECUFuelPrCycle(const double T, const double* const X); // ECU fuel pr cycle controller
344
345 // PI controller
346 double PIController(PIType *p_PI, StateType *p_State, const double* const adX);
347
350
352 StateType mS_p_InM; // Pressure intake manifold
353 StateType mS_p_ExM; // Pressure Exhaust manifold
354 StateType mS_N_eng; // Engine speed
355 StateType mS_N_TC; // Turbo charger speed
356
357 StateType mS_PI_N_eng; // Integrator for ECU PI speed controller
358 StateType mS_PI_Lambda; // Integrator for ECU Lambda controller
359 StateType mS_PI_WG; // Integrator for ECU Wastegate opening controller
360
363
366
367 CPrintDuringExec* m_Print; // Pointer to CPrintDuringExec
368
369#ifdef FH_VISUALIZATION
370 Ogre::SceneNode* m_RenderNode;
371#endif
372};
Definition: CIEngine.h:269
ModelInType m_InMod
Model input indexes.
Definition: CIEngine.h:362
const double * out_CC_IMEP(const double T, const double *const X)
Output functions.
CCIEngine(const string &simobjectname, ISimObjectCreator *const creator)
The constructor sets the pointer to the output object and the parser object.
bool LoadParameterFile(ISimObjectCreator *creator)
Loads engine parameters from xml file.
void OdeFcn(const double T, const double *const X, double *const XDot, const bool bIsMajorTimeStep)
Calculates the state derivatives.
ModParType m_ModPar
Model parameters.
Definition: CIEngine.h:349
ModVarType m_Var
Model variables used in the different submodels.
Definition: CIEngine.h:365
StateType mS_p_InM
States.
Definition: CIEngine.h:352
Definition: CIEngine.h:120
Definition: CIEngine.h:43
Definition: CIEngine.h:163
Definition: CIEngine.h:67
Definition: CIEngine.h:206
Definition: CIEngine.h:151
Definition: CIEngine.h:61
Definition: CIEngine.h:32
Definition: CIEngine.h:235
Definition: CIEngine.h:195
Definition: CIEngine.h:83
Definition: CIEngine.h:139
Definition: CIEngine.h:55
Definition: CIEngine.h:89
Definition: CIEngine.h:220
Definition: CIEngine.h:106
Definition: CIEngine.h:256
Definition: CIEngine.h:245
Definition: CIEngine.h:176
Definition: CIEngine.h:74