2 using System.Collections.Generic;
5 using System.Globalization;
10 public class CEPHandler
17 private Dictionary<string, CEP>
_ceps;
18 public Dictionary<string, CEP>
CEPS =>
_ceps;
23 private Dictionary<string, Dictionary<string, double>>
_fleetShares;
33 if (!
Load(DataPath, Helper, DataCor))
48 List<CEP> weightedCEPS =
new List<CEP>();
52 foreach (
string aggVehClass
in FleetShares[AggClass].Keys)
58 if (!
CEPS.ContainsKey(aggVehClass) && !
Load(DataPath, Helper, DataCor,
true))
62 weightedCEPS.Add(
CEPS[aggVehClass] *
FleetShares[AggClass][aggVehClass]);
70 Helper.
ErrMsg =
"The aggregated vehicle class (" + AggClass +
") includes heavy and non heavy vehicles! This is not allowed. Aggregated vehicle class not added.";
80 Helper.
ErrMsg =
"The aggregated vehicle class (" + AggClass +
") is not available in the FleetShare file!";
86 Helper.
ErrMsg =
"The aggregated vehicle class (" + AggClass +
") is a unknown class!";
101 if (vehicle_Data.Mileage.HasValue) DataCor.
VehMileage = vehicle_Data.Mileage.Value;
122 List<List<double>> matrixFCvalues;
123 List<List<double>> matrixPollutants;
124 List<double> idlingValuesFCvalues;
125 List<double> idlingValuesPollutants;
126 List<string> headerFCvalues;
127 List<string> headerPollutants;
142 if (!
ReadEmissionData(
true, DataPath[1], Helper, fleetMix, DataCor, out headerFCvalues, out matrixFCvalues, out idlingValuesFCvalues))
144 if (!
ReadEmissionData(
false, DataPath[2], Helper, fleetMix, DataCor, out headerPollutants, out matrixPollutants, out idlingValuesPollutants))
152 idlingValuesFCvalues,
153 idlingValuesPollutants));
158 #region ReadVehicleFile
169 path = DataPath +
@"\" + Helper.
gClass +
".PHEMLight.veh";
173 if (!File.Exists(@path))
175 Helper.
ErrMsg =
"File do not exist! (" + path +
")";
180 using (StreamReader r =
new StreamReader(path))
184 string json = r.ReadToEnd();
189 Helper.
ErrMsg =
"Error during file read! (" + path +
")";
196 if (
Vehicle.VehicleData.MassType ==
null)
Vehicle.VehicleData.MassType =
"LV";
197 if (
Vehicle.VehicleData.FuelType ==
null)
Vehicle.VehicleData.FuelType =
"D";
198 if (
Vehicle.VehicleData.CalcType ==
null)
Vehicle.VehicleData.CalcType =
"Conv";
199 if (
Vehicle.VehicleData.Mass ==
null)
Vehicle.VehicleData.Mass = 0;
200 if (
Vehicle.VehicleData.Loading ==
null)
Vehicle.VehicleData.Loading = 0;
201 if (
Vehicle.VehicleData.RedMassWheel ==
null)
Vehicle.VehicleData.RedMassWheel = 0;
202 if (
Vehicle.VehicleData.WheelDiameter ==
null)
Vehicle.VehicleData.WheelDiameter = 0;
207 if (
Vehicle.AuxiliariesData.Pauxnorm ==
null)
Vehicle.AuxiliariesData.Pauxnorm = 0;
210 if (
Vehicle.EngineData.ICEData.Prated ==
null)
Vehicle.EngineData.ICEData.Prated = 0;
211 if (
Vehicle.EngineData.ICEData.nrated ==
null)
Vehicle.EngineData.ICEData.nrated = 0;
212 if (
Vehicle.EngineData.ICEData.Idling ==
null)
Vehicle.EngineData.ICEData.Idling = 0;
213 if (
Vehicle.EngineData.EMData.Prated ==
null)
Vehicle.EngineData.EMData.Prated = 0;
214 if (
Vehicle.EngineData.EMData.nrated ==
null)
Vehicle.EngineData.EMData.nrated = 0;
217 if (
Vehicle.RollingResData.Fr0 ==
null)
Vehicle.RollingResData.Fr0 = 0;
218 if (
Vehicle.RollingResData.Fr1 ==
null)
Vehicle.RollingResData.Fr1 = 0;
219 if (
Vehicle.RollingResData.Fr2 ==
null)
Vehicle.RollingResData.Fr2 = 0;
220 if (
Vehicle.RollingResData.Fr3 ==
null)
Vehicle.RollingResData.Fr3 = 0;
221 if (
Vehicle.RollingResData.Fr4 ==
null)
Vehicle.RollingResData.Fr4 = 0;
224 if (
Vehicle.TransmissionData.AxelRatio ==
null)
Vehicle.TransmissionData.AxelRatio = 0;
225 if (
Vehicle.TransmissionData.Transm ==
null)
227 Helper.
ErrMsg =
"Transmission ratios missing in vehicle file! Calculation stopped! (" + path +
")";
232 if (!
Vehicle.TransmissionData.Transm.ContainsKey(
"Speed"))
234 Helper.
ErrMsg =
"No Speed signal in transmission data given! Calculation stopped! (" + path +
")";
237 if (!
Vehicle.TransmissionData.Transm.ContainsKey(
"GearRatio"))
239 Helper.
ErrMsg =
"No GearRatio signal in transmission data given! Calculation stopped! (" + path +
")";
242 if (!
Vehicle.TransmissionData.Transm.ContainsKey(
"RotMassF"))
244 Helper.
ErrMsg =
"No RotMassF signal in transmission data given! Calculation stopped! (" + path +
")";
250 if (
Vehicle.FLDData.P_n_max_v0 ==
null)
Vehicle.FLDData.P_n_max_v0 = 0;
251 if (
Vehicle.FLDData.P_n_max_p0 ==
null)
Vehicle.FLDData.P_n_max_p0 = 0;
252 if (
Vehicle.FLDData.P_n_max_v1 ==
null)
Vehicle.FLDData.P_n_max_v1 = 0;
253 if (
Vehicle.FLDData.P_n_max_p1 ==
null)
Vehicle.FLDData.P_n_max_p1 = 0;
254 if (
Vehicle.FLDData.DragCurve ==
null)
256 Helper.
ErrMsg =
"Drag curve missing in vehicle file! Calculation stopped! (" + path +
")";
261 if (!
Vehicle.FLDData.DragCurve.ContainsKey(
"n_norm"))
263 Helper.
ErrMsg =
"No n_norm signal in drag curve data given! Calculation stopped! (" + path +
")";
266 if (!
Vehicle.FLDData.DragCurve.ContainsKey(
"pe_drag_norm"))
268 Helper.
ErrMsg =
"No pe_drag_norm signal in drag curve data given! Calculation stopped! (" + path +
")";
277 #region ReadEmissionData
283 out List<string> header,
284 out List<List<double>> matrix,
285 out List<double> idlingValues)
290 header =
new List<string>();
291 matrix =
new List<List<double>>();
292 idlingValues =
new List<double>();
297 path = DataPath +
@"\" + Helper.
gClass +
"_FC.csv";
299 path = DataPath +
@"\" + Helper.
gClass +
".csv";
306 if (!File.Exists(path))
308 Helper.
ErrMsg =
"File do not exist! (" + path +
")";
311 StreamReader fileReader = File.OpenText(@path);
314 if ((line =
ReadLine(fileReader)) !=
null)
316 List<string> entries =
split(line,
',');
318 for (
int i = 1; i < entries.Count; i++)
320 header.Add(entries[i]);
333 List<string> stringIdlings =
split(line,
',').ToList();
334 stringIdlings.RemoveAt(0);
338 while ((line =
ReadLine(fileReader)) !=
null)
347 Helper.
ErrMsg =
"Error in correction calculation";
356 ref List<string> header,
357 ref List<List<double>> matrix,
358 ref List<double> idlingValues)
360 for (
int i = 0; i < header.Count; i++)
365 for (
int j = 0; j < matrix.Count; j++)
367 matrix[j][i + 1] *= CorF;
369 idlingValues[i] *= CorF;
387 foreach (
string Key
in DataCor.
DETFactors.Keys)
389 if (Emi.ToUpper() == Key.ToUpper())
398 if (Emi.ToUpper().Contains(
"NOX")) CorF += (DataCor.
TNOxFactor - 1);
408 #region ReadFleetShares
413 string path = DataPath;
414 if (!File.Exists(@path))
416 Helper.
ErrMsg =
"FleetShares file does not exist! (" + path +
")";
419 StreamReader shareReader = File.OpenText(@path);
421 _fleetShares =
new Dictionary<string, Dictionary<string, double>>();
423 while ((line =
ReadLine(shareReader)) !=
null)
428 List<string> splitLine =
split(line,
',');
429 string aggregateClass = splitLine[0];
432 FleetShares.Add(aggregateClass,
new Dictionary<string, double>());
434 string subClass = splitLine[1];
436 if (!
FleetShares[aggregateClass].ContainsKey(subClass))
446 private List<string>
split(
string s,
char delim)
448 return s.Split(delim).ToList();
454 return double.Parse(s, CultureInfo.InvariantCulture);
460 return s.Select(p =>
todouble(p)).Cast<
double>().ToList();
477 public string Type {
get;
set; }
504 public double?
Mass {
get;
set; }
508 public double?
Cw {
get;
set; }
509 public double?
A {
get;
set; }
514 #region Rolling Resistance
518 public double?
Fr0 {
get;
set; }
519 public double?
Fr1 {
get;
set; }
520 public double?
Fr2 {
get;
set; }
521 public double?
Fr3 {
get;
set; }
522 public double?
Fr4 {
get;
set; }
564 #region Full load and Drag data
572 public Dictionary<string, List<double>>
DragCurve {
get;
set; }
576 DragCurve =
new Dictionary<string, List<double>>();
586 public Dictionary<string, List<double>>
Transm {
get;
set; }
590 Transm =
new Dictionary<string, List<double>>();
bool ReadFleetShares(string DataPath, Helpers Helper)
std::vector< std::string > split(const std::string &s, char delim)
bool ReadVehicleFile(string DataPath, Helpers Helper, bool fleetMix, out VEHPHEMLightJSON.VEH Vehicle)
Dictionary< string, Dictionary< string, double > > FleetShares
Dictionary< string, CEP > CEPS
bool GetCEP(List< string > DataPath, Helpers Helper, Correction DataCor)
bool Load(const std::vector< std::string > &DataPath, Helpers *Helper)
List< string > split(string s, char delim)
double todouble(string s)
bool GetFleetCEP(List< string > DataPath, string AggClass, Helpers Helper, Correction DataCor)
List< double > todoubleList(List< string > s)
bool ReadEmissionData(bool readFC, const std::vector< std::string > &DataPath, const std::string &emissionClass, Helpers *Helper, std::vector< std::string > &header, std::vector< std::vector< double > > &matrix, std::vector< double > &idlingValues)
double todouble(const std::string &s)
std::string ReadLine(std::ifstream &s)
std::map< std::string, CEP * > _ceps
double GetDetTempCor(Correction DataCor, string Emi)
string ReadLine(StreamReader s)
bool CorrectEmissionData(Correction DataCor, ref List< string > header, ref List< List< double >> matrix, ref List< double > idlingValues)
bool CalcCorrection(Correction DataCor, Helpers Helper, VEHPHEMLightJSON.Vehicle_Data vehicle_Data)
std::vector< double > todoubleList(const std::vector< std::string > &s)
Dictionary< string, Dictionary< string, double > > _fleetShares
bool Load(List< string > DataPath, Helpers Helper, Correction DataCor, bool fleetMix=false)
bool ReadVehicleFile(const std::vector< std::string > &DataPath, const std::string &emissionClass, Helpers *Helper, double &vehicleMass, double &vehicleLoading, double &vehicleMassRot, double &crossArea, double &cWValue, double &f0, double &f1, double &f2, double &f3, double &f4, double &axleRatio, double &auxPower, double &ratedPower, double &engineIdlingSpeed, double &engineRatedSpeed, double &effectiveWheelDiameter, std::vector< double > &transmissionGearRatios, std::string &vehicleMassType, std::string &vehicleFuelType, double &pNormV0, double &pNormP0, double &pNormV1, double &pNormP1, std::vector< std::vector< double > > &matrixSpeedInertiaTable, std::vector< std::vector< double > > &normedDragTable)
bool ReadEmissionData(bool readFC, string DataPath, Helpers Helper, bool fleetMix, Correction DataCor, out List< string > header, out List< List< double >> matrix, out List< double > idlingValues)
static CEP AddRangeCeps(CEP[] cps, Helpers Helper)
static bool CheckClass(CEP[] cps)
static string[] AGGREGATED_VEHICLECLASSES
bool IniDETfactor(Helpers Helper)
Dictionary< string, double > DETFactors
bool IniTNOxfactor(Helpers Helper)
bool setclass(const std::string &VEH)
Dictionary< string, List< double > > DragCurve
Dictionary< string, List< double > > Transm
Transmission_Data TransmissionData
Rollres_Data RollingResData
FullLoadDrag_Data FLDData
C++ TraCI client API implementation.