diff --git a/VECTO/AdvancedAuxiliariesModule.vb b/VECTO/AdvancedAuxiliariesModule.vb index 77e3e99522da8c77bbde79eeb0255c09fd8b8ca5..556546d550fd8c23cc0835d9a3da9940b6ef2e7f 100644 --- a/VECTO/AdvancedAuxiliariesModule.vb +++ b/VECTO/AdvancedAuxiliariesModule.vb @@ -3,6 +3,7 @@ Imports System.IO Imports System.Linq Imports System.Runtime.Remoting Imports TUGraz.VectoCore.BusAuxiliaries.Interfaces +Imports VectoAuxiliaries Module AdvancedAuxiliariesModule Public WithEvents AdvancedAuxModel As IAdvancedAuxiliaries @@ -100,7 +101,7 @@ Module AdvancedAuxiliariesModule o = Activator.CreateInstance(chosenAssembly.Value.AssemblyName, "VectoAuxiliaries.AdvancedAuxiliaries") iAdvancedAux = DirectCast(o.Unwrap, IAdvancedAuxiliaries) - iAdvancedAux.Configure(filePath, vectoFilePath) + Configure(filePath, vectoFilePath) Catch ex As Exception @@ -111,6 +112,31 @@ Module AdvancedAuxiliariesModule Return result End Function + Function Configure(filePath As String, vectoFilePath As String) As Boolean + Try + + Dim frmAuxiliaryConfig As New frmAuxiliaryConfig(filePath, vectoFilePath) + + frmAuxiliaryConfig.Show() + + If frmAuxiliaryConfig.DialogResult <> DialogResult.OK Then + + Return True + + Else + + Return False + + End If + + + Catch ex As Exception + + Return False + + End Try + End Function + ''' <summary> ''' Gets location of Advanced Auxiliaries Directory which contains all the assemblies available. diff --git a/VECTO/VECTO.vbproj b/VECTO/VECTO.vbproj index 70ba541d405815b1659726f8dae7f60518df9992..f946f6135fb1819fe792125ee33762294db70518 100644 --- a/VECTO/VECTO.vbproj +++ b/VECTO/VECTO.vbproj @@ -523,6 +523,10 @@ <Project>{550d99d4-25f7-48d9-b0f0-e5dd6cb3485d}</Project> <Name>BusAuxiliaries</Name> </ProjectReference> + <ProjectReference Include="..\VECTOAux\VectoAuxiliaries\VectoAuxiliaries.vbproj"> + <Project>{FDEEE460-0B8A-4EF6-8D9E-72F203A50F65}</Project> + <Name>VectoAuxiliaries</Name> + </ProjectReference> <ProjectReference Include="..\VectoCommon\VectoCommon\VectoCommon.csproj"> <Project>{79a066ad-69a9-4223-90f6-6ed5d2d084f4}</Project> <Name>VectoCommon</Name> diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs index 1fd7136f6bef4e6f917cf7f09c103d52b26d4e19..566210bfa5f9f5af0e1b3fa8bf1ba8358fc402ac 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs @@ -32,10 +32,11 @@ using System; using System.IO; using System.Linq; -using Pneumatics; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.BusAuxiliaries; using TUGraz.VectoCore.BusAuxiliaries.Interfaces; +using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.PneumaticSystem; using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; @@ -46,254 +47,254 @@ using VectoAuxiliaries; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class BusAuxiliariesAdapter : LoggingObject, IAuxInProvider, IAuxPort - { - protected readonly IDataBus DataBus; - protected internal BusAuxState CurrentState; - protected internal BusAuxState PreviousState; - - protected internal readonly IAuxPort AdditionalAux; - - protected IAdvancedAuxiliaries Auxiliaries; - private readonly FuelConsumptionAdapter _fcMapAdapter; - - public BusAuxiliariesAdapter(IDataBus container, string aauxFile, string cycleName, Kilogram vehicleWeight, - FuelConsumptionMap fcMap, PerSecond engineIdleSpeed, IAuxPort additionalAux = null) - { - // mAAUX_Global.advancedAuxModel.Signals.DeclarationMode = Cfg.DeclMode - // mAAUX_Global.advancedAuxModel.Signals.WHTC = Declaration.WHTCcorrFactor - CurrentState = new BusAuxState(); - PreviousState = new BusAuxState { AngularSpeed = engineIdleSpeed }; - - AdditionalAux = additionalAux; - - DataBus = container; - var tmpAux = new AdvancedAuxiliaries { - VectoInputs = { - Cycle = DetermineCycle(cycleName), - VehicleWeightKG = vehicleWeight - } - }; - - _fcMapAdapter = new FuelConsumptionAdapter() { FcMap = fcMap }; - tmpAux.VectoInputs.FuelMap = _fcMapAdapter; - // TODO: MQ 2019-07-30: how to handle fuel in aaux? - tmpAux.VectoInputs.FuelDensity = FuelData.Instance().Lookup((container as IVehicleContainer).RunData.EngineData.Fuels.First().FuelData.FuelType).FuelDensity; - - //'Set Signals - tmpAux.Signals.EngineIdleSpeed = engineIdleSpeed; - tmpAux.Initialise(Path.GetFileName(aauxFile), Path.GetDirectoryName(Path.GetFullPath(aauxFile)) + @"\"); - - tmpAux.Signals.TotalCycleTimeSeconds = - tmpAux.actuationsMap.GetNumActuations(new ActuationsKey("CycleTime", tmpAux.VectoInputs.Cycle)); - - // call initialize again _after_ setting the cycle time to get the correct consumtions - tmpAux.Initialise(Path.GetFileName(aauxFile), Path.GetDirectoryName(Path.GetFullPath(aauxFile)) + @"\"); - - - Auxiliaries = tmpAux; - } - - private static string DetermineCycle(string cycleName) - { - var cycle = cycleName.ToLower(); - - if (cycle.Contains("bus")) { - if (cycle.Contains("heavy_urban")) { - return "Heavy urban"; - } - if (cycle.Contains("suburban")) { - return "Suburban"; - } - if (cycle.Contains("interurban")) { - return "Interurban"; - } - if (cycle.Contains("urban")) { - return "Urban"; - } - } - if (cycle.Contains("coach")) { - return "Coach"; - } - Logger<BusAuxiliariesAdapter>() - .Warn("UnServiced Cycle Name '{0}' in Pneumatics Actuations Map 0 Actuations returned", cycleName); - return cycleName; - } - - public IAuxPort Port() - { - return this; - } - - public NewtonMeter Initialize(NewtonMeter torque, PerSecond angularSpeed) - { - //PreviousState.TotalFuelConsumption = 0.SI<Kilogram>(); - PreviousState.AngularSpeed = angularSpeed; - CurrentState.AngularSpeed = angularSpeed; - if (AdditionalAux != null) { - AdditionalAux.Initialize(torque, angularSpeed); - } - PreviousState.PowerDemand = GetBusAuxPowerDemand(0.SI<Second>(), 1.SI<Second>(), torque, torque, angularSpeed); - return PreviousState.PowerDemand / angularSpeed; - } - - - public NewtonMeter TorqueDemand(Second absTime, Second dt, NewtonMeter torquePowerTrain, NewtonMeter torqueEngine, - PerSecond angularSpeed, bool dryRun = false) - { - CurrentState.AngularSpeed = angularSpeed; - CurrentState.dt = dt; - CurrentState.PowerDemand = GetBusAuxPowerDemand(absTime, dt, torquePowerTrain, torqueEngine, angularSpeed, dryRun); - - var avgAngularSpeed = (CurrentState.AngularSpeed + PreviousState.AngularSpeed) / 2.0; - return CurrentState.PowerDemand / avgAngularSpeed; - } - - public Watt PowerDemandEngineOn(PerSecond engineSpeed) - { - throw new NotImplementedException(); - } - - public Watt PowerDemandEngineOff() - { - throw new NotImplementedException(); - } - - - protected internal void DoWriteModalResults(IModalDataContainer container) - { - _fcMapAdapter.AllowExtrapolation = true; - // cycleStep has to be called here and not in DoCommit, write is called before Commit! - var message = String.Empty; - Auxiliaries.CycleStep(CurrentState.dt, ref message); - Log.Warn(message); - - CurrentState.TotalFuelConsumption = Auxiliaries.TotalFuelGRAMS; - container[ModalResultField.P_aux] = CurrentState.PowerDemand; - - container[ModalResultField.AA_NonSmartAlternatorsEfficiency] = Auxiliaries.AA_NonSmartAlternatorsEfficiency; - if (Auxiliaries.AA_SmartIdleCurrent_Amps != null) { - container[ModalResultField.AA_SmartIdleCurrent_Amps] = Auxiliaries.AA_SmartIdleCurrent_Amps; - } - container[ModalResultField.AA_SmartIdleAlternatorsEfficiency] = Auxiliaries.AA_SmartIdleAlternatorsEfficiency; - if (Auxiliaries.AA_SmartTractionCurrent_Amps != null) { - container[ModalResultField.AA_SmartTractionCurrent_Amps] = - Auxiliaries.AA_SmartTractionCurrent_Amps; - } - container[ModalResultField.AA_SmartTractionAlternatorEfficiency] = Auxiliaries.AA_SmartTractionAlternatorEfficiency; - if (Auxiliaries.AA_SmartOverrunCurrent_Amps != null) { - container[ModalResultField.AA_SmartOverrunCurrent_Amps] = Auxiliaries.AA_SmartOverrunCurrent_Amps; - } - container[ModalResultField.AA_SmartOverrunAlternatorEfficiency] = Auxiliaries.AA_SmartOverrunAlternatorEfficiency; - if (Auxiliaries.AA_CompressorFlowRate_LitrePerSec != null) { - container[ModalResultField.AA_CompressorFlowRate_LitrePerSec] = - Auxiliaries.AA_CompressorFlowRate_LitrePerSec; - } - container[ModalResultField.AA_OverrunFlag] = Auxiliaries.AA_OverrunFlag; - container[ModalResultField.AA_EngineIdleFlag] = Auxiliaries.AA_EngineIdleFlag; - container[ModalResultField.AA_CompressorFlag] = Auxiliaries.AA_CompressorFlag; - if (Auxiliaries.AA_TotalCycleFC_Grams != null) { - container[ModalResultField.AA_TotalCycleFC_Grams] = Auxiliaries.AA_TotalCycleFC_Grams; - } - if (Auxiliaries.AA_TotalCycleFC_Litres != null) { - container[ModalResultField.AA_TotalCycleFC_Litres] = Auxiliaries.AA_TotalCycleFC_Litres; - } - if (Auxiliaries.AA_AveragePowerDemandCrankHVACMechanicals != null) { - container[ModalResultField.AA_AveragePowerDemandCrankHVACMechanicals] = - Auxiliaries.AA_AveragePowerDemandCrankHVACMechanicals; - } - if (Auxiliaries.AA_AveragePowerDemandCrankHVACElectricals != null) { - container[ModalResultField.AA_AveragePowerDemandCrankHVACElectricals] = - Auxiliaries.AA_AveragePowerDemandCrankHVACElectricals; - } - if (Auxiliaries.AA_AveragePowerDemandCrankElectrics != null) { - container[ModalResultField.AA_AveragePowerDemandCrankElectrics] = - Auxiliaries.AA_AveragePowerDemandCrankElectrics; - } - if (Auxiliaries.AA_AveragePowerDemandCrankPneumatics != null) { - container[ModalResultField.AA_AveragePowerDemandCrankPneumatics] = - Auxiliaries.AA_AveragePowerDemandCrankPneumatics; - } - if (Auxiliaries.AA_TotalCycleFuelConsumptionCompressorOff != null) { - container[ModalResultField.AA_TotalCycleFuelConsumptionCompressorOff] = - Auxiliaries.AA_TotalCycleFuelConsumptionCompressorOff; - } - container[ModalResultField.AA_TotalCycleFuelConsumptionCompressorOn] = - Auxiliaries.AA_TotalCycleFuelConsumptionCompressorOn; - } - - protected internal void DoCommitSimulationStep() - { - PreviousState = CurrentState; - CurrentState = new BusAuxState(); - } - - protected internal KilogramPerSecond AAuxFuelConsumption - { - get { return (CurrentState.TotalFuelConsumption - PreviousState.TotalFuelConsumption) / CurrentState.dt; } - } - - private Watt GetBusAuxPowerDemand(Second absTime, Second dt, NewtonMeter torquePowerTrain, NewtonMeter torqueEngine, - PerSecond angularSpeed, bool dryRun = false) - { - Auxiliaries.ResetCalculations(); - - _fcMapAdapter.AllowExtrapolation = true; - - Auxiliaries.Signals.ClutchEngaged = DataBus.ClutchClosed(absTime); - Auxiliaries.Signals.EngineDrivelinePower = torquePowerTrain * angularSpeed; - Auxiliaries.Signals.EngineDrivelineTorque = torquePowerTrain; - Auxiliaries.Signals.InternalEnginePower = torqueEngine * angularSpeed - DataBus.BrakePower; - if (DataBus.DriverBehavior == DrivingBehavior.Coasting) { - // make sure smart aux are _not_ enabled for now - // set internal_engine_power a little bit lower so there is no excessive power for smart aux - Auxiliaries.Signals.InternalEnginePower = 0.9 * torqueEngine * angularSpeed /*- DataBus.BrakePower*/; - // if smart aux should be on during coasting use the following line - // set internal_engine_power to a large value (*10) so that there's excessive power for smart aux (alreadin during search operating point) - //(float)DataBus.EngineDragPower(angularSpeed).Value() / 100; - } else { - if (DataBus.DriverBehavior != DrivingBehavior.Braking) { - Auxiliaries.Signals.InternalEnginePower = 0.SI<Watt>(); - //(float)((0.9 * torqueEngine * angularSpeed - DataBus.BrakePower) / 1000).Value(); - } else { - // smart aux should be on during braking - } - } - Auxiliaries.Signals.EngineMotoringPower = -DataBus.EngineDragPower(angularSpeed); - Auxiliaries.Signals.EngineSpeed = angularSpeed; - var avgAngularSpeed = (PreviousState.AngularSpeed + CurrentState.AngularSpeed) / 2; - Auxiliaries.Signals.PreExistingAuxPower = AdditionalAux != null - ? AdditionalAux.TorqueDemand(absTime, dt, torquePowerTrain, torqueEngine, angularSpeed, dryRun) * avgAngularSpeed - : 0.SI<Watt>(); - //mAAUX_Global.PreExistingAuxPower; - Auxiliaries.Signals.Idle = DataBus.VehicleStopped; - Auxiliaries.Signals.InNeutral = DataBus.Gear == 0; - Auxiliaries.Signals.RunningCalc = true; - - //mAAUX_Global.Internal_Engine_Power; - //'Power coming out of Advanced Model is in Watts. - - return Auxiliaries.AuxiliaryPowerAtCrankWatts + Auxiliaries.Signals.PreExistingAuxPower; - } - - protected class FuelConsumptionAdapter : IFuelConsumptionMap - { - protected internal FuelConsumptionMap FcMap; - - public bool AllowExtrapolation { get; set; } - - public KilogramPerSecond GetFuelConsumption(NewtonMeter torque, PerSecond angularVelocity) - { - return FcMap.GetFuelConsumption(torque, angularVelocity, AllowExtrapolation).Value; - } - } - - public class BusAuxState - { - public Second dt; - public PerSecond AngularSpeed; - public Watt PowerDemand; - public Kilogram TotalFuelConsumption = 0.SI<Kilogram>(); - } - } + public class BusAuxiliariesAdapter : LoggingObject, IAuxInProvider, IAuxPort + { + protected readonly IDataBus DataBus; + protected internal BusAuxState CurrentState; + protected internal BusAuxState PreviousState; + + protected internal readonly IAuxPort AdditionalAux; + + protected IAdvancedAuxiliaries Auxiliaries; + private readonly FuelConsumptionAdapter _fcMapAdapter; + + public BusAuxiliariesAdapter(IDataBus container, string aauxFile, string cycleName, Kilogram vehicleWeight, + FuelConsumptionMap fcMap, PerSecond engineIdleSpeed, IAuxPort additionalAux = null) + { + // mAAUX_Global.advancedAuxModel.Signals.DeclarationMode = Cfg.DeclMode + // mAAUX_Global.advancedAuxModel.Signals.WHTC = Declaration.WHTCcorrFactor + CurrentState = new BusAuxState(); + PreviousState = new BusAuxState { AngularSpeed = engineIdleSpeed }; + + AdditionalAux = additionalAux; + + DataBus = container; + var tmpAux = new AdvancedAuxiliaries { + VectoInputs = { + Cycle = DetermineCycle(cycleName), + VehicleWeightKG = vehicleWeight + } + }; + + _fcMapAdapter = new FuelConsumptionAdapter() { FcMap = fcMap }; + tmpAux.VectoInputs.FuelMap = _fcMapAdapter; + // TODO: MQ 2019-07-30: how to handle fuel in aaux? + tmpAux.VectoInputs.FuelDensity = FuelData.Instance().Lookup((container as IVehicleContainer).RunData.EngineData.Fuels.First().FuelData.FuelType).FuelDensity; + + //'Set Signals + tmpAux.Signals.EngineIdleSpeed = engineIdleSpeed; + tmpAux.Initialise(Path.GetFileName(aauxFile), Path.GetDirectoryName(Path.GetFullPath(aauxFile)) + @"\"); + + tmpAux.Signals.TotalCycleTimeSeconds = + tmpAux.actuationsMap.GetNumActuations(new ActuationsKey("CycleTime", tmpAux.VectoInputs.Cycle)); + + // call initialize again _after_ setting the cycle time to get the correct consumtions + tmpAux.Initialise(Path.GetFileName(aauxFile), Path.GetDirectoryName(Path.GetFullPath(aauxFile)) + @"\"); + + + Auxiliaries = tmpAux; + } + + private static string DetermineCycle(string cycleName) + { + var cycle = cycleName.ToLower(); + + if (cycle.Contains("bus")) { + if (cycle.Contains("heavy_urban")) { + return "Heavy urban"; + } + if (cycle.Contains("suburban")) { + return "Suburban"; + } + if (cycle.Contains("interurban")) { + return "Interurban"; + } + if (cycle.Contains("urban")) { + return "Urban"; + } + } + if (cycle.Contains("coach")) { + return "Coach"; + } + Logger<BusAuxiliariesAdapter>() + .Warn("UnServiced Cycle Name '{0}' in Pneumatics Actuations Map 0 Actuations returned", cycleName); + return cycleName; + } + + public IAuxPort Port() + { + return this; + } + + public NewtonMeter Initialize(NewtonMeter torque, PerSecond angularSpeed) + { + //PreviousState.TotalFuelConsumption = 0.SI<Kilogram>(); + PreviousState.AngularSpeed = angularSpeed; + CurrentState.AngularSpeed = angularSpeed; + if (AdditionalAux != null) { + AdditionalAux.Initialize(torque, angularSpeed); + } + PreviousState.PowerDemand = GetBusAuxPowerDemand(0.SI<Second>(), 1.SI<Second>(), torque, torque, angularSpeed); + return PreviousState.PowerDemand / angularSpeed; + } + + + public NewtonMeter TorqueDemand(Second absTime, Second dt, NewtonMeter torquePowerTrain, NewtonMeter torqueEngine, + PerSecond angularSpeed, bool dryRun = false) + { + CurrentState.AngularSpeed = angularSpeed; + CurrentState.dt = dt; + CurrentState.PowerDemand = GetBusAuxPowerDemand(absTime, dt, torquePowerTrain, torqueEngine, angularSpeed, dryRun); + + var avgAngularSpeed = (CurrentState.AngularSpeed + PreviousState.AngularSpeed) / 2.0; + return CurrentState.PowerDemand / avgAngularSpeed; + } + + public Watt PowerDemandEngineOn(PerSecond engineSpeed) + { + throw new NotImplementedException(); + } + + public Watt PowerDemandEngineOff() + { + throw new NotImplementedException(); + } + + + protected internal void DoWriteModalResults(IModalDataContainer container) + { + _fcMapAdapter.AllowExtrapolation = true; + // cycleStep has to be called here and not in DoCommit, write is called before Commit! + var message = String.Empty; + Auxiliaries.CycleStep(CurrentState.dt, ref message); + Log.Warn(message); + + CurrentState.TotalFuelConsumption = Auxiliaries.TotalFuelGRAMS; + container[ModalResultField.P_aux] = CurrentState.PowerDemand; + + container[ModalResultField.AA_NonSmartAlternatorsEfficiency] = Auxiliaries.AA_NonSmartAlternatorsEfficiency; + if (Auxiliaries.AA_SmartIdleCurrent_Amps != null) { + container[ModalResultField.AA_SmartIdleCurrent_Amps] = Auxiliaries.AA_SmartIdleCurrent_Amps; + } + container[ModalResultField.AA_SmartIdleAlternatorsEfficiency] = Auxiliaries.AA_SmartIdleAlternatorsEfficiency; + if (Auxiliaries.AA_SmartTractionCurrent_Amps != null) { + container[ModalResultField.AA_SmartTractionCurrent_Amps] = + Auxiliaries.AA_SmartTractionCurrent_Amps; + } + container[ModalResultField.AA_SmartTractionAlternatorEfficiency] = Auxiliaries.AA_SmartTractionAlternatorEfficiency; + if (Auxiliaries.AA_SmartOverrunCurrent_Amps != null) { + container[ModalResultField.AA_SmartOverrunCurrent_Amps] = Auxiliaries.AA_SmartOverrunCurrent_Amps; + } + container[ModalResultField.AA_SmartOverrunAlternatorEfficiency] = Auxiliaries.AA_SmartOverrunAlternatorEfficiency; + if (Auxiliaries.AA_CompressorFlowRate_LitrePerSec != null) { + container[ModalResultField.AA_CompressorFlowRate_LitrePerSec] = + Auxiliaries.AA_CompressorFlowRate_LitrePerSec; + } + container[ModalResultField.AA_OverrunFlag] = Auxiliaries.AA_OverrunFlag; + container[ModalResultField.AA_EngineIdleFlag] = Auxiliaries.AA_EngineIdleFlag; + container[ModalResultField.AA_CompressorFlag] = Auxiliaries.AA_CompressorFlag; + if (Auxiliaries.AA_TotalCycleFC_Grams != null) { + container[ModalResultField.AA_TotalCycleFC_Grams] = Auxiliaries.AA_TotalCycleFC_Grams; + } + if (Auxiliaries.AA_TotalCycleFC_Litres != null) { + container[ModalResultField.AA_TotalCycleFC_Litres] = Auxiliaries.AA_TotalCycleFC_Litres; + } + if (Auxiliaries.AA_AveragePowerDemandCrankHVACMechanicals != null) { + container[ModalResultField.AA_AveragePowerDemandCrankHVACMechanicals] = + Auxiliaries.AA_AveragePowerDemandCrankHVACMechanicals; + } + if (Auxiliaries.AA_AveragePowerDemandCrankHVACElectricals != null) { + container[ModalResultField.AA_AveragePowerDemandCrankHVACElectricals] = + Auxiliaries.AA_AveragePowerDemandCrankHVACElectricals; + } + if (Auxiliaries.AA_AveragePowerDemandCrankElectrics != null) { + container[ModalResultField.AA_AveragePowerDemandCrankElectrics] = + Auxiliaries.AA_AveragePowerDemandCrankElectrics; + } + if (Auxiliaries.AA_AveragePowerDemandCrankPneumatics != null) { + container[ModalResultField.AA_AveragePowerDemandCrankPneumatics] = + Auxiliaries.AA_AveragePowerDemandCrankPneumatics; + } + if (Auxiliaries.AA_TotalCycleFuelConsumptionCompressorOff != null) { + container[ModalResultField.AA_TotalCycleFuelConsumptionCompressorOff] = + Auxiliaries.AA_TotalCycleFuelConsumptionCompressorOff; + } + container[ModalResultField.AA_TotalCycleFuelConsumptionCompressorOn] = + Auxiliaries.AA_TotalCycleFuelConsumptionCompressorOn; + } + + protected internal void DoCommitSimulationStep() + { + PreviousState = CurrentState; + CurrentState = new BusAuxState(); + } + + protected internal KilogramPerSecond AAuxFuelConsumption + { + get { return (CurrentState.TotalFuelConsumption - PreviousState.TotalFuelConsumption) / CurrentState.dt; } + } + + private Watt GetBusAuxPowerDemand(Second absTime, Second dt, NewtonMeter torquePowerTrain, NewtonMeter torqueEngine, + PerSecond angularSpeed, bool dryRun = false) + { + Auxiliaries.ResetCalculations(); + + _fcMapAdapter.AllowExtrapolation = true; + + Auxiliaries.Signals.ClutchEngaged = DataBus.ClutchClosed(absTime); + Auxiliaries.Signals.EngineDrivelinePower = torquePowerTrain * angularSpeed; + Auxiliaries.Signals.EngineDrivelineTorque = torquePowerTrain; + Auxiliaries.Signals.InternalEnginePower = torqueEngine * angularSpeed - DataBus.BrakePower; + if (DataBus.DriverBehavior == DrivingBehavior.Coasting) { + // make sure smart aux are _not_ enabled for now + // set internal_engine_power a little bit lower so there is no excessive power for smart aux + Auxiliaries.Signals.InternalEnginePower = 0.9 * torqueEngine * angularSpeed /*- DataBus.BrakePower*/; + // if smart aux should be on during coasting use the following line + // set internal_engine_power to a large value (*10) so that there's excessive power for smart aux (alreadin during search operating point) + //(float)DataBus.EngineDragPower(angularSpeed).Value() / 100; + } else { + if (DataBus.DriverBehavior != DrivingBehavior.Braking) { + Auxiliaries.Signals.InternalEnginePower = 0.SI<Watt>(); + //(float)((0.9 * torqueEngine * angularSpeed - DataBus.BrakePower) / 1000).Value(); + } else { + // smart aux should be on during braking + } + } + Auxiliaries.Signals.EngineMotoringPower = -DataBus.EngineDragPower(angularSpeed); + Auxiliaries.Signals.EngineSpeed = angularSpeed; + var avgAngularSpeed = (PreviousState.AngularSpeed + CurrentState.AngularSpeed) / 2; + Auxiliaries.Signals.PreExistingAuxPower = AdditionalAux != null + ? AdditionalAux.TorqueDemand(absTime, dt, torquePowerTrain, torqueEngine, angularSpeed, dryRun) * avgAngularSpeed + : 0.SI<Watt>(); + //mAAUX_Global.PreExistingAuxPower; + Auxiliaries.Signals.Idle = DataBus.VehicleStopped; + Auxiliaries.Signals.InNeutral = DataBus.Gear == 0; + Auxiliaries.Signals.RunningCalc = true; + + //mAAUX_Global.Internal_Engine_Power; + //'Power coming out of Advanced Model is in Watts. + + return Auxiliaries.AuxiliaryPowerAtCrankWatts + Auxiliaries.Signals.PreExistingAuxPower; + } + + protected class FuelConsumptionAdapter : IFuelConsumptionMap + { + protected internal FuelConsumptionMap FcMap; + + public bool AllowExtrapolation { get; set; } + + public KilogramPerSecond GetFuelConsumption(NewtonMeter torque, PerSecond angularVelocity) + { + return FcMap.GetFuelConsumption(torque, angularVelocity, AllowExtrapolation).Value; + } + } + + public class BusAuxState + { + public Second dt; + public PerSecond AngularSpeed; + public Watt PowerDemand; + public Kilogram TotalFuelConsumption = 0.SI<Kilogram>(); + } + } } \ No newline at end of file