Skip to content

Commit

Permalink
unifying mass handling and adding loading parameter #13056 #14285
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Feb 6, 2024
1 parent 165018b commit b6718fa
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 33 deletions.
9 changes: 9 additions & 0 deletions src/microsim/MSVehicleType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ MSVehicleType::setShape(SUMOVehicleShape shape) {
// ------------ Static methods for building vehicle types
MSVehicleType*
MSVehicleType::build(SUMOVTypeParameter& from) {
if (from.hasParameter("vehicleMass")) {
if (from.wasSet(VTYPEPARS_MASS_SET)) {
WRITE_WARNINGF(TL("The vType '%' has a 'mass' attribute and a 'vehicleMass' parameter. The 'mass' attribute will take precedence."), from.id);
} else {
WRITE_WARNINGF(TL("The vType '%' has a 'vehicleMass' parameter, which is deprecated. Please use the 'mass' attribute (for the empty mass) and the 'loading' parameter, if needed."), from.id);
from.mass = from.getDouble("vehicleMass", from.mass);
from.parametersSet |= VTYPEPARS_MASS_SET;
}
}
MSVehicleType* vtype = new MSVehicleType(from);
const double decel = from.getCFParam(SUMO_ATTR_DECEL, SUMOVTypeParameter::getDefaultDecel(from.vehicleClass));
const double emergencyDecel = from.getCFParam(SUMO_ATTR_EMERGENCYDECEL, SUMOVTypeParameter::getDefaultEmergencyDecel(from.vehicleClass, decel, MSGlobals::gDefaultEmergencyDecel));
Expand Down
6 changes: 4 additions & 2 deletions src/microsim/devices/MSDevice_Battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ MSDevice_Battery::getParameter(const std::string& key) const {
} else if (key == toString(SUMO_ATTR_CHARGINGSTATIONID)) {
return getChargingStationID();
} else if (key == toString(SUMO_ATTR_VEHICLEMASS)) {
return toString(myHolder.getEmissionParameters()->getDouble(SUMO_ATTR_VEHICLEMASS));
WRITE_WARNING(TL("Getting the vehicle mass via parameters is deprecated, please use getMass for the vehicle or its type."));
return toString(myHolder.getEmissionParameters()->getDouble(SUMO_ATTR_MASS));
}
throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
}
Expand All @@ -453,7 +454,8 @@ MSDevice_Battery::setParameter(const std::string& key, const std::string& value)
} else if (key == toString(SUMO_ATTR_MAXIMUMBATTERYCAPACITY)) {
setMaximumBatteryCapacity(doubleValue);
} else if (key == toString(SUMO_ATTR_VEHICLEMASS)) {
myHolder.getEmissionParameters()->setDouble(SUMO_ATTR_VEHICLEMASS, doubleValue);
WRITE_WARNING(TL("Setting the vehicle mass via parameters is deprecated, please use setMass for the vehicle or its type."));
myHolder.getEmissionParameters()->setDouble(SUMO_ATTR_MASS, doubleValue);
} else {
throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
}
Expand Down
18 changes: 4 additions & 14 deletions src/microsim/devices/MSDevice_ElecHybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,6 @@ MSDevice_ElecHybrid::MSDevice_ElecHybrid(SUMOVehicle& holder, const std::string&
} else {
myOverheadWireChargingPower = overheadWireChargingPower;
}

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());
params->checkParam(SUMO_ATTR_MAXIMUMPOWER, getID());
}


