From ff5f52d8529a8b889739c68db9a5541bd5c74299 Mon Sep 17 00:00:00 2001 From: Alexey Egorov Date: Thu, 29 Sep 2022 01:27:37 +0700 Subject: [PATCH] * Add camshaft reduction ratio to allow 2-stroke and steam engine simulation * Add intake atmosphere pressure and temperature to allow steam engines and supercharge --- es/objects/objects.mr | 16 ++++++++++++++-- include/camshaft.h | 4 ++++ include/intake.h | 9 +++++++++ scripting/include/camshaft_node.h | 1 + scripting/include/intake_node.h | 2 ++ src/camshaft.cpp | 4 +++- src/intake.cpp | 12 ++++++++---- 7 files changed, 41 insertions(+), 7 deletions(-) diff --git a/es/objects/objects.mr b/es/objects/objects.mr index e6f1d25d..0062547a 100644 --- a/es/objects/objects.mr +++ b/es/objects/objects.mr @@ -449,12 +449,14 @@ public node camshaft_parameters { input advance: 0.0; input base_radius: 0.0; input lobe_profile: function(); + input reduction_ratio: 0.5; } private node _camshaft => __engine_sim__camshaft { input advance [float]; input base_radius [float]; input lobe_profile [function]; + input reduction_ratio [float]; alias output __out [camshaft_channel]; } @@ -463,11 +465,13 @@ public node camshaft { input advance: parameters.advance; input base_radius: parameters.base_radius; input lobe_profile: parameters.lobe_profile; + input reduction_ratio: parameters.reduction_ratio; alias output __out [_camshaft]: _camshaft( advance: advance, base_radius: base_radius, - lobe_profile: lobe_profile + lobe_profile: lobe_profile, + reduction_ratio: reduction_ratio ); } @@ -483,6 +487,8 @@ public node intake_parameters { input runner_length: 4.0 * units.inch; input runner_flow_rate: k_carb(200.0); input velocity_decay: 0.25; + input atmosphere_pressure: 1.0 * units.atm; + input atmosphere_temperature: 25.0 + units.K0; } private node _intake => __engine_sim__intake { @@ -496,6 +502,8 @@ private node _intake => __engine_sim__intake { input throttle_gamma [float]; input runner_length [float]; input velocity_decay [float]; + input atmosphere_pressure [float]; + input atmosphere_temperature [float]; alias output __out [intake_channel]; } @@ -511,6 +519,8 @@ public node intake { input throttle_gamma: parameters.throttle_gamma; input runner_length: parameters.runner_length; input velocity_decay: parameters.velocity_decay; + input atmosphere_pressure: parameters.atmosphere_pressure; + input atmosphere_temperature: parameters.atmosphere_temperature; alias output __out [_intake]: _intake( plenum_volume: plenum_volume, @@ -522,7 +532,9 @@ public node intake { idle_throttle_plate_position: idle_throttle_plate_position, throttle_gamma: throttle_gamma, runner_length: runner_length, - velocity_decay: velocity_decay + velocity_decay: velocity_decay, + atmosphere_pressure: atmosphere_pressure, + atmosphere_temperature: atmosphere_temperature ); } diff --git a/include/camshaft.h b/include/camshaft.h index 73e0ed95..6b6f5c48 100644 --- a/include/camshaft.h +++ b/include/camshaft.h @@ -16,6 +16,9 @@ class Camshaft : public Part { // Camshaft advance in camshaft degrees double Advance = 0; + // Camshaft to crankshaft reduction ratio + double ReductionRatio = 0.5; + // Corresponding crankshaft Crankshaft *Crankshaft; @@ -51,6 +54,7 @@ class Camshaft : public Part { double *m_lobeAngles; double m_advance; double m_baseRadius; + double m_reductionRatio; int m_lobes; }; diff --git a/include/intake.h b/include/intake.h index 4555a116..ebb0d41a 100644 --- a/include/intake.h +++ b/include/intake.h @@ -34,6 +34,13 @@ class Intake : public Part { // Velocity decay factor double VelocityDecay = 0.5; + + // Atmospere pressure + double AtmospherePressure = units::pressure(1.0, units::atm); + + // Atmospere pressure + double AtmosphereTemperature = units::celcius(25.0); + }; public: @@ -67,6 +74,8 @@ class Intake : public Part { double m_idleThrottlePlatePosition; double m_runnerLength; double m_velocityDecay; + double m_atmospherePressure; + double m_atmosphereTemperature; GasSystem m_atmosphere; }; diff --git a/scripting/include/camshaft_node.h b/scripting/include/camshaft_node.h index f4e20371..cefadae2 100644 --- a/scripting/include/camshaft_node.h +++ b/scripting/include/camshaft_node.h @@ -44,6 +44,7 @@ namespace es_script { addInput("advance", &m_parameters.Advance); addInput("base_radius", &m_parameters.BaseRadius); addInput("lobe_profile", &m_lobeProfile); + addInput("reduction_ratio", &m_parameters.ReductionRatio); ObjectReferenceNode::registerInputs(); } diff --git a/scripting/include/intake_node.h b/scripting/include/intake_node.h index d92f9dc7..610e2c49 100644 --- a/scripting/include/intake_node.h +++ b/scripting/include/intake_node.h @@ -38,6 +38,8 @@ namespace es_script { addInput("throttle_gamma", &m_throttleGammaUnused); addInput("runner_length", &m_parameters.RunnerLength); addInput("velocity_decay", &m_parameters.VelocityDecay); + addInput("atmosphere_pressure", &m_parameters.AtmospherePressure); + addInput("atmosphere_temperature", &m_parameters.AtmosphereTemperature); ObjectReferenceNode::registerInputs(); } diff --git a/src/camshaft.cpp b/src/camshaft.cpp index 47365b04..ef574844 100644 --- a/src/camshaft.cpp +++ b/src/camshaft.cpp @@ -14,6 +14,7 @@ Camshaft::Camshaft() { m_lobes = 0; m_advance = 0; m_baseRadius = 0; + m_reductionRatio = 0.5; } Camshaft::~Camshaft() { @@ -29,6 +30,7 @@ void Camshaft::initialize(const Parameters ¶ms) { m_lobeProfile = params.LobeProfile; m_advance = params.Advance; m_baseRadius = params.BaseRadius; + m_reductionRatio = params.ReductionRatio; } void Camshaft::destroy() { @@ -52,7 +54,7 @@ double Camshaft::sampleLobe(double theta) const { double Camshaft::getAngle() const { const double angle = - std::fmod((m_crankshaft->getAngle() + m_advance) * 0.5, 2 * constants::pi); + std::fmod((m_crankshaft->getAngle() + m_advance) * m_reductionRatio, 2 * constants::pi); return (angle < 0) ? angle + 2 * constants::pi : angle; diff --git a/src/intake.cpp b/src/intake.cpp index a3546ee3..1b645e38 100644 --- a/src/intake.cpp +++ b/src/intake.cpp @@ -15,6 +15,8 @@ Intake::Intake() { m_totalFuelInjected = 0; m_molecularAfr = 0; m_runnerLength = 0; + m_atmospherePressure = units::pressure(1.0, units::atm); + m_atmosphereTemperature = units::celcius(25.0); } Intake::~Intake() { @@ -34,9 +36,9 @@ void Intake::initialize(Parameters ¶ms) { 0.0); m_atmosphere.initialize( - units::pressure(1.0, units::atm), + params.AtmospherePressure, units::volume(1000.0, units::m3), - units::celcius(25.0)); + params.AtmosphereTemperature); m_atmosphere.setGeometry( units::distance(100.0, units::m), units::distance(100.0, units::m), @@ -51,6 +53,8 @@ void Intake::initialize(Parameters ¶ms) { m_crossSectionArea = params.CrossSectionArea; m_velocityDecay = params.VelocityDecay; m_runnerFlowRate = params.RunnerFlowRate; + m_atmospherePressure = params.AtmospherePressure; + m_atmosphereTemperature = params.AtmosphereTemperature; } void Intake::destroy() { @@ -84,13 +88,13 @@ void Intake::process(double dt) { flowParams.direction_y = -1.0; flowParams.dt = dt; - m_atmosphere.reset(units::pressure(1.0, units::atm), units::celcius(25.0), fuelAirMix); + m_atmosphere.reset(m_atmospherePressure, m_atmosphereTemperature, 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); + m_atmosphere.reset(m_atmospherePressure, m_atmosphereTemperature, fuelMix); flowParams.system_0 = &m_atmosphere; flowParams.system_1 = &m_system; flowParams.k_flow = m_idleFlowK;