33 CEP::CEP(
VEHPHEMLightJSON::VEH*
Vehicle, std::vector<std::string>& headerLineFCvalues, std::vector<std::vector<double> >& matrixFCvalues, std::vector<std::string>& headerLinePollutants, std::vector<std::vector<double> >& matrixPollutants, std::vector<double>& idlingFCvalues, std::vector<double>& idlingPollutants) {
80 std::vector<std::string> FCvaluesIdentifier;
81 std::vector<std::vector<double> > normalizedFCvaluesMeasures;
82 for (
int i = 0; i < (int)headerLineFCvalues.size(); i++) {
83 FCvaluesIdentifier.push_back(headerLineFCvalues[i]);
84 normalizedFCvaluesMeasures.push_back(std::vector<double>());
88 std::vector<std::string> pollutantIdentifier;
89 std::vector<std::vector<double> > normalizedPollutantMeasures;
90 for (
int i = 0; i < (int)headerLinePollutants.size(); i++) {
91 pollutantIdentifier.push_back(headerLinePollutants[i]);
92 normalizedPollutantMeasures.push_back(std::vector<double>());
97 for (
int i = 0; i < (int)
Vehicle->getTransmissionData()->getTransm()[
"Speed"].size(); i++) {
111 int headerFCCount = (int)headerLineFCvalues.size();
112 for (
int i = 0; i < (int)matrixFCvalues.size(); i++) {
113 for (
int j = 0; j < (int)matrixFCvalues[i].size(); j++) {
114 if ((
int)matrixFCvalues[i].size() != headerFCCount + 1) {
122 normalizedFCvaluesMeasures[j - 1].push_back(matrixFCvalues[i][j]);
130 for (
int i = 0; i < (int)headerLineFCvalues.size(); i++) {
138 int headerCount = (int)headerLinePollutants.size();
139 for (
int i = 0; i < (int)matrixPollutants.size(); i++) {
140 for (
int j = 0; j < (int)matrixPollutants[i].size(); j++) {
141 if ((
int)matrixPollutants[i].size() != headerCount + 1) {
149 normalizedPollutantMeasures[j - 1].push_back(matrixPollutants[i][j]);
156 for (
int i = 0; i < (int)headerLinePollutants.size(); i++) {
161 _FleetMix = std::map<std::string, double>();
207 double CEP::GetEmission(
const std::string& pollutant,
double power,
double speed,
Helpers* VehicleClass,
const double drivingPower,
const double ratedPower) {
209 std::vector<double>* emissionCurve =
nullptr;
210 std::vector<double>* powerPattern =
nullptr;
219 VehicleClass->
setErrMsg(std::string(
"Emission pollutant or fuel value ") + pollutant + std::string(
" not found!"));
233 VehicleClass->
setErrMsg(std::string(
"Emission pollutant or fuel value ") + pollutant + std::string(
" not found!"));
237 double normalizingPower = ratedPower;
241 emissionMultiplier = ratedPower;
247 normalizingPower = drivingPower;
251 if (emissionCurve ==
nullptr || emissionCurve->empty()) {
252 VehicleClass->
setErrMsg(std::string(
"Empty emission curve for ") + pollutant + std::string(
" found!"));
255 if (emissionCurve->size() == 1) {
256 return emissionCurve->front() * emissionMultiplier;
260 if (power <= powerPattern->front() * normalizingPower) {
261 return emissionCurve->front() * emissionMultiplier;
265 if (power >= powerPattern->back() * normalizingPower) {
266 return emissionCurve->back() * emissionMultiplier;
270 return Interpolate(power, (*powerPattern)[lowerIndex] * normalizingPower, (*powerPattern)[upperIndex] * normalizingPower, (*emissionCurve)[lowerIndex], (*emissionCurve)[upperIndex]) * emissionMultiplier;
275 double fCBr, fCHC, fCCO, fCCO2;
288 if (!
CalcfCValMix(fCBr, fCHC, fCCO, fCCO2, VehicleClass)) {
293 return (_FC * fCBr - _CO * fCCO - _HC * fCHC) / fCCO2;
299 double sumfCBr, sumfCHC, sumfCCO, sumfCCO2;
308 for (std::map<std::string, double>::const_iterator
id =
_FleetMix.begin();
id !=
_FleetMix.end(); ++
id) {
314 VehicleClass->
setErrMsg(
"All propolsion types in the fleetshares file are not known!");
318 for (std::map<std::string, double>::const_iterator
id =
_FleetMix.begin();
id !=
_FleetMix.end(); ++
id) {
319 if (!
GetfcVals(id->first, _fCBr, _fCHC, _fCCO, _fCCO2, VehicleClass)) {
323 sumfCBr += _fCBr *
_FleetMix[
id->first] / Sum;
324 sumfCHC += _fCHC *
_FleetMix[
id->first] / Sum;
325 sumfCCO += _fCCO *
_FleetMix[
id->first] / Sum;
326 sumfCCO2 += _fCCO2 *
_FleetMix[
id->first] / Sum;
338 bool CEP::GetfcVals(
const std::string& _fuelTypex,
double& _fCBr,
double& _fCHC,
double& _fCCO,
double& _fCCO2,
Helpers* VehicleClass) {
364 VehicleClass->
setErrMsg(std::string(
"The propulsion type is not known! (") +
getFuelType() + std::string(
")"));
370 double CEP::getFMot(
const double speed,
const double ratedPower,
const double wheelRadius) {
383 double n = (30 * speed * iTot) / (wheelRadius *
M_PI);
403 if (value <= pattern.front() * scale) {
409 if (value >= pattern.back() * scale) {
410 lowerIndex = (int)pattern.size() - 1;
411 upperIndex = (int)pattern.size() - 1;
416 int middleIndex = ((int)pattern.size() - 1) / 2;
417 upperIndex = (int)pattern.size() - 1;
420 while (upperIndex - lowerIndex > 1) {
421 if (pattern[middleIndex] * scale == value) {
422 lowerIndex = middleIndex;
423 upperIndex = middleIndex;
426 else if (pattern[middleIndex] * scale < value) {
427 lowerIndex = middleIndex;
428 middleIndex = (upperIndex - lowerIndex) / 2 + lowerIndex;
431 upperIndex = middleIndex;
432 middleIndex = (upperIndex - lowerIndex) / 2 + lowerIndex;
442 return e1 + (px - p1) / (p2 - p1) * (e2 - e1);
bool GetfcVals(const std::string &_fuelTypex, double &_fCBr, double &_fCHC, double &_fCCO, double &_fCCO2, Helpers *VehicleClass)
void FindLowerUpperInPattern(int &lowerIndex, int &upperIndex, const std::vector< double > &pattern, double value, double scale=1.)
std::map< std::string, std::vector< double > > _normedCepCurveFCvalues
double GetRotationalCoeffecient(double speed)
const double & getRatedPower() const
std::vector< double > _normalizedPowerPatternFCvalues
std::vector< double > _dragNormTable
std::vector< double > _speedCurveRotational
void setCalcType(const std::string &value)
void InitializeInstanceFields()
double getFMot(const double speed, const double ratedPower, const double wheelRadius)
double Interpolate(double px, double p1, double p2, double e1, double e2)
const bool & getHeavyVehicle() const
void setRatedPower(const double &value)
const std::string & getCalcType() const
std::map< std::string, double > _idlingValuesPollutants
double GetPMaxNorm(double speed)
std::vector< double > _speedPatternRotational
std::vector< double > _gearTransmissionCurve
const std::string & getFuelType() const
double GetEmission(const std::string &pollutant, double power, double speed, Helpers *VehicleClass, const double drivingPower, const double ratedPower)
double _engineIdlingSpeed
double GetCO2Emission(double _FC, double _CO, double _HC, Helpers *VehicleClass)
std::vector< double > _nNormTable
void setFuelType(const std::string &value)
std::map< std::string, std::vector< double > > _cepNormalizedCurvePollutants
double _crossSectionalArea
double _effectiveWheelDiameter
double CalcEngPower(double power, const double ratedPower)
CEP(VEHPHEMLightJSON::VEH *Vehicle, std::vector< std::string > &headerLineFCvalues, std::vector< std::vector< double > > &matrixFCvalues, std::vector< std::string > &headerLinePollutants, std::vector< std::vector< double > > &matrixPollutants, std::vector< double > &idlingFCvalues, std::vector< double > &idlingPollutants)
bool CalcfCValMix(double &_fCBr, double &_fCHC, double &_fCCO, double &_fCCO2, Helpers *VehicleClass)
std::vector< double > _normalizedPowerPatternPollutants
std::string privateCalcType
std::map< std::string, double > _idlingValueFCvalues
std::map< std::string, double > _FleetMix
std::string privateFuelType
static const std::string HeavyVehicle
static const double & getDRIVE_TRAIN_EFFICIENCY()
static const std::string strLPG
static const std::string strCNG
static const double ZERO_SPEED_ACCURACY
static const std::string strGasoline
static const std::string strDiesel
void setErrMsg(const std::string &value)
C++ TraCI client API implementation.