Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Unverified Commit c0cdf93a authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

adding basic functionality to analyze why a simulation run aborted.

parent e0f8d7b3
Branches
Tags
No related merge requests found
...@@ -10,6 +10,7 @@ using TUGraz.VectoCore.InputData.Reader.DataObjectAdapter; ...@@ -10,6 +10,7 @@ using TUGraz.VectoCore.InputData.Reader.DataObjectAdapter;
using TUGraz.VectoCore.InputData.Reader.DataObjectAdapter.SimulationComponents; using TUGraz.VectoCore.InputData.Reader.DataObjectAdapter.SimulationComponents;
using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.Declaration.IterativeRunStrategies; using TUGraz.VectoCore.Models.Declaration.IterativeRunStrategies;
using TUGraz.VectoCore.Models.Declaration.PostMortemAnalysisStrategy;
using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.Simulation.Impl;
using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data;
...@@ -115,7 +116,7 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl.DeclarationMode.PrimaryBusRunDa ...@@ -115,7 +116,7 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl.DeclarationMode.PrimaryBusRunDa
Cycle = new DrivingCycleProxy(cycle, mission.MissionType.ToString()), Cycle = new DrivingCycleProxy(cycle, mission.MissionType.ToString()),
ExecutionMode = ExecutionMode.Declaration, ExecutionMode = ExecutionMode.Declaration,
}; };
simulationRunData.PostMortemStrategy = new PrimaryBusPostMortemStrategy();
return simulationRunData; return simulationRunData;
} }
...@@ -539,6 +540,7 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl.DeclarationMode.PrimaryBusRunDa ...@@ -539,6 +540,7 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl.DeclarationMode.PrimaryBusRunDa
runData.ModFileSuffix += ovcMode == OvcHevMode.ChargeSustaining ? "CS" : "CD"; runData.ModFileSuffix += ovcMode == OvcHevMode.ChargeSustaining ? "CS" : "CD";
} }
runData.OVCMode = ovcMode; runData.OVCMode = ovcMode;
return runData; return runData;
} }
......
...@@ -35,7 +35,4 @@ namespace TUGraz.VectoCore.Models.Declaration.IterativeRunStrategies ...@@ -35,7 +35,4 @@ namespace TUGraz.VectoCore.Models.Declaration.IterativeRunStrategies
{ {
//IIterativeRunResult CreateIterativeResult(IModalDataContainer modData); //IIterativeRunResult CreateIterativeResult(IModalDataContainer modData);
} }
} }
\ No newline at end of file
using System;
using TUGraz.VectoCore.Models.Simulation;
namespace TUGraz.VectoCore.Models.Declaration.PostMortemAnalysisStrategy
{
public interface IPostMortemAnalyzeStrategy
{
bool AbortSimulation(IVehicleContainer container, Exception exception);
}
public class DefaultPostMortemAnalyseStrategy : IPostMortemAnalyzeStrategy
{
#region Implementation of IPostMortemAnalyzeStrategy
public bool AbortSimulation(IVehicleContainer container, Exception exception)
{
return true;
}
#endregion
}
public class PrimaryBusPostMortemStrategy : IPostMortemAnalyzeStrategy
{
#region Implementation of IPostMortemAnalyzeStrategy
public bool AbortSimulation(IVehicleContainer container, Exception exception)
{
return false;
}
#endregion
}
}
\ No newline at end of file
...@@ -48,6 +48,7 @@ using TUGraz.VectoCore.InputData.Reader.DataObjectAdapter.SimulationComponents; ...@@ -48,6 +48,7 @@ using TUGraz.VectoCore.InputData.Reader.DataObjectAdapter.SimulationComponents;
using TUGraz.VectoCore.InputData.Reader.Impl; using TUGraz.VectoCore.InputData.Reader.Impl;
using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.Declaration.IterativeRunStrategies; using TUGraz.VectoCore.Models.Declaration.IterativeRunStrategies;
using TUGraz.VectoCore.Models.Declaration.PostMortemAnalysisStrategy;
using TUGraz.VectoCore.Models.Simulation.DataBus; using TUGraz.VectoCore.Models.Simulation.DataBus;
using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.Simulation.Impl;
using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data;
...@@ -189,6 +190,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Data ...@@ -189,6 +190,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
[JsonIgnore] [JsonIgnore]
public IIterativeRunStrategy IterativeRunStrategy { get; internal set; } = new DefaultIterativeStrategy(); public IIterativeRunStrategy IterativeRunStrategy { get; internal set; } = new DefaultIterativeStrategy();
[JsonIgnore]
public IPostMortemAnalyzeStrategy PostMortemStrategy { get; internal set; } = new DefaultPostMortemAnalyseStrategy();
public NewtonMeter TorqueDriftLeftWheel { get; internal set; } public NewtonMeter TorqueDriftLeftWheel { get; internal set; }
public NewtonMeter TorqueDriftRightWheel { get; internal set; } public NewtonMeter TorqueDriftRightWheel { get; internal set; }
......
using System;
using TUGraz.VectoCommon.Exceptions;
using TUGraz.VectoCore.Models.Declaration.PostMortemAnalysisStrategy;
namespace TUGraz.VectoCore.Models.Simulation.Impl
{
public interface IPostMortemAnalyzer
{
/**
* @returns true if the original exception shall be thrown
*/
bool AbortSimulation(IVehicleContainer container, Exception ex);
}
public class NoPostMortemAnalysis : IPostMortemAnalyzer
{
#region Implementation of IPostMortemAnalyzer
public bool AbortSimulation(IVehicleContainer container, Exception ex)
{
return true;
}
#endregion
}
public class DefaultPostMortemAnalyzer : IPostMortemAnalyzer
{
protected readonly IPostMortemAnalyzeStrategy _strategy;
public DefaultPostMortemAnalyzer(IPostMortemAnalyzeStrategy postMortemStrategy)
{
_strategy = postMortemStrategy;
}
#region Implementation of IPostMortemAnalyzer
public bool AbortSimulation(IVehicleContainer container, Exception ex)
{
if (!_strategy.AbortSimulation(container, ex)) {
//_strategy.M
return false;
}
return true;
}
#endregion
}
}
\ No newline at end of file
...@@ -41,7 +41,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -41,7 +41,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
{ {
public class DistanceRun : VectoRun public class DistanceRun : VectoRun
{ {
public DistanceRun(IVehicleContainer container, IFollowUpRunCreator followUpCreator) : base(container, followUpCreator) {} public DistanceRun(IVehicleContainer container, IFollowUpRunCreator followUpCreator, IPostMortemAnalyzer postMortem) : base(container, followUpCreator, postMortem) {}
public DistanceRun(IVehicleContainer container) : base(container) {} public DistanceRun(IVehicleContainer container) : base(container) {}
protected override IResponse DoSimulationStep() protected override IResponse DoSimulationStep()
{ {
......
...@@ -268,7 +268,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory ...@@ -268,7 +268,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory
var container = PowertrainBuilder.Build(data, modData, sumWriter); var container = PowertrainBuilder.Build(data, modData, sumWriter);
run = new DistanceRun(container, new FollowUpRunCreator(data.IterativeRunStrategy)); run = new DistanceRun(container, new FollowUpRunCreator(data.IterativeRunStrategy), new DefaultPostMortemAnalyzer(data.PostMortemStrategy));
break; break;
case CycleType.EngineOnly: case CycleType.EngineOnly:
if ((data.SimulationType & SimulationType.EngineOnly) == 0) { if ((data.SimulationType & SimulationType.EngineOnly) == 0) {
......
...@@ -38,6 +38,7 @@ using TUGraz.VectoCommon.Models; ...@@ -38,6 +38,7 @@ using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils; using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Connector.Ports.Impl;
using TUGraz.VectoCore.Models.Declaration.PostMortemAnalysisStrategy;
using TUGraz.VectoCore.Utils; using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Simulation.Impl namespace TUGraz.VectoCore.Models.Simulation.Impl
...@@ -52,6 +53,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -52,6 +53,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
protected Second dt = 1.SI<Second>(); protected Second dt = 1.SI<Second>();
private bool _cancelled; private bool _cancelled;
private readonly IFollowUpRunCreator _followUpCreator; private readonly IFollowUpRunCreator _followUpCreator;
private readonly IPostMortemAnalyzer _postMortemAnalyzer;
protected ISimulationOutPort CyclePort { get; set; } protected ISimulationOutPort CyclePort { get; set; }
[Required, ValidateObject] [Required, ValidateObject]
...@@ -72,7 +74,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -72,7 +74,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
public virtual double Progress => CyclePort.Progress * (PostProcessingDone ? 1.0 : 0.99) * (WritingResultsDone ? 1.0 : 0.99); public virtual double Progress => CyclePort.Progress * (PostProcessingDone ? 1.0 : 0.99) * (WritingResultsDone ? 1.0 : 0.99);
protected VectoRun(IVehicleContainer container, IFollowUpRunCreator followUpCreator = null) protected VectoRun(IVehicleContainer container, IFollowUpRunCreator followUpCreator = null, IPostMortemAnalyzer postMortem = null)
{ {
Container = container; Container = container;
RunIdentifier = Interlocked.Increment(ref _runIdCounter); RunIdentifier = Interlocked.Increment(ref _runIdCounter);
...@@ -81,6 +83,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -81,6 +83,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
PostProcessingDone = false; PostProcessingDone = false;
WritingResultsDone = false; WritingResultsDone = false;
_followUpCreator = followUpCreator ?? new NoFollowUpRunCreator(); _followUpCreator = followUpCreator ?? new NoFollowUpRunCreator();
_postMortemAnalyzer = postMortem ?? new NoPostMortemAnalysis();
} }
[DebuggerStepThrough] [DebuggerStepThrough]
public IVehicleContainer GetContainer() => Container; public IVehicleContainer GetContainer() => Container;
...@@ -108,7 +112,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -108,7 +112,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
Container.AbsTime = AbsTime; Container.AbsTime = AbsTime;
Initialize(); Initialize();
IResponse response; IResponse response = null;
var iterationCount = 0; var iterationCount = 0;
try { try {
...@@ -138,40 +142,54 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -138,40 +142,54 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
PostProcessingDone = true; PostProcessingDone = true;
} catch (VectoSimulationException vse) { } catch (VectoSimulationException vse) {
if (_postMortemAnalyzer?.AbortSimulation(Container, vse) ?? true) {
Log.Error("SIMULATION RUN ABORTED! ========================"); Log.Error("SIMULATION RUN ABORTED! ========================");
Log.Error(vse); Log.Error(vse);
Container.RunStatus = Status.Aborted; Container.RunStatus = Status.Aborted;
var ex = new VectoSimulationException("{6} ({7} {8}) - absTime: {0}, distance: {1}, dt: {2}, v: {3}, Gear: {4} | {5}, f_equiv:{9}", var ex = new VectoSimulationException(
"{6} ({7} {8}) - absTime: {0}, distance: {1}, dt: {2}, v: {3}, Gear: {4} | {5}, f_equiv:{9}",
vse, AbsTime, Container.MileageCounter.Distance, dt, Container.VehicleInfo.VehicleSpeed, vse, AbsTime, Container.MileageCounter.Distance, dt, Container.VehicleInfo.VehicleSpeed,
TryCatch(() => Container.GearboxInfo.Gear), vse.Message, RunIdentifier, CycleName, RunSuffix, TryCatch(() => Container.RunData.HybridStrategyParameters?.EquivalenceFactor)); TryCatch(() => Container.GearboxInfo.Gear), vse.Message, RunIdentifier, CycleName, RunSuffix,
TryCatch(() => Container.RunData.HybridStrategyParameters?.EquivalenceFactor));
Container.FinishSimulationRun(ex); Container.FinishSimulationRun(ex);
throw ex; throw ex;
}
} catch (VectoException ve) { } catch (VectoException ve) {
if (_postMortemAnalyzer?.AbortSimulation(Container, ve) ?? true) {
Log.Error("SIMULATION RUN ABORTED! ========================"); Log.Error("SIMULATION RUN ABORTED! ========================");
Log.Error(ve); Log.Error(ve);
Container.RunStatus = Status.Aborted; Container.RunStatus = Status.Aborted;
var ex = new VectoSimulationException("{6} ({7} {8}) - absTime: {0}, distance: {1}, dt: {2}, v: {3}, Gear: {4} | {5}, f_equiv:{9}", var ex = new VectoSimulationException(
"{6} ({7} {8}) - absTime: {0}, distance: {1}, dt: {2}, v: {3}, Gear: {4} | {5}, f_equiv:{9}",
ve, AbsTime, Container.MileageCounter.Distance, dt, Container.VehicleInfo.VehicleSpeed, ve, AbsTime, Container.MileageCounter.Distance, dt, Container.VehicleInfo.VehicleSpeed,
TryCatch(() => Container.GearboxInfo.Gear), ve.Message, RunIdentifier, CycleName, RunSuffix, TryCatch(() => Container.RunData.HybridStrategyParameters?.EquivalenceFactor)); TryCatch(() => Container.GearboxInfo.Gear), ve.Message, RunIdentifier, CycleName, RunSuffix,
TryCatch(() => Container.RunData.HybridStrategyParameters?.EquivalenceFactor));
try { try {
Container.FinishSimulationRun(ex); Container.FinishSimulationRun(ex);
} catch (Exception ve2) { } catch (Exception ve2) {
ve = new VectoException("Multiple Exceptions occured.", ve = new VectoException("Multiple Exceptions occured.",
new AggregateException(ve, new VectoException("Exception during finishing Simulation.", ve2))); new AggregateException(ve,
new VectoException("Exception during finishing Simulation.", ve2)));
throw ve; throw ve;
} }
throw ex; throw ex;
}
} catch (Exception e) { } catch (Exception e) {
if (_postMortemAnalyzer?.AbortSimulation(Container, e) ?? true) {
Log.Error("SIMULATION RUN ABORTED! ========================"); Log.Error("SIMULATION RUN ABORTED! ========================");
Log.Error(e); Log.Error(e);
Container.RunStatus = Status.Aborted; Container.RunStatus = Status.Aborted;
var ex = new VectoSimulationException("{6} ({7} {8}) - absTime: {0}, distance: {1}, dt: {2}, v: {3}, Gear: {4} | {5}, f_equiv:{9}", var ex = new VectoSimulationException(
"{6} ({7} {8}) - absTime: {0}, distance: {1}, dt: {2}, v: {3}, Gear: {4} | {5}, f_equiv:{9}",
e, AbsTime, Container.MileageCounter.Distance, dt, Container.VehicleInfo.VehicleSpeed, e, AbsTime, Container.MileageCounter.Distance, dt, Container.VehicleInfo.VehicleSpeed,
TryCatch(() => Container.GearboxInfo.Gear), e.Message, RunIdentifier, CycleName, RunSuffix, TryCatch(() => Container.RunData.HybridStrategyParameters?.EquivalenceFactor) ?? "-"); TryCatch(() => Container.GearboxInfo.Gear), e.Message, RunIdentifier, CycleName, RunSuffix,
TryCatch(() => Container.RunData.HybridStrategyParameters?.EquivalenceFactor) ?? "-");
Container.FinishSimulationRun(ex); Container.FinishSimulationRun(ex);
throw ex; throw ex;
} }
}
if (CheckCyclePortProgress()) { if (CheckCyclePortProgress()) {
if (CyclePort.Progress < 1) { if (CyclePort.Progress < 1) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment