diff --git a/VectoCore/Models/SimulationComponent/Data/CrossWindCorrectionCurve.cs b/VectoCore/Models/SimulationComponent/Data/CrossWindCorrectionCurve.cs index da9ed422d03614de638db074f720c398f6834fe3..2f8751a005b0a2dc058a2082a544eca96b355fea 100644 --- a/VectoCore/Models/SimulationComponent/Data/CrossWindCorrectionCurve.cs +++ b/VectoCore/Models/SimulationComponent/Data/CrossWindCorrectionCurve.cs @@ -131,7 +131,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data averageAirDragPower = (Physics.AirDensity / 2.0 * CdA * vAverage * vAverage * vAverage).Cast<Watt>(); } else { // compute the average force within the current simulation interval - // P(t) = k * CdA * v(t)^3 , v(t) = v0 + a * t // a != 0, P_avg = 1/dt * Integral P(t) + // P(t) = k * CdA * v(t)^3 , v(t) = v0 + a * t // a != 0, P_avg = 1/T * Integral P(t) dt // => P_avg = (CdA * rho/2)/(4*a * dt) * (v2^4 - v1^4) var acceleration = (v2 - v1) / dt; averageAirDragPower = diff --git a/VectoCore/Models/SimulationComponent/Data/VAirBetaCrosswindCorrection.cs b/VectoCore/Models/SimulationComponent/Data/VAirBetaCrosswindCorrection.cs index 91d92679f6b5fb1274c38eaeb2edb8151abe716d..adac8e653e1f24020aa3ee4c00dab9ac6307efcd 100644 --- a/VectoCore/Models/SimulationComponent/Data/VAirBetaCrosswindCorrection.cs +++ b/VectoCore/Models/SimulationComponent/Data/VAirBetaCrosswindCorrection.cs @@ -70,13 +70,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data var vAir = DataBus.CycleData.LeftSample.AirSpeedRelativeToVehicle; var beta = DataBus.CycleData.LeftSample.WindYawAngle; + // F_air(t) = k * CdA_korr * v_air^2 // assumption: v_air = const for the current interval + // P(t) = F_air(t) * v(t) , v(t) = v1 + a * t + // P_avg = 1/T * Integral P(t) dt + // P_avg = k * CdA_korr * v_air^2 * (v1 + v2) / 2 var airDragForce = (AirDragArea + DeltaCdA(beta)) * Physics.AirDensity / 2.0 * vAir * vAir; var vAverage = (v1 + v2) / 2; - if (v1.IsEqual(v2)) { - return (airDragForce * vAverage).Cast<Watt>(); - } - var acceleration = (v2 - v1) / dt; - return (airDragForce * (v2 * v2 - v1 * v1) / (2 * acceleration * dt)).Cast<Watt>(); + + return (airDragForce * vAverage).Cast<Watt>(); } protected SquareMeter DeltaCdA(double beta) diff --git a/VectoCoreTest/Models/Simulation/MeasuredSpeedModeTest.cs b/VectoCoreTest/Models/Simulation/MeasuredSpeedModeTest.cs index 1283088bf79df9168a3d45f734aa1687e3079a4d..c5657d9d8c294665998c250ff2c021fd70a848ea 100644 --- a/VectoCoreTest/Models/Simulation/MeasuredSpeedModeTest.cs +++ b/VectoCoreTest/Models/Simulation/MeasuredSpeedModeTest.cs @@ -381,9 +381,37 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation { var tbl = VectoCSVFile.Read(@"TestData/MeasuredSpeed/VairBeta.vcdb"); - var vairbeta = new VAirBetaCrosswindCorrection(1.SI<SquareMeter>(), tbl); - - Assert.AreEqual(0, vairbeta.AverageAirDragPowerLoss(20.KMPHtoMeterPerSecond(), 20.KMPHtoMeterPerSecond(), 1.SI<Second>()) ); + var dataBus = new MockVairVechicleContainer(); + var vairbeta = new VAirBetaCrosswindCorrection(5.SI<SquareMeter>(), tbl); + vairbeta.SetDataBus(dataBus); + + var cycleEntry = new DrivingCycleData.DrivingCycleEntry() { + AirSpeedRelativeToVehicle = 20.KMPHtoMeterPerSecond(), + WindYawAngle = 0 + }; + dataBus.CycleData = new CycleData() { LeftSample = cycleEntry }; + + var pAvg = + vairbeta.AverageAirDragPowerLoss(20.KMPHtoMeterPerSecond(), 20.KMPHtoMeterPerSecond(), 1.SI<Second>()).Value(); + Assert.AreEqual(509.259, pAvg, 1e-3); + + pAvg = + vairbeta.AverageAirDragPowerLoss(20.KMPHtoMeterPerSecond(), 21.KMPHtoMeterPerSecond(), 1.SI<Second>()).Value(); + Assert.AreEqual(521.990, pAvg, 1e-3); + + pAvg = + vairbeta.AverageAirDragPowerLoss(20.KMPHtoMeterPerSecond(), 30.KMPHtoMeterPerSecond(), 1.SI<Second>()).Value(); + Assert.AreEqual(636.574, pAvg, 1e-3); + + cycleEntry.WindYawAngle = 20; + + pAvg = + vairbeta.AverageAirDragPowerLoss(20.KMPHtoMeterPerSecond(), 20.KMPHtoMeterPerSecond(), 1.SI<Second>()).Value(); + Assert.AreEqual(638.611, pAvg, 1e-3); + + pAvg = + vairbeta.AverageAirDragPowerLoss(20.KMPHtoMeterPerSecond(), 30.KMPHtoMeterPerSecond(), 1.SI<Second>()).Value(); + Assert.AreEqual(798.263, pAvg, 1e-3); } } } \ No newline at end of file diff --git a/VectoCoreTest/Utils/MockVairVechicleContainer.cs b/VectoCoreTest/Utils/MockVairVechicleContainer.cs new file mode 100644 index 0000000000000000000000000000000000000000..7e607a47b8d1c9786cb1f286dc566cb721421e35 --- /dev/null +++ b/VectoCoreTest/Utils/MockVairVechicleContainer.cs @@ -0,0 +1,84 @@ +using System.Collections.Generic; +using TUGraz.VectoCore.Models.Connector.Ports; +using TUGraz.VectoCore.Models.Simulation; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.Simulation.DataBus; +using TUGraz.VectoCore.Models.Simulation.Impl; +using TUGraz.VectoCore.Models.SimulationComponent; +using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.OutputData; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Tests.Utils +{ + public class MockVairVechicleContainer : IVehicleContainer + { + // only CycleData Lookup is set / accessed... + + public uint Gear { get; private set; } + public MeterPerSecond StartSpeed { get; private set; } + public MeterPerSquareSecond StartAcceleration { get; private set; } + public FullLoadCurve GearFullLoadCurve { get; private set; } + public PerSecond EngineSpeed { get; private set; } + + public Watt EngineStationaryFullPower(PerSecond angularSpeed) + { + throw new System.NotImplementedException(); + } + + public PerSecond EngineIdleSpeed { get; private set; } + public PerSecond EngineRatedSpeed { get; private set; } + public MeterPerSecond VehicleSpeed { get; private set; } + public Kilogram VehicleMass { get; private set; } + public Kilogram VehicleLoading { get; private set; } + public Kilogram TotalMass { get; private set; } + public Meter Distance { get; private set; } + + public bool ClutchClosed(Second absTime) + { + throw new System.NotImplementedException(); + } + + public Watt BrakePower { get; set; } + public Meter CycleStartDistance { get; private set; } + + public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Meter lookaheadDistance) + { + throw new System.NotImplementedException(); + } + + public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Second time) + { + throw new System.NotImplementedException(); + } + + public bool VehicleStopped { get; private set; } + public DrivingBehavior DrivingBehavior { get; private set; } + public CycleData CycleData { get; set; } + public ExecutionMode ExecutionMode { get; set; } + public IModalDataContainer ModalData { get; private set; } + public VectoRunData RunData { get; private set; } + + public ISimulationOutPort GetCycleOutPort() + { + throw new System.NotImplementedException(); + } + + public VectoRun.Status RunStatus { get; set; } + + public void AddComponent(VectoSimulationComponent component) + { + throw new System.NotImplementedException(); + } + + public void CommitSimulationStep(Second time, Second simulationInterval) + { + throw new System.NotImplementedException(); + } + + public void FinishSimulation() + { + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/VectoCoreTest/VectoCoreTest.csproj b/VectoCoreTest/VectoCoreTest.csproj index 08001f426877e9ad00ec88a5c17c8bd7144e7d40..1aabd19d48334574ff8ac428cdd0bc18642edf87 100644 --- a/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCoreTest/VectoCoreTest.csproj @@ -93,6 +93,7 @@ <Compile Include="Models\SimulationComponent\GearboxPowertrainTest.cs" /> <Compile Include="Utils\InputDataHelper.cs" /> <Compile Include="Utils\MockSimulationDataFactory.cs" /> + <Compile Include="Utils\MockVairVechicleContainer.cs" /> <Compile Include="Utils\Port.cs" /> <Compile Include="Models\SimulationComponentData\AuxiliaryTypeHelperTest.cs" /> <Compile Include="Models\Simulation\AuxTests.cs" />