diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs index 027ee37c5867af81fe0e31d367ab8b75213c4d06..96550f8add63e7f9d6a9d1f9842879c650736772 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs @@ -14,7 +14,6 @@ using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.DataBus; 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.Utils; @@ -23,8 +22,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies { public class HybridStrategy : AbstractHybridStrategy<Gearbox> { - public HybridStrategy(VectoRunData runData, IVehicleContainer vehicleContainer) : base(runData, - vehicleContainer) + public HybridStrategy(VectoRunData runData, IVehicleContainer vehicleContainer) : base(runData, vehicleContainer) { // register pre-processors vehicleContainer.AddPreprocessor(GetGearshiftPreprocessor(runData)); @@ -44,7 +42,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies builder.BuildSimpleHybridPowertrain(runData, testContainer); return new VelocitySpeedGearshiftPreprocessor(VelocityDropData, runData.GearboxData.TractionInterruption, - testContainer, -grad, grad, 2); + testContainer, -grad, grad); } protected override IResponse RequestDryRun(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, GearshiftPosition nextGear, HybridStrategyResponse cfg) @@ -92,7 +90,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return null; } - var vDrop = DataBus.VehicleInfo.VehicleSpeed - estimatedVelocityPostShift; var vehicleSpeedPostShift = estimatedVelocityPostShift; // DataBus.VehicleInfo.VehicleSpeed - vDrop * ModelData.GearshiftParameters.VelocityDropFactor; TestPowertrain.Gearbox.Gear = nextGear; @@ -103,41 +100,33 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } } - //if (!nextGear.Engaged) { - TestPowertrain.Gearbox._nextGear = Controller.ShiftStrategy.NextGear; - TestPowertrain.Gearbox.Disengaged = !nextGear.Engaged; - //} + TestPowertrain.Gearbox._nextGear = Controller.ShiftStrategy.NextGear; + TestPowertrain.Gearbox.Disengaged = !nextGear.Engaged; - //if (!PreviousState.GearboxEngaged) { - TestPowertrain.CombustionEngine.Initialize( - (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineTorque, - (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineSpeed); - TestPowertrain.CombustionEngine.PreviousState.EngineOn = //true; - (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineOn; - TestPowertrain.CombustionEngine.PreviousState.EnginePower = - (DataBus.EngineInfo as CombustionEngine).PreviousState.EnginePower; - TestPowertrain.CombustionEngine.PreviousState.dt = (DataBus.EngineInfo as CombustionEngine).PreviousState.dt; - TestPowertrain.CombustionEngine.PreviousState.EngineSpeed = - (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineSpeed; - TestPowertrain.CombustionEngine.PreviousState.EngineTorque = - (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineTorque; - TestPowertrain.CombustionEngine.PreviousState.EngineTorqueOut = - (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineTorqueOut; - TestPowertrain.CombustionEngine.PreviousState.DynamicFullLoadTorque = - (DataBus.EngineInfo as CombustionEngine).PreviousState.DynamicFullLoadTorque; + var combustionEngineInfo = DataBus.EngineInfo as CombustionEngine; + var enginePrevious = combustionEngineInfo.PreviousState; + TestPowertrain.CombustionEngine.Initialize(enginePrevious.EngineTorque, enginePrevious.EngineSpeed); + var testPreviousState = TestPowertrain.CombustionEngine.PreviousState; + testPreviousState.EngineOn = enginePrevious.EngineOn; + testPreviousState.EnginePower = enginePrevious.EnginePower; + testPreviousState.dt = enginePrevious.dt; + testPreviousState.EngineSpeed = enginePrevious.EngineSpeed; + testPreviousState.EngineTorque = enginePrevious.EngineTorque; + testPreviousState.EngineTorqueOut = enginePrevious.EngineTorqueOut; + testPreviousState.DynamicFullLoadTorque = enginePrevious.DynamicFullLoadTorque; switch (TestPowertrain.CombustionEngine.EngineAux) { case EngineAuxiliary engineAux: engineAux.PreviousState.AngularSpeed = - ((DataBus.EngineInfo as CombustionEngine).EngineAux as EngineAuxiliary).PreviousState + (combustionEngineInfo.EngineAux as EngineAuxiliary).PreviousState .AngularSpeed; break; case BusAuxiliariesAdapter busAux: busAux.PreviousState.AngularSpeed = - ((DataBus.EngineInfo as CombustionEngine).EngineAux as BusAuxiliariesAdapter).PreviousState + (combustionEngineInfo.EngineAux as BusAuxiliariesAdapter).PreviousState .AngularSpeed; if (busAux.ElectricStorage is SimpleBattery bat) { - bat.SOC = ((DataBus.EngineInfo as CombustionEngine).EngineAux as BusAuxiliariesAdapter) + bat.SOC = (combustionEngineInfo.EngineAux as BusAuxiliariesAdapter) .ElectricStorage .SOC; } @@ -313,7 +302,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineTorqueOut; TestPowertrain.CombustionEngine.PreviousState.DynamicFullLoadTorque = (DataBus.EngineInfo as CombustionEngine).PreviousState.DynamicFullLoadTorque; - + switch (TestPowertrain.CombustionEngine.EngineAux) { case EngineAuxiliary engineAux: engineAux.PreviousState.AngularSpeed = @@ -465,7 +454,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies // ===================================================== - public abstract class AbstractHybridStrategy<T> : LoggingObject, IHybridControlStrategy where T: class, IHybridControlledGearbox, IGearbox + public abstract class AbstractHybridStrategy<T> : LoggingObject, IHybridControlStrategy where T : class, IHybridControlledGearbox, IGearbox { public class StrategyState @@ -497,7 +486,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies public DrivingAction DrivingAction { get; } - public HybridResultEntry Solution { get; } + public HybridResultEntry Solution { get; } public List<HybridResultEntry> EvaluatedConfigs { get; } } @@ -552,7 +541,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies ElectricMotorsOff = ModelData.ElectricMachinesData .Select(x => new KeyValuePair<PowertrainPosition, NewtonMeter>(x.Item1, null)) - .ToDictionary(x => x.Key, x => new Tuple<PerSecond, NewtonMeter>(null, x.Value)); + .ToDictionary(x => x.Key, x => new Tuple<PerSecond, NewtonMeter>(null, x.Value)); var emPos = ModelData.ElectricMachinesData.First().Item1; ElectricMotorCanPropellDuringTractionInterruption = emPos == PowertrainPosition.HybridP4 || emPos == PowertrainPosition.HybridP3; @@ -574,8 +563,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies builder.BuildSimpleHybridPowertrain(runData, testContainer); TestPowertrain = new TestPowertrain<T>(testContainer, DataBus); - - + + var shiftStrategyParameters = runData.GearshiftParameters; if (shiftStrategyParameters == null) { @@ -608,16 +597,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies public virtual IHybridStrategyResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, bool dryRun) { - + if (DataBus.DriverInfo.DrivingAction == DrivingAction.Accelerate && StrategyParameters.MaxPropulsionTorque != null && DataBus.GearboxInfo.TCLocked) { var nextGear = DataBus.VehicleInfo.VehicleStopped ? Controller.ShiftStrategy.NextGear : !DataBus.GearboxInfo.GearEngaged(absTime) ? Controller.ShiftStrategy.NextGear - : (PreviousState.GearboxEngaged + : PreviousState.GearboxEngaged ? DataBus.GearboxInfo.Gear - : Controller.ShiftStrategy.NextGear); - var emOff = new HybridStrategyResponse() { + : Controller.ShiftStrategy.NextGear; + var emOff = new HybridStrategyResponse { CombustionEngineOn = DataBus.EngineInfo.EngineOn, // AllowICEOff(absTime), GearboxInNeutral = false, NextGear = nextGear, @@ -693,19 +682,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } - if (DataBus.DriverInfo.DrivingAction == DrivingAction.Brake && (eval.Count == 0 )) { + if (DataBus.DriverInfo.DrivingAction == DrivingAction.Brake && eval.Count == 0) { eval.Add(MaxRecuperationSetting(absTime, dt, outTorque, outAngularVelocity, dryRun)); } var best = SelectBestOption(eval, absTime, dt, outTorque, outAngularVelocity, dryRun, currentGear); - + if (best == null) { best = ResponseEmOff; best.ICEOff = false; } - + var retVal = CreateResponse(best, currentGear); - + retVal.GearboxEngaged = DataBus.GearboxInfo.GearEngaged(absTime); //if (!DataBus.EngineInfo.EngineOn && !best.ICEOff && retVal.ShiftRequired) { // CurrentState.ICEStartTStmp = absTime + dt; @@ -762,16 +751,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies // overwrite delta value... var maxTorque = StrategyParameters.MaxPropulsionTorque.FullLoadDriveTorque(response.Gearbox.InputSpeed); - + var emPos = ModelData.ElectricMachinesData.First().Item1; var gbxInTq = GetGearboxInTorqueLimitedVehiclePorpTorque(dryRunResponse, emPos); dryRunResponse.DeltaFullLoad = (gbxInTq - maxTorque) * dryRunResponse.Gearbox.InputSpeed; - dryRunResponse.DeltaFullLoadTorque = (gbxInTq - maxTorque); + dryRunResponse.DeltaFullLoadTorque = gbxInTq - maxTorque; dryRunResponse.DeltaDragLoad = (gbxInTq - maxTorque) * dryRunResponse.Gearbox.InputSpeed; - dryRunResponse.DeltaDragLoadTorque = (gbxInTq - maxTorque); + dryRunResponse.DeltaDragLoadTorque = gbxInTq - maxTorque; } } @@ -876,7 +865,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies if (candidates.ContainsKey(nextGear)) { continue; } - var emOff = new HybridStrategyResponse() { + var emOff = new HybridStrategyResponse { CombustionEngineOn = DataBus.EngineInfo.EngineOn, // AllowICEOff(absTime), GearboxInNeutral = false, NextGear = nextGear, @@ -898,11 +887,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var maxPwr = candidates.MaxBy(x => x.Value.Item1); if (!emOffResponse.Gearbox.Gear.Equals(maxPwr.Key)) { - return new HybridStrategyResponse() { + return new HybridStrategyResponse { ShiftRequired = true, NextGear = maxPwr.Key, //CombustionEngineOn = - EvaluatedSolution = new HybridResultEntry() { + EvaluatedSolution = new HybridResultEntry { Gear = maxPwr.Key, Response = maxPwr.Value.Item2 }, @@ -915,17 +904,17 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies ? Controller.ShiftStrategy.NextGear : PreviousState.GearboxEngaged ? DataBus.GearboxInfo.Gear : Controller.ShiftStrategy.NextGear; - var maxEmDriveSetting = new HybridStrategyResponse() { + var maxEmDriveSetting = new HybridStrategyResponse { CombustionEngineOn = true, GearboxInNeutral = false, - MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() { + MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> { {emPos , Tuple.Create(emOffResponse.ElectricMotor.AngularVelocity, emOffResponse.ElectricMotor.MaxDriveTorque)} }, }; var maxEmDriveResponse = RequestDryRun(absTime, dt, outTorque, outAngularVelocity, currentGear, maxEmDriveSetting); - var deltaFullLoadTq = (maxEmDriveResponse.Engine.TotalTorqueDemand - - maxEmDriveResponse.Engine.DynamicFullLoadTorque); + var deltaFullLoadTq = maxEmDriveResponse.Engine.TotalTorqueDemand - + maxEmDriveResponse.Engine.DynamicFullLoadTorque; var maxEngineSpeed = maxEmDriveResponse.Gearbox.Gear.Gear == 0 || !DataBus.ClutchInfo.ClutchClosed(absTime) || !DataBus.GearboxInfo.TCLocked @@ -936,7 +925,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var gbxInTq = GetGearboxInTorqueLimitedVehiclePorpTorque(emOffResponse, emPos); if (deltaFullLoadTq.IsSmallerOrEqual(0)) { // the engine is not overloaded if EM boosts, limit to max gearbox torque - return new HybridStrategyLimitedResponse() { + return new HybridStrategyLimitedResponse { //Delta = outTorque * outAngularVelocity - StrategyParameters.MaxDrivetrainPower, Delta = (gbxInTq - maxTorqueGbxIn) * emOffResponse.Gearbox.InputSpeed, DeltaEngineSpeed = maxEmDriveResponse.Engine.EngineSpeed - maxEngineSpeed, // .DeltaEngineSpeed @@ -949,7 +938,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies // gearbox in torque is much higher above limit than ice operating point above full-load curve (with em boosting) // search to max torque curve // i.e. when limiting to max torque the ICE operating point is below full-load curve - return new HybridStrategyLimitedResponse() { + return new HybridStrategyLimitedResponse { Delta = (gbxInTq - maxTorqueGbxIn) * emOffResponse.Gearbox.InputSpeed, DeltaEngineSpeed = maxEmDriveResponse.Engine.EngineSpeed - maxEngineSpeed, // .DeltaEngineSpeed GearboxResponse = maxEmDriveResponse.Gearbox, @@ -962,27 +951,23 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var avgEngineSpeed = (maxEmDriveResponse.Engine.EngineSpeed + DataBus.EngineInfo.EngineSpeed) / 2; var maxTorque = SearchAlgorithm.Search(outTorque, deltaFullLoadTq, -outTorque * 0.1, getYValue: resp => { - var r = resp as IResponse; - var deltaMaxTq = (r.Engine.TotalTorqueDemand - - r.Engine.DynamicFullLoadTorque); + var r = (IResponse)resp; + var deltaMaxTq = r.Engine.TotalTorqueDemand - r.Engine.DynamicFullLoadTorque; return deltaMaxTq * avgEngineSpeed; }, - evaluateFunction: x => { - return RequestDryRun(absTime, dt, x, outAngularVelocity, currentGear, maxEmDriveSetting); - }, + evaluateFunction: x => RequestDryRun(absTime, dt, x, outAngularVelocity, currentGear, maxEmDriveSetting), criterion: resp => { - var r = resp as IResponse; - var deltaMaxTq = (r.Engine.TotalTorqueDemand - - r.Engine.DynamicFullLoadTorque); + var r = (IResponse)resp; + var deltaMaxTq = r.Engine.TotalTorqueDemand - r.Engine.DynamicFullLoadTorque; return (deltaMaxTq * avgEngineSpeed).Value(); }); var rqMaxTorque = RequestDryRun(absTime, dt, maxTorque, outAngularVelocity, currentGear, maxEmDriveSetting); // limiting to ICE FLD with max propulsion - delta gearbox torque var rqMaxGbxInTq = GetGearboxInTorqueLimitedVehiclePorpTorque(rqMaxTorque, emPos); - var delta1 = ( rqMaxGbxInTq - maxTorqueGbxIn) * emOffResponse.Gearbox.InputSpeed; + var delta1 = (rqMaxGbxInTq - maxTorqueGbxIn) * emOffResponse.Gearbox.InputSpeed; var delta2 = (outTorque - maxTorque) * outAngularVelocity; var delta = VectoMath.Max(delta1, delta2); - return new HybridStrategyLimitedResponse() { + return new HybridStrategyLimitedResponse { Delta = delta, DeltaEngineSpeed = maxEmDriveResponse.Engine.EngineSpeed - maxEngineSpeed, GearboxResponse = maxEmDriveResponse.Gearbox, @@ -996,7 +981,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return new HybridResultEntry { U = double.NaN, Response = null, - Setting = new HybridStrategyResponse() { + Setting = new HybridStrategyResponse { GearboxInNeutral = false, CombustionEngineOn = DataBus.EngineInfo.EngineOn, MechanicalAssistPower = ElectricMotorsOff.ToDictionary(x => x.Key, @@ -1036,7 +1021,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies ? Constants.SimulationSettings.ATGearboxDisengageWhenHaltingSpeed : Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed; var vehiclespeedBelowThreshold = DataBus.VehicleInfo.VehicleSpeed.IsSmaller(disengageSpeedThreshold); - if ((vehiclespeedBelowThreshold) && (emPos == PowertrainPosition.HybridP2 || emPos == PowertrainPosition.HybridP1)) { + if (vehiclespeedBelowThreshold && (emPos == PowertrainPosition.HybridP2 || emPos == PowertrainPosition.HybridP1)) { if (DataBus.GearboxInfo.GearboxType.AutomaticTransmission()) { var firstgear = ResponseEmOff; firstgear.Gear = GearList.First(); @@ -1047,12 +1032,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return; } } - + var nextGear = !DataBus.GearboxInfo.GearEngaged(absTime) ? new GearshiftPosition(0) - : (PreviousState.GearboxEngaged + : PreviousState.GearboxEngaged ? DataBus.GearboxInfo.Gear - : Controller.ShiftStrategy.NextGear); + : Controller.ShiftStrategy.NextGear; if (!nextGear.IsLockedGear()) { eval.Add(ResponseEmOff); @@ -1067,16 +1052,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies // return; //} var currentGear = nextGear; - var tmp = new HybridStrategyResponse() { + var tmp = new HybridStrategyResponse { CombustionEngineOn = DataBus.EngineInfo.EngineOn, // AllowICEOff(absTime), GearboxInNeutral = false, NextGear = nextGear, MechanicalAssistPower = ElectricMotorsOff }; - var firstResponse = RequestDryRun(absTime, dt, outTorque, outAngularVelocity, nextGear, tmp); + var firstResponse = RequestDryRun(absTime, dt, outTorque, outAngularVelocity, nextGear, tmp); var engineSpeedTooLow = EngineSpeedTooLow(firstResponse); - + if (GearList.HasPredecessor(nextGear) && engineSpeedTooLow && (!vehiclespeedBelowThreshold || AllowEmergencyShift)) { // engine speed would fall below idling speed - consider downshift var estimatedVelocityPostShift = VelocityDropData.Valid @@ -1105,11 +1090,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies if (tmp.CombustionEngineOn) { var firstEntry = new HybridResultEntry(); - CalcualteCosts(firstResponse, dt, firstEntry, AllowICEOff(absTime), dryRun); + CalculateCosts(firstResponse, dt, firstEntry, AllowICEOff(absTime), dryRun); var minimumShiftTimePassed = (DataBus.GearboxInfo.LastShift + ModelData.GearshiftParameters.TimeBetweenGearshifts).IsSmallerOrEqual(absTime); if (DataBus.GearboxInfo.GearEngaged(absTime) && !vehiclespeedBelowThreshold) { var reEngaged = !PreviousState.GearboxEngaged && DataBus.GearboxInfo.GearEngaged(absTime); - if (((firstEntry.IgnoreReason.EngineSpeedBelowDownshift() && !firstEntry.IgnoreReason.EngineTorqueDemandTooHigh())|| + if ((firstEntry.IgnoreReason.EngineSpeedBelowDownshift() && !firstEntry.IgnoreReason.EngineTorqueDemandTooHigh() || firstEntry.IgnoreReason.EngineSpeedTooLow()) && !reEngaged) { // ICE torque below FLD is OK as EM may regenerate and shift ICE operating point on drag line // for negative torques the shift line is vertical anyway ;-) @@ -1132,7 +1117,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } } - var deltaDragTqFirst = disengaged ? + var deltaDragTqFirst = disengaged ? (firstResponse as ResponseDryRun).DeltaDragLoadTorque : firstResponse.Engine.TotalTorqueDemand - firstResponse.Engine.DragTorque; @@ -1149,7 +1134,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies EvaluateConfigsForGear( absTime, dt, outTorque, outAngularVelocity, nextGear, AllowICEOff(absTime), eval, emPos, dryRun); } - }else if (DataBus.GearboxInfo.GearEngaged(absTime)) { + } else if (DataBus.GearboxInfo.GearEngaged(absTime)) { eval.AddRange(FindSolution(absTime, dt, outTorque, outAngularVelocity, dryRun)); } else { eval.Add(ResponseEmOff); @@ -1170,11 +1155,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return; } - var maxRecuperation = new HybridStrategyResponse() { + var maxRecuperation = new HybridStrategyResponse { CombustionEngineOn = DataBus.EngineInfo.EngineOn, // AllowICEOff(absTime), GearboxInNeutral = false, NextGear = nextGear, - MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() { + MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> { { emPos, Tuple.Create(firstResponse.ElectricMotor.AngularVelocity, VectoMath.Max(firstResponse.ElectricMotor.MaxRecuperationTorque, 0.SI<NewtonMeter>())) } } }; @@ -1192,7 +1177,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies if (deltaDragTqMaxRecuperation.IsEqual(0)) { // with max recuperation we are already at the drag curve (e.g. because search braking power was invoked before eval.Add( - new HybridResultEntry() { + new HybridResultEntry { ICEOff = !DataBus.EngineInfo.EngineOn, Gear = nextGear, Setting = maxRecuperation @@ -1200,18 +1185,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return; } - if (deltaDragTqMaxRecuperation.IsSmaller(0) && + if (deltaDragTqMaxRecuperation.IsSmaller(0) && maxRecuperationResponse.ElectricSystem.RESSPowerDemand.IsBetween(maxRecuperationResponse.ElectricSystem.MaxPowerDrag, maxRecuperationResponse.ElectricSystem.MaxPowerDrive)) { // even with full recuperation (and no braking) the operating point is below the drag curve (and the battery can handle it) - use full recuperation eval.Add( - new HybridResultEntry() { + new HybridResultEntry { ICEOff = !DataBus.EngineInfo.EngineOn, Gear = nextGear, - Setting = new HybridStrategyResponse() { + Setting = new HybridStrategyResponse { CombustionEngineOn = DataBus.EngineInfo.EngineOn, GearboxInNeutral = false, NextGear = nextGear, - MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() { + MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> { { emPos, Tuple.Create(firstResponse.ElectricMotor.AngularVelocity, firstResponse.ElectricMotor.MaxRecuperationTorque) } } } @@ -1227,7 +1212,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies getYValue: r => { var response = r as IResponse; var deltaDragLoad = disengaged - ? (response as ResponseDryRun).DeltaDragLoadTorque + ? (response as ResponseDryRun).DeltaDragLoadTorque : response.Engine.TotalTorqueDemand - response.Engine.DragTorque; if (!response.Engine.EngineOn && DataBus.GearboxInfo.GearboxType.AutomaticTransmission()) { deltaDragLoad = response.Gearbox.InputTorque; @@ -1235,11 +1220,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return deltaDragLoad; }, evaluateFunction: emTq => { - var cfg = new HybridStrategyResponse() { + var cfg = new HybridStrategyResponse { CombustionEngineOn = DataBus.EngineInfo.EngineOn, GearboxInNeutral = false, NextGear = nextGear, - MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() { + MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> { { emPos, Tuple.Create(firstResponse.ElectricMotor.AngularVelocity, emTq) } } }; @@ -1248,7 +1233,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies criterion: r => { var response = r as IResponse; var deltaDragLoad = disengaged - ? (response as ResponseDryRun).DeltaDragLoadTorque + ? (response as ResponseDryRun).DeltaDragLoadTorque : response.Engine.TotalTorqueDemand - response.Engine.DragTorque; if (!response.Engine.EngineOn && DataBus.GearboxInfo.GearboxType.AutomaticTransmission()) { deltaDragLoad = response.Gearbox.InputTorque; @@ -1258,14 +1243,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies ); if (emRecuperationTq.IsBetween( firstResponse.ElectricMotor.MaxDriveTorque ?? 0.SI<NewtonMeter>(), firstResponse.ElectricMotor.MaxRecuperationTorque ?? 0.SI<NewtonMeter>())) { - var entry = new HybridResultEntry() { + var entry = new HybridResultEntry { ICEOff = !DataBus.EngineInfo.EngineOn, Gear = nextGear, - Setting = new HybridStrategyResponse() { + Setting = new HybridStrategyResponse { CombustionEngineOn = DataBus.EngineInfo.EngineOn, GearboxInNeutral = false, NextGear = nextGear, - MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() { + MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> { { emPos, Tuple.Create(firstResponse.ElectricMotor.AngularVelocity, emRecuperationTq) } } } @@ -1275,14 +1260,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } else { if (emRecuperationTq.IsGreater(0)) { eval.Add( - new HybridResultEntry() { + new HybridResultEntry { ICEOff = !DataBus.EngineInfo.EngineOn, Gear = nextGear, - Setting = new HybridStrategyResponse() { + Setting = new HybridStrategyResponse { CombustionEngineOn = DataBus.EngineInfo.EngineOn, GearboxInNeutral = false, NextGear = nextGear, - MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() { + MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> { { emPos, Tuple.Create(firstResponse.ElectricMotor.AngularVelocity, firstResponse.ElectricMotor.MaxRecuperationTorque) } } } @@ -1329,7 +1314,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } var targetEngineSpeed = ModelData.EngineData.IdleSpeed + - 0.7 * (ModelData.EngineData.FullLoadCurves[0].NP98hSpeed); + 0.7 * ModelData.EngineData.FullLoadCurves[0].NP98hSpeed; var best = candidates.MinBy(x => VectoMath.Abs(x.Value - targetEngineSpeed)).Key; return best; } @@ -1338,11 +1323,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies { var nextGear = !DataBus.GearboxInfo.GearEngaged(absTime) ? new GearshiftPosition(0) - : (PreviousState.GearboxEngaged + : PreviousState.GearboxEngaged ? DataBus.GearboxInfo.Gear - : Controller.ShiftStrategy.NextGear); - var tmp = new HybridStrategyResponse() - { + : Controller.ShiftStrategy.NextGear; + var tmp = new HybridStrategyResponse { CombustionEngineOn = DataBus.EngineInfo.EngineOn, // AllowICEOff(absTime), GearboxInNeutral = false, NextGear = nextGear, @@ -1354,7 +1338,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies //.Gears[resp.Gearbox.Gear].ShiftPolygon //.IsBelowDownshiftCurve(resp.Engine.TorqueOutDemand, resp.Engine.EngineSpeed)) { var engineSpeed = resp.Gearbox.InputSpeed; - if (resp.Gearbox.Gear.IsLockedGear() &&GearList.HasPredecessor(resp.Gearbox.Gear) && ModelData.GearboxData + if (resp.Gearbox.Gear.IsLockedGear() && GearList.HasPredecessor(resp.Gearbox.Gear) && ModelData.GearboxData .Gears[resp.Gearbox.Gear.Gear].ShiftPolygon .IsBelowDownshiftCurve(resp.Engine.TorqueOutDemand, engineSpeed)) { // consider downshift @@ -1495,14 +1479,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return best; } - private HybridResultEntry DoSelectBestOption( + private HybridResultEntry DoSelectBestOption( List<HybridResultEntry> eval, Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, bool dryRun, GearshiftPosition currentGear) { if (eval.Count == 0) { return null; } - HybridResultEntry best = null; + HybridResultEntry best; if (DataBus.VehicleInfo.VehicleSpeed.IsSmallerOrEqual(ModelData.GearshiftParameters.StartSpeed) && DataBus.VehicleInfo.VehicleSpeed.IsSmaller(DataBus.DrivingCycleInfo.TargetSpeed, 1.KMPHtoMeterPerSecond())) { @@ -1582,15 +1566,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } } - var emEngaged = (!ElectricMotorCanPropellDuringTractionInterruption || - (DataBus.GearboxInfo.GearEngaged(absTime) && (eval.First().Response?.Gearbox.Gear.Engaged ?? true))); + var emEngaged = !ElectricMotorCanPropellDuringTractionInterruption || + DataBus.GearboxInfo.GearEngaged(absTime) && (eval.First().Response?.Gearbox.Gear.Engaged ?? true); if (DataBus.DriverInfo.DrivingAction == DrivingAction.Accelerate && emEngaged) { //var filtered = eval.Where(x => !x.IgnoreReason.InvalidEngineSpeed()).ToArray(); - var filtered = eval - .Where(x => !x.IgnoreReason.EngineSpeedTooLow() && !x.IgnoreReason.EngineSpeedTooHigh()).ToArray(); + var filtered = eval.Where(x => !x.IgnoreReason.EngineSpeedTooLow() && !x.IgnoreReason.EngineSpeedTooHigh()).ToArray(); if (filtered.Length == 0) { - filtered = eval - .Where(x => !x.IgnoreReason.EngineSpeedTooLow() && !x.IgnoreReason.EngineSpeedTooHigh()).ToArray(); + filtered = eval.Where(x => !x.IgnoreReason.EngineSpeedTooLow() && !x.IgnoreReason.EngineSpeedTooHigh()).ToArray(); } if (filtered.Length == 0) { filtered = eval.OrderBy(x => Math.Abs(GearList.Distance(currentGear, x.Gear))).ToArray(); @@ -1601,7 +1583,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } var filtered3 = filtered2 - .Where(x => !((x.IgnoreReason & HybridConfigurationIgnoreReason.BatteryBelowMinSoC) != 0)) + .Where(x => (x.IgnoreReason & HybridConfigurationIgnoreReason.BatteryBelowMinSoC) == 0) .OrderBy(x => Math.Abs(GearList.Distance(currentGear, x.Gear))).ToArray(); if (filtered3.Length == 0) { filtered3 = filtered2; @@ -1623,8 +1605,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return best; } var filtered = eval.Where(x => !x.IgnoreReason.BatteryDemandExceeded()).ToArray(); - var filtered2 = filtered - .Where(x => !x.IgnoreReason.EngineSpeedTooLow() && !x.IgnoreReason.EngineSpeedTooHigh()).ToArray(); + var filtered2 = filtered.Where(x => !x.IgnoreReason.EngineSpeedTooLow() && !x.IgnoreReason.EngineSpeedTooHigh()).ToArray(); if (filtered2.Length == 0) { filtered2 = filtered.OrderBy(x => Math.Abs(GearList.Distance(currentGear, x.Gear))).ToArray(); } @@ -1635,13 +1616,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return best; } } - return eval.FirstOrDefault(); + return eval.FirstOrDefault(); } private HybridStrategyResponse CreateResponse(HybridResultEntry best, GearshiftPosition currentGear) { - var retVal = new HybridStrategyResponse() { + var retVal = new HybridStrategyResponse { CombustionEngineOn = !best.ICEOff, GearboxInNeutral = best.Setting.GearboxInNeutral, MechanicalAssistPower = best.Setting.MechanicalAssistPower, @@ -1670,7 +1651,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies private HybridResultEntry MaxRecuperationSetting(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, bool dryRun) { - var first = new HybridStrategyResponse() { + var first = new HybridStrategyResponse { CombustionEngineOn = DataBus.EngineInfo.EngineOn, // AllowICEOff(absTime), GearboxInNeutral = false, MechanicalAssistPower = ElectricMotorsOff @@ -1679,7 +1660,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var firstResponse = RequestDryRun(absTime, dt, outTorque, outAngularVelocity, currentGear, first); var emPos = ModelData.ElectricMachinesData.First().Item1; - + var emTorque = !ElectricMotorCanPropellDuringTractionInterruption && (!firstResponse.Gearbox.Gear.Engaged || !DataBus.GearboxInfo.GearEngaged(absTime)) ? null : firstResponse.ElectricMotor.MaxRecuperationTorque; return TryConfiguration(absTime, dt, outTorque, outAngularVelocity, currentGear, emPos, Tuple.Create(firstResponse.ElectricMotor.AngularVelocity, emTorque), double.NaN, AllowICEOff(absTime), dryRun); } @@ -1688,7 +1669,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies PerSecond outAngularVelocity, bool dryRun) { var duringTractionInterruption = (PreviousState.GearshiftTriggerTstmp + ModelData.GearboxData.TractionInterruption).IsGreaterOrEqual(absTime, ModelData.GearboxData.TractionInterruption / 20); - var allowICEOff = AllowICEOff(absTime) && (DataBus.EngineInfo.EngineOn ? !duringTractionInterruption : true); //DataBus.GearboxInfo.GearEngaged(absTime); + var allowICEOff = AllowICEOff(absTime) && (!DataBus.EngineInfo.EngineOn || !duringTractionInterruption); //DataBus.GearboxInfo.GearEngaged(absTime); var emPos = ModelData.ElectricMachinesData.First().Item1; @@ -1696,8 +1677,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var gear = PreviousState.GearboxEngaged ? DataBus.GearboxInfo.Gear : Controller.ShiftStrategy.NextGear; // DataBus.GearboxInfo.Gear; - var firstGear = GearList.Predecessor(gear, (uint)gearRange.Item1); - var lastGear = GearList.Successor(gear, (uint)gearRange.Item2); + var firstGear = GearList.Predecessor(gear, gearRange.Item1); + var lastGear = GearList.Successor(gear, gearRange.Item2); var responses = new List<HybridResultEntry>(); @@ -1718,7 +1699,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } } - var tmpBest = responses.Where(x => !double.IsNaN(x.Score)).OrderBy(x => x.Score).FirstOrDefault(); + var tmpBest = responses.Where(x => !double.IsNaN(x.Score)).OrderBy(x => x.Score).FirstOrDefault(); if (allowEmergencyUpshift && tmpBest != null && !tmpBest.ICEOff) { var nextGear = GearList.Successor(gear); var emOffEntry = EvaluateConfigsForGear( @@ -1743,16 +1724,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies if (dryRun || !minimumShiftTimePassed || (absTime - DataBus.GearboxInfo.LastUpshift).IsSmaller( ModelData.GearshiftParameters.DownshiftAfterUpshiftDelay /*, 0.1*/) - || (DataBus.DriverInfo.DrivingAction == DrivingAction.Accelerate && - DataBus.VehicleInfo.VehicleSpeed.IsSmaller(5.KMPHtoMeterPerSecond()))) { + || DataBus.DriverInfo.DrivingAction == DrivingAction.Accelerate && + DataBus.VehicleInfo.VehicleSpeed.IsSmaller(5.KMPHtoMeterPerSecond())) { gearRangeDownshift = 0; } if (dryRun || !minimumShiftTimePassed || (absTime - DataBus.GearboxInfo.LastDownshift).IsSmaller( ModelData.GearshiftParameters.UpshiftAfterDownshiftDelay /*,0.1*/) - || (DataBus.DriverInfo.DrivingAction == DrivingAction.Accelerate && - DataBus.VehicleInfo.VehicleSpeed.IsSmaller(5.KMPHtoMeterPerSecond()))) { + || DataBus.DriverInfo.DrivingAction == DrivingAction.Accelerate && + DataBus.VehicleInfo.VehicleSpeed.IsSmaller(5.KMPHtoMeterPerSecond())) { gearRangeUpshift = 0; } } @@ -1772,17 +1753,17 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies if (StrategyParameters.MaxPropulsionTorque != null && ModelData.GearboxData.Type.AutomaticTransmission()) { var maxTqNextGear = StrategyParameters.MaxPropulsionTorque.FullLoadDriveTorque(emOffEntry.Response.Gearbox.InputSpeed); - if ((( emOffEntry.Response.Gearbox.InputTorque - maxTqNextGear) * emOffEntry.Response.Gearbox.InputSpeed).IsGreater(0, Constants.SimulationSettings.LineSearchTolerance)) { + if (((emOffEntry.Response.Gearbox.InputTorque - maxTqNextGear) * emOffEntry.Response.Gearbox.InputSpeed).IsGreater(0, Constants.SimulationSettings.LineSearchTolerance)) { return null; } } - CalcualteCosts(emOffEntry.Response, dt, emOffEntry, allowICEOff, dryRun); + CalculateCosts(emOffEntry.Response, dt, emOffEntry, allowICEOff, dryRun); responses.Add(emOffEntry); var emTqReq = emOffEntry.Response.ElectricMotor.TorqueRequest; // + - //emOffEntry.Response.ElectricMotor.InertiaTorque; + //emOffEntry.Response.ElectricMotor.InertiaTorque; IterateEMTorque( absTime, dt, outTorque, outAngularVelocity, nextGear, allowICEOff, emOffEntry.Response, emTqReq, emPos, responses, dryRun); @@ -1792,7 +1773,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies private HybridResultEntry GetEmOffResultEntry( Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, GearshiftPosition nextGear) { - var emOffSetting = new HybridStrategyResponse() { + var emOffSetting = new HybridStrategyResponse { CombustionEngineOn = true, GearboxInNeutral = false, MechanicalAssistPower = ElectricMotorsOff @@ -1805,7 +1786,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies - var entry = new HybridResultEntry() { + var entry = new HybridResultEntry { U = double.NaN, Response = emOffResponse, Setting = emOffSetting, @@ -1824,14 +1805,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var maxEmTorque = firstResponse.ElectricMotor.MaxDriveTorque ?? 0.SI<NewtonMeter>(); var maxU = allowIceOff ? -1.0 - : Math.Min((maxEmTorque) / emTqReq, -1.0); + : Math.Min(maxEmTorque / emTqReq, -1.0); if (DataBus.DriverInfo.DrivingAction == DrivingAction.Brake) { maxU = 0; } var voltage = DataBus.BatteryInfo.InternalVoltage; if (firstResponse.ElectricMotor.MaxDriveTorque != null && (ElectricMotorCanPropellDuringTractionInterruption || firstResponse.Gearbox.Gear.Engaged)) { - for (var u = -stepSize; u >= maxU; u -= stepSize * (u < -10 ? 100 :(u < -4 ? 10 : (u < -2 ? 5 : 1)))) { + for (var u = -stepSize; u >= maxU; u -= stepSize * (u < -10 ? 100 : u < -4 ? 10 : u < -2 ? 5 : 1)) { var emTorque = emTqReq.Abs() * u; if (!emTorque.IsBetween( 0.SI<NewtonMeter>(), firstResponse.ElectricMotor.MaxDriveTorque)) { @@ -1855,12 +1836,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var tmp = TryConfiguration(absTime, dt, outTorque, outAngularVelocity, nextGear, emPos, Tuple.Create(firstResponse.ElectricMotor.AngularVelocity, maxEmTorque), maxEmTorque / emTqReq, allowIceOff, dryRun); - if (!tmp.Response?.ElectricSystem.ConsumerPower.IsSmaller(emDrivePower)?? false) { + if (!tmp.Response?.ElectricSystem.ConsumerPower.IsSmaller(emDrivePower) ?? false) { responses.Add(tmp); } } // if battery is getting empty try to set EM-torque to discharge battery to lower SoC boundary - + if (maxEmTorque.IsSmaller(0) && (-emDrivePower).IsGreaterOrEqual(maxEmTorque * firstResponse.ElectricMotor.AngularVelocity)) { // maxEmTorque < 0 ==> EM can still propel // (-emDrivePower).IsGreaterOrEqual(maxEmTorque * firstResponse.ElectricMotor.AngularVelocity) ==> power available from battery for driving does not exceed max EM power (otherwise torque lookup may fail) @@ -1868,7 +1849,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies // .LookupTorque(emDrivePower, firstResponse.ElectricMotor.AngularVelocity, maxEmTorque); var emDriveTorque = DataBus.ElectricMotorInfo(emPos).GetTorqueForElectricPower(voltage, emDrivePower, firstResponse.ElectricMotor.AngularVelocity, dt); - var emDragTorque = ModelData.ElectricMachinesData.Where(x => x.Item1 == emPos).First().Item2 + var emDragTorque = ModelData.ElectricMachinesData.First(x => x.Item1 == emPos).Item2 .EfficiencyData.LookupDragTorque(voltage, firstResponse.ElectricMotor.AngularVelocity); if (emDriveTorque != null && emDriveTorque.IsBetween( @@ -1893,10 +1874,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return response.Engine.TorqueOutDemand; }, evaluateFunction: emTq => { - var cfg = new HybridStrategyResponse() { - CombustionEngineOn = nextGear.IsLockedGear() ? true : false, + var cfg = new HybridStrategyResponse { + CombustionEngineOn = nextGear.IsLockedGear(), GearboxInNeutral = false, - MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() { + MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> { { emPos, Tuple.Create(firstResponse.ElectricMotor.AngularVelocity, emTq) } } }; @@ -1916,7 +1897,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies allowIceOff, dryRun); responses.Add(tmp); } - } catch (Exception ) { + } catch (Exception) { Log.Debug("Failed to find EM torque to compensate drag losses of next components."); } } @@ -1932,10 +1913,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return response.Engine.TotalTorqueDemand - response.Engine.DynamicFullLoadTorque; }, evaluateFunction: emTq => { - var cfg = new HybridStrategyResponse() { - CombustionEngineOn = nextGear.IsLockedGear() ? true : false, + var cfg = new HybridStrategyResponse { + CombustionEngineOn = nextGear.IsLockedGear(), GearboxInNeutral = false, - MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() { + MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> { { emPos, Tuple.Create(firstResponse.ElectricMotor.AngularVelocity, emTq) } } }; @@ -1960,12 +1941,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } } } - + // iterate over 'EM recuperates' up to max available recuperation potential if (firstResponse.ElectricMotor.MaxRecuperationTorque != null && (ElectricMotorCanPropellDuringTractionInterruption || firstResponse.Gearbox.Gear.Engaged)) { for (var u = stepSize; u <= 1.0; u += stepSize) { var emTorque = firstResponse.ElectricMotor.MaxRecuperationTorque * u; - if (!(emTorque).IsBetween( + if (!emTorque.IsBetween( firstResponse.ElectricMotor.MaxRecuperationTorque, firstResponse.ElectricMotor.MaxDriveTorque ?? 0.SI<NewtonMeter>())) { continue; } @@ -1974,7 +1955,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies responses.Add(tmp); } var maxEmTorqueRecuperate = firstResponse.ElectricMotor.MaxRecuperationTorque ?? 0.SI<NewtonMeter>(); - + if (maxEmTorqueRecuperate.IsGreater(0) && allowIceOff && DataBus.DriverInfo.DrivingAction != DrivingAction.Brake) { if (ElectricMotorCanPropellDuringTractionInterruption) { // this means that the EM is between wheels and transmission @@ -1988,10 +1969,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return response.Engine.TorqueOutDemand; }, evaluateFunction: emTq => { - var cfg = new HybridStrategyResponse() { - CombustionEngineOn = nextGear.IsLockedGear() ? true : false, + var cfg = new HybridStrategyResponse { + CombustionEngineOn = nextGear.IsLockedGear(), GearboxInNeutral = false, - MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() { + MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> { { emPos, Tuple.Create(firstResponse.ElectricMotor.AngularVelocity, emTq) } } }; @@ -2001,7 +1982,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var response = r as IResponse; return response.Engine.TorqueOutDemand.Value(); }, - abortCriterion: (r,c) => r == null + abortCriterion: (r, c) => r == null ); if (emTorqueICEOff.IsBetween(maxEmTorqueRecuperate, 0.SI<NewtonMeter>())) { // only consider where EM is recuperating @@ -2029,27 +2010,27 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies PerSecond outAngularVelocity, GearshiftPosition nextGear, PowertrainPosition emPos, Tuple<PerSecond, NewtonMeter> emTorque, double u, bool allowIceOff, bool dryRun) { - var cfg = new HybridStrategyResponse() { + var cfg = new HybridStrategyResponse { CombustionEngineOn = true, GearboxInNeutral = false, - MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() { + MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> { { emPos, emTorque } } }; var resp = RequestDryRun(absTime, dt, outTorque, outAngularVelocity, nextGear, cfg); - + var tmp = new HybridResultEntry { U = u, Setting = cfg, Response = resp, Gear = nextGear, }; - - CalcualteCosts(resp, dt, tmp, allowIceOff, dryRun); + + CalculateCosts(resp, dt, tmp, allowIceOff, dryRun); return tmp; } - private void CalcualteCosts(IResponse resp, Second dt, HybridResultEntry tmp, bool allowIceOff, bool dryRun) + private void CalculateCosts(IResponse resp, Second dt, HybridResultEntry tmp, bool allowIceOff, bool dryRun) { tmp.IgnoreReason = 0; if (resp == null) { @@ -2098,7 +2079,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies if (resp.Gearbox.Gear.Engaged && resp.Engine.EngineSpeed.IsGreaterOrEqual( VectoMath.Min( ModelData.GearboxData.Gears[resp.Gearbox.Gear.Gear].MaxSpeed, - DataBus.EngineInfo.EngineN95hSpeed)) ) { + DataBus.EngineInfo.EngineN95hSpeed))) { tmp.FuelCosts = iceOff ? 0 : double.NaN; tmp.IgnoreReason |= HybridConfigurationIgnoreReason.EngineSpeedTooHigh; } @@ -2172,7 +2153,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } var maxSoC = Math.Min(DataBus.BatteryInfo.MaxSoC, StrategyParameters.MaxSoC); - var minSoC = Math.Max(DataBus.BatteryInfo.MinSoC , StrategyParameters.MinSoC); + var minSoC = Math.Max(DataBus.BatteryInfo.MinSoC, StrategyParameters.MinSoC); tmp.SoCPenalty = 1 - Math.Pow((DataBus.BatteryInfo.StateOfCharge - StrategyParameters.TargetSoC) / (0.5 * (maxSoC - minSoC)), StrategyParameters.CostFactorSOCExponent); var socthreshold = StrategyParameters.MinSoC + (StrategyParameters.MaxSoC - StrategyParameters.MinSoC) * 0.1; @@ -2247,16 +2228,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies tmp.IgnoreReason &= ~HybridConfigurationIgnoreReason.BatterySoCTooLow; } } - if (!double.IsNaN(tmp.BatCosts)) { - tmp.BatCosts = -(batEnergy).Value(); + if (!double.IsNaN(tmp.BatCosts)) { + tmp.BatCosts = -batEnergy.Value(); } } public virtual IHybridStrategyResponse Initialize(NewtonMeter outTorque, PerSecond outAngularVelocity) { - var retVal = new HybridStrategyResponse() - { MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() }; + var retVal = new HybridStrategyResponse { MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() }; foreach (var em in ModelData.ElectricMachinesData) { retVal.MechanicalAssistPower[em.Item1] = null; @@ -2290,10 +2270,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies PreviousState.ICEStartTStmp = time; } } - CurrentState = new StrategyState(); - CurrentState.ICEStartTStmp = PreviousState.ICEStartTStmp; - CurrentState.GearshiftTriggerTstmp = PreviousState.GearshiftTriggerTstmp; - CurrentState.ICEOn = DataBus.EngineCtl.CombustionEngineOn; + + CurrentState = new StrategyState { + ICEStartTStmp = PreviousState.ICEStartTStmp, + GearshiftTriggerTstmp = PreviousState.GearshiftTriggerTstmp, + ICEOn = DataBus.EngineCtl.CombustionEngineOn + }; AllowEmergencyShift = false; DebugData = new DebugData(); DryRunSolution = null; @@ -2302,7 +2284,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies public void WriteModalResults(Second time, Second simulationInterval, IModalDataContainer container) { - container[ModalResultField.HybridStrategyScore] = (CurrentState.Solution?.Score ?? 0)/1e3; + container[ModalResultField.HybridStrategyScore] = (CurrentState.Solution?.Score ?? 0) / 1e3; container[ModalResultField.HybridStrategySolution] = CurrentState.Solution?.U ?? -100; container[ModalResultField.MaxPropulsionTorqe] = CurrentState.MaxGbxTq ?? 0.SI<NewtonMeter>(); @@ -2327,7 +2309,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies //} } - + } } \ No newline at end of file