Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow building 2stroke and steam engines + free supercharge for fun #309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions es/objects/objects.mr
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -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
);
}

Expand All @@ -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 {
Expand All @@ -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];
}

Expand All @@ -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,
Expand All @@ -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
);
}

Expand Down
4 changes: 4 additions & 0 deletions include/camshaft.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,6 +54,7 @@ class Camshaft : public Part {
double *m_lobeAngles;
double m_advance;
double m_baseRadius;
double m_reductionRatio;
int m_lobes;
};

Expand Down
9 changes: 9 additions & 0 deletions include/intake.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions scripting/include/camshaft_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<CamshaftNode>::registerInputs();
}
Expand Down
2 changes: 2 additions & 0 deletions scripting/include/intake_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<IntakeNode>::registerInputs();
}
Expand Down
4 changes: 3 additions & 1 deletion src/camshaft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Camshaft::Camshaft() {
m_lobes = 0;
m_advance = 0;
m_baseRadius = 0;
m_reductionRatio = 0.5;
}

Camshaft::~Camshaft() {
Expand All @@ -29,6 +30,7 @@ void Camshaft::initialize(const Parameters &params) {
m_lobeProfile = params.LobeProfile;
m_advance = params.Advance;
m_baseRadius = params.BaseRadius;
m_reductionRatio = params.ReductionRatio;
}

void Camshaft::destroy() {
Expand All @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions src/intake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -34,9 +36,9 @@ void Intake::initialize(Parameters &params) {
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),
Expand All @@ -51,6 +53,8 @@ void Intake::initialize(Parameters &params) {
m_crossSectionArea = params.CrossSectionArea;
m_velocityDecay = params.VelocityDecay;
m_runnerFlowRate = params.RunnerFlowRate;
m_atmospherePressure = params.AtmospherePressure;
m_atmosphereTemperature = params.AtmosphereTemperature;
}

void Intake::destroy() {
Expand Down Expand Up @@ -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;
Expand Down