From 239ac7935e3ffca2cdfd96b1854edbef4435fa11 Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Fri, 22 May 2015 10:21:02 +0200 Subject: [PATCH] make tests run again, started with refactoring for declaration data --- VectoCore/FileIO/InputFileReader.cs | 23 ++++ VectoCore/FileIO/VehicleFileDeclaration.cs | 2 +- .../Connector/Ports/IDriverDemandProvider.cs | 4 +- .../Ports/IDrivingCycleDemandProvider.cs | 4 +- .../Simulation/Impl/SimulatorFactory.cs | 4 +- .../Data/CombustionEngineData.cs | 34 +++--- .../Data/JsonDataHeader.cs | 2 +- .../Data/SimulationComponentData.cs | 4 +- .../SimulationComponent/Data/VehicleData.cs | 103 +++++++++++------- ...clarationModeSimulationComponentFactory.cs | 26 +++-- ...gineeringModeSimulationComponentFactory.cs | 67 +++++++++++- .../Models/SimulationComponent/IDriver.cs | 2 +- .../Models/SimulationComponent/IVehicle.cs | 7 +- .../Impl/DistanceBasedDrivingCycle.cs | 4 +- .../Models/SimulationComponent/Impl/Driver.cs | 14 ++- .../Impl/TimeBasedDrivingCycle.cs | 15 +-- .../SimulationComponent/Impl/Vehicle.cs | 4 +- VectoCore/Utils/SI.cs | 64 +++++++---- VectoCore/VectoCore.csproj | 9 +- .../Models/SimulationComponent/VehicleTest.cs | 9 +- .../VehicleDataTest.cs | 4 +- VectoCoreTest/Utils/ResultFileHelper.cs | 1 + 22 files changed, 281 insertions(+), 125 deletions(-) create mode 100644 VectoCore/FileIO/InputFileReader.cs diff --git a/VectoCore/FileIO/InputFileReader.cs b/VectoCore/FileIO/InputFileReader.cs new file mode 100644 index 0000000000..2c023d53b2 --- /dev/null +++ b/VectoCore/FileIO/InputFileReader.cs @@ -0,0 +1,23 @@ +using System; +using Common.Logging; +using Newtonsoft.Json; + +namespace TUGraz.VectoCore.FileIO +{ + public class InputFileReader + { + protected ILog Log; + + protected InputFileReader() + { + Log = LogManager.GetLogger(GetType()); + } + + protected Tuple<int, bool> GetFileVersion(string jsonStr) + { + dynamic json = JsonConvert.DeserializeObject(jsonStr); + return new Tuple<int, bool>(Int32.Parse(json.Header.FileVersion.ToString()), + Boolean.Parse(json.Body.SavedInDeclMode.ToString())); + } + } +} \ No newline at end of file diff --git a/VectoCore/FileIO/VehicleFileDeclaration.cs b/VectoCore/FileIO/VehicleFileDeclaration.cs index f234a69b9f..138b36d153 100644 --- a/VectoCore/FileIO/VehicleFileDeclaration.cs +++ b/VectoCore/FileIO/VehicleFileDeclaration.cs @@ -117,7 +117,7 @@ namespace TUGraz.VectoCore.FileIO { //[JsonProperty] //public double Inertia; - [JsonProperty(Required = Required.Always)] public string WheelsStr; + [JsonProperty("Wheels", Required = Required.Always)] public string WheelsStr; //[JsonProperty(Required = Required.Always)] //public double AxleWeightShare; [JsonProperty(Required = Required.Always)] public bool TwinTyres; diff --git a/VectoCore/Models/Connector/Ports/IDriverDemandProvider.cs b/VectoCore/Models/Connector/Ports/IDriverDemandProvider.cs index f960621dc2..bce021607f 100644 --- a/VectoCore/Models/Connector/Ports/IDriverDemandProvider.cs +++ b/VectoCore/Models/Connector/Ports/IDriverDemandProvider.cs @@ -9,7 +9,7 @@ /// Returns the inport to connect it to another outport. /// </summary> /// <returns></returns> - IDriverDemandInPort InPort(); + IDriverDemandInPort InShaft(); } /// <summary> @@ -21,6 +21,6 @@ /// Returns the outport to send requests to. /// </summary> /// <returns></returns> - IDriverDemandOutPort OutPort(); + IDriverDemandOutPort OutShaft(); } } \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IDrivingCycleDemandProvider.cs b/VectoCore/Models/Connector/Ports/IDrivingCycleDemandProvider.cs index 54a062609a..c33b4f8d4d 100644 --- a/VectoCore/Models/Connector/Ports/IDrivingCycleDemandProvider.cs +++ b/VectoCore/Models/Connector/Ports/IDrivingCycleDemandProvider.cs @@ -9,7 +9,7 @@ /// Returns the inport to connect it to another outport. /// </summary> /// <returns></returns> - IDrivingCycleDemandInPort InPort(); + IDrivingCycleDemandInPort InShaft(); } /// <summary> @@ -21,6 +21,6 @@ /// Returns the outport to send requests to. /// </summary> /// <returns></returns> - IDrivingCycleDemandOutPort OutPort(); + IDrivingCycleDemandOutPort OutShaft(); } } \ No newline at end of file diff --git a/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs b/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs index 97ff0a9af0..064d70baa2 100644 --- a/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs +++ b/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.SimulationComponent; using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Factories; using TUGraz.VectoCore.Models.SimulationComponent.Impl; namespace TUGraz.VectoCore.Models.Simulation.Impl @@ -217,7 +218,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl return; } - var vehicleData = VehicleData.ReadFromFile(vehicleFile); + var vehicleData = EngineeringModeSimulationComponentFactory.Instance().CreateVehicleData(vehicleFile); + //VehicleData.ReadFromFile(vehicleFile); _vehicle = new Vehicle(_container, vehicleData); } diff --git a/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs b/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs index 166c129343..ce53411e44 100644 --- a/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs +++ b/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs @@ -69,7 +69,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data public SI Displacement { get { return _data.Body.Displacement.SI().Cubic.Centi.Meter.ConvertTo().Cubic.Meter.Value(); } - protected set { _data.Body.Displacement = (double)value.ConvertTo().Cubic.Centi.Meter; } + protected set { _data.Body.Displacement = (double) value.ConvertTo().Cubic.Centi.Meter; } } /// <summary> @@ -78,7 +78,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data public PerSecond IdleSpeed { get { return _data.Body.IdleSpeed.RPMtoRad(); } - protected set { _data.Body.IdleSpeed = (double)value.ConvertTo().Rounds.Per.Minute; } + protected set { _data.Body.IdleSpeed = (double) value.ConvertTo().Rounds.Per.Minute; } } /// <summary> @@ -87,7 +87,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data public KilogramSquareMeter Inertia { get { return _data.Body.Inertia.SI<KilogramSquareMeter>(); } - protected set { _data.Body.Inertia = (double)value.ConvertTo().Kilo.Gramm.Square.Meter; } + protected set { _data.Body.Inertia = (double) value.ConvertTo().Kilo.Gramm.Square.Meter; } } /// <summary> @@ -96,7 +96,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data public SI WHTCUrban { get { return _data.Body.WHTCUrban.SI().Gramm.Per.Kilo.Watt.Hour.ConvertTo().Kilo.Gramm.Per.Watt.Second.Value(); } - protected set { _data.Body.WHTCUrban = (double)value.ConvertTo().Gramm.Per.Kilo.Watt.Hour; } + protected set { _data.Body.WHTCUrban = (double) value.ConvertTo().Gramm.Per.Kilo.Watt.Hour; } } /// <summary> @@ -105,7 +105,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data public SI WHTCRural { get { return _data.Body.WHTCRural.SI().Gramm.Per.Kilo.Watt.Hour.ConvertTo().Kilo.Gramm.Per.Watt.Second.Value(); } - protected set { _data.Body.WHTCRural = (double)value.ConvertTo().Gramm.Per.Kilo.Watt.Hour; } + protected set { _data.Body.WHTCRural = (double) value.ConvertTo().Gramm.Per.Kilo.Watt.Hour; } } /// <summary> @@ -114,7 +114,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data public SI WHTCMotorway { get { return _data.Body.WHTCMotorway.SI().Gramm.Per.Kilo.Watt.Hour.ConvertTo().Kilo.Gramm.Per.Watt.Second.Value(); } - protected set { _data.Body.WHTCMotorway = (double)value.ConvertTo().Gramm.Per.Kilo.Watt.Hour; } + protected set { _data.Body.WHTCMotorway = (double) value.ConvertTo().Gramm.Per.Kilo.Watt.Hour; } } [DataMember] @@ -157,7 +157,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data public string ToJson() { - _data.Header.Date = DateTime.Now; + _data.Header.Date = DateTime.Now.ToString(CultureInfo.InvariantCulture); _data.Header.FileVersion = 2; _data.Header.AppVersion = "3.0.0"; // todo: get current app version! _data.Header.CreatedBy = ""; // todo: get current user @@ -260,7 +260,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data if (obj.GetType() != GetType()) { return false; } - return Equals((DataFullLoadCurve)obj); + return Equals((DataFullLoadCurve) obj); } public override int GetHashCode() @@ -301,7 +301,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data if (obj.GetType() != GetType()) { return false; } - return Equals((DataBody)obj); + return Equals((DataBody) obj); } public override int GetHashCode() @@ -342,7 +342,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data if (obj.GetType() != GetType()) { return false; } - return Equals((Data)obj); + return Equals((Data) obj); } public override int GetHashCode() @@ -359,18 +359,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + return sourceType == typeof (string) || base.CanConvertFrom(context, sourceType); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { - return value.GetType() == typeof(string) - ? new Range((string)value) + return value.GetType() == typeof (string) + ? new Range((string) value) : base.ConvertFrom(context, culture, value); } } - [TypeConverter(typeof(RangeConverter))] + [TypeConverter(typeof (RangeConverter))] private class Range { private readonly uint _end; @@ -413,13 +413,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data if (obj.GetType() != GetType()) { return false; } - return Equals((Range)obj); + return Equals((Range) obj); } public override int GetHashCode() { unchecked { - return (int)((_start * 397) ^ _end); + return (int) ((_start * 397) ^ _end); } } @@ -447,7 +447,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data if (obj.GetType() != GetType()) { return false; } - return Equals((CombustionEngineData)obj); + return Equals((CombustionEngineData) obj); } public override int GetHashCode() diff --git a/VectoCore/Models/SimulationComponent/Data/JsonDataHeader.cs b/VectoCore/Models/SimulationComponent/Data/JsonDataHeader.cs index 646416f189..db169b94b8 100644 --- a/VectoCore/Models/SimulationComponent/Data/JsonDataHeader.cs +++ b/VectoCore/Models/SimulationComponent/Data/JsonDataHeader.cs @@ -7,7 +7,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data { [JsonProperty(Required = Required.Always)] public string AppVersion; [JsonProperty(Required = Required.Always)] public string CreatedBy; - [JsonProperty(Required = Required.Always)] public DateTime Date; + [JsonProperty(Required = Required.Always)] public string Date; [JsonProperty(Required = Required.Always)] public double FileVersion; #region Equality members diff --git a/VectoCore/Models/SimulationComponent/Data/SimulationComponentData.cs b/VectoCore/Models/SimulationComponent/Data/SimulationComponentData.cs index a4ff190fbe..ea6d458a1f 100644 --- a/VectoCore/Models/SimulationComponent/Data/SimulationComponentData.cs +++ b/VectoCore/Models/SimulationComponent/Data/SimulationComponentData.cs @@ -13,11 +13,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data Log = LogManager.GetLogger(GetType()); } - protected static Tuple<int, bool> GetFileVersion(string jsonStr) { dynamic json = JsonConvert.DeserializeObject(jsonStr); - return new Tuple<int, bool>(json.Header.FileVersion, json.Body.SavedinDeclMode); + return new Tuple<int, bool>(Int32.Parse(json.Header.FileVersion.ToString()), + Boolean.Parse(json.Body.SavedInDeclMode.ToString())); } } } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Data/VehicleData.cs b/VectoCore/Models/SimulationComponent/Data/VehicleData.cs index 8245d55e61..9c561e76d3 100644 --- a/VectoCore/Models/SimulationComponent/Data/VehicleData.cs +++ b/VectoCore/Models/SimulationComponent/Data/VehicleData.cs @@ -1,4 +1,5 @@ using System; +using System.CodeDom; using System.Collections; using System.Collections.Generic; using System.IO; @@ -95,76 +96,102 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data CrossSectionAreaRigidTruck = data.CrossSectionAreaRigidTruck.SI<SquareMeter>(); } - public string BasePath { get; protected set; } + public string BasePath { get; internal set; } public bool SavedInDeclarationMode { get; internal set; } - protected readonly VehicleCategory _vehicleCategory; + public VehicleCategory VehicleCategory { get; internal set; } - public VehicleCategory VehicleCategory - { - get { return _vehicleCategory; } - } + public CrossWindCorrectionMode CrossWindCorrectionMode { get; internal set; } - public CrossWindCorrectionMode CrossWindCorrectionMode { get; protected set; } + public RetarderData Retarder { get; internal set; } - public RetarderData Retarder { get; protected set; } + private List<Axle> _axleData; - //[DataMember] private List<Axle> _axleData; + /// <summary> + /// Set the properties for all axles of the vehicle + /// </summary> + public List<Axle> AxleData + { + get { return _axleData; } + internal set + { + _axleData = value; + ComputeRollResistanceAndReducedMassWheels(); + } + } - public AxleConfiguration AxleConfiguration { get; protected set; } + public AxleConfiguration AxleConfiguration { get; internal set; } - public Kilogram CurbWeight { get; protected set; } + public Kilogram CurbWeight { get; internal set; } - public Kilogram CurbWeigthExtra { get; protected set; } + public Kilogram CurbWeigthExtra { get; internal set; } - public Kilogram Loading { get; protected set; } + public Kilogram Loading { get; internal set; } public Kilogram TotalVehicleWeight() { - return CurbWeight + CurbWeigthExtra + Loading; + var retVal = 0.SI<Kilogram>(); + retVal += CurbWeight ?? 0.SI<Kilogram>(); + retVal += CurbWeigthExtra ?? 0.SI<Kilogram>(); + retVal += Loading ?? 0.SI<Kilogram>(); + return retVal; } - public Kilogram GrossVehicleMassRating { get; protected internal set; } - - public double DragCoefficient { get; protected internal set; } + public Kilogram GrossVehicleMassRating { get; internal set; } - public SquareMeter CrossSectionArea { get; protected internal set; } + public double DragCoefficient { get; internal set; } - public double DragCoefficientRigidTruck { get; protected internal set; } + public SquareMeter CrossSectionArea { get; internal set; } - public SquareMeter CrossSectionAreaRigidTruck { get; protected internal set; } + public double DragCoefficientRigidTruck { get; internal set; } - public CrossWindCorrectionMode CrossWindCorrection { get; protected set; } + public SquareMeter CrossSectionAreaRigidTruck { get; internal set; } - public Meter DynamicTyreRadius { get; protected set; } + public CrossWindCorrectionMode CrossWindCorrection { get; internal set; } - public Kilogram ReducedMassWheels { get; set; } + public Meter DynamicTyreRadius { get; internal set; } - public string Rim { get; protected set; } + public Kilogram ReducedMassWheels { get; private set; } - public double TotalRollResistanceCoefficient { get; protected set; } - } + public string Rim { get; internal set; } - public class Axle - { - //private DataV5Engineering.DataBody.AxleData _data; + public double TotalRollResistanceCoefficient { get; private set; } - public Axle() + protected void ComputeRollResistanceAndReducedMassWheels() { - //_data = data; + if (TotalVehicleWeight() == 0.SI<Kilogram>()) { + throw new VectoException("Total vehicle weight must be greater than 0! Set CurbWeight and Loading before!"); + } + if (DynamicTyreRadius == null) { + throw new VectoException("Dynamic tyre radius must be set before axles!"); + } + + var RRC = 0.0; + var mRed0 = 0.SI<Kilogram>(); + foreach (var axle in _axleData) { + var nrWheels = axle.TwinTyres ? 4 : 2; + RRC += axle.AxleWeightShare * axle.RollResistanceCoefficient * + Math.Pow( + (axle.AxleWeightShare * TotalVehicleWeight() * Physics.GravityAccelleration / axle.TyreTestLoad / + nrWheels).Double(), Physics.RollResistanceExponent - 1); + mRed0 += nrWheels * (axle.Inertia / DynamicTyreRadius / DynamicTyreRadius).Cast<Kilogram>(); + } + TotalRollResistanceCoefficient = RRC; + ReducedMassWheels = mRed0; } + } - //public Axle(DataV5Declaration.DataBody.AxleData data) {} - - public KilogramSquareMeter Inertia { get; protected set; } + public class Axle + { + public KilogramSquareMeter Inertia { get; internal set; } - public double RollResistanceCoefficient { get; protected set; } + public double RollResistanceCoefficient { get; internal set; } - public Newton TyreTestLoad { get; protected set; } + public Newton TyreTestLoad { get; internal set; } - public double AxleWeightShare { get; protected set; } + public double AxleWeightShare { get; internal set; } - public bool TwinTyres { get; protected set; } + public bool TwinTyres { get; internal set; } } } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Factories/DeclarationModeSimulationComponentFactory.cs b/VectoCore/Models/SimulationComponent/Factories/DeclarationModeSimulationComponentFactory.cs index 25723571c1..462a91d8a1 100644 --- a/VectoCore/Models/SimulationComponent/Factories/DeclarationModeSimulationComponentFactory.cs +++ b/VectoCore/Models/SimulationComponent/Factories/DeclarationModeSimulationComponentFactory.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using Newtonsoft.Json; using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.FileIO; @@ -8,7 +9,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Factories { - public class DeclarationModeSimulationComponentFactory + public class DeclarationModeSimulationComponentFactory : InputFileReader { protected static DeclarationModeSimulationComponentFactory _instance; @@ -20,7 +21,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Factories public VehicleData CreateVehicleData(string fileName) { var json = File.ReadAllText(fileName); - var fileInfo = SimulationComponentData.GetFileVersion(json); + var fileInfo = GetFileVersion(json); if (!fileInfo.Item2) { throw new VectoException("File not saved in Declaration Mode!"); @@ -37,15 +38,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Factories protected VehicleData CreateVehicleData(string basePath, VehicleFileV5Declaration.DataBodyDecl data) { - return new VehicleData { - SavedInDeclarationMode = data.SavedInDeclarationMode, - VehicleCategory = data.VehicleCategory(), - GrossVehicleMassRating = data.GrossVehicleMassRating.SI<Kilogram>(), - DragCoefficient = data.DragCoefficient, - CrossSectionArea = data.CrossSectionArea.SI<SquareMeter>(), - DragCoefficientRigidTruck = data.DragCoefficientRigidTruck, - CrossSectionAreaRigidTruck = data.CrossSectionAreaRigidTruck.SI<SquareMeter>() - }; + //return new VehicleData { + // SavedInDeclarationMode = data.SavedInDeclarationMode, + // VehicleCategory = data.VehicleCategory(), + // GrossVehicleMassRating = data.GrossVehicleMassRating.SI<Kilogram>(), + // DragCoefficient = data.DragCoefficient, + // CrossSectionArea = data.CrossSectionArea.SI<SquareMeter>(), + // DragCoefficientRigidTruck = data.DragCoefficientRigidTruck, + // CrossSectionAreaRigidTruck = data.CrossSectionAreaRigidTruck.SI<SquareMeter>() + //}; + return null; } } } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Factories/EngineeringModeSimulationComponentFactory.cs b/VectoCore/Models/SimulationComponent/Factories/EngineeringModeSimulationComponentFactory.cs index 4fc13cbb6f..180216a222 100644 --- a/VectoCore/Models/SimulationComponent/Factories/EngineeringModeSimulationComponentFactory.cs +++ b/VectoCore/Models/SimulationComponent/Factories/EngineeringModeSimulationComponentFactory.cs @@ -1,7 +1,68 @@ -namespace TUGraz.VectoCore.Models.SimulationComponent.Factories +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Newtonsoft.Json; +using TUGraz.VectoCore.Exceptions; +using TUGraz.VectoCore.FileIO; +using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Models.SimulationComponent.Factories { - public class EngineeringModeSimulationComponentFactory + public class EngineeringModeSimulationComponentFactory : InputFileReader { - + protected static EngineeringModeSimulationComponentFactory _instance; + + public static EngineeringModeSimulationComponentFactory Instance() + { + return _instance ?? (_instance = new EngineeringModeSimulationComponentFactory()); + } + + public VehicleData CreateVehicleData(string fileName) + { + var json = File.ReadAllText(fileName); + var fileInfo = GetFileVersion(json); + + if (fileInfo.Item2) { + Log.WarnFormat("File {0} was saved in Declaration Mode but is used for Engineering Mode!", fileName); + } + + switch (fileInfo.Item1) { + case 5: + var data = JsonConvert.DeserializeObject<VehicleFileV5Engineering>(json); + return CreateVehicleData(Path.GetDirectoryName(fileName), data.Body); + default: + throw new UnsupportedFileVersionException("Unsupported Version of .vveh file. Got Version " + fileInfo.Item1); + } + } + + protected VehicleData CreateVehicleData(string basePath, VehicleFileV5Engineering.DataBodyEng data) + { + return new VehicleData { + BasePath = basePath, + SavedInDeclarationMode = data.SavedInDeclarationMode, + VehicleCategory = data.VehicleCategory(), + CurbWeight = data.CurbWeight.SI<Kilogram>(), + CurbWeigthExtra = data.CurbWeightExtra.SI<Kilogram>(), + Loading = data.Loading.SI<Kilogram>(), + GrossVehicleMassRating = data.GrossVehicleMassRating.SI().Kilo.Kilo.Gramm.Cast<Kilogram>(), + DragCoefficient = data.DragCoefficient, + CrossSectionArea = data.CrossSectionArea.SI<SquareMeter>(), + DragCoefficientRigidTruck = data.DragCoefficientRigidTruck, + CrossSectionAreaRigidTruck = data.CrossSectionAreaRigidTruck.SI<SquareMeter>(), + DynamicTyreRadius = data.DynamicTyreRadius.SI().Milli.Meter.Cast<Meter>(), + // .SI<Meter>(), + Rim = data.RimStr, + Retarder = new RetarderData(data.Retarder, basePath), + AxleData = data.AxleConfig.Axles.Select(axle => new Axle { + Inertia = axle.Inertia.SI<KilogramSquareMeter>(), + TwinTyres = axle.TwinTyres, + RollResistanceCoefficient = axle.RollResistanceCoefficient, + AxleWeightShare = axle.AxleWeightShare, + TyreTestLoad = axle.TyreTestLoad.SI<Newton>() + }).ToList() + }; + } } } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/IDriver.cs b/VectoCore/Models/SimulationComponent/IDriver.cs index dbba662e0b..e6e019ffc7 100644 --- a/VectoCore/Models/SimulationComponent/IDriver.cs +++ b/VectoCore/Models/SimulationComponent/IDriver.cs @@ -5,5 +5,5 @@ namespace TUGraz.VectoCore.Models.SimulationComponent /// <summary> /// Defines interfaces for a driver. /// </summary> - public interface IDriver : IDriverDemandInProvider, IDriverDemandOutProvider {} + public interface IDriver : IDrivingCycleDemandOutProvider, IDriverDemandInProvider {} } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/IVehicle.cs b/VectoCore/Models/SimulationComponent/IVehicle.cs index dab1636302..5a1a336c12 100644 --- a/VectoCore/Models/SimulationComponent/IVehicle.cs +++ b/VectoCore/Models/SimulationComponent/IVehicle.cs @@ -4,6 +4,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent { public interface IVehicle : IRoadPortInProvider, IDriverDemandOutProvider, IFvInPort, IDriverDemandOutPort {} } - /// </summary> - public interface IVehicle : IDriverDemandOutProvider, IRoadPortInProvider {} -} \ No newline at end of file + +/// </summary> +// public interface IVehicle : IDriverDemandOutProvider, IRoadPortInProvider {} +//} \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs index f2bac35791..2943cfd797 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs @@ -26,7 +26,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region IDrivingCycleDemandInProvider - public IDrivingCycleDemandInPort InPort() + public IDrivingCycleDemandInPort InShaft() { return this; } @@ -35,7 +35,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region IDrivingCycleOutProvider - public IDrivingCycleOutPort OutPort() + public IDrivingCycleOutPort OutShaft() { return this; } diff --git a/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/Models/SimulationComponent/Impl/Driver.cs index ad3f6b334d..039200c73a 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -5,7 +5,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class Driver : IDriver, IDriverDemandInPort, IDriverDemandOutPort + public class Driver : IDriver, IDrivingCycleDemandOutPort, IDriverDemandInPort { public Driver(DriverData driverData) { @@ -17,17 +17,23 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl throw new NotImplementedException(); } - public IDriverDemandOutPort OutShaft() + public void Connect(IDriverDemandOutPort other) { throw new NotImplementedException(); } - public void Connect(IDriverDemandOutPort other) + public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond velocity, Radian gradient) { throw new NotImplementedException(); } - public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond velocity, Radian gradient) + + public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSquareSecond accelleration, Radian gradient) + { + throw new NotImplementedException(); + } + + public IDrivingCycleDemandOutPort OutShaft() { throw new NotImplementedException(); } diff --git a/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs index b461043a7b..4237148953 100644 --- a/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs @@ -11,11 +11,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <summary> /// Class representing one Time Based Driving Cycle /// </summary> - public class TimeBasedDrivingCycle : VectoSimulationComponent, IDrivingCycleDemandDrivingCycle, IDrivingCycleDemandInPort, + public class TimeBasedDrivingCycle : VectoSimulationComponent, IDrivingCycleDemandDrivingCycle, + IDrivingCycleDemandInPort, IDrivingCycleOutPort { protected DrivingCycleData Data; - private IDrivingCycleDemandOutPort _outPort; + private IDrivingCycleDemandOutPort _outPort; public TimeBasedDrivingCycle(IVehicleContainer container, DrivingCycleData cycle) : base(container) { @@ -31,9 +32,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #endregion - #region IDrivingCycleDemandInProvider + #region IDrivingCycleDemandInProvider - public IDrivingCycleDemandInPort InPort() + public IDrivingCycleDemandInPort InShaft() { return this; } @@ -45,7 +46,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl IResponse IDrivingCycleOutPort.Request(TimeSpan absTime, TimeSpan dt) { //todo: change to variable time steps - var index = (int)Math.Floor(absTime.TotalSeconds); + var index = (int) Math.Floor(absTime.TotalSeconds); if (index >= Data.Entries.Count) { return new ResponseCycleFinished(); } @@ -56,9 +57,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #endregion - #region IDrivingCycleDemandInPort + #region IDrivingCycleDemandInPort - void IDrivingCycleDemandInPort.Connect(IDrivingCycleDemandOutPort other) + void IDrivingCycleDemandInPort.Connect(IDrivingCycleDemandOutPort other) { _outPort = other; } diff --git a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs index fe50c962c1..f2c0419099 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs @@ -28,12 +28,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _previousState.Velocity = initialVelocity.SI<MeterPerSecond>(); } - public IFvInPort InPort() + public IFvInPort InShaft() { return this; } - public IDriverDemandOutPort OutPort() + public IDriverDemandOutPort OutShaft() { return this; } diff --git a/VectoCore/Utils/SI.cs b/VectoCore/Utils/SI.cs index b6790b01aa..957dbb31b0 100644 --- a/VectoCore/Utils/SI.cs +++ b/VectoCore/Utils/SI.cs @@ -15,7 +15,7 @@ namespace TUGraz.VectoCore.Utils { static Newton() { - Constructors.Add(typeof(Newton), val => new Newton(val)); + Constructors.Add(typeof (Newton), val => new Newton(val)); } [JsonConstructor] @@ -26,7 +26,7 @@ namespace TUGraz.VectoCore.Utils { static Radian() { - Constructors.Add(typeof(Radian), val => new Radian(val)); + Constructors.Add(typeof (Radian), val => new Radian(val)); } [JsonConstructor] @@ -34,16 +34,21 @@ namespace TUGraz.VectoCore.Utils } + public class MeterPerSquareSecond : SIBase<MeterPerSquareSecond> { - public MeterPerSquareSecond() : this(0) {} - protected MeterPerSquareSecond(double val) : base(val, new SI().Meter.Per.Square.Second) {} + static MeterPerSquareSecond() + { + Constructors.Add(typeof (MeterPerSquareSecond), val => new MeterPerSquareSecond(val)); + } + + protected MeterPerSquareSecond(double val) : base(new SI(val).Meter.Per.Square.Second) {} } public class Second : SIBase<Second> { static Second() { - Constructors.Add(typeof(Second), val => new Second(val)); + Constructors.Add(typeof (Second), val => new Second(val)); } [JsonConstructor] @@ -52,33 +57,52 @@ namespace TUGraz.VectoCore.Utils public class Meter : SIBase<Meter> { - public Meter() : this(0) {} - protected Meter(double val) : base(val, new SI().Meter) {} + static Meter() + { + Constructors.Add(typeof (Meter), val => new Meter(val)); + } + + protected Meter(double val) : base(new SI(val).Meter) {} } public class Kilogram : SIBase<Kilogram> { - public Kilogram() : this(0) {} - protected Kilogram(double val) : base(val, new SI().Kilo.Gramm) {} + static Kilogram() + { + Constructors.Add(typeof (Kilogram), val => new Kilogram(val)); + } + + [JsonConstructor] + protected Kilogram(double val) : base(new SI(val).Kilo.Gramm) {} } public class SquareMeter : SIBase<SquareMeter> { - public SquareMeter() : this(0) {} - protected SquareMeter(double val) : base(val, new SI().Square.Meter) {} + static SquareMeter() + { + Constructors.Add(typeof (SquareMeter), val => new SquareMeter(val)); + } + + [JsonConstructor] + private SquareMeter(double val) : base(new SI(val).Square.Meter) {} } public class KilogramSquareMeter : SIBase<KilogramSquareMeter> { - public KilogramSquareMeter() : this(0) {} - protected KilogramSquareMeter(double val) : base(val, new SI().Kilo.Gramm.Square.Meter) {} + static KilogramSquareMeter() + { + Constructors.Add(typeof (KilogramSquareMeter), val => new KilogramSquareMeter(val)); + } + + [JsonConstructor] + protected KilogramSquareMeter(double val) : base(new SI(val).Kilo.Gramm.Square.Meter) {} } public class Watt : SIBase<Watt> { static Watt() { - Constructors.Add(typeof(Watt), val => new Watt(val)); + Constructors.Add(typeof (Watt), val => new Watt(val)); } [JsonConstructor] @@ -99,7 +123,7 @@ namespace TUGraz.VectoCore.Utils { static PerSecond() { - Constructors.Add(typeof(PerSecond), val => new PerSecond(val)); + Constructors.Add(typeof (PerSecond), val => new PerSecond(val)); } [JsonConstructor] @@ -110,7 +134,7 @@ namespace TUGraz.VectoCore.Utils { static MeterPerSecond() { - Constructors.Add(typeof(MeterPerSecond), val => new MeterPerSecond(val)); + Constructors.Add(typeof (MeterPerSecond), val => new MeterPerSecond(val)); } [JsonConstructor] @@ -122,7 +146,7 @@ namespace TUGraz.VectoCore.Utils { static RoundsPerMinute() { - Constructors.Add(typeof(RoundsPerMinute), val => new RoundsPerMinute(val)); + Constructors.Add(typeof (RoundsPerMinute), val => new RoundsPerMinute(val)); } [JsonConstructor] @@ -134,7 +158,7 @@ namespace TUGraz.VectoCore.Utils { static NewtonMeter() { - Constructors.Add(typeof(NewtonMeter), val => new NewtonMeter(val)); + Constructors.Add(typeof (NewtonMeter), val => new NewtonMeter(val)); } [JsonConstructor] @@ -163,8 +187,8 @@ namespace TUGraz.VectoCore.Utils public static T Create(double val) { - RuntimeHelpers.RunClassConstructor(typeof(T).TypeHandle); - return Constructors[typeof(T)](val); + RuntimeHelpers.RunClassConstructor(typeof (T).TypeHandle); + return Constructors[typeof (T)](val); } protected SIBase(Type type, Func<double, T> constructor) diff --git a/VectoCore/VectoCore.csproj b/VectoCore/VectoCore.csproj index 16aaa62ae1..c52471e4eb 100644 --- a/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore.csproj @@ -108,6 +108,7 @@ <ItemGroup> <Compile Include="Exceptions\VectoExceptions.cs" /> <Compile Include="Exceptions\VectoSimulationException.cs" /> + <Compile Include="FileIO\InputFileReader.cs" /> <Compile Include="FileIO\VehicleFileDeclaration.cs" /> <Compile Include="FileIO\VehicleFileEngineering.cs" /> <Compile Include="Models\Connector\Ports\IDriverDemandPort.cs" /> @@ -122,8 +123,10 @@ <Compile Include="Models\Connector\Ports\IFvPort.cs" /> <Compile Include="Models\Connector\Ports\ITnPort.cs" /> <Compile Include="Models\DeclarationData.cs" /> + <Compile Include="Models\Declaration\LookupData.cs" /> <Compile Include="Models\Declaration\Rims.cs" /> <Compile Include="Models\Declaration\Wheels.cs" /> + <Compile Include="Models\SimulationComponent\Data\AuxiliaryCycleDataAdapter.cs" /> <Compile Include="Models\SimulationComponent\Data\CombustionEngineData.cs" /> <Compile Include="Models\SimulationComponent\Data\DrivingCycleData.cs" /> <Compile Include="Models\SimulationComponent\Data\Engine\FuelConsumptionMap.cs" /> @@ -138,24 +141,24 @@ <Compile Include="Models\SimulationComponent\Data\RetarderData.cs" /> <Compile Include="Models\SimulationComponent\Data\RetarderLossMap.cs" /> <Compile Include="Models\SimulationComponent\Data\VehicleData.cs" /> + <Compile Include="Models\SimulationComponent\Factories\DeclarationModeSimulationComponentFactory.cs" /> + <Compile Include="Models\SimulationComponent\Factories\EngineeringModeSimulationComponentFactory.cs" /> <Compile Include="Models\SimulationComponent\IClutch.cs" /> <Compile Include="Models\SimulationComponent\IEngineOnlyDrivingCycle.cs" /> <Compile Include="Models\SimulationComponent\IDriverDemandDrivingCycle.cs" /> <Compile Include="Models\SimulationComponent\IDriver.cs" /> <Compile Include="Models\SimulationComponent\Impl\MappingAuxiliary.cs" /> + <Compile Include="Models\SimulationComponent\Impl\Vehicle.cs" /> <Compile Include="Models\SimulationComponent\IVehicle.cs" /> <Compile Include="Models\SimulationComponent\Impl\Clutch.cs" /> <Compile Include="Models\SimulationComponent\Impl\AxleGear.cs" /> <Compile Include="Models\SimulationComponent\Impl\Retarder.cs" /> - <Compile Include="Models\SimulationComponent\Impl\Vehicle.cs" /> <Compile Include="Models\SimulationComponent\IPowerTrainComponent.cs" /> <Compile Include="Models\Simulation\Data\ISummaryDataWriter.cs" /> <Compile Include="Models\Simulation\Data\SummaryFileWriter.cs" /> <Compile Include="Models\Simulation\Data\VectoJobData.cs" /> <Compile Include="Models\SimulationComponent\Impl\Driver.cs" /> <Compile Include="Models\SimulationComponent\Data\DriverData.cs" /> - <Compile Include="Models\SimulationComponent\Impl\Vehicle.cs" /> - <Compile Include="Models\SimulationComponent\Data\VehicleData.cs" /> <Compile Include="Utils\Formulas.cs" /> <Compile Include="Utils\IntExtensionMethods.cs" /> <Compile Include="Utils\Physics.cs" /> diff --git a/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs b/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs index 3e0b269589..89d14cd359 100644 --- a/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs @@ -2,7 +2,9 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Factories; using TUGraz.VectoCore.Models.SimulationComponent.Impl; +using TUGraz.VectoCore.Tests.Utils; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Tests.Models.SimulationComponent @@ -17,15 +19,16 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent { var container = new VehicleContainer(); - var vehicleData = VehicleData.ReadFromFile(VehicleDataFile); + var vehicleData = EngineeringModeSimulationComponentFactory.Instance().CreateVehicleData(VehicleDataFile); + //VehicleData.ReadFromFile(VehicleDataFile); //vehicleData.CrossWindCorrection = VehicleData.CrossWindCorrectionMode.NoCorrection; var vehicle = new Vehicle(container, vehicleData, 17.210535); var mockPort = new MockFvOutPort(); - vehicle.InPort().Connect(mockPort); + vehicle.InShaft().Connect(mockPort); - var requestPort = vehicle.OutPort(); + var requestPort = vehicle.OutShaft(); var absTime = TimeSpan.FromSeconds(0); var dt = TimeSpan.FromSeconds(1); diff --git a/VectoCoreTest/Models/SimulationComponentData/VehicleDataTest.cs b/VectoCoreTest/Models/SimulationComponentData/VehicleDataTest.cs index 008ad5875d..ba8e708d35 100644 --- a/VectoCoreTest/Models/SimulationComponentData/VehicleDataTest.cs +++ b/VectoCoreTest/Models/SimulationComponentData/VehicleDataTest.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Factories; namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData { @@ -11,7 +12,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData [TestMethod] public void ReadVehicleFileTest() { - var vehicleData = VehicleData.ReadFromFile(VehicleDataFile); + var vehicleData = EngineeringModeSimulationComponentFactory.Instance().CreateVehicleData(VehicleDataFile); + //VehicleData.ReadFromFile(VehicleDataFile); Assert.AreEqual(VehicleCategory.Coach, vehicleData.VehicleCategory); } diff --git a/VectoCoreTest/Utils/ResultFileHelper.cs b/VectoCoreTest/Utils/ResultFileHelper.cs index dda285790a..3658b316ca 100644 --- a/VectoCoreTest/Utils/ResultFileHelper.cs +++ b/VectoCoreTest/Utils/ResultFileHelper.cs @@ -38,6 +38,7 @@ namespace TUGraz.VectoCore.Tests.Utils var resultFiles = expectedFiles.ZipAll(actualFiles, (expectedFile, actualFile) => new { expectedFile, actualFile }); foreach (var result in resultFiles) { Assert.IsTrue(File.Exists(result.actualFile), "MOD File is missing: " + result); + Assert.IsTrue(File.Exists(result.expectedFile), "Expected File is missing: " + result); var expected = ModalResults.ReadFromFile(result.expectedFile); var actual = ModalResults.ReadFromFile(result.actualFile); -- GitLab