Skip to content

Commit

Permalink
reducing dependency between battery device and energy model #2212 #2775
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Feb 2, 2024
1 parent f803520 commit bbf87ea
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 20 deletions.
10 changes: 10 additions & 0 deletions src/microsim/MSVehicleType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,18 @@ MSVehicleType::check() {
toString(getVehicleClass()), getID());
}
}
if (!myParameter.wasSet(VTYPEPARS_EMISSIONCLASS_SET) && !OptionsCont::getOptions().getBool("device.battery.track-fuel")
&& (OptionsCont::getOptions().getFloat("device.battery.probability") == 1.
|| myParameter.getDouble("device.battery.probability", -1.) == 1.
|| StringUtils::toBool(myParameter.getParameter("has.battery.device", "false")))) {
myParameter.emissionClass = PollutantsInterface::getClassByName("Energy");
myParameter.parametersSet |= VTYPEPARS_EMISSIONCLASS_SET;
WRITE_WARNINGF(TL("The battery device is active for vType '%' but no emission class is set. The emission class Energy/unknown will be used, please consider setting an explicit emission class!"),
getID());
}
}


void
MSVehicleType::setAccel(double accel) {
if (myOriginalType != nullptr && accel < 0) {
Expand Down
32 changes: 13 additions & 19 deletions src/microsim/devices/MSDevice_Battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,12 @@ MSDevice_Battery::MSDevice_Battery(SUMOVehicle& holder, const std::string& id, c
myStoppingThreshold = stoppingThreshold;
}

EnergyParams* const params = myHolder.getEmissionParameters();
params->checkParam(SUMO_ATTR_VEHICLEMASS, getID());
params->checkParam(SUMO_ATTR_FRONTSURFACEAREA, getID());
params->checkParam(SUMO_ATTR_AIRDRAGCOEFFICIENT, getID());
params->checkParam(SUMO_ATTR_INTERNALMOMENTOFINERTIA, getID());
params->checkParam(SUMO_ATTR_RADIALDRAGCOEFFICIENT, getID());
params->checkParam(SUMO_ATTR_ROLLDRAGCOEFFICIENT, getID());
params->checkParam(SUMO_ATTR_CONSTANTPOWERINTAKE, getID());
params->checkParam(SUMO_ATTR_PROPULSIONEFFICIENCY, getID());
params->checkParam(SUMO_ATTR_RECUPERATIONEFFICIENCY, getID());
params->checkParam(SUMO_ATTR_RECUPERATIONEFFICIENCY_BY_DECELERATION, getID());

myTrackFuel = !PollutantsInterface::getEnergyHelper().includesClass(holder.getVehicleType().getEmissionClass()) && OptionsCont::getOptions().getBool("device.battery.track-fuel");
myTrackFuel = PollutantsInterface::getFuel(holder.getVehicleType().getEmissionClass()) != "Electricity" && OptionsCont::getOptions().getBool("device.battery.track-fuel");
if (!myTrackFuel && !holder.getVehicleType().getParameter().wasSet(VTYPEPARS_EMISSIONCLASS_SET)) {
WRITE_WARNINGF(TL("The battery device is active for vehicle '%' but no emission class is set. "
"Please consider setting an explicit emission class or battery outputs might be inconsistent with emission outputs!"),
holder.getID());
}
}


Expand All @@ -169,14 +162,15 @@ bool MSDevice_Battery::notifyMove(SUMOTrafficObject& tObject, double /* oldPos *
EnergyParams* const params = myHolder.getEmissionParameters();
if (getMaximumBatteryCapacity() != 0) {
params->setDouble(SUMO_ATTR_ANGLE, myLastAngle == std::numeric_limits<double>::infinity() ? 0. : GeomHelper::angleDiff(myLastAngle, veh.getAngle()));
if (myTrackFuel) {
// [ml]
myConsum = PollutantsInterface::compute(veh.getVehicleType().getEmissionClass(), PollutantsInterface::FUEL, veh.getSpeed(), veh.getAcceleration(),
veh.getSlope(), params) * TS;
} else {
// [Wh]
if (!myTrackFuel && !veh.getVehicleType().getParameter().wasSet(VTYPEPARS_EMISSIONCLASS_SET)) {
// no explicit emission class, we fall back to the energy model; a warning has been issued on creation
myConsum = PollutantsInterface::getEnergyHelper().compute(0, PollutantsInterface::ELEC, veh.getSpeed(), veh.getAcceleration(),
veh.getSlope(), params) * TS;
} else {
myConsum = PollutantsInterface::compute(veh.getVehicleType().getEmissionClass(),
myTrackFuel ? PollutantsInterface::FUEL : PollutantsInterface::ELEC,
veh.getSpeed(), veh.getAcceleration(),
veh.getSlope(), params) * TS;
}
if (veh.isParking()) {
// recuperation from last braking step is ok but further consumption should cease
Expand Down
7 changes: 7 additions & 0 deletions src/utils/emissions/HelpersEnergy.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class HelpersEnergy : public PollutantsInterface::Helper {
*/
HelpersEnergy();

/** @brief Returns the fuel type described by this emission class as described in the Amitran interface (Gasoline, Diesel, ...)
* @param[in] c the emission class
* @return always "Electricity"
*/
std::string getFuel(const SUMOEmissionClass /* c */) const {
return "Electricity";
}

/** @brief Computes the emitted pollutant amount using the given speed and acceleration
*
Expand Down
6 changes: 6 additions & 0 deletions src/utils/emissions/HelpersHBEFA4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10109,6 +10109,12 @@ HelpersHBEFA4::getFuel(const SUMOEmissionClass c) const {
if (name.find("_diesel_") != std::string::npos) {
fuel = "Diesel";
}
if (name.find("_BEV") != std::string::npos) {
fuel = "Electricity";
}
if (name.find("_PHEV") != std::string::npos) {
fuel = "Hybrid" + fuel;
}
return fuel;
}

Expand Down
8 changes: 8 additions & 0 deletions src/utils/emissions/HelpersMMPEVEM.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class HelpersMMPEVEM : public PollutantsInterface::Helper {
*/
HelpersMMPEVEM();

/** @brief Returns the fuel type described by this emission class as described in the Amitran interface (Gasoline, Diesel, ...)
* @param[in] c the emission class
* @return always "Electricity"
*/
std::string getFuel(const SUMOEmissionClass /* c */) const {
return "Electricity";
}

/**
* \brief Compute the amount of emitted pollutants for an emission class in a
* given state.
Expand Down
17 changes: 17 additions & 0 deletions src/utils/emissions/HelpersPHEMlight5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ HelpersPHEMlight5::getClassByName(const std::string& eClass, const SUMOVehicleCl
}


std::string
HelpersPHEMlight5::getFuel(const SUMOEmissionClass c) const {
const std::string name = myEmissionClassStrings.getString(c);
std::string fuel = "Gasoline";
if (name.find("_D_") != std::string::npos) {
fuel = "Diesel";
}
if (name.find("_BEV_") != std::string::npos) {
fuel = "Electricity";
}
if (name.find("_HEV") != std::string::npos) {
fuel = "Hybrid" + fuel;
}
return fuel;
}


double
HelpersPHEMlight5::getEmission(PHEMlightdllV5::CEP* currCep, const std::string& e, const double p, const double v, const double drivingPower) const {
return currCep->GetEmission(e, p, v, &myHelper, drivingPower);
Expand Down
6 changes: 6 additions & 0 deletions src/utils/emissions/HelpersPHEMlight5.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class HelpersPHEMlight5 : public HelpersPHEMlight {
*/
SUMOEmissionClass getClassByName(const std::string& eClass, const SUMOVehicleClass vc);

/** @brief Returns the fuel type described by this emission class as described in the Amitran interface (Gasoline, Diesel, ...)
* @param[in] c the emission class
* @return the fuel type
*/
std::string getFuel(const SUMOEmissionClass c) const;

/** @brief Returns the amount of emitted pollutant given the vehicle type and state (in mg/s or in ml/s for fuel)
* @param[in] c The vehicle emission class
* @param[in] v The vehicle's current velocity
Expand Down
2 changes: 1 addition & 1 deletion src/utils/emissions/PollutantsInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class PollutantsInterface {

/** @brief Returns the fuel type of the given emission class
* @param[in] c The vehicle emission class
* @return "Diesel", "Gasoline", "HybridDiesel", or "HybridGasoline"
* @return "Diesel", "Gasoline", "HybridDiesel", "HybridGasoline", or "Electricity"
*/
static std::string getFuel(const SUMOEmissionClass c);

Expand Down

0 comments on commit bbf87ea

Please sign in to comment.