Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
EnergyParams.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
19// A class for parameters used by the emission models
20/****************************************************************************/
21#include <config.h>
22
28
29#include "PollutantsInterface.h"
30#include "HelpersEnergy.h"
31#include "EnergyParams.h"
32
33
34// ===========================================================================
35// static definitions
36// ===========================================================================
38const std::vector<SumoXMLAttr> EnergyParams::myParamAttrs = {
47};
48
49
50// ===========================================================================
51// method definitions
52// ===========================================================================
54 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
55
56 if (typeParams == nullptr) {
58 myHaveDefaultMass = true;
61 } else {
62 for (SumoXMLAttr attr : myParamAttrs) {
63 if (typeParams->hasParameter(toString(attr))) {
64 myMap[attr] = typeParams->getDouble(toString(attr), INVALID_DOUBLE);
65 }
66 }
67 for (auto item : myCharacteristicMapMap) {
68 std::string characteristicMapString = typeParams->getParameter(toString(item.first), "");
69 if (characteristicMapString != "") {
70 myCharacteristicMapMap.at(item.first) = CharacteristicMap(typeParams->getParameter(toString(item.first)));
71 }
72 }
73 myMap[SUMO_ATTR_MASS] = typeParams->mass;
76 const double ecMass = PollutantsInterface::getWeight(typeParams->emissionClass);
77 if (ecMass != -1.) {
78 myMap[SUMO_ATTR_MASS] = ecMass;
79 }
80 }
81 if (myMap.count(SUMO_ATTR_FRONTSURFACEAREA) == 0) {
83 myMap[SUMO_ATTR_FRONTSURFACEAREA] = typeParams->width * typeParams->height * M_PI / 4.;
84 }
85 const std::string& ecName = PollutantsInterface::getName(typeParams->emissionClass);
87 if (StringUtils::startsWith(ecName, "MMPEVEM") || StringUtils::startsWith(ecName, "Energy")) {
88 WRITE_WARNINGF(TL("Vehicle type '%' uses the emission class '%' which does not have proper defaults for its vehicle class. "
89 "Please use a different emission model or complete the vType definition with further parameters."), typeParams->id, ecName);
90 if (!typeParams->wasSet(VTYPEPARS_MASS_SET)) {
91 WRITE_WARNING(TL(" And also set a vehicle mass!"));
92 }
93 }
94 }
95 if (!StringUtils::startsWith(ecName, "MMPEVEM")) {
97 WRITE_WARNINGF(TL("Vehicle type '%' uses the Energy model parameter 'internalMomentOfInertia' which is deprecated. Use 'rotatingMass' instead."), typeParams->id);
98 if (!typeParams->hasParameter(toString(SUMO_ATTR_ROTATINGMASS))) {
100 }
101 }
102 }
103 }
104}
105
106
108
109
110void
111EnergyParams::setDynamicValues(const SUMOTime stopDuration, const bool parking, const SUMOTime waitingTime, const double angle) {
112 if ((stopDuration >= 0. && myStopDurationSeconds < 0.) || (stopDuration < 0. && myStopDurationSeconds >= 0.)) {
113 myStopDurationSeconds = STEPS2TIME(stopDuration);
114 myAmParking = parking;
115 }
116 myWaitingTimeSeconds = STEPS2TIME(waitingTime);
118 myAngle = angle;
119}
120
121
122void
123EnergyParams::setMass(const double mass) {
124 myMap[SUMO_ATTR_MASS] = mass;
125 myHaveDefaultMass = false;
126}
127
128
129void
131 myTransportableMass = mass;
132}
133
134
135double
136EnergyParams::getTotalMass(const double defaultEmptyMass, const double defaultLoading) const {
137 return getDoubleOptional(SUMO_ATTR_MASS, defaultEmptyMass) + getDoubleOptional(SUMO_ATTR_LOADING, defaultLoading) + getTransportableMass();
138}
139
140
141double
145
146
147double
149 auto it = myMap.find(attr);
150 if (it != myMap.end()) {
151 return it->second;
152 }
153 if (mySecondaryParams != nullptr) {
154 return mySecondaryParams->getDouble(attr);
155 }
156 throw UnknownElement("Unknown emission model parameter: " + toString(attr));
157}
158
159
160double
161EnergyParams::getDoubleOptional(SumoXMLAttr attr, const double def) const {
162 auto it = myMap.find(attr);
163 if (it != myMap.end() && it->second != INVALID_DOUBLE) {
164 if (attr == SUMO_ATTR_MASS) {
165 if (!myHaveDefaultMass) {
166 return it->second;
167 }
168 } else if (attr == SUMO_ATTR_FRONTSURFACEAREA) {
170 return it->second;
171 }
172 } else {
173 return it->second;
174 }
175 }
176 if (mySecondaryParams != nullptr) {
177 return mySecondaryParams->getDoubleOptional(attr, def);
178 }
179 return def;
180}
181
182
185 auto it = myCharacteristicMapMap.find(attr);
186 if (it != myCharacteristicMapMap.end()) {
187 return it->second;
188 }
189 if (mySecondaryParams != nullptr) {
191 }
192 throw UnknownElement("Unknown emission model parameter: " + toString(attr));
193}
194
195
196bool
201
202
203bool
207
208
209/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:315
#define STEPS2TIME(x)
Definition SUMOTime.h:55
const long long int VTYPEPARS_MASS_SET
const double DEFAULT_VEH_HEIGHT
const double DEFAULT_VEH_SHUT_OFF_STOP
const double DEFAULT_VEH_MASS
const double DEFAULT_VEH_WIDTH
@ SVC_HOV
vehicle is a HOV
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_TAXI
vehicle is a taxi
@ SVC_E_VEHICLE
is an electric vehicle
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_GEAREFFICIENCY
Gear efficiency.
@ SUMO_ATTR_MAXIMUMPOWER
Maximum Power.
@ SUMO_ATTR_INTERNALBATTERYRESISTANCE
Internal battery resistance.
@ SUMO_ATTR_MAXIMUMTORQUE
Maximum torque.
@ SUMO_ATTR_MASS
@ SUMO_ATTR_ROLLDRAGCOEFFICIENT
Roll Drag coefficient.
@ SUMO_ATTR_CONSTANTPOWERINTAKE
Constant Power Intake.
@ SUMO_ATTR_LOADING
additional mass loaded on the vehicle
@ SUMO_ATTR_RECUPERATIONEFFICIENCY_BY_DECELERATION
Recuperation efficiency (by deceleration)
@ SUMO_ATTR_WHEELRADIUS
@ SUMO_ATTR_RECUPERATIONEFFICIENCY
Recuperation efficiency (constant)
@ SUMO_ATTR_AIRDRAGCOEFFICIENT
Air drag coefficient.
@ SUMO_ATTR_POWERLOSSMAP
A string encoding the power loss map.
@ SUMO_ATTR_MAXIMUMRECUPERATIONPOWER
Maximum recuperation power.
@ SUMO_ATTR_SHUT_OFF_STOP
@ SUMO_ATTR_MAXIMUMRECUPERATIONTORQUE
Maximum recuperation torque.
@ SUMO_ATTR_RADIALDRAGCOEFFICIENT
Radial drag coefficient.
@ SUMO_ATTR_GEARRATIO
Gear ratio.
@ SUMO_ATTR_ROTATINGMASS
Mass equivalent of rotating elements.
@ SUMO_ATTR_PROPULSIONEFFICIENCY
Propulsion efficiency.
@ SUMO_ATTR_INTERNALMOMENTOFINERTIA
Internal moment of inertia.
@ SUMO_ATTR_NOMINALBATTERYVOLTAGE
Nominal battery voltage.
@ SUMO_ATTR_FRONTSURFACEAREA
Front surface area.
@ SUMO_ATTR_SHUT_OFF_AUTO
engine gets switched off if stopping duration exceeds value
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:64
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
The purpose of this class is to store a characteristic map (German: Kennfeld) of arbitrary dimensions...
An upper class for objects with additional parameters.
double getDouble(SumoXMLAttr attr) const
Returns the value for a given key.
static const std::vector< SumoXMLAttr > myParamAttrs
void setMass(const double mass)
Sets the empty mass of the vehicle (type) This is to be used by traci/libsumo.
bool isOff() const
Returns whether the vehicle is currently consuming any energy derived from the parking state.
double getTotalMass(const double defaultEmptyMass, const double defaultLoading) const
Returns the sum of the empty mass (SUMO_ATTR_MASS), tthe loading (SUMO_ATTR_LOADING) and the mass of ...
static const EnergyParams * myDefault
bool myHaveDefaultMass
bool myHaveDefaultFrontSurfaceArea
double getDoubleOptional(SumoXMLAttr attr, const double def) const
Returns the value for a given key with an optional default. SUMO_ATTR_MASS and SUMO_ATTR_FRONTSURFACE...
double myWaitingTimeSeconds
std::map< SumoXMLAttr, double > myMap
The key->value maps.
EnergyParams(const SUMOVTypeParameter *typeParams=nullptr)
Constructor.
std::map< SumoXMLAttr, CharacteristicMap > myCharacteristicMapMap
double myTransportableMass
bool isEngineOff() const
Returns the state of the engine when the vehicle is not moving.
const EnergyParams * mySecondaryParams
const CharacteristicMap & getCharacteristicMap(SumoXMLAttr attr) const
Return the CharacteristicMap that belongs to a given attribute.
double getTransportableMass() const
Returns the mass of all transportables in the vehicle.
double myStopDurationSeconds
~EnergyParams()
Destructor.
double myLastAngle
void setTransportableMass(const double mass)
Sets the mass of all transportables in the vehicle.
double getAngleDiff() const
Returns the angle difference between the last two calls of setDynamicValues (usually the last two tim...
void setDynamicValues(const SUMOTime stopDuration, const bool parking, const SUMOTime waitingTime, const double angle)
Sets the values which change possibly in every simulation step and are relevant for emsssion calculat...
static double angleDiff(const double angle1, const double angle2)
Returns the difference of the second angle to the first angle in radiants.
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
double getDouble(const std::string &key, const double defaultValue) const
Returns the value for a given key converted to a double.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
static double getWeight(const SUMOEmissionClass c)
Returns a representative weight for the given emission class see http://colombo-fp7....
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
Structure representing possible vehicle parameter.
double width
This class' width.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
double height
This class' height.
SUMOEmissionClass emissionClass
The emission class of this vehicle.
SUMOVehicleClass vehicleClass
The vehicle's class.
std::string id
The vehicle type's id.
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
#define M_PI
Definition odrSpiral.cpp:45