Skip to content

Commit

Permalink
phemlight now respects maximumpower #14285, removing unused code #12
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Feb 16, 2024
1 parent f3da4fb commit b5b549c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 59 deletions.
54 changes: 5 additions & 49 deletions src/foreign/PHEMlight/V5/cpp/CEP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,49 +193,12 @@ namespace PHEMlightdllV5 {
privateRatedPower = value;
}

double CEP::CalcPower(double speed, double acc, double gradient, bool HBEV) {
//Declaration
double power = 0;
double rotFactor = GetRotationalCoeffecient(speed);
double powerAux = (_auxPower * getRatedPower());

//Calculate the power
power += (_massVehicle + _vehicleLoading) * Constants::GRAVITY_CONST * (_resistanceF0 + _resistanceF1 * speed + _resistanceF4 * std::pow(speed, 4)) * speed;
power += (_crossSectionalArea * _cWValue * Constants::AIR_DENSITY_CONST / 2) * std::pow(speed, 3);
power += (_massVehicle * rotFactor + _vehicleMassRot + _vehicleLoading) * acc * speed;
power += (_massVehicle + _vehicleLoading) * Constants::GRAVITY_CONST * gradient * 0.01 * speed;
power /= 1000;
power /= Constants::_DRIVE_TRAIN_EFFICIENCY;
if (!HBEV) {
power += powerAux;
}

//Return result
return power;
}

double CEP::CalcWheelPower(double speed, double acc, double gradient) {
//Declaration
double power = 0;
double rotFactor = GetRotationalCoeffecient(speed);

//Calculate the power
power += (_massVehicle + _vehicleLoading) * Constants::GRAVITY_CONST * (_resistanceF0 + _resistanceF1 * speed + _resistanceF4 * std::pow(speed, 4)) * speed;
power += (_crossSectionalArea * _cWValue * Constants::AIR_DENSITY_CONST / 2) * std::pow(speed, 3);
power += (_massVehicle * rotFactor + _vehicleMassRot + _vehicleLoading) * acc * speed;
power += (_massVehicle + _vehicleLoading) * Constants::GRAVITY_CONST * gradient * 0.01 * speed;
power /= 1000;

//Return result
return power;
}

double CEP::CalcEngPower(double power) {
if (power < _normalizedPowerPatternFCvalues.front() * getRatedPower()) {
return _normalizedPowerPatternFCvalues.front() * getRatedPower();
double CEP::CalcEngPower(double power, const double ratedPower) {
if (power < _normalizedPowerPatternFCvalues.front() * ratedPower) {
return _normalizedPowerPatternFCvalues.front() * ratedPower;
}
if (power > _normalizedPowerPatternFCvalues.back() * getRatedPower()) {
return _normalizedPowerPatternFCvalues.back() * getRatedPower();
if (power > _normalizedPowerPatternFCvalues.back() * ratedPower) {
return _normalizedPowerPatternFCvalues.back() * ratedPower;
}

return power;
Expand Down Expand Up @@ -495,13 +458,6 @@ namespace PHEMlightdllV5 {
return e1 + (px - p1) / (p2 - p1) * (e2 - e1);
}

double CEP::GetMaxAccel(double speed, double gradient, bool HBEV) {
double rotFactor = GetRotationalCoeffecient(speed);
double pMaxForAcc = GetPMaxNorm(speed) * getRatedPower() - CalcPower(speed, 0, gradient, HBEV);

return (pMaxForAcc * 1000) / ((_massVehicle * rotFactor + _vehicleMassRot + _vehicleLoading) * speed);
}

double CEP::GetPMaxNorm(double speed) {
// Linear function between v0 and v1, constant elsewhere
if (speed <= _pNormV0) {
Expand Down
8 changes: 1 addition & 7 deletions src/foreign/PHEMlight/V5/cpp/CEP.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ namespace PHEMlightdllV5 {
std::vector<double> _dragNormTable;

public:
double CalcPower(double speed, double acc, double gradient, bool HBEV);

double CalcWheelPower(double speed, double acc, double gradient);

double CalcEngPower(double power);
double CalcEngPower(double power, const double ratedPower);

double GetEmission(const std::string& pollutant, double power, double speed, Helpers* VehicleClass, const double drivingPower, const double ratedPower);

Expand All @@ -157,8 +153,6 @@ namespace PHEMlightdllV5 {
double Interpolate(double px, double p1, double p2, double e1, double e2);

public:
double GetMaxAccel(double speed, double gradient, bool HBEV);

double GetPMaxNorm(double speed);

//--------------------------------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions src/utils/emissions/HelpersPHEMlight5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ HelpersPHEMlight5::getModifiedAccel(const SUMOEmissionClass c, const double v, c
const double mass = param->getDoubleOptional(SUMO_ATTR_MASS, currCep->getVehicleMass());
const double massRot = currCep->getVehicleMassRot();
const double load = param->getDoubleOptional(SUMO_ATTR_LOADING, currCep->getVehicleLoading());
const double pMaxForAcc = currCep->GetPMaxNorm(v) * currCep->getRatedPower() - calcPower(currCep, v, 0, slope, param);
const double ratedPower = param->getDoubleOptional(SUMO_ATTR_MAXIMUMPOWER, currCep->getRatedPower());
const double pMaxForAcc = currCep->GetPMaxNorm(v) * ratedPower - calcPower(currCep, v, 0, slope, param);
const double maxAcc = (pMaxForAcc * 1000) / ((mass * rotFactor + massRot + load) * v);
return MIN2(a, maxAcc);
}
Expand Down Expand Up @@ -213,13 +214,13 @@ HelpersPHEMlight5::compute(const SUMOEmissionClass c, const PollutantsInterface:
const bool isBEV = currCep->getFuelType() == PHEMlightdllV5::Constants::strBEV;
const bool isHybrid = currCep->getCalcType() == PHEMlightdllV5::Constants::strHybrid;
const double power_raw = calcPower(currCep, corrSpeed, corrAcc, slope, param);
const double power = isHybrid ? calcWheelPower(currCep, corrSpeed, corrAcc, slope, param) : currCep->CalcEngPower(power_raw);
const double ratedPower = param->getDoubleOptional(SUMO_ATTR_MAXIMUMPOWER, currCep->getRatedPower());
const double power = isHybrid ? calcWheelPower(currCep, corrSpeed, corrAcc, slope, param) : currCep->CalcEngPower(power_raw, ratedPower);

if (!isBEV && corrAcc < getCoastingDecel(c, corrSpeed, corrAcc, slope, param) &&
corrSpeed > PHEMlightdllV5::Constants::ZERO_SPEED_ACCURACY) {
return 0.;
}
const double ratedPower = param->getDoubleOptional(SUMO_ATTR_MAXIMUMPOWER, currCep->getRatedPower());
// TODO: this is probably only needed for non-heavy vehicles, so if execution speed becomes an issue this could be optimized out
const double drivingPower = calcPower(currCep, PHEMlightdllV5::Constants::NORMALIZING_SPEED, PHEMlightdllV5::Constants::NORMALIZING_ACCELARATION, 0, param);
switch (e) {
Expand Down

0 comments on commit b5b549c

Please sign in to comment.