27#define JSON_USE_IMPLICIT_CONVERSIONS 0
46 if (!
Load(DataPath, Helper, DataCor)) {
77 std::string emissionRep = Helper->
getgClass();
80 std::vector<std::vector<double> > matrixFCvalues;
81 std::vector<std::vector<double> > matrixPollutants;
82 std::vector<double> idlingValuesFCvalues;
83 std::vector<double> idlingValuesPollutants;
84 std::vector<std::string> headerFCvalues;
85 std::vector<std::string> headerPollutants;
93 if (DataCor !=
nullptr) {
100 if (!
ReadEmissionData(
true, DataPath, emissionRep, Helper, fleetMix, DataCor, headerFCvalues, matrixFCvalues, idlingValuesFCvalues)) {
104 if (!
ReadEmissionData(
false, DataPath, emissionRep, Helper, fleetMix, DataCor, headerPollutants, matrixPollutants, idlingValuesPollutants)) {
109 _ceps.insert(std::make_pair(Helper->
getgClass(),
new CEP(
Vehicle, headerFCvalues, matrixFCvalues, headerPollutants, matrixPollutants, idlingValuesFCvalues, idlingValuesPollutants)));
114 double json2double(
const nlohmann::json& vd,
const std::string& key) {
115 if (vd.contains(key)) {
116 return vd.at(key).get<
double>();
122 std::string path =
"";
126 std::ifstream vehicleReader;
127 for (std::vector<std::string>::const_iterator i = DataPath.begin(); i != DataPath.end(); i++) {
128 vehicleReader.open(((*i) + emissionClass +
".PHEMLight.veh").c_str());
129 if (vehicleReader.good()) {
133 if (!vehicleReader.good()) {
134 Helper->
setErrMsg(
"File does not exist! (" + emissionClass +
".PHEMLight.veh)");
141 vehicleReader >>
json;
143 Helper->
setErrMsg(
"Error during file read! (" + emissionClass +
".PHEMLight.veh)");
150 Helper->
setErrMsg(
"No VehicleData in " + emissionClass +
".PHEMLight.veh!");
153 const nlohmann::json& vd = *vehDataIt;
154 Vehicle->getVehicleData()->setMassType(vd.contains(
"MassType") ? vd.at(
"MassType").get<std::string>() :
"LV");
155 Vehicle->getVehicleData()->setFuelType(vd.contains(
"FuelType") ? vd.at(
"FuelType").get<std::string>() :
"D");
156 Vehicle->getVehicleData()->setCalcType(vd.contains(
"CalcType") ? vd.at(
"CalcType").get<std::string>() :
"Conv");
167 if (auxDataIt ==
json.
end() || !auxDataIt->contains(
"Pauxnorm")) {
168 Vehicle->getAuxiliariesData()->setPauxnorm(0.);
170 Vehicle->getAuxiliariesData()->setPauxnorm(auxDataIt->at(
"Pauxnorm").get<
double>());
175 if (engDataIt ==
json.
end() || !engDataIt->contains(
"ICEData") || !engDataIt->contains(
"EMData")) {
176 Helper->
setErrMsg(
"Incomplete EngineData in " + emissionClass +
".PHEMLight.veh!");
179 const nlohmann::json& iced = (*engDataIt)[
"ICEData"];
180 const nlohmann::json& emd = (*engDataIt)[
"EMData"];
190 Helper->
setErrMsg(
"No RollingResData in " + emissionClass +
".PHEMLight.veh!");
193 const nlohmann::json& rrd = *rrDataIt;
203 Helper->
setErrMsg(
"No TransmissionData in " + emissionClass +
".PHEMLight.veh!");
208 if (transmIt == trDataIt->end()) {
209 Helper->
setErrMsg(std::string(
"Transmission ratios missing in vehicle file! Calculation stopped! (") + path + std::string(
")"));
212 if (!transmIt->contains(
"Speed")) {
213 Helper->
setErrMsg(std::string(
"No Speed signal in transmission data given! Calculation stopped! (") + path + std::string(
")"));
216 if (!transmIt->contains(
"GearRatio")) {
217 Helper->
setErrMsg(std::string(
"No GearRatio signal in transmission data given! Calculation stopped! (") + path + std::string(
")"));
220 if (!transmIt->contains(
"RotMassF")) {
221 Helper->
setErrMsg(std::string(
"No RotMassF signal in transmission data given! Calculation stopped! (") + path + std::string(
")"));
225 Vehicle->getTransmissionData()->setTransm(transmIt->get<std::map<std::string, std::vector<double> > >());
230 Helper->
setErrMsg(
"No FLDData in " + emissionClass +
".PHEMLight.veh!");
233 const nlohmann::json& fld = *fldDataIt;
239 if (dragIt == fldDataIt->end()) {
240 Helper->
setErrMsg(std::string(
"Drag curve missing in vehicle file! Calculation stopped! (") + path + std::string(
")"));
243 if (!dragIt->contains(
"n_norm")) {
244 Helper->
setErrMsg(std::string(
"No n_norm signal in drag curve data given! Calculation stopped! (") + path + std::string(
")"));
247 if (!dragIt->contains(
"pe_drag_norm")) {
248 Helper->
setErrMsg(std::string(
"No pe_drag_norm signal in drag curve data given! Calculation stopped! (") + path + std::string(
")"));
252 Vehicle->getFLDData()->setDragCurve(dragIt->get<std::map<std::string, std::vector<double> > >());
257 bool CEPHandler::ReadEmissionData(
bool readFC,
const std::vector<std::string>& DataPath,
const std::string& emissionClass,
Helpers* Helper,
bool ,
Correction* DataCor, std::vector<std::string>& header, std::vector<std::vector<double> >& matrix, std::vector<double>& idlingValues) {
260 std::string path =
"";
261 header = std::vector<std::string>();
262 matrix = std::vector<std::vector<double> >();
263 idlingValues = std::vector<double>();
265 std::string pollutantExtension =
"";
267 pollutantExtension += std::string(
"_FC");
270 std::ifstream fileReader;
271 for (std::vector<std::string>::const_iterator i = DataPath.begin(); i != DataPath.end(); i++) {
272 fileReader.open(((*i) + emissionClass + pollutantExtension +
".csv").c_str());
273 if (fileReader.good()) {
277 if (!fileReader.good()) {
278 Helper->
setErrMsg(
"File does not exist! (" + emissionClass + pollutantExtension +
".csv)");
283 if ((line =
ReadLine(fileReader)) !=
"") {
284 const std::vector<std::string>& entries =
split(line,
',');
286 for (
int i = 1; i < (int)entries.size(); i++) {
287 header.push_back(entries[i]);
300 std::vector<std::string> stringIdlings =
split(line,
',');
301 stringIdlings.erase(stringIdlings.begin());
305 while ((line =
ReadLine(fileReader)) !=
"") {
311 Helper->
setErrMsg(
"Error in correction calculation");
320 for (
int i = 0; i < (int)header.size(); i++) {
323 for (
int j = 0; j < (int)matrix.size(); j++) {
324 matrix[j][i + 1] *= CorF;
326 idlingValues[i] *= CorF;
337 std::string emi = Emi;
338 std::transform(emi.begin(), emi.end(), emi.begin(), [](
char c) { return (char)::toupper(c); });
345 if (emi.find(
"NOX") != std::string::npos) {
356 std::vector<std::string> elems;
357 std::stringstream ss(s);
359 while (std::getline(ss, item, delim)) {
360 elems.push_back(item);
366 std::stringstream ss(s);
373 std::vector<double> result;
374 for (std::vector<std::string>::const_iterator i = s.begin(); i != s.end(); ++i) {
382 std::getline(s, line);
383 size_t lastNWChar = line.find_last_not_of(
" \n\r\t");
384 if (lastNWChar != std::string::npos) {
385 line.erase(lastNWChar + 1);
399 return privateVersion;
403 privateVersion = value;
407 return &privateVehicleData;
411 return &privateAuxiliariesData;
415 return &privateEngineData;
419 return &privateRollingResData;
423 return &privateFLDData;
427 return &privateTransmissionData;
431 return privateMassType;
435 privateMassType = value;
439 return privateFuelType;
443 privateFuelType = value;
447 return privateCalcType;
451 privateCalcType = value;
463 return privateLoading;
467 privateLoading = value;
471 return privateRedMassWheel;
475 privateRedMassWheel = value;
479 return privateWheelDiameter;
483 privateWheelDiameter = value;
503 return privateMileage;
507 privateMileage = value;
551 return &privateICEData;
555 return &privateEMData;
559 return privatePrated;
563 privatePrated = value;
567 return privatenrated;
571 privatenrated = value;
575 return privateIdling;
579 privateIdling = value;
583 return privatePrated;
587 privatePrated = value;
591 return privatenrated;
595 privatenrated = value;
599 return privatePauxnorm;
603 privatePauxnorm = value;
607 return privateP_n_max_v0;
611 privateP_n_max_v0 = value;
615 return privateP_n_max_p0;
619 privateP_n_max_p0 = value;
623 return privateP_n_max_v1;
627 privateP_n_max_v1 = value;
631 return privateP_n_max_p1;
635 privateP_n_max_p1 = value;
639 return privateDragCurve;
643 privateDragCurve = value;
647 setDragCurve(std::map<std::string, std::vector<double> >());
651 return privateAxelRatio;
655 privateAxelRatio = value;
659 return privateTransm;
663 privateTransm = value;
667 setTransm(std::map<std::string, std::vector<double> >());
bool Load(std::vector< std::string > &DataPath, Helpers *Helper, Correction *DataCor, bool fleetMix=false)
const std::map< std::string, CEP * > & getCEPS() const
bool ReadVehicleFile(const std::vector< std::string > &DataPath, const std::string &emissionClass, Helpers *Helper, bool fleetMix, VEHPHEMLightJSON::VEH *&Vehicle)
std::string ReadLine(std::ifstream &s)
std::vector< double > todoubleList(const std::vector< std::string > &s)
double todouble(const std::string &s)
bool CorrectEmissionData(Correction *DataCor, std::vector< std::string > &header, std::vector< std::vector< double > > &matrix, std::vector< double > &idlingValues)
bool CalcCorrection(Correction *DataCor, Helpers *Helper, VEHPHEMLightJSON::Vehicle_Data *vehicle_Data)
std::map< std::string, CEP * > _ceps
bool GetCEP(std::vector< std::string > &DataPath, Helpers *Helper, Correction *DataCor)
const std::vector< std::string > split(const std::string &s, char delim)
double GetDetTempCor(Correction *DataCor, const std::string &Emi)
bool ReadEmissionData(bool readFC, const std::vector< std::string > &DataPath, const std::string &emissionClass, Helpers *Helper, bool fleetMix, Correction *DataCor, std::vector< std::string > &header, std::vector< std::vector< double > > &matrix, std::vector< double > &idlingValues)
bool IniDETfactor(Helpers *Helper)
const bool & getUseTNOx() const
bool IniTNOxfactor(Helpers *Helper)
std::map< std::string, double > DETFactors
const double & getTNOxFactor() const
void setVehMileage(const double &value)
const bool & getUseDet() const
const std::string & getgClass() const
void setErrMsg(const std::string &value)
const double & getPauxnorm() const
void setPauxnorm(const double &value)
const double & getPrated() const
void setPrated(const double &value)
void setnrated(const double &value)
const double & getnrated() const
void setP_n_max_v0(const double &value)
const double & getP_n_max_p0() const
const double & getP_n_max_p1() const
void setP_n_max_p0(const double &value)
const double & getP_n_max_v0() const
void setP_n_max_p1(const double &value)
std::map< std::string, std::vector< double > > & getDragCurve()
void setP_n_max_v1(const double &value)
void setDragCurve(const std::map< std::string, std::vector< double > > &value)
const double & getP_n_max_v1() const
const double & getnrated() const
const double & getIdling() const
void setIdling(const double &value)
void setPrated(const double &value)
const double & getPrated() const
void setnrated(const double &value)
const double & getFr3() const
const double & getFr4() const
void setFr2(const double &value)
void setFr0(const double &value)
const double & getFr0() const
void setFr1(const double &value)
void setFr3(const double &value)
const double & getFr2() const
void setFr4(const double &value)
const double & getFr1() const
void setAxelRatio(const double &value)
void setTransm(const std::map< std::string, std::vector< double > > &value)
const double & getAxelRatio() const
std::map< std::string, std::vector< double > > & getTransm()
FullLoadDrag_Data * getFLDData()
void setType(const std::string &value)
void setVersion(const std::string &value)
Vehicle_Data * getVehicleData()
Aux_Data * getAuxiliariesData()
Engine_Data * getEngineData()
const std::string & getType() const
Transmission_Data * getTransmissionData()
const std::string & getVersion() const
Rollres_Data * getRollingResData()
void setMassType(const std::string &value)
void setLoading(const double &value)
const double & getA() const
const std::string & getMassType() const
const double & getRedMassWheel() const
void setA(const double &value)
void setRedMassWheel(const double &value)
void setMileage(const double &value)
const double & getWheelDiameter() const
void setCw(const double &value)
const double & getCw() const
const double & getLoading() const
const double & getMass() const
const double & getMileage() const
void setWheelDiameter(const double &value)
const std::string & getCalcType() const
const std::string & getFuelType() const
void setFuelType(const std::string &value)
void setMass(const double &value)
void setCalcType(const std::string &value)
C++ TraCI client API implementation.
namespace for Niels Lohmann
iterator end() noexcept
returns an iterator to one past the last element
iterator find(const typename object_t::key_type &key)
find an element in a JSON object
iter_impl< basic_json > iterator
an iterator for a basic_json container
basic_json<> json
default specialization
double json2double(const nlohmann::json &vd, const std::string &key)