LCOV - code coverage report
Current view: top level - unit_tests/tests - test_engine_math.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 74 78 94.9 %
Date: 2024-04-22 23:59:02 Functions: 13 13 100.0 %

          Line data    Source code
       1             : /*
       2             :  * @file        test_engine_math.c
       3             :  *
       4             :  * @date Nov 14, 2013
       5             :  * @author Andrey Belomutskiy, (c) 2012-2020
       6             :  */
       7             : 
       8             : #include "pch.h"
       9             : 
      10             : #include "speed_density.h"
      11             : #include "maf.h"
      12             : #include "advance_map.h"
      13             : 
      14           4 : TEST(misc, testIgnitionPlanning) {
      15           1 :         printf("*************************************************** testIgnitionPlanning\r\n");
      16           1 :         EngineTestHelper eth(engine_type_e::FORD_ESCORT_GT);
      17             : 
      18           1 :         engine->periodicFastCallback();
      19           1 :         assertEqualsM("testIgnitionPlanning_AFR", 13.5, engine->fuelComputer.targetAFR);
      20             : 
      21           1 :         ASSERT_EQ(IM_BATCH, engineConfiguration->injectionMode);
      22           1 : }
      23             : 
      24           4 : TEST(misc, testEngineMath) {
      25           1 :         printf("*************************************************** testEngineMath\r\n");
      26             : 
      27             :         // todo: let's see if we can make 'engine' unneeded in this test?
      28           1 :         EngineTestHelper eth(engine_type_e::FORD_ESCORT_GT);
      29             : 
      30           1 :     setCamOperationMode();
      31           1 :         engineConfiguration->fuelAlgorithm = LM_SPEED_DENSITY;
      32             : 
      33           1 :         ASSERT_NEAR( 50,  getOneDegreeTimeMs(600) * 180, EPS4D) << "600 RPM";
      34           1 :         ASSERT_EQ( 5,  getOneDegreeTimeMs(6000) * 180) << "6000 RPM";
      35             : 
      36           1 :         auto fuelComputer = &engine->fuelComputer;
      37             : 
      38           1 :         Sensor::setMockValue(SensorType::Clt, 300);
      39           1 :         Sensor::setMockValue(SensorType::Iat, 350);
      40           1 :         ASSERT_FLOAT_EQ(312.5, fuelComputer->getTCharge(1000, 0));
      41           1 :         ASSERT_FLOAT_EQ(313.5833, fuelComputer->getTCharge(1000, 50));
      42           1 :         ASSERT_FLOAT_EQ(314.6667, fuelComputer->getTCharge(1000, 100));
      43             : 
      44             : 
      45           1 :         ASSERT_FLOAT_EQ(312.5, fuelComputer->getTCharge(4000, 0));
      46           1 :         ASSERT_FLOAT_EQ(320.0833, fuelComputer->getTCharge(4000, 50));
      47           1 :         ASSERT_FLOAT_EQ(327.6667, fuelComputer->getTCharge(4000, 100));
      48             : 
      49             :         // test Air Interpolation mode
      50           1 :         engineConfiguration->tChargeMode = TCHARGE_MODE_AIR_INTERP;
      51           1 :         engineConfiguration->tChargeAirCoefMin = 0.098f;
      52           1 :         engineConfiguration->tChargeAirCoefMax = 0.902f;
      53           1 :         engineConfiguration->tChargeAirFlowMax = 153.6f;
      54             :         // calc. some airMass given the engine displacement=1.839 and 4 cylinders (FORD_ESCORT_GT)
      55           1 :         fuelComputer->sdAirMassInOneCylinder = SpeedDensityBase::getAirmassImpl(/*VE*/1.0f, /*MAP*/100.0f, /*tChargeK*/273.15f + 20.0f);
      56           1 :         ASSERT_NEAR(0.5464f, fuelComputer->sdAirMassInOneCylinder, EPS4D);
      57             : 
      58           1 :         Sensor::setMockValue(SensorType::Clt, 90);
      59           1 :         Sensor::setMockValue(SensorType::Iat, 20);
      60           1 :         Sensor::setMockValue(SensorType::Map, 100);
      61           1 :         Sensor::setMockValue(SensorType::Tps1, 0);
      62           1 :         Sensor::setMockValue(SensorType::Rpm, 1000);
      63             : 
      64             :         // calc. airFlow using airMass, and find tCharge
      65           1 :         engine->periodicFastCallback();
      66           1 :         ASSERT_NEAR(59.12f, engine->engineState.sd.tCharge, EPS4D);
      67           1 :         ASSERT_NEAR(56.9758f/*kg/h*/, engine->engineState.airflowEstimate, EPS4D);
      68           1 : }
      69             : 
      70             : typedef enum {
      71             :     CS_OPEN = 0,
      72             :     CS_CLOSED = 1,
      73             :     CS_SWIRL_TUMBLE = 2,
      74             : 
      75             : } chamber_style_e;
      76             : 
      77             : /**
      78             :  * @param octane gas octane number
      79             :  * @param bore in mm
      80             :  */
      81           4 : static float getTopAdvanceForBore(chamber_style_e style, int octane, double compression, double bore) {
      82             :     int octaneCorrection;
      83           4 :     if ( octane <= 90) {
      84           2 :         octaneCorrection = -2;
      85           2 :     } else if (octane < 94) {
      86           0 :         octaneCorrection = -1;
      87             :     } else {
      88           2 :         octaneCorrection = 0;
      89             :     }
      90             : 
      91             :     int compressionCorrection;
      92           4 :     if (compression <= 9) {
      93           3 :         compressionCorrection = 2;
      94           1 :     } else if (compression <= 10) {
      95           0 :         compressionCorrection = 1;
      96           1 :     } else if (compression <= 11) {
      97           1 :         compressionCorrection = 0;
      98             :     } else {
      99             :         // compression ratio above 11
     100           0 :         compressionCorrection = -2;
     101             :     }
     102             :     int base;
     103           4 :     if (style == CS_OPEN) {
     104           2 :         base = 33;
     105           2 :     } else if (style == CS_CLOSED) {
     106           0 :         base = 28;
     107             :     } else {
     108             :         // CS_SWIRL_TUMBLE
     109           2 :         base = 22;
     110             :     }
     111             : 
     112           4 :     float boreCorrection = (bore - 4 * 25.4) / 25.4 * 6;
     113           4 :     float result = base + octaneCorrection + compressionCorrection + boreCorrection;
     114           4 :     return ((int)(result * 10)) / 10.0;
     115             : }
     116             : 
     117             : 
     118           4 : TEST(misc, testIgnitionMapGenerator) {
     119           1 :         printf("*************************************************** testIgnitionMapGenerator\r\n");
     120             : 
     121           1 :         ASSERT_EQ(35, getTopAdvanceForBore(CS_OPEN, 98, 8, 101.6));
     122           1 :         ASSERT_EQ(33, getTopAdvanceForBore(CS_OPEN, 98, 11, 101.6));
     123             : 
     124           1 :         float rpmBin[16];
     125           1 :         setRpmBin(rpmBin, 16, 800, 7000);
     126           1 :         ASSERT_EQ(650, rpmBin[0]);
     127           1 :         ASSERT_EQ( 800,  rpmBin[1]) << "@1";
     128           1 :         ASSERT_EQ( 1100,  rpmBin[2]) << "@2";
     129           1 :         ASSERT_EQ( 1400,  rpmBin[3]) << "rpm@3";
     130           1 :         ASSERT_EQ( 4700,  rpmBin[14]) << "rpm@14";
     131           1 :         ASSERT_EQ(7000, rpmBin[15]);
     132             : 
     133             : 
     134           1 :         ASSERT_FLOAT_EQ(22.0, getTopAdvanceForBore(CS_SWIRL_TUMBLE, 89, 9, 101.6));
     135           1 :     ASSERT_FLOAT_EQ(32.2, getTopAdvanceForBore(CS_SWIRL_TUMBLE, 89, 9, 145));
     136             : 
     137           1 :     assertEqualsM2("100@6000", 36.0, getInitialAdvance(6000, 100, 36), 0.1);
     138           1 :     assertEqualsM2("100@600", 9.9, getInitialAdvance(600, 100, 36), 0.2);
     139             : 
     140           1 :     assertEqualsM2("2400", 34.2, getInitialAdvance(2400, 40, 36), 0.1);
     141           1 :     assertEqualsM2("4400", 41.9, getInitialAdvance(4400, 40, 36), 0.1);
     142           1 :     assertEqualsM2("20@800", 14.2, getInitialAdvance(800, 20, 36), 0.2);
     143             : }

Generated by: LCOV version 1.14