diff --git a/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs b/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs index ecfd626cb5fa20960a986b66e0f3446bb7612aac..40e35ab921e259c23e4d62f16ec9a7e403243ce0 100644 --- a/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs +++ b/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs @@ -141,7 +141,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine /// <returns>[kg/s]</returns> public SI GetFuelConsumption(NewtonMeter torque, RadianPerSecond engineSpeed) { - return _fuelMap.Interpolate((double)torque, (double)engineSpeed).SI().Kilo.Gramm.Per.Second; + return _fuelMap.Interpolate((double)torque, (double)engineSpeed.To().Rounds.Per.Minute).SI().Kilo.Gramm.Per.Second; } #region Equality members diff --git a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index d1aacb1738231f8a9164e1c8aeb61eef1f056067..f90d7953c86e92ed7aa3b0713f2c32374a916fee 100644 --- a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -92,10 +92,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected bool Equals(EngineState other) { - return OperationMode == other.OperationMode - && EnginePower.Equals(other.EnginePower) - && EngineSpeed.Equals(other.EngineSpeed) - && EnginePowerLoss.Equals(other.EnginePowerLoss) + return OperationMode == other.OperationMode + && Equals(EnginePower, other.EnginePower) + && Equals(EngineSpeed, other.EngineSpeed) + && Equals(EnginePowerLoss, other.EnginePowerLoss) && AbsTime.Equals(other.AbsTime); } @@ -103,19 +103,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; - return Equals((EngineState)obj); + var other = obj as EngineState; + return other != null && Equals(other); } public override int GetHashCode() { unchecked { - var hashCode = (int)OperationMode; - hashCode = (hashCode * 397) ^ EnginePower.GetHashCode(); - hashCode = (hashCode * 397) ^ EngineSpeed.GetHashCode(); - hashCode = (hashCode * 397) ^ EnginePowerLoss.GetHashCode(); - hashCode = (hashCode * 397) ^ AbsTime.GetHashCode(); + var hashCode = (int) OperationMode; + hashCode = (hashCode*397) ^ (EnginePower != null ? EnginePower.GetHashCode() : 0); + hashCode = (hashCode*397) ^ (EngineSpeed != null ? EngineSpeed.GetHashCode() : 0); + hashCode = (hashCode*397) ^ (EnginePowerLoss != null ? EnginePowerLoss.GetHashCode() : 0); + hashCode = (hashCode*397) ^ AbsTime.GetHashCode(); return hashCode; } } @@ -166,14 +166,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public override void CommitSimulationStep(IModalDataWriter writer) { - writer[ModalResultField.PaEng] = _currentState.EnginePowerLoss; - writer[ModalResultField.Pe_drag] = _currentState.FullDragPower; - writer[ModalResultField.Pe_full] = _currentState.DynamicFullLoadPower; - writer[ModalResultField.Pe_eng] = _currentState.EnginePower; - - writer[ModalResultField.Tq_drag] = _currentState.FullDragTorque; - writer[ModalResultField.Tq_full] = _currentState.DynamicFullLoadTorque; - writer[ModalResultField.Tq_eng] = _currentState.EngineTorque; + writer[ModalResultField.PaEng] = (double)_currentState.EnginePowerLoss; + writer[ModalResultField.Pe_drag] = (double)_currentState.FullDragPower; + writer[ModalResultField.Pe_full] = (double)_currentState.DynamicFullLoadPower; + writer[ModalResultField.Pe_eng] = (double)_currentState.EnginePower; + + writer[ModalResultField.Tq_drag] = (double)_currentState.FullDragTorque; + writer[ModalResultField.Tq_full] = (double)_currentState.DynamicFullLoadTorque; + writer[ModalResultField.Tq_eng] = (double)_currentState.EngineTorque; writer[ModalResultField.n] = (double)_currentState.EngineSpeed.To().Rounds.Per.Minute; try diff --git a/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs b/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs index 6b1c59dea8084680252cae3ee33cf22cad56cda2..5119e43c5adc6d165620cc52c38efc3af81c7a59 100644 --- a/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs +++ b/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs @@ -41,8 +41,8 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle var i = 0; var results = new[] { ModalResultField.n, ModalResultField.PaEng, ModalResultField.Tq_drag, ModalResultField.Pe_drag, ModalResultField.Pe_eng, ModalResultField.Tq_eng, ModalResultField.Tq_full, ModalResultField.Pe_full, }; //, ModalResultField.FC }; - var siFactor = new double[] {1, 1000, 1, 1000, 1000, 1, 1, 1000, 1 }; - var tolerances = new double[] {0.0001, 0.1, 0.0001, 0.1, 0.1, 0.001, 0.001, 0.1, 0.01 }; + var siFactor = new[] {1, 1000, 1, 1000, 1000, 1, 1, 1000, 1 }; + var tolerances = new[] {0.0001, 0.1, 0.0001, 0.1, 0.1, 0.001, 0.001, 0.1, 0.01 }; foreach (var cycle in data.Entries) { port.Request(absTime, dt, cycle.EngineTorque, cycle.EngineSpeed); diff --git a/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs b/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs index 7612bd280c4ff309ddfdbbdc7b464a7c4fbb216f..b58ed85f5ee7f15df83db9552a84cda5de841b95 100644 --- a/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs +++ b/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs @@ -34,7 +34,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation Assert.AreEqual(0.0, outPort.AbsTime.TotalSeconds); Assert.AreEqual(1.0, outPort.Dt.TotalSeconds); Assert.AreEqual(new SI(600).Rounds.Per.Minute, outPort.AngularFrequency); - Assert.AreEqual(0, outPort.Torque); + Assert.AreEqual(0.SI<NewtonMeter>(), outPort.Torque); Assert.AreEqual(0.5, dataWriter[ModalResultField.time]); } @@ -61,7 +61,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation // todo: assert correct values! Assert.AreEqual(0.0, outPort.AbsTime.TotalSeconds); Assert.AreEqual(1.0, outPort.Dt.TotalSeconds); - Assert.AreEqual(0.0, outPort.Velocity); + Assert.AreEqual(0.0.SI<MeterPerSecond>(), outPort.Velocity); Assert.AreEqual(-0.020237973, outPort.Gradient); Assert.AreEqual(0.5, dataWriter[ModalResultField.time]); } diff --git a/VectoCoreTest/Models/SimulationComponentData/FuelConsumptionMapTest.cs b/VectoCoreTest/Models/SimulationComponentData/FuelConsumptionMapTest.cs index cf2cddca34f576b947aa58c2b8b9acc78bb65477..4f2eeb202a5688d7cde28adc911e13209b286528 100644 --- a/VectoCoreTest/Models/SimulationComponentData/FuelConsumptionMapTest.cs +++ b/VectoCoreTest/Models/SimulationComponentData/FuelConsumptionMapTest.cs @@ -38,7 +38,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData try { Assert.AreEqual((double)entry[2].SI().Gramm.Per.Hour.To().Kilo.Gramm.Per.Second, - (double)map.GetFuelConsumption(entry[1].SI<NewtonMeter>(), entry[0].SI().Rounds.Per.Minute.To<RadianPerSecond>()), + (double)map.GetFuelConsumption(entry[1].SI<NewtonMeter>(), entry[0].RPMtoRad()), Tolerance, string.Format("Line: {0}, n={1}, T={2}", (i + 2), entry[0].SI().Rounds.Per.Minute, entry[1])); @@ -46,7 +46,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData catch (VectoException ex) { throw new VectoException(string.Format("Row {0}: Error in ConsumptionMap n={1}, T={2}: {3}", - i + 2, entry[0].SI().Rounds.Per.Minute, entry[1], ex.Message)); + i + 2, entry[0], entry[1], ex.Message)); } } }