Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/emissions/EnergyParams.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2002-2025 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
/****************************************************************************/
14
/// @file EnergyParams.h
15
/// @author Jakob Erdmann
16
/// @author Michael Behrisch
17
/// @date Sept 2021
18
///
19
// A class for parameters used by the emission models
20
/****************************************************************************/
21
#pragma once
22
#include <config.h>
23
#include <map>
24
#include <string>
25
#include <vector>
26
#include <utils/common/SUMOVehicleClass.h>
27
#include <utils/common/ToString.h>
28
#include <utils/emissions/CharacteristicMap.h>
29
#include <utils/xml/SUMOXMLDefinitions.h>
30
31
32
// ===========================================================================
33
// class declarations
34
// ===========================================================================
35
class SUMOVTypeParameter;
36
37
38
// ===========================================================================
39
// class definitions
40
// ===========================================================================
41
/**
42
* @class EnergyParams
43
* @brief An upper class for objects with additional parameters
44
*/
45
class EnergyParams {
46
public:
47
/// @brief Constructor
48
EnergyParams(const SUMOVTypeParameter* typeParams = nullptr);
49
50
/// @brief Constructor
51
EnergyParams(const EnergyParams* secondaryParams) : mySecondaryParams(secondaryParams) {}
52
53
/// @brief Destructor
54
~EnergyParams();
55
56
/**@brief Set secondary params
57
* @param[in] secondaryParams The secondary parameters
58
*/
59
void setSecondary(const EnergyParams* secondaryParams) {
60
mySecondaryParams = secondaryParams;
61
}
62
63
/**@brief Sets the values which change possibly in every simulation step and are relevant for emsssion calculation
64
* @param[in] stopDuration the total duration of the current stop (-1 means no current stop)
65
* @param[in] parking whether the current stop is a parking stop (only meaningful if stopDuration != -1)
66
* @param[in] waitingTime the current total waiting time
67
* @param[in] angle the current absolute angle of the vehicle
68
*/
69
void setDynamicValues(const SUMOTime stopDuration, const bool parking, const SUMOTime waitingTime, const double angle);
70
71
/**@brief Sets the empty mass of the vehicle (type)
72
* This is to be used by traci/libsumo
73
* @param[in] mass the new mass
74
*/
75
void setMass(const double mass);
76
77
/**@brief Returns the mass of all transportables in the vehicle
78
* @return The total mass of persons and containers in kg
79
*/
80
double getTransportableMass() const {
81
return myTransportableMass;
82
}
83
84
/**@brief Sets the mass of all transportables in the vehicle
85
* @param[in] mass the new mass
86
*/
87
void setTransportableMass(const double mass);
88
89
/**@brief Returns the sum of the empty mass (SUMO_ATTR_MASS), tthe loading (SUMO_ATTR_LOADING) and the mass of all transportables in the vehicle
90
* @return The total mass in kg
91
*/
92
double getTotalMass(const double defaultEmptyMass, const double defaultLoading) const;
93
94
/**@brief Returns the angle difference between the last two calls of setDynamicValues (usually the last two time steps)
95
* @return The angle difference in radians
96
*/
97
double getAngleDiff() const;
98
99
/**@brief Returns the value for a given key
100
* @param[in] key The key to ask for
101
* @return The value stored under the key
102
*/
103
double getDouble(SumoXMLAttr attr) const;
104
105
/**@brief Returns the value for a given key with an optional default.
106
* SUMO_ATTR_MASS and SUMO_ATTR_FRONTSURFACEAREA get a special treatment and return the given def value
107
* also if the map has a value which is flagged as default.
108
* @param[in] key The key to ask for
109
* @param[in] def The default value if no value is stored or the stored value is flagged as default
110
* @return The value stored under the key
111
*/
112
double getDoubleOptional(SumoXMLAttr attr, const double def) const;
113
114
/**
115
* @brief Return the CharacteristicMap that belongs to a given attribute.
116
*
117
* @param[in] attr Name of an attribute
118
* @return A CharacteristicMap
119
*/
120
const CharacteristicMap& getCharacteristicMap(SumoXMLAttr attr) const;
121
122
/// @brief Returns a complete inner description
123
const std::string dump() const {
124
return joinToString(myMap, ", ", ":") + (mySecondaryParams ? mySecondaryParams->dump() : "");
125
}
126
127
/** @brief Returns the state of the engine when the vehicle is not moving
128
* @return whether the engine is running
129
*/
130
bool isEngineOff() const;
131
132
/** @brief Returns whether the vehicle is currently consuming any energy derived from the parking state
133
* @return whether the vehicle has any consumption
134
*/
135
bool isOff() const;
136
137
static const EnergyParams* getDefault() {
138
if (myDefault == nullptr) {
139
myDefault = new EnergyParams();
140
}
141
return myDefault;
142
}
143
144
private:
145
/// @brief The key->value maps
146
std::map<SumoXMLAttr, double> myMap;
147
std::map<SumoXMLAttr, CharacteristicMap> myCharacteristicMapMap;
148
const EnergyParams* mySecondaryParams = nullptr;
149
bool myHaveDefaultMass = false;
150
bool myHaveDefaultFrontSurfaceArea = false;
151
double myStopDurationSeconds = -1.;
152
bool myAmParking = false;
153
double myWaitingTimeSeconds = -1.;
154
double myLastAngle = INVALID_DOUBLE;
155
double myAngle = INVALID_DOUBLE;
156
double myTransportableMass = 0.;
157
158
static const EnergyParams* myDefault;
159
static const std::vector<SumoXMLAttr> myParamAttrs;
160
161
/// @brief invalidate copy constructor
162
EnergyParams(const EnergyParams& s) = delete;
163
164
/// @brief invalidate assignment operator
165
EnergyParams& operator=(const EnergyParams& s) = delete;
166
};
167
168