From 5e379b1cf70006dbe782df991a655c475630a146 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sun, 2 Mar 2025 12:03:54 -0500 Subject: engine tests --- engine.c | 2 +- test.c | 5 +++- test.h | 10 +++++++- test_engine.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 95 insertions(+), 4 deletions(-) diff --git a/engine.c b/engine.c index 00b3b48..ad1932e 100644 --- a/engine.c +++ b/engine.c @@ -98,5 +98,5 @@ density_ratio(const Engine *e) { p3 = e->map; t1 = e->ambient_temperature; t3 = manifold_temperature(e); - return (p1 * t3) / (p3 * t1); + return (p3 * t1) / (p1 * t3); } diff --git a/test.c b/test.c index afaff5d..72952f5 100644 --- a/test.c +++ b/test.c @@ -49,7 +49,10 @@ main(void) { test_as_cubic_foot_per_min(); test_comp_outlet_pressure(); - test_comp_outlet_temperature(); test_pressure_ratio(); + test_pressure_ratio_intercooled(); + test_comp_outlet_temperature_adiabatic(); + test_comp_outlet_temperature(); + test_manifold_temperature(); test_volume_flow_rate(); } diff --git a/test.h b/test.h index 4504b00..4f14ef8 100644 --- a/test.h +++ b/test.h @@ -2,7 +2,7 @@ #define test(got, want) { \ if (got < want-EPSILON || got > want+EPSILON) { \ - fprintf(stderr, "got %f; want %f\n", got, want); \ + fprintf(stderr, "got %.7f; want %.7f\n", got, want); \ assert(got == want); \ } \ } @@ -53,3 +53,11 @@ void test_cubic_foot_per_min(void); void test_as_cubic_metre_per_sec(void); void test_as_cubic_metre_per_min(void); void test_as_cubic_foot_per_min(void); + +void test_comp_outlet_pressure(void); +void test_pressure_ratio(void); +void test_pressure_ratio_intercooled(void); +void test_comp_outlet_temperature_adiabatic(void); +void test_comp_outlet_temperature(void); +void test_manifold_temperature(void); +void test_volume_flow_rate(void); diff --git a/test_engine.c b/test_engine.c index 12f0c21..76e58fa 100644 --- a/test_engine.c +++ b/test_engine.c @@ -5,4 +5,84 @@ #include "unit.h" #include "engine.h" -/* TODO */ +void +test_comp_outlet_pressure(void) { + Engine e; + init_engine(&e); + e.map = millibar(2000); + e.intercooler_deltap = psi(0.4); + test(comp_outlet_pressure(&e), millibar(2027.579029173)); +} + +void +test_pressure_ratio(void) { + Engine e = { + .ambient_pressure = psi(14.3), + .map = psi(14.3+18), + }; + test(pressure_ratio(&e), 2.2587413); + +} +void +test_pressure_ratio_intercooled(void) { + Engine e = { + .ambient_pressure = psi(14.3), + .map = psi(14.3+18), + .intercooler_deltap = psi(0.4), + }; + test(pressure_ratio(&e), 2.2867133); +} + +void +test_comp_outlet_temperature_adiabatic(void) { + Engine e = { + .ambient_temperature = fahrenheit(70), + .ambient_pressure = psi(14.7), + .map = psi(31.7), + .comp_efficiency = percent(100), + }; + test(comp_outlet_temperature(&e), kelvin(366.4715514)); +} + +void +test_comp_outlet_temperature(void) { + Engine e = { + .ambient_temperature = fahrenheit(70), + .ambient_pressure = psi(14.7), + .map = psi(31.7), + .comp_efficiency = percent(70), + }; + test(comp_outlet_temperature(&e), kelvin(397.418883)); +} + +void +test_manifold_temperature(void) { + Engine e = { + .ambient_temperature = fahrenheit(80), + .ambient_pressure = millibar(1015.9166), + .map = millibar(2031.8332), + .comp_efficiency = percent(70), + .intercooler_efficiency = percent(70), + }; + test(manifold_temperature(&e), kelvin(327.9429247)); +} + + +void +test_volume_flow_rate(void) { + Pressure p_ambient, p_boost, map; + + p_ambient = millibar(982.052713333343); + p_boost = psi(10); + map = p_ambient + p_boost; + Engine e = { + .displacement = cubic_inch(250), + .rpm = rpm(5000), + .map = map, + .ambient_temperature = fahrenheit(70), + .ambient_pressure = p_ambient, + .ve = percent(80), + .comp_efficiency = percent(65), + }; + test(volume_flow_rate(&e), cubic_metre_per_sec(0.1855992)); +} -- cgit v1.2.3