Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Select Git revision
  • fa38f33114cfd2f568216919fe87f59db381e98b
  • stable default
  • feat-fchv-bus
  • fix-h2-ice-bus
  • powertrains-multiple-axles
  • amdm3/develop
  • issue-1039
  • amdm3/main
  • test/nuget_publish
  • IEPC-experiments
  • amdm2/main
  • amdm2/develop
  • aptngearbox-not-auto
  • playground
  • official/main
  • official/develop
  • issue-templates
  • pdf-reports
  • HEV-timeruns-dev
  • timerun-empower-hybrids
  • timerun-pwheel-hybrids
  • Release/v5.0.3
  • Release/v5.0.1
  • Release/5.0.0-RC
  • Nuget/v0.11.4-DEV
  • Release/v0.11.4-DEV
  • Release/4.3.4-DEV
  • Release/4.3.3
  • Release/4.3.2-RC
  • Release/v4.3.0-DEV
  • Release/4.2.7
  • XMLConverterTool/4.2.6.0
  • Release/4.2.6-RC
  • Release/v4.2.5
  • Release/v4.2.3
  • Release/v4.2.2.3539-RC
  • Release/v4.2.1.3469
  • Release/v0.11.2.3456-DEV
  • Release/v4.2.0.3448-RC
  • Release/v4.1.3.3415
  • Release/v4.1.1.3413
41 results

DeclarationDataAdapter.cs

