Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

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

combustion engine: avoid throwing an exception in case PT1 cannot be calculated - rewrite with ifs

parent c5ba3b2a
No related branches found
No related tags found
No related merge requests found
......@@ -562,8 +562,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var stationaryFullLoadPower = stationaryFullLoadTorque * avgAngularVelocity;
Watt dynFullPowerCalculated;
// disable pt1 behaviour if PT1Disabled is true, or if the previous enginepower is greater than the current stationary fullload power (in this case the pt1 calculation fails)
if (PT1Disabled || PreviousState.EnginePower.IsGreaterOrEqual(stationaryFullLoadPower)) {
dynFullPowerCalculated = stationaryFullLoadPower;
......@@ -571,9 +569,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
try {
var pt1 = ModelData.FullLoadCurves[DataBus.GearboxInfo.Gear.Gear].PT1(avgAngularVelocity).Value.Value();
var powerRatio = (PreviousState.EnginePower / stationaryFullLoadPower).Value();
var tStarPrev = pt1 * Math.Log(1.0 / (1 - powerRatio), Math.E).SI<Second>();
var tStar = tStarPrev + PreviousState.dt;
dynFullPowerCalculated = stationaryFullLoadPower * (pt1.IsEqual(0) ? 1 : 1 - Math.Exp((-tStar / pt1).Value()));
var tStarPrev = pt1 * Math.Log(1.0 / (1 - powerRatio), Math.E);
if (!double.IsNaN(tStarPrev)) {
var tStar = tStarPrev.SI<Second>() + PreviousState.dt;
dynFullPowerCalculated = stationaryFullLoadPower * (pt1.IsEqual(0) ? 1 : 1 - Math.Exp((-tStar / pt1).Value()));
} else {
if (dryRun) {
Log.Info("PT1 calculation failed (dryRun: {0})", dryRun);
dynFullPowerCalculated = stationaryFullLoadPower;
} else {
Log.Warn("PT1 calculation failed (dryRun: {0})", dryRun);
throw new VectoException("PT1 calculation failed!");
}
}
} catch (VectoException e) {
if (dryRun) {
Log.Info("PT1 calculation failed (dryRun: {0}): {1}", dryRun, e.Message);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment