Skip to content

Commit

Permalink
wip: adding first gain sched unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Steinar Elgsæter committed Oct 25, 2023
1 parent dc655b1 commit 83b8939
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
44 changes: 44 additions & 0 deletions TimeSeriesAnalysis.Tests/Tests/PlantSimulatorMISOTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class MISOTests
UnitModel processModel2;
UnitModel processModel3;
UnitModel processModel4;

GainSchedModel gainSched1;
GainSchedParameters gainSchedParameters1;

PidParameters pidParameters1;
PidModel pidModel1;
Select minSelect1;
Expand All @@ -121,6 +125,16 @@ public void SetUp()
{
Shared.GetParserObj().EnableDebugOutput();

gainSchedParameters1 = new GainSchedParameters
{
TimeConstant_s = new double[] { 10 },
LinearGains = new List<double[]> { new double[] { 5 }, new double[] { 10 } },
TimeDelay_s = 0,
Bias = 0
};



modelParameters1 = new UnitParameters
{
TimeConstant_s = 10,
Expand Down Expand Up @@ -156,6 +170,8 @@ public void SetUp()
processModel3 = new UnitModel(modelParameters3, "SubProcess3");
processModel4 = new UnitModel(modelParameters4, "SubProcess4");

gainSched1 = new GainSchedModel(gainSchedParameters1,"GainSched1");

pidParameters1 = new PidParameters()
{
Kp = 0.5,
Expand Down Expand Up @@ -196,6 +212,34 @@ public void DeserializeModelWithMissingInput_GivesGoodErrorMessage()
var isOk = plantSim.Simulate(inputData, out TimeSeriesDataSet simData);
}

[TestCase]
public void GainSched_Single_RunsAndConverges()
{
var plantSim = new PlantSimulator(new List<ISimulatableModel> { gainSched1 });
var inputData = new TimeSeriesDataSet();
inputData.Add(plantSim.AddExternalSignal(gainSched1, SignalType.External_U, (int)INDEX.FIRST),
TimeSeriesCreator.ThreeSteps(N/5, N/3, N/2, N, 0, 1, 2, 3));
inputData.CreateTimestamps(timeBase_s);
var isOk = plantSim.Simulate(inputData, out TimeSeriesDataSet simData);
Assert.IsTrue(isOk);
SISOTests.CommonAsserts(inputData, simData, plantSim);
double[] simY = simData.GetValues(processModel1.GetID(), SignalType.Output_Y);

Assert.IsTrue(Math.Abs(simY[0] - (1 * 50 + 0.5 * 50 + 5)) < 0.01);
Assert.IsTrue(Math.Abs(simY.Last() - (1 * 55 + 0.5 * 45 + 5)) < 0.01);

/*Plot.FromList(new List<double[]> {
simData.GetValues(processModel1.GetID(),SignalType.Output_Y_sim),
simData.GetValues(processModel1.GetID(),SignalType.External_U,0),
simData.GetValues(processModel1.GetID(),SignalType.External_U,1)
},
new List<string> { "y1=y_sim1", "y3=u1","y3=u2" },
timeBase_s, "UnitTest_SingleMISO");*/
}




[TestCase]
public void MISO_Single_RunsAndConverges()
{
Expand Down
5 changes: 5 additions & 0 deletions TimeSeriesAnalysis.Tests/Tests/PlantSimulatorSISOTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public void SetUp()
pidModel1 = new PidModel(pidParameters1, "PID1");
}






// MISO= multiple-input/single-output
// SISO= single-input/single-output

Expand Down

0 comments on commit 83b8939

Please sign in to comment.