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
  • 326acc30610b24dbe9d6c05648f90e34f643cd47
  • 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

AuxTests.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.
    Auxiliary.cs 4.05 KiB
    /*
    * Copyright 2015 European Union
    *
    * Licensed under the EUPL (the "Licence");
    * You may not use this work except in compliance with the Licence.
    * You may obtain a copy of the Licence at:
    *
    * http://ec.europa.eu/idabc/eupl5
    *
    * Unless required by applicable law or agreed to in writing, software 
    * 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.
    */
    
    using System;
    using System.Collections.Generic;
    using TUGraz.VectoCore.Exceptions;
    using TUGraz.VectoCore.Models.Connector.Ports;
    using TUGraz.VectoCore.Models.Simulation;
    using TUGraz.VectoCore.Models.Simulation.Data;
    using TUGraz.VectoCore.Models.SimulationComponent.Data;
    using TUGraz.VectoCore.OutputData;
    using TUGraz.VectoCore.Utils;
    
    namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
    {
    	public class Auxiliary : VectoSimulationComponent, IAuxiliary, ITnInPort, ITnOutPort
    	{
    		public const string DirectAuxiliaryId = "";
    
    		private readonly Dictionary<string, Func<PerSecond, Watt>> _auxDict = new Dictionary<string, Func<PerSecond, Watt>>();
    		private readonly Dictionary<string, Watt> _powerDemands = new Dictionary<string, Watt>();
    
    		protected ITnOutPort NextComponent;
    
    		public Auxiliary(IVehicleContainer container) : base(container) {}
    
    		#region ITnInProvider
    
    		public ITnInPort InPort()
    		{
    			return this;
    		}
    
    		#endregion
    
    		#region ITnOutProvider
    
    		public ITnOutPort OutPort()
    		{
    			return this;
    		}
    
    		#endregion
    
    		#region ITnInPort
    
    		void ITnInPort.Connect(ITnOutPort other)
    		{
    			NextComponent = other;
    		}
    
    		#endregion
    
    		#region ITnOutPort
    
    		IResponse ITnOutPort.Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity, bool dryRun)
    		{
    			var currentAngularVelocity = angularVelocity ?? DataBus.EngineSpeed;
    			var powerDemand = ComputePowerDemand(currentAngularVelocity);
    
    			var retVal = NextComponent.Request(absTime, dt, torque + powerDemand / currentAngularVelocity, angularVelocity,
    				dryRun);
    			retVal.AuxiliariesPowerDemand = powerDemand;
    			return retVal;
    		}
    
    		private Watt ComputePowerDemand(PerSecond engineSpeed)
    		{
    			_powerDemands.Clear();
    			var powerDemand = 0.SI<Watt>();
    
    			foreach (var kv in _auxDict) {
    				var demand = kv.Value(engineSpeed);
    				powerDemand += demand;
    				_powerDemands[kv.Key] = demand;
    			}
    			return powerDemand;
    		}
    
    		public IResponse Initialize(NewtonMeter torque, PerSecond angularSpeed)
    		{
    			var powerDemand = ComputePowerDemand(angularSpeed);
    			return NextComponent.Initialize(torque + powerDemand / angularSpeed, angularSpeed);
    		}
    
    		#endregion
    
    		#region VectoSimulationComponent
    
    		protected override void DoWriteModalResults(IModalDataContainer container)
    		{
    			var sum = 0.SI<Watt>();
    			foreach (var kv in _powerDemands) {
    				sum += kv.Value;
    				// todo: aux write directauxiliary somewhere to moddata .... probably Padd column??
    				if (!string.IsNullOrWhiteSpace(kv.Key)) {
    					container[kv.Key] = kv.Value;
    				}
    			}
    			container[ModalResultField.Paux] = sum;
    		}
    
    		protected override void DoCommitSimulationStep() {}
    
    		#endregion
    
    		public void AddConstant(string auxId, Watt powerDemand)
    		{
    			_auxDict[auxId] = speed => powerDemand;
    		}
    
    		public void AddDirect()
    		{
    			_auxDict[DirectAuxiliaryId] = speed => DataBus.CycleData.LeftSample.AdditionalAuxPowerDemand;
    		}
    
    		public void AddMapping(string auxId, AuxiliaryData data)
    		{
    			if (!DataBus.CycleData.LeftSample.AuxiliarySupplyPower.ContainsKey("Aux_" + auxId)) {
    				var error = string.Format("driving cycle does not contain column for auxiliary: {0}", auxId);
    				Log.Error(error);
    				throw new VectoException(error);
    			}
    
    			_auxDict[auxId] = speed => {
    				var powerSupply = DataBus.CycleData.LeftSample.AuxiliarySupplyPower["Aux_" + auxId];
    				var nAuxiliary = speed * data.TransmissionRatio;
    				var powerAuxOut = powerSupply / data.EfficiencyToSupply;
    				var powerAuxIn = data.GetPowerDemand(nAuxiliary, powerAuxOut);
    				return powerAuxIn / data.EfficiencyToEngine;
    			};
    		}
    	}
    }