From 82f7ef8396fc517ed31780f530ae3e4dc5d3db4f Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Wed, 8 Jul 2015 11:13:44 +0200 Subject: [PATCH] implemented steering pump auxiliaries in declaration mode, renamed declaration classes (removed declaration from name, because it is already in namespace) --- .../Models/Declaration/DeclarationData.cs | 180 +++--------------- VectoCore/Models/Declaration/Fan.cs | 41 ++++ VectoCore/Models/Declaration/HVAC.cs | 36 ++++ VectoCore/Models/Declaration/LookupData.cs | 2 +- .../Declaration/{DeclarationPT1.cs => PT1.cs} | 2 +- .../Models/Declaration/PneumaticSystem.cs | 36 ++++ .../Declaration/{Declaration.cs => Rims.cs} | 4 +- .../{DeclarationSegments.cs => Segments.cs} | 2 +- VectoCore/Models/Declaration/SteeringPump.cs | 72 +++++++ .../{DeclarationWheels.cs => Wheels.cs} | 2 +- VectoCore/Utils/DoubleExtensionMethods.cs | 10 +- VectoCore/VectoCore.csproj | 12 +- VectoCoreTest/Models/DeclarationDataTest.cs | 4 +- 13 files changed, 234 insertions(+), 169 deletions(-) create mode 100644 VectoCore/Models/Declaration/Fan.cs create mode 100644 VectoCore/Models/Declaration/HVAC.cs rename VectoCore/Models/Declaration/{DeclarationPT1.cs => PT1.cs} (95%) create mode 100644 VectoCore/Models/Declaration/PneumaticSystem.cs rename VectoCore/Models/Declaration/{Declaration.cs => Rims.cs} (86%) rename VectoCore/Models/Declaration/{DeclarationSegments.cs => Segments.cs} (97%) create mode 100644 VectoCore/Models/Declaration/SteeringPump.cs rename VectoCore/Models/Declaration/{DeclarationWheels.cs => Wheels.cs} (90%) diff --git a/VectoCore/Models/Declaration/DeclarationData.cs b/VectoCore/Models/Declaration/DeclarationData.cs index 733b33d9e9..1e2a7369dd 100644 --- a/VectoCore/Models/Declaration/DeclarationData.cs +++ b/VectoCore/Models/Declaration/DeclarationData.cs @@ -1,42 +1,36 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using TUGraz.VectoCore.Utils; - -namespace TUGraz.VectoCore.Models.Declaration +namespace TUGraz.VectoCore.Models.Declaration { public class DeclarationData { private static DeclarationData _instance; - private DeclarationSegments _segments; - private DeclarationRims _rims; - private DeclarationWheels _wheels; - private DeclarationPT1 _pt1; + private Segments _segments; + private Rims _rims; + private Wheels _wheels; + private PT1 _pt1; private ElectricSystem _electricSystem; - private DeclarationFan _fan; - private DeclarationHVAC _hvac; - private DeclarationPneumaticSystem _pneumaticSystem; - private DeclarationSteeringPump _steeringPump; + private Fan _fan; + private HVAC _hvac; + private PneumaticSystem _pneumaticSystem; + private SteeringPump _steeringPump; - public static DeclarationWheels Wheels + public static Wheels Wheels { - get { return Instance()._wheels ?? (Instance()._wheels = new DeclarationWheels()); } + get { return Instance()._wheels ?? (Instance()._wheels = new Wheels()); } } - public static DeclarationRims Rims + public static Rims Rims { - get { return Instance()._rims ?? (Instance()._rims = new DeclarationRims()); } + get { return Instance()._rims ?? (Instance()._rims = new Rims()); } } - public static DeclarationSegments Segments + public static Segments Segments { - get { return Instance()._segments ?? (Instance()._segments = new DeclarationSegments()); } + get { return Instance()._segments ?? (Instance()._segments = new Segments()); } } - public static DeclarationPT1 PT1 + public static PT1 PT1 { - get { return Instance()._pt1 ?? (Instance()._pt1 = new DeclarationPT1()); } + get { return Instance()._pt1 ?? (Instance()._pt1 = new PT1()); } } public static ElectricSystem ElectricSystem @@ -44,24 +38,24 @@ namespace TUGraz.VectoCore.Models.Declaration get { return Instance()._electricSystem ?? (Instance()._electricSystem = new ElectricSystem()); } } - public static DeclarationFan Fan + public static Fan Fan { - get { return Instance()._fan ?? (Instance()._fan = new DeclarationFan()); } + get { return Instance()._fan ?? (Instance()._fan = new Fan()); } } - public static DeclarationHVAC HVAC + public static HVAC HVAC { - get { return Instance()._hvac ?? (Instance()._hvac = new DeclarationHVAC()); } + get { return Instance()._hvac ?? (Instance()._hvac = new HVAC()); } } - public static DeclarationPneumaticSystem PneumaticSystem + public static PneumaticSystem PneumaticSystem { - get { return Instance()._pneumaticSystem ?? (Instance()._pneumaticSystem = new DeclarationPneumaticSystem()); } + get { return Instance()._pneumaticSystem ?? (Instance()._pneumaticSystem = new PneumaticSystem()); } } - public static DeclarationSteeringPump SteeringPump + public static SteeringPump SteeringPump { - get { return Instance()._steeringPump ?? (Instance()._steeringPump = new DeclarationSteeringPump()); } + get { return Instance()._steeringPump ?? (Instance()._steeringPump = new SteeringPump()); } } private static DeclarationData Instance() @@ -69,128 +63,4 @@ namespace TUGraz.VectoCore.Models.Declaration return _instance ?? (_instance = new DeclarationData()); } } - - public class DeclarationSteeringPump : LookupData<MissionType, string, string, Watt> - { - private readonly Dictionary<Tuple<MissionType, string, string>, Watt> _data = - new Dictionary<Tuple<MissionType, string, string>, Watt>(); - - - - - public override Watt Lookup(MissionType mission, string hdvClass, string technology) - { - return _data[Tuple.Create(mission, hdvClass, technology)]; - } - - protected override string ResourceId - { - get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.SP-Table.csv"; } - } - - protected override void ParseData(DataTable table) - { - _data.Clear(); - NormalizeTable(table); - - foreach (DataRow row in table.Rows) { - var hdvClass = row.Field<string>("hdvclass/powerdemandpershare"); - foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { - _data[Tuple.Create(mission, hdvClass)] = row.ParseDouble(mission.ToString().ToLower()).SI<Watt>(); - } - } - } - } - - public class DeclarationPneumaticSystem : LookupData<MissionType, string, Watt> - { - private readonly Dictionary<Tuple<MissionType, string>, Watt> _data = - new Dictionary<Tuple<MissionType, string>, Watt>(); - - public override Watt Lookup(MissionType mission, string hdvClass) - { - return _data[Tuple.Create(mission, hdvClass)]; - } - - protected override string ResourceId - { - get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.PS-Table.csv"; } - } - - protected override void ParseData(DataTable table) - { - _data.Clear(); - NormalizeTable(table); - - foreach (DataRow row in table.Rows) { - var hdvClass = row.Field<string>("hdvclass/power"); - foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { - _data[Tuple.Create(mission, hdvClass)] = row.ParseDouble(mission.ToString().ToLower()).SI<Watt>(); - } - } - } - } - - public class DeclarationHVAC : LookupData<MissionType, string, Watt> - { - private readonly Dictionary<Tuple<MissionType, string>, Watt> _data = - new Dictionary<Tuple<MissionType, string>, Watt>(); - - public override Watt Lookup(MissionType mission, string hdvClass) - { - return _data[Tuple.Create(mission, hdvClass)]; - } - - protected override string ResourceId - { - get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.HVAC-Table.csv"; } - } - - protected override void ParseData(DataTable table) - { - _data.Clear(); - NormalizeTable(table); - - foreach (DataRow row in table.Rows) { - var hdvClass = row.Field<string>("hdvclass/power"); - foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { - _data[Tuple.Create(mission, hdvClass)] = row.ParseDouble(mission.ToString().ToLower()).SI<Watt>(); - } - } - } - } - - public class DeclarationFan : LookupData<MissionType, string, Watt> - { - private readonly Dictionary<Tuple<MissionType, string>, Watt> _data = - new Dictionary<Tuple<MissionType, string>, Watt>(); - - private const string DefaultTechnology = "Crankshaft mounted - Electronically controlled visco clutch (Default)"; - - protected override string ResourceId - { - get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.Fan-Tech.csv"; } - } - - protected override void ParseData(DataTable table) - { - NormalizeTable(table); - - _data.Clear(); - foreach (DataRow row in table.Rows) { - foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { - _data[Tuple.Create(mission, row.Field<string>("Technology"))] = - row.ParseDouble(mission.ToString().ToLower()).SI<Watt>(); - } - } - } - - public override Watt Lookup(MissionType mission, string technology) - { - if (string.IsNullOrWhiteSpace(technology.Trim())) { - technology = DefaultTechnology; - } - return _data[Tuple.Create(mission, technology)]; - } - } } \ No newline at end of file diff --git a/VectoCore/Models/Declaration/Fan.cs b/VectoCore/Models/Declaration/Fan.cs new file mode 100644 index 0000000000..9bc356c81f --- /dev/null +++ b/VectoCore/Models/Declaration/Fan.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Data; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Models.Declaration +{ + public class Fan : LookupData<MissionType, string, Watt> + { + private readonly Dictionary<Tuple<MissionType, string>, Watt> _data = + new Dictionary<Tuple<MissionType, string>, Watt>(); + + private const string DefaultTechnology = "Crankshaft mounted - Electronically controlled visco clutch (Default)"; + + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.Fan-Tech.csv"; } + } + + protected override void ParseData(DataTable table) + { + NormalizeTable(table); + + _data.Clear(); + foreach (DataRow row in table.Rows) { + foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { + _data[Tuple.Create(mission, row.Field<string>("Technology"))] = + row.ParseDouble(mission.ToString().ToLower()).SI<Watt>(); + } + } + } + + public override Watt Lookup(MissionType mission, string technology) + { + if (string.IsNullOrWhiteSpace(technology.Trim())) { + technology = DefaultTechnology; + } + return _data[Tuple.Create(mission, technology)]; + } + } +} \ No newline at end of file diff --git a/VectoCore/Models/Declaration/HVAC.cs b/VectoCore/Models/Declaration/HVAC.cs new file mode 100644 index 0000000000..1abe9195db --- /dev/null +++ b/VectoCore/Models/Declaration/HVAC.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Data; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Models.Declaration +{ + public class HVAC : LookupData<MissionType, string, Watt> + { + private readonly Dictionary<Tuple<MissionType, string>, Watt> _data = + new Dictionary<Tuple<MissionType, string>, Watt>(); + + public override Watt Lookup(MissionType mission, string hdvClass) + { + return _data[Tuple.Create(mission, hdvClass)]; + } + + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.HVAC-Table.csv"; } + } + + protected override void ParseData(DataTable table) + { + _data.Clear(); + NormalizeTable(table); + + foreach (DataRow row in table.Rows) { + var hdvClass = row.Field<string>("hdvclass/power"); + foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { + _data[Tuple.Create(mission, hdvClass)] = row.ParseDouble(mission.ToString().ToLower()).SI<Watt>(); + } + } + } + } +} \ No newline at end of file diff --git a/VectoCore/Models/Declaration/LookupData.cs b/VectoCore/Models/Declaration/LookupData.cs index 3f5baa63d1..ed0e3fddf3 100644 --- a/VectoCore/Models/Declaration/LookupData.cs +++ b/VectoCore/Models/Declaration/LookupData.cs @@ -43,7 +43,7 @@ namespace TUGraz.VectoCore.Models.Declaration public abstract class LookupData<TKey, TValue> : LookupData { - protected Dictionary<TKey, TValue> Data; + protected Dictionary<TKey, TValue> Data = new Dictionary<TKey, TValue>(); public virtual TValue Lookup(TKey key) { diff --git a/VectoCore/Models/Declaration/DeclarationPT1.cs b/VectoCore/Models/Declaration/PT1.cs similarity index 95% rename from VectoCore/Models/Declaration/DeclarationPT1.cs rename to VectoCore/Models/Declaration/PT1.cs index 92e18849bc..202f1ebf14 100644 --- a/VectoCore/Models/Declaration/DeclarationPT1.cs +++ b/VectoCore/Models/Declaration/PT1.cs @@ -6,7 +6,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public class DeclarationPT1 : LookupData<PerSecond, Second> + public class PT1 : LookupData<PerSecond, Second> { private List<KeyValuePair<PerSecond, Second>> _entries; diff --git a/VectoCore/Models/Declaration/PneumaticSystem.cs b/VectoCore/Models/Declaration/PneumaticSystem.cs new file mode 100644 index 0000000000..0743f18ef1 --- /dev/null +++ b/VectoCore/Models/Declaration/PneumaticSystem.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Data; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Models.Declaration +{ + public class PneumaticSystem : LookupData<MissionType, string, Watt> + { + private readonly Dictionary<Tuple<MissionType, string>, Watt> _data = + new Dictionary<Tuple<MissionType, string>, Watt>(); + + public override Watt Lookup(MissionType mission, string hdvClass) + { + return _data[Tuple.Create(mission, hdvClass)]; + } + + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.PS-Table.csv"; } + } + + protected override void ParseData(DataTable table) + { + _data.Clear(); + NormalizeTable(table); + + foreach (DataRow row in table.Rows) { + var hdvClass = row.Field<string>("hdvclass/power"); + foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { + _data[Tuple.Create(mission, hdvClass)] = row.ParseDouble(mission.ToString().ToLower()).SI<Watt>(); + } + } + } + } +} \ No newline at end of file diff --git a/VectoCore/Models/Declaration/Declaration.cs b/VectoCore/Models/Declaration/Rims.cs similarity index 86% rename from VectoCore/Models/Declaration/Declaration.cs rename to VectoCore/Models/Declaration/Rims.cs index b0e6fc01d3..c544d5366b 100644 --- a/VectoCore/Models/Declaration/Declaration.cs +++ b/VectoCore/Models/Declaration/Rims.cs @@ -4,9 +4,9 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public class DeclarationRims : LookupData<string, DeclarationRims.RimsEntry> + public class Rims : LookupData<string, Rims.RimsEntry> { - internal DeclarationRims() + internal Rims() { var csvFile = ReadCsvFile(ResourceId); ParseData(csvFile); diff --git a/VectoCore/Models/Declaration/DeclarationSegments.cs b/VectoCore/Models/Declaration/Segments.cs similarity index 97% rename from VectoCore/Models/Declaration/DeclarationSegments.cs rename to VectoCore/Models/Declaration/Segments.cs index 9414323941..766bf0af89 100644 --- a/VectoCore/Models/Declaration/DeclarationSegments.cs +++ b/VectoCore/Models/Declaration/Segments.cs @@ -6,7 +6,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public class DeclarationSegments : LookupData<VehicleCategory, AxleConfiguration, Kilogram, Kilogram, Segment> + public class Segments : LookupData<VehicleCategory, AxleConfiguration, Kilogram, Kilogram, Segment> { private const string ResourceNamespace = "TUGraz.VectoCore.Resources.Declaration."; diff --git a/VectoCore/Models/Declaration/SteeringPump.cs b/VectoCore/Models/Declaration/SteeringPump.cs new file mode 100644 index 0000000000..50be63f3c8 --- /dev/null +++ b/VectoCore/Models/Declaration/SteeringPump.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Models.Declaration +{ + public class SteeringPump : LookupData<MissionType, string, string, Watt> + { + private readonly SteeringPumpTechnologies _technologies = new SteeringPumpTechnologies(); + + private readonly Dictionary<Tuple<MissionType, string>, Watt[]> _data = + new Dictionary<Tuple<MissionType, string>, Watt[]>(); + + public override Watt Lookup(MissionType mission, string hdvClass, string technology) + { + var shares = _data[Tuple.Create(mission, hdvClass)]; + var sum = 0.SI<Watt>(); + var factors = _technologies.Lookup(technology); + for (var i = 0; i < 4; i++) { + sum += shares[i] * factors[i]; + } + return sum; + } + + + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.SP-Table.csv"; } + } + + protected override void ParseData(DataTable table) + { + _data.Clear(); + NormalizeTable(table); + + foreach (DataRow row in table.Rows) { + var hdvClass = row.Field<string>("hdvclass/powerdemandpershare"); + foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { + var values = row.Field<string>(mission.ToString().ToLower()).Split('/').ToDouble(); + values = values.Concat(Enumerable.Repeat(0.0, 3)); + + _data[Tuple.Create(mission, hdvClass)] = values.Take(4).SI<Watt>().ToArray(); + } + } + } + + public class SteeringPumpTechnologies : LookupData<string, double[]> + { + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.SP-Tech.csv"; } + } + + protected override void ParseData(DataTable table) + { + Data.Clear(); + foreach (DataRow row in table.Rows) { + var tech = row.Field<string>("Scaling Factors"); + var factors = new[] { row.ParseDouble("U"), row.ParseDouble("F"), row.ParseDouble("B"), row.ParseDouble("S") }; + Data[tech] = factors; + } + } + + public override double[] Lookup(string tech) + { + return Data[tech]; + } + } + } +} \ No newline at end of file diff --git a/VectoCore/Models/Declaration/DeclarationWheels.cs b/VectoCore/Models/Declaration/Wheels.cs similarity index 90% rename from VectoCore/Models/Declaration/DeclarationWheels.cs rename to VectoCore/Models/Declaration/Wheels.cs index f36bb36c64..2122d792e3 100644 --- a/VectoCore/Models/Declaration/DeclarationWheels.cs +++ b/VectoCore/Models/Declaration/Wheels.cs @@ -5,7 +5,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public class DeclarationWheels : LookupData<string, DeclarationWheels.WheelsEntry> + public class Wheels : LookupData<string, Wheels.WheelsEntry> { protected override string ResourceId { diff --git a/VectoCore/Utils/DoubleExtensionMethods.cs b/VectoCore/Utils/DoubleExtensionMethods.cs index c616f65a30..439afc2820 100644 --- a/VectoCore/Utils/DoubleExtensionMethods.cs +++ b/VectoCore/Utils/DoubleExtensionMethods.cs @@ -1,4 +1,7 @@ using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; namespace TUGraz.VectoCore.Utils { @@ -100,7 +103,7 @@ namespace TUGraz.VectoCore.Utils /// <returns></returns> public static SI SI(this double self) { - return (SI)self; + return (SI) self; } /// <summary> @@ -113,5 +116,10 @@ namespace TUGraz.VectoCore.Utils { return SIBase<T>.Create(self); } + + public static IEnumerable<T> SI<T>(this IEnumerable<double> self) where T : SIBase<T> + { + return self.Select(x => x.SI<T>()); + } } } \ No newline at end of file diff --git a/VectoCore/VectoCore.csproj b/VectoCore/VectoCore.csproj index 02d81f8265..5aad91d7c5 100644 --- a/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore.csproj @@ -122,18 +122,22 @@ <Compile Include="Models\Connector\Ports\Impl\Response.cs" /> <Compile Include="Models\Connector\Ports\IFvPort.cs" /> <Compile Include="Models\Connector\Ports\ITnPort.cs" /> + <Compile Include="Models\Declaration\Fan.cs" /> + <Compile Include="Models\Declaration\HVAC.cs" /> + <Compile Include="Models\Declaration\PneumaticSystem.cs" /> + <Compile Include="Models\Declaration\SteeringPump.cs" /> <Compile Include="Models\SimulationComponent\Data\AccelerationCurve.cs" /> <Compile Include="Models\Declaration\DeclarationData.cs" /> - <Compile Include="Models\Declaration\DeclarationPT1.cs" /> + <Compile Include="Models\Declaration\PT1.cs" /> <Compile Include="Models\Declaration\ElectricSystem.cs" /> <Compile Include="Models\Declaration\LookupData.cs" /> - <Compile Include="Models\Declaration\Declaration.cs" /> - <Compile Include="Models\Declaration\DeclarationWheels.cs" /> + <Compile Include="Models\Declaration\Rims.cs" /> + <Compile Include="Models\Declaration\Wheels.cs" /> <Compile Include="Models\Declaration\Mission.cs" /> <Compile Include="Models\Declaration\MissionType.cs" /> <Compile Include="Utils\RessourceHelper.cs" /> <Compile Include="Models\Declaration\Segment.cs" /> - <Compile Include="Models\Declaration\DeclarationSegments.cs" /> + <Compile Include="Models\Declaration\Segments.cs" /> <Compile Include="Models\SimulationComponent\Data\AuxiliaryCycleDataAdapter.cs" /> <Compile Include="Models\Declaration\Axle.cs" /> <Compile Include="Models\Declaration\AxleConfiguration.cs" /> diff --git a/VectoCoreTest/Models/DeclarationDataTest.cs b/VectoCoreTest/Models/DeclarationDataTest.cs index 05703aba25..c743d91216 100644 --- a/VectoCoreTest/Models/DeclarationDataTest.cs +++ b/VectoCoreTest/Models/DeclarationDataTest.cs @@ -336,8 +336,6 @@ namespace TUGraz.VectoCore.Tests.Models } } } - - Assert.Inconclusive(); } [TestMethod] @@ -443,7 +441,7 @@ namespace TUGraz.VectoCore.Tests.Models // // todo axleGear - // var wheels = new DeclarationWheels(container, 0.SI<Meter>()); + // var wheels = new Wheels(container, 0.SI<Meter>()); // var missionVehicleData = new VehicleData(vehicleData, loading, mission.AxleWeightDistribution); // var vehicle = new Vehicle(container, missionVehicleData); -- GitLab