Expand Down Expand Up @@ -767,7 +755,8 @@ MSDevice_ElecHybrid::getParameter(const std::string& key) const {
} else if (key == toString(SUMO_ATTR_SUBSTATIONID)) {
return getTractionSubstationID();
} else if (key == toString(SUMO_ATTR_VEHICLEMASS)) {
return toString(myHolder.getEmissionParameters()->getDouble(SUMO_ATTR_VEHICLEMASS));
WRITE_WARNING(TL("Getting the vehicle mass via parameters is deprecated, please use getMass for the vehicle or its type."));
return toString(myHolder.getEmissionParameters()->getDouble(SUMO_ATTR_MASS));
}
throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
}
Expand Down Expand Up @@ -943,7 +932,8 @@ MSDevice_ElecHybrid::setParameter(const std::string& key, const std::string& val
} else if (key == toString(SUMO_ATTR_OVERHEADWIRECHARGINGPOWER)) {
myOverheadWireChargingPower = doubleValue;
} else if (key == toString(SUMO_ATTR_VEHICLEMASS)) {
myHolder.getEmissionParameters()->setDouble(SUMO_ATTR_VEHICLEMASS, doubleValue);
WRITE_WARNING(TL("Setting the vehicle mass via parameters is deprecated, please use setMass for the vehicle or its type."));
myHolder.getEmissionParameters()->setDouble(SUMO_ATTR_MASS, doubleValue);
} else {
throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
}
Expand Down
23 changes: 15 additions & 8 deletions src/utils/emissions/EnergyParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ EnergyParams::EnergyParams(const SUMOVTypeParameter* typeParams) :
myCharacteristicMapMap.at(item.first) = CharacteristicMap(typeParams->getParameter(toString(item.first)));
}
}
myMap[SUMO_ATTR_MASS] = typeParams->mass;
if (typeParams->wasSet(VTYPEPARS_MASS_SET)) {
myMap[SUMO_ATTR_MASS] = typeParams->mass;
}
myMap[SUMO_ATTR_LOADING] = typeParams->getDouble("loading", INVALID_DOUBLE);
myMap[SUMO_ATTR_WIDTH] = typeParams->width;
myMap[SUMO_ATTR_HEIGHT] = typeParams->height;
}
Expand All @@ -68,15 +71,24 @@ EnergyParams::EnergyParams(const SUMOEmissionClass c) {
myMap[SUMO_ATTR_WAITINGTIME] = -1.;

if (c != EMISSION_CLASS_UNSPECIFIED && StringUtils::startsWith(PollutantsInterface::getName(c), "PHEMlight5/")) {
myMap[SUMO_ATTR_VEHICLEMASS] = INVALID_DOUBLE;
myMap[SUMO_ATTR_MASS] = INVALID_DOUBLE;
myMap[SUMO_ATTR_LOADING] = INVALID_DOUBLE;
myMap[SUMO_ATTR_FRONTSURFACEAREA] = INVALID_DOUBLE;
myMap[SUMO_ATTR_AIRDRAGCOEFFICIENT] = INVALID_DOUBLE;
myMap[SUMO_ATTR_CONSTANTPOWERINTAKE] = INVALID_DOUBLE;
return;
}
const SUMOVTypeParameter::VClassDefaultValues defaultValues(SVC_PASSENGER);
myMap[SUMO_ATTR_MASS] = defaultValues.mass;
myMap[SUMO_ATTR_LOADING] = INVALID_DOUBLE;
myMap[SUMO_ATTR_WIDTH] = defaultValues.width;
myMap[SUMO_ATTR_HEIGHT] = defaultValues.height;

// default values from
// https://sumo.dlr.de/docs/Models/Electric.html#kia_soul_ev_2020
myMap[SUMO_ATTR_VEHICLEMASS] = 1830.;
if (c != EMISSION_CLASS_UNSPECIFIED && StringUtils::startsWith(PollutantsInterface::getName(c), "Energy/")) {
myMap[SUMO_ATTR_MASS] = 1830.;
}
myMap[SUMO_ATTR_FRONTSURFACEAREA] = 2.6;
myMap[SUMO_ATTR_AIRDRAGCOEFFICIENT] = 0.35;
myMap[SUMO_ATTR_INTERNALMOMENTOFINERTIA] = 0.01;
Expand All @@ -101,11 +113,6 @@ EnergyParams::EnergyParams(const SUMOEmissionClass c) {
myMap[SUMO_ATTR_INTERNALBATTERYRESISTANCE] = 0.1142; // [Ohm]
myMap[SUMO_ATTR_NOMINALBATTERYVOLTAGE] = 396.0; // [V]
myCharacteristicMapMap.insert(std::pair<SumoXMLAttr, CharacteristicMap>(SUMO_ATTR_POWERLOSSMAP, CharacteristicMap("2,1|-1e9,1e9;-1e9,1e9|0,0,0,0"))); // P_loss_EM = 0 W for all operating points in the default EV power loss map

const SUMOVTypeParameter::VClassDefaultValues defaultValues(SVC_PASSENGER);
myMap[SUMO_ATTR_MASS] = defaultValues.mass;
myMap[SUMO_ATTR_WIDTH] = defaultValues.width;
myMap[SUMO_ATTR_HEIGHT] = defaultValues.height;
}


Expand Down
4 changes: 2 additions & 2 deletions src/utils/emissions/HelpersEnergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ HelpersEnergy::compute(const SUMOEmissionClass /* c */, const PollutantsInterfac
// Approximation order could be improved. Refs. #2592.

const double lastV = v - ACCEL2SPEED(a);
const double mass = param->getDouble(SUMO_ATTR_VEHICLEMASS);
const double mass = param->getDouble(SUMO_ATTR_MASS) + param->getDoubleOptional(SUMO_ATTR_LOADING, 0.);

// calculate power needed for potential energy difference
double power = mass * GRAVITY * sin(DEG2RAD(slope)) * v;
Expand Down Expand Up @@ -157,7 +157,7 @@ HelpersEnergy::acceleration(const SUMOEmissionClass /* c */, const PollutantsInt
//
// Power used for accelerating, `Prest`, is the total used power minus power wasted by running resistances.

const double mass = param->getDouble(SUMO_ATTR_VEHICLEMASS);
const double mass = param->getDouble(SUMO_ATTR_MASS) + param->getDoubleOptional(SUMO_ATTR_LOADING, 0.);
double const1, const2, const3;
double Prest;
int numX;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/emissions/HelpersMMPEVEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ double HelpersMMPEVEM::compute(const SUMOEmissionClass /* c */,

// Extract all required parameters
// Vehicle mass
const double m = ptr_energyParams->getDouble(SUMO_ATTR_VEHICLEMASS);
const double m = ptr_energyParams->getDouble(SUMO_ATTR_MASS) + ptr_energyParams->getDoubleOptional(SUMO_ATTR_LOADING, 0.);
// Wheel radius
const double r_wheel = ptr_energyParams->getDouble(SUMO_ATTR_WHEELRADIUS);
// Internal moment of inertia
Expand Down
12 changes: 6 additions & 6 deletions src/utils/emissions/HelpersPHEMlight5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ double
HelpersPHEMlight5::calcWheelPower(PHEMlightdllV5::CEP* currCep, const double v, const double a, const double slope, const EnergyParams* param) const {
// copy of CEP::CalcWheelPower
const double rotFactor = currCep->GetRotationalCoeffecient(v);
const double mass = param->getDoubleOptional(SUMO_ATTR_VEHICLEMASS, currCep->getVehicleMass());
const double mass = param->getDoubleOptional(SUMO_ATTR_MASS, currCep->getVehicleMass());
const double massRot = currCep->getVehicleMassRot();
const double load = currCep->getVehicleLoading();
const double load = param->getDoubleOptional(SUMO_ATTR_LOADING, currCep->getVehicleLoading());
const double cw = param->getDoubleOptional(SUMO_ATTR_FRONTSURFACEAREA, currCep->getCrossSectionalArea()) * param->getDoubleOptional(SUMO_ATTR_AIRDRAGCOEFFICIENT, currCep->getCWValue());

double power = (mass + load) * PHEMlightdllV5::Constants::GRAVITY_CONST * currCep->getResistance(v) * v;
Expand All @@ -169,9 +169,9 @@ HelpersPHEMlight5::getModifiedAccel(const SUMOEmissionClass c, const double v, c
}
// this is a copy of CEP::GetMaxAccel
const double rotFactor = currCep->GetRotationalCoeffecient(v);
const double mass = param->getDoubleOptional(SUMO_ATTR_VEHICLEMASS, currCep->getVehicleMass());
const double mass = param->getDoubleOptional(SUMO_ATTR_MASS, currCep->getVehicleMass());
const double massRot = currCep->getVehicleMassRot();
const double load = currCep->getVehicleLoading();
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 maxAcc = (pMaxForAcc * 1000) / ((mass * rotFactor + massRot + load) * v);
return MIN2(a, maxAcc);
Expand All @@ -188,8 +188,8 @@ HelpersPHEMlight5::getCoastingDecel(const SUMOEmissionClass c, const double v, c
return v / PHEMlightdllV5::Constants::SPEED_DCEL_MIN * getCoastingDecel(c, PHEMlightdllV5::Constants::SPEED_DCEL_MIN, a, slope, param);
}
const double rotFactor = currCep->GetRotationalCoeffecient(v);
const double mass = param->getDoubleOptional(SUMO_ATTR_VEHICLEMASS, currCep->getVehicleMass());
const double load = currCep->getVehicleLoading();
const double mass = param->getDoubleOptional(SUMO_ATTR_MASS, currCep->getVehicleMass());
const double load = param->getDoubleOptional(SUMO_ATTR_LOADING, currCep->getVehicleLoading());
const double cw = param->getDoubleOptional(SUMO_ATTR_FRONTSURFACEAREA, currCep->getCrossSectionalArea()) * param->getDoubleOptional(SUMO_ATTR_AIRDRAGCOEFFICIENT, currCep->getCWValue());

const double fRoll = currCep->getResistance(v, true) * (mass + load) * PHEMlightdllV5::Constants::GRAVITY_CONST;
Expand Down
1 change: 1 addition & 0 deletions src/utils/xml/SUMOXMLDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ StringBijection<int>::Entry SUMOXMLDefinitions::attrs[] = {
// general emission / consumption
{ "shutOffStopDuration", SUMO_ATTR_SHUT_OFF_STOP },
{ "shutOffAutoDuration", SUMO_ATTR_SHUT_OFF_AUTO },
{ "loading", SUMO_ATTR_LOADING },

{ "sigma", SUMO_ATTR_SIGMA },
{ "sigmaStep", SUMO_ATTR_SIGMA_STEP },
Expand Down
2 changes: 2 additions & 0 deletions src/utils/xml/SUMOXMLDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,8 @@ enum SumoXMLAttr {
SUMO_ATTR_SHUT_OFF_STOP,
/// @brief engine gets switched off if stopping duration exceeds value
SUMO_ATTR_SHUT_OFF_AUTO,
/// @brief additional mass loaded on the vehicle
SUMO_ATTR_LOADING,
/// @}

/// @name Car following model attributes
Expand Down

0 comments on commit b6718fa

Please sign in to comment.