diff --git a/VectoCore/FileIO/InputFileReader.cs b/VectoCore/FileIO/InputFileReader.cs index 2c023d53b2a1d2230ded3db40339052db9ab7825..8c91cd6e93933b3ac33648a1cde7a06122cce64a 100644 --- a/VectoCore/FileIO/InputFileReader.cs +++ b/VectoCore/FileIO/InputFileReader.cs @@ -1,5 +1,4 @@ -using System; -using Common.Logging; +using Common.Logging; using Newtonsoft.Json; namespace TUGraz.VectoCore.FileIO @@ -8,16 +7,27 @@ namespace TUGraz.VectoCore.FileIO { protected ILog Log; + protected class VersionInfo + { + public bool SavedInDeclarationMode; + public int Version; + } + protected InputFileReader() { Log = LogManager.GetLogger(GetType()); } - protected Tuple<int, bool> GetFileVersion(string jsonStr) + protected VersionInfo GetFileVersion(string jsonStr) + { + var data = new { Header = new { FileVersion = -1 }, Body = new { SavedInDeclMode = false } }; + JsonConvert.PopulateObject(jsonStr, data); + return new VersionInfo { SavedInDeclarationMode = data.Body.SavedInDeclMode, Version = data.Header.FileVersion }; + } + + protected T Deserialize<T>(string json) { - dynamic json = JsonConvert.DeserializeObject(jsonStr); - return new Tuple<int, bool>(Int32.Parse(json.Header.FileVersion.ToString()), - Boolean.Parse(json.Body.SavedInDeclMode.ToString())); + return JsonConvert.DeserializeObject<T>(json); } } } \ No newline at end of file diff --git a/VectoCore/FileIO/VehicleFileDeclaration.cs b/VectoCore/FileIO/VehicleFileDeclaration.cs index 138b36d15399f9d4cb7a0e21d9fc48be1ae253f3..994dc676cd7ab85e1213dda7d47885b4bc53b387 100644 --- a/VectoCore/FileIO/VehicleFileDeclaration.cs +++ b/VectoCore/FileIO/VehicleFileDeclaration.cs @@ -1,10 +1,7 @@ using System; using System.Collections.Generic; -using System.Runtime.Serialization; using Newtonsoft.Json; -using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Models.SimulationComponent.Data; -using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.FileIO { @@ -69,7 +66,7 @@ namespace TUGraz.VectoCore.FileIO public VehicleCategory VehicleCategory() { - return (VehicleCategory) Enum.Parse(typeof (VehicleCategory), VehicleCategoryStr, true); + return (VehicleCategory)Enum.Parse(typeof(VehicleCategory), VehicleCategoryStr, true); } [JsonProperty(Required = Required.Always)] public double CurbWeight; diff --git a/VectoCore/Models/Declaration/LookupData.cs b/VectoCore/Models/Declaration/LookupData.cs index ac6411b5d1cd507026e153b43c0260dfe432e1dd..76264ef7546d83a3e4fd9733ebd5fd0f0725b514 100644 --- a/VectoCore/Models/Declaration/LookupData.cs +++ b/VectoCore/Models/Declaration/LookupData.cs @@ -1,9 +1,10 @@ using System; using System.Collections.Generic; using System.Data; +using System.Reflection; using TUGraz.VectoCore.Utils; -namespace TUGraz.VectoCore.Resources.Declaration +namespace TUGraz.VectoCore.Models.Declaration { public abstract class LookupData<TEntryType> { @@ -12,10 +13,8 @@ namespace TUGraz.VectoCore.Resources.Declaration protected DataTable ReadCsvFile(string resourceId) { - var myAssembly = System.Reflection.Assembly.GetExecutingAssembly(); - + var myAssembly = Assembly.GetExecutingAssembly(); var file = myAssembly.GetManifestResourceStream(resourceId); - return VectoCSVFile.ReadStream(file); } diff --git a/VectoCore/Models/Declaration/Rims.cs b/VectoCore/Models/Declaration/Rims.cs index 21fd9f9125793ea48b965df5f4ecc1fbe93ed009..cffa2aacdef4e8260b49e57325563089687be6e0 100644 --- a/VectoCore/Models/Declaration/Rims.cs +++ b/VectoCore/Models/Declaration/Rims.cs @@ -1,7 +1,6 @@ using System; using System.Data; using System.Linq; -using TUGraz.VectoCore.Resources.Declaration; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration diff --git a/VectoCore/Models/Declaration/Wheels.cs b/VectoCore/Models/Declaration/Wheels.cs index c5467822f8ca867eee1de632a5ebc5f89412e20d..f5e3ecfd03301140b4aa6dcf0ccb9cb3e644005e 100644 --- a/VectoCore/Models/Declaration/Wheels.cs +++ b/VectoCore/Models/Declaration/Wheels.cs @@ -1,12 +1,6 @@ using System; -using System.Collections; -using System.Collections.Generic; using System.Data; -using System.IO; using System.Linq; -using System.Security.AccessControl; -using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; -using TUGraz.VectoCore.Resources.Declaration; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration diff --git a/VectoCore/Models/DeclarationData.cs b/VectoCore/Models/DeclarationData.cs index 260a7f878086e3ac2c48e94aa320164b2ce3307e..569e6b0091d2f3092f3c620c1e015dd57caeccca 100644 --- a/VectoCore/Models/DeclarationData.cs +++ b/VectoCore/Models/DeclarationData.cs @@ -1,4 +1,6 @@ using TUGraz.VectoCore.Models.Declaration; +using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models { @@ -6,9 +8,9 @@ namespace TUGraz.VectoCore.Models { private static DeclarationData _instance; - public readonly Wheels Wheels; + public Wheels Wheels { get; private set; } - public readonly Rims Rims; + public Rims Rims { get; private set; } private DeclarationData() { @@ -20,5 +22,29 @@ namespace TUGraz.VectoCore.Models { return _instance ?? (_instance = new DeclarationData()); } + + public static Segment GetSegment(VehicleCategory vehicleCategory, AxleConfiguration axleConfiguration, + Kilogram grossVehicleMassRating) + { + throw new System.NotImplementedException(); + } + } + + public class Segment + { + public string HDVClass { get; internal set; } + public string VACC { get; internal set; } + public Mission[] Missions { get; internal set; } + } + + public class Mission + { + public string VCDV { get; set; } + public string Name { get; set; } + public double[] AxleWeightDistribution { get; set; } + public double MassExtra { get; set; } + public Kilogram RefLoad { get; set; } + public string CycleFile { get; set; } + public Kilogram[] Loadings { get; set; } } } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Factories/DeclarationModeFactory.cs b/VectoCore/Models/SimulationComponent/Factories/DeclarationModeFactory.cs new file mode 100644 index 0000000000000000000000000000000000000000..7f6f568f11de181318d6d8e7757d6d8dfd512bbc --- /dev/null +++ b/VectoCore/Models/SimulationComponent/Factories/DeclarationModeFactory.cs @@ -0,0 +1,77 @@ +using System; +using System.IO; +using TUGraz.VectoCore.Exceptions; +using TUGraz.VectoCore.FileIO; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Data; + +namespace TUGraz.VectoCore.Models.SimulationComponent.Factories +{ + public class DeclarationModeFactory : InputFileReader + { + protected static DeclarationModeFactory _instance; + + public static DeclarationModeFactory Instance() + { + return _instance ?? (_instance = new DeclarationModeFactory()); + } + + protected void CheckDeclarationMode(VersionInfo fileInfo) + { + if (!fileInfo.SavedInDeclarationMode) { + throw new VectoException("File not saved in Declaration Mode!"); + } + } + + public VehicleData ReadVehicleData(string filename) + { + var json = File.ReadAllText(filename); + var fileInfo = GetFileVersion(json); + CheckDeclarationMode(fileInfo); + + switch (fileInfo.Version) { + case 5: + return CreateVehicleData(Path.GetDirectoryName(filename), Deserialize<VehicleFileV5Declaration>(json)); + default: + throw new UnsupportedFileVersionException(string.Format("Unsupported Version of {0} file. Got Version {1}", + Path.GetExtension(filename), fileInfo.Version)); + } + } + + protected VehicleData CreateVehicleData(string basePath, VehicleFileV5Declaration 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 null; + } + + public VectoJobData ReadJobFile(string filename) + { + var json = File.ReadAllText(filename); + var fileInfo = GetFileVersion(json); + CheckDeclarationMode(fileInfo); + + switch (fileInfo.Version) { + case 5: + return CreateVectoJobData(Path.GetDirectoryName(filename), Deserialize<VectoJobFileV2Declaration>(json)); + default: + throw new UnsupportedFileVersionException(string.Format("Unsupported Version of {0} file. Got Version {1}", + Path.GetExtension(filename), fileInfo.Version)); + } + } + + private VectoJobData CreateVectoJobData(string basePath, VectoJobFileV2Declaration data) + { + throw new NotImplementedException(); + } + } + + public class VectoJobFileV2Declaration {} +} \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Factories/DeclarationModeSimulationComponentFactory.cs b/VectoCore/Models/SimulationComponent/Factories/DeclarationModeSimulationComponentFactory.cs deleted file mode 100644 index 462a91d8a155d3a97cee064cea7565d1586e9e30..0000000000000000000000000000000000000000 --- a/VectoCore/Models/SimulationComponent/Factories/DeclarationModeSimulationComponentFactory.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.IO; -using Newtonsoft.Json; -using TUGraz.VectoCore.Exceptions; -using TUGraz.VectoCore.FileIO; -using TUGraz.VectoCore.Models.SimulationComponent.Data; -using TUGraz.VectoCore.Models.SimulationComponent.Impl; -using TUGraz.VectoCore.Utils; - -namespace TUGraz.VectoCore.Models.SimulationComponent.Factories -{ - public class DeclarationModeSimulationComponentFactory : InputFileReader - { - protected static DeclarationModeSimulationComponentFactory _instance; - - public static DeclarationModeSimulationComponentFactory Instance() - { - return _instance ?? (_instance = new DeclarationModeSimulationComponentFactory()); - } - - public VehicleData CreateVehicleData(string fileName) - { - var json = File.ReadAllText(fileName); - var fileInfo = GetFileVersion(json); - - if (!fileInfo.Item2) { - throw new VectoException("File not saved in Declaration Mode!"); - } - - switch (fileInfo.Item1) { - case 5: - var data = JsonConvert.DeserializeObject<VehicleFileV5Declaration>(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, 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 null; - } - } -} \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Factories/EngineeringModeSimulationComponentFactory.cs b/VectoCore/Models/SimulationComponent/Factories/EngineeringModeSimulationComponentFactory.cs index 180216a2229923842e2e04343d5325c54c9f5a1b..310604e719f46febc67edb9a64b1bf21ab3ac5ed 100644 --- a/VectoCore/Models/SimulationComponent/Factories/EngineeringModeSimulationComponentFactory.cs +++ b/VectoCore/Models/SimulationComponent/Factories/EngineeringModeSimulationComponentFactory.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; +using System.IO; using System.Linq; using Newtonsoft.Json; using TUGraz.VectoCore.Exceptions; diff --git a/VectoCore/Models/SimulationComponent/Impl/Wheels.cs b/VectoCore/Models/SimulationComponent/Impl/Wheels.cs index 7f32d93926ae864d338fb9fef617b436646110fa..22312359373e9f5332b888a8f4888cadb4bb8555 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Wheels.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Wheels.cs @@ -19,7 +19,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region IRoadPortOutProvider - IFvOutPort IRoadPortOutProvider.OutPort() + public IFvOutPort OutPort() { return this; } @@ -28,7 +28,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region IInShaft - ITnInPort IInShaft.InShaft() + public ITnInPort InShaft() { return this; } @@ -39,8 +39,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl IResponse IFvOutPort.Request(TimeSpan absTime, TimeSpan dt, Newton force, MeterPerSecond velocity) { - NewtonMeter torque = (force * _dynamicWheelRadius).Cast<NewtonMeter>(); - var angularVelocity = (velocity / _dynamicWheelRadius).Cast<PerSecond>(); + var torque = force * _dynamicWheelRadius; + var angularVelocity = velocity / _dynamicWheelRadius; return _outPort.Request(absTime, dt, torque, angularVelocity); } diff --git a/VectoCore/Utils/SI.cs b/VectoCore/Utils/SI.cs index 957dbb31b0c33cf95684509a275d871d946a2c1c..c8adb861b778c1f367b339cb87c46920f0d5353f 100644 --- a/VectoCore/Utils/SI.cs +++ b/VectoCore/Utils/SI.cs @@ -15,18 +15,23 @@ namespace TUGraz.VectoCore.Utils { static Newton() { - Constructors.Add(typeof (Newton), val => new Newton(val)); + Constructors.Add(typeof(Newton), val => new Newton(val)); } [JsonConstructor] private Newton(double val) : base(new SI(val).Newton) {} + + public static NewtonMeter operator *(Newton newton, Meter meter) + { + return ((newton as SI) * meter).Cast<NewtonMeter>(); + } } public class Radian : SIBase<Radian> { static Radian() { - Constructors.Add(typeof (Radian), val => new Radian(val)); + Constructors.Add(typeof(Radian), val => new Radian(val)); } [JsonConstructor] @@ -38,7 +43,7 @@ namespace TUGraz.VectoCore.Utils { static MeterPerSquareSecond() { - Constructors.Add(typeof (MeterPerSquareSecond), val => new MeterPerSquareSecond(val)); + Constructors.Add(typeof(MeterPerSquareSecond), val => new MeterPerSquareSecond(val)); } protected MeterPerSquareSecond(double val) : base(new SI(val).Meter.Per.Square.Second) {} @@ -48,7 +53,7 @@ namespace TUGraz.VectoCore.Utils { static Second() { - Constructors.Add(typeof (Second), val => new Second(val)); + Constructors.Add(typeof(Second), val => new Second(val)); } [JsonConstructor] @@ -59,17 +64,29 @@ namespace TUGraz.VectoCore.Utils { static Meter() { - Constructors.Add(typeof (Meter), val => new Meter(val)); + Constructors.Add(typeof(Meter), val => new Meter(val)); } protected Meter(double val) : base(new SI(val).Meter) {} } + public class Ton : SIBase<Ton> + { + static Ton() + { + Constructors.Add(typeof(Ton), val => new Ton(val)); + } + + [JsonConstructor] + protected Ton(double val) : base(new SI(val).Kilo.Kilo.Gramm) {} + } + + public class Kilogram : SIBase<Kilogram> { static Kilogram() { - Constructors.Add(typeof (Kilogram), val => new Kilogram(val)); + Constructors.Add(typeof(Kilogram), val => new Kilogram(val)); } [JsonConstructor] @@ -80,7 +97,7 @@ namespace TUGraz.VectoCore.Utils { static SquareMeter() { - Constructors.Add(typeof (SquareMeter), val => new SquareMeter(val)); + Constructors.Add(typeof(SquareMeter), val => new SquareMeter(val)); } [JsonConstructor] @@ -91,7 +108,7 @@ namespace TUGraz.VectoCore.Utils { static KilogramSquareMeter() { - Constructors.Add(typeof (KilogramSquareMeter), val => new KilogramSquareMeter(val)); + Constructors.Add(typeof(KilogramSquareMeter), val => new KilogramSquareMeter(val)); } [JsonConstructor] @@ -102,7 +119,7 @@ namespace TUGraz.VectoCore.Utils { static Watt() { - Constructors.Add(typeof (Watt), val => new Watt(val)); + Constructors.Add(typeof(Watt), val => new Watt(val)); } [JsonConstructor] @@ -123,7 +140,7 @@ namespace TUGraz.VectoCore.Utils { static PerSecond() { - Constructors.Add(typeof (PerSecond), val => new PerSecond(val)); + Constructors.Add(typeof(PerSecond), val => new PerSecond(val)); } [JsonConstructor] @@ -134,11 +151,17 @@ namespace TUGraz.VectoCore.Utils { static MeterPerSecond() { - Constructors.Add(typeof (MeterPerSecond), val => new MeterPerSecond(val)); + Constructors.Add(typeof(MeterPerSecond), val => new MeterPerSecond(val)); } [JsonConstructor] private MeterPerSecond(double val) : base(new SI(val).Meter.Per.Second) {} + + + public static PerSecond operator /(MeterPerSecond meterPerSecond, Meter meter) + { + return ((meterPerSecond as SI) / meter).Cast<PerSecond>(); + } } @@ -146,7 +169,7 @@ namespace TUGraz.VectoCore.Utils { static RoundsPerMinute() { - Constructors.Add(typeof (RoundsPerMinute), val => new RoundsPerMinute(val)); + Constructors.Add(typeof(RoundsPerMinute), val => new RoundsPerMinute(val)); } [JsonConstructor] @@ -158,7 +181,7 @@ namespace TUGraz.VectoCore.Utils { static NewtonMeter() { - Constructors.Add(typeof (NewtonMeter), val => new NewtonMeter(val)); + Constructors.Add(typeof(NewtonMeter), val => new NewtonMeter(val)); } [JsonConstructor] @@ -178,6 +201,11 @@ namespace TUGraz.VectoCore.Utils { return ((newtonMeter as SI) / watt).Cast<Second>(); } + + public static Newton operator /(NewtonMeter newtonMeter, Meter meter) + { + return ((newtonMeter as SI) / meter).Cast<Newton>(); + } } public abstract class SIBase<T> : SI where T : SIBase<T> @@ -187,8 +215,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 c52471e4eb3b1f416d369995a5ac8c37fec1246b..de31a10e38d54565c203bc733b5da7ab2603f692 100644 --- a/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore.csproj @@ -141,7 +141,7 @@ <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\DeclarationModeFactory.cs" /> <Compile Include="Models\SimulationComponent\Factories\EngineeringModeSimulationComponentFactory.cs" /> <Compile Include="Models\SimulationComponent\IClutch.cs" /> <Compile Include="Models\SimulationComponent\IEngineOnlyDrivingCycle.cs" /> diff --git a/VectoCoreTest/Models/DeclarationData/DeclarationDataTest.cs b/VectoCoreTest/Models/DeclarationData/DeclarationDataTest.cs deleted file mode 100644 index 6ca8b17508eb54d5cb60465b42ebd94f860bccab..0000000000000000000000000000000000000000 --- a/VectoCoreTest/Models/DeclarationData/DeclarationDataTest.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using TUGraz.VectoCore.Models.Declaration; - -namespace TUGraz.VectoCore.Tests.Models.DeclarationData -{ - [TestClass] - public class DeclarationDataTest - { - public const double Tolerance = 0.0001; - - [TestMethod] - public void WheelDataTest() - { - var wheels = VectoCore.Models.DeclarationData.Instance().Wheels; - - var tmp = wheels.Lookup("285/70 R 19.5"); - - Assert.AreEqual(7.9, tmp.Inertia.Double(), Tolerance); - Assert.AreEqual(0.8943, tmp.DynamicTyreRadius.Double(), Tolerance); - Assert.AreEqual(0, tmp.SizeClass); - } - - [TestMethod] - public void RimsDataTest() - { - var rims = VectoCore.Models.DeclarationData.Instance().Rims; - - var tmp = rims.Lookup("15° DC Rims"); - - Assert.AreEqual(3.03, tmp.F_a, Tolerance); - Assert.AreEqual(3.05, tmp.F_b, Tolerance); - } - } -} \ No newline at end of file diff --git a/VectoCoreTest/Models/DeclarationDataTest.cs b/VectoCoreTest/Models/DeclarationDataTest.cs new file mode 100644 index 0000000000000000000000000000000000000000..dacd84f8c23e5872c246bd66e83c8ff237e12b00 --- /dev/null +++ b/VectoCoreTest/Models/DeclarationDataTest.cs @@ -0,0 +1,148 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TUGraz.VectoCore.Models; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Factories; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Tests.Models +{ + [TestClass] + public class DeclarationDataTest + { + public const double Tolerance = 0.0001; + + [TestMethod] + public void WheelDataTest() + { + var wheels = DeclarationData.Instance().Wheels; + + var tmp = wheels.Lookup("285/70 R 19.5"); + + Assert.AreEqual(7.9, tmp.Inertia.Double(), Tolerance); + Assert.AreEqual(0.8943, tmp.DynamicTyreRadius.Double(), Tolerance); + Assert.AreEqual(0, tmp.SizeClass); + } + + [TestMethod] + public void RimsDataTest() + { + var rims = DeclarationData.Instance().Rims; + + var tmp = rims.Lookup("15° DC Rims"); + + Assert.AreEqual(3.03, tmp.F_a, Tolerance); + Assert.AreEqual(3.05, tmp.F_b, Tolerance); + } + + [TestMethod] + public void SegmentTest() + { + //var factory = DeclarationModeFactory.Instance(); + //var job = factory.ReadJobFile("12t Delivery Truck.vecto"); + //var vehicleData = factory.ReadVehicleData(job.VehicleFile); + + var vehicleData = new { + VehicleCategory = VehicleCategory.RigidTruck, + AxleConfiguration = AxleConfiguration.AxleConfig4x2, + GrossVehicleMassRating = 11900.SI<Kilogram>(), + CurbWeight = 5850.SI<Kilogram>() + }; + + var segment = DeclarationData.GetSegment(vehicleData.VehicleCategory, vehicleData.AxleConfiguration, + vehicleData.GrossVehicleMassRating); + + + Assert.AreEqual(2, segment.HDVClass); + Assert.AreEqual("Truck.vacc", segment.VACC); + Assert.AreEqual(3, segment.Missions.Length); + + var longHaulMission = segment.Missions[0]; + Assert.AreEqual("LongHaul", longHaulMission.Name); + Assert.AreEqual("RigidSolo.vcdv", longHaulMission.VCDV); + Assert.AreEqual(new[] { 40, 60 }, longHaulMission.AxleWeightDistribution); + Assert.AreEqual(1900, longHaulMission.MassExtra); + Assert.AreEqual(588.2 * vehicleData.GrossVehicleMassRating - 2511.8, longHaulMission.RefLoad); + Assert.AreEqual("Long_Haul.vdri", longHaulMission.CycleFile); + + Assert.AreEqual( + new[] { + 0.SI<Kilogram>(), longHaulMission.RefLoad, + vehicleData.GrossVehicleMassRating - longHaulMission.MassExtra - vehicleData.CurbWeight + }, + longHaulMission.Loadings); + + var regionalDeliveryMission = segment.Missions[1]; + Assert.AreEqual("RegionalDelivery", regionalDeliveryMission.Name); + Assert.AreEqual("RigidSolo.vcdv", regionalDeliveryMission.VCDV); + Assert.AreEqual(new[] { 45, 55 }, regionalDeliveryMission.AxleWeightDistribution); + Assert.AreEqual(1900, regionalDeliveryMission.MassExtra); + Assert.AreEqual(394.1 * vehicleData.GrossVehicleMassRating - 1705.9, regionalDeliveryMission.RefLoad); + Assert.AreEqual("Regional_Delivery.vdri", regionalDeliveryMission.CycleFile); + + Assert.AreEqual( + new[] { + 0.SI<Kilogram>(), regionalDeliveryMission.RefLoad, + vehicleData.GrossVehicleMassRating - regionalDeliveryMission.MassExtra - vehicleData.CurbWeight + }, + regionalDeliveryMission.Loadings); + + var urbanDeliveryMission = segment.Missions[1]; + Assert.AreEqual("UrbanDelivery", urbanDeliveryMission.Name); + Assert.AreEqual("RigidSolo.vcdv", urbanDeliveryMission.VCDV); + Assert.AreEqual(new[] { 45, 55 }, urbanDeliveryMission.AxleWeightDistribution); + Assert.AreEqual(1900, urbanDeliveryMission.MassExtra); + Assert.AreEqual(394.1 * vehicleData.GrossVehicleMassRating - 1705.9, urbanDeliveryMission.RefLoad); + Assert.AreEqual("Urban_Delivery.vdri", urbanDeliveryMission.CycleFile); + + Assert.AreEqual( + new[] { + 0.SI<Kilogram>(), urbanDeliveryMission.RefLoad, + vehicleData.GrossVehicleMassRating - urbanDeliveryMission.MassExtra - vehicleData.CurbWeight + }, + urbanDeliveryMission.Loadings); + + + //var runs = new List<IVectoSimulator>(); + + //foreach (var mission in segment.Missions) { + // foreach (var loading in mission.Loadings) { + // var container = new VehicleContainer(); + + // // connect cycle --> driver --> vehicle --> wheels --> axleGear --> gearBox + // // --> retarder --> clutch --> aux --> ... --> aux_XXX --> directAux --> engine + // var engineData = factory.ReadEngineData(job.EngineFile); + // var engine = new CombustionEngine(container, engineData); + + // // todo AUX + // // todo clutch + // // todo retarder + + // var gearboxData = factory.ReadGearboxData(job.GearboxFile); + // var gearbox = new Gearbox(container, gearboxData); + // gearbox.InShaft().Connect(engine.OutShaft()); + + // // todo axleGear + + // var wheels = new Wheels(container, 0.SI<Meter>()); + + // var missionVehicleData = new VehicleData(vehicleData, loading); + // var vehicle = new Vehicle(container, missionVehicleData); + // vehicle.InPort().Connect(wheels.OutPort()); + + // var driverData = new DriverData(); + // var driver = new Driver(driverData); + // driver.InShaft().Connect(vehicle.OutShaft()); + + // var cycleData = DrivingCycleData.ReadFromFileEngineOnly(mission.CycleFile); + // var cycle = new DistanceBasedDrivingCycle(container, cycleData); + // cycle.InShaft().Connect(driver.OutShaft()); + + // var simulator = new VectoSimulator(container, cycle); + // runs.Add(simulator); + // } + //} + } + } +} \ No newline at end of file diff --git a/VectoCoreTest/VectoCoreTest.csproj b/VectoCoreTest/VectoCoreTest.csproj index f2cea47f3dfec99791be1d586451119de3513fc7..0ab02b720d163406724e75da0910178ca35dd195 100644 --- a/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCoreTest/VectoCoreTest.csproj @@ -70,7 +70,7 @@ <ItemGroup> <Compile Include="Exceptions\ExceptionTests.cs" /> <Compile Include="Integration\EngineOnlyCycle\EngineOnlyCycleTest.cs" /> - <Compile Include="Models\DeclarationData\DeclarationDataTest.cs" /> + <Compile Include="Models\DeclarationDataTest.cs" /> <Compile Include="Models\SimulationComponentData\FuelConsumptionMapTest.cs" /> <Compile Include="Models\SimulationComponentData\FullLoadCurveTest.cs" /> <Compile Include="Models\SimulationComponentData\GearboxDataTest.cs" /> @@ -263,6 +263,9 @@ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> </ItemGroup> + <ItemGroup> + <Folder Include="Models\DeclarationData\" /> + </ItemGroup> <Choose> <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> <ItemGroup>