diff --git a/VECTOAux/VectoAuxiliaries/AdvancedAuxiliaries.vb b/VECTOAux/VectoAuxiliaries/AdvancedAuxiliaries.vb index fed02ad3081b0de7bf8c96aa2087a7b6192546b2..1760a7744515ed1ea378713aa4469c48674e3e6d 100644 --- a/VECTOAux/VectoAuxiliaries/AdvancedAuxiliaries.vb +++ b/VECTOAux/VectoAuxiliaries/AdvancedAuxiliaries.vb @@ -271,7 +271,7 @@ Public Class AdvancedAuxiliaries Throw New NotImplementedException End Function - Public ReadOnly Property TotalFuelGRAMS As Single Implements VectoAuxiliaries.IAdvancedAuxiliaries.TotalFuelGRAMS + Public ReadOnly Property TotalFuelGRAMS As Double Implements VectoAuxiliaries.IAdvancedAuxiliaries.TotalFuelGRAMS Get If Not M13 Is Nothing Then diff --git a/VectoCommon/AdvancedAuxiliaryInterfaces/IAdvancedAuxiliaries.vb b/VectoCommon/AdvancedAuxiliaryInterfaces/IAdvancedAuxiliaries.vb index 4cc3a55f3e21c5729d8c8eca40f0f3e3f0991fd3..11742c04e59515aeb62ffa56a9e833e76175da04 100644 --- a/VectoCommon/AdvancedAuxiliaryInterfaces/IAdvancedAuxiliaries.vb +++ b/VectoCommon/AdvancedAuxiliaryInterfaces/IAdvancedAuxiliaries.vb @@ -60,7 +60,7 @@ Public Interface IAdvancedAuxiliaries ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> - ReadOnly Property TotalFuelGRAMS As Single + ReadOnly Property TotalFuelGRAMS As Double ''' <summary> ''' Total Cycle Fuel in Litres diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs index 5988322470655ff2f94bfa213bf7f283d1d207cc..91489d43671d9caf5df9675a845abeae419db34a 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs @@ -32,6 +32,7 @@ using System; using System.IO; using System.Windows.Forms.VisualStyles; +using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Simulation; @@ -44,20 +45,25 @@ using VectoAuxiliaries; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class BusAuxiliariesAdapter : StatefulVectoSimulationComponent<BusAuxiliariesAdapter.BusAuxState>, - IEngineAuxInProvider, IEngineAuxPort + public class BusAuxiliariesAdapter : LoggingObject, IEngineAuxInProvider, IEngineAuxPort { + protected IDataBus DataBus; + protected internal BusAuxState CurrentState; + protected internal BusAuxState PreviousState; + protected IAdvancedAuxiliaries Auxiliaries; private readonly FuelConsumptionAdapter _fcMapAdapter; - public BusAuxiliariesAdapter(IVehicleContainer container, string aauxFile, string cycleName, Kilogram vehicleWeight, - FuelConsumptionMap fcMap, - PerSecond engineIdleSpeed) : base(container) + public BusAuxiliariesAdapter(IDataBus container, string aauxFile, string cycleName, Kilogram vehicleWeight, + FuelConsumptionMap fcMap, PerSecond engineIdleSpeed) { // mAAUX_Global.advancedAuxModel.Signals.DeclarationMode = Cfg.DeclMode // mAAUX_Global.advancedAuxModel.Signals.WHTC = Declaration.WHTCcorrFactor + CurrentState = new BusAuxState(); + PreviousState = new BusAuxState(); + DataBus = container; var tmpAux = new AdvancedAuxiliaries(); // 'Set Statics @@ -114,6 +120,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public NewtonMeter Initialize(NewtonMeter torque, PerSecond angularSpeed) { + PreviousState.TotalFuelConsumption = 0.SI<Kilogram>(); PreviousState.AngularSpeed = angularSpeed; PreviousState.PowerDemand = GetBusAuxPowerDemand(0.SI<Second>(), 1.SI<Second>(), torque, torque, angularSpeed); return PreviousState.PowerDemand / angularSpeed; @@ -132,7 +139,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } - protected override void DoWriteModalResults(IModalDataContainer container) + protected internal void DoWriteModalResults(IModalDataContainer container) { _fcMapAdapter.AllowExtrapolation = true; // cycleStep has to be called here and not in DoCommit, write is called before Commit! @@ -140,6 +147,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Auxiliaries.CycleStep(CurrentState.dt.Value(), ref message); Log.Warn(message); + CurrentState.TotalFuelConsumption = Auxiliaries.TotalFuelGRAMS.SI().Gramm.Cast<Kilogram>(); container[ModalResultField.P_aux] = CurrentState.PowerDemand; container[ModalResultField.AA_NonSmartAlternatorsEfficiency] = Auxiliaries.AA_NonSmartAlternatorsEfficiency; @@ -193,11 +201,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl new SI(Auxiliaries.AA_TotalCycleFuelConsumptionCompressorOn.Value); } - protected override void DoCommitSimulationStep() + protected internal void DoCommitSimulationStep() { - AdvanceState(); + 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) @@ -256,6 +269,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public Second dt; public PerSecond AngularSpeed; public Watt PowerDemand; + public Kilogram TotalFuelConsumption; } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index 90c9b97008a487fa2615752958700b5e5daf08a7..14c6d7c99eb4a5ab96676cf7616288639a9c036a 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -342,6 +342,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var fcWHTC = fcAux * ModelData.WHTCCorrectionFactor; var fcAAUX = fcWHTC; + var advancedAux = EngineAux as BusAuxiliariesAdapter; + if (advancedAux != null) { + advancedAux.DoWriteModalResults(container); + fcAAUX = advancedAux.AAuxFuelConsumption; + } var fcFinal = fcAAUX; container[ModalResultField.FCMap] = fc; @@ -368,6 +373,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected override void DoCommitSimulationStep() { AdvanceState(); + var advancedAux = EngineAux as BusAuxiliariesAdapter; + if (advancedAux != null) { + advancedAux.DoCommitSimulationStep(); + } } #endregion