diff --git a/VectoCore/Models/SimulationComponent/Impl/AuxiliaryData.cs b/VectoCore/Models/SimulationComponent/Data/AuxiliaryData.cs similarity index 96% rename from VectoCore/Models/SimulationComponent/Impl/AuxiliaryData.cs rename to VectoCore/Models/SimulationComponent/Data/AuxiliaryData.cs index b615eaa8b463ef8f84e1364f61e13b877b09d606..032439971f5e6ddc824e3deb0c4839978d2fd55e 100644 --- a/VectoCore/Models/SimulationComponent/Impl/AuxiliaryData.cs +++ b/VectoCore/Models/SimulationComponent/Data/AuxiliaryData.cs @@ -1,4 +1,3 @@ -using System; using System.Data; using System.IO; using System.Linq; @@ -6,7 +5,7 @@ using System.Text; using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Utils; -namespace TUGraz.VectoCore.Models.SimulationComponent.Impl +namespace TUGraz.VectoCore.Models.SimulationComponent.Data { public class AuxiliaryData { diff --git a/VectoCore/Models/SimulationComponent/Data/IAuxiliaryDemand.cs b/VectoCore/Models/SimulationComponent/Data/IAuxiliaryDemand.cs deleted file mode 100644 index 6cdeceb213290d9c4ab6c5412c188a818227a64d..0000000000000000000000000000000000000000 --- a/VectoCore/Models/SimulationComponent/Data/IAuxiliaryDemand.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using TUGraz.VectoCore.Utils; - -namespace TUGraz.VectoCore.Models.SimulationComponent.Data -{ - /// <summary> - /// Interface for getting an power demand of an auxiliary. - /// </summary> - public interface IAuxiliaryDemand - { - /// <summary> - /// Returns the current power demand - /// </summary> - Watt GetPowerDemand(); - } -} \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Data/IAuxiliary.cs b/VectoCore/Models/SimulationComponent/IAuxiliary.cs similarity index 69% rename from VectoCore/Models/SimulationComponent/Data/IAuxiliary.cs rename to VectoCore/Models/SimulationComponent/IAuxiliary.cs index b74ce7bd6f5d584563929884095764d5279450dd..b0def57f8d98a35343e7a45127521a4ac9f869fb 100644 --- a/VectoCore/Models/SimulationComponent/Data/IAuxiliary.cs +++ b/VectoCore/Models/SimulationComponent/IAuxiliary.cs @@ -1,4 +1,4 @@ -namespace TUGraz.VectoCore.Models.SimulationComponent.Data +namespace TUGraz.VectoCore.Models.SimulationComponent { /// <summary> /// Defines interfaces for auxiliary components. diff --git a/VectoCore/Models/SimulationComponent/Impl/Auxiliary.cs b/VectoCore/Models/SimulationComponent/Impl/Auxiliary.cs index 6cbe073b3448ac90ad0fe9bd5b8156a9f62f7302..5015ce4ac6dfec79099e867320da9d7cb1dd417d 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Auxiliary.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Auxiliary.cs @@ -16,7 +16,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl private readonly Dictionary<string, Func<PerSecond, Watt>> _auxDict = new Dictionary<string, Func<PerSecond, Watt>>(); private readonly Dictionary<string, Watt> _powerDemands = new Dictionary<string, Watt>(); - private ITnOutPort _outPort; + protected ITnOutPort NextComponent; public Auxiliary(IVehicleContainer container) : base(container) {} @@ -42,7 +42,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl void ITnInPort.Connect(ITnOutPort other) { - _outPort = other; + NextComponent = other; } #endregion @@ -54,7 +54,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var currentEngineSpeed = engineSpeed ?? DataBus.EngineSpeed; var powerDemand = ComputePowerDemand(currentEngineSpeed); - return _outPort.Request(absTime, dt, torque + powerDemand / currentEngineSpeed, engineSpeed, dryRun); + return NextComponent.Request(absTime, dt, torque + powerDemand / currentEngineSpeed, engineSpeed, dryRun); } private Watt ComputePowerDemand(PerSecond engineSpeed) @@ -73,7 +73,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse Initialize(NewtonMeter torque, PerSecond engineSpeed) { var powerDemand = ComputePowerDemand(engineSpeed); - return _outPort.Initialize(torque + powerDemand / engineSpeed, engineSpeed); + return NextComponent.Initialize(torque + powerDemand / engineSpeed, engineSpeed); } #endregion diff --git a/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs b/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs index eb341a0eb6159faceb92cf62a3825107e904cab6..69f8f54db03c8ad1224a846dc97260cf811aee93 100644 --- a/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs +++ b/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs @@ -8,7 +8,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public class AxleGear : VectoSimulationComponent, IPowerTrainComponent, ITnInPort, ITnOutPort { - private ITnOutPort _nextComponent; + protected ITnOutPort NextComponent; private readonly GearData _gearData; public AxleGear(VehicleContainer container, GearData gearData) : base(container) @@ -28,7 +28,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public void Connect(ITnOutPort other) { - _nextComponent = other; + NextComponent = other; } public IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, @@ -41,7 +41,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ? 0.SI<NewtonMeter>() : _gearData.LossMap.GearboxInTorque(inAngularVelocity, outTorque); - var retVal = _nextComponent.Request(absTime, dt, inTorque, inAngularVelocity, dryRun); + var retVal = NextComponent.Request(absTime, dt, inTorque, inAngularVelocity, dryRun); retVal.AxlegearPowerRequest = outTorque * outAngularVelocity; return retVal; @@ -52,7 +52,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var inAngularVelocity = angularVelocity * _gearData.Ratio; var inTorque = _gearData.LossMap.GearboxInTorque(inAngularVelocity, torque); - return _nextComponent.Initialize(inTorque, inAngularVelocity); + return NextComponent.Initialize(inTorque, inAngularVelocity); } protected override void DoWriteModalResults(IModalDataWriter writer) diff --git a/VectoCore/Models/SimulationComponent/Impl/Brakes.cs b/VectoCore/Models/SimulationComponent/Impl/Brakes.cs index 56597f1473fa2d532a5555720f2b87f626510cc4..18154abd7867c191279ed32171848074dd0dd503 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Brakes.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Brakes.cs @@ -9,7 +9,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public class Brakes : VectoSimulationComponent, IPowerTrainComponent, ITnOutPort, ITnInPort, IBrakes { - protected ITnOutPort Next; + protected ITnOutPort NextComponent; protected NewtonMeter BreakTorque; @@ -40,7 +40,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (!dryRun && BreakPower < 0) { throw new VectoSimulationException("Negative Braking Power is not allowed!"); } - var retVal = Next.Request(absTime, dt, torque - torque.Sign() * BreakTorque, angularVelocity, dryRun); + var retVal = NextComponent.Request(absTime, dt, torque - torque.Sign() * BreakTorque, angularVelocity, dryRun); retVal.BrakePower = BreakPower; return retVal; } @@ -49,13 +49,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { BreakPower = 0.SI<Watt>(); BreakTorque = 0.SI<NewtonMeter>(); - return Next.Initialize(torque, angularVelocity); + return NextComponent.Initialize(torque, angularVelocity); } public void Connect(ITnOutPort other) { - Next = other; + NextComponent = other; } protected override void DoWriteModalResults(IModalDataWriter writer) diff --git a/VectoCore/Models/SimulationComponent/Impl/Clutch.cs b/VectoCore/Models/SimulationComponent/Impl/Clutch.cs index ad2e7801f33bbd59c6a4fd9b2886ad6345a7209a..80992b1928b310207165daea7837cb3441325161 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Clutch.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Clutch.cs @@ -13,7 +13,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { private readonly PerSecond _idleSpeed; private readonly PerSecond _ratedSpeed; - private ITnOutPort _nextComponent; + protected ITnOutPort NextComponent; private const double ClutchEff = 1; private ClutchState _clutchState = SimulationComponent.ClutchState.ClutchSlipping; @@ -56,7 +56,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity, bool dryRun = false) { if (angularVelocity == null) { - var retval = _nextComponent.Request(absTime, dt, torque, null, dryRun); + var retval = NextComponent.Request(absTime, dt, torque, null, dryRun); retval.ClutchPowerRequest = 0.SI<Watt>(); return retval; } @@ -64,7 +64,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl PerSecond engineSpeedIn; AddClutchLoss(torque, angularVelocity, out torqueIn, out engineSpeedIn); - var retVal = _nextComponent.Request(absTime, dt, torqueIn, engineSpeedIn, dryRun); + var retVal = NextComponent.Request(absTime, dt, torqueIn, engineSpeedIn, dryRun); retVal.ClutchPowerRequest = Formulas.TorqueToPower(torque, angularVelocity); return retVal; } @@ -75,13 +75,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl PerSecond engineSpeedIn; AddClutchLoss(torque, angularVelocity, out torqueIn, out engineSpeedIn); - var retVal = _nextComponent.Initialize(torqueIn, engineSpeedIn); + var retVal = NextComponent.Initialize(torqueIn, engineSpeedIn); return retVal; } public void Connect(ITnOutPort other) { - _nextComponent = other; + NextComponent = other; } private void AddClutchLoss(NewtonMeter torque, PerSecond angularVelocity, out NewtonMeter torqueIn, diff --git a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index 2785755dfd21bb8d0a046c4f0df809b788f15c63..03eaf5a861c09eaaac767c35bee34ed592d2ea61 100644 --- a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -39,20 +39,21 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <summary> /// Current state is computed in request method /// </summary> - internal EngineState _currentState = new EngineState(); + internal EngineState CurrentState = new EngineState(); - private CombustionEngineData _data; - internal EngineState _previousState = new EngineState(); + internal EngineState PreviousState = new EngineState(); + + private readonly CombustionEngineData _data; public CombustionEngine(IVehicleContainer cockpit, CombustionEngineData data) : base(cockpit) { _data = data; - _previousState.OperationMode = EngineOperationMode.Idle; - _previousState.EnginePower = 0.SI<Watt>(); - _previousState.EngineSpeed = _data.IdleSpeed; - _previousState.dt = 1.SI<Second>(); + PreviousState.OperationMode = EngineOperationMode.Idle; + PreviousState.EnginePower = 0.SI<Watt>(); + PreviousState.EngineSpeed = _data.IdleSpeed; + PreviousState.dt = 1.SI<Second>(); StationaryIdleFullLoadPower = Formulas.TorqueToPower(_data.FullLoadCurve.FullLoadStationaryTorque(_data.IdleSpeed), _data.IdleSpeed); @@ -62,7 +63,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl PerSecond IEngineInfo.EngineSpeed { - get { return _previousState.EngineSpeed; } + get { return PreviousState.EngineSpeed; } } #endregion @@ -91,7 +92,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (engineSpeed == null) { // TODO: clarify what to do if engine speed is undefined (clutch open) - engineSpeed = _previousState.EngineSpeed; + engineSpeed = PreviousState.EngineSpeed; } ComputeRequestedEnginePower(absTime, dt, torque, engineSpeed, out requestedPower, out requestedEnginePower); @@ -99,28 +100,28 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ValidatePowerDemand(requestedEnginePower); - _currentState.EnginePower = LimitEnginePower(requestedEnginePower); + CurrentState.EnginePower = LimitEnginePower(requestedEnginePower); if (dryRun) { return new ResponseDryRun { - DeltaFullLoad = (requestedEnginePower - _currentState.DynamicFullLoadPower), - DeltaDragLoad = (requestedEnginePower - _currentState.FullDragPower), + DeltaFullLoad = (requestedEnginePower - CurrentState.DynamicFullLoadPower), + DeltaDragLoad = (requestedEnginePower - CurrentState.FullDragPower), EnginePowerRequest = requestedEnginePower }; } - if (!_currentState.EnginePower.IsEqual(requestedEnginePower, Constants.SimulationSettings.EngineFLDPowerTolerance)) { - var delta = (requestedEnginePower - _currentState.EnginePower); + if (!CurrentState.EnginePower.IsEqual(requestedEnginePower, Constants.SimulationSettings.EngineFLDPowerTolerance)) { + var delta = (requestedEnginePower - CurrentState.EnginePower); return delta > 0 ? new ResponseOverload { Delta = delta, EnginePowerRequest = requestedEnginePower, Source = this } : new ResponseUnderload { Delta = delta, EnginePowerRequest = requestedEnginePower, Source = this }; } - UpdateEngineState(_currentState.EnginePower); + UpdateEngineState(CurrentState.EnginePower); // = requestedEnginePower; //todo + _currentState.EnginePowerLoss; - _currentState.EngineTorque = Formulas.PowerToTorque(_currentState.EnginePower, - _currentState.EngineSpeed); + CurrentState.EngineTorque = Formulas.PowerToTorque(CurrentState.EnginePower, + CurrentState.EngineSpeed); return new ResponseSuccess { EnginePowerRequest = requestedEnginePower }; } @@ -128,26 +129,26 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected void ComputeRequestedEnginePower(Second absTime, Second dt, NewtonMeter torque, PerSecond engineSpeed, out Watt requestedPower, out Watt requestedEnginePower) { - _currentState.dt = dt; - _currentState.EngineSpeed = engineSpeed; - _currentState.AbsTime = absTime; + CurrentState.dt = dt; + CurrentState.EngineSpeed = engineSpeed; + CurrentState.AbsTime = absTime; requestedPower = Formulas.TorqueToPower(torque, engineSpeed); - _currentState.EnginePowerLoss = InertiaPowerLoss(torque, engineSpeed); - requestedEnginePower = requestedPower + _currentState.EnginePowerLoss; + CurrentState.EnginePowerLoss = InertiaPowerLoss(torque, engineSpeed); + requestedEnginePower = requestedPower + CurrentState.EnginePowerLoss; if (engineSpeed < _data.IdleSpeed.Value() - EngineIdleSpeedStopThreshold) { - _currentState.OperationMode = EngineOperationMode.Stopped; + CurrentState.OperationMode = EngineOperationMode.Stopped; //todo: _currentState.EnginePowerLoss = enginePowerLoss; } - _currentState.FullDragTorque = _data.FullLoadCurve.DragLoadStationaryTorque(engineSpeed); - _currentState.FullDragPower = Formulas.TorqueToPower(_currentState.FullDragTorque, engineSpeed); + CurrentState.FullDragTorque = _data.FullLoadCurve.DragLoadStationaryTorque(engineSpeed); + CurrentState.FullDragPower = Formulas.TorqueToPower(CurrentState.FullDragTorque, engineSpeed); } public IResponse Initialize(NewtonMeter torque, PerSecond engineSpeed) { - _previousState = new EngineState { + PreviousState = new EngineState { EngineSpeed = engineSpeed, dt = 1.SI<Second>(), EnginePowerLoss = 0.SI<Watt>(), @@ -157,11 +158,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl EngineTorque = torque, EnginePower = Formulas.TorqueToPower(torque, engineSpeed) }; - _previousState.StationaryFullLoadPower = Formulas.TorqueToPower(_previousState.StationaryFullLoadTorque, + PreviousState.StationaryFullLoadPower = Formulas.TorqueToPower(PreviousState.StationaryFullLoadTorque, engineSpeed); - _previousState.DynamicFullLoadTorque = _previousState.StationaryFullLoadTorque; - _previousState.DynamicFullLoadPower = _previousState.StationaryFullLoadPower; - _previousState.FullDragPower = Formulas.TorqueToPower(_previousState.FullDragTorque, engineSpeed); + PreviousState.DynamicFullLoadTorque = PreviousState.StationaryFullLoadTorque; + PreviousState.DynamicFullLoadPower = PreviousState.StationaryFullLoadPower; + PreviousState.FullDragPower = Formulas.TorqueToPower(PreviousState.FullDragTorque, engineSpeed); return new ResponseSuccess(); } @@ -172,32 +173,32 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected override void DoWriteModalResults(IModalDataWriter writer) { - writer[ModalResultField.PaEng] = _currentState.EnginePowerLoss; - writer[ModalResultField.Pe_drag] = _currentState.FullDragPower; - writer[ModalResultField.Pe_full] = _currentState.DynamicFullLoadPower; - writer[ModalResultField.Pe_eng] = _currentState.EnginePower; + writer[ModalResultField.PaEng] = CurrentState.EnginePowerLoss; + writer[ModalResultField.Pe_drag] = CurrentState.FullDragPower; + writer[ModalResultField.Pe_full] = CurrentState.DynamicFullLoadPower; + writer[ModalResultField.Pe_eng] = CurrentState.EnginePower; - writer[ModalResultField.Tq_drag] = _currentState.FullDragTorque; - writer[ModalResultField.Tq_full] = _currentState.DynamicFullLoadTorque; - writer[ModalResultField.Tq_eng] = _currentState.EngineTorque; - writer[ModalResultField.n] = _currentState.EngineSpeed; + writer[ModalResultField.Tq_drag] = CurrentState.FullDragTorque; + writer[ModalResultField.Tq_full] = CurrentState.DynamicFullLoadTorque; + writer[ModalResultField.Tq_eng] = CurrentState.EngineTorque; + writer[ModalResultField.n] = CurrentState.EngineSpeed; try { writer[ModalResultField.FCMap] = - _data.ConsumptionMap.GetFuelConsumption(_currentState.EngineTorque, _currentState.EngineSpeed) + _data.ConsumptionMap.GetFuelConsumption(CurrentState.EngineTorque, CurrentState.EngineSpeed) .ConvertTo() .Gramm.Per.Hour; } catch (VectoException ex) { - Log.Warn("t: {0} - {1} n: {2} Tq: {3}", _currentState.AbsTime, ex.Message, _currentState.EngineSpeed, - _currentState.EngineTorque); + Log.Warn("t: {0} - {1} n: {2} Tq: {3}", CurrentState.AbsTime, ex.Message, CurrentState.EngineSpeed, + CurrentState.EngineTorque); writer[ModalResultField.FCMap] = double.NaN.SI(); } } protected override void DoCommitSimulationStep() { - _previousState = _currentState; - _currentState = new EngineState(); + PreviousState = CurrentState; + CurrentState = new EngineState(); } #endregion @@ -208,13 +209,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <param name="requestedEnginePower">[W]</param> protected virtual void ValidatePowerDemand(Watt requestedEnginePower) { - if (_currentState.FullDragPower >= 0 && requestedEnginePower < 0) { + if (CurrentState.FullDragPower >= 0 && requestedEnginePower < 0) { throw new VectoSimulationException("P_engine_drag > 0! n: {0} [1/min] ", - _currentState.EngineSpeed.ConvertTo().Rounds.Per.Minute); + CurrentState.EngineSpeed.ConvertTo().Rounds.Per.Minute); } - if (_currentState.DynamicFullLoadPower <= 0 && requestedEnginePower > 0) { + if (CurrentState.DynamicFullLoadPower <= 0 && requestedEnginePower > 0) { throw new VectoSimulationException("P_engine_full < 0! n: {0} [1/min] ", - _currentState.EngineSpeed.ConvertTo().Rounds.Per.Minute); + CurrentState.EngineSpeed.ConvertTo().Rounds.Per.Minute); } } @@ -223,7 +224,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// </summary> protected virtual Watt LimitEnginePower(Watt requestedEnginePower) { - return VectoMath.Limit(requestedEnginePower, _currentState.FullDragPower, _currentState.DynamicFullLoadPower); + return VectoMath.Limit(requestedEnginePower, CurrentState.FullDragPower, CurrentState.DynamicFullLoadPower); } /// <summary> @@ -233,16 +234,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected virtual void UpdateEngineState(Watt requestedEnginePower) { if (requestedEnginePower < -ZeroThreshold) { - _currentState.OperationMode = IsFullLoad(requestedEnginePower, _currentState.DynamicFullLoadPower) + CurrentState.OperationMode = IsFullLoad(requestedEnginePower, CurrentState.DynamicFullLoadPower) ? EngineOperationMode.FullLoad : EngineOperationMode.Load; } else if (requestedEnginePower > ZeroThreshold) { - _currentState.OperationMode = IsFullLoad(requestedEnginePower, _currentState.FullDragPower) + CurrentState.OperationMode = IsFullLoad(requestedEnginePower, CurrentState.FullDragPower) ? EngineOperationMode.FullDrag : EngineOperationMode.Drag; } else { // -ZeroThreshold <= requestedEnginePower <= ZeroThreshold - _currentState.OperationMode = EngineOperationMode.Idle; + CurrentState.OperationMode = EngineOperationMode.Idle; } } @@ -258,9 +259,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } //_currentState.StationaryFullLoadPower = _data.GetFullLoadCurve(gear).FullLoadStationaryPower(rpm); - _currentState.StationaryFullLoadTorque = + CurrentState.StationaryFullLoadTorque = _data.FullLoadCurve.FullLoadStationaryTorque(angularVelocity); - _currentState.StationaryFullLoadPower = Formulas.TorqueToPower(_currentState.StationaryFullLoadTorque, + CurrentState.StationaryFullLoadPower = Formulas.TorqueToPower(CurrentState.StationaryFullLoadTorque, angularVelocity); double pt1 = _data.FullLoadCurve.PT1(angularVelocity).Value(); @@ -268,19 +269,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl // var dynFullPowerCalculated = (1 / (pt1 + 1)) * // (_currentState.StationaryFullLoadPower + pt1 * _previousState.EnginePower); var tStarPrev = pt1 * - Math.Log(1 / (1 - (_previousState.EnginePower / _currentState.StationaryFullLoadPower).Value()), Math.E) + Math.Log(1 / (1 - (PreviousState.EnginePower / CurrentState.StationaryFullLoadPower).Value()), Math.E) .SI<Second>(); - var tStar = tStarPrev + _previousState.dt; - var dynFullPowerCalculated = _currentState.StationaryFullLoadPower * (1 - Math.Exp((-tStar / pt1).Value())); - _currentState.DynamicFullLoadPower = (dynFullPowerCalculated < _currentState.StationaryFullLoadPower) + var tStar = tStarPrev + PreviousState.dt; + var dynFullPowerCalculated = CurrentState.StationaryFullLoadPower * (1 - Math.Exp((-tStar / pt1).Value())); + CurrentState.DynamicFullLoadPower = (dynFullPowerCalculated < CurrentState.StationaryFullLoadPower) ? dynFullPowerCalculated - : _currentState.StationaryFullLoadPower; + : CurrentState.StationaryFullLoadPower; - if (_currentState.DynamicFullLoadPower < StationaryIdleFullLoadPower) { - _currentState.DynamicFullLoadPower = StationaryIdleFullLoadPower; + if (CurrentState.DynamicFullLoadPower < StationaryIdleFullLoadPower) { + CurrentState.DynamicFullLoadPower = StationaryIdleFullLoadPower; } - _currentState.DynamicFullLoadTorque = Formulas.PowerToTorque(_currentState.DynamicFullLoadPower, + CurrentState.DynamicFullLoadTorque = Formulas.PowerToTorque(CurrentState.DynamicFullLoadPower, angularVelocity); } @@ -298,9 +299,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <returns>[W]</returns> protected Watt InertiaPowerLoss(NewtonMeter torque, PerSecond angularVelocity) { - var deltaEngineSpeed = angularVelocity - _previousState.EngineSpeed; + var deltaEngineSpeed = angularVelocity - PreviousState.EngineSpeed; // TODO: consider simulation interval! (not simply divide by 1 Second but the current dt) - var avgEngineSpeed = (_previousState.EngineSpeed + angularVelocity) / 2.SI<Second>(); + var avgEngineSpeed = (PreviousState.EngineSpeed + angularVelocity) / 2.SI<Second>(); var result = _data.Inertia * deltaEngineSpeed * avgEngineSpeed; return result.Cast<Watt>(); @@ -421,8 +422,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected bool Equals(CombustionEngine other) { return Equals(_data, other._data) - && Equals(_previousState, other._previousState) - && Equals(_currentState, other._currentState); + && Equals(PreviousState, other.PreviousState) + && Equals(CurrentState, other.CurrentState); } public override int GetHashCode() @@ -430,8 +431,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (_data != null ? _data.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (_previousState != null ? _previousState.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (_currentState != null ? _currentState.GetHashCode() : 0); + hashCode = (hashCode * 397) ^ (PreviousState != null ? PreviousState.GetHashCode() : 0); + hashCode = (hashCode * 397) ^ (CurrentState != null ? CurrentState.GetHashCode() : 0); return hashCode; } } diff --git a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs index 4562f09a41546701597a7aa196b4de0ee781dfd0..0b5cd6b6cf57a39a15d26562ba7ca0affcecb606 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs @@ -27,7 +27,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl internal readonly DrivingCycleEnumerator CycleIntervalIterator; - private IDrivingCycleOutPort _outPort; + protected IDrivingCycleOutPort NextComponent; public DistanceBasedDrivingCycle(IVehicleContainer container, DrivingCycleData cycle) : base(container) { @@ -57,7 +57,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl void IDrivingCycleInPort.Connect(IDrivingCycleOutPort other) { - _outPort = other; + NextComponent = other; } #endregion @@ -130,7 +130,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl CurrentState.WaitTime = PreviousState.WaitTime + dt; CurrentState.Gradient = ComputeGradient(); - return _outPort.Request(absTime, dt, CycleIntervalIterator.LeftSample.VehicleTargetSpeed, CurrentState.Gradient); + return NextComponent.Request(absTime, dt, CycleIntervalIterator.LeftSample.VehicleTargetSpeed, CurrentState.Gradient); } private IResponse DriveDistance(Second absTime, Meter ds) @@ -148,7 +148,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl CurrentState.VehicleTargetSpeed = CycleIntervalIterator.LeftSample.VehicleTargetSpeed; CurrentState.Gradient = ComputeGradient(); - return _outPort.Request(absTime, ds, CurrentState.VehicleTargetSpeed, CurrentState.Gradient); + return NextComponent.Request(absTime, ds, CurrentState.VehicleTargetSpeed, CurrentState.Gradient); } private Radian ComputeGradient() @@ -185,7 +185,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl }; CurrentState = PreviousState.Clone(); //return new ResponseSuccess(); - return _outPort.Initialize(CycleIntervalIterator.LeftSample.VehicleTargetSpeed, + return NextComponent.Initialize(CycleIntervalIterator.LeftSample.VehicleTargetSpeed, CycleIntervalIterator.LeftSample.RoadGradient); } diff --git a/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 0007528895d120564b4c889f13725270501ed7ab..d10b55cbf0dfeca6746d3820ef552ab5919d5166 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -22,7 +22,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { internal DriverState CurrentState = new DriverState(); - protected IDriverDemandOutPort Next; + protected IDriverDemandOutPort NextComponent; protected DriverData DriverData; @@ -46,14 +46,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public void Connect(IDriverDemandOutPort other) { - Next = other; + NextComponent = other; } public IResponse Initialize(MeterPerSecond vehicleSpeed, Radian roadGradient) { LookaheadDeceleration = DriverData.AccelerationCurve.MinDeceleration(); - return Next.Initialize(vehicleSpeed, roadGradient); + return NextComponent.Initialize(vehicleSpeed, roadGradient); } @@ -110,7 +110,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl IResponse retVal = null; var response = previousResponse ?? - Next.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient); + NextComponent.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient); response.Switch(). Case<ResponseSuccess>(r => { @@ -136,7 +136,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Log.Debug("Found operating point for Drive/Accelerate. dt: {0}, acceleration: {1}", CurrentState.dt, CurrentState.Acceleration); - retVal = Next.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient); + retVal = NextComponent.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient); retVal.Switch(). Case<ResponseUnderload>(). Case<ResponseSuccess>(). @@ -205,7 +205,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { var operatingPoint = ComputeAcceleration(ds, DataBus.VehicleSpeed); - var response = Next.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient, true); + var response = NextComponent.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, + gradient, true); //if (response is ResponseFailTimeInterval) { // return response; @@ -238,7 +239,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return new ResponseSpeedLimitExceeded(); } - var retVal = Next.Request(absTime, CurrentState.dt, CurrentState.Acceleration, gradient); + var retVal = NextComponent.Request(absTime, CurrentState.dt, CurrentState.Acceleration, gradient); CurrentState.Response = retVal; retVal.SimulationInterval = CurrentState.dt; @@ -282,7 +283,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var response = previousResponse ?? - Next.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient); + NextComponent.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient); response.Switch(). Case<ResponseSuccess>(r => retVal = r). @@ -318,7 +319,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Log.Debug("Found operating point for breaking. dt: {0}, acceleration: {1}", operatingPoint.SimulationInterval, operatingPoint.Acceleration); - retVal = Next.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient); + retVal = NextComponent.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient); retVal.Switch(). Case<ResponseSuccess>(). @@ -398,7 +399,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl DataBus.BreakPower = breakingPower; var response = (ResponseDryRun) - Next.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient, true); + NextComponent.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient, true); delta = DataBus.ClutchClosed(absTime) ? response.DeltaDragLoad : response.GearboxPowerRequest; if (delta.IsEqual(0, Constants.SimulationSettings.EngineFLDPowerTolerance)) { @@ -508,7 +509,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl retVal.SimulationInterval = tmp.SimulationInterval; retVal.SimulationDistance = tmp.SimulationDistance; - var response = (ResponseDryRun)Next.Request(absTime, retVal.SimulationInterval, retVal.Acceleration, gradient, true); + var response = + (ResponseDryRun)NextComponent.Request(absTime, retVal.SimulationInterval, retVal.Acceleration, gradient, true); delta = actionRoll ? response.GearboxPowerRequest : (coasting ? response.DeltaDragLoad : response.DeltaFullLoad); if (delta.IsEqual(0, Constants.SimulationSettings.EngineFLDPowerTolerance)) { @@ -659,7 +661,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var oldGear = DataBus.Gear; //DataBus.Gear = 0; DataBus.BreakPower = double.PositiveInfinity.SI<Watt>(); - var retVal = Next.Request(absTime, dt, 0.SI<MeterPerSquareSecond>(), gradient); + var retVal = NextComponent.Request(absTime, dt, 0.SI<MeterPerSquareSecond>(), gradient); CurrentState.dt = dt; //DataBus.Gear = oldGear; return retVal; diff --git a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyCombustionEngine.cs b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyCombustionEngine.cs index 28878e49b3bfb7550262004a1e7677a9b21fd465..fe87710c7e6d73ac24010c372f9301ed6e695429 100644 --- a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyCombustionEngine.cs +++ b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyCombustionEngine.cs @@ -10,7 +10,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public class EngineOnlyCombustionEngine : CombustionEngine { - protected readonly List<Second> _enginePowerCorrections = new List<Second>(); + protected readonly List<Second> EnginePowerCorrections = new List<Second>(); public EngineOnlyCombustionEngine(IVehicleContainer cockpit, CombustionEngineData data) : base(cockpit, data) {} @@ -27,20 +27,20 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ValidatePowerDemand(requestedEnginePower); - _currentState.EnginePower = LimitEnginePower(requestedEnginePower); + CurrentState.EnginePower = LimitEnginePower(requestedEnginePower); if (dryRun) { return new ResponseDryRun { - DeltaFullLoad = (requestedEnginePower - _currentState.DynamicFullLoadPower), - DeltaDragLoad = (requestedEnginePower - _currentState.FullDragPower) + DeltaFullLoad = (requestedEnginePower - CurrentState.DynamicFullLoadPower), + DeltaDragLoad = (requestedEnginePower - CurrentState.FullDragPower) }; } - UpdateEngineState(_currentState.EnginePower); + UpdateEngineState(CurrentState.EnginePower); // = requestedEnginePower; //todo + _currentState.EnginePowerLoss; - _currentState.EngineTorque = Formulas.PowerToTorque(_currentState.EnginePower, - _currentState.EngineSpeed); + CurrentState.EngineTorque = Formulas.PowerToTorque(CurrentState.EnginePower, + CurrentState.EngineSpeed); return new ResponseSuccess(); } @@ -52,23 +52,23 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <returns>[W]</returns> protected override Watt LimitEnginePower(Watt requestedEnginePower) { - if (requestedEnginePower > _currentState.DynamicFullLoadPower) { - if (requestedEnginePower / _currentState.DynamicFullLoadPower > MaxPowerExceededThreshold) { - _enginePowerCorrections.Add(_currentState.AbsTime); + if (requestedEnginePower > CurrentState.DynamicFullLoadPower) { + if (requestedEnginePower / CurrentState.DynamicFullLoadPower > MaxPowerExceededThreshold) { + EnginePowerCorrections.Add(CurrentState.AbsTime); Log.Warn( "t: {0} requested power > P_engine_full * 1.05 - corrected. P_request: {1} P_engine_full: {2}", - _currentState.AbsTime, requestedEnginePower, _currentState.DynamicFullLoadPower); + CurrentState.AbsTime, requestedEnginePower, CurrentState.DynamicFullLoadPower); } - return _currentState.DynamicFullLoadPower; + return CurrentState.DynamicFullLoadPower; } - if (requestedEnginePower < _currentState.FullDragPower) { - if (requestedEnginePower / _currentState.FullDragPower > MaxPowerExceededThreshold && + if (requestedEnginePower < CurrentState.FullDragPower) { + if (requestedEnginePower / CurrentState.FullDragPower > MaxPowerExceededThreshold && requestedEnginePower > -99999) { - _enginePowerCorrections.Add(_currentState.AbsTime); + EnginePowerCorrections.Add(CurrentState.AbsTime); Log.Warn("t: {0} requested power < P_engine_drag * 1.05 - corrected. P_request: {1} P_engine_drag: {2}", - _currentState.AbsTime, requestedEnginePower, _currentState.FullDragPower); + CurrentState.AbsTime, requestedEnginePower, CurrentState.FullDragPower); } - return _currentState.FullDragPower; + return CurrentState.FullDragPower; } return requestedEnginePower; } @@ -76,7 +76,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IList<string> Warnings() { IList<string> retVal = new List<string>(); - retVal.Add(string.Format("Engine power corrected (>5%) in {0} time steps ", _enginePowerCorrections.Count)); + retVal.Add(string.Format("Engine power corrected (>5%) in {0} time steps ", EnginePowerCorrections.Count)); return retVal; } } diff --git a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyDrivingCycle.cs index 70541e4c1c1cc020cf195623e9aff6bccf8d9571..397f38c4b45351030083b315ed549640042bc0c8 100644 --- a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyDrivingCycle.cs @@ -17,7 +17,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ISimulationOutPort { protected DrivingCycleData Data; - private ITnOutPort _outPort; + protected ITnOutPort NextComponent; private IEnumerator<DrivingCycleData.DrivingCycleEntry> RightSample { get; set; } private IEnumerator<DrivingCycleData.DrivingCycleEntry> LeftSample { get; set; } @@ -66,13 +66,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return new ResponseCycleFinished(); } - return _outPort.Request(absTime, dt, Data.Entries[index].EngineTorque, Data.Entries[index].EngineSpeed); + return NextComponent.Request(absTime, dt, Data.Entries[index].EngineTorque, Data.Entries[index].EngineSpeed); } public IResponse Initialize() { var index = 0; - return _outPort.Initialize(Data.Entries[index].EngineTorque, Data.Entries[index].EngineSpeed); + return NextComponent.Initialize(Data.Entries[index].EngineTorque, Data.Entries[index].EngineSpeed); } #endregion @@ -81,7 +81,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl void ITnInPort.Connect(ITnOutPort other) { - _outPort = other; + NextComponent = other; } #endregion diff --git a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs index f23e0b48599829bc161fc926281873c4fe249a88..9a565c4e1704060da713f66cde98608acfd8ccd5 100644 --- a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs +++ b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs @@ -10,7 +10,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public class EngineOnlyGearbox : VectoSimulationComponent, IGearbox, ITnInPort, ITnOutPort { - private ITnOutPort _outPort; + protected ITnOutPort NextComponent; public EngineOnlyGearbox(IVehicleContainer cockpit) : base(cockpit) {} #region ITnInProvider @@ -45,7 +45,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl void ITnInPort.Connect(ITnOutPort other) { - _outPort = other; + NextComponent = other; } #endregion @@ -54,16 +54,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl IResponse ITnOutPort.Request(Second absTime, Second dt, NewtonMeter torque, PerSecond engineSpeed, bool dryRun) { - if (_outPort == null) { + if (NextComponent == null) { Log.Error("Ccannot handle incoming request - no outport available. absTime: {0}, dt: {1}", absTime, dt); throw new VectoSimulationException("Cannot handle incoming request - no outport available."); } - return _outPort.Request(absTime, dt, torque, engineSpeed, dryRun); + return NextComponent.Request(absTime, dt, torque, engineSpeed, dryRun); } public IResponse Initialize(NewtonMeter torque, PerSecond engineSpeed) { - return _outPort.Initialize(torque, engineSpeed); + return NextComponent.Initialize(torque, engineSpeed); } #endregion diff --git a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index ead72ac5a868831d809829a91d27ee1f5dbd1219..bff9d6c25964074f665f37bac7bf90a396465afb 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -18,7 +18,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <summary> /// The next port. /// </summary> - protected ITnOutPort Next; + protected ITnOutPort NextComponent; /// <summary> /// The data and settings for the gearbox. @@ -138,7 +138,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } Log.Debug("Current Gear: Neutral"); - var neutralResponse = Next.Request(absTime, dt, 0.SI<NewtonMeter>(), null); + var neutralResponse = NextComponent.Request(absTime, dt, 0.SI<NewtonMeter>(), null); neutralResponse.GearboxPowerRequest = outTorque * outEngineSpeed; return neutralResponse; @@ -176,7 +176,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Log.Debug("Current Gear: {0}", Gear); _powerLoss = inTorque * inEngineSpeed - outTorque * outEngineSpeed; - var response = Next.Request(absTime, dt, inTorque, inEngineSpeed, dryRun); + var response = NextComponent.Request(absTime, dt, inTorque, inEngineSpeed, dryRun); response.GearboxPowerRequest = outTorque * outEngineSpeed; return response; } @@ -270,7 +270,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _shiftTime = double.NegativeInfinity.SI<Second>(); Gear = FindGear(torque, engineSpeed, true); - return Next.Initialize(torque, engineSpeed); + return NextComponent.Initialize(torque, engineSpeed); } #endregion @@ -279,7 +279,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl void ITnInPort.Connect(ITnOutPort other) { - Next = other; + NextComponent = other; } #endregion diff --git a/VectoCore/Models/SimulationComponent/Impl/Retarder.cs b/VectoCore/Models/SimulationComponent/Impl/Retarder.cs index 4c91866e84dd79239046727a884ee3e0f006ad5b..232fb6aba42577f0959080fb05f4518ba9ee7ff7 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Retarder.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Retarder.cs @@ -9,7 +9,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public class Retarder : VectoSimulationComponent, IPowerTrainComponent, ITnInPort, ITnOutPort { - private ITnOutPort _nextComponent; + protected ITnOutPort NextComponent; private readonly RetarderLossMap _lossMap; @@ -40,7 +40,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public void Connect(ITnOutPort other) { - _nextComponent = other; + NextComponent = other; } public IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity, bool dryRun = false) @@ -48,13 +48,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var retarderTorqueLoss = _lossMap.RetarderLoss(angularVelocity); _retarderLoss = retarderTorqueLoss * angularVelocity; - return _nextComponent.Request(absTime, dt, torque + retarderTorqueLoss, angularVelocity, dryRun); + return NextComponent.Request(absTime, dt, torque + retarderTorqueLoss, angularVelocity, dryRun); } public IResponse Initialize(NewtonMeter torque, PerSecond angularVelocity) { var retarderTorqueLoss = _lossMap.RetarderLoss(angularVelocity); - return _nextComponent.Initialize(torque + retarderTorqueLoss, angularVelocity); + return NextComponent.Initialize(torque + retarderTorqueLoss, angularVelocity); } } } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs index 0a97dbc49b5744b17ce9d1b8f22128710061e206..1fa19a646fc91702baac7fd713e4862de02c5c14 100644 --- a/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs @@ -16,7 +16,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ISimulationOutPort { protected DrivingCycleData Data; - private IDrivingCycleOutPort _outPort; + protected IDrivingCycleOutPort NextComponent; public TimeBasedDrivingCycle(IVehicleContainer container, DrivingCycleData cycle) : base(container) { @@ -58,7 +58,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl // TODO!! var dx = 0.SI<Meter>(); - return _outPort.Request(absTime, dt, Data.Entries[index].VehicleTargetSpeed, + return NextComponent.Request(absTime, dt, Data.Entries[index].VehicleTargetSpeed, Data.Entries[index].RoadGradient); } @@ -77,7 +77,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Connect(IDrivingCycleOutPort other) { - _outPort = other; + NextComponent = other; } #endregion diff --git a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs index d5ea228d96a2e7b928fa635129f1aa213c215d69..e1d292d7ffb1f46779a1db64834019068a5c75e9 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs @@ -13,7 +13,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public class Vehicle : VectoSimulationComponent, IVehicle, IMileageCounter, IFvInPort, IDriverDemandOutPort { - private IFvOutPort _nextInstance; + protected IFvOutPort NextComponent; private VehicleState _previousState; private VehicleState _currentState; private readonly VehicleData _data; @@ -68,7 +68,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public void Connect(IFvOutPort other) { - _nextInstance = other; + NextComponent = other; } public IResponse Initialize(MeterPerSecond vehicleSpeed, Radian roadGradient) @@ -77,7 +77,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _currentState = new VehicleState { Distance = 0.SI<Meter>(), Velocity = vehicleSpeed }; var vehicleAccelerationForce = RollingResistance(roadGradient) + AirDragResistance() + SlopeResistance(roadGradient); - return _nextInstance.Initialize(vehicleAccelerationForce, vehicleSpeed); + return NextComponent.Initialize(vehicleAccelerationForce, vehicleSpeed); } public IResponse Request(Second absTime, Second dt, MeterPerSquareSecond accelleration, Radian gradient, @@ -94,7 +94,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl + AirDragResistance() + SlopeResistance(gradient); - var retval = _nextInstance.Request(absTime, dt, vehicleAccelerationForce, _currentState.Velocity, dryRun); + var retval = NextComponent.Request(absTime, dt, vehicleAccelerationForce, _currentState.Velocity, dryRun); return retval; } diff --git a/VectoCore/Models/SimulationComponent/Impl/Wheels.cs b/VectoCore/Models/SimulationComponent/Impl/Wheels.cs index 42d24687ec9e15f064a3cf1f24409fd7b60cd9ac..928e35c04dea8088fd49680a2ae725656749c9e8 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Wheels.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Wheels.cs @@ -8,7 +8,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public class Wheels : VectoSimulationComponent, IWheels, IFvOutPort, ITnInPort { - private ITnOutPort _outPort; + protected ITnOutPort NextComponent; private readonly Meter _dynamicWheelRadius; public Wheels(IVehicleContainer cockpit, Meter rdyn) @@ -42,7 +42,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Log.Debug("request: force: {0}, velocity: {1}", force, velocity); var torque = force * _dynamicWheelRadius; var angularVelocity = velocity / _dynamicWheelRadius; - var retVal = _outPort.Request(absTime, dt, torque, angularVelocity, dryRun); + var retVal = NextComponent.Request(absTime, dt, torque, angularVelocity, dryRun); retVal.WheelsPowerRequest = torque * angularVelocity; return retVal; } @@ -52,7 +52,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var torque = force * _dynamicWheelRadius; var angularVelocity = velocity / _dynamicWheelRadius; - return _outPort.Initialize(torque, angularVelocity); + return NextComponent.Initialize(torque, angularVelocity); } #endregion @@ -61,7 +61,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl void ITnInPort.Connect(ITnOutPort other) { - _outPort = other; + NextComponent = other; } #endregion diff --git a/VectoCore/VectoCore.csproj b/VectoCore/VectoCore.csproj index afbae69158ff7a4e655bf599ff267055af58072a..d3cb894c722f228bcb52ba3c6dc25ea11762270c 100644 --- a/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore.csproj @@ -140,6 +140,7 @@ <Compile Include="Models\Declaration\VehicleClass.cs" /> <Compile Include="Models\Declaration\Wheels.cs" /> <Compile Include="Models\Declaration\WHTCCorrection.cs" /> + <Compile Include="Models\SimulationComponent\Data\AuxiliaryData.cs" /> <Compile Include="Models\SimulationComponent\Data\AuxSupplyPowerReader.cs" /> <Compile Include="Models\SimulationComponent\Data\CycleData.cs" /> <Compile Include="Models\SimulationComponent\Data\AccelerationCurve.cs" /> @@ -152,11 +153,11 @@ <Compile Include="Models\SimulationComponent\Data\Engine\PT1Curve.cs" /> <Compile Include="Models\LoggingObject.cs" /> <Compile Include="Models\SimulationComponent\Data\GearboxType.cs" /> + <Compile Include="Models\SimulationComponent\IAuxiliary.cs" /> <Compile Include="Models\SimulationComponent\IBrakes.cs" /> <Compile Include="Models\SimulationComponent\IDriverActions.cs" /> <Compile Include="Models\SimulationComponent\IDriverStrategy.cs" /> <Compile Include="Models\SimulationComponent\IDrivingCycleInfo.cs" /> - <Compile Include="Models\SimulationComponent\Impl\AuxiliaryData.cs" /> <Compile Include="Models\SimulationComponent\Impl\Brakes.cs" /> <Compile Include="Models\SimulationComponent\Impl\DefaultDriverStrategy.cs" /> <Compile Include="Models\SimulationComponent\Impl\EngineOnlyCombustionEngine.cs" /> @@ -179,7 +180,6 @@ <Compile Include="Models\SimulationComponent\Data\CrossWindCorrectionMode.cs" /> <Compile Include="Models\SimulationComponent\Data\DrivingCycleData.cs" /> <Compile Include="Models\SimulationComponent\Data\Engine\FuelConsumptionMap.cs" /> - <Compile Include="Models\SimulationComponent\Data\IAuxiliaryDemand.cs" /> <Compile Include="Models\SimulationComponent\Data\Engine\EngineFullLoadCurve.cs" /> <Compile Include="Models\SimulationComponent\Data\GearboxData.cs" /> <Compile Include="Models\SimulationComponent\Data\Gearbox\GearData.cs" /> @@ -211,7 +211,6 @@ <Compile Include="Utils\Physics.cs" /> <Compile Include="Utils\SI.cs" /> <Compile Include="Models\SimulationComponent\Data\SimulationComponentData.cs" /> - <Compile Include="Models\SimulationComponent\Data\IAuxiliary.cs" /> <Compile Include="Models\SimulationComponent\ICombustionEngine.cs" /> <Compile Include="Models\SimulationComponent\IGearbox.cs" /> <Compile Include="Models\Connector\Ports\ISimulationPort.cs" /> diff --git a/VectoCoreTest/Integration/SimulationRuns/MinimalPowertrain.cs b/VectoCoreTest/Integration/SimulationRuns/MinimalPowertrain.cs index ebb486cf862103dee09452d00462e3457035dff3..b36226bf33b5dddfc508c8964b240ea13e9a720b 100644 --- a/VectoCoreTest/Integration/SimulationRuns/MinimalPowertrain.cs +++ b/VectoCoreTest/Integration/SimulationRuns/MinimalPowertrain.cs @@ -74,10 +74,10 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns // 1.5 , 5 , 18 , 18 , 0 , 2.842372 , 964.1117 , 323.7562 , 323.7562 , 2208.664 , -158.0261 , 32.68693 , 222.9902 , -15.95456 , 32.68693 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 5.965827 , 0.2423075 , 26.47879 , 32.68693 , 0 , 7574.113 , - , - AssertHelper.AreRelativeEqual(964.1117.RPMtoRad().Value(), vehicleContainer.Engine.EngineSpeed.Value()); - Assert.AreEqual(2208.664, engine._previousState.StationaryFullLoadTorque.Value(), Tolerance); - Assert.AreEqual(-158.0261, engine._previousState.FullDragTorque.Value(), Tolerance); + Assert.AreEqual(2208.664, engine.PreviousState.StationaryFullLoadTorque.Value(), Tolerance); + Assert.AreEqual(-158.0261, engine.PreviousState.FullDragTorque.Value(), Tolerance); - Assert.AreEqual(323.7562, engine._previousState.EngineTorque.Value(), Tolerance); + Assert.AreEqual(323.7562, engine.PreviousState.EngineTorque.Value(), Tolerance); } diff --git a/VectoCoreTest/Models/Simulation/AuxTests.cs b/VectoCoreTest/Models/Simulation/AuxTests.cs index a27a629e4e13390929d0ab47091ed590d50fe21c..d9cd836bd5b68fb228ef4cb7cd6beed342cf576e 100644 --- a/VectoCoreTest/Models/Simulation/AuxTests.cs +++ b/VectoCoreTest/Models/Simulation/AuxTests.cs @@ -8,6 +8,7 @@ using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.Impl; using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.FileIO; +using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Impl; namespace TUGraz.VectoCore.Tests.Models.Simulation diff --git a/VectoCoreTest/Models/SimulationComponent/DriverTest.cs b/VectoCoreTest/Models/SimulationComponent/DriverTest.cs index e73eab768d8347dccad747463c88b5424d2e7c06..9e295dfacb071071257c2cfe5f3cb0446d6955c6 100644 --- a/VectoCoreTest/Models/SimulationComponent/DriverTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/DriverTest.cs @@ -72,7 +72,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent Assert.AreEqual(4.9812, vehicleContainer.VehicleSpeed.Value(), Tolerance); Assert.AreEqual(0.2004, response.SimulationInterval.Value(), Tolerance); - Assert.AreEqual(engine._previousState.FullDragPower.Value(), engine._previousState.EnginePower.Value(), + Assert.AreEqual(engine.PreviousState.FullDragPower.Value(), engine.PreviousState.EnginePower.Value(), Constants.SimulationSettings.EngineFLDPowerTolerance); while (vehicleContainer.VehicleSpeed > 1) { @@ -129,7 +129,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent Assert.AreEqual(4.9812, vehicleContainer.VehicleSpeed.Value(), Tolerance); Assert.AreEqual(0.2004, response.SimulationInterval.Value(), Tolerance); - Assert.AreEqual(engine._previousState.FullDragPower.Value(), engine._previousState.EnginePower.Value(), + Assert.AreEqual(engine.PreviousState.FullDragPower.Value(), engine.PreviousState.EnginePower.Value(), Constants.SimulationSettings.EngineFLDPowerTolerance); while (vehicleContainer.VehicleSpeed > 1) {