27#define JSON_USE_IMPLICIT_CONVERSIONS 0
47 if (!
Load(DataPath, Helper, DataCor)) {
78 std::string emissionRep = Helper->
getgClass();
81 std::vector<std::vector<double> > matrixFCvalues;
82 std::vector<std::vector<double> > matrixPollutants;
83 std::vector<double> idlingValuesFCvalues;
84 std::vector<double> idlingValuesPollutants;
85 std::vector<std::string> headerFCvalues;
86 std::vector<std::string> headerPollutants;
94 if (DataCor !=
nullptr) {
101 if (!
ReadEmissionData(
true, DataPath, emissionRep, Helper, fleetMix, DataCor, headerFCvalues, matrixFCvalues, idlingValuesFCvalues)) {
105 if (!
ReadEmissionData(
false, DataPath, emissionRep, Helper, fleetMix, DataCor, headerPollutants, matrixPollutants, idlingValuesPollutants)) {
110 _ceps.insert(std::make_pair(Helper->
getgClass(),
new CEP(
Vehicle, headerFCvalues, matrixFCvalues, headerPollutants, matrixPollutants, idlingValuesFCvalues, idlingValuesPollutants)));
117 return vd.
at(key).
get<
double>();
123 std::string path =
"";
127 std::ifstream vehicleReader;
128 for (std::vector<std::string>::const_iterator i = DataPath.begin(); i != DataPath.end(); i++) {
129 vehicleReader.open(((*i) + emissionClass +
".PHEMLight.veh").c_str());
130 if (vehicleReader.good()) {
134 if (!vehicleReader.good()) {
135 Helper->
setErrMsg(
"File does not exist! (" + emissionClass +
".PHEMLight.veh)");
142 vehicleReader >> json;
144 Helper->
setErrMsg(
"Error during file read! (" + emissionClass +
".PHEMLight.veh)");
150 if (vehDataIt == json.end()) {
151 Helper->
setErrMsg(
"No VehicleData in " + emissionClass +
".PHEMLight.veh!");
155 Vehicle->getVehicleData()->setMassType(vd.
contains(
"MassType") ? vd.
at(
"MassType").
get<std::string>() :
"LV");
156 Vehicle->getVehicleData()->setFuelType(vd.
contains(
"FuelType") ? vd.
at(
"FuelType").
get<std::string>() :
"D");
157 Vehicle->getVehicleData()->setCalcType(vd.
contains(
"CalcType") ? vd.
at(
"CalcType").
get<std::string>() :
"Conv");
168 if (auxDataIt == json.end() || !auxDataIt->contains(
"Pauxnorm")) {
169 Vehicle->getAuxiliariesData()->setPauxnorm(0.);
171 Vehicle->getAuxiliariesData()->setPauxnorm(auxDataIt->at(
"Pauxnorm").get<
double>());
176 if (engDataIt == json.end() || !engDataIt->contains(
"ICEData") || !engDataIt->contains(
"EMData")) {
177 Helper->
setErrMsg(
"Incomplete EngineData in " + emissionClass +
".PHEMLight.veh!");
190 if (rrDataIt == json.end()) {
191 Helper->
setErrMsg(
"No RollingResData in " + emissionClass +
".PHEMLight.veh!");
203 if (trDataIt == json.end()) {
204 Helper->
setErrMsg(
"No TransmissionData in " + emissionClass +
".PHEMLight.veh!");
209 if (transmIt == trDataIt->end()) {
210 Helper->
setErrMsg(std::string(
"Transmission ratios missing in vehicle file! Calculation stopped! (") + path + std::string(
")"));
213 if (!transmIt->contains(
"Speed")) {
214 Helper->
setErrMsg(std::string(
"No Speed signal in transmission data given! Calculation stopped! (") + path + std::string(
")"));
217 if (!transmIt->contains(
"GearRatio")) {
218 Helper->
setErrMsg(std::string(
"No GearRatio signal in transmission data given! Calculation stopped! (") + path + std::string(
")"));
221 if (!transmIt->contains(
"RotMassF")) {
222 Helper->
setErrMsg(std::string(
"No RotMassF signal in transmission data given! Calculation stopped! (") + path + std::string(
")"));
226 Vehicle->getTransmissionData()->setTransm(transmIt->get<std::map<std::string, std::vector<double> > >());
230 if (fldDataIt == json.end()) {
231 Helper->
setErrMsg(
"No FLDData in " + emissionClass +
".PHEMLight.veh!");
240 if (dragIt == fldDataIt->end()) {
241 Helper->
setErrMsg(std::string(
"Drag curve missing in vehicle file! Calculation stopped! (") + path + std::string(
")"));
244 if (!dragIt->contains(
"n_norm")) {
245 Helper->
setErrMsg(std::string(
"No n_norm signal in drag curve data given! Calculation stopped! (") + path + std::string(
")"));
248 if (!dragIt->contains(
"pe_drag_norm")) {
249 Helper->
setErrMsg(std::string(
"No pe_drag_norm signal in drag curve data given! Calculation stopped! (") + path + std::string(
")"));
253 Vehicle->getFLDData()->setDragCurve(dragIt->get<std::map<std::string, std::vector<double> > >());
258 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) {
261 std::string path =
"";
262 header = std::vector<std::string>();
263 matrix = std::vector<std::vector<double> >();
264 idlingValues = std::vector<double>();
266 std::string pollutantExtension =
"";
268 pollutantExtension += std::string(
"_FC");
271 std::ifstream fileReader;
272 for (std::vector<std::string>::const_iterator i = DataPath.begin(); i != DataPath.end(); i++) {
273 fileReader.open(((*i) + emissionClass + pollutantExtension +
".csv").c_str());
274 if (fileReader.good()) {
278 if (!fileReader.good()) {
279 Helper->
setErrMsg(
"File does not exist! (" + emissionClass + pollutantExtension +
".csv)");
284 if ((line =
ReadLine(fileReader)) !=
"") {
285 const std::vector<std::string>& entries =
split(line,
',');
287 for (
int i = 1; i < (int)entries.size(); i++) {
288 header.push_back(entries[i]);
301 std::vector<std::string> stringIdlings =
split(line,
',');
302 stringIdlings.erase(stringIdlings.begin());
306 while ((line =
ReadLine(fileReader)) !=
"") {
312 Helper->
setErrMsg(
"Error in correction calculation");
321 for (
int i = 0; i < (int)header.size(); i++) {
324 for (
int j = 0; j < (int)matrix.size(); j++) {
325 matrix[j][i + 1] *= CorF;
327 idlingValues[i] *= CorF;
338 std::string emi = Emi;
339 std::transform(emi.begin(), emi.end(), emi.begin(), [](
char c) { return (char)::toupper(c); });
346 if (emi.find(
"NOX") != std::string::npos) {
357 std::vector<std::string> elems;
358 std::stringstream ss(s);
360 while (std::getline(ss, item, delim)) {
361 elems.push_back(item);
367 std::stringstream ss(s);
374 std::vector<double> result;
375 for (std::vector<std::string>::const_iterator i = s.begin(); i != s.end(); ++i) {
383 std::getline(s, line);
384 size_t lastNWChar = line.find_last_not_of(
" \n\r\t");
385 if (lastNWChar != std::string::npos) {
386 line.erase(lastNWChar + 1);
400 return privateVersion;
404 privateVersion = value;
408 return &privateVehicleData;
412 return &privateAuxiliariesData;
416 return &privateEngineData;
420 return &privateRollingResData;
424 return &privateFLDData;
428 return &privateTransmissionData;
432 return privateMassType;
436 privateMassType = value;
440 return privateFuelType;
444 privateFuelType = value;
448 return privateCalcType;
452 privateCalcType = value;
464 return privateLoading;
468 privateLoading = value;
472 return privateRedMassWheel;
476 privateRedMassWheel = value;
480 return privateWheelDiameter;
484 privateWheelDiameter = value;
504 return privateMileage;
508 privateMileage = value;
552 return &privateICEData;
556 return &privateEMData;
560 return privatePrated;
564 privatePrated = value;
568 return privatenrated;
572 privatenrated = value;
576 return privateIdling;
580 privateIdling = value;
584 return privatePrated;
588 privatePrated = value;
592 return privatenrated;
596 privatenrated = value;
600 return privatePauxnorm;
604 privatePauxnorm = value;
608 return privateP_n_max_v0;
612 privateP_n_max_v0 = value;
616 return privateP_n_max_p0;
620 privateP_n_max_p0 = value;
624 return privateP_n_max_v1;
628 privateP_n_max_v1 = value;
632 return privateP_n_max_p1;
636 privateP_n_max_p1 = value;
640 return privateDragCurve;
644 privateDragCurve = value;
648 setDragCurve(std::map<std::string, std::vector<double> >());
652 return privateAxelRatio;
656 privateAxelRatio = value;
660 return privateTransm;
664 privateTransm = value;
668 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.
a class to store JSON values
bool contains(KeyT &&key) const
check the existence of an element in a JSON object
reference at(size_type idx)
access specified array element with bounds checking
auto get() const noexcept(noexcept(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))) -> decltype(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))
get a (pointer) value (explicit)
a template for a bidirectional iterator for the basic_json class This class implements a both iterato...
double json2double(const nlohmann::json &vd, const std::string &key)