diff --git a/VectoCore/Configuration/Constants.cs b/VectoCore/Configuration/Constants.cs index 748c1a022e34a9d6d9c7c6ec802b07874d018b86..0b6ece8226aa1e1f30eb2bb9c2357e9082ee366d 100644 --- a/VectoCore/Configuration/Constants.cs +++ b/VectoCore/Configuration/Constants.cs @@ -1,4 +1,6 @@ -namespace TUGraz.VectoCore.Configuration +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Configuration { public class Constants { @@ -14,5 +16,20 @@ public const string CycleFile = ".vdri"; } + + public class SimulationSettings + { + /// <summary> + /// base time interval for the simulation. the distance is estimated to reach this time interval as good as possible + /// </summary> + public static readonly Second TargetTimeInterval = 0.5.SI<Second>(); + + /// <summary> + /// simulation interval if the vehicle stands still + /// </summary> + public static readonly Meter DriveOffDistance = 1.SI<Meter>(); + + public const double DrivingCycleRoadGradientTolerance = 0.25; + } } } \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IDriverDemandPort.cs b/VectoCore/Models/Connector/Ports/IDriverDemandPort.cs index b196964bdfa832a45964f919671a2a5976ccfb96..5468b6fb1aa417076ea85b6e1d7e12358ab491f5 100644 --- a/VectoCore/Models/Connector/Ports/IDriverDemandPort.cs +++ b/VectoCore/Models/Connector/Ports/IDriverDemandPort.cs @@ -3,6 +3,33 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Connector.Ports { + /// <summary> + /// Defines a method to acquire an DriverDemand in port. + /// </summary> + public interface IDriverDemandInProvider + { + /// <summary> + /// Returns the inport to connect it to another outport. + /// </summary> + /// <returns></returns> + IDriverDemandInPort InPort(); + } + + /// <summary> + /// Defines a method to acquire an DriverDemand out port. + /// </summary> + public interface IDriverDemandOutProvider + { + /// <summary> + /// Returns the outport to send requests to. + /// </summary> + /// <returns></returns> + IDriverDemandOutPort OutPort(); + } + + //=============================================== + + /// <summary> /// Defines a connect method to connect the inport to an outport. /// </summary> @@ -24,8 +51,8 @@ namespace TUGraz.VectoCore.Models.Connector.Ports /// </summary> /// <param name="absTime">[s]</param> /// <param name="dt">[s]</param> - /// <param name="accelleration">[m/s^2]</param> + /// <param name="acceleration">[m/s^2]</param> /// <param name="gradient">[rad]</param> - IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSquareSecond accelleration, Radian gradient); + IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSquareSecond acceleration, Radian gradient); } } \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IDriverDemandProvider.cs b/VectoCore/Models/Connector/Ports/IDriverDemandProvider.cs deleted file mode 100644 index bce021607fd92a0e1aa9267e9b075f4b33b27db4..0000000000000000000000000000000000000000 --- a/VectoCore/Models/Connector/Ports/IDriverDemandProvider.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace TUGraz.VectoCore.Models.Connector.Ports -{ - /// <summary> - /// Defines a method to acquire an DriverDemand in port. - /// </summary> - public interface IDriverDemandInProvider - { - /// <summary> - /// Returns the inport to connect it to another outport. - /// </summary> - /// <returns></returns> - IDriverDemandInPort InShaft(); - } - - /// <summary> - /// Defines a method to acquire an DriverDemand out port. - /// </summary> - public interface IDriverDemandOutProvider - { - /// <summary> - /// Returns the outport to send requests to. - /// </summary> - /// <returns></returns> - IDriverDemandOutPort OutShaft(); - } -} \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IDrivingCycleDemandPort.cs b/VectoCore/Models/Connector/Ports/IDrivingCycleDemandPort.cs deleted file mode 100644 index 815fd145a1e52493a9c2ce54a2c1581417c6fac4..0000000000000000000000000000000000000000 --- a/VectoCore/Models/Connector/Ports/IDrivingCycleDemandPort.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using TUGraz.VectoCore.Utils; - -namespace TUGraz.VectoCore.Models.Connector.Ports -{ - /// <summary> - /// Defines a connect method to connect the inport to an outport. - /// </summary> - public interface IDrivingCycleDemandInPort - { - /// <summary> - /// Connects the inport to another outport. - /// </summary> - void Connect(IDrivingCycleDemandOutPort other); - } - - /// <summary> - /// Defines a request method for a DriverDemand-Out-Port. - /// </summary> - public interface IDrivingCycleDemandOutPort - { - /// <summary> - /// Requests the Outport with the given velocity [m/s] and road gradient [rad]. - /// </summary> - /// <param name="absTime">[s]</param> - /// <param name="dt">[s]</param> - /// <param name="velocity">[m/s]</param> - /// <param name="gradient">[rad]</param> - IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond velocity, Radian gradient); - } -} \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IDrivingCycleDemandProvider.cs b/VectoCore/Models/Connector/Ports/IDrivingCycleDemandProvider.cs deleted file mode 100644 index c33b4f8d4d637e77f2d13c6aec57197557954e40..0000000000000000000000000000000000000000 --- a/VectoCore/Models/Connector/Ports/IDrivingCycleDemandProvider.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace TUGraz.VectoCore.Models.Connector.Ports -{ - /// <summary> - /// Defines a method to acquire an DriverDemand in port. - /// </summary> - public interface IDrivingCycleDemandInProvider - { - /// <summary> - /// Returns the inport to connect it to another outport. - /// </summary> - /// <returns></returns> - IDrivingCycleDemandInPort InShaft(); - } - - /// <summary> - /// Defines a method to acquire an DriverDemand out port. - /// </summary> - public interface IDrivingCycleDemandOutProvider - { - /// <summary> - /// Returns the outport to send requests to. - /// </summary> - /// <returns></returns> - IDrivingCycleDemandOutPort OutShaft(); - } -} \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IDrivingCyclePort.cs b/VectoCore/Models/Connector/Ports/IDrivingCyclePort.cs index 549e9edb457335ef13ef1e4118f00c6e301a59bd..ab4f7669e93b6d37e64b09963cb8b57aaa39ba18 100644 --- a/VectoCore/Models/Connector/Ports/IDrivingCyclePort.cs +++ b/VectoCore/Models/Connector/Ports/IDrivingCyclePort.cs @@ -1,18 +1,69 @@ -using System; +using System; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Connector.Ports { /// <summary> - /// Defines a method to request the outport. + /// Defines a method to acquire an DriverDemand in port. + /// </summary> + public interface IDrivingCycleInProvider + { + /// <summary> + /// Returns the inport to connect it to another outport. + /// </summary> + /// <returns></returns> + IDrivingCycleInPort InPort(); + } + + /// <summary> + /// Defines a method to acquire an DriverDemand out port. + /// </summary> + public interface IDrivingCycleOutProvider + { + /// <summary> + /// Returns the outport to send requests to. + /// </summary> + /// <returns></returns> + IDrivingCycleOutPort OutPort(); + } + + + //============================================================= + + + /// <summary> + /// Defines a connect method to connect the inport to an outport. + /// </summary> + public interface IDrivingCycleInPort + { + /// <summary> + /// Connects the inport to another outport. + /// </summary> + void Connect(IDrivingCycleOutPort other); + } + + /// <summary> + /// Defines a request method for a DriverDemand-Out-Port. /// </summary> public interface IDrivingCycleOutPort { /// <summary> - /// Requests a demand for a specific absolute time and a time interval dt. + /// Requests the Outport with the given velocity [m/s] and road gradient [rad]. + /// </summary> + /// <param name="absTime">[s]</param> + /// <param name="ds"></param> + /// <param name="targetVelocity">[m/s]</param> + /// <param name="gradient">[rad]</param> + IResponse Request(TimeSpan absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient); + + /// <summary> + /// Requests the outport to simulate the given time interval /// </summary> - /// <param name="absTime">The absolute time of the simulation.</param> - /// <param name="dt">The current time interval.</param> + /// <param name="absTime"></param> + /// <param name="dt"></param> + /// <param name="targetVelocity"></param> + /// <param name="gradient"></param> /// <returns></returns> - IResponse Request(TimeSpan absTime, TimeSpan dt); + IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond targetVelocity, Radian gradient); } } \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IDrivingCycleProvider.cs b/VectoCore/Models/Connector/Ports/IDrivingCycleProvider.cs deleted file mode 100644 index 624b3953b626dfb320bea1028182f31816b8ab9f..0000000000000000000000000000000000000000 --- a/VectoCore/Models/Connector/Ports/IDrivingCycleProvider.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace TUGraz.VectoCore.Models.Connector.Ports -{ - /// <summary> - /// Defines a method to acquire an DriverCycle Demand out port. - /// </summary> - public interface IDrivingCycleOutProvider - { - /// <summary> - /// Returns the outport to send requests to. - /// </summary> - /// <returns></returns> - IDrivingCycleOutPort OutShaft(); - } -} \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IFvPort.cs b/VectoCore/Models/Connector/Ports/IFvPort.cs index ac85d7d342244d4323b53d534f88cede4c20acf3..70f633b5767a9f3339713534f6c8e35c9b273192 100644 --- a/VectoCore/Models/Connector/Ports/IFvPort.cs +++ b/VectoCore/Models/Connector/Ports/IFvPort.cs @@ -3,6 +3,33 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Connector.Ports { + /// <summary> + /// Defines a method to acquire an Fv in port. + /// </summary> + public interface IFvInProvider + { + /// <summary> + /// Returns the inport to connect it to another outport. + /// </summary> + /// <returns></returns> + IFvInPort InPort(); + } + + /// <summary> + /// Defines a method to acquire an Fv out port. + /// </summary> + public interface IFvOutProvider + { + /// <summary> + /// Returns the outport to send requests to. + /// </summary> + /// <returns></returns> + IFvOutPort OutPort(); + } + + // ================================================== + + /// <summary> /// Defines a connect method to connect the inport to an outport. /// </summary> diff --git a/VectoCore/Models/Connector/Ports/IResponse.cs b/VectoCore/Models/Connector/Ports/IResponse.cs index a1d76d8ca1619ea5c0725ce6c27698152213fd95..0faf538ddcc9e5a5641ad45a50fdce66d860abff 100644 --- a/VectoCore/Models/Connector/Ports/IResponse.cs +++ b/VectoCore/Models/Connector/Ports/IResponse.cs @@ -1,7 +1,13 @@ +using System; +using System.Security.Cryptography.X509Certificates; + namespace TUGraz.VectoCore.Models.Connector.Ports { - /// <summary> - /// Defines an interface for a Response. - /// </summary> - public interface IResponse {} + /// <summary> + /// Defines an interface for a Response. + /// </summary> + public interface IResponse + { + TimeSpan SimulationInterval { get; set; } + } } \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IRoadPortProvider.cs b/VectoCore/Models/Connector/Ports/IRoadPortProvider.cs deleted file mode 100644 index 7bc3047afbcafe7f7a2bbd7ad51694e1a2d1138d..0000000000000000000000000000000000000000 --- a/VectoCore/Models/Connector/Ports/IRoadPortProvider.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace TUGraz.VectoCore.Models.Connector.Ports -{ - /// <summary> - /// Defines a method to acquire an Fv in port. - /// </summary> - public interface IRoadPortInProvider - { - /// <summary> - /// Returns the inport to connect it to another outport. - /// </summary> - /// <returns></returns> - IFvInPort InPort(); - } - - /// <summary> - /// Defines a method to acquire an Fv out port. - /// </summary> - public interface IRoadPortOutProvider - { - /// <summary> - /// Returns the outport to send requests to. - /// </summary> - /// <returns></returns> - IFvOutPort OutPort(); - } -} \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IShaft.cs b/VectoCore/Models/Connector/Ports/IShaft.cs deleted file mode 100644 index 46a672e1db6fff6f7ec597171992c2cee681aa7b..0000000000000000000000000000000000000000 --- a/VectoCore/Models/Connector/Ports/IShaft.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace TUGraz.VectoCore.Models.Connector.Ports -{ - /// <summary> - /// Defines a method to acquire an Tn in port. - /// </summary> - public interface IInShaft - { - /// <summary> - /// Returns the inport to connect it to another outport. - /// </summary> - /// <returns></returns> - ITnInPort InShaft(); - } - - /// <summary> - /// Defines a method to acquire an Tn out port. - /// </summary> - public interface IOutShaft - { - /// <summary> - /// Returns the outport to send requests to. - /// </summary> - /// <returns></returns> - ITnOutPort OutShaft(); - } -} \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/ISimulationPort.cs b/VectoCore/Models/Connector/Ports/ISimulationPort.cs new file mode 100644 index 0000000000000000000000000000000000000000..1e58ab5011cfaff2a4a24b72278a9b6886f9d23b --- /dev/null +++ b/VectoCore/Models/Connector/Ports/ISimulationPort.cs @@ -0,0 +1,37 @@ +using System; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Models.Connector.Ports +{ + /// <summary> + /// Defines a method to acquire an DriverCycle Demand out port. + /// </summary> + public interface ISimulationOutProvider + { + /// <summary> + /// Returns the outport to send requests to. + /// </summary> + /// <returns></returns> + ISimulationOutPort OutPort(); + } + + //======================================================================== + + /// <summary> + /// Defines a method to request the outport. + /// </summary> + public interface ISimulationOutPort + { + /// <summary> + /// Requests a demand for a specific absolute time and a time interval dt. + /// </summary> + /// <param name="absTime">The absolute time of the simulation.</param> + /// <param name="ds"></param> + /// <returns></returns> + IResponse Request(TimeSpan absTime, Meter ds); + + IResponse Request(TimeSpan absTime, TimeSpan dt); + + IResponse Initialize(); + } +} \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/ITnOutPort.cs b/VectoCore/Models/Connector/Ports/ITnOutPort.cs deleted file mode 100644 index 66c250afedefd66af7f872b0a0f67ebe1c419590..0000000000000000000000000000000000000000 --- a/VectoCore/Models/Connector/Ports/ITnOutPort.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using TUGraz.VectoCore.Utils; - -namespace TUGraz.VectoCore.Models.Connector.Ports -{ - public interface ITnOutPort : ITnPort, IOutPort - { - /// <summary> - /// Requests the Outport with the given torque [Nm] and angularVelocity [rad/s]. - /// </summary> - /// <param name="absTime">[s]</param> - /// <param name="dt">[s]</param> - /// <param name="torque">[Nm]</param> - /// <param name="angularVelocity">[rad/s]</param> - IResponse Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond angularVelocity); - } -} \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/ITnPort.cs b/VectoCore/Models/Connector/Ports/ITnPort.cs index 9c8d4d8e1a5ff1f8ede02549ba285b0c440ad328..5ee9f5deeb2c4080d8509777f0f80afa4fc2bdc2 100644 --- a/VectoCore/Models/Connector/Ports/ITnPort.cs +++ b/VectoCore/Models/Connector/Ports/ITnPort.cs @@ -3,6 +3,34 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Connector.Ports { + /// <summary> + /// Defines a method to acquire an Tn in port. + /// </summary> + public interface ITnInProvider + { + /// <summary> + /// Returns the inport to connect it to another outport. + /// </summary> + /// <returns></returns> + ITnInPort InPort(); + } + + /// <summary> + /// Defines a method to acquire an Tn out port. + /// </summary> + public interface ITnOutProvider + { + /// <summary> + /// Returns the outport to send requests to. + /// </summary> + /// <returns></returns> + ITnOutPort OutPort(); + } + + + //======================================================================== + + /// <summary> /// Defines a connect method to connect the inport to an outport. /// </summary> diff --git a/VectoCore/Models/Connector/Ports/Impl/Response.cs b/VectoCore/Models/Connector/Ports/Impl/Response.cs index 4931c543c7bb2ddd2235b29988e8729092ed082e..a95af729576062be7e1f61f5b8262edd4e356fcf 100644 --- a/VectoCore/Models/Connector/Ports/Impl/Response.cs +++ b/VectoCore/Models/Connector/Ports/Impl/Response.cs @@ -1,21 +1,27 @@ using System; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Connector.Ports.Impl { + public abstract class AbstractResponse : IResponse + { + public TimeSpan SimulationInterval { get; set; } + } + /// <summary> /// Response when the Cycle is finished. /// </summary> - public class ResponseCycleFinished : IResponse {} + public class ResponseCycleFinished : AbstractResponse {} /// <summary> /// Response when a request was successful. /// </summary> - public class ResponseSuccess : IResponse {} + public class ResponseSuccess : AbstractResponse {} /// <summary> /// Response when the request resulted in an engine overload. /// </summary> - public class ResponseFailOverload : IResponse + public class ResponseFailOverload : AbstractResponse { public double Delta { get; set; } public double Gradient { get; set; } @@ -24,8 +30,13 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl /// <summary> /// Response when the request should have another time interval. /// </summary> - public class ResponseFailTimeInterval : IResponse + public class ResponseFailTimeInterval : AbstractResponse { public TimeSpan DeltaT { get; set; } } + + public class ResponseDrivingCycleDistanceExceeded : AbstractResponse + { + public Meter MaxDistance { get; set; } + } } \ No newline at end of file diff --git a/VectoCore/Models/Simulation/IVehicleContainer.cs b/VectoCore/Models/Simulation/IVehicleContainer.cs index d9182acd78b7e7a6f3991be40fcdf41fbc2147a7..b904c3216409dbccb0bc3d591c7ed9c5e22f9626 100644 --- a/VectoCore/Models/Simulation/IVehicleContainer.cs +++ b/VectoCore/Models/Simulation/IVehicleContainer.cs @@ -10,7 +10,7 @@ namespace TUGraz.VectoCore.Models.Simulation /// </summary> public interface IVehicleContainer : ICockpit { - IDrivingCycleOutPort GetCycleOutPort(); + ISimulationOutPort GetCycleOutPort(); /// <summary> /// Adds a component to the vehicle container. diff --git a/VectoCore/Models/Simulation/Impl/DistanceRun.cs b/VectoCore/Models/Simulation/Impl/DistanceRun.cs new file mode 100644 index 0000000000000000000000000000000000000000..f3169bf39aabc38a1c3ff300dc2e376097871506 --- /dev/null +++ b/VectoCore/Models/Simulation/Impl/DistanceRun.cs @@ -0,0 +1,45 @@ +using System; +using TUGraz.VectoCore.Configuration; +using TUGraz.VectoCore.Models.Connector.Ports; +using TUGraz.VectoCore.Models.Connector.Ports.Impl; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Models.Simulation.Impl +{ + public class DistanceRun : VectoRun + { + public DistanceRun(IVehicleContainer container) : base(container) {} + + protected override Connector.Ports.IResponse DoSimulationStep() + { + //_dt = TimeSpan.FromSeconds(1) - TimeSpan.FromMilliseconds(_dt.Milliseconds); + + // estimate distance to be traveled within the next TargetTimeInterval + var ds = (Container.VehicleSpeed() * Constants.SimulationSettings.TargetTimeInterval).Cast<Meter>(); + + if (ds.IsEqual(0)) { + ds = Constants.SimulationSettings.DriveOffDistance; + } + + var response = CyclePort.Request(AbsTime, ds); + + //while (response is ResponseFailTimeInterval) { + // _dt = (response as ResponseFailTimeInterval).DeltaT; + // response = CyclePort.Request(_absTime, _dt); + //} + + if (response is ResponseCycleFinished) { + return response; + } + + AbsTime = (AbsTime + TimeSpan.FromTicks(response.SimulationInterval.Ticks / 2)); + dt = response.SimulationInterval; + return response; + } + + protected override IResponse Initialize() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs b/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs index 2d8ec08b201e1b1f8df890ba81ee4bd4802e44bf..f96a671e3f1b91601c63cae414f5ebb156037501 100644 --- a/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs +++ b/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs @@ -32,7 +32,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl private VehicleContainer BuildFullPowertrain(VectoRunData data) { - IDrivingCycleDemandDrivingCycle cycle; + IDrivingCycle cycle; if (_engineOnly) { cycle = new TimeBasedDrivingCycle(_container, data.Cycle); } else { @@ -91,19 +91,19 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } } - protected virtual IDriver AddComponent(IDrivingCycleDemandDrivingCycle prev, IDriver next) + protected virtual IDriver AddComponent(IDrivingCycle prev, IDriver next) { - prev.InShaft().Connect(next.OutShaft()); + prev.InPort().Connect(next.OutPort()); return next; } protected virtual IVehicle AddComponent(IDriver prev, IVehicle next) { - prev.InShaft().Connect(next.OutShaft()); + prev.InPort().Connect(next.OutPort()); return next; } - protected virtual IWheels AddComponent(IRoadPortInProvider prev, IWheels next) + protected virtual IWheels AddComponent(IFvInProvider prev, IWheels next) { prev.InPort().Connect(next.OutPort()); return next; @@ -112,35 +112,35 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl protected virtual IPowerTrainComponent AddComponent(IWheels prev, IPowerTrainComponent next) { - prev.InShaft().Connect(next.OutShaft()); + prev.InPort().Connect(next.OutPort()); return next; } protected virtual IPowerTrainComponent AddComponent(IPowerTrainComponent prev, IPowerTrainComponent next) { - prev.InShaft().Connect(next.OutShaft()); + prev.InPort().Connect(next.OutPort()); return next; } - protected virtual void AddComponent(IPowerTrainComponent prev, IOutShaft next) + protected virtual void AddComponent(IPowerTrainComponent prev, ITnOutProvider next) { - prev.InShaft().Connect(next.OutShaft()); + prev.InPort().Connect(next.OutPort()); } private VehicleContainer BuildEngineOnly(VectoRunData data) { - var cycle = new EngineOnlyDrivingCycle(_container, data.Cycle); + var cycle = new EngineOnlySimulation(_container, data.Cycle); var engine = new CombustionEngine(_container, data.EngineData); var gearBox = new EngineOnlyGearbox(_container); IAuxiliary addAux = new DirectAuxiliary(_container, new AuxiliaryCycleDataAdapter(data.Cycle)); - addAux.InShaft().Connect(engine.OutShaft()); + addAux.InPort().Connect(engine.OutPort()); - gearBox.InShaft().Connect(addAux.OutShaft()); + gearBox.InPort().Connect(addAux.OutPort()); - cycle.InShaft().Connect(gearBox.OutShaft()); + cycle.InPort().Connect(gearBox.OutPort()); return _container; } diff --git a/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs b/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs index 7825484fbe7cd53e4a79d9c31ffc0aebad182abe..66fd5f748454d4b3523f1bdd00fef0e42406b338 100644 --- a/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs +++ b/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs @@ -78,7 +78,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl var sumWriterDecorator = DecorateSumWriter(data.IsEngineOnly, SumWriter, data.JobFileName, jobName, data.Cycle.Name); var builder = new PowertrainBuilder(modWriter, sumWriterDecorator, DataReader.IsEngineOnly); - yield return new VectoRun(builder.Build(data)); + yield return new DistanceRun(builder.Build(data)); } } diff --git a/VectoCore/Models/Simulation/Impl/VectoRun.cs b/VectoCore/Models/Simulation/Impl/VectoRun.cs index 7f9f75c3aec5e2b8c9042f636d4a5bf810590589..dfe20a3abbe323cd42a3a744ae3d584ef6f0f1a0 100644 --- a/VectoCore/Models/Simulation/Impl/VectoRun.cs +++ b/VectoCore/Models/Simulation/Impl/VectoRun.cs @@ -9,10 +9,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl /// <summary> /// Simulator for one vecto simulation job. /// </summary> - public class VectoRun : IVectoRun + public abstract class VectoRun : IVectoRun { - private TimeSpan _absTime = new TimeSpan(seconds: 0, minutes: 0, hours: 0); - private TimeSpan _dt = new TimeSpan(seconds: 1, minutes: 0, hours: 0); + protected TimeSpan AbsTime = new TimeSpan(seconds: 0, minutes: 0, hours: 0); + + protected TimeSpan dt = new TimeSpan(seconds: 1, minutes: 0, hours: 0); public VectoRun(IVehicleContainer container) { @@ -26,7 +27,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl protected string JobName { get; set; } - protected IDrivingCycleOutPort CyclePort { get; set; } + protected ISimulationOutPort CyclePort { get; set; } protected IModalDataWriter DataWriter { get; set; } protected IVehicleContainer Container { get; set; } @@ -39,31 +40,23 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl { LogManager.GetLogger(GetType()).Info("VectoJob started running."); IResponse response; - do { - response = CyclePort.Request(_absTime, _dt); - while (response is ResponseFailTimeInterval) { - _dt = (response as ResponseFailTimeInterval).DeltaT; - response = CyclePort.Request(_absTime, _dt); - } - - if (response is ResponseCycleFinished) { - break; - } - - var time = (_absTime + TimeSpan.FromTicks(_dt.Ticks / 2)).TotalSeconds; - var simulationInterval = _dt.TotalSeconds; - Container.CommitSimulationStep(time, simulationInterval); + do { + response = DoSimulationStep(); + Container.CommitSimulationStep(AbsTime.TotalSeconds, dt.TotalSeconds); // set _dt to difference to next full second. - _absTime += _dt; - _dt = TimeSpan.FromSeconds(1) - TimeSpan.FromMilliseconds(_dt.Milliseconds); + AbsTime += dt; } while (response is ResponseSuccess); Container.FinishSimulation(); LogManager.GetLogger(GetType()).Info("VectoJob finished."); } + + protected abstract IResponse DoSimulationStep(); + + protected abstract IResponse Initialize(); } } \ No newline at end of file diff --git a/VectoCore/Models/Simulation/Impl/VehicleContainer.cs b/VectoCore/Models/Simulation/Impl/VehicleContainer.cs index 6628f506f27102b22970344bb701a3f3936fb7a0..185ec935bb443834bc939045a3c5e0206020ef56 100644 --- a/VectoCore/Models/Simulation/Impl/VehicleContainer.cs +++ b/VectoCore/Models/Simulation/Impl/VehicleContainer.cs @@ -17,7 +17,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl internal IGearboxCockpit _gearbox; internal IVehicleCockpit _vehicle; - internal IDrivingCycleOutPort _cycle; + internal ISimulationOutPort _cycle; internal ISummaryDataWriter _sumWriter; internal IModalDataWriter _dataWriter; @@ -81,7 +81,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl #region IVehicleContainer - public IDrivingCycleOutPort GetCycleOutPort() + public ISimulationOutPort GetCycleOutPort() { return _cycle; } @@ -105,7 +105,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl _vehicle = vehicle; } - var cycle = component as IDrivingCycleOutPort; + var cycle = component as ISimulationOutPort; if (cycle != null) { _cycle = cycle; } diff --git a/VectoCore/Models/SimulationComponent/Data/DrivingCycleData.cs b/VectoCore/Models/SimulationComponent/Data/DrivingCycleData.cs index 997dc64d7204db63e927f8500eb75d9d473c90e4..f202b45abec3b9f47f343d88b8b3cababe8dcff7 100644 --- a/VectoCore/Models/SimulationComponent/Data/DrivingCycleData.cs +++ b/VectoCore/Models/SimulationComponent/Data/DrivingCycleData.cs @@ -46,7 +46,25 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data var data = VectoCSVFile.Read(fileName); var entries = parser.Parse(data).ToList(); - log.Info(string.Format("Data loaded. Number of Entries: {0}", entries.Count)); + if (type == CycleType.DistanceBased) { + var filtered = new List<DrivingCycleEntry>(); + var current = entries.First(); + current.Altitude = 0.SI<Meter>(); + filtered.Add(current); + var distance = current.Distance; + var altitude = current.Altitude; + foreach (var entry in entries) { + altitude += (entry.Distance - distance) * Math.Sin(entry.RoadGradient.Value()); + distance = entry.Distance; + if (!CycleEntriesAreEqual(current, entry)) { + entry.Altitude = altitude; + filtered.Add(entry); + current = entry; + } + } + log.Info(string.Format("Data loaded. Number of Entries: {0}, filtered Entries: {1}", entries.Count, filtered.Count)); + entries = filtered; + } var cycle = new DrivingCycleData { Entries = entries, @@ -55,6 +73,25 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data return cycle; } + private static bool CycleEntriesAreEqual(DrivingCycleEntry first, DrivingCycleEntry second) + { + var retVal = first.VehicleTargetSpeed == second.VehicleTargetSpeed; + retVal = retVal && + first.RoadGradient.IsEqual(second.RoadGradient, Constants.SimulationSettings.DrivingCycleRoadGradientTolerance); + retVal = retVal && first.StoppingTime.IsEqual(0) && second.StoppingTime.IsEqual(0); + retVal = retVal && first.AdditionalAuxPowerDemand == second.AdditionalAuxPowerDemand; + retVal = retVal && first.AuxiliarySupplyPower.Count == second.AuxiliarySupplyPower.Count; + + foreach (var key in first.AuxiliarySupplyPower.Keys) { + if (!second.AuxiliarySupplyPower.ContainsKey(key)) { + return false; + } + retVal = retVal && first.AuxiliarySupplyPower[key] == second.AuxiliarySupplyPower[key]; + } + + return retVal; + } + private static IDataParser CreateDataParser(CycleType type) { switch (type) { @@ -149,29 +186,34 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data /// [m] Travelled distance used for distance-based cycles. If "t" /// is also defined this column will be ignored. /// </summary> - public double Distance { get; set; } + public Meter Distance { get; set; } /// <summary> /// [s] Used for time-based cycles. If neither this nor the distance /// "s" is defined the data will be interpreted as 1Hz. /// </summary> - public double Time { get; set; } + public Second Time { get; set; } /// <summary> /// [m/s] Required except for Engine Only Mode calculations. /// </summary> - public MeterPerSecond VehicleSpeed { get; set; } + public MeterPerSecond VehicleTargetSpeed { get; set; } /// <summary> - /// [%] Optional. + /// [rad] Optional. + /// </summary> + public Radian RoadGradient { get; set; } + + /// <summary> + /// [m] relative altitude of the driving cycle over distance /// </summary> - public double RoadGradient { get; set; } + public Meter Altitude { get; set; } /// <summary> /// [s] Required for distance-based cycles. Not used in time based /// cycles. "stop" defines the time the vehicle spends in stop phases. /// </summary> - public double StoppingTime { get; set; } + public Second StoppingTime { get; set; } /// <summary> /// [W] Supply Power input for each auxiliary defined in the @@ -250,9 +292,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ValidateHeader(table.Columns.Cast<DataColumn>().Select(col => col.ColumnName).ToArray()); return table.Rows.Cast<DataRow>().Select(row => new DrivingCycleEntry { - Distance = row.ParseDouble(Fields.Distance), - VehicleSpeed = row.ParseDouble(Fields.VehicleSpeed).SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>(), - RoadGradient = row.ParseDoubleOrGetDefault(Fields.RoadGradient), + Distance = row.ParseDouble(Fields.Distance).SI<Meter>(), + VehicleTargetSpeed = row.ParseDouble(Fields.VehicleSpeed).SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>(), + RoadGradient = (row.ParseDoubleOrGetDefault(Fields.RoadGradient) / 100.0).SI().GradientPercent.Cast<Radian>(), + StoppingTime = (row.ParseDouble(Fields.StoppingTime)).SI<Second>(), AdditionalAuxPowerDemand = row.ParseDoubleOrGetDefault(Fields.AdditionalAuxPowerDemand).SI().Kilo.Watt.Cast<Watt>(), EngineSpeed = @@ -311,9 +354,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ValidateHeader(table.Columns.Cast<DataColumn>().Select(col => col.ColumnName).ToArray()); var entries = table.Rows.Cast<DataRow>().Select((row, index) => new DrivingCycleEntry { - Time = row.ParseDoubleOrGetDefault(Fields.Time, index), - VehicleSpeed = row.ParseDouble(Fields.VehicleSpeed).SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>(), - RoadGradient = row.ParseDoubleOrGetDefault(Fields.RoadGradient), + Time = row.ParseDoubleOrGetDefault(Fields.Time, index).SI<Second>(), + VehicleTargetSpeed = row.ParseDouble(Fields.VehicleSpeed).SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>(), + RoadGradient = (row.ParseDoubleOrGetDefault(Fields.RoadGradient) / 100.0).SI().GradientPercent.Cast<Radian>(), AdditionalAuxPowerDemand = row.ParseDoubleOrGetDefault(Fields.AdditionalAuxPowerDemand).SI().Kilo.Watt.Cast<Watt>(), Gear = row.ParseDoubleOrGetDefault(Fields.Gear), @@ -392,7 +435,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data entry.EngineSpeed); } } - entry.Time = absTime.TotalSeconds; + entry.Time = absTime.TotalSeconds.SI<Second>(); absTime += new TimeSpan(0, 0, 1); yield return entry; diff --git a/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs b/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs index 1bc5286a2f6cfdcfeb89aca843b10c61e28c1bf3..5946347629890427c93a9047c2754004fa59e064 100644 --- a/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs +++ b/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs @@ -65,7 +65,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine { // delauney map needs is initialised with rpm, therefore the engineSpeed has to be converted. return - _fuelMap.Interpolate(torque.Double(), engineSpeed.ConvertTo().Rounds.Per.Minute.Double()).SI().Kilo.Gramm.Per.Second; + _fuelMap.Interpolate(torque.Value(), engineSpeed.ConvertTo().Rounds.Per.Minute.Value()).SI().Kilo.Gramm.Per.Second; } private static class Fields diff --git a/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs b/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs index 15e014396f7b12d30369da76dbbd1a1ef75e34ee..87088182e0c9106f14351a8c334ce890e472cef7 100644 --- a/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs +++ b/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs @@ -270,14 +270,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine var k = (p2.TorqueFullLoad - p1.TorqueFullLoad) / (p2.EngineSpeed - p1.EngineSpeed); var d = p2.TorqueFullLoad - k * p2.EngineSpeed; - if (k.Double().IsEqual(0.0)) { + if (k.IsEqual(0.0)) { // rectangle - return (p1.EngineSpeed + (area / d.Double())); + return (p1.EngineSpeed + (area / d.Value())); } - var a = k.Double() / 2.0; - var b = d.Double(); - var c = (k * p1.EngineSpeed * p1.EngineSpeed + 2 * p1.EngineSpeed * d).Double(); + var a = k.Value() / 2.0; + var b = d.Value(); + var c = (k * p1.EngineSpeed * p1.EngineSpeed + 2 * p1.EngineSpeed * d).Value(); var D = b * b - 4 * a * c; @@ -334,14 +334,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine var d = p2.TorqueFullLoad - k * p2.EngineSpeed; var retVal = new List<PerSecond>(); - if (k.Double().IsEqual(0, 0.0001)) { + if (k.IsEqual(0, 0.0001)) { // constant torque, solve linear equation - retVal.Add((power.Double() / d.Double()).SI<PerSecond>()); + retVal.Add((power.Value() / d.Value()).SI<PerSecond>()); } else { // non-constant torque, solve quadratic equation - var a = k.Double(); - var b = d.Double(); - var c = -power.Double(); + var a = k.Value(); + var b = d.Value(); + var c = -power.Value(); var D = b * b - 4 * a * c; if (D < 0) { @@ -368,7 +368,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine if (lowEngineSpeed < _fullLoadEntries[startSegment].EngineSpeed) { // add part of the first segment area += ((_fullLoadEntries[startSegment].EngineSpeed - lowEngineSpeed) * - (FullLoadStationaryTorque(lowEngineSpeed) + _fullLoadEntries[startSegment].TorqueFullLoad) / 2.0).Double(); + (FullLoadStationaryTorque(lowEngineSpeed) + _fullLoadEntries[startSegment].TorqueFullLoad) / 2.0).Value(); } for (var i = startSegment + 1; i <= endSegment; i++) { var speedHigh = _fullLoadEntries[i].EngineSpeed; @@ -379,7 +379,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine torqueHigh = FullLoadStationaryTorque(highEngineSpeed); } area += ((speedHigh - _fullLoadEntries[i - 1].EngineSpeed) * - (torqueHigh + _fullLoadEntries[i - 1].TorqueFullLoad) / 2.0).Double(); + (torqueHigh + _fullLoadEntries[i - 1].TorqueFullLoad) / 2.0).Value(); } return area; } diff --git a/VectoCore/Models/SimulationComponent/Data/Gearbox/TransmissionLossMap.cs b/VectoCore/Models/SimulationComponent/Data/Gearbox/TransmissionLossMap.cs index a3665d84445df8ff0c0b22c3d2f4e6a06328c82d..bc429a3f29fc25e2aee419ad7de7010784c67a70 100644 --- a/VectoCore/Models/SimulationComponent/Data/Gearbox/TransmissionLossMap.cs +++ b/VectoCore/Models/SimulationComponent/Data/Gearbox/TransmissionLossMap.cs @@ -84,8 +84,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox _lossMap = new DelauneyMap(); //_reverseLossMap = new DelauneyMap(); foreach (var entry in _entries) { - _lossMap.AddPoint(entry.InputSpeed.Double(), (entry.InputTorque.Double() - entry.TorqueLoss.Double()) * gearRatio, - entry.InputTorque.Double()); + _lossMap.AddPoint(entry.InputSpeed.Value(), (entry.InputTorque.Value() - entry.TorqueLoss.Value()) * gearRatio, + entry.InputTorque.Value()); // @@@quam: according to Raphael, not needed for now... //_reverseLossMap.AddPoint(entry.InputSpeed.Double(), entry.InputTorque.Double(), // entry.InputTorque.Double() - entry.TorqueLoss.Double()); @@ -103,7 +103,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox public NewtonMeter GearboxInTorque(PerSecond angularVelocity, NewtonMeter gbxOutTorque) { try { - return VectoMath.Max(_lossMap.Interpolate(angularVelocity.Double(), gbxOutTorque.Double()).SI<NewtonMeter>(), + return VectoMath.Max(_lossMap.Interpolate(angularVelocity.Value(), gbxOutTorque.Value()).SI<NewtonMeter>(), 0.SI<NewtonMeter>()); } catch (Exception e) { throw new VectoSimulationException( diff --git a/VectoCore/Models/SimulationComponent/Data/VehicleData.cs b/VectoCore/Models/SimulationComponent/Data/VehicleData.cs index f592fa991c9229a336bcb91c73258aa223e30c1c..c50a3175cfea4b908ecbdf6c249dee19d75604e2 100644 --- a/VectoCore/Models/SimulationComponent/Data/VehicleData.cs +++ b/VectoCore/Models/SimulationComponent/Data/VehicleData.cs @@ -95,7 +95,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data RRC += axle.AxleWeightShare * axle.RollResistanceCoefficient * Math.Pow( (axle.AxleWeightShare * TotalVehicleWeight() * Physics.GravityAccelleration / axle.TyreTestLoad / - nrWheels).Double(), Physics.RollResistanceExponent - 1); + nrWheels).Value(), Physics.RollResistanceExponent - 1); mRed0 += nrWheels * (axle.Inertia / DynamicTyreRadius / DynamicTyreRadius).Cast<Kilogram>(); } TotalRollResistanceCoefficient = RRC; diff --git a/VectoCore/Models/SimulationComponent/Factories/EngineeringModeFactory.cs b/VectoCore/Models/SimulationComponent/Factories/EngineeringModeFactory.cs deleted file mode 100644 index af2c8e0e53b49c08a6d18eb29feea0e39f708a31..0000000000000000000000000000000000000000 --- a/VectoCore/Models/SimulationComponent/Factories/EngineeringModeFactory.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System.IO; -using System.Linq; -using Newtonsoft.Json; -using TUGraz.VectoCore.Exceptions; -using TUGraz.VectoCore.FileIO; -using TUGraz.VectoCore.Models.Declaration; -using TUGraz.VectoCore.Models.SimulationComponent.Data; -using TUGraz.VectoCore.Utils; - -namespace TUGraz.VectoCore.Models.SimulationComponent.Factories -{ - public class EngineeringModeFactory : InputFileReader - { - protected static EngineeringModeFactory _instance; - - public static EngineeringModeFactory Instance() - { - return _instance ?? (_instance = new EngineeringModeFactory()); - } - - private void CheckEngineeringMode(string fileName, VersionInfo fileInfo) - { - if (fileInfo.SavedInDeclarationMode) { - Log.WarnFormat("File {0} was saved in Declaration Mode but is used for Engineering Mode!", fileName); - } - } - - public VehicleData CreateVehicleData(string fileName) - { - var json = File.ReadAllText(fileName); - var fileInfo = GetFileVersion(json); - CheckEngineeringMode(fileName, fileInfo); - - switch (fileInfo.Version) { - case 5: - var data = JsonConvert.DeserializeObject<VehicleFileV5Engineering>(json); - return CreateVehicleData(Path.GetDirectoryName(fileName), data.Body); - default: - throw new UnsupportedFileVersionException(fileName, fileInfo.Version); - } - } - - - protected VehicleData CreateVehicleData(string basePath, VehicleFileV5Engineering.DataBodyEng data) - { - return new VehicleData { - BasePath = basePath, - SavedInDeclarationMode = data.SavedInDeclarationMode, - VehicleCategory = data.VehicleCategory(), - CurbWeight = data.CurbWeight.SI<Kilogram>(), - CurbWeigthExtra = data.CurbWeightExtra.SI<Kilogram>(), - Loading = data.Loading.SI<Kilogram>(), - GrossVehicleMassRating = data.GrossVehicleMassRating.SI().Kilo.Kilo.Gramm.Cast<Kilogram>(), - DragCoefficient = data.DragCoefficient, - CrossSectionArea = data.CrossSectionArea.SI<SquareMeter>(), - DragCoefficientRigidTruck = data.DragCoefficientRigidTruck, - CrossSectionAreaRigidTruck = data.CrossSectionAreaRigidTruck.SI<SquareMeter>(), - DynamicTyreRadius = data.DynamicTyreRadius.SI().Milli.Meter.Cast<Meter>(), - // .SI<Meter>(), - Rim = data.RimStr, - Retarder = new RetarderData(data.Retarder, basePath), - AxleData = data.AxleConfig.Axles.Select(axle => new Axle { - Inertia = axle.Inertia.SI<KilogramSquareMeter>(), - TwinTyres = axle.TwinTyres, - RollResistanceCoefficient = axle.RollResistanceCoefficient, - AxleWeightShare = axle.AxleWeightShare, - TyreTestLoad = axle.TyreTestLoad.SI<Newton>() - }).ToList() - }; - } - } -} \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/ICombustionEngine.cs b/VectoCore/Models/SimulationComponent/ICombustionEngine.cs index afb7be9d04565c5011e0449135484c32649f7e32..6ea31f7b463813aed53403b0942df68163c3436a 100644 --- a/VectoCore/Models/SimulationComponent/ICombustionEngine.cs +++ b/VectoCore/Models/SimulationComponent/ICombustionEngine.cs @@ -6,5 +6,5 @@ namespace TUGraz.VectoCore.Models.SimulationComponent /// <summary> /// Defines Interfaces for a combustion engine. /// </summary> - public interface ICombustionEngine : IOutShaft, IEngineCockpit {} + public interface ICombustionEngine : ITnOutProvider, IEngineCockpit {} } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/IDriver.cs b/VectoCore/Models/SimulationComponent/IDriver.cs index e6e019ffc7bbc670994f70711ec5fb4d7c409dde..9527fb200c8e5ea23ef2517225d8ef65aa768685 100644 --- a/VectoCore/Models/SimulationComponent/IDriver.cs +++ b/VectoCore/Models/SimulationComponent/IDriver.cs @@ -5,5 +5,5 @@ namespace TUGraz.VectoCore.Models.SimulationComponent /// <summary> /// Defines interfaces for a driver. /// </summary> - public interface IDriver : IDrivingCycleDemandOutProvider, IDriverDemandInProvider {} + public interface IDriver : IDrivingCycleOutProvider, IDriverDemandInProvider {} } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/IDriverDemandDrivingCycle.cs b/VectoCore/Models/SimulationComponent/IDrivingCycle.cs similarity index 63% rename from VectoCore/Models/SimulationComponent/IDriverDemandDrivingCycle.cs rename to VectoCore/Models/SimulationComponent/IDrivingCycle.cs index 6d8656334e67b7e0d3e7d33c36eb9f784748c6f2..647aab5838747764b9f101151afeba4118a76b2e 100644 --- a/VectoCore/Models/SimulationComponent/IDriverDemandDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/IDrivingCycle.cs @@ -5,5 +5,5 @@ namespace TUGraz.VectoCore.Models.SimulationComponent /// <summary> /// Defines interfaces for a driver demand driving cycle. /// </summary> - public interface IDrivingCycleDemandDrivingCycle : IDrivingCycleOutProvider, IDrivingCycleDemandInProvider {} + public interface IDrivingCycle : ISimulationOutProvider, IDrivingCycleInProvider {} } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/IEngineOnlyDrivingCycle.cs b/VectoCore/Models/SimulationComponent/IEngineOnlyDrivingCycle.cs index ac196bd5fa3a0284589b41eefaf74ab871876f22..cee733a53edd52445002b11ddf0446bd277cef35 100644 --- a/VectoCore/Models/SimulationComponent/IEngineOnlyDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/IEngineOnlyDrivingCycle.cs @@ -5,5 +5,5 @@ namespace TUGraz.VectoCore.Models.SimulationComponent /// <summary> /// Defines interfaces for a engine only driving cycle. /// </summary> - public interface IEngineOnlyDrivingCycle : IDrivingCycleOutProvider, IInShaft {} + public interface IEngineOnlySimulation : ISimulationOutProvider, ITnInProvider {} } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/IPowerTrainComponent.cs b/VectoCore/Models/SimulationComponent/IPowerTrainComponent.cs index 7c0d4202c02237dc8c618c4dbc6105c87597ee02..8841c6aaa21f7e3b5cd4b60c2110649a71bb57fc 100644 --- a/VectoCore/Models/SimulationComponent/IPowerTrainComponent.cs +++ b/VectoCore/Models/SimulationComponent/IPowerTrainComponent.cs @@ -2,5 +2,5 @@ namespace TUGraz.VectoCore.Models.SimulationComponent { - public interface IPowerTrainComponent : IInShaft, IOutShaft {} + public interface IPowerTrainComponent : ITnInProvider, ITnOutProvider {} } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/IVehicle.cs b/VectoCore/Models/SimulationComponent/IVehicle.cs index 9b5249d625380e5f17b213d58ce6e9b0dc88ff6a..f2949fac5a007d07353dbcbea2601735d00529bc 100644 --- a/VectoCore/Models/SimulationComponent/IVehicle.cs +++ b/VectoCore/Models/SimulationComponent/IVehicle.cs @@ -3,5 +3,5 @@ using TUGraz.VectoCore.Models.Simulation.Cockpit; namespace TUGraz.VectoCore.Models.SimulationComponent { - public interface IVehicle : IRoadPortInProvider, IDriverDemandOutProvider, IVehicleCockpit {} + public interface IVehicle : IFvInProvider, IDriverDemandOutProvider, IVehicleCockpit {} } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/IWheels.cs b/VectoCore/Models/SimulationComponent/IWheels.cs index 354f551e2e3c6b595fb9d487c6ad53b791778a10..62d3756c16b4a14193aed5b1eceab5a89780a5da 100644 --- a/VectoCore/Models/SimulationComponent/IWheels.cs +++ b/VectoCore/Models/SimulationComponent/IWheels.cs @@ -5,5 +5,5 @@ namespace TUGraz.VectoCore.Models.SimulationComponent /// <summary> /// Defines interfaces for a wheels component. /// </summary> - public interface IWheels : IRoadPortOutProvider, IInShaft {} + public interface IWheels : IFvOutProvider, ITnInProvider {} } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs b/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs index 1731e19655f073ad47f98a81b36fbfbbd6f4bf37..d460551aacc0ed9c8b812129e064574da68a0ee0 100644 --- a/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs +++ b/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs @@ -17,12 +17,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _gearData = gearData; } - public ITnInPort InShaft() + public ITnInPort InPort() { return this; } - public ITnOutPort OutShaft() + public ITnOutPort OutPort() { return this; } diff --git a/VectoCore/Models/SimulationComponent/Impl/Clutch.cs b/VectoCore/Models/SimulationComponent/Impl/Clutch.cs index 3a57e7667eae70d9b3e81cac36a043cf4a56e554..8115687d9f6bdf58148b624557911c6864d9f7a9 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Clutch.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Clutch.cs @@ -41,13 +41,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl //throw new NotImplementedException(); } - public ITnInPort InShaft() + public ITnInPort InPort() { return this; } - public ITnOutPort OutShaft() + public ITnOutPort OutPort() { return this; } diff --git a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index 566c50af58e714ea125f1330f68309c684e865fd..72c376749914d588273baa74cbbe39b241d49075 100644 --- a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -62,9 +62,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #endregion - #region IOutShaft + #region ITnOutProvider - public ITnOutPort OutShaft() + public ITnOutPort OutPort() { return this; } @@ -235,15 +235,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _currentState.StationaryFullLoadPower = Formulas.TorqueToPower(_currentState.StationaryFullLoadTorque, angularVelocity); - double pt1 = _data.GetFullLoadCurve(gear).PT1(angularVelocity).Double(); + double pt1 = _data.GetFullLoadCurve(gear).PT1(angularVelocity).Value(); // var dynFullPowerCalculated = (1 / (pt1 + 1)) * // (_currentState.StationaryFullLoadPower + pt1 * _previousState.EnginePower); var tStarPrev = pt1 * - Math.Log(1 / (1 - (_previousState.EnginePower / _currentState.StationaryFullLoadPower).Double()), Math.E) + Math.Log(1 / (1 - (_previousState.EnginePower / _currentState.StationaryFullLoadPower).Value()), Math.E) .SI<Second>(); var tStar = tStarPrev + _previousState.dt.TotalSeconds.SI<Second>(); - var dynFullPowerCalculated = _currentState.StationaryFullLoadPower * (1 - Math.Exp((-tStar / pt1).Double())); + var dynFullPowerCalculated = _currentState.StationaryFullLoadPower * (1 - Math.Exp((-tStar / pt1).Value())); _currentState.DynamicFullLoadPower = (dynFullPowerCalculated < _currentState.StationaryFullLoadPower) ? dynFullPowerCalculated : _currentState.StationaryFullLoadPower; diff --git a/VectoCore/Models/SimulationComponent/Impl/DirectAuxiliary.cs b/VectoCore/Models/SimulationComponent/Impl/DirectAuxiliary.cs index eb7a7deddf795453ff94770361ac41ed49177a14..6617c929f4df3319e190f839986a1f8a8c5c9f0f 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DirectAuxiliary.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DirectAuxiliary.cs @@ -20,18 +20,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _demand = demand; } - #region IInShaft + #region ITnInProvider - public ITnInPort InShaft() + public ITnInPort InPort() { return this; } #endregion - #region IOutShaft + #region ITnOutProvider - public ITnOutPort OutShaft() + public ITnOutPort OutPort() { return this; } diff --git a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs index 2943cfd797cc15fc8fbc0ea2a3e08e5caf6f4136..e16b4717a1b18642386a2893b711f9d304e3eea9 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs @@ -1,73 +1,179 @@ using System; +using System.Linq; +using System.Net.Cache; +using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Models.Connector.Ports; +using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { /// <summary> /// Class representing one Distance Based Driving Cycle /// </summary> - public class DistanceBasedDrivingCycle : VectoSimulationComponent, IDrivingCycleDemandDrivingCycle, - IDrivingCycleOutPort, - IDrivingCycleDemandInPort + public class DistanceBasedDrivingCycle : VectoSimulationComponent, IDrivingCycle, + ISimulationOutPort, + IDrivingCycleInPort { - protected TimeSpan AbsTime = new TimeSpan(seconds: 0, minutes: 0, hours: 0); protected DrivingCycleData Data; - protected double Distance = 0; - protected TimeSpan Dt = new TimeSpan(seconds: 1, minutes: 0, hours: 0); - private IDrivingCycleDemandOutPort _outPort; + + private DrivingCycleState _previousState = null; + private DrivingCycleState _currentState = new DrivingCycleState(); + + private IDrivingCycleOutPort _outPort; public DistanceBasedDrivingCycle(IVehicleContainer container, DrivingCycleData cycle) : base(container) { Data = cycle; } - #region IDrivingCycleDemandInProvider + #region IDrivingCycleInProvider - public IDrivingCycleDemandInPort InShaft() + public IDrivingCycleInPort InPort() { return this; } #endregion - #region IDrivingCycleOutProvider + #region ISimulationOutProvider - public IDrivingCycleOutPort OutShaft() + public ISimulationOutPort OutPort() { return this; } #endregion - #region IDrivingCycleDemandInPort + #region IDrivingCycleInPort - void IDrivingCycleDemandInPort.Connect(IDrivingCycleDemandOutPort other) + void IDrivingCycleInPort.Connect(IDrivingCycleOutPort other) { _outPort = other; } #endregion - #region IDrivingCycleOutPort + #region ISimulationOutPort - IResponse IDrivingCycleOutPort.Request(TimeSpan absTime, TimeSpan dt) + IResponse ISimulationOutPort.Request(TimeSpan absTime, Meter ds) { - //todo: Distance calculation and comparison!!! - throw new NotImplementedException("Distance based Cycle is not yet implemented."); + var currentCycleEntry = Data.Entries[_currentState.CycleIndex]; + var nextCycleEntry = Data.Entries[_currentState.CycleIndex + 1]; + + IResponse retVal = null; + if (currentCycleEntry.Distance.IsEqual(_previousState.Distance.Value())) { + // exactly on an entry in the cycle... + if (!currentCycleEntry.StoppingTime.IsEqual(0)) { + // stop for certain time... + if (!currentCycleEntry.VehicleTargetSpeed.IsEqual(0)) { + Log.WarnFormat("Stopping Time requested in cycle but target-velocity not zero. distance: {0}, target speed: {1}", + currentCycleEntry.StoppingTime, currentCycleEntry.VehicleTargetSpeed); + throw new VectoSimulationException("Stopping Time only allowed when target speed is zero!"); + } + retVal = _outPort.Request(absTime, TimeSpan.FromSeconds(currentCycleEntry.StoppingTime.Value()), + currentCycleEntry.VehicleTargetSpeed, currentCycleEntry.RoadGradient); + //retVal = OutPort().Request(absTime, TimeSpan.FromSeconds(currentCycleEntry.StoppingTime.Value())); + } + } + + if (_previousState.Distance + ds > nextCycleEntry.Distance) { + // only drive until next sample point in cycle + return new ResponseDrivingCycleDistanceExceeded() { + MaxDistance = nextCycleEntry.Distance - _previousState.Distance + }; + } + + + retVal = DriveDistance(absTime, ds); + //throw new NotImplementedException("Distance based Cycle is not yet implemented."); + } + + private IResponse DriveDistance(TimeSpan absTime, Meter ds) + { + _currentState = _previousState.Clone(); + _currentState.Distance += ds; + while (_currentState.Distance < Data.Entries[_currentState.CycleIndex + 1].Distance) { + _currentState.CycleIndex++; + } + + var leftSamplePoint = Data.Entries[_currentState.CycleIndex]; + var rightSamplePoint = Data.Entries[_currentState.CycleIndex + 1]; + _currentState.Altitude = VectoMath.Interpolate(leftSamplePoint.Distance, rightSamplePoint.Distance, + leftSamplePoint.Altitude, rightSamplePoint.Altitude, _currentState.Distance); + + _currentState.VehicleTargetSpeed = Data.Entries[_currentState.CycleIndex].VehicleTargetSpeed; + + var gradient = ((_currentState.Altitude - _previousState.Altitude) / + (_currentState.Distance - _previousState.Distance)).GradientPercent.Cast<Radian>(); + + + return _outPort.Request(absTime, ds, _currentState.VehicleTargetSpeed, gradient); + } + + IResponse ISimulationOutPort.Request(TimeSpan absTime, TimeSpan dt) + { + throw new NotImplementedException(); + } + + IResponse ISimulationOutPort.Initialize() + { + var first = Data.Entries.First(); + _previousState = new DrivingCycleState() { + AbsTime = TimeSpan.FromSeconds(0), + Distance = first.Distance, + Altitude = first.Altitude, + CycleIndex = 0, + }; + return new ResponseSuccess(); + //TODO: return _outPort.Initialize(); } #endregion + protected IResponse ProcessResponse(IResponse response) {} + #region VectoSimulationComponent public override void CommitSimulationStep(IModalDataWriter writer) { + _previousState = _currentState; + _currentState = new DrivingCycleState(); throw new NotImplementedException("Distance based Cycle is not yet implemented."); } #endregion + + protected void LookupCycle(Meter ds) {} + + + public class DrivingCycleState + { + public DrivingCycleState() {} + + public DrivingCycleState Clone() + { + return new DrivingCycleState() { + AbsTime = AbsTime, + Distance = Distance, + VehicleTargetSpeed = VehicleTargetSpeed, + Altitude = Altitude, + CycleIndex = CycleIndex + }; + } + + public TimeSpan AbsTime; + + public Meter Distance; + + public MeterPerSecond VehicleTargetSpeed; + + public Meter Altitude; + + public int CycleIndex; + } } } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 1ce034eb3fe364d1292de9f7d3b0bf0fbc1e3ae6..135294610bcabdc94b212d99b111eeebdc550489 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -8,7 +8,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class Driver : VectoSimulationComponent, IDriver, IDrivingCycleDemandOutPort, IDriverDemandInPort + public class Driver : VectoSimulationComponent, IDriver, IDrivingCycleOutPort, IDriverDemandInPort { protected IDriverDemandOutPort _other; @@ -17,7 +17,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl //throw new NotImplementedException(); } - public IDriverDemandInPort InShaft() + public IDriverDemandInPort InPort() { return this; } @@ -27,18 +27,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _other = other; } - public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond velocity, Radian gradient) + public IResponse Request(TimeSpan absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) { throw new NotImplementedException(); } - public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSquareSecond accelleration, Radian gradient) + public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond accelleration, Radian gradient) { throw new NotImplementedException(); } - public IDrivingCycleDemandOutPort OutShaft() + public IDrivingCycleOutPort OutPort() { return this; } diff --git a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyDrivingCycle.cs index da14aa901d862b3ff22371b6b39475ccbc9a34f5..e4ecf5e6b311a21d3430d838a46fda817fc1293d 100644 --- a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyDrivingCycle.cs @@ -1,47 +1,54 @@ using System; +using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { /// <summary> /// Class representing one EngineOnly Driving Cycle /// </summary> - public class EngineOnlyDrivingCycle : VectoSimulationComponent, IEngineOnlyDrivingCycle, ITnInPort, - IDrivingCycleOutPort + public class EngineOnlySimulation : VectoSimulationComponent, IEngineOnlySimulation, ITnInPort, + ISimulationOutPort { protected DrivingCycleData Data; private ITnOutPort _outPort; - public EngineOnlyDrivingCycle(IVehicleContainer container, DrivingCycleData cycle) : base(container) + public EngineOnlySimulation(IVehicleContainer container, DrivingCycleData cycle) : base(container) { Data = cycle; } - #region IInShaft + #region ITnInProvider - public ITnInPort InShaft() + public ITnInPort InPort() { return this; } #endregion - #region IDrivingCycleOutProvider + #region ISimulationOutProvider - public IDrivingCycleOutPort OutShaft() + public ISimulationOutPort OutPort() { return this; } #endregion - #region IDrivingCycleOutPort + #region ISimulationOutPort - IResponse IDrivingCycleOutPort.Request(TimeSpan absTime, TimeSpan dt) + public IResponse Request(TimeSpan absTime, Meter ds) + { + throw new VectoSimulationException("Engine-Only Simulation can not handle distance request"); + } + + IResponse ISimulationOutPort.Request(TimeSpan absTime, TimeSpan dt) { //todo: change to variable time steps var index = (int)Math.Floor(absTime.TotalSeconds); @@ -52,6 +59,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return _outPort.Request(absTime, dt, Data.Entries[index].EngineTorque, Data.Entries[index].EngineSpeed); } + public IResponse Initialize() + { + // nothing to initialize here... + // TODO: _outPort.initialize(); + throw new NotImplementedException(); + } + #endregion #region ITnInPort diff --git a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs index d6b997ae048d5c2a834fb8f7080cb4cddbf59274..e47a981c80666df47721a39a67291e2ad8ed8c46 100644 --- a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs +++ b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs @@ -13,18 +13,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl private ITnOutPort _outPort; public EngineOnlyGearbox(IVehicleContainer cockpit) : base(cockpit) {} - #region IInShaft + #region ITnInProvider - public ITnInPort InShaft() + public ITnInPort InPort() { return this; } - #endregion IOutShaft + #endregion ITnOutProvider - #region IOutShaft + #region ITnOutProvider - public ITnOutPort OutShaft() + public ITnOutPort OutPort() { return this; } diff --git a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index 36823d7ee2bf8712351859a9115b185e6db214ee..7faeb67cc9c67eb4ddeb3fcfd277340caf78d96b 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -19,18 +19,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Data = gearboxData; } - #region IInShaft + #region ITnInProvider - public ITnInPort InShaft() + public ITnInPort InPort() { return this; } #endregion - #region IOutShaft + #region ITnOutProvider - public ITnOutPort OutShaft() + public ITnOutPort OutPort() { return this; } diff --git a/VectoCore/Models/SimulationComponent/Impl/MappingAuxiliary.cs b/VectoCore/Models/SimulationComponent/Impl/MappingAuxiliary.cs index 36425689203ff93362ad92ab08cd44948a414281..b55ac5422a646c979bcecf8f92a56db24f39bb19 100644 --- a/VectoCore/Models/SimulationComponent/Impl/MappingAuxiliary.cs +++ b/VectoCore/Models/SimulationComponent/Impl/MappingAuxiliary.cs @@ -39,18 +39,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _data = data; } - #region IInShaft + #region ITnInProvider - public ITnInPort InShaft() + public ITnInPort InPort() { return this; } #endregion - #region IOutShaft + #region ITnOutProvider - public ITnOutPort OutShaft() + public ITnOutPort OutPort() { return this; } diff --git a/VectoCore/Models/SimulationComponent/Impl/Retarder.cs b/VectoCore/Models/SimulationComponent/Impl/Retarder.cs index 8889912ab158b2ec74b9bd51a41fdc125f9617a0..b3cb58d0ba2397360ef27bdaddb291eca39bb2af 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Retarder.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Retarder.cs @@ -26,12 +26,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl writer[ModalResultField.PlossRetarder] = _lossMap; } - public ITnInPort InShaft() + public ITnInPort InPort() { return this; } - public ITnOutPort OutShaft() + public ITnOutPort OutPort() { return this; } diff --git a/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs index 52838a1cf5f56b4a9eb34086d7da83abd04efa4e..5100afd79d15fe6070528e928332738d4067356a 100644 --- a/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs @@ -11,39 +11,44 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <summary> /// Class representing one Time Based Driving Cycle /// </summary> - public class TimeBasedDrivingCycle : VectoSimulationComponent, IDrivingCycleDemandDrivingCycle, - IDrivingCycleDemandInPort, - IDrivingCycleOutPort + public class TimeBasedDrivingCycle : VectoSimulationComponent, IDrivingCycle, + IDrivingCycleInPort, + ISimulationOutPort { protected DrivingCycleData Data; - private IDrivingCycleDemandOutPort _outPort; + private IDrivingCycleOutPort _outPort; public TimeBasedDrivingCycle(IVehicleContainer container, DrivingCycleData cycle) : base(container) { Data = cycle; } - #region IDrivingCycleOutProvider + #region ISimulationOutProvider - public IDrivingCycleOutPort OutShaft() + public ISimulationOutPort OutPort() { return this; } #endregion - #region IDrivingCycleDemandInProvider + #region IDrivingCycleInProvider - public IDrivingCycleDemandInPort InShaft() + public IDrivingCycleInPort InPort() { return this; } #endregion - #region IDrivingCycleOutPort + #region ISimulationOutPort - IResponse IDrivingCycleOutPort.Request(TimeSpan absTime, TimeSpan dt) + IResponse ISimulationOutPort.Request(TimeSpan absTime, Meter ds) + { + throw new NotImplementedException(); + } + + public IResponse Request(TimeSpan absTime, TimeSpan dt) { //todo: change to variable time steps var index = (int)Math.Floor(absTime.TotalSeconds); @@ -51,15 +56,26 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return new ResponseCycleFinished(); } - return _outPort.Request(absTime, dt, Data.Entries[index].VehicleSpeed, - Data.Entries[index].RoadGradient.SI().GradientPercent.Cast<Radian>()); + // TODO!! + var dx = 0.SI<Meter>(); + return _outPort.Request(absTime, dx, Data.Entries[index].VehicleTargetSpeed, + Data.Entries[index].RoadGradient); + } + + public IResponse Initialize() + { + // nothing to initialize here... + // TODO: _outPort.initialize(); + throw new NotImplementedException(); } #endregion - #region IDrivingCycleDemandInPort + #region IDrivingCycleInPort - void IDrivingCycleDemandInPort.Connect(IDrivingCycleDemandOutPort other) + void IDrivingCycleInPort. + Connect(IDrivingCycleOutPort + other) { _outPort = other; } @@ -68,7 +84,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region VectoSimulationComponent - public override void CommitSimulationStep(IModalDataWriter writer) {} + public override + void CommitSimulationStep + (IModalDataWriter + writer) {} #endregion } diff --git a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs index bbe6145774a4b67d675e9ff0aa283a1e480aa858..713048a5297339097083b4d013e311b2cc3c2728 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs @@ -33,7 +33,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return this; } - public IDriverDemandOutPort OutShaft() + public IDriverDemandOutPort OutPort() { return this; } @@ -53,15 +53,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { _currentState.Velocity = _previousState.Velocity + (accelleration * (dt.TotalSeconds / 2.0).SI<Second>()).Cast<MeterPerSecond>(); - var force = RollingResistance(gradient) + AirDragResistance() + AccelerationForce(accelleration) + - SlopeResistance(gradient); - return _nextInstance.Request(absTime, dt, force, _currentState.Velocity); + // DriverAcceleration = vehicleAccelerationForce - RollingResistance - AirDragResistance - SlopeResistance + var vehicleAccelerationForce = DriverAcceleration(accelleration) + RollingResistance(gradient) + + AirDragResistance() + + SlopeResistance(gradient); + + return _nextInstance.Request(absTime, dt, vehicleAccelerationForce, _currentState.Velocity); } protected Newton RollingResistance(Radian gradient) { - return (Math.Cos(gradient.Double()) * _data.TotalVehicleWeight() * + return (Math.Cos(gradient.Value()) * _data.TotalVehicleWeight() * Physics.GravityAccelleration * _data.TotalRollResistanceCoefficient).Cast<Newton>(); } @@ -83,7 +86,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return (Cd * _data.CrossSectionArea * Physics.AirDensity / 2 * vAir * vAir).Cast<Newton>(); } - protected Newton AccelerationForce(MeterPerSquareSecond accelleration) + protected Newton DriverAcceleration(MeterPerSquareSecond accelleration) { return ((_data.TotalVehicleWeight() + _data.ReducedMassWheels) * accelleration).Cast<Newton>(); } @@ -91,7 +94,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected Newton SlopeResistance(Radian gradient) { - return (_data.TotalVehicleWeight() * Physics.GravityAccelleration * Math.Sin(gradient.Double())).Cast<Newton>(); + return (_data.TotalVehicleWeight() * Physics.GravityAccelleration * Math.Sin(gradient.Value())).Cast<Newton>(); } public MeterPerSecond VehicleSpeed() diff --git a/VectoCore/Models/SimulationComponent/Impl/Wheels.cs b/VectoCore/Models/SimulationComponent/Impl/Wheels.cs index 22312359373e9f5332b888a8f4888cadb4bb8555..5bc8b3c00ed76ab07d1d39c2c5bb2f781316f5b9 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Wheels.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Wheels.cs @@ -17,7 +17,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _dynamicWheelRadius = rdyn; } - #region IRoadPortOutProvider + #region IFvOutProvider public IFvOutPort OutPort() { @@ -26,9 +26,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #endregion - #region IInShaft + #region ITnInProvider - public ITnInPort InShaft() + public ITnInPort InPort() { return this; } diff --git a/VectoCore/Utils/DoubleExtensionMethods.cs b/VectoCore/Utils/DoubleExtensionMethods.cs index 813c467d955da1a563f6c49f501a2c6d97f62b80..de76c92b7cfc0442ff134a6888610987e1ed3dfc 100644 --- a/VectoCore/Utils/DoubleExtensionMethods.cs +++ b/VectoCore/Utils/DoubleExtensionMethods.cs @@ -102,7 +102,7 @@ namespace TUGraz.VectoCore.Utils /// <returns></returns> public static SI SI(this double self) { - return (SI) self; + return (SI)self; } /// <summary> diff --git a/VectoCore/Utils/Formulas.cs b/VectoCore/Utils/Formulas.cs index 91debb47ea3ee1a000e9e11a9e1310ca52e2ce8a..5ec60523d3a3d9eabb2f4465a38a1849767bc556 100644 --- a/VectoCore/Utils/Formulas.cs +++ b/VectoCore/Utils/Formulas.cs @@ -24,7 +24,7 @@ namespace TUGraz.VectoCore.Utils /// <returns>torque [Nm]</returns> public static NewtonMeter PowerToTorque(Watt power, PerSecond angularVelocity) { - if (Math.Abs(angularVelocity.Double()) < 1E-10) { + if (Math.Abs(angularVelocity.Value()) < 1E-10) { throw new VectoSimulationException("Can not compute Torque for 0 angular Velocity!"); } return power / angularVelocity; diff --git a/VectoCore/Utils/SI.cs b/VectoCore/Utils/SI.cs index b5e21f5c96720378b4a1c8b7357dc1c0562747f5..9905dcf27682b7474dd0d693ae64b95b7ebc3f70 100644 --- a/VectoCore/Utils/SI.cs +++ b/VectoCore/Utils/SI.cs @@ -15,7 +15,7 @@ namespace TUGraz.VectoCore.Utils { static Newton() { - Constructors.Add(typeof (Newton), val => new Newton(val)); + Constructors.Add(typeof(Newton), val => new Newton(val)); } [JsonConstructor] @@ -31,7 +31,7 @@ namespace TUGraz.VectoCore.Utils { static Radian() { - Constructors.Add(typeof (Radian), val => new Radian(val)); + Constructors.Add(typeof(Radian), val => new Radian(val)); } [JsonConstructor] @@ -43,7 +43,7 @@ namespace TUGraz.VectoCore.Utils { static MeterPerSquareSecond() { - Constructors.Add(typeof (MeterPerSquareSecond), val => new MeterPerSquareSecond(val)); + Constructors.Add(typeof(MeterPerSquareSecond), val => new MeterPerSquareSecond(val)); } protected MeterPerSquareSecond(double val) : base(new SI(val).Meter.Per.Square.Second) {} @@ -53,7 +53,7 @@ namespace TUGraz.VectoCore.Utils { static Second() { - Constructors.Add(typeof (Second), val => new Second(val)); + Constructors.Add(typeof(Second), val => new Second(val)); } [JsonConstructor] @@ -64,7 +64,7 @@ namespace TUGraz.VectoCore.Utils { static Meter() { - Constructors.Add(typeof (Meter), val => new Meter(val)); + Constructors.Add(typeof(Meter), val => new Meter(val)); } protected Meter(double val) : base(new SI(val).Meter) {} @@ -74,7 +74,7 @@ namespace TUGraz.VectoCore.Utils { static Ton() { - Constructors.Add(typeof (Ton), val => new Ton(val)); + Constructors.Add(typeof(Ton), val => new Ton(val)); } [JsonConstructor] @@ -86,7 +86,7 @@ namespace TUGraz.VectoCore.Utils { static Kilogram() { - Constructors.Add(typeof (Kilogram), val => new Kilogram(val)); + Constructors.Add(typeof(Kilogram), val => new Kilogram(val)); } [JsonConstructor] @@ -97,7 +97,7 @@ namespace TUGraz.VectoCore.Utils { static SquareMeter() { - Constructors.Add(typeof (SquareMeter), val => new SquareMeter(val)); + Constructors.Add(typeof(SquareMeter), val => new SquareMeter(val)); } [JsonConstructor] @@ -108,7 +108,7 @@ namespace TUGraz.VectoCore.Utils { static CubicMeter() { - Constructors.Add(typeof (CubicMeter), val => new CubicMeter(val)); + Constructors.Add(typeof(CubicMeter), val => new CubicMeter(val)); } [JsonConstructor] @@ -119,7 +119,7 @@ namespace TUGraz.VectoCore.Utils { static KilogramSquareMeter() { - Constructors.Add(typeof (KilogramSquareMeter), val => new KilogramSquareMeter(val)); + Constructors.Add(typeof(KilogramSquareMeter), val => new KilogramSquareMeter(val)); } [JsonConstructor] @@ -130,7 +130,7 @@ namespace TUGraz.VectoCore.Utils { static KilogramPerWattSecond() { - Constructors.Add(typeof (KilogramPerWattSecond), val => new KilogramPerWattSecond(val)); + Constructors.Add(typeof(KilogramPerWattSecond), val => new KilogramPerWattSecond(val)); } [JsonConstructor] @@ -141,7 +141,7 @@ namespace TUGraz.VectoCore.Utils { static Watt() { - Constructors.Add(typeof (Watt), val => new Watt(val)); + Constructors.Add(typeof(Watt), val => new Watt(val)); } [JsonConstructor] @@ -162,7 +162,7 @@ namespace TUGraz.VectoCore.Utils { static PerSecond() { - Constructors.Add(typeof (PerSecond), val => new PerSecond(val)); + Constructors.Add(typeof(PerSecond), val => new PerSecond(val)); } [JsonConstructor] @@ -173,7 +173,7 @@ namespace TUGraz.VectoCore.Utils { static MeterPerSecond() { - Constructors.Add(typeof (MeterPerSecond), val => new MeterPerSecond(val)); + Constructors.Add(typeof(MeterPerSecond), val => new MeterPerSecond(val)); } [JsonConstructor] @@ -191,7 +191,7 @@ namespace TUGraz.VectoCore.Utils { static RoundsPerMinute() { - Constructors.Add(typeof (RoundsPerMinute), val => new RoundsPerMinute(val)); + Constructors.Add(typeof(RoundsPerMinute), val => new RoundsPerMinute(val)); } [JsonConstructor] @@ -203,7 +203,7 @@ namespace TUGraz.VectoCore.Utils { static NewtonMeter() { - Constructors.Add(typeof (NewtonMeter), val => new NewtonMeter(val)); + Constructors.Add(typeof(NewtonMeter), val => new NewtonMeter(val)); } [JsonConstructor] @@ -237,8 +237,8 @@ namespace TUGraz.VectoCore.Utils public static T Create(double val) { - RuntimeHelpers.RunClassConstructor(typeof (T).TypeHandle); - return Constructors[typeof (T)](val); + RuntimeHelpers.RunClassConstructor(typeof(T).TypeHandle); + return Constructors[typeof(T)](val); } protected SIBase(Type type, Func<double, T> constructor) @@ -535,12 +535,12 @@ namespace TUGraz.VectoCore.Utils /// <summary> /// Gets the basic double value. /// </summary> - public double Double() + public double Value() { return Val; } - public SI Value() + public SI Clone() { return new SI(Val, Numerator, Denominator); } @@ -971,6 +971,16 @@ namespace TUGraz.VectoCore.Utils return other != null && Val.Equals(other.Val) && HasEqualUnit(other); } + public bool IsEqual(SI si, double tolerance = DoubleExtensionMethods.Tolerance) + { + return HasEqualUnit(si) && Val.IsEqual(si.Val, tolerance); + } + + public bool IsEqual(double val, double tolerance = DoubleExtensionMethods.Tolerance) + { + return Val.IsEqual(val, tolerance); + } + public override int GetHashCode() { unchecked { diff --git a/VectoCore/VectoCore.csproj b/VectoCore/VectoCore.csproj index c61527e774ef8e409942450c1c8cf4294cd71182..9b25846302390e9c49284b6174cfc03d074c97cc 100644 --- a/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore.csproj @@ -129,13 +129,8 @@ <Compile Include="FileIO\Reader\ISimulationDataReader.cs" /> <Compile Include="FileIO\VectoFiles.cs" /> <Compile Include="Models\Connector\Ports\IDriverDemandPort.cs" /> - <Compile Include="Models\Connector\Ports\IDriverDemandProvider.cs" /> - <Compile Include="Models\Connector\Ports\IDrivingCycleDemandPort.cs" /> - <Compile Include="Models\Connector\Ports\IDrivingCycleProvider.cs" /> - <Compile Include="Models\Connector\Ports\IDrivingCycleDemandProvider.cs" /> + <Compile Include="Models\Connector\Ports\IDrivingCyclePort.cs" /> <Compile Include="Models\Connector\Ports\IResponse.cs" /> - <Compile Include="Models\Connector\Ports\IRoadPortProvider.cs" /> - <Compile Include="Models\Connector\Ports\IShaft.cs" /> <Compile Include="Models\Connector\Ports\Impl\Response.cs" /> <Compile Include="Models\Connector\Ports\IFvPort.cs" /> <Compile Include="Models\Connector\Ports\ITnPort.cs" /> @@ -156,6 +151,7 @@ <Compile Include="Models\Declaration\Mission.cs" /> <Compile Include="Models\Declaration\MissionType.cs" /> <Compile Include="Models\SimulationComponent\Data\Engine\PT1Curve.cs" /> + <Compile Include="Models\Simulation\Impl\DistanceRun.cs" /> <Compile Include="Models\Simulation\Impl\PowertrainBuilder.cs" /> <Compile Include="Utils\DataTableExtensionMethods.cs" /> <Compile Include="Utils\RessourceHelper.cs" /> @@ -180,7 +176,7 @@ <Compile Include="Models\SimulationComponent\Data\VehicleData.cs" /> <Compile Include="Models\SimulationComponent\IClutch.cs" /> <Compile Include="Models\SimulationComponent\IEngineOnlyDrivingCycle.cs" /> - <Compile Include="Models\SimulationComponent\IDriverDemandDrivingCycle.cs" /> + <Compile Include="Models\SimulationComponent\IDrivingCycle.cs" /> <Compile Include="Models\SimulationComponent\IDriver.cs" /> <Compile Include="Models\SimulationComponent\Impl\MappingAuxiliary.cs" /> <Compile Include="Models\SimulationComponent\Impl\Vehicle.cs" /> @@ -203,7 +199,7 @@ <Compile Include="Models\SimulationComponent\IAuxiliary.cs" /> <Compile Include="Models\SimulationComponent\ICombustionEngine.cs" /> <Compile Include="Models\SimulationComponent\IGearbox.cs" /> - <Compile Include="Models\Connector\Ports\IDrivingCyclePort.cs" /> + <Compile Include="Models\Connector\Ports\ISimulationPort.cs" /> <Compile Include="Models\SimulationComponent\Impl\DistanceBasedDrivingCycle.cs" /> <Compile Include="Models\SimulationComponent\Impl\DirectAuxiliary.cs" /> <Compile Include="Models\SimulationComponent\Impl\TimeBasedDrivingCycle.cs" /> @@ -260,8 +256,10 @@ <EmbeddedResource Include="Resources\Declaration\VAUX\PS-Table.csv" /> <EmbeddedResource Include="Resources\Declaration\VAUX\SP-Table.csv" /> <EmbeddedResource Include="Resources\Declaration\VAUX\SP-Tech.csv" /> + <EmbeddedResource Include="Resources\Declaration\DefaultTC.vtcc" /> <None Include="Resources\Declaration\VCDV\parameters.csv" /> <EmbeddedResource Include="Resources\Declaration\WHTC-Weighting-Factors.csv" /> + <EmbeddedResource Include="Resources\Declaration\WHTC.csv" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. diff --git a/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs b/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs index aef1232210951a464c18f8c7daa20a6d87682291..96f73a4d2e9fc62fa83ff7ad713727c1d7e77d1f 100644 --- a/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs +++ b/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs @@ -34,9 +34,9 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle var engine = new CombustionEngine(vehicle, engineData); - aux.InShaft().Connect(engine.OutShaft()); - gearbox.InShaft().Connect(aux.OutShaft()); - var port = aux.OutShaft(); + aux.InPort().Connect(engine.OutPort()); + gearbox.InPort().Connect(aux.OutPort()); + var port = aux.OutPort(); // IVectoJob job = SimulationFactory.CreateTimeBasedEngineOnlyRun(TestContext.DataRow["EngineFile"].ToString(), // TestContext.DataRow["CycleFile"].ToString(), "test2.csv"); @@ -98,7 +98,7 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle var engine = new CombustionEngine(vehicleContainer, EngineeringModeSimulationDataReader.CreateEngineDataFromFile(EngineFile)); - gearbox.InShaft().Connect(engine.OutShaft()); + gearbox.InPort().Connect(engine.OutPort()); var absTime = new TimeSpan(); var dt = TimeSpan.FromSeconds(1); @@ -106,7 +106,7 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle var angularVelocity = 644.4445.RPMtoRad(); var power = 2329.973.SI<Watt>(); - gearbox.OutShaft().Request(absTime, dt, Formulas.PowerToTorque(power, angularVelocity), angularVelocity); + gearbox.OutPort().Request(absTime, dt, Formulas.PowerToTorque(power, angularVelocity), angularVelocity); foreach (var sc in vehicleContainer.SimulationComponents()) { sc.CommitSimulationStep(dataWriter); diff --git a/VectoCoreTest/Integration/SimulationRuns/MinimalPowertrain.cs b/VectoCoreTest/Integration/SimulationRuns/MinimalPowertrain.cs new file mode 100644 index 0000000000000000000000000000000000000000..89c6c41155db10326c4f255c2b32f6bd4706a975 --- /dev/null +++ b/VectoCoreTest/Integration/SimulationRuns/MinimalPowertrain.cs @@ -0,0 +1,94 @@ +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TUGraz.VectoCore.FileIO.Reader.Impl; +using TUGraz.VectoCore.Models.Connector.Ports; +using TUGraz.VectoCore.Models.Declaration; +using TUGraz.VectoCore.Models.Simulation.Impl; +using TUGraz.VectoCore.Models.SimulationComponent; +using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; +using TUGraz.VectoCore.Tests.Utils; +using TUGraz.VectoCore.Utils; +using Wheels = TUGraz.VectoCore.Models.SimulationComponent.Impl.Wheels; + +namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns +{ + [TestClass] + public class MinimalPowertrain + { + public const string CycleFile = @"TestData\Cycles\Coach_24t_xshort.vdri"; + public const string EngineFile = @"TestData\Components\24t Coach.veng"; + + [TestMethod] + public void TestWheelsAndEngine() + { + var engineData = EngineeringModeSimulationDataReader.CreateEngineDataFromFile(EngineFile); + var cycleData = DrivingCycleData.ReadFromFileDistanceBased(CycleFile); + + var vehicleData = new VehicleData() { + AxleConfiguration = AxleConfiguration.AxleConfig_4x2, + CrossSectionArea = 0.SI<SquareMeter>(), + CrossWindCorrectionMode = CrossWindCorrectionMode.NoCorrection, + CurbWeight = 1000.SI<Kilogram>(), + CurbWeigthExtra = 0.SI<Kilogram>(), + Loading = 0.SI<Kilogram>(), + DynamicTyreRadius = 0.56.SI<Meter>(), + Retarder = new RetarderData() { Type = RetarderData.RetarderType.None }, + AxleData = new List<Axle>(), + SavedInDeclarationMode = false, + }; + + var vehicleContainer = new VehicleContainer(); + + var cycle = new DistanceBasedDrivingCycle(vehicleContainer, cycleData); + + dynamic tmp = AddComponent(cycle, new MockDriver(vehicleContainer)); + tmp = AddComponent(tmp, new Vehicle(vehicleContainer, vehicleData)); + tmp = AddComponent(tmp, new Wheels(vehicleContainer, vehicleData.DynamicTyreRadius)); + AddComponent(tmp, new CombustionEngine(vehicleContainer, engineData)); + + var run = new DistanceRun(vehicleContainer); + + run.Run(); + } + + + // ======================== + + protected virtual IDriver AddComponent(IDrivingCycle prev, IDriver next) + { + prev.InPort().Connect(next.OutPort()); + return next; + } + + protected virtual IVehicle AddComponent(IDriver prev, IVehicle next) + { + prev.InPort().Connect(next.OutPort()); + return next; + } + + protected virtual IWheels AddComponent(IFvInProvider prev, IWheels next) + { + prev.InPort().Connect(next.OutPort()); + return next; + } + + + protected virtual void AddComponent(IWheels prev, ITnOutProvider next) + { + prev.InPort().Connect(next.OutPort()); + //return next; + } + + protected virtual IPowerTrainComponent AddComponent(IPowerTrainComponent prev, IPowerTrainComponent next) + { + prev.InPort().Connect(next.OutPort()); + return next; + } + + protected virtual void AddComponent(IPowerTrainComponent prev, ITnOutProvider next) + { + prev.InPort().Connect(next.OutPort()); + } + } +} \ No newline at end of file diff --git a/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs b/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs index f8babfb301d8c82ff54e57a7b21fb2ed5c0a5d5f..63d229b29581f37a74f1cac4f7686a5c545fd305 100644 --- a/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs +++ b/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs @@ -24,8 +24,8 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration var tmp = wheels.Lookup("285/70 R19.5"); - Assert.AreEqual(7.9, tmp.Inertia.Double(), Tolerance); - Assert.AreEqual(0.8943, tmp.DynamicTyreRadius.Double(), Tolerance); + Assert.AreEqual(7.9, tmp.Inertia.Value(), Tolerance); + Assert.AreEqual(0.8943, tmp.DynamicTyreRadius.Value(), Tolerance); Assert.AreEqual("b", tmp.SizeClass); } @@ -46,31 +46,31 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration var pt1 = DeclarationData.PT1; // FIXED POINTS - Assert.AreEqual(0, pt1.Lookup(400.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.47, pt1.Lookup(800.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.58, pt1.Lookup(1000.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.53, pt1.Lookup(1200.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.46, pt1.Lookup(1400.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.43, pt1.Lookup(1500.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.22, pt1.Lookup(1750.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.2, pt1.Lookup(1800.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.11, pt1.Lookup(2000.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.11, pt1.Lookup(2500.RPMtoRad()).Double(), Tolerance); + Assert.AreEqual(0, pt1.Lookup(400.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.47, pt1.Lookup(800.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.58, pt1.Lookup(1000.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.53, pt1.Lookup(1200.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.46, pt1.Lookup(1400.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.43, pt1.Lookup(1500.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.22, pt1.Lookup(1750.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.2, pt1.Lookup(1800.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.11, pt1.Lookup(2000.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.11, pt1.Lookup(2500.RPMtoRad()).Value(), Tolerance); // INTERPOLATE - Assert.AreEqual(0.235, pt1.Lookup(600.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.525, pt1.Lookup(900.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.555, pt1.Lookup(1100.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.495, pt1.Lookup(1300.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.445, pt1.Lookup(1450.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.325, pt1.Lookup(1625.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.21, pt1.Lookup(1775.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.155, pt1.Lookup(1900.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.11, pt1.Lookup(2250.RPMtoRad()).Double(), Tolerance); + Assert.AreEqual(0.235, pt1.Lookup(600.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.525, pt1.Lookup(900.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.555, pt1.Lookup(1100.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.495, pt1.Lookup(1300.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.445, pt1.Lookup(1450.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.325, pt1.Lookup(1625.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.21, pt1.Lookup(1775.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.155, pt1.Lookup(1900.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.11, pt1.Lookup(2250.RPMtoRad()).Value(), Tolerance); // EXTRAPOLATE - Assert.AreEqual(0.11, pt1.Lookup(3000.RPMtoRad()).Double(), Tolerance); + Assert.AreEqual(0.11, pt1.Lookup(3000.RPMtoRad()).Value(), Tolerance); AssertHelper.Exception<VectoException>(() => pt1.Lookup(200.RPMtoRad())); AssertHelper.Exception<VectoException>(() => pt1.Lookup(0.RPMtoRad())); } @@ -139,8 +139,8 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration var baseConsumption = es.Lookup(expectation.Mission, technologies: new string[] { }); var leds = es.Lookup(expectation.Mission, technologies: new[] { "LED lights" }); - Assert.AreEqual(expectation.Base, baseConsumption.Double(), Tolerance); - Assert.AreEqual(expectation.LED, leds.Double(), Tolerance); + Assert.AreEqual(expectation.Base, baseConsumption.Value(), Tolerance); + Assert.AreEqual(expectation.LED, leds.Value(), Tolerance); } } @@ -190,12 +190,12 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration for (var i = 0; i < missions.Length; i++) { // default tech Watt defaultValue = fan.Lookup(missions[i], ""); - Assert.AreEqual(expected[defaultFan][i], defaultValue.Double(), Tolerance); + Assert.AreEqual(expected[defaultFan][i], defaultValue.Value(), Tolerance); // all fan techs foreach (var expect in expected) { Watt value = fan.Lookup(missions[i], expect.Key); - Assert.AreEqual(expect.Value[i], value.Double(), Tolerance); + Assert.AreEqual(expect.Value[i], value.Value(), Tolerance); } } } @@ -223,7 +223,7 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration for (var i = 0; i < missions.Length; i++) { foreach (var expect in expected) { Watt value = hvac.Lookup(missions[i], expect.Key); - Assert.AreEqual(expect.Value[i], value.Double(), Tolerance); + Assert.AreEqual(expect.Value[i], value.Value(), Tolerance); } } } @@ -251,7 +251,7 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration for (var i = 0; i < missions.Length; i++) { foreach (var expect in expected) { Watt value = ps.Lookup(missions[i], expect.Key); - Assert.AreEqual(expect.Value[i], value.Double(), Tolerance); + Assert.AreEqual(expect.Value[i], value.Value(), Tolerance); } } } @@ -310,7 +310,7 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration var hdvClass = hdvClasses.Key; for (var i = 0; i < missions.Length; i++) { Watt value = sp.Lookup(missions[i], hdvClass, technology); - Assert.AreEqual(hdvClasses.Value[i], value.Double(), Tolerance); + Assert.AreEqual(hdvClasses.Value[i], value.Value(), Tolerance); } } } @@ -412,7 +412,7 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration // var gearboxData = factory.ReadGearboxData(job.GearboxFile); // var gearbox = new Gearbox(container, gearboxData); - // gearbox.InShaft().Connect(engine.OutShaft()); + // gearbox.InPort().Connect(engine.OutPort()); // // todo axleGear @@ -424,11 +424,11 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration // var driverData = new DriverData(); // var driver = new Driver(driverData); - // driver.InShaft().Connect(vehicle.OutShaft()); + // driver.InPort().Connect(vehicle.OutPort()); // var cycleData = DrivingCycleData.ReadFromFileEngineOnly(mission.CycleFile); - // var cycle = new DistanceBasedDrivingCycle(container, cycleData); - // cycle.InShaft().Connect(driver.OutShaft()); + // var cycle = new DistanceBasedSimulation(container, cycleData); + // cycle.InPort().Connect(driver.OutPort()); // var simulator = new VectoRun(container, cycle); // runs.Add(simulator); @@ -439,8 +439,8 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration public void EqualAcceleration(AccelerationCurveData data, double velocity, double acceleration, double deceleration) { var entry = data.Lookup(velocity.SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>()); - Assert.AreEqual(entry.Acceleration.Double(), acceleration, Tolerance); - Assert.AreEqual(entry.Deceleration.Double(), deceleration, Tolerance); + Assert.AreEqual(entry.Acceleration.Value(), acceleration, Tolerance); + Assert.AreEqual(entry.Deceleration.Value(), deceleration, Tolerance); } public void TestAcceleration(AccelerationCurveData data) diff --git a/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs b/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs index 8937390ef9fbe32cdaeecd696fab71333952df47..31ba15de08dba48583fad26b1f3bf60c1e5465f5 100644 --- a/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs +++ b/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs @@ -20,11 +20,11 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation var container = new VehicleContainer(dataWriter, sumWriter); var cycleData = DrivingCycleData.ReadFromFileEngineOnly(@"TestData\Cycles\Coach Engine Only.vdri"); - var cycle = new EngineOnlyDrivingCycle(container, cycleData); + var cycle = new EngineOnlySimulation(container, cycleData); var outPort = new MockTnOutPort(); - var inPort = cycle.InShaft(); - var cycleOut = cycle.OutShaft(); + var inPort = cycle.InPort(); + var cycleOut = cycle.OutPort(); inPort.Connect(outPort); @@ -50,21 +50,21 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation var container = new VehicleContainer(); var cycleData = DrivingCycleData.ReadFromFileEngineOnly(@"TestData\Cycles\Coach Engine Only Paux_var-dt.vdri"); - var cycle = new EngineOnlyDrivingCycle(container, cycleData); + var cycle = new EngineOnlySimulation(container, cycleData); var outPort = new MockTnOutPort(); - var inPort = cycle.InShaft(); + var inPort = cycle.InPort(); inPort.Connect(outPort); var absTime = TimeSpan.FromSeconds(10); var dt = TimeSpan.FromSeconds(1); - var response = cycle.OutShaft().Request(absTime, dt); + var response = cycle.OutPort().Request(absTime, dt); Assert.IsInstanceOfType(response, typeof(ResponseFailTimeInterval)); dt = TimeSpan.FromSeconds(0.25); - response = cycle.OutShaft().Request(absTime, dt); + response = cycle.OutPort().Request(absTime, dt); Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); var dataWriter = new TestModalDataWriter(); @@ -79,13 +79,13 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation dt = TimeSpan.FromSeconds(1); absTime = TimeSpan.FromSeconds(500); - response = cycle.OutShaft().Request(absTime, dt); + response = cycle.OutPort().Request(absTime, dt); Assert.IsInstanceOfType(response, typeof(ResponseFailTimeInterval)); dt = TimeSpan.FromSeconds(0.25); for (int i = 0; i < 2; i++) { - response = cycle.OutShaft().Request(absTime, dt); + response = cycle.OutPort().Request(absTime, dt); Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); dataWriter = new TestModalDataWriter(); @@ -111,10 +111,10 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation var cycleData = DrivingCycleData.ReadFromFileTimeBased(@"TestData\Cycles\Coach First Cycle only.vdri"); var cycle = new TimeBasedDrivingCycle(container, cycleData); - var outPort = new MockDrivingCycleDemandOutPort(); + var outPort = new MockDrivingCycleOutPort(); - var inPort = cycle.InShaft(); - var cycleOut = cycle.OutShaft(); + var inPort = cycle.InPort(); + var cycleOut = cycle.OutPort(); inPort.Connect(outPort); @@ -125,9 +125,9 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); Assert.AreEqual(absTime, outPort.AbsTime); - Assert.AreEqual(dt, outPort.Dt); + //Assert.AreEqual(dt, outPort.Ds); Assert.AreEqual(0.SI<MeterPerSecond>(), outPort.Velocity); - Assert.AreEqual((-0.020237973).SI().GradientPercent.Cast<Radian>(), outPort.Gradient); + Assert.AreEqual(-0.000202379727237.SI<Radian>().Value(), outPort.Gradient.Value(), 1E-15); } [TestMethod] @@ -138,10 +138,10 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation var cycleData = DrivingCycleData.ReadFromFileTimeBased(@"TestData\Cycles\Cycle time field missing.vdri"); var cycle = new TimeBasedDrivingCycle(container, cycleData); - var outPort = new MockDrivingCycleDemandOutPort(); + var outPort = new MockDrivingCycleOutPort(); - var inPort = cycle.InShaft(); - var cycleOut = cycle.OutShaft(); + var inPort = cycle.InPort(); + var cycleOut = cycle.OutPort(); inPort.Connect(outPort); @@ -151,7 +151,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation while (cycleOut.Request(absTime, dt) is ResponseSuccess) { Assert.AreEqual(absTime, outPort.AbsTime); - Assert.AreEqual(dt, outPort.Dt); + Assert.AreEqual(dt, outPort.Ds); var time = (absTime + TimeSpan.FromTicks(dt.Ticks / 2)).TotalSeconds; var simulationInterval = dt.TotalSeconds; diff --git a/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs b/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs index 66d3a71c4c83821964084c278a181d99d34b2f91..0d928530059fc860de382f2ce1d9b0eba283a659 100644 --- a/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs @@ -24,33 +24,33 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var clutch = new Clutch(vehicle, engineData); - var inPort = clutch.InShaft(); + var inPort = clutch.InPort(); var outPort = new MockTnOutPort(); inPort.Connect(outPort); - var clutchOutPort = clutch.OutShaft(); + var clutchOutPort = clutch.OutPort(); //Test - Clutch slipping gearbox.CurrentGear = 1; clutchOutPort.Request(new TimeSpan(), new TimeSpan(), 100.SI<NewtonMeter>(), 30.SI<PerSecond>()); - Assert.AreEqual(48.293649, (double) outPort.Torque, 0.001); - Assert.AreEqual(62.119969, (double) outPort.AngularVelocity, 0.001); + Assert.AreEqual(48.293649, (double)outPort.Torque, 0.001); + Assert.AreEqual(62.119969, (double)outPort.AngularVelocity, 0.001); //Test - Clutch opened gearbox.CurrentGear = 0; clutchOutPort.Request(new TimeSpan(), new TimeSpan(), 100.SI<NewtonMeter>(), 30.SI<PerSecond>()); - Assert.AreEqual(0, (double) outPort.Torque, 0.001); - Assert.AreEqual((double) engineData.IdleSpeed, (double) outPort.AngularVelocity, 0.001); + Assert.AreEqual(0, (double)outPort.Torque, 0.001); + Assert.AreEqual((double)engineData.IdleSpeed, (double)outPort.AngularVelocity, 0.001); //Test - Clutch closed gearbox.CurrentGear = 1; clutchOutPort.Request(new TimeSpan(), new TimeSpan(), 100.SI<NewtonMeter>(), 80.SI<PerSecond>()); - Assert.AreEqual(100.0, (double) outPort.Torque, 0.001); - Assert.AreEqual(80.0, (double) outPort.AngularVelocity, 0.001); + Assert.AreEqual(100.0, (double)outPort.Torque, 0.001); + Assert.AreEqual(80.0, (double)outPort.AngularVelocity, 0.001); } } } \ No newline at end of file diff --git a/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs b/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs index d94e883ceb8aa3e21f3e81a9116378e8efe995ac..769647c0e1558768079ca4fa3c266aedd464d04a 100644 --- a/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs @@ -36,7 +36,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent { try { func(); - Assert.Fail("Expected Exception {0}, but no exception occured.", typeof (T)); + Assert.Fail("Expected Exception {0}, but no exception occured.", typeof(T)); } catch (T ex) { if (message != null) { Assert.AreEqual(message, ex.Message); @@ -51,7 +51,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var engineData = EngineeringModeSimulationDataReader.CreateEngineDataFromFile(CoachEngine); var engine = new CombustionEngine(vehicle, engineData); - var port = engine.OutShaft(); + var port = engine.OutPort(); Assert.IsNotNull(port); } @@ -64,7 +64,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent new EngineOnlyGearbox(vehicle); - var port = engine.OutShaft(); + var port = engine.OutPort(); var absTime = new TimeSpan(seconds: 0, minutes: 0, hours: 0); var dt = new TimeSpan(seconds: 1, minutes: 0, hours: 0); @@ -81,7 +81,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var engineData = EngineeringModeSimulationDataReader.CreateEngineDataFromFile(CoachEngine); var engine = new CombustionEngine(vehicle, engineData); var gearbox = new EngineOnlyGearbox(vehicle); - var port = engine.OutShaft(); + var port = engine.OutPort(); var absTime = new TimeSpan(seconds: 0, minutes: 0, hours: 0); var dt = new TimeSpan(seconds: 1, minutes: 0, hours: 0); @@ -150,11 +150,11 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent TestContext.DataRow["EngineFile"].ToString()); var engine = new CombustionEngine(vehicleContainer, engineData); - gearbox.InShaft().Connect(engine.OutShaft()); + gearbox.InPort().Connect(engine.OutPort()); var expectedResults = VectoCSVFile.Read(TestContext.DataRow["ResultFile"].ToString()); - var requestPort = gearbox.OutShaft(); + var requestPort = gearbox.OutPort(); //var modalData = new ModalDataWriter(string.Format("load_jump_{0}.csv", TestContext.DataRow["TestName"].ToString())); var modalData = new TestModalDataWriter(); @@ -210,27 +210,27 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent { var engineData = EngineeringModeSimulationDataReader.CreateEngineDataFromFile(CoachEngine); var motorway = engineData.WHTCMotorway; - Assert.AreEqual(motorway.Double(), 0); + Assert.AreEqual(motorway.Value(), 0); Assert.IsTrue(motorway.HasEqualUnit(new SI().Kilo.Gramm.Per.Watt.Second.ConvertTo())); var rural = engineData.WHTCRural; - Assert.AreEqual(rural.Double(), 0); + Assert.AreEqual(rural.Value(), 0); Assert.IsTrue(rural.HasEqualUnit(new SI().Kilo.Gramm.Per.Watt.Second.ConvertTo())); var urban = engineData.WHTCUrban; - Assert.AreEqual(urban.Double(), 0); + Assert.AreEqual(urban.Value(), 0); Assert.IsTrue(urban.HasEqualUnit(new SI().Kilo.Gramm.Per.Watt.Second.ConvertTo())); var displace = engineData.Displacement; - Assert.AreEqual(0.01273, displace.Double()); + Assert.AreEqual(0.01273, displace.Value()); Assert.IsTrue(displace.HasEqualUnit(new SI().Cubic.Meter)); var inert = engineData.Inertia; - Assert.AreEqual(3.8, inert.Double(), 0.00001); + Assert.AreEqual(3.8, inert.Value(), 0.00001); Assert.IsTrue(inert.HasEqualUnit(new SI().Kilo.Gramm.Square.Meter)); var idle = engineData.IdleSpeed; - Assert.AreEqual(58.6430628670095, idle.Double(), 0.000001); + Assert.AreEqual(58.6430628670095, idle.Value(), 0.000001); Assert.IsTrue(idle.HasEqualUnit(0.SI<PerSecond>())); var flc0 = engineData.GetFullLoadCurve(0); diff --git a/VectoCoreTest/Models/SimulationComponent/DistanceBasedDrivingCycleTest.cs b/VectoCoreTest/Models/SimulationComponent/DistanceBasedDrivingCycleTest.cs new file mode 100644 index 0000000000000000000000000000000000000000..9fbc718a8b409e087ea6ff05ea73020e99a40e56 --- /dev/null +++ b/VectoCoreTest/Models/SimulationComponent/DistanceBasedDrivingCycleTest.cs @@ -0,0 +1,41 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TUGraz.VectoCore.FileIO.Reader.Impl; +using TUGraz.VectoCore.Models.Connector.Ports.Impl; +using TUGraz.VectoCore.Models.Simulation.Impl; +using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; +using TUGraz.VectoCore.Tests.Utils; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Tests.Models.SimulationComponent +{ + [TestClass] + public class DistanceBasedDrivingCycleTest + { + public const string ShortCycle = @"TestData\Cycles\Coach_24t_xshort.vdri"; + + public const double Tolerance = 0.0001; + + [TestMethod] + public void TestDistanceRequest() + { + var cycleData = DrivingCycleData.ReadFromFile(ShortCycle, DrivingCycleData.CycleType.DistanceBased); + + var vehicleContainer = new VehicleContainer(); + var cycle = new DistanceBasedDrivingCycle(vehicleContainer, cycleData); + + var driver = new MockDriver(vehicleContainer); + cycle.InPort().Connect(driver.OutPort()); + + cycle.OutPort().Initialize(); + + var response = cycle.OutPort().Request(TimeSpan.FromSeconds(0), 1.SI<Meter>()); + + Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); + + Assert.AreEqual(0, driver.LastRequest.TargetVelocity.Value(), Tolerance); + Assert.AreEqual(0.028416069495827, driver.LastRequest.Gradient.Value(), 1E-12); + } + } +} \ No newline at end of file diff --git a/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs b/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs index c8922b7c49bac3a69481b85cd0a26a1bdddc1d7d..77db5e33089ef5997947a8f4a5818894c5e2e50e 100644 --- a/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs @@ -25,7 +25,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var axleGear = new AxleGear(vehicle, gbxData.AxleGearData); var mockPort = new MockTnOutPort(); - axleGear.InShaft().Connect(mockPort); + axleGear.InPort().Connect(mockPort); var absTime = TimeSpan.FromSeconds(0); var dt = TimeSpan.FromSeconds(1); @@ -45,11 +45,11 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var loss = 9401.44062.SI<Watt>(); - Assert.AreEqual(Formulas.PowerToTorque(PvD + loss, angSpeed * gbxData.AxleGearData.Ratio).Double(), - mockPort.Torque.Double(), 0.01, + Assert.AreEqual(Formulas.PowerToTorque(PvD + loss, angSpeed * gbxData.AxleGearData.Ratio).Value(), + mockPort.Torque.Value(), 0.01, "Torque Engine Side") ; - Assert.AreEqual((angSpeed * gbxData.AxleGearData.Ratio).Double(), mockPort.AngularVelocity.Double(), 0.01, + Assert.AreEqual((angSpeed * gbxData.AxleGearData.Ratio).Value(), mockPort.AngularVelocity.Value(), 0.01, "Torque Engine Side"); } diff --git a/VectoCoreTest/Models/SimulationComponent/RetarderTest.cs b/VectoCoreTest/Models/SimulationComponent/RetarderTest.cs index 281c443f8edce7e245b7813092a6cd5bbce0bfe0..522ff647526cf2f99e7b67c5ae117684d11674b6 100644 --- a/VectoCoreTest/Models/SimulationComponent/RetarderTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/RetarderTest.cs @@ -23,8 +23,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var nextRequest = new MockTnOutPort(); - retarder.InShaft().Connect(nextRequest); - var outPort = retarder.OutShaft(); + retarder.InPort().Connect(nextRequest); + var outPort = retarder.OutPort(); var absTime = TimeSpan.FromSeconds(0); var dt = TimeSpan.FromSeconds(0); @@ -32,20 +32,20 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent // -------- outPort.Request(absTime, dt, 0.SI<NewtonMeter>(), 10.RPMtoRad()); - Assert.AreEqual(10.RPMtoRad().Double(), (double)nextRequest.AngularVelocity, Delta); + Assert.AreEqual(10.RPMtoRad().Value(), (double)nextRequest.AngularVelocity, Delta); Assert.AreEqual(10.002, (double)nextRequest.Torque, Delta); // -------- outPort.Request(absTime, dt, 100.SI<NewtonMeter>(), 1000.RPMtoRad()); - Assert.AreEqual(1000.RPMtoRad().Double(), (double)nextRequest.AngularVelocity, Delta); + Assert.AreEqual(1000.RPMtoRad().Value(), (double)nextRequest.AngularVelocity, Delta); Assert.AreEqual(112, (double)nextRequest.Torque, Delta); // -------- outPort.Request(absTime, dt, 50.SI<NewtonMeter>(), 1550.RPMtoRad()); - Assert.AreEqual(1550.RPMtoRad().Double(), (double)nextRequest.AngularVelocity, Delta); + Assert.AreEqual(1550.RPMtoRad().Value(), (double)nextRequest.AngularVelocity, Delta); Assert.AreEqual(50 + 14.81, (double)nextRequest.Torque, Delta); } } diff --git a/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs b/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs index ba91afff4bc0cab54ac3d23b84279781400cb595..2b26d8a344d09d64bf3c4d8d6009143963b5525f 100644 --- a/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs @@ -28,7 +28,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent vehicle.InPort().Connect(mockPort); - var requestPort = vehicle.OutShaft(); + var requestPort = vehicle.OutPort(); var absTime = TimeSpan.FromSeconds(0); var dt = TimeSpan.FromSeconds(1); @@ -38,8 +38,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var retVal = requestPort.Request(absTime, dt, accell, gradient); - Assert.AreEqual(-2549.07832743748, mockPort.Force.Double(), 0.0001); - Assert.AreEqual(17.0824194205, mockPort.Velocity.Double(), 0.0001); + Assert.AreEqual(-2549.07832743748, mockPort.Force.Value(), 0.0001); + Assert.AreEqual(17.0824194205, mockPort.Velocity.Value(), 0.0001); } } } \ No newline at end of file diff --git a/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs b/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs index 6898e6f147ff7002d9a6a933f9a95cfd853d855c..e599f1691278fb82adcc2ac7b2d75f4b73edeebb 100644 --- a/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs @@ -24,7 +24,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent IWheels wheels = new Wheels(container, vehicleData.DynamicTyreRadius); var mockPort = new MockTnOutPort(); - wheels.InShaft().Connect(mockPort); + wheels.InPort().Connect(mockPort); var requestPort = wheels.OutPort(); @@ -36,8 +36,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var retVal = requestPort.Request(absTime, dt, force, velocity); - Assert.AreEqual(2600.0, mockPort.Torque.Double(), 0.0001); - Assert.AreEqual(38.4615384615, mockPort.AngularVelocity.Double(), 0.0001); + Assert.AreEqual(2600.0, mockPort.Torque.Value(), 0.0001); + Assert.AreEqual(38.4615384615, mockPort.AngularVelocity.Value(), 0.0001); } } } \ No newline at end of file diff --git a/VectoCoreTest/Models/SimulationComponentData/AccelerationCurveTest.cs b/VectoCoreTest/Models/SimulationComponentData/AccelerationCurveTest.cs index 7519b6863fc4fdd98f69560d2a5adf84153b4555..8b4a72ee2c626628be489104f47a4e7730f14b1c 100644 --- a/VectoCoreTest/Models/SimulationComponentData/AccelerationCurveTest.cs +++ b/VectoCoreTest/Models/SimulationComponentData/AccelerationCurveTest.cs @@ -13,8 +13,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData public void EqualAcceleration(double velocity, double acceleration, double deceleration) { var entry = Data.Lookup(velocity.SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>()); - Assert.AreEqual(entry.Acceleration.Double(), acceleration, Tolerance); - Assert.AreEqual(entry.Deceleration.Double(), deceleration, Tolerance); + Assert.AreEqual(entry.Acceleration.Value(), acceleration, Tolerance); + Assert.AreEqual(entry.Deceleration.Value(), deceleration, Tolerance); } [TestMethod] diff --git a/VectoCoreTest/Models/SimulationComponentData/FullLoadCurveTest.cs b/VectoCoreTest/Models/SimulationComponentData/FullLoadCurveTest.cs index 6fd37e3f8da440676134d7f94abe2685916bf337..79d610acec527ff143eb1946bd2cfd006d825338 100644 --- a/VectoCoreTest/Models/SimulationComponentData/FullLoadCurveTest.cs +++ b/VectoCoreTest/Models/SimulationComponentData/FullLoadCurveTest.cs @@ -17,9 +17,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData { var fldCurve = FullLoadCurve.ReadFromFile(CoachEngineFLD); - Assert.AreEqual(1180, fldCurve.FullLoadStationaryTorque(560.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(1352, fldCurve.FullLoadStationaryTorque(2000.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(1231, fldCurve.FullLoadStationaryTorque(580.RPMtoRad()).Double(), Tolerance); + Assert.AreEqual(1180, fldCurve.FullLoadStationaryTorque(560.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(1352, fldCurve.FullLoadStationaryTorque(2000.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(1231, fldCurve.FullLoadStationaryTorque(580.RPMtoRad()).Value(), Tolerance); } [TestMethod] @@ -34,9 +34,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData { var fldCurve = FullLoadCurve.ReadFromFile(CoachEngineFLD); - Assert.AreEqual(69198.814183, fldCurve.FullLoadStationaryPower(560.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(283162.218372, fldCurve.FullLoadStationaryPower(2000.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(74767.810760, fldCurve.FullLoadStationaryPower(580.RPMtoRad()).Double(), Tolerance); + Assert.AreEqual(69198.814183, fldCurve.FullLoadStationaryPower(560.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(283162.218372, fldCurve.FullLoadStationaryPower(2000.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(74767.810760, fldCurve.FullLoadStationaryPower(580.RPMtoRad()).Value(), Tolerance); } [TestMethod] @@ -44,11 +44,11 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData { var fldCurve = FullLoadCurve.ReadFromFile(CoachEngineFLD); - Assert.AreEqual(-149, fldCurve.DragLoadStationaryTorque(560.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(-301, fldCurve.DragLoadStationaryTorque(2000.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(-148.5, fldCurve.DragLoadStationaryTorque(580.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(-150, fldCurve.DragLoadStationaryTorque(520.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(-339, fldCurve.DragLoadStationaryTorque(2200.RPMtoRad()).Double(), Tolerance); + Assert.AreEqual(-149, fldCurve.DragLoadStationaryTorque(560.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(-301, fldCurve.DragLoadStationaryTorque(2000.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(-148.5, fldCurve.DragLoadStationaryTorque(580.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(-150, fldCurve.DragLoadStationaryTorque(520.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(-339, fldCurve.DragLoadStationaryTorque(2200.RPMtoRad()).Value(), Tolerance); } [TestMethod] @@ -56,9 +56,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData { var fldCurve = FullLoadCurve.ReadFromFile(CoachEngineFLD); - Assert.AreEqual(-8737.81636, fldCurve.DragLoadStationaryPower(560.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(-63041.29254, fldCurve.DragLoadStationaryPower(2000.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(-9019.51251, fldCurve.DragLoadStationaryPower(580.RPMtoRad()).Double(), Tolerance); + Assert.AreEqual(-8737.81636, fldCurve.DragLoadStationaryPower(560.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(-63041.29254, fldCurve.DragLoadStationaryPower(2000.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(-9019.51251, fldCurve.DragLoadStationaryPower(580.RPMtoRad()).Value(), Tolerance); } [TestMethod] @@ -66,9 +66,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData { var fldCurve = FullLoadCurve.ReadFromFile(CoachEngineFLD); - Assert.AreEqual(0.6, fldCurve.PT1(560.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.25, fldCurve.PT1(2000.RPMtoRad()).Double(), Tolerance); - Assert.AreEqual(0.37, fldCurve.PT1(1700.RPMtoRad()).Double(), Tolerance); + Assert.AreEqual(0.6, fldCurve.PT1(560.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.25, fldCurve.PT1(2000.RPMtoRad()).Value(), Tolerance); + Assert.AreEqual(0.37, fldCurve.PT1(1700.RPMtoRad()).Value(), Tolerance); } /// <summary> @@ -100,7 +100,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData { var curve = FullLoadCurve.ReadFromFile(@"TestData\Components\FullLoadCurve no header.vfld"); var result = curve.FullLoadStationaryTorque(1.SI<PerSecond>()); - Assert.AreNotEqual(result.Double(), 0.0); + Assert.AreNotEqual(result.Value(), 0.0); } /// <summary> diff --git a/VectoCoreTest/Models/SimulationComponentData/GearboxDataTest.cs b/VectoCoreTest/Models/SimulationComponentData/GearboxDataTest.cs index 7c8b8bd21f292f707bb5946256b71f87905ed3ce..3b44f37b1fdc8d80122c8671c078ea6ca9158da7 100644 --- a/VectoCoreTest/Models/SimulationComponentData/GearboxDataTest.cs +++ b/VectoCoreTest/Models/SimulationComponentData/GearboxDataTest.cs @@ -21,19 +21,19 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData var gbxData = EngineeringModeSimulationDataReader.CreateGearboxDataFromFile(GearboxFile); Assert.AreEqual(GearboxData.GearboxType.AMT, gbxData.Type); - Assert.AreEqual(1.0, gbxData.TractionInterruption.Double(), 0.0001); + Assert.AreEqual(1.0, gbxData.TractionInterruption.Value(), 0.0001); Assert.AreEqual(8, gbxData.GearsCount()); Assert.AreEqual(3.240355, gbxData.AxleGearData.Ratio, 0.0001); Assert.AreEqual(1.0, gbxData[7].Ratio, 0.0001); - Assert.AreEqual(-400, gbxData[1].ShiftPolygon.Downshift[0].Torque.Double(), 0.0001); - Assert.AreEqual(560.RPMtoRad().Double(), gbxData[1].ShiftPolygon.Downshift[0].AngularSpeed.Double(), 0.0001); - Assert.AreEqual(1289.RPMtoRad().Double(), gbxData[1].ShiftPolygon.Upshift[0].AngularSpeed.Double(), 0.0001); + Assert.AreEqual(-400, gbxData[1].ShiftPolygon.Downshift[0].Torque.Value(), 0.0001); + Assert.AreEqual(560.RPMtoRad().Value(), gbxData[1].ShiftPolygon.Downshift[0].AngularSpeed.Value(), 0.0001); + Assert.AreEqual(1289.RPMtoRad().Value(), gbxData[1].ShiftPolygon.Upshift[0].AngularSpeed.Value(), 0.0001); - Assert.AreEqual(200.RPMtoRad().Double(), gbxData[1].LossMap[15].InputSpeed.Double(), 0.0001); - Assert.AreEqual(-350, gbxData[1].LossMap[15].InputTorque.Double(), 0.0001); - Assert.AreEqual(13.072, gbxData[1].LossMap[15].TorqueLoss.Double(), 0.0001); + Assert.AreEqual(200.RPMtoRad().Value(), gbxData[1].LossMap[15].InputSpeed.Value(), 0.0001); + Assert.AreEqual(-350, gbxData[1].LossMap[15].InputTorque.Value(), 0.0001); + Assert.AreEqual(13.072, gbxData[1].LossMap[15].TorqueLoss.Value(), 0.0001); } [TestMethod] @@ -63,7 +63,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData var loss = powerEngine - PvD; Assert.AreEqual(Double.Parse(TestContext.DataRow["GbxPowerLoss"].ToString(), CultureInfo.InvariantCulture), - loss.Double(), 0.1, + loss.Value(), 0.1, TestContext.DataRow["TestName"].ToString()); } @@ -71,8 +71,6 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData public void TestInputOutOfRange() { var gbxData = EngineeringModeSimulationDataReader.CreateGearboxDataFromFile(GearboxFile); - - } protected PerSecond SpeedToAngularSpeed(double v, double r) diff --git a/VectoCoreTest/Utils/DoubleExtensionMethodTest.cs b/VectoCoreTest/Utils/DoubleExtensionMethodTest.cs index aba3daa14437402ec31a2b6c5deda74168f33747..6ba744238c711f9246adad2f9861e8b8ce226fcc 100644 --- a/VectoCoreTest/Utils/DoubleExtensionMethodTest.cs +++ b/VectoCoreTest/Utils/DoubleExtensionMethodTest.cs @@ -11,7 +11,7 @@ namespace TUGraz.VectoCore.Tests.Utils public void DoubleExtensions_SI() { var val = 600.RPMtoRad(); - Assert.AreEqual(600 / 60 * 2 * Math.PI, val.Double()); + Assert.AreEqual(600 / 60 * 2 * Math.PI, val.Value()); Assert.IsTrue(0.SI<PerSecond>().HasEqualUnit(val)); @@ -23,7 +23,7 @@ namespace TUGraz.VectoCore.Tests.Utils val = val / 2; Assert.AreEqual(val, val2); Assert.AreEqual(600.SI().Rounds.Per.Minute.Cast<PerSecond>(), val2); - Assert.AreEqual(600.SI().Rounds.Per.Minute.Cast<PerSecond>().Double(), val2.Double()); + Assert.AreEqual(600.SI().Rounds.Per.Minute.Cast<PerSecond>().Value(), val2.Value()); } [TestMethod] diff --git a/VectoCoreTest/Utils/DummyGearbox.cs b/VectoCoreTest/Utils/DummyGearbox.cs index e1e361018671d4a4e5e2f302c80707a4c81e06bf..d65c280bfb94fddf50226eda9e9a98ebb64c99f5 100644 --- a/VectoCoreTest/Utils/DummyGearbox.cs +++ b/VectoCoreTest/Utils/DummyGearbox.cs @@ -15,12 +15,12 @@ namespace TUGraz.VectoCore.Tests.Utils public DummyGearbox(IVehicleContainer cockpit) : base(cockpit) {} - public ITnInPort InShaft() + public ITnInPort InPort() { return this; } - public ITnOutPort OutShaft() + public ITnOutPort OutPort() { return this; } diff --git a/VectoCoreTest/Utils/MockDriver.cs b/VectoCoreTest/Utils/MockDriver.cs new file mode 100644 index 0000000000000000000000000000000000000000..00149fd180927538657fc7842bfdc8bd69298687 --- /dev/null +++ b/VectoCoreTest/Utils/MockDriver.cs @@ -0,0 +1,60 @@ +using System; +using TUGraz.VectoCore.Models.Connector.Ports; +using TUGraz.VectoCore.Models.Connector.Ports.Impl; +using TUGraz.VectoCore.Models.Simulation; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.SimulationComponent; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Tests.Utils +{ + public class MockDriver : VectoSimulationComponent, IDriver, IDrivingCycleOutPort, IDriverDemandInPort + { + private IDriverDemandOutPort _next; + + public RequestData LastRequest; + + public MockDriver(IVehicleContainer container) : base(container) {} + + public override void CommitSimulationStep(IModalDataWriter writer) {} + + + public IDrivingCycleOutPort OutPort() + { + return this; + } + + public IDriverDemandInPort InPort() + { + return this; + } + + public IResponse Request(TimeSpan absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) + { + LastRequest = new RequestData() { AbsTime = absTime, ds = ds, Gradient = gradient, TargetVelocity = targetVelocity }; + var acc = 0.SI<MeterPerSquareSecond>(); + return new ResponseSuccess(); //_next.Request(absTime, TimeSpan.FromSeconds(0), acc, 0.SI<Radian>()); + } + + public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond targetVelocity, Radian gradient) + { + LastRequest = new RequestData() { AbsTime = absTime, dt = dt, Gradient = gradient, TargetVelocity = targetVelocity }; + var acc = 0.SI<MeterPerSquareSecond>(); + return new ResponseSuccess(); //_next.Request(absTime, dt, acc, gradient); + } + + public void Connect(IDriverDemandOutPort other) + { + _next = other; + } + + public class RequestData + { + public TimeSpan AbsTime; + public Meter ds; + public TimeSpan dt; + public MeterPerSecond TargetVelocity; + public Radian Gradient; + } + } +} \ No newline at end of file diff --git a/VectoCoreTest/Utils/MockPorts.cs b/VectoCoreTest/Utils/MockPorts.cs index eeea54f924bc7ef78d162a44cfcb6f750b2a175b..a960a9f1402a34973135f81b05ad36b25f92c430 100644 --- a/VectoCoreTest/Utils/MockPorts.cs +++ b/VectoCoreTest/Utils/MockPorts.cs @@ -25,21 +25,34 @@ namespace TUGraz.VectoCore.Tests.Utils } } - public class MockDrivingCycleDemandOutPort : IDrivingCycleDemandOutPort + public class MockDrivingCycleOutPort : IDrivingCycleOutPort { public TimeSpan AbsTime { get; set; } + public Meter Ds { get; set; } + public TimeSpan Dt { get; set; } public MeterPerSecond Velocity { get; set; } public Radian Gradient { get; set; } - public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond velocity, Radian gradient) + public IResponse Request(TimeSpan absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) + { + AbsTime = absTime; + Ds = ds; + Velocity = targetVelocity; + Gradient = gradient; + LogManager.GetLogger(GetType()).DebugFormat("Request: absTime: {0}, ds: {1}, velocity: {2}, gradient: {3}", + absTime, ds, targetVelocity, gradient); + return new ResponseSuccess(); + } + + public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond targetVelocity, Radian gradient) { AbsTime = absTime; Dt = dt; - Velocity = velocity; + Velocity = targetVelocity; Gradient = gradient; - LogManager.GetLogger(GetType()).DebugFormat("Request: absTime: {0}, dt: {1}, velocity: {2}, gradient: {3}", - absTime, dt, velocity, gradient); + LogManager.GetLogger(GetType()).DebugFormat("Request: absTime: {0}, ds: {1}, velocity: {2}, gradient: {3}", + absTime, dt, targetVelocity, gradient); return new ResponseSuccess(); } } diff --git a/VectoCoreTest/Utils/SITest.cs b/VectoCoreTest/Utils/SITest.cs index 69f33eab2458c3d7e69bb9b0009cfb9b02aa53a7..48b3da99910d088e82bf9a14d10abcf4d0b9edf1 100644 --- a/VectoCoreTest/Utils/SITest.cs +++ b/VectoCoreTest/Utils/SITest.cs @@ -35,40 +35,40 @@ namespace TUGraz.VectoCore.Tests.Utils var torque = 1500.SI<NewtonMeter>(); var power = angularVelocity * torque; Assert.IsInstanceOfType(power, typeof(Watt)); - Assert.AreEqual(600.0 / 60 * 2 * Math.PI * 1500, power.Double()); + Assert.AreEqual(600.0 / 60 * 2 * Math.PI * 1500, power.Value()); var siStandardMult = power * torque; Assert.IsInstanceOfType(siStandardMult, typeof(SI)); - Assert.AreEqual(600.0 / 60 * 2 * Math.PI * 1500 * 1500, siStandardMult.Double()); + Assert.AreEqual(600.0 / 60 * 2 * Math.PI * 1500 * 1500, siStandardMult.Value()); Assert.IsTrue(siStandardMult.HasEqualUnit(new SI().Watt.Newton.Meter)); //div var torque2 = power / angularVelocity; Assert.IsInstanceOfType(torque2, typeof(NewtonMeter)); - Assert.AreEqual(1500, torque2.Double()); + Assert.AreEqual(1500, torque2.Value()); var siStandardDiv = power / power; Assert.IsInstanceOfType(siStandardMult, typeof(SI)); Assert.IsTrue(siStandardDiv.HasEqualUnit(new SI())); - Assert.AreEqual(600.0 / 60 * 2 * Math.PI * 1500 * 1500, siStandardMult.Double()); + Assert.AreEqual(600.0 / 60 * 2 * Math.PI * 1500 * 1500, siStandardMult.Value()); //add var angularVelocity2 = 400.SI<RoundsPerMinute>().Cast<PerSecond>(); var angVeloSum = angularVelocity + angularVelocity2; Assert.IsInstanceOfType(angVeloSum, typeof(PerSecond)); - Assert.AreEqual((400.0 + 600) / 60 * 2 * Math.PI, angVeloSum.Double(), 0.0000001); + Assert.AreEqual((400.0 + 600) / 60 * 2 * Math.PI, angVeloSum.Value(), 0.0000001); AssertException<VectoException>(() => { var x = 500.SI().Watt + 300.SI().Newton; }); //subtract var angVeloDiff = angularVelocity - angularVelocity2; Assert.IsInstanceOfType(angVeloDiff, typeof(PerSecond)); - Assert.AreEqual((600.0 - 400) / 60 * 2 * Math.PI, angVeloDiff.Double(), 0.0000001); + Assert.AreEqual((600.0 - 400) / 60 * 2 * Math.PI, angVeloDiff.Value(), 0.0000001); //general si unit var generalSIUnit = 3600000000.0.SI().Gramm.Per.Kilo.Watt.Hour.ConvertTo().Kilo.Gramm.Per.Watt.Second; Assert.IsInstanceOfType(generalSIUnit, typeof(SI)); - Assert.AreEqual(1, generalSIUnit.Double()); + Assert.AreEqual(1, generalSIUnit.Value()); //type conversion @@ -81,7 +81,7 @@ namespace TUGraz.VectoCore.Tests.Utils // cast SI to specialized unit classes. var angularVelocity5 = angularVelocity4.Cast<PerSecond>(); Assert.AreEqual(angularVelocity3, angularVelocity5); - Assert.AreEqual(angularVelocity3.Double(), angularVelocity4.Double()); + Assert.AreEqual(angularVelocity3.Value(), angularVelocity4.Value()); Assert.IsInstanceOfType(angularVelocity3, typeof(PerSecond)); Assert.IsInstanceOfType(angularVelocity5, typeof(PerSecond)); Assert.IsInstanceOfType(angularVelocity4, typeof(SI)); @@ -101,7 +101,7 @@ namespace TUGraz.VectoCore.Tests.Utils public void SI_Test() { var si = new SI(); - Assert.AreEqual(0.0, si.Double()); + Assert.AreEqual(0.0, si.Value()); Assert.AreEqual("0 [-]", si.ToString()); Assert.IsTrue(si.HasEqualUnit(new SI())); @@ -118,15 +118,15 @@ namespace TUGraz.VectoCore.Tests.Utils var kg = 5.SI().Kilo.Gramm; - Assert.AreEqual(5.0, kg.Double()); + Assert.AreEqual(5.0, kg.Value()); Assert.AreEqual("5 [kg]", kg.ToString()); - kg = kg.ConvertTo().Kilo.Gramm.Value(); - Assert.AreEqual(5.0, kg.Double()); + kg = kg.ConvertTo().Kilo.Gramm.Clone(); + Assert.AreEqual(5.0, kg.Value()); Assert.AreEqual("5 [kg]", kg.ToString()); - kg = kg.ConvertTo().Gramm.Value(); - Assert.AreEqual(5000, kg.Double()); + kg = kg.ConvertTo().Gramm.Clone(); + Assert.AreEqual(5000, kg.Value()); Assert.AreEqual("5000 [g]", kg.ToString()); var x = 5.SI(); @@ -141,12 +141,14 @@ namespace TUGraz.VectoCore.Tests.Utils Assert.AreEqual((5 * 2).SI(), x * 2.0); - var y = 2.SI(); - Assert.AreEqual((2 * 5).SI(), y * x); + //var y = 2.SI(); + //Assert.AreEqual((2 * 5).SI(), y * x); - var percent = 10.SI<Radian>().ConvertTo().GradientPercent; - Assert.AreEqual(67.975.ToString("F3") + " [Percent]", percent.ToString("F3")); - Assert.AreEqual(67.975, percent.Double(), 0.001); + //var percent = 10.SI<Radian>().ConvertTo().GradientPercent; + //Assert.AreEqual(67.975.ToString("F3") + " [Percent]", percent.ToString("F3")); + //Assert.AreEqual(67.975, percent.Value(), 0.001); + + Assert.AreEqual(45.0 / 180.0 * Math.PI, 1.SI().GradientPercent.Cast<Radian>().Value(), 0.000001); } [TestMethod] @@ -182,11 +184,11 @@ namespace TUGraz.VectoCore.Tests.Utils var v5 = v1 * v2; Assert.IsTrue(v5.HasEqualUnit(0.SI().Square.Newton.Meter)); - Assert.AreEqual(v1.Double() * v2.Double(), v5.Double()); + Assert.AreEqual(v1.Value() * v2.Value(), v5.Value()); var v6 = v1 / v2; Assert.IsTrue(v6.HasEqualUnit(0.SI())); - Assert.AreEqual(v1.Double() / v2.Double(), v6.Double()); + Assert.AreEqual(v1.Value() / v2.Value(), v6.Value()); var t = 10.SI<NewtonMeter>(); var angVelo = 5.SI<PerSecond>(); diff --git a/VectoCoreTest/VectoCoreTest.csproj b/VectoCoreTest/VectoCoreTest.csproj index f94e5325f72a6d521171429457c1e19981bec3db..ac00c3f78626ed05c5088bf5b72a95e5e51b2128 100644 --- a/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCoreTest/VectoCoreTest.csproj @@ -46,6 +46,7 @@ <Reference Include="Common.Logging.NLog31"> <HintPath>..\packages\Common.Logging.NLog31.3.0.0\lib\net40\Common.Logging.NLog31.dll</HintPath> </Reference> + <Reference Include="Microsoft.CSharp" /> <Reference Include="NLog"> <HintPath>..\packages\NLog.3.2.0.0\lib\net45\NLog.dll</HintPath> </Reference> @@ -70,6 +71,7 @@ <ItemGroup> <Compile Include="Exceptions\ExceptionTests.cs" /> <Compile Include="Integration\EngineOnlyCycle\EngineOnlyCycleTest.cs" /> + <Compile Include="Integration\SimulationRuns\MinimalPowertrain.cs" /> <Compile Include="Models\Declaration\DeclarationDataTest.cs" /> <Compile Include="Models\SimulationComponentData\AccelerationCurveTest.cs" /> <Compile Include="Models\SimulationComponentData\FuelConsumptionMapTest.cs" /> @@ -78,12 +80,14 @@ <Compile Include="Models\SimulationComponentData\VehicleDataTest.cs" /> <Compile Include="Models\SimulationComponent\ClutchTest.cs" /> <Compile Include="Models\SimulationComponent\CombustionEngineTest.cs" /> + <Compile Include="Models\SimulationComponent\DistanceBasedDrivingCycleTest.cs" /> <Compile Include="Models\SimulationComponent\GearboxTest.cs" /> <Compile Include="Models\SimulationComponent\RetarderTest.cs" /> <Compile Include="Models\SimulationComponent\WheelsTest.cs" /> <Compile Include="Models\SimulationComponent\VehicleTest.cs" /> <Compile Include="Models\Simulation\DrivingCycleTests.cs" /> <Compile Include="Utils\AssertHelper.cs" /> + <Compile Include="Utils\MockDriver.cs" /> <Compile Include="Utils\ResultFileHelper.cs" /> <Compile Include="Utils\MockPorts.cs" /> <Compile Include="Models\Simulation\SimulationTests.cs" />