Skip to content

Commit

Permalink
-refactoring unit tests
Browse files Browse the repository at this point in the history
- refacotring the many PlantSimulator.SimulateSingle alternatives.
  • Loading branch information
Steinar Elgsæter committed Dec 17, 2024
1 parent 6516a66 commit c2ece8e
Show file tree
Hide file tree
Showing 13 changed files with 417 additions and 375 deletions.
2 changes: 1 addition & 1 deletion Dynamic/Identification/ClosedLoopUnitIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private static double EstimateDisturbanceLF(UnitDataSet dataSet, UnitModel unitM
{
unitParams.LinearGains = new double[] { Kp };
umInternal.SetModelParameters(unitParams);
(var isOk, var y_proc) = PlantSimulator.SimulateSingle(dataSet, umInternal, false);
(var isOk, var y_proc) = PlantSimulator.SimulateSingle(dataSet, umInternal);
var d_LF = vec.Multiply(vec.Subtract(y_proc, y_proc[0]), -1);
var d_est1 = vec.Add(d_HF, d_LF);
var d_est2 = vec.Subtract(dataSet.Y_meas, y_proc);
Expand Down
2 changes: 1 addition & 1 deletion Dynamic/Identification/DisturbanceCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public static DisturbanceIdResult CalculateDisturbanceVector(UnitDataSet unitDat
// non-disturbance related changes in the dataset producing "unitDataSet_adjusted"
var unitDataSet_adjusted = RemoveSetpointAndOtherInputChangeEffectsFromDataSet(unitDataSet, unitModel, pidInputIdx, pidParams);
unitDataSet_adjusted.D = null;
(bool isOk, double[] y_proc) = PlantSimulator.SimulateSingle(unitDataSet_adjusted, unitModel, false);
(bool isOk, double[] y_proc) = PlantSimulator.SimulateSingle(unitDataSet_adjusted, unitModel);

if (y_proc == null)
{
Expand Down
5 changes: 4 additions & 1 deletion Dynamic/Identification/FitScoreCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ static public double GetPlantWideSimulated(PlantSimulator plantSimObj, TimeSerie
{
if (!modelObj.GetAdditiveInputIDs()[0].StartsWith(disturbanceSignalPrefix))
{
measY = inputData.GetValues(outputName);
if (inputData.ContainsSignal(outputName))
{
measY = inputData.GetValues(outputName);
}
}
}
else if (inputData.ContainsSignal(outputName))
Expand Down
8 changes: 4 additions & 4 deletions Dynamic/Identification/GainSchedIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ static private (GainSchedParameters, int) ChooseBestModelFromFittingInfo(
if (simulateAndAddToYsimInDataSet)
{
var bestModel = new GainSchedModel(BestGainSchedParams);
PlantSimulator.SimulateSingle(dataSet, bestModel, true);
PlantSimulator.SimulateSingleToYsim(dataSet, bestModel);
}
return (BestGainSchedParams, bestModelIdx);
}
Expand Down Expand Up @@ -512,7 +512,7 @@ private static bool DetermineOperatingPointAndSimulate(ref GainSchedParameters g
}
gsParams.MoveOperatingPointUWithoutChangingModel(desiredOpU);

(var isOk, var y_sim) = PlantSimulator.SimulateSingle(dataSet, gsIdentModel,false);
(var isOk, var y_sim) = PlantSimulator.SimulateSingle(dataSet, gsIdentModel);

if (isOk)
{
Expand All @@ -523,7 +523,7 @@ private static bool DetermineOperatingPointAndSimulate(ref GainSchedParameters g
if (estBias.HasValue)
{
gsParams.IncreaseOperatingPointY(estBias.Value);
(var isOk2, var y_sim2) = PlantSimulator.SimulateSingle(dataSet, gsIdentModel, false);
(var isOk2, var y_sim2) = PlantSimulator.SimulateSingle(dataSet, gsIdentModel);
dataSet.Y_sim = y_sim2;
if (gsParams.Fitting == null)
gsParams.Fitting = new FittingInfo();
Expand Down Expand Up @@ -587,7 +587,7 @@ private static void EstimateTimeDelay(ref GainSchedParameters gsParams, ref Unit
copiedGsParams.TimeConstant_s = vec.Subtract(gsParams.TimeConstant_s, timedelay_s);

var gsIdentModel = new GainSchedModel(copiedGsParams, "ident_model");
(var isOk, var y_sim) = PlantSimulator.SimulateSingle(dataSet, gsIdentModel, false);
(var isOk, var y_sim) = PlantSimulator.SimulateSingle(dataSet, gsIdentModel);

if (isOk)
{
Expand Down
7 changes: 2 additions & 5 deletions Dynamic/Identification/UnitIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ public static UnitModel IdentifyLinearDiff(ref UnitDataSet dataSet, FittingSpecs

if (model.modelParameters.Fitting.WasAbleToIdentify)
{
PlantSimulator.SimulateSingle(dataSet, model, true);
//var simulator = new UnitSimulator(model);
//simulator.Simulate(ref dataSet, default, true);// overwrite any y_sim
PlantSimulator.SimulateSingleToYsim(dataSet, model);
model.SetFittedDataSet(dataSet);
}
return model;
Expand Down Expand Up @@ -451,10 +449,9 @@ private static UnitModel Identify_Internal(ref UnitDataSet dataSet, FittingSpecs
// simulate
if (modelParameters.Fitting.WasAbleToIdentify)
{
PlantSimulator.SimulateSingle(dataSet, model, true);// overwrite any y_sim
PlantSimulator.SimulateSingleToYsim(dataSet, model);
model.SetFittedDataSet(dataSet);
}

return model;
}

Expand Down
Loading

0 comments on commit c2ece8e

Please sign in to comment.