Eclipse SUMO - Simulation of Urban MObility
EnergyParams.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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// ===========================================================================
43 myMap[SUMO_ATTR_SHUT_OFF_AUTO] = std::numeric_limits<double>::max();
47
48 // default values from
49 // https://sumo.dlr.de/docs/Models/Electric.html#kia_soul_ev_2020
60 myMap[SUMO_ATTR_ANGLE] = 0.; // actually angleDiff in the last step
61 // @todo set myVecMap defaults as needed
62
63 // Default values for the MMPEVEM
64 myMap[SUMO_ATTR_WHEELRADIUS] = 0.3588; // [m]
65 myMap[SUMO_ATTR_MAXIMUMTORQUE] = 310.0; // [Nm]
66 // @todo SUMO_ATTR_MAXIMUMPOWER predates the MMPEVEM emission model. Do you want to set this somewhere else or to another value?
67 myMap[SUMO_ATTR_MAXIMUMPOWER] = 107000.0; // [W]
68 myMap[SUMO_ATTR_GEAREFFICIENCY] = 0.96; // [1]
69 myMap[SUMO_ATTR_GEARRATIO] = 10.0; // [1]
74 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
75
76 if (typeParams != nullptr) {
77 for (auto item : myMap) {
78 myMap[item.first] = typeParams->getDouble(toString(item.first), item.second);
79 }
80 for (auto item : myVecMap) {
81 myVecMap[item.first] = typeParams->getDoubles(toString(item.first), item.second);
82 }
83 for (auto item : myCharacteristicMapMap) {
84 std::string characteristicMapString = typeParams->getParameter(toString(item.first), "");
85 if (characteristicMapString != "") {
86 myCharacteristicMapMap.at(item.first) = CharacteristicMap(typeParams->getParameter(toString(item.first)));
87 }
88 }
89 myMap[SUMO_ATTR_MASS] = typeParams->mass;
90 myMap[SUMO_ATTR_WIDTH] = typeParams->width;
91 myMap[SUMO_ATTR_HEIGHT] = typeParams->height;
92 } else {
94 myMap[SUMO_ATTR_MASS] = defaultValues.mass;
95 myMap[SUMO_ATTR_WIDTH] = defaultValues.width;
96 myMap[SUMO_ATTR_HEIGHT] = defaultValues.height;
97 }
98}
99
100
102
103
104void
106 myMap[attr] = value;
107}
108
109
110double
112 auto it = myMap.find(attr);
113 if (it != myMap.end()) {
114 return it->second;
115 }
116 if (mySecondaryParams != nullptr) {
117 return mySecondaryParams->getDouble(attr);
118 }
119 throw UnknownElement("Unknown Energy Model parameter: " + toString(attr));
120}
121
122
123const std::vector<double>&
125 if (mySecondaryParams != nullptr) {
126 return mySecondaryParams->getDoubles(attr);
127 }
128 auto it = myVecMap.find(attr);
129 if (it != myVecMap.end()) {
130 return it->second;
131 }
132 throw UnknownElement("Unknown Energy Model parameter: " + toString(attr));
133}
134
135
138 if (mySecondaryParams != nullptr) {
140 }
141 auto it = myCharacteristicMapMap.find(attr);
142 if (it != myCharacteristicMapMap.end()) {
143 return it->second;
144 }
145 throw UnknownElement("Unknown Energy Model parameter: " + toString(attr));
146}
147
148
149void
150EnergyParams::checkParam(const SumoXMLAttr paramKey, const std::string& id, const double lower, const double upper) {
151 const auto& p = myMap.find(paramKey);
152 if (p != myMap.end() && (p->second < lower || p->second > upper)) {
153 WRITE_WARNINGF(TL("Vehicle device '%' doesn't have a valid value for parameter % (%)."), id, toString(paramKey), p->second);
154 setDouble(paramKey, EnergyParams::getDefault()->getDouble(paramKey));
155 }
156}
157
158
159bool
161 // they all got a default in the constructor so getDouble is safe here
164}
165
166
167bool
169 // they all got a default in the constructor so getDouble is safe here
171}
172
173
174/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:266
#define TL(string)
Definition: MsgHandler.h:282
@ 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_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_VEHICLEMASS
Vehicle mass.
@ SUMO_ATTR_RADIALDRAGCOEFFICIENT
Radial drag coefficient.
@ SUMO_ATTR_GEARRATIO
Gear ratio.
@ 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
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.
Definition: EnergyParams.h:41
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
Definition: EnergyParams.h:107
void setDouble(SumoXMLAttr attr, double value)
Sets a parameter.
std::map< SumoXMLAttr, double > myMap
The key->value maps.
Definition: EnergyParams.h:102
EnergyParams(const SUMOVTypeParameter *typeParams=nullptr)
Constructor.
std::map< SumoXMLAttr, std::vector< double > > myVecMap
Definition: EnergyParams.h:103
std::map< SumoXMLAttr, CharacteristicMap > myCharacteristicMapMap
Definition: EnergyParams.h:104
bool isEngineOff() const
Returns the state of the engine when the vehicle is not moving.
const EnergyParams * mySecondaryParams
Definition: EnergyParams.h:105
const CharacteristicMap & getCharacteristicMap(SumoXMLAttr attr) const
Return the CharacteristicMap that belongs to a given attribute.
~EnergyParams()
Destructor.
static const EnergyParams * getDefault()
Definition: EnergyParams.h:93
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.
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.
Structure representing possible vehicle parameter.
double width
This class' width.
double height
This class' height.
double mass
The mass.
struct for default values that depend of VClass