3 using System.Collections.Generic;
6 using System.Threading.Tasks;
17 public CEP(
bool heavyVehicle,
19 double vehicleLoading,
20 double vehicleMassRot,
29 List<double> transmissionGearRatios,
32 double engineIdlingSpeed,
33 double engineRatedSpeed,
34 double effictiveWheelDiameter,
39 string vehicelFuelType,
40 List<List<double>> matrixFC,
41 List<string> headerLinePollutants,
42 List<List<double>> matrixPollutants,
43 List<List<double>> matrixSpeedRotational,
44 List<List<double>> normedDragTable,
46 List<double> idlingPollutants)
72 List<string> pollutantIdentifier =
new List<string>();
73 List<List<double>> pollutantMeasures =
new List<List<double>>();
74 List<List<double>> normalizedPollutantMeasures =
new List<List<double>>();
77 for (
int i = 0; i < headerLinePollutants.Count; i++)
79 pollutantIdentifier.Add(headerLinePollutants[i]);
83 for (
int i = 0; i < headerLinePollutants.Count; i++)
85 pollutantMeasures.Add(
new List<double>());
86 normalizedPollutantMeasures.Add(
new List<double>());
93 for (
int i = 0; i < matrixSpeedRotational.Count; i++)
95 if (matrixSpeedRotational[i].Count != 3)
98 _speedPatternRotational.Add(matrixSpeedRotational[i][0] / 3.6);
99 _gearTransmissionCurve.Add(matrixSpeedRotational[i][1]);
106 for (
int i = 0; i < normedDragTable.Count; i++)
108 if (normedDragTable[i].Count != 2)
112 _dragNormTable.Add(normedDragTable[i][1]);
120 for (
int i = 0; i < matrixFC.Count; i++)
122 if (matrixFC[i].Count != 2)
126 _normalizedPowerPatternFC.Add(matrixFC[i][0]);
128 _normedCepCurveFC.Add(matrixFC[i][1]);
134 double pollutantMultiplyer = 1;
155 int headerCount = headerLinePollutants.Count;
156 for (
int i = 0; i < matrixPollutants.Count; i++)
158 for (
int j = 0; j < matrixPollutants[i].Count; j++)
160 if (matrixPollutants[i].Count != headerCount + 1)
170 pollutantMeasures[j - 1].Add(matrixPollutants[i][j] * pollutantMultiplyer);
171 normalizedPollutantMeasures[j - 1].Add(matrixPollutants[i][j]);
179 for (
int i = 0; i < headerLinePollutants.Count; i++)
182 _cepNormalizedCurvePollutants.Add(pollutantIdentifier[i], normalizedPollutantMeasures[i]);
183 _idlingValuesPollutants.Add(pollutantIdentifier[i], idlingPollutants[i] * pollutantMultiplyer);
191 #region ConstrutorForFleetmix 192 private CEP(
bool heavyVehicle,
194 double vehicleLoading,
195 double vehicleMassRot,
206 double engineIdlingSpeed,
207 double engineRatedSpeed,
208 double effictiveWheelDiameter,
269 #region NormalizingType 300 #region NormalizingPower 321 _drivingPower = value;
327 #region Private Members 375 public double CalcPower(
double speed,
double acc,
double gradient)
385 power += (_massVehicle * rotFactor + _vehicleMassRot +
_vehicleLoading) * acc * speed;
399 if (power < _powerPatternFC.First())
return _powerPatternFC.First();
400 if (power > _powerPatternFC.Last())
return _powerPatternFC.Last();
410 List<double> emissionCurve;
411 List<double> powerPattern;
421 if (pollutant ==
"FC")
427 if (!_cepCurvePollutants.ContainsKey(pollutant))
429 VehicleClass.
ErrMsg =
"Emission pollutant " + pollutant +
" not found!";
433 return _idlingValuesPollutants[pollutant];
438 if (pollutant ==
"FC")
445 if (!_cepCurvePollutants.ContainsKey(pollutant))
447 VehicleClass.
ErrMsg =
"Emission pollutant " + pollutant +
" not found!";
451 emissionCurve = _cepCurvePollutants[pollutant];
455 if (emissionCurve.Count == 0)
457 VehicleClass.
ErrMsg =
"Empty emission curve for " + pollutant +
" found!";
460 if (emissionCurve.Count == 1)
462 return emissionCurve[0];
466 if (power <= powerPattern.First())
468 return emissionCurve[0];
472 if (power >= powerPattern.Last())
474 return emissionCurve.Last();
478 return Interpolate(power, powerPattern[lowerIndex], powerPattern[upperIndex], emissionCurve[lowerIndex], emissionCurve[upperIndex]);
483 #region GetNormedEmission 487 List<double> emissionCurve;
488 List<double> powerPattern;
494 if (pollutant ==
"FC")
501 if (!_cepCurvePollutants.ContainsKey(pollutant))
503 VehicleClass.
ErrMsg =
"Emission pollutant " + pollutant +
" not found!";
506 emissionCurve = _cepNormalizedCurvePollutants[pollutant];
510 if (emissionCurve.Count == 0)
512 VehicleClass.
ErrMsg =
"Empty emission curve for " + pollutant +
" found!";
515 if (emissionCurve.Count == 1)
517 return emissionCurve[0];
520 if (power <= powerPattern.First())
522 return emissionCurve[0];
526 if (power >= powerPattern.Last())
528 return emissionCurve.Last();
532 return Interpolate(power, powerPattern[lowerIndex], powerPattern[upperIndex], emissionCurve[lowerIndex], emissionCurve[upperIndex]);
537 #region GetCO2Emission 544 double fCCO2 = 0.273;
559 VehicleClass.
ErrMsg =
"The propolsion type is not known! (" + _fuelType +
")";
563 return (_FC * fCBr - _CO * fCCO - _HC * fCHC) / fCCO2;
567 #region GetDecelCoast 582 _speedPatternRotational[lowerIndex],
583 _speedPatternRotational[upperIndex],
584 _gearTransmissionCurve[lowerIndex],
585 _gearTransmissionCurve[upperIndex]);
589 double n = (30 * speed * iTot) / ((_effectiveWheelDiameter / 2) * Math.PI);
599 _nNormTable[lowerIndex],
600 _nNormTable[upperIndex],
601 _dragNormTable[lowerIndex],
602 _dragNormTable[upperIndex]) * _ratedPower * 1000 / speed) / 0.9;
605 double fRoll = (_resistanceF0
606 + _resistanceF1 * speed
607 + Math.Pow(_resistanceF2 * speed, 2)
608 + Math.Pow(_resistanceF3 * speed, 3)
611 double fAir = _cWValue * _crossSectionalArea * 1.2 * 0.5 * Math.Pow(speed, 2);
615 return -(fMot + fRoll + fAir + fGrad) / ((_massVehicle +
_vehicleLoading) * rotCoeff);
619 #region GetRotationalCoeffecient 628 _speedPatternRotational[lowerIndex],
629 _speedPatternRotational[upperIndex],
630 _speedCurveRotational[lowerIndex],
631 _speedCurveRotational[upperIndex]);
636 #region GetGearCoeffecient 645 _speedPatternRotational[lowerIndex],
646 _speedPatternRotational[upperIndex],
647 _gearTransmissionCurve[lowerIndex],
648 _gearTransmissionCurve[upperIndex]);
652 #region GetDragCoeffecient 661 _nNormTable[lowerIndex],
662 _nNormTable[upperIndex],
663 _dragNormTable[lowerIndex],
664 _dragNormTable[upperIndex]);
669 #region FindLowerUpperInPattern 675 if (value <= pattern.First())
682 if (value >= pattern.Last())
684 lowerIndex = pattern.Count - 1;
685 upperIndex = pattern.Count - 1;
690 int middleIndex = (pattern.Count - 1) / 2;
691 upperIndex = pattern.Count - 1;
694 while (upperIndex - lowerIndex > 1)
696 if (pattern[middleIndex] == value)
698 lowerIndex = middleIndex;
699 upperIndex = middleIndex;
702 else if (pattern[middleIndex] < value)
704 lowerIndex = middleIndex;
705 middleIndex = (upperIndex - lowerIndex) / 2 + lowerIndex;
709 upperIndex = middleIndex;
710 middleIndex = (upperIndex - lowerIndex) / 2 + lowerIndex;
714 if (pattern[lowerIndex] <= value && value < pattern[upperIndex])
722 private double Interpolate(
double px,
double p1,
double p2,
double e1,
double e2)
727 return e1 + (px - p1) / (p2 - p1) * (e2 - e1);
740 CEP newCEP =
new CEP(cps.Select(p => p.HeavyVehicle ? 1 : 0).Sum() > 0,
741 cps.Select(p => p._massVehicle).Sum(),
742 cps.Select(p => p._vehicleLoading).Sum(),
743 cps.Select(p => p._vehicleMassRot).Sum(),
744 cps.Select(p => p._crossSectionalArea).Sum(),
745 cps.Select(p => p._cWValue).Sum(),
746 cps.Select(p => p._resistanceF0).Sum(),
747 cps.Select(p => p._resistanceF1).Sum(),
748 cps.Select(p => p._resistanceF2).Sum(),
749 cps.Select(p => p._resistanceF3).Sum(),
750 cps.Select(p => p._resistanceF4).Sum(),
751 cps.Select(p => p._axleRatio).Sum(),
752 cps.Select(p => p._auxPower).Sum(),
753 cps.Select(p => p._ratedPower).Sum(),
754 cps.Select(p => p._engineIdlingSpeed).Sum(),
755 cps.Select(p => p._engineRatedSpeed).Sum(),
756 cps.Select(p => p._effectiveWheelDiameter).Sum(),
757 cps.Select(p => p._pNormV0).Sum(),
758 cps.Select(p => p._pNormP0).Sum(),
759 cps.Select(p => p._pNormV1).Sum(),
760 cps.Select(p => p._pNormP1).Sum());
762 newCEP._fuelType = cps.First().FuelType;
765 #region SpeedRotationalTable 766 double minSpeedRotational = cps.Select(p => p._speedPatternRotational.First()).
Min();
767 double maxSpeedRotational = cps.Select(p => p._speedPatternRotational.Last()).
Max();
769 newCEP._speedPatternRotational
774 newCEP._speedCurveRotational =
new List<double>();
775 newCEP._gearTransmissionCurve =
new List<double>();
777 for (
int i = 0; i < newCEP._speedPatternRotational.Count; i++)
779 newCEP._speedCurveRotational.Add(cps.Select(p => p.GetRotationalCoeffecient(newCEP._speedPatternRotational[i])).Sum());
781 newCEP._gearTransmissionCurve.Add(cps.Select(p => p.GetGearCoeffecient(newCEP._speedPatternRotational[i])).Sum());
785 #region NormalizingPower 788 if (newCEP._heavyVehicle)
790 newCEP._normalizingPower = newCEP._ratedPower;
795 newCEP._normalizingPower = newCEP._drivingPower;
801 double minNormPowerPatternFC = cps.Select(p => p._normalizedPowerPatternFC.First()).
Min();
802 double maxNormPowerPatternFC = cps.Select(p => p._normalizedPowerPatternFC.Last()).
Max();
804 newCEP._normalizedPowerPatternFC
806 maxNormPowerPatternFC,
809 newCEP._cepCurveFC =
new List<double>();
810 newCEP._normedCepCurveFC =
new List<double>();
811 newCEP._powerPatternFC =
new List<double>();
813 for (
int i = 0; i < newCEP._normalizedPowerPatternFC.Count; i++)
815 double newCepVal = cps.Select(p => p.GetNormedEmission(
"FC", newCEP._normalizedPowerPatternFC[i],
double.MaxValue, Helper)).Sum();
816 newCEP._cepCurveFC.Add(newCepVal * newCEP._ratedPower);
817 newCEP._normedCepCurveFC.Add(newCepVal);
818 newCEP._powerPatternFC.Add(newCEP._normalizedPowerPatternFC[i] * newCEP._ratedPower);
823 double minNormPowerPattern = cps.Select(p => p._normailzedPowerPatternPollutants.First()).
Min();
824 double maxNormPowerPattern = cps.Select(p => p._normailzedPowerPatternPollutants.Last()).
Max();
826 newCEP._normailzedPowerPatternPollutants
831 newCEP._cepCurvePollutants =
new Dictionary<string, List<double>>();
832 newCEP._powerPatternPollutants =
new List<double>();
833 newCEP._cepNormalizedCurvePollutants =
new Dictionary<string, List<double>>();
835 foreach (
string id in cps.First()._cepCurvePollutants.Keys)
837 newCEP._cepCurvePollutants.Add(
id,
new List<double>());
838 newCEP._cepNormalizedCurvePollutants.Add(
id,
new List<double>());
841 for (
int i = 0; i < newCEP._normailzedPowerPatternPollutants.Count; i++)
843 foreach (
string id in newCEP._cepCurvePollutants.Keys)
847 double newCepVal = cps.Select(p => p.GetNormedEmission(
id, newCEP._normailzedPowerPatternPollutants[i],
double.MaxValue, Helper)).Sum();
848 newCEP._cepCurvePollutants[id].Add(newCepVal * newCEP._ratedPower);
849 newCEP._cepNormalizedCurvePollutants[id].Add(newCepVal);
853 newCEP._cepCurvePollutants[id].Add(cps.Select(p => p.GetEmission(
id, newCEP._normailzedPowerPatternPollutants[i] * p._normalizingPower,
double.MaxValue, Helper)).Sum());
854 newCEP._cepNormalizedCurvePollutants[id].Add(cps.Select(p => p.GetNormedEmission(
id, newCEP._normailzedPowerPatternPollutants[i],
double.MaxValue, Helper)).Sum());
857 newCEP._powerPatternPollutants.Add(newCEP._normailzedPowerPatternPollutants[i] * newCEP.NormalizingPower);
862 newCEP._idlingValueFC = cps.Select(p => p._idlingValueFC).Sum();
863 newCEP._idlingValuesPollutants =
new Dictionary<string, double>();
865 foreach (
string id in cps.First()._idlingValuesPollutants.Keys)
867 newCEP._idlingValuesPollutants.Add(
id, cps.Select(p => p._idlingValuesPollutants[
id]).Sum());
872 double minTragTable = cps.Select(p => p._nNormTable.First()).
Min();
873 double maxTragTable = cps.Select(p => p._nNormTable.Last()).
Max();
880 newCEP._dragNormTable =
new List<double>();
882 for (
int i = 0; i < newCEP._nNormTable.Count; i++)
884 newCEP._dragNormTable.Add(cps.Select(p => p.GetDragCoeffecient(newCEP._nNormTable[i])).Sum());
895 CEP newCEP =
new CEP(cp1.HeavyVehicle,
896 d * cp1._massVehicle,
897 d * cp1._vehicleLoading,
898 d * cp1._vehicleMassRot,
899 d * cp1._crossSectionalArea,
901 d * cp1._resistanceF0,
902 d * cp1._resistanceF1,
903 d * cp1._resistanceF2,
904 d * cp1._resistanceF3,
905 d * cp1._resistanceF4,
909 d * cp1._engineIdlingSpeed,
910 d * cp1._engineRatedSpeed,
911 d * cp1._effectiveWheelDiameter,
917 newCEP._fuelType = cp1.FuelType;
920 #region SpeedRotationalTable 921 newCEP._speedPatternRotational =
new List<double>(cp1._speedPatternRotational);
922 newCEP._speedCurveRotational =
new List<double>(cp1._speedCurveRotational.Select(p => p * d));
923 newCEP._gearTransmissionCurve =
new List<double>(cp1._gearTransmissionCurve.Select(p => p * d));
926 #region NormalizingPower 929 if (newCEP._heavyVehicle)
931 newCEP._normalizingPower = newCEP._ratedPower;
936 newCEP._normalizingPower = newCEP._drivingPower;
942 newCEP._powerPatternFC =
new List<double>(cp1._powerPatternFC.Select(p => p * d));
943 newCEP._normalizedPowerPatternFC =
new List<double>(cp1._normalizedPowerPatternFC);
944 newCEP._cepCurveFC =
new List<double>(cp1._cepCurveFC.Select(p => p * d));
945 newCEP._normedCepCurveFC =
new List<double>(cp1._normedCepCurveFC.Select(p => p * d));
949 newCEP._powerPatternPollutants =
new List<double>(cp1._normailzedPowerPatternPollutants.Select(p => p * newCEP._normalizingPower));
950 newCEP._normailzedPowerPatternPollutants =
new List<double>(cp1._normailzedPowerPatternPollutants);
951 newCEP._cepCurvePollutants =
new Dictionary<string, List<double>>();
952 newCEP._cepNormalizedCurvePollutants =
new Dictionary<string, List<double>>();
954 foreach (
string id in cp1._cepCurvePollutants.Keys)
956 newCEP._cepCurvePollutants.Add(
id,
new List<double>(cp1._cepCurvePollutants[
id].Select(p => p * d)));
957 newCEP._cepNormalizedCurvePollutants.Add(
id,
new List<double>(cp1._cepNormalizedCurvePollutants[
id].Select(p => p * d)));
962 newCEP._idlingValueFC = cp1._idlingValueFC * d;
963 newCEP._idlingValuesPollutants =
new Dictionary<string, double>();
965 foreach (
string id in cp1._idlingValuesPollutants.Keys)
967 newCEP._idlingValuesPollutants.Add(
id,
968 cp1._idlingValuesPollutants[
id] * d);
973 newCEP._nNormTable =
new List<double>(cp1._nNormTable);
974 newCEP._dragNormTable =
new List<double>(cp1._dragNormTable.Select(p => p * d));
980 #region CreatePattern 984 List<double> pattern =
new List<double>();
985 double actualMin =
min;
986 double actualMax =
max;
989 actualMin = Math.Ceiling(min / increment) * increment;
991 actualMin = Math.Floor(min / increment) * increment;
994 actualMax = Math.Floor(max / increment) * increment;
996 actualMax = Math.Ceiling(max / increment) * increment;
998 double curVal = actualMin;
1000 while (curVal <= actualMax)
1002 pattern.Add(curVal);
1003 curVal += increment;
List< double > _normalizedPowerPatternFC
List< double > _cepCurveFC
std::vector< double > _speedPatternRotational
List< double > _normedCepCurveFC
static const double SPEED_DCEL_MIN
static const std::string strCNG
List< double > _speedPatternRotational
const double SPEED_ROTATIONAL_INCREMENT
const double POWER_FC_INCREMENT
Dictionary< string, List< double > > _cepNormalizedCurvePollutants
double GetEmission(string pollutant, double power, double speed, Helpers VehicleClass)
List< double > _powerPatternPollutants
std::vector< double > _normailzedPowerPatternPollutants
std::vector< double > _dragNormTable
std::map< std::string, std::vector< double > > _cepCurvePollutants
double _effectiveWheelDiameter
std::vector< double > _nNormTable
List< double > _nNormTable
double GetDragCoeffecient(double nNorm)
static CEP AddRangeCeps(CEP[] cps, Helpers Helper)
List< double > _gearTransmissionCurve
const double NNORM_INCREMENT
double GetGearCoeffecient(double speed)
CEP(bool heavyVehicle, double vehicleMass, double vehicleLoading, double vehicleMassRot, double crossArea, double cWValue, double f0, double f1, double f2, double f3, double f4, double axleRatio, List< double > transmissionGearRatios, double auxPower, double ratedPower, double engineIdlingSpeed, double engineRatedSpeed, double effictiveWheelDiameter, double pNormV0, double pNormP0, double pNormV1, double pNormP1, string vehicelFuelType, List< List< double >> matrixFC, List< string > headerLinePollutants, List< List< double >> matrixPollutants, List< List< double >> matrixSpeedRotational, List< List< double >> normedDragTable, double idlingFC, List< double > idlingPollutants)
Dictionary< string, double > _idlingValuesPollutants
static CEP operator*(CEP cp1, double d)
List< double > _powerPatternFC
double GetRotationalCoeffecient(double speed)
double _engineIdlingSpeed
std::map< std::string, double > _idlingValuesPollutants
std::vector< double > _normedCepCurveFC
static const double NORMALIZING_SPEED
Dictionary< string, List< double > > _cepCurvePollutants
NormalizingType _normalizingType
std::map< std::string, std::vector< double > > _cepNormalizedCurvePollutants
List< double > _normailzedPowerPatternPollutants
std::vector< double > _normalizedPowerPatternFC
static const double NORMALIZING_ACCELARATION
static const std::string strDiesel
double GetDecelCoast(double speed, double acc, double gradient)
NormalizingType NormalizingTypeX
double CalcEngPower(double power)
List< double > _dragNormTable
double GetNormedEmission(string pollutant, double power, double speed, Helpers VehicleClass)
const double POWER_POLLUTANT_INCREMENT
std::vector< double > _speedCurveRotational
std::vector< double > _gearTransmissionCurve
static const std::string strGasoline
void FindLowerUpperInPattern(out int lowerIndex, out int upperIndex, List< double > pattern, double value)
static List< double > CreatePattern(double min, double max, double increment)
CEP(bool heavyVehicle, double vehicleMass, double vehicleLoading, double vehicleMassRot, double crossArea, double cWValue, double f0, double f1, double f2, double f3, double f4, double axleRatio, std::vector< double > &transmissionGearRatios, double auxPower, double ratedPower, double engineIdlingSpeed, double engineRatedSpeed, double effictiveWheelDiameter, double pNormV0, double pNormP0, double pNormV1, double pNormP1, const std::string &vehicelFuelType, std::vector< std::vector< double > > &matrixFC, std::vector< std::string > &headerLinePollutants, std::vector< std::vector< double > > &matrixPollutants, std::vector< std::vector< double > > &matrixSpeedRotational, std::vector< std::vector< double > > &normedDragTable, double idlingFC, std::vector< double > &idlingPollutants)
std::vector< double > _powerPatternFC
List< double > _speedCurveRotational
std::vector< double > _cepCurveFC
static const std::string strBEV
double Interpolate(double px, double p1, double p2, double e1, double e2)
static const double GRAVITY_CONST
double GetCO2Emission(double _FC, double _CO, double _HC, Helpers VehicleClass)
CEP(bool heavyVehicle, 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 effictiveWheelDiameter, double pNormV0, double pNormP0, double pNormV1, double pNormP1)
double _crossSectionalArea
std::vector< double > _powerPatternPollutants
static double _DRIVE_TRAIN_EFFICIENCY
static const double ZERO_SPEED_ACCURACY
double CalcPower(double speed, double acc, double gradient)
static const double AIR_DENSITY_CONST
void FindLowerUpperInPattern(int &lowerIndex, int &upperIndex, std::vector< double > &pattern, double value)