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
CoachAdvancedAuxPowertrain.cs 8.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • /*
    * This file is part of VECTO.
    *
    * Copyright © 2012-2016 European Union
    *
    * Developed by Graz University of Technology,
    *              Institute of Internal Combustion Engines and Thermodynamics,
    *              Institute of Technical Informatics
    *
    * VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved
    * by the European Commission - subsequent versions of the EUPL (the "Licence");
    * You may not use VECTO except in compliance with the Licence.
    * You may obtain a copy of the Licence at:
    *
    * https://joinup.ec.europa.eu/community/eupl/og_page/eupl
    *
    * Unless required by applicable law or agreed to in writing, VECTO
    * distributed under the Licence is distributed on an "AS IS" basis,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the Licence for the specific language governing permissions and
    * limitations under the Licence.
    *
    * Authors:
    *   Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology
    *   Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology
    *   Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology
    *   Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology
    *   Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology
    *   Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
    */
    
    using System;
    
    using System.Collections.Generic;
    using System.Linq;
    
    using TUGraz.VectoCommon.Models;
    using TUGraz.VectoCommon.Utils;
    
    using TUGraz.VectoCore.InputData.Reader;
    
    using TUGraz.VectoCore.Models.Declaration;
    using TUGraz.VectoCore.Models.Simulation.Data;
    using TUGraz.VectoCore.Models.Simulation.Impl;
    using TUGraz.VectoCore.Models.SimulationComponent.Data;
    using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox;
    using TUGraz.VectoCore.Models.SimulationComponent.Impl;
    using TUGraz.VectoCore.OutputData;
    using TUGraz.VectoCore.OutputData.FileIO;
    using TUGraz.VectoCore.Tests.Utils;
    using Wheels = TUGraz.VectoCore.Models.SimulationComponent.Impl.Wheels;
    
    namespace TUGraz.VectoCore.Tests.Integration
    {
    	public class CoachAdvancedAuxPowertrain
    	{
    		public const string AccelerationFile = @"TestData\Components\Truck.vacc";
    		public const string EngineFile = @"TestData\Components\24t Coach.veng";
    		public const string AxleGearLossMap = @"TestData\Components\Axle.vtlm";
    		public const string GearboxIndirectLoss = @"TestData\Components\Indirect Gear.vtlm";
    		public const string GearboxDirectLoss = @"TestData\Components\Direct Gear.vtlm";
    		public const string GearboxShiftPolygonFile = @"TestData\Components\ShiftPolygons.vgbs";
    		public const string GearboxFullLoadCurveFile = @"TestData\Components\Gearbox.vfld";
    
    		public const string AdvancedAuxFile = @"Testdata\Integration\BusAuxiliaries\AdvAuxTest.aaux";
    
    		public static VectoRun CreateEngineeringRun(DrivingCycleData cycleData, string modFileName,
    			bool overspeed = false)
    		{
    			var container = CreatePowerTrain(cycleData, modFileName.Replace(".vmod", ""), overspeed);
    
    			return new DistanceRun(container);
    		}
    
    		public static VehicleContainer CreatePowerTrain(DrivingCycleData cycleData, string modFileName,
    			bool overspeed = false)
    		{
    
    			var fileWriter = new FileOutputWriter(modFileName);
    
    			var modData = new ModalDataContainer(modFileName, fileWriter, ExecutionMode.Engineering) { WriteAdvancedAux = true };
    			var container = new VehicleContainer(ExecutionMode.Engineering, modData) {
    				RunData = new VectoRunData { JobName = modFileName, Cycle = cycleData }
    			};
    
    
    			var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(EngineFile);
    			var axleGearData = CreateAxleGearData();
    			var gearboxData = CreateGearboxData();
    			var vehicleData = CreateVehicleData(3300.SI<Kilogram>());
    			var driverData = CreateDriverData(AccelerationFile, overspeed);
    
    			var cycle = new DistanceBasedDrivingCycle(container, cycleData);
    			var engine = new CombustionEngine(container, engineData);
    			var clutch = new Clutch(container, engineData, engine.IdleController);
    
    			dynamic tmp = Port.AddComponent(cycle, new Driver(container, driverData, new DefaultDriverStrategy()));
    			tmp = Port.AddComponent(tmp, new Vehicle(container, vehicleData));
    			tmp = Port.AddComponent(tmp, new Wheels(container, vehicleData.DynamicTyreRadius, vehicleData.WheelsInertia));
    			tmp = Port.AddComponent(tmp, new Brakes(container));
    			tmp = Port.AddComponent(tmp, new AxleGear(container, axleGearData));
    			tmp = Port.AddComponent(tmp, new DummyRetarder(container));
    			tmp = Port.AddComponent(tmp,
    				new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)));
    			tmp = Port.AddComponent(tmp, clutch);
    
    			var aux = new BusAuxiliariesAdapter(container, AdvancedAuxFile, "Coach",
    				vehicleData.TotalVehicleWeight(), engineData.ConsumptionMap, engineData.IdleSpeed);
    
    			engine.Connect(aux.Port());
    
    			Port.AddComponent(tmp, engine);
    
    			engine.IdleController.RequestPort = clutch.IdleControlPort;
    
    			return container;
    		}
    
    		private static GearboxData CreateGearboxData()
    		{
    			var ratios = new[] { 6.38, 4.63, 3.44, 2.59, 1.86, 1.35, 1, 0.76 };
    
    			return new GearboxData {
    				Gears = ratios.Select((ratio, i) =>
    					Tuple.Create((uint)i,
    						new GearData {
    
    							FullLoadCurve = FullLoadCurveReader.ReadFromFile(GearboxFullLoadCurveFile),
    
    							LossMap = ratio.IsEqual(1)
    								? TransmissionLossMap.ReadFromFile(GearboxIndirectLoss, ratio, string.Format("Gear {0}", i))
    								: TransmissionLossMap.ReadFromFile(GearboxDirectLoss, ratio, string.Format("Gear {0}", i)),
    
    							Ratio = ratio,
    
    							ShiftPolygon = ShiftPolygonReader.ReadFromFile(GearboxShiftPolygonFile)
    
    						}))
    					.ToDictionary(k => k.Item1 + 1, v => v.Item2),
    				ShiftTime = 2.SI<Second>(),
    				Inertia = 0.SI<KilogramSquareMeter>(),
    				TractionInterruption = 1.SI<Second>(),
    				StartSpeed = 2.SI<MeterPerSecond>(),
    				StartAcceleration = 0.6.SI<MeterPerSquareSecond>(),
    				StartTorqueReserve = 0.2,
    				SkipGears = true,
    
    				TorqueReserve = 0.2,
    				UpshiftAfterDownshiftDelay = 10.SI<Second>(),
    				DownshiftAfterUpshiftDelay = 10.SI<Second>(),
    				UpshiftMinAcceleration = 0.1.SI<MeterPerSquareSecond>()
    
    			};
    		}
    
    		private static AxleGearData CreateAxleGearData()
    		{
    			const double ratio = 3.240355;
    			return new AxleGearData {
    				AxleGear = new GearData {
    					Ratio = ratio,
    					LossMap = TransmissionLossMap.ReadFromFile(AxleGearLossMap, ratio, "AxleGear")
    				}
    			};
    		}
    
    		private static VehicleData CreateVehicleData(Kilogram loading)
    		{
    			var axles = new List<Axle> {
    				new Axle {
    					AxleWeightShare = 0.4375,
    					Inertia = 21.66667.SI<KilogramSquareMeter>(),
    					RollResistanceCoefficient = 0.0055,
    					TwinTyres = false,
    					TyreTestLoad = 62538.75.SI<Newton>()
    				},
    				new Axle {
    					AxleWeightShare = 0.375,
    					Inertia = 10.83333.SI<KilogramSquareMeter>(),
    					RollResistanceCoefficient = 0.0065,
    					TwinTyres = true,
    					TyreTestLoad = 52532.55.SI<Newton>()
    				},
    				new Axle {
    					AxleWeightShare = 0.1875,
    					Inertia = 21.66667.SI<KilogramSquareMeter>(),
    					RollResistanceCoefficient = 0.0055,
    					TwinTyres = false,
    					TyreTestLoad = 62538.75.SI<Newton>()
    				}
    			};
    			return new VehicleData {
    				AxleConfiguration = AxleConfiguration.AxleConfig_6x2,
    				//AerodynamicDragAera = 3.2634.SI<SquareMeter>(),
    				//CrossWindCorrectionMode = CrossWindCorrectionMode.NoCorrection,
    				CrossWindCorrectionCurve =
    					new CrosswindCorrectionCdxALookup(CrossWindCorrectionCurveReader.GetNoCorrectionCurve(3.2634.SI<SquareMeter>()),
    						CrossWindCorrectionMode.NoCorrection),
    				CurbWeight = 15700.SI<Kilogram>(),
    				Loading = loading,
    				DynamicTyreRadius = 0.52.SI<Meter>(),
    				AxleData = axles,
    				SavedInDeclarationMode = false
    			};
    		}
    
    		private static DriverData CreateDriverData(string accelerationFile, bool overspeed = false)
    		{
    			return new DriverData {
    				AccelerationCurve = AccelerationCurveData.ReadFromFile(accelerationFile),
    				LookAheadCoasting = new DriverData.LACData {
    					Enabled = true,
    
    					//Deceleration = -0.5.SI<MeterPerSquareSecond>()
    
    Markus Quaritsch's avatar
    Markus Quaritsch committed
    					LookAheadDistanceFactor = DeclarationData.Driver.LookAhead.LookAheadDistanceFactor,
    					LookAheadDecisionFactor = new LACDecisionFactor()
    
    				},
    				OverSpeedEcoRoll = overspeed
    					? new DriverData.OverSpeedEcoRollData {
    
    						MinSpeed = 50.KMPHtoMeterPerSecond(),
    						OverSpeed = 5.KMPHtoMeterPerSecond()
    					}
    					: new DriverData.OverSpeedEcoRollData {
    
    					},
    				StartStop = new VectoRunData.StartStopData {
    					Enabled = false
    				}
    			};
    		}
    	}
    }