Everything works OK after serious changes:

- all components, componentCfg-s and parameter providers use base classes
 - less boilerplate code, simpler access to test/procedure parameters from code
 - CreateTestParams(test), CreateProcedureParams(procedure) methods added
 - TestBenchSim class is made static, it is not inheritted by any device anymore
This commit is contained in:
Milan Hanajik
2015-01-02 12:51:27 +01:00
parent 752719bd62
commit 94de991bf6
126 changed files with 1117 additions and 1629 deletions
+58 -71
View File
@@ -7,7 +7,7 @@ namespace TBF.BenchControl
/// Test bench model inherited by all classes for the simulation of devices.
/// Define DN100, MUNICH or nothing.
/// </summary>
public class TestBenchSim
public static class TestBenchSim
{
private static readonly ILog log = LogManager.GetLogger(typeof(TestBenchSim));
@@ -34,10 +34,10 @@ namespace TBF.BenchControl
public static bool Div2sim;
public static bool Div3sim;
int regulValveNo; /// 0=undefined, 1..5
int refFlowmtrNo; /// 0=undefined, 1..4
static int regulValveNo; /// 0=undefined, 1..5
static int refFlowmtrNo; /// 0=undefined, 1..4
public void Initialize()
public static void Initialize()
{
Mass1sim = 0.0f; /// Initialize tanks
Mass2sim = 0.0f;
@@ -226,10 +226,10 @@ namespace TBF.BenchControl
const ulong Path5 = 0;
#endif
/// <summary>Run this device</summary>
public void RunDevice(int regulValveNo, int refFlowmtrNo, Elde.StatusP statusP)
public static void RunDevice(int regulValveNo, int refFlowmtrNo, Elde.StatusP statusP)
{
this.regulValveNo = regulValveNo;
this.refFlowmtrNo = refFlowmtrNo;
TestBenchSim.regulValveNo = regulValveNo;
TestBenchSim.refFlowmtrNo = refFlowmtrNo;
float time = 1.0f;
#if DN100
@@ -239,14 +239,36 @@ namespace TBF.BenchControl
if (Div2sim && (RouteSim & Path4) == Path4) Mass2sim += DiffKg(Flow4sim, time);
if (Div1sim && (RouteSim & Path5) == Path5) Mass1sim += DiffKg(Flow5sim, time);
#elif MUNICH || FUZHOU150 || FUZHOU300
if (Div1sim && (RouteSim & Path1) == Path1) Mass1sim += DiffKg(Flow1sim, time);
if (Div1sim && (RouteSim & Path2) == Path2) Mass1sim += DiffKg(Flow2sim, time);
if (Div1sim && (RouteSim & Path1) == Path1)
{
float diff = DiffKg(Flow1sim, time);
Mass1sim += diff;
log.WarnFormat("Path1: Div1, Mass1+={0}kg, flow={1}m3/h, Mass1={2}kg", diff, Flow1sim, Mass1sim);
}
if (Div1sim && (RouteSim & Path2) == Path2)
{
float diff = DiffKg(Flow2sim, time);
Mass1sim += diff;
log.WarnFormat("Path2: Div1, Mass1 += {0}kg, flow={1}m3/h, Mass1={2}kg", diff, Flow1sim, Mass1sim);
}
if (Div2sim && (RouteSim & Path3) == Path3)
{
Mass2sim += DiffKg(Flow3sim, time);
float diff = DiffKg(Flow3sim, time);
Mass2sim += diff;
log.WarnFormat("Path3: Div2, Mass2 += {0}kg, flow={1}m3/h, Mass2={2}kg", diff, Flow1sim, Mass2sim);
}
if (Div3sim && (RouteSim & Path4) == Path4)
{
float diff = DiffKg(Flow4sim, time);
Mass2sim += diff;
log.WarnFormat("Path4: Div3, Mass2 += {0}kg, flow={1}m3/h, Mass2={2}kg", diff, Flow1sim, Mass2sim);
}
if (Div3sim && (RouteSim & Path5) == Path5)
{
float diff = DiffKg(Flow5sim, time);
Mass2sim += diff;
log.WarnFormat("Path5: Div3, Mass2 += {0}kg, flow={1}m3/h, Mass2={2}kg", diff, Flow1sim, Mass2sim);
}
if (Div3sim && (RouteSim & Path4) == Path4) Mass2sim += DiffKg(Flow4sim, time);
if (Div3sim && (RouteSim & Path5) == Path5) Mass2sim += DiffKg(Flow5sim, time);
#else
if (Div1sim && (RouteSim & Path1) == Path1) Mass1sim += DiffKg(Flow1sim, time);
if (Div2sim && (RouteSim & Path2) == Path2) Mass2sim += DiffKg(Flow2sim, time);
@@ -258,43 +280,55 @@ namespace TBF.BenchControl
if ((RouteSim & EmptyValve2) == EmptyValve2) Mass2sim -= DiffKg(10.0f, time);
if (Mass2sim < 0) Mass2sim = 0;
UiBridge.Bridge.OnLog(this, string.Format("I{1}/RV{2}: q1={3}, q2={4}, q3={5}, q4={6}, q5={7}, D123={8}{9}{10}, m1={11}, m2={12}, S={13}\r\n",
time,
refFlowmtrNo, regulValveNo,
Flow1sim.ToString("F1"), Flow2sim.ToString("F1"), Flow3sim.ToString("F1"), Flow4sim.ToString("F1"), Flow5sim.ToString("F1"),
(Div1sim ? "o" : "x"), (Div2sim ? "o" : "x"), (Div3sim ? "o" : "x"),
Mass1sim.ToString("F1"), Mass2sim.ToString("F1"), ((ulong)statusP).ToString("X")));
UiBridge.Bridge.OnLog(null, string.Format("I{1}/RV{2}: q1={3}, q2={4}, q3={5}, q4={6}, q5={7}, D123={8}{9}{10}, m1={11}, m2={12}, S={13}\r\n",
time, refFlowmtrNo, regulValveNo,
Flow1sim.ToString("F1"),
Flow2sim.ToString("F1"),
Flow3sim.ToString("F1"),
Flow4sim.ToString("F1"),
Flow5sim.ToString("F1"),
(Div1sim ? "o" : "x"),
(Div2sim ? "o" : "x"),
(Div3sim ? "o" : "x"),
Mass1sim.ToString("F1"),
Mass2sim.ToString("F1"),
((ulong)statusP).ToString("X")
)
);
}
/// <summary>
/// Calculate the mass change from the flow and the time period
/// </summary>
/// <param name="flowM3H">Flow in [m3/h]</param>
/// <param name="timeSec">Time period in [s]</param>
/// <returns>Mass change in [kg]</returns>
float DiffKg(float flowM3H, float timeSec)
static float DiffKg(float flowM3H, float timeSec)
{
return timeSec * flowM3H / 3.6f;
}
/// <summary>
/// Get the simulated mass. Use the balance range to distinguish the balances.
/// </summary>
/// <param name="balanceNr">0-based balance number</param>
/// <returns>Simulated mass reading [kg]</returns>
public float GetSimMass(int balanceNr)
public static float GetSimMass(int balanceNr)
{
if (balanceNr == 0) return Mass1sim;
else if (balanceNr == 1) return Mass2sim;
else return 0;
}
/// <summary>
/// Set the simulated diverter. Use the nominal flow to distinguish the path.
/// </summary>
/// <param name="toTank">Diverter state: true = to the tank</param>
/// <param name="nominalFlow">Nominal flow of the path [m3/h]</param>
public void SetSimDiverter(bool toTank)
public static void SetSimDiverter(bool toTank)
{
#if DN100
switch (regulValveNo)
@@ -343,60 +377,12 @@ namespace TBF.BenchControl
return;
}
/// <summary>
/// Determine which autput section is used
/// </summary>
/// <param name="nominalFlow"></param>
/// <returns></returns>
int OutputPathId(float nominalFlow)
{
#if DN100
//
// Qn1=0.3, Qn2=2.5, Qn3=25, Qn4=250, Qn5=0.2
//
if (nominalFlow < 0.25f) return 5;
else if (nominalFlow < 1.0f) return 1;
else if (nominalFlow < 10.0f) return 2;
else if (nominalFlow < 100.0f) return 3;
else return 4;
#elif MUNICH
//
// Qn1=200, Qn2=20, Qn3=3, Qn4=0.25
//
if (nominalFlow <= 0.25f) return 4;
else if (nominalFlow <= 3.0f) return 3;
else if (nominalFlow <= 20.0f) return 2;
else return 1;
#elif FUZHOU150
//
// Qn1=350, Qn2=50, Qn3=7, Qn4=0.5
//
if (nominalFlow <= 0.5f) return 4;
else if (nominalFlow <= 7.0f) return 3;
else if (nominalFlow <= 50.0f) return 2;
else return 1;
#elif FUZHOU300
//
// Qn1=350, Qn2=50, Qn3=7, Qn4=0.5
//
if (nominalFlow <= 0.5f) return 4;
else if (nominalFlow <= 7.0f) return 3;
else if (nominalFlow <= 50.0f) return 2;
else return 1;
#else
//
// Qn1=1, Qn2=10
//
if (nominalFlow < 3.0f) return 1;
else return 2;
#endif
}
/// <summary>
/// Get the simulated flow in [m3/h].
/// </summary>
/// <returns>Simulated flow [m3/h]</returns>
public float GetSimFlow()
public static float GetSimFlow()
{
switch (refFlowmtrNo)
{
@@ -409,12 +395,13 @@ namespace TBF.BenchControl
}
}
/// <summary>
/// Update simulated flow. Use the nominal flow to distinguish the path.
/// </summary>
/// <param name="targetFlow">Target flow [m3/h]</param>
/// <param name="nominalFlow">Nominal flow of the path [m3/h]</param>
public void UpdateSimFlow(float targetFlow)
public static void UpdateSimFlow(float targetFlow)
{
float A = 0.7f; /// higher value -> slower regulation
float B = 1.0f - A;