Code development platform for open source projects from the European Union institutions

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

optimize average acc torque preprocessing (reduce from 3 nested loops to two),...

optimize average acc torque preprocessing (reduce from 3 nested loops to two), reduce computation time from 1.8s to ~0.24s
parent 3ad0ba88
No related branches found
No related tags found
No related merge requests found
using System;
using System.Collections.Generic;
using System.Diagnostics;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Simulation;
using TUGraz.VectoCore.Models.Simulation.Data;
......@@ -30,21 +31,26 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl {
var numTorqueSteps = 100;
var entries = new List<KeyValuePair<Tuple<PerSecond, NewtonMeter>, NewtonMeter>>();
var speedStepSize = (UpperLimit - Data.EngineData.IdleSpeed) / numSpeedSteps;
for (var engineSpeed = Data.EngineData.IdleSpeed;
engineSpeed < UpperLimit;
engineSpeed += speedStepSize) {
for (var torque = 0.SI<NewtonMeter>(); torque < fld.MaxTorque; torque += fld.MaxTorque / numTorqueSteps) {
var sum = 0.SI<NewtonMeter>();
for (var tmpSpeed = engineSpeed; tmpSpeed < UpperLimit; tmpSpeed += speedStepSize) {
sum += VectoMath.Min(torque, fld.FullLoadStationaryTorque(tmpSpeed));
}
var tmp = sum * speedStepSize / (UpperLimit - engineSpeed);
if (engineSpeed.IsEqual(UpperLimit, speedStepSize / 2)) {
tmp = 0.SI<NewtonMeter>();
}
var maxTorque = new Dictionary<PerSecond, NewtonMeter>();
for (var engineSpeed = UpperLimit;
engineSpeed >= Data.EngineData.IdleSpeed;
engineSpeed -= speedStepSize) {
maxTorque[engineSpeed] = fld.FullLoadStationaryTorque(engineSpeed);
}
for (var torque = 0.SI<NewtonMeter>(); torque < fld.MaxTorque; torque += fld.MaxTorque / numTorqueSteps) {
var sum = 0.SI<NewtonMeter>();
for (var engineSpeed = UpperLimit ;
engineSpeed >= Data.EngineData.IdleSpeed;
engineSpeed -= speedStepSize) {
sum += VectoMath.Min(torque, maxTorque[engineSpeed]); ;
var tmp = engineSpeed.IsEqual(UpperLimit, speedStepSize / 2)
? 0.SI<NewtonMeter>()
: sum * speedStepSize / (UpperLimit - engineSpeed);
entries.Add(new KeyValuePair<Tuple<PerSecond, NewtonMeter>, NewtonMeter>(Tuple.Create(engineSpeed, torque), tmp));
}
}
......
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