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)
106 for (
int i = 0; i < normedDragTable.Count; i++)
108 if (normedDragTable[i].Count != 2)
120 for (
int i = 0; i < matrixFC.Count; i++)
122 if (matrixFC[i].Count != 2)
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++)
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
327 #region Private Members
375 public double CalcPower(
double speed,
double acc,
double gradient)
410 List<double> emissionCurve;
411 List<double> powerPattern;
421 if (pollutant ==
"FC")
429 VehicleClass.
ErrMsg =
"Emission pollutant " + pollutant +
" not found!";
438 if (pollutant ==
"FC")
447 VehicleClass.
ErrMsg =
"Emission pollutant " + pollutant +
" not found!";
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")
503 VehicleClass.
ErrMsg =
"Emission pollutant " + pollutant +
" not found!";
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;
563 VehicleClass.
ErrMsg =
"The propolsion type is not known! (" +
_fuelType +
")";
567 return (_FC * fCBr - _CO * fCCO - _HC * fCHC) / fCCO2;
571 #region GetDecelCoast
623 #region GetRotationalCoeffecient
640 #region GetGearCoeffecient
656 #region GetDragCoeffecient
673 #region FindLowerUpperInPattern
679 if (value <= pattern.First())
686 if (value >= pattern.Last())
688 lowerIndex = pattern.Count - 1;
689 upperIndex = pattern.Count - 1;
694 int middleIndex = (pattern.Count - 1) / 2;
695 upperIndex = pattern.Count - 1;
698 while (upperIndex - lowerIndex > 1)
700 if (pattern[middleIndex] == value)
702 lowerIndex = middleIndex;
703 upperIndex = middleIndex;
706 else if (pattern[middleIndex] < value)
708 lowerIndex = middleIndex;
709 middleIndex = (upperIndex - lowerIndex) / 2 + lowerIndex;
713 upperIndex = middleIndex;
714 middleIndex = (upperIndex - lowerIndex) / 2 + lowerIndex;
718 if (pattern[lowerIndex] <= value && value < pattern[upperIndex])
726 private double Interpolate(
double px,
double p1,
double p2,
double e1,
double e2)
731 return e1 + (px - p1) / (p2 - p1) * (e2 - e1);
769 CEP newCEP =
new CEP(cps.Select(p => p.HeavyVehicle ? 1 : 0).Sum() > 0,
770 cps.Select(p => p._massVehicle).Sum(),
771 cps.Select(p => p._vehicleLoading).Sum(),
772 cps.Select(p => p._vehicleMassRot).Sum(),
773 cps.Select(p => p._crossSectionalArea).Sum(),
774 cps.Select(p => p._cWValue).Sum(),
775 cps.Select(p => p._resistanceF0).Sum(),
776 cps.Select(p => p._resistanceF1).Sum(),
777 cps.Select(p => p._resistanceF2).Sum(),
778 cps.Select(p => p._resistanceF3).Sum(),
779 cps.Select(p => p._resistanceF4).Sum(),
780 cps.Select(p => p._axleRatio).Sum(),
781 cps.Select(p => p._auxPower).Sum(),
782 cps.Select(p => p._ratedPower).Sum(),
783 cps.Select(p => p._engineIdlingSpeed).Sum(),
784 cps.Select(p => p._engineRatedSpeed).Sum(),
785 cps.Select(p => p._effectiveWheelDiameter).Sum(),
786 cps.Select(p => p._pNormV0).Sum(),
787 cps.Select(p => p._pNormP0).Sum(),
788 cps.Select(p => p._pNormV1).Sum(),
789 cps.Select(p => p._pNormP1).Sum());
791 newCEP._fuelType = cps.First().FuelType;
794 #region SpeedRotationalTable
795 double minSpeedRotational = cps.Select(p => p._speedPatternRotational.First()).
Min();
796 double maxSpeedRotational = cps.Select(p => p._speedPatternRotational.Last()).
Max();
798 newCEP._speedPatternRotational
803 newCEP._speedCurveRotational =
new List<double>();
804 newCEP._gearTransmissionCurve =
new List<double>();
806 for (
int i = 0; i < newCEP._speedPatternRotational.Count; i++)
808 newCEP._speedCurveRotational.Add(cps.Select(p => p.GetRotationalCoeffecient(newCEP._speedPatternRotational[i])).Sum());
810 newCEP._gearTransmissionCurve.Add(cps.Select(p => p.GetGearCoeffecient(newCEP._speedPatternRotational[i])).Sum());
814 #region NormalizingPower
817 if (newCEP._heavyVehicle)
819 newCEP._normalizingPower = newCEP._ratedPower;
824 newCEP._normalizingPower = newCEP._drivingPower;
830 double minNormPowerPatternFC = cps.Select(p => p._normalizedPowerPatternFC.First()).
Min();
831 double maxNormPowerPatternFC = cps.Select(p => p._normalizedPowerPatternFC.Last()).
Max();
833 newCEP._normalizedPowerPatternFC
835 maxNormPowerPatternFC,
838 newCEP._cepCurveFC =
new List<double>();
839 newCEP._normedCepCurveFC =
new List<double>();
840 newCEP._powerPatternFC =
new List<double>();
842 for (
int i = 0; i < newCEP._normalizedPowerPatternFC.Count; i++)
844 double newCepVal = cps.Select(p => p.GetNormedEmission(
"FC", newCEP._normalizedPowerPatternFC[i],
double.MaxValue, Helper)).Sum();
845 newCEP._cepCurveFC.Add(newCepVal * newCEP._ratedPower);
846 newCEP._normedCepCurveFC.Add(newCepVal);
847 newCEP._powerPatternFC.Add(newCEP._normalizedPowerPatternFC[i] * newCEP._ratedPower);
852 double minNormPowerPattern = cps.Select(p => p._normailzedPowerPatternPollutants.First()).
Min();
853 double maxNormPowerPattern = cps.Select(p => p._normailzedPowerPatternPollutants.Last()).
Max();
855 newCEP._normailzedPowerPatternPollutants
860 newCEP._cepCurvePollutants =
new Dictionary<string, List<double>>();
861 newCEP._powerPatternPollutants =
new List<double>();
862 newCEP._cepNormalizedCurvePollutants =
new Dictionary<string, List<double>>();
864 foreach (
string id in cps.First()._cepCurvePollutants.Keys)
866 newCEP._cepCurvePollutants.Add(
id,
new List<double>());
867 newCEP._cepNormalizedCurvePollutants.Add(
id,
new List<double>());
870 for (
int i = 0; i < newCEP._normailzedPowerPatternPollutants.Count; i++)
872 foreach (
string id in newCEP._cepCurvePollutants.Keys)
876 double newCepVal = cps.Select(p => p.GetNormedEmission(
id, newCEP._normailzedPowerPatternPollutants[i],
double.MaxValue, Helper)).Sum();
877 newCEP._cepCurvePollutants[id].Add(newCepVal * newCEP._ratedPower);
878 newCEP._cepNormalizedCurvePollutants[id].Add(newCepVal);
882 newCEP._cepCurvePollutants[id].Add(cps.Select(p => p.GetEmission(
id, newCEP._normailzedPowerPatternPollutants[i] * p._normalizingPower,
double.MaxValue, Helper)).Sum());
883 newCEP._cepNormalizedCurvePollutants[id].Add(cps.Select(p => p.GetNormedEmission(
id, newCEP._normailzedPowerPatternPollutants[i],
double.MaxValue, Helper)).Sum());
886 newCEP._powerPatternPollutants.Add(newCEP._normailzedPowerPatternPollutants[i] * newCEP.NormalizingPower);
891 newCEP._idlingValueFC = cps.Select(p => p._idlingValueFC).Sum();
892 newCEP._idlingValuesPollutants =
new Dictionary<string, double>();
894 foreach (
string id in cps.First()._idlingValuesPollutants.Keys)
896 newCEP._idlingValuesPollutants.Add(
id, cps.Select(p => p._idlingValuesPollutants[
id]).Sum());
901 double minTragTable = cps.Select(p => p._nNormTable.First()).
Min();
902 double maxTragTable = cps.Select(p => p._nNormTable.Last()).
Max();
909 newCEP._dragNormTable =
new List<double>();
911 for (
int i = 0; i < newCEP._nNormTable.Count; i++)
913 newCEP._dragNormTable.Add(cps.Select(p => p.GetDragCoeffecient(newCEP._nNormTable[i])).Sum());
924 CEP newCEP =
new CEP(cp1.HeavyVehicle,
925 d * cp1._massVehicle,
926 d * cp1._vehicleLoading,
927 d * cp1._vehicleMassRot,
928 d * cp1._crossSectionalArea,
930 d * cp1._resistanceF0,
931 d * cp1._resistanceF1,
932 d * cp1._resistanceF2,
933 d * cp1._resistanceF3,
934 d * cp1._resistanceF4,
938 d * cp1._engineIdlingSpeed,
939 d * cp1._engineRatedSpeed,
940 d * cp1._effectiveWheelDiameter,
946 newCEP._fuelType = cp1.FuelType;
949 #region SpeedRotationalTable
950 newCEP._speedPatternRotational =
new List<double>(cp1._speedPatternRotational);
951 newCEP._speedCurveRotational =
new List<double>(cp1._speedCurveRotational.Select(p => p * d));
952 newCEP._gearTransmissionCurve =
new List<double>(cp1._gearTransmissionCurve.Select(p => p * d));
955 #region NormalizingPower
958 if (newCEP._heavyVehicle)
960 newCEP._normalizingPower = newCEP._ratedPower;
965 newCEP._normalizingPower = newCEP._drivingPower;
971 newCEP._powerPatternFC =
new List<double>(cp1._powerPatternFC.Select(p => p * d));
972 newCEP._normalizedPowerPatternFC =
new List<double>(cp1._normalizedPowerPatternFC);
973 newCEP._cepCurveFC =
new List<double>(cp1._cepCurveFC.Select(p => p * d));
974 newCEP._normedCepCurveFC =
new List<double>(cp1._normedCepCurveFC.Select(p => p * d));
978 newCEP._powerPatternPollutants =
new List<double>(cp1._normailzedPowerPatternPollutants.Select(p => p * newCEP._normalizingPower));
979 newCEP._normailzedPowerPatternPollutants =
new List<double>(cp1._normailzedPowerPatternPollutants);
980 newCEP._cepCurvePollutants =
new Dictionary<string, List<double>>();
981 newCEP._cepNormalizedCurvePollutants =
new Dictionary<string, List<double>>();
983 foreach (
string id in cp1._cepCurvePollutants.Keys)
985 newCEP._cepCurvePollutants.Add(
id,
new List<double>(cp1._cepCurvePollutants[
id].Select(p => p * d)));
986 newCEP._cepNormalizedCurvePollutants.Add(
id,
new List<double>(cp1._cepNormalizedCurvePollutants[
id].Select(p => p * d)));
991 newCEP._idlingValueFC = cp1._idlingValueFC * d;
992 newCEP._idlingValuesPollutants =
new Dictionary<string, double>();
994 foreach (
string id in cp1._idlingValuesPollutants.Keys)
996 newCEP._idlingValuesPollutants.Add(
id,
997 cp1._idlingValuesPollutants[
id] * d);
1002 newCEP._nNormTable =
new List<double>(cp1._nNormTable);
1003 newCEP._dragNormTable =
new List<double>(cp1._dragNormTable.Select(p => p * d));
1009 #region CreatePattern
1010 static public List<double>
CreatePattern(
double min,
double max,
double increment)
1013 List<double> pattern =
new List<double>();
1014 double actualMin = min;
1015 double actualMax = max;
1018 actualMin = Math.Ceiling(min / increment) * increment;
1020 actualMin = Math.Floor(min / increment) * increment;
1023 actualMax = Math.Floor(max / increment) * increment;
1025 actualMax = Math.Ceiling(max / increment) * increment;
1027 double curVal = actualMin;
1029 while (curVal <= actualMax)
1031 pattern.Add(curVal);
1032 curVal += increment;