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