Blame
  • Forked from VECTO / VECTO Sim
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    DeclarationDataAdapter.cs 9.82 KiB
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using TUGraz.VectoCore.Configuration;
    using TUGraz.VectoCore.Exceptions;
    using TUGraz.VectoCore.FileIO.DeclarationFile;
    using TUGraz.VectoCore.Models.Declaration;
    using TUGraz.VectoCore.Models.Simulation.Data;
    using TUGraz.VectoCore.Models.SimulationComponent.Data;
    using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
    using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox;
    using TUGraz.VectoCore.Utils;
    
    namespace TUGraz.VectoCore.FileIO.Reader.DataObjectAdaper
    {
    	public class DeclarationDataAdapter : AbstractSimulationDataAdapter
    	{
    		public override VehicleData CreateVehicleData(VectoVehicleFile vehicle, Mission segment, Kilogram loading)
    		{
    			var fileV5Decl = vehicle as VehicleFileV5Declaration;
    			if (fileV5Decl != null) {
    				return CreateVehicleData(fileV5Decl, segment, loading);
    			}
    			throw new VectoException("Unsupported VehicleData File Instance");
    		}
    
    		public override VehicleData CreateVehicleData(VectoVehicleFile vehicle)
    		{
    			var fileV5Decl = vehicle as VehicleFileV5Declaration;
    			if (fileV5Decl != null) {
    				return SetCommonVehicleData(fileV5Decl.Body, fileV5Decl.BasePath);
    			}
    			throw new VectoException("Mission Data and loading required in DeclarationMode");
    		}
    
    		public override CombustionEngineData CreateEngineData(VectoEngineFile engine)
    		{
    			var fileV2Decl = engine as EngineFileV3Declaration;
    			if (fileV2Decl != null) {
    				return CreateEngineData(fileV2Decl);
    			}
    			throw new VectoException("Unsupported EngineData File Instance");
    		}
    
    		public override GearboxData CreateGearboxData(VectoGearboxFile gearbox, CombustionEngineData engine)
    		{
    			var fileV5Decl = gearbox as GearboxFileV5Declaration;
    			if (fileV5Decl != null) {
    				return CreateGearboxData(fileV5Decl, engine);
    			}
    			throw new VectoException("Unsupported GearboxData File Instance");
    		}
    
    		public override DriverData CreateDriverData(VectoJobFile job)
    		{
    			var fileV2Decl = job as VectoJobFileV2Declaration;
    			if (fileV2Decl != null) {
    				return CreateDriverData(fileV2Decl);
    			}
    			throw new VectoException("Unsupported Job File Instance");
    		}
    
    		//==========================
    
    
    		public DriverData CreateDriverData(VectoJobFileV2Declaration job)
    		{
    			var data = job.Body;
    
    			var lookAheadData = new DriverData.LACData() {
    				Enabled = DeclarationData.Driver.LookAhead.Enabled,
    				Deceleration = DeclarationData.Driver.LookAhead.Deceleration,
    				MinSpeed = DeclarationData.Driver.LookAhead.MinimumSpeed
    			};
    			var overspeedData = new DriverData.OverSpeedEcoRollData() {
    				Mode = DriverData.ParseDriverMode(data.OverSpeedEcoRoll.Mode),
    				MinSpeed = DeclarationData.Driver.OverSpeedEcoRoll.MinSpeed,
    				OverSpeed = DeclarationData.Driver.OverSpeedEcoRoll.OverSpeed,
    				UnderSpeed = DeclarationData.Driver.OverSpeedEcoRoll.UnderSpeed
    			};
    			if (!DeclarationData.Driver.OverSpeedEcoRoll.AllowedModes.Contains(overspeedData.Mode)) {
    				throw new VectoSimulationException(
    					string.Format("Specified Overspeed/EcoRoll Mode not allowed in declaration mode! {0}", overspeedData.Mode));
    			}
    			var startstopData = new VectoRunData.StartStopData() {
    				Enabled = data.StartStop.Enabled,
    				Delay = DeclarationData.Driver.StartStop.Delay,
    				MinTime = DeclarationData.Driver.StartStop.MinTime,
    				MaxSpeed = DeclarationData.Driver.StartStop.MaxSpeed,
    			};
    			var retVal = new DriverData() {
    				LookAheadCoasting = lookAheadData,
    				OverSpeedEcoRoll = overspeedData,
    				StartStop = startstopData,
    			};
    			return retVal;
    		}
    
    
    		internal VehicleData CreateVehicleData(VehicleFileV5Declaration vehicle, Mission mission, Kilogram loading)
    		{
    			var data = vehicle.Body;
    			var retVal = SetCommonVehicleData(data, vehicle.BasePath);
    
    			retVal.BasePath = vehicle.BasePath;
    
    			retVal.GrossVehicleMassRating = vehicle.Body.GrossVehicleMassRating.SI<Ton>().Cast<Kilogram>();
    
    			retVal.CurbWeigthExtra = mission.MassExtra;
    			retVal.Loading = loading;
    			retVal.DynamicTyreRadius =
    				DeclarationData.DynamicTyreRadius(data.AxleConfig.Axles[DeclarationData.PoweredAxle()].WheelsStr, data.RimStr);
    
    			if (data.AxleConfig.Axles.Count < mission.AxleWeightDistribution.Length) {
    				throw new VectoException(
    					string.Format("Vehicle does not contain sufficient axles. {0} axles defined, {1} axles required",
    						data.AxleConfig.Axles.Count, mission.AxleWeightDistribution.Count()));
    			}
    			retVal.AxleData = new List<Axle>();
    			for (var i = 0; i < mission.AxleWeightDistribution.Length; i++) {
    				var axleInput = data.AxleConfig.Axles[i];
    				var axle = new Axle {
    					AxleWeightShare = mission.AxleWeightDistribution[i],
    					TwinTyres = axleInput.TwinTyres,
    					RollResistanceCoefficient = axleInput.RollResistanceCoefficient,
    					TyreTestLoad = axleInput.TyreTestLoad.SI<Newton>(),
    					Inertia = DeclarationData.Wheels.Lookup(axleInput.WheelsStr.Replace(" ", "")).Inertia,
    				};
    				retVal.AxleData.Add(axle);
    			}
    
    			foreach (var tmp in mission.TrailerAxleWeightDistribution) {
    				retVal.AxleData.Add(new Axle() {
    					AxleWeightShare = tmp,
    					TwinTyres = DeclarationData.Trailer.TwinTyres,
    					RollResistanceCoefficient = DeclarationData.Trailer.RollResistanceCoefficient,
    					TyreTestLoad = DeclarationData.Trailer.TyreTestLoad.SI<Newton>(),
    					Inertia = DeclarationData.Wheels.Lookup(DeclarationData.Trailer.WheelsType).Inertia
    				});
    			}
    
    			return retVal;
    		}
    
    		internal CombustionEngineData CreateEngineData(EngineFileV3Declaration engine)
    		{
    			var retVal = SetCommonCombustionEngineData(engine.Body, engine.BasePath);
    			retVal.Inertia = DeclarationData.Engine.EngineInertia(retVal.Displacement);
    			retVal.FullLoadCurve = EngineFullLoadCurve.ReadFromFile(Path.Combine(engine.BasePath, engine.Body.FullLoadCurve),
    				true);
    			retVal.FullLoadCurve.EngineData = retVal;
    			return retVal;
    		}
    
    		internal GearboxData CreateGearboxData(GearboxFileV5Declaration gearbox, CombustionEngineData engine)
    		{
    			var retVal = SetCommonGearboxData(gearbox.Body);
    
    			if (retVal.Type == GearboxData.GearboxType.AT) {
    				throw new VectoSimulationException("Automatic Transmission currently not supported in DeclarationMode!");
    			}
    			if (retVal.Type == GearboxData.GearboxType.Custom) {
    				throw new VectoSimulationException("Custom Transmission not supported in DeclarationMode!");
    			}
    
    			if (gearbox.Body.Gears.Count < 2) {
    				throw new VectoSimulationException("At least two gears must be defined: 1 Axle-Gear and 1 Gearbox-Gear!");
    			}
    
    			retVal.Inertia = DeclarationData.Gearbox.Inertia.SI<KilogramSquareMeter>();
    			retVal.TractionInterruption = DeclarationData.Gearbox.TractionInterruption(retVal.Type);
    			retVal.SkipGears = DeclarationData.Gearbox.SkipGears(retVal.Type);
    			retVal.EarlyShiftUp = DeclarationData.Gearbox.EarlyShiftGears((retVal.Type));
    
    			retVal.TorqueReserve = DeclarationData.Gearbox.TorqueReserve;
    			retVal.StartTorqueReserve = DeclarationData.Gearbox.TorqueReserveStart;
    			retVal.ShiftTime = DeclarationData.Gearbox.MinTimeBetweenGearshifts.SI<Second>();
    			retVal.StartSpeed = DeclarationData.Gearbox.StartSpeed.SI<MeterPerSecond>();
    			retVal.StartAcceleration = DeclarationData.Gearbox.StartAcceleration.SI<MeterPerSquareSecond>();
    
    			retVal.HasTorqueConverter = false;
    
    			var axleGear = gearbox.Body.Gears.First();
    			var lossMap = TransmissionLossMap.ReadFromFile(Path.Combine(gearbox.BasePath, axleGear.LossMap), axleGear.Ratio);
    			retVal.AxleGearData = new GearData { LossMap = lossMap, Ratio = axleGear.Ratio, TorqueConverterActive = false };
    
    			retVal.Gears = gearbox.Body.Gears.Skip(1).Select((gear, i) => {
    				lossMap = TransmissionLossMap.ReadFromFile(Path.Combine(gearbox.BasePath, axleGear.LossMap), axleGear.Ratio);
    				EngineFullLoadCurve fullLoadCurve;
    				if (string.IsNullOrWhiteSpace(gear.FullLoadCurve) || gear.FullLoadCurve == "<NOFILE>") {
    					fullLoadCurve = engine.FullLoadCurve;
    				} else {
    					var gearFullLoad = GearFullLoadCurve.ReadFromFile(Path.Combine(gearbox.BasePath, gear.FullLoadCurve));
    					fullLoadCurve = IntersectFullLoadCurves(gearFullLoad, engine.FullLoadCurve);
    				}
    
    				var shiftPolygon = DeclarationData.Gearbox.ComputeShiftPolygon(fullLoadCurve, engine.IdleSpeed);
    				return new KeyValuePair<uint, GearData>((uint)i,
    					new GearData { LossMap = lossMap, ShiftPolygon = shiftPolygon, Ratio = gear.Ratio, TorqueConverterActive = false });
    			}).ToDictionary(kv => kv.Key, kv => kv.Value);
    			return retVal;
    		}
    
    		private EngineFullLoadCurve IntersectFullLoadCurves(GearFullLoadCurve fullLoadCurve,
    			EngineFullLoadCurve engineFullLoadCurve)
    		{
    			//create new entries
    
    			throw new NotImplementedException();
    		}
    
    		public IEnumerable<VectoRunData.AuxData> CreateAuxiliaryData(IEnumerable<VectoRunData.AuxData> auxList,
    			MissionType mission, VehicleClass hvdClass)
    		{
    			foreach (var auxData in auxList) {
    				var aux = new VectoRunData.AuxData { DemandType = AuxiliaryDemandType.Constant };
    
    				switch (auxData.Type) {
    					case AuxiliaryType.Fan:
    						aux.PowerDemand = DeclarationData.Fan.Lookup(mission, auxData.Technology);
    						aux.ID = Constants.Auxiliaries.IDs.Fan;
    						break;
    					case AuxiliaryType.SteeringPump:
    						aux.PowerDemand = DeclarationData.SteeringPump.Lookup(mission, hvdClass, auxData.Technology);
    						aux.ID = Constants.Auxiliaries.IDs.SteeringPump;
    						break;
    					case AuxiliaryType.HeatingVentilationAirCondition:
    						aux.PowerDemand = DeclarationData.HeatingVentilationAirConditioning.Lookup(mission, hvdClass);
    						aux.ID = Constants.Auxiliaries.IDs.HeatingVentilationAirCondition;
    						break;
    					case AuxiliaryType.PneumaticSystem:
    						aux.PowerDemand = DeclarationData.PneumaticSystem.Lookup(mission, hvdClass);
    						aux.ID = Constants.Auxiliaries.IDs.PneumaticSystem;
    						break;
    					case AuxiliaryType.ElectricSystem:
    						aux.PowerDemand = DeclarationData.ElectricSystem.Lookup(mission, auxData.TechList);
    						aux.ID = Constants.Auxiliaries.IDs.ElectricSystem;
    						break;
    				}
    				yield return aux;
    			}
    		}
    	}
    }