forked from bobsayshilol/engine-sim
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintake.cpp
More file actions
111 lines (93 loc) · 3.28 KB
/
intake.cpp
File metadata and controls
111 lines (93 loc) · 3.28 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
#include "../include/intake.h"
#include "../include/units.h"
#include <cmath>
Intake::Intake() {
m_inputFlowK = 0;
m_idleFlowK = 0;
m_flow = 0;
m_throttle = 1.0;
m_idleThrottlePlatePosition = 0.0;
m_crossSectionArea = 0.0;
m_flowRate = 0;
m_totalFuelInjected = 0;
m_molecularAfr = 0;
m_throttleGamma = 1.0;
m_runnerLength = 0;
}
Intake::~Intake() {
/* void */
}
void Intake::initialize(Parameters ¶ms) {
const double width = std::sqrt(params.CrossSectionArea);
m_system.initialize(
units::pressure(1.0, units::atm),
params.Volume,
units::celcius(25.0));
m_system.setGeometry(
width,
params.Volume / params.CrossSectionArea,
1.0,
0.0);
m_atmosphere.initialize(
units::pressure(1.0, units::atm),
units::volume(1000.0, units::m3),
units::celcius(25.0));
m_atmosphere.setGeometry(
units::distance(100.0, units::m),
units::distance(100.0, units::m),
1.0,
0.0);
m_inputFlowK = params.InputFlowK;
m_molecularAfr = params.MolecularAfr;
m_idleFlowK = params.IdleFlowK;
m_idleThrottlePlatePosition = params.IdleThrottlePlatePosition;
m_throttleGamma = params.ThrottleGamma;
m_runnerLength = params.RunnerLength;
m_crossSectionArea = params.CrossSectionArea;
m_velocityDecay = params.VelocityDecay;
m_runnerFlowRate = params.RunnerFlowRate;
}
void Intake::destroy() {
/* void */
}
void Intake::process(double dt) {
const double ideal_afr = 0.8 * m_molecularAfr * 4;
const double current_afr = (m_system.mix().p_o2 + m_system.mix().p_inert) / m_system.mix().p_fuel;
const double p_air = ideal_afr / (1 + ideal_afr);
GasSystem::Mix fuelAirMix;
fuelAirMix.p_fuel = 1 - p_air;
fuelAirMix.p_inert = p_air * 0.75;
fuelAirMix.p_o2 = p_air * 0.25;
const double idle_afr = 2.0;
const double p_idle_air = idle_afr / (1 + idle_afr);
GasSystem::Mix fuelMix;
fuelMix.p_fuel = (1.0 - p_idle_air);
fuelMix.p_inert = p_idle_air * 0.75;
fuelMix.p_o2 = p_idle_air * 0.25;
const double throttle = getThrottlePlatePosition();
const double flowAttenuation = std::pow(std::cos(throttle * constants::pi / 2), m_throttleGamma);
GasSystem::FlowParameters flowParams;
flowParams.crossSectionArea_0 = units::area(10, units::m2);
flowParams.crossSectionArea_1 = m_crossSectionArea;
flowParams.direction_x = 0.0;
flowParams.direction_y = -1.0;
flowParams.dt = dt;
m_atmosphere.reset(units::pressure(1.0, units::atm), units::celcius(25.0), fuelAirMix);
flowParams.system_0 = &m_atmosphere;
flowParams.system_1 = &m_system;
flowParams.k_flow = flowAttenuation * m_inputFlowK;
m_flow = m_system.flow(flowParams);
m_atmosphere.reset(units::pressure(1.0, units::atm), units::celcius(25.0), fuelMix);
flowParams.system_0 = &m_atmosphere;
flowParams.system_1 = &m_system;
flowParams.k_flow = m_idleFlowK;
const double idleCircuitFlow = m_system.flow(flowParams);
m_system.dissipateExcessVelocity();
m_system.updateVelocity(dt, m_velocityDecay);
if (m_flow > 0) {
m_totalFuelInjected += fuelAirMix.p_fuel * m_flow;
}
if (idleCircuitFlow > 0) {
m_totalFuelInjected += fuelMix.p_fuel * idleCircuitFlow;
}
}