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/****************************************************************************/
18// A class for parameters used by the emission models
19/****************************************************************************/
20#include <config.h>
21
26
27#include "PollutantsInterface.h"
28#include "HelpersEnergy.h"
29#include "EnergyParams.h"
30
31
32// ===========================================================================
33// static definitions
34// ===========================================================================
36
37
38// ===========================================================================
39// method definitions
40// ===========================================================================
42 EnergyParams(typeParams != nullptr ? typeParams->emissionClass : EMISSION_CLASS_UNSPECIFIED) {
43 if (typeParams != nullptr) {
44 for (auto item : myMap) {
45 myMap[item.first] = typeParams->getDouble(toString(item.first), item.second);
46 }
47 for (auto item : myVecMap) {
48 myVecMap[item.first] = typeParams->getDoubles(toString(item.first), item.second);
49 }
50 for (auto item : myCharacteristicMapMap) {
51 std::string characteristicMapString = typeParams->getParameter(toString(item.first), "");
52 if (characteristicMapString != "") {
53 myCharacteristicMapMap.at(item.first) = CharacteristicMap(typeParams->getParameter(toString(item.first)));
54 }
55 }
56 if (typeParams->wasSet(VTYPEPARS_MASS_SET)) {
57 myMap[SUMO_ATTR_MASS] = typeParams->mass;
58 }
59 myMap[SUMO_ATTR_LOADING] = typeParams->getDouble("loading", INVALID_DOUBLE);
60 myMap[SUMO_ATTR_WIDTH] = typeParams->width;
61 myMap[SUMO_ATTR_HEIGHT] = typeParams->height;
64 WRITE_WARNINGF(TL("Vehicle type '%' uses the Energy model with parameter 'internalMomentOfInertia' which is deprecated. Use 'rotatingMass' instead."), typeParams->id);
65 if (!typeParams->hasParameter(toString(SUMO_ATTR_ROTATINGMASS))) {
67 }
68 }
69 }
70 }
71}
72
73
76 myMap[SUMO_ATTR_SHUT_OFF_AUTO] = std::numeric_limits<double>::max();
80
90 return;
91 }
93 myMap[SUMO_ATTR_MASS] = defaultValues.mass;
95 myMap[SUMO_ATTR_WIDTH] = defaultValues.width;
96 myMap[SUMO_ATTR_HEIGHT] = defaultValues.height;
97
98 // default values from
99 // https://sumo.dlr.de/docs/Models/Electric.html#kia_soul_ev_2020
101 myMap[SUMO_ATTR_MASS] = 1830.;
102 }
112 myMap[SUMO_ATTR_ANGLE] = 0.; // actually angleDiff in the last step
113 // @todo set myVecMap defaults as needed
114
115 // Default values for the MMPEVEM, taken from the VW_ID3
116 myMap[SUMO_ATTR_WHEELRADIUS] = 0.3588; // [m]
117 myMap[SUMO_ATTR_MAXIMUMTORQUE] = 310.0; // [Nm]
118 // @todo SUMO_ATTR_MAXIMUMPOWER predates the MMPEVEM emission model. Do you want to set this somewhere else or to another value?
119 myMap[SUMO_ATTR_MAXIMUMPOWER] = 107000.0; // [W]
120 myMap[SUMO_ATTR_GEAREFFICIENCY] = 0.96; // [1]
121 myMap[SUMO_ATTR_GEARRATIO] = 10.0; // [1]
126 myMap[SUMO_ATTR_INTERNALMOMENTOFINERTIA] = 12.5; // [kgm^2]
127 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
128}
129
130
132
133
134void
136 myMap[attr] = value;
137}
138
139
140double
142 auto it = myMap.find(attr);
143 if (it != myMap.end()) {
144 return it->second;
145 }
146 if (mySecondaryParams != nullptr) {
147 return mySecondaryParams->getDouble(attr);
148 }
149 throw UnknownElement("Unknown Energy Model parameter: " + toString(attr));
150}
151
152
153double
154EnergyParams::getDoubleOptional(SumoXMLAttr attr, const double def) const {
155 auto it = myMap.find(attr);
156 if (it != myMap.end() && it->second != INVALID_DOUBLE) {
157 return it->second;
158 }
159 if (mySecondaryParams != nullptr) {
160 return mySecondaryParams->getDoubleOptional(attr, def);
161 }
162 return def;
163}
164
165
166const std::vector<double>&
168 auto it = myVecMap.find(attr);
169 if (it != myVecMap.end()) {
170 return it->second;
171 }
172 if (mySecondaryParams != nullptr) {
173 return mySecondaryParams->getDoubles(attr);
174 }
175 throw UnknownElement("Unknown Energy Model parameter: " + toString(attr));
176}
177
178
181 auto it = myCharacteristicMapMap.find(attr);
182 if (it != myCharacteristicMapMap.end()) {
183 return it->second;
184 }
185 if (mySecondaryParams != nullptr) {
187 }
188 throw UnknownElement("Unknown Energy Model parameter: " + toString(attr));
189}
190
191
192void
193EnergyParams::checkParam(const SumoXMLAttr paramKey, const std::string& id, const double lower, const double upper) {
194 const auto& p = myMap.find(paramKey);
195 if (p != myMap.end() && (p->second < lower || p->second > upper)) {
196 WRITE_WARNINGF(TL("Vehicle device '%' doesn't have a valid value for parameter % (%)."), id, toString(paramKey), p->second);
197 setDouble(paramKey, EnergyParams::getDefault()->getDouble(paramKey));
198 }
199}
200
201
202bool
204 // they all got a default in the constructor so getDouble is safe here
207}
208
209
210bool
212 // they all got a default in the constructor so getDouble is safe here
214}
215
216
217/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define TL(string)
Definition MsgHandler.h:315
const long long int VTYPEPARS_MASS_SET
const SUMOEmissionClass EMISSION_CLASS_UNSPECIFIED
emission class not specified
int SUMOEmissionClass
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_PARKING
@ SUMO_ATTR_GEAREFFICIENCY
Gear efficiency.
@ SUMO_ATTR_MAXIMUMPOWER
Maximum Power.
@ SUMO_ATTR_WAITINGTIME
@ 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_ANGLE
@ SUMO_ATTR_MAXIMUMRECUPERATIONPOWER
Maximum recuperation power.
@ SUMO_ATTR_SHUT_OFF_STOP
@ SUMO_ATTR_HEIGHT
@ 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_DURATION
@ SUMO_ATTR_WIDTH
@ 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
bool isOff() const
Returns whether the vehicle is currently consuming any energy derived from the parking state.
static const EnergyParams * myDefault
void setDouble(SumoXMLAttr attr, double value)
Sets a parameter.
double getDoubleOptional(SumoXMLAttr attr, const double def) const
std::map< SumoXMLAttr, double > myMap
The key->value maps.
EnergyParams(const SUMOVTypeParameter *typeParams=nullptr)
Constructor.
std::map< SumoXMLAttr, std::vector< double > > myVecMap
std::map< SumoXMLAttr, CharacteristicMap > myCharacteristicMapMap
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.
~EnergyParams()
Destructor.
static const EnergyParams * getDefault()
const std::vector< double > & getDoubles(SumoXMLAttr attr) const
Returns the value for a given key.
void checkParam(const SumoXMLAttr paramKey, const std::string &id, const double lower=0., const double upper=std::numeric_limits< double >::infinity())
std::vector< double > getDoubles(const std::string &key, std::vector< double > defaultValue=std::vector< double >()) const
Returns the value for a given key converted to a list of doubles.
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 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.
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.
struct for default values that depend of VClass