Skip to content

Commit

Permalink
- fix an issue where PlantSimualtor.Simulate would remove items from …
Browse files Browse the repository at this point in the history
…the inputData set. This again made it impossible to calcualte FitScore after simulating. Now work on a cloned copy and leave original unaltered
  • Loading branch information
Steinar Elgsæter committed Nov 26, 2024
1 parent b8ad379 commit 1bf46ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
18 changes: 10 additions & 8 deletions Dynamic/PlantSimulator/PlantSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,9 @@ public bool Simulate(TimeSeriesDataSet inputData, out TimeSeriesDataSet simData)
// initalize the new time-series to be created in simData.
var init = new PlantSimulatorInitalizer(this);

var didInit = init.ToSteadyStateAndEstimateDisturbances(ref inputData, ref simData, compLoopDict);
var inputDataMinimal = new TimeSeriesDataSet(inputData);

var didInit = init.ToSteadyStateAndEstimateDisturbances(ref inputDataMinimal, ref simData, compLoopDict);
if (!didInit)
{
Shared.GetParserObj().AddError("PlantSimulator failed to initalize.");
Expand All @@ -759,7 +761,7 @@ public bool Simulate(TimeSeriesDataSet inputData, out TimeSeriesDataSet simData)
"\" has null inputIDs.");
return false;
}
double[] inputVals = GetValuesFromEitherDataset(inputIDs, timeIdx, simData, inputData);
double[] inputVals = GetValuesFromEitherDataset(inputIDs, timeIdx, simData, inputDataMinimal);

string outputID = model.GetOutputID();
if (outputID == null)
Expand All @@ -769,17 +771,17 @@ public bool Simulate(TimeSeriesDataSet inputData, out TimeSeriesDataSet simData)
return false;
}
double[] outputVals =
GetValuesFromEitherDataset(new string[] { outputID }, timeIdx, simData, inputData);
GetValuesFromEitherDataset(new string[] { outputID }, timeIdx, simData, inputDataMinimal);
if (outputVals != null)
{
model.WarmStart(inputVals, outputVals[0]);
}
}

var idxToIgnore = inputData.GetIndicesToIgnore();
var idxToIgnore = inputDataMinimal.GetIndicesToIgnore();
int lastGoodTimeIndex = 0;
// if start of dataset is bad, then parse forward until first good time index..
while (idxToIgnore.Contains(lastGoodTimeIndex) && lastGoodTimeIndex < inputData.GetLength())
while (idxToIgnore.Contains(lastGoodTimeIndex) && lastGoodTimeIndex < inputDataMinimal.GetLength())
{
lastGoodTimeIndex++;
}
Expand All @@ -799,7 +801,7 @@ public bool Simulate(TimeSeriesDataSet inputData, out TimeSeriesDataSet simData)
{
inputDataLookBackIdx = 1;//if set to zero, model fails(requires changing model order).
}
double[] inputVals = GetValuesFromEitherDataset(inputIDs, lastGoodTimeIndex - inputDataLookBackIdx, simData, inputData);
double[] inputVals = GetValuesFromEitherDataset(inputIDs, lastGoodTimeIndex - inputDataLookBackIdx, simData, inputDataMinimal);
if (inputVals == null)
{
Shared.GetParserObj().AddError("PlantSimulator.Simulate() failed. Model \"" + model.GetID() +
Expand All @@ -826,8 +828,8 @@ public bool Simulate(TimeSeriesDataSet inputData, out TimeSeriesDataSet simData)
}
}
}
simData.SetTimeStamps(inputData.GetTimeStamps().ToList());
PlantFitScore = FitScoreCalculator.GetPlantWideSimulated(this, inputData, simData);
simData.SetTimeStamps(inputDataMinimal.GetTimeStamps().ToList());
PlantFitScore = FitScoreCalculator.GetPlantWideSimulated(this, inputData, simData);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions TimeSeriesAnalysis.Tests/Tests/DisturbanceEstimatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public void PlantSimulator_StepDisturbance_EstimatesOk(double stepAmplitude)
[TestCase(4,-1)]
public void PlantSimulator_StepDisturbanceANDSetPointStep_EstimatesOk(double disturbanceStepAmplitude,double setpointAmplitude)
{
// Shared.EnablePlots();
// Shared.EnablePlots();
var trueDisturbance = TimeSeriesCreator.Step(100, N, 0, disturbanceStepAmplitude);
var setpoint = TimeSeriesCreator.Step(50, N, 50, 50+setpointAmplitude);
DisturbanceTestUsingPlantSimulator(new UnitModel(dynamicModelParameters, "PlantSim_d"), trueDisturbance, true, setpoint);
// Shared.DisablePlots();
//Shared.DisablePlots();
}


Expand Down
2 changes: 1 addition & 1 deletion TimeSeriesAnalysis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<RunAnalyzersDuringLiveAnalysis>False</RunAnalyzersDuringLiveAnalysis>
<RepositoryUrl>https://github.com/equinor/TimeSeriesAnalysis.git</RepositoryUrl>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<Version>1.3.37</Version>
<Version>1.3.38</Version>
<Company>Equinor</Company>
<Authors>Equinor</Authors>
<IncludeSymbols>true</IncludeSymbols>
Expand Down

0 comments on commit 1bf46ea

Please sign in to comment.