791 lines
24 KiB
C#
791 lines
24 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using Dirichlet.Numerics;
|
|
using log4net;
|
|
|
|
namespace TBF.BenchControl
|
|
{
|
|
/// <summary>
|
|
/// Test bench model inherited by all classes for the simulation of devices.
|
|
/// Define DN100, MUNICH or nothing.
|
|
/// </summary>
|
|
public static class TestBenchSim
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(TestBenchSim));
|
|
|
|
///
|
|
/// Incremented in RunDevice() depending on diverters and valves
|
|
///
|
|
public static float Mass1sim; /// Volume in [ltr] or mass in [kg] in the tank1 on the balance1, filled by the diverter1
|
|
public static float Mass2sim; /// Volume in [ltr] or mass in [kg] in the tank2 on the balance2, filled by the diverter2
|
|
|
|
///
|
|
/// Set by regulation valves
|
|
///
|
|
public static float Flow1sim; /// flow in [m3/h] through RV1
|
|
public static float Flow2sim; /// flow in [m3/h] through RV2
|
|
public static float Flow3sim; /// flow in [m3/h] through RV3
|
|
public static float Flow4sim; /// flow in [m3/h] through RV4
|
|
public static float Flow5sim; /// flow in [m3/h] through RV5
|
|
public static float Flow6sim; /// flow in [m3/h] through RV5
|
|
|
|
///
|
|
/// Valves and diverters
|
|
///
|
|
public static UInt128 SimRoute;
|
|
public static bool Div1sim;
|
|
public static bool Div2sim;
|
|
public static bool Div3sim;
|
|
|
|
static int regulValveNo; /// 0=undefined, 1..5
|
|
static int refFlowmtrNo; /// 0=undefined, 1..4
|
|
|
|
public static void Initialize()
|
|
{
|
|
Mass1sim = 0.0f; /// Initialize tanks
|
|
Mass2sim = 0.0f;
|
|
Flow1sim = 0.0f; /// Initialize regulation valves
|
|
Flow2sim = 0.0f;
|
|
Flow3sim = 0.0f;
|
|
Flow4sim = 0.0f;
|
|
Flow5sim = 0.0f;
|
|
Flow6sim = 0.0f;
|
|
SimRoute = 0; /// Initialize other valves
|
|
Div1sim = false;
|
|
Div2sim = false;
|
|
Div3sim = false;
|
|
}
|
|
|
|
#if DN100
|
|
/// Paths modulating the flows
|
|
const ulong K5 = (1L << 0);
|
|
const ulong K7 = (1L << 1);
|
|
const ulong K10 = (1L << 2);
|
|
const ulong K13 = (1L << 3);
|
|
const ulong K16 = (1L << 4);
|
|
const ulong K2 = (1L << 5);
|
|
const ulong EmptyValve1 = (1L << 17);
|
|
const ulong EmptyValve2 = (1L << 18);
|
|
const ulong Vl5 = (1L << 21);
|
|
const ulong Path1 = K2 | K5 | K7;
|
|
const ulong Path2 = K2 | K5 | K10;
|
|
const ulong Path3 = K2 | K5 | K13;
|
|
const ulong Path4 = K2 | K5 | K16;
|
|
const ulong Path5 = K2 | K5 | Vl5;
|
|
#elif MUNICH
|
|
const ulong VL11 = (1L << 0);
|
|
const ulong VL13 = (1L << 1);
|
|
const ulong VL21 = (1L << 2);
|
|
const ulong VL23 = (1L << 3);
|
|
const ulong VZ1 = (1L << 4);
|
|
const ulong VP2 = (1L << 5);
|
|
const ulong VP4 = (1L << 6);
|
|
const ulong VP5 = (1L << 7);
|
|
|
|
const ulong VP6 = (1L << 8);
|
|
const ulong VL12 = (1L << 9);
|
|
const ulong VL22 = (1L << 10);
|
|
const ulong VI11 = (1L << 11);
|
|
const ulong VI12 = (1L << 12);
|
|
const ulong VI13 = (1L << 13);
|
|
const ulong VI21 = (1L << 14);
|
|
const ulong VI22 = (1L << 15);
|
|
|
|
const ulong VI2P = (1L << 16);
|
|
const ulong VI31 = (1L << 17);
|
|
const ulong VI32 = (1L << 18);
|
|
const ulong VI3P = (1L << 19);
|
|
const ulong VI41 = (1L << 20);
|
|
const ulong VI42 = (1L << 21);
|
|
const ulong VI43 = (1L << 22);
|
|
const ulong VI4P = (1L << 23);
|
|
|
|
const ulong VB1 = (1L << 24);
|
|
const ulong VB1a = (1L << 25);
|
|
const ulong VB2 = (1L << 26);
|
|
const ulong VB2a = (1L << 27);
|
|
const ulong VM1 = (1L << 28);
|
|
const ulong VM2 = (1L << 29);
|
|
const ulong VM3 = (1L << 30);
|
|
const ulong VM4 = ((ulong)1 << 31);
|
|
|
|
const ulong Pump1 = ((ulong)1 << 32);
|
|
const ulong Block = ((ulong)1 << 33);
|
|
const ulong VZ8 = ((ulong)1 << 37);
|
|
|
|
const ulong EmptyValve1 = VB1 | VB1a;
|
|
const ulong EmptyValve2 = VB2 | VB2a;
|
|
|
|
const ulong Path1 = VZ1 | VL12 | VI11 | VI13;
|
|
const ulong Path2 = VZ1 | VL11 | VL12 | VI21 | VI22 | VI13;
|
|
const ulong Path3 = VZ1 | VL11 | VL12 | VI31 | VI32;
|
|
const ulong Path4 = VZ1 | VL11 | VL12 | VI41 | VI42;
|
|
const ulong Path5 = VZ1 | VL11 | VL12 | VI41 | VI43;
|
|
#elif FUZHOU150
|
|
const ulong VL11 = (1L << 2);
|
|
const ulong VL13 = (1L << 3);
|
|
const ulong VL4 = (1L << 4);
|
|
const ulong VZ6 = (1L << 5);
|
|
const ulong VZ7 = (1L << 6);
|
|
const ulong VP5 = (1L << 7);
|
|
|
|
const ulong VP6 = (1L << 8);
|
|
const ulong VL12 = (1L << 9);
|
|
const ulong VZ14 = (1L << 10);
|
|
const ulong VI11 = (1L << 11);
|
|
const ulong VI12 = (1L << 12);
|
|
const ulong VI13 = (1L << 13);
|
|
const ulong VI21 = (1L << 14);
|
|
const ulong VI22 = (1L << 15);
|
|
|
|
const ulong VI2p = (1L << 16);
|
|
const ulong VI31 = (1L << 17);
|
|
const ulong VI32 = (1L << 18);
|
|
const ulong VI3p = (1L << 19);
|
|
const ulong VI41 = (1L << 20);
|
|
const ulong VI42 = (1L << 21);
|
|
const ulong VI43 = (1L << 22);
|
|
const ulong VI4p = (1L << 23);
|
|
|
|
const ulong VB1 = (1L << 24);
|
|
const ulong VB1a = (1L << 25);
|
|
const ulong VB2 = (1L << 26);
|
|
const ulong VB2a = (1L << 27);
|
|
const ulong VM1 = (1L << 28);
|
|
const ulong VM2 = (1L << 29);
|
|
const ulong VM3 = (1L << 20);
|
|
|
|
const ulong Pump1 = ((ulong)1 << 32);
|
|
const ulong Pump4 = ((ulong)1 << 33);
|
|
const ulong Pump2 = ((ulong)1 << 37);
|
|
const ulong Pump3 = ((ulong)1 << 38);
|
|
const ulong Pump5 = ((ulong)1 << 39);
|
|
|
|
const ulong EmptyValve1 = VB1 | VB1a;
|
|
const ulong EmptyValve2 = VB2 | VB2a;
|
|
|
|
const ulong Path1 = VL12 | VI11 | VI13;
|
|
const ulong Path2 = VL12 | VI21 | VI22 | VI13;
|
|
const ulong Path3 = VL12 | VI31 | VI32;
|
|
const ulong Path4 = VL12 | VI41 | VI42;
|
|
const ulong Path5 = VL12 | VI41 | VI43;
|
|
#elif FUZHOU300
|
|
const ulong VL11 = (1L << 2);
|
|
const ulong VL13 = (1L << 3);
|
|
const ulong VL4 = (1L << 4);
|
|
const ulong VZ6 = (1L << 5);
|
|
const ulong VZ7 = (1L << 6);
|
|
const ulong VP5 = (1L << 7);
|
|
|
|
const ulong VP6 = (1L << 8);
|
|
const ulong VL12 = (1L << 9);
|
|
const ulong VZ14 = (1L << 10);
|
|
const ulong VI11 = (1L << 11);
|
|
const ulong VI12 = (1L << 12);
|
|
const ulong VI13 = (1L << 13);
|
|
const ulong VI21 = (1L << 14);
|
|
const ulong VI22 = (1L << 15);
|
|
|
|
const ulong VI2p = (1L << 16);
|
|
const ulong VI31 = (1L << 17);
|
|
const ulong VI32 = (1L << 18);
|
|
const ulong VI3p = (1L << 19);
|
|
const ulong VI41 = (1L << 20);
|
|
const ulong VI42 = (1L << 21);
|
|
const ulong VI43 = (1L << 22);
|
|
const ulong VI4p = (1L << 23);
|
|
|
|
const ulong VB1 = (1L << 24);
|
|
const ulong VB1a = (1L << 25);
|
|
const ulong VB2 = (1L << 26);
|
|
const ulong VB2a = (1L << 27);
|
|
const ulong VM1 = (1L << 28);
|
|
const ulong VM2 = (1L << 29);
|
|
const ulong VM3 = (1L << 20);
|
|
|
|
const ulong Pump1 = ((ulong)1 << 32);
|
|
const ulong Pump4 = ((ulong)1 << 33);
|
|
const ulong Pump2 = ((ulong)1 << 37);
|
|
const ulong Pump3 = ((ulong)1 << 38);
|
|
const ulong Pump5 = ((ulong)1 << 39);
|
|
|
|
const ulong EmptyValve1 = VB1 | VB1a;
|
|
const ulong EmptyValve2 = VB2 | VB2a;
|
|
|
|
const ulong Path1 = VL12 | VI11 | VI13;
|
|
const ulong Path2 = VL12 | VI21 | VI22 | VI13;
|
|
const ulong Path3 = VL12 | VI31 | VI32;
|
|
const ulong Path4 = VL12 | VI41 | VI42;
|
|
const ulong Path5 = VL12 | VI41 | VI43;
|
|
#elif PT200IL || PUCHONG_PT200 || GENESIS || BERLIN
|
|
const ulong VM11 = (1L << 4);
|
|
const ulong VM12 = (1L << 5);
|
|
const ulong VM21 = (1L << 6);
|
|
const ulong VM22 = (1L << 7);
|
|
|
|
const ulong VZ14 = (1L << 8);
|
|
const ulong VZ13 = (1L << 9);
|
|
const ulong VL11 = (1L << 10);
|
|
const ulong VL13 = (1L << 11);
|
|
const ulong VL4 = (1L << 12);
|
|
const ulong VZ6 = (1L << 13);
|
|
const ulong VZ7 = (1L << 14);
|
|
const ulong VP5 = (1L << 15);
|
|
|
|
const ulong VP6 = (1L << 16);
|
|
const ulong VL12 = (1L << 17);
|
|
const ulong VL51 = (1L << 18);
|
|
const ulong VL53 = (1L << 19);
|
|
const ulong VI11 = (1L << 20);
|
|
const ulong VI12 = (1L << 21);
|
|
const ulong VI13 = (1L << 22);
|
|
const ulong VV1 = (1L << 23);
|
|
|
|
const ulong VI21 = (1L << 25);
|
|
const ulong VI22 = (1L << 26);
|
|
const ulong VI2p = (1L << 27);
|
|
const ulong VI31 = (1L << 28);
|
|
const ulong VI32 = (1L << 29);
|
|
const ulong VI3p = (1L << 30);
|
|
const ulong VI41 = (1L << 31);
|
|
|
|
const ulong VI42 = (1L << 32);
|
|
const ulong VI4p = (1L << 33);
|
|
const ulong VI43 = (1L << 37);
|
|
|
|
const ulong VM1 = (1L << 50);
|
|
const ulong VM2 = (1L << 51);
|
|
const ulong VM3 = (1L << 52);
|
|
|
|
const ulong VB1 = (1L << 41);
|
|
const ulong VB1a = (1L << 42);
|
|
const ulong VB2 = (1L << 43);
|
|
const ulong VB2a = (1L << 44);
|
|
|
|
const ulong Pump1 = (1L << 48);
|
|
const ulong Pump4 = (1L << 49);
|
|
const ulong Pump2 = (1L << 38);
|
|
const ulong Pump3 = (1L << 39);
|
|
const ulong Pump5 = (1L << 40);
|
|
|
|
const ulong EmptyValve1 = VB1 | VB1a;
|
|
const ulong EmptyValve2 = VB2 | VB2a;
|
|
|
|
const ulong Path1 = VL12 | VI11 | VI13;
|
|
const ulong Path2 = VL12 | VI21 | VI22 | VI13;
|
|
const ulong Path3 = VL12 | VI31 | VI32;
|
|
const ulong Path4 = VL12 | VI41 | VI42;
|
|
const ulong Path5 = VL12 | VI41 | VI43;
|
|
#elif BADGER_MALA_TRAT || BADGER_VELKA_TRAT
|
|
const ulong VZ34 = (1L << 0);
|
|
const ulong VZ35 = (1L << 1);
|
|
const ulong VZ39 = (1L << 2);
|
|
const ulong VZ37 = (1L << 3);
|
|
const ulong VZ38 = (1L << 4);
|
|
const ulong VL31 = (1L << 5);
|
|
const ulong VV1 = (1L << 6);
|
|
const ulong VS33 = (1L << 7);
|
|
|
|
const ulong VS31 = (1L << 8);
|
|
const ulong VS32 = (1L << 9);
|
|
const ulong VV2 = (1L << 10);
|
|
const ulong VL32 = (1L << 11);
|
|
const ulong VI31 = (1L << 12);
|
|
const ulong VI32 = (1L << 13);
|
|
const ulong VI33 = (1L << 14);
|
|
const ulong VI34 = (1L << 15);
|
|
|
|
const ulong DIV1 = (1L << 16);
|
|
const ulong DIV2 = (1L << 17);
|
|
const ulong VB1 = (1L << 18);
|
|
const ulong VB1a = (1L << 19);
|
|
const ulong VB2 = (1L << 20);
|
|
const ulong VB2a = (1L << 21);
|
|
const ulong P1 = (1L << 22);
|
|
const ulong P2 = (1L << 23);
|
|
|
|
const ulong EmptyValve1 = VB1 | VB1a;
|
|
const ulong EmptyValve2 = VB2 | VB2a;
|
|
|
|
const ulong Path1 = VI31;
|
|
const ulong Path2 = VI32;
|
|
const ulong Path3 = VI33;
|
|
const ulong Path4 = VI34;
|
|
const ulong Path5 = 0;
|
|
#elif CEVAK_PT40_272 || MURES_PT40 || FUZHOU_40 || SLM_50 || MALTA_WSD25
|
|
const ulong VL11 = (1L << 0);
|
|
const ulong VL13 = (1L << 1);
|
|
const ulong VL18 = (1L << 2);
|
|
const ulong VZ12 = (1L << 3);
|
|
const ulong VL15 = (1L << 4);
|
|
const ulong VL21 = (1L << 5);
|
|
const ulong VL23 = (1L << 6);
|
|
const ulong VL28 = (1L << 7);
|
|
|
|
const ulong VZ5 = (1L << 8);
|
|
const ulong VI1 = (1L << 9);
|
|
const ulong VI2 = (1L << 10);
|
|
const ulong VI3 = (1L << 11);
|
|
const ulong VZ9 = (1L << 12);
|
|
const ulong VBa = (1L << 13);
|
|
const ulong VB = (1L << 14);
|
|
const ulong DIV1 = (1L << 15);
|
|
|
|
const ulong P1 = (1L << 16);
|
|
const ulong P2 = (1L << 17);
|
|
const ulong VL9 = (1L << 18);
|
|
const ulong VV1 = (1L << 19);
|
|
const ulong VV2 = (1L << 20);
|
|
const ulong VZ6 = (1L << 21);
|
|
const ulong VV3 = (1L << 22);
|
|
const ulong Gate = (1L << 23);
|
|
|
|
const ulong EmptyValve1 = VB | VBa;
|
|
const ulong EmptyValve2 = 0x0000FFFFFFFFFFFF;
|
|
|
|
const ulong Path1 = VI1;
|
|
const ulong Path2 = VI2;
|
|
const ulong Path3 = VI3;
|
|
const ulong Path4 = 0;
|
|
const ulong Path5 = 0;
|
|
#elif TORINO50
|
|
const ulong nic1 = (1L << 0);
|
|
const ulong nic2 = (1L << 1);
|
|
const ulong VL11 = (1L << 2);
|
|
const ulong VL13 = (1L << 3);
|
|
const ulong VL18 = (1L << 4);
|
|
const ulong VZ13 = (1L << 5);
|
|
const ulong VL15 = (1L << 6);
|
|
const ulong VZ10 = (1L << 7);
|
|
|
|
const ulong VZ6 = (1L << 8);
|
|
const ulong VV1 = (1L << 9);
|
|
const ulong VV4 = (1L << 10);
|
|
const ulong VL12 = (1L << 11);
|
|
const ulong VI1 = (1L << 12);
|
|
const ulong VI2 = (1L << 13);
|
|
const ulong VI3 = (1L << 14);
|
|
const ulong VI4 = (1L << 15);
|
|
|
|
const ulong VB1 = (1L << 16);
|
|
const ulong VB1a = (1L << 17);
|
|
const ulong VB2 = (1L << 18);
|
|
const ulong VB2a = (1L << 19);
|
|
const ulong DIV1 = (1L << 20);
|
|
const ulong DIV2 = (1L << 21);
|
|
const ulong P1 = (1L << 22);
|
|
const ulong P3 = (1L << 23);
|
|
|
|
const ulong P2 = (1L << 24);
|
|
|
|
const ulong EmptyValve1 = VB1 | VB1a;
|
|
const ulong EmptyValve2 = VB2 | VB2a;
|
|
|
|
const ulong Path1 = VI1;
|
|
const ulong Path2 = VI2;
|
|
const ulong Path3 = VI3;
|
|
const ulong Path4 = VI4;
|
|
const ulong Path5 = 0;
|
|
#elif TORUN_PT50_2015 || TURA_IPERL
|
|
const ulong VL11 = (1L << 0);
|
|
const ulong VL13 = (1L << 1);
|
|
const ulong VL15 = (1L << 2);
|
|
const ulong VL21 = (1L << 3);
|
|
const ulong VL23 = (1L << 4);
|
|
const ulong VL18 = (1L << 5);
|
|
const ulong VL28 = (1L << 6);
|
|
const ulong VZ5 = (1L << 7);
|
|
|
|
const ulong VZ6 = (1L << 8);
|
|
const ulong DIV1 = (1L << 9);
|
|
const ulong DIV2 = (1L << 10);
|
|
const ulong P1 = (1L << 11);
|
|
const ulong P2 = (1L << 12);
|
|
const ulong P3 = (1L << 13);
|
|
const ulong DIV3 = (1L << 14);
|
|
const ulong rez1 = (1L << 15);
|
|
|
|
const ulong nic1 = (1L << 16);
|
|
const ulong nic2 = (1L << 17);
|
|
const ulong VI1 = (1L << 18);
|
|
const ulong VI2 = (1L << 19);
|
|
const ulong VI3 = (1L << 20);
|
|
const ulong VI4 = (1L << 21);
|
|
const ulong VI5 = (1L << 22);
|
|
const ulong VB1 = (1L << 23);
|
|
|
|
const ulong VV12 = (1L << 24);
|
|
const ulong VV22 = (1L << 25);
|
|
const ulong VI6 = (1L << 26);
|
|
const ulong VV3 = (1L << 27);
|
|
const ulong VB2 = (1L << 28);
|
|
|
|
const ulong EmptyValve1 = VB1;
|
|
const ulong EmptyValve2 = VB2;
|
|
|
|
const ulong Path1 = VI1;
|
|
const ulong Path2 = VI2;
|
|
const ulong Path3 = VI3;
|
|
const ulong Path4 = VI4;
|
|
const ulong Path5 = VI5;
|
|
const ulong Path6 = VI6;
|
|
#elif TURA_SPECIAL
|
|
const ulong VL11 = (1L << 0);
|
|
const ulong VL13 = (1L << 1);
|
|
const ulong VL15 = (1L << 2);
|
|
const ulong VL21 = (1L << 3);
|
|
const ulong VL23 = (1L << 4);
|
|
const ulong VL18 = (1L << 5);
|
|
const ulong VL28 = (1L << 6);
|
|
const ulong VZ5 = (1L << 7);
|
|
|
|
const ulong VZ6 = (1L << 8);
|
|
const ulong DIV1 = (1L << 9);
|
|
const ulong DIV2 = (1L << 10);
|
|
const ulong P1 = (1L << 11);
|
|
const ulong P2 = (1L << 12);
|
|
const ulong P3 = (1L << 13);
|
|
const ulong DIV3 = (1L << 14);
|
|
const ulong rez1 = (1L << 15);
|
|
|
|
const ulong nic1 = (1L << 16);
|
|
const ulong nic2 = (1L << 17);
|
|
const ulong VI1 = (1L << 18);
|
|
const ulong VI2 = (1L << 19);
|
|
const ulong VI3 = (1L << 20);
|
|
const ulong VI4 = (1L << 21);
|
|
const ulong VI5 = (1L << 22);
|
|
const ulong VB1 = (1L << 23);
|
|
|
|
const ulong VV12 = (1L << 24);
|
|
const ulong VV22 = (1L << 25);
|
|
const ulong VI6 = (1L << 26);
|
|
const ulong VV3 = (1L << 27);
|
|
const ulong VB2 = (1L << 28);
|
|
|
|
const ulong EmptyValve1 = VB1;
|
|
const ulong EmptyValve2 = VB2;
|
|
|
|
const ulong Path1 = VI1;
|
|
const ulong Path2 = VI2;
|
|
const ulong Path3 = VI3;
|
|
const ulong Path4 = VI4;
|
|
const ulong Path5 = VI5;
|
|
const ulong Path6 = VI6;
|
|
#else
|
|
/// Paths modulating the flows
|
|
const ulong V1 = (1L << 1);
|
|
const ulong V2 = (1L << 2);
|
|
const ulong V3 = (1L << 3);
|
|
const ulong V3b = (1L << 4);
|
|
const ulong V4 = (1L << 5);
|
|
const ulong V4b = (1L << 6);
|
|
const ulong V5 = (1L << 7);
|
|
const ulong V5b = (1L << 8);
|
|
const ulong EmptyValve1 = (1L << 9); // =Ve1
|
|
const ulong EmptyValve2 = (1L << 10); // =Ve2
|
|
const ulong Path1 = V1 | V3 | V3b | V4 | V4b;
|
|
const ulong Path2 = V2 | V3 | V3b | V5 | V5b;
|
|
const ulong Path3 = 0;
|
|
const ulong Path4 = 0;
|
|
const ulong Path5 = 0;
|
|
#endif
|
|
/// <summary>Run this device</summary>
|
|
public static void RunDevice(int regulValveNo, int refFlowmtrNo, Elde.StatusP statusP)
|
|
{
|
|
TestBenchSim.regulValveNo = regulValveNo;
|
|
TestBenchSim.refFlowmtrNo = refFlowmtrNo;
|
|
float time = 1.0f;
|
|
|
|
#if DN100
|
|
if (Div1sim && (SimRoute & Path1) == Path1) Mass1sim += DiffKg(Flow1sim, time);
|
|
if (Div1sim && (SimRoute & Path2) == Path2) Mass1sim += DiffKg(Flow2sim, time);
|
|
if (Div2sim && (SimRoute & Path3) == Path3) Mass2sim += DiffKg(Flow3sim, time);
|
|
if (Div2sim && (SimRoute & Path4) == Path4) Mass2sim += DiffKg(Flow4sim, time);
|
|
if (Div1sim && (SimRoute & Path5) == Path5) Mass1sim += DiffKg(Flow5sim, time);
|
|
#elif MUNICH || FUZHOU150 || FUZHOU300 || PT200IL || PUCHONG_PT200 || GENESIS || BERLIN
|
|
if (Div1sim && (SimRoute & 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 && (SimRoute & 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 && (SimRoute & Path3) == Path3)
|
|
{
|
|
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 && (SimRoute & 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 && (SimRoute & 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);
|
|
}
|
|
#elif BADGER_MALA_TRAT || BADGER_VELKA_TRAT || TORINO50 /// Path1,2 do WT1, Path3,4 do WT2
|
|
if (Div1sim && (SimRoute & Path1) == Path1) Mass1sim += DiffKg(Flow1sim, time);
|
|
if (Div1sim && (SimRoute & Path2) == Path2) Mass1sim += DiffKg(Flow2sim, time);
|
|
if (Div2sim && (SimRoute & Path3) == Path3) Mass2sim += DiffKg(Flow3sim, time);
|
|
if (Div2sim && (SimRoute & Path4) == Path4) Mass2sim += DiffKg(Flow4sim, time);
|
|
#elif CEVAK_PT40_272 || MURES_PT40 || FUZHOU_40 || SLM_50 || MALTA_WSD25 /// Path1,2,3 do WT1
|
|
if (Div1sim && (SimRoute & Path1) == Path1) Mass1sim += DiffKg(Flow1sim, time);
|
|
if (Div1sim && (SimRoute & Path2) == Path2) Mass1sim += DiffKg(Flow2sim, time);
|
|
if (Div1sim && (SimRoute & Path3) == Path3) Mass1sim += DiffKg(Flow3sim, time);
|
|
#elif TORUN_PT50_2015 || TURA_IPERL /// Path1,2,3,4,5 do WT1, Path6 do WT2
|
|
if (Div1sim && (SimRoute & Path1) == Path1) Mass1sim += DiffKg(Flow1sim, time);
|
|
if (Div1sim && (SimRoute & Path2) == Path2) Mass1sim += DiffKg(Flow2sim, time);
|
|
if (Div1sim && (SimRoute & Path3) == Path3) Mass1sim += DiffKg(Flow3sim, time);
|
|
if (Div2sim && (SimRoute & Path4) == Path4) Mass1sim += DiffKg(Flow4sim, time);
|
|
if (Div2sim && (SimRoute & Path5) == Path5) Mass1sim += DiffKg(Flow5sim, time);
|
|
if (Div3sim && (SimRoute & Path6) == Path6) Mass2sim += DiffKg(Flow4sim, time);
|
|
#elif TURA_SPECIAL
|
|
if (Div1sim && (SimRoute & Path1) == Path1) Mass1sim += DiffKg(Flow1sim, time);
|
|
if (Div1sim && (SimRoute & Path2) == Path2) Mass1sim += DiffKg(Flow2sim, time);
|
|
if (Div1sim && (SimRoute & Path3) == Path3) Mass1sim += DiffKg(Flow3sim, time);
|
|
if (Div2sim && (SimRoute & Path4) == Path4) Mass1sim += DiffKg(Flow4sim, time);
|
|
if (Div2sim && (SimRoute & Path5) == Path5) Mass1sim += DiffKg(Flow5sim, time);
|
|
if (Div3sim && (SimRoute & Path6) == Path6) Mass2sim += DiffKg(Flow4sim, time);
|
|
#else
|
|
if (Div1sim && (SimRoute & Path1) == Path1) Mass1sim += DiffKg(Flow1sim, time);
|
|
if (Div2sim && (SimRoute & Path2) == Path2) Mass2sim += DiffKg(Flow2sim, time);
|
|
#endif
|
|
|
|
if ((SimRoute & EmptyValve1) == EmptyValve1) Mass1sim -= DiffKg(100.0f, time);
|
|
if (Mass1sim < 0) Mass1sim = 0;
|
|
|
|
if ((SimRoute & EmptyValve2) == EmptyValve2) Mass2sim -= DiffKg(10.0f, time);
|
|
if (Mass2sim < 0) Mass2sim = 0;
|
|
|
|
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>
|
|
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 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 static void SetSimDiverter(bool toTank)
|
|
{
|
|
#if DN100
|
|
switch (regulValveNo)
|
|
{
|
|
case 1:
|
|
case 2:
|
|
case 5:
|
|
Div1sim = toTank;
|
|
break;
|
|
case 3:
|
|
case 4:
|
|
Div2sim = toTank;
|
|
break;
|
|
default:
|
|
if (toTank) { throw (new Exception()); }
|
|
break;
|
|
}
|
|
#elif MUNICH || FUZHOU150 || FUZHOU300 || PT200IL || PUCHONG_PT200 || GENESIS || BERLIN
|
|
switch (regulValveNo)
|
|
{
|
|
case 1:
|
|
case 2:
|
|
Div1sim = toTank;
|
|
break;
|
|
case 3:
|
|
Div2sim = toTank;
|
|
break;
|
|
case 4:
|
|
case 5:
|
|
Div3sim = toTank;
|
|
break;
|
|
default:
|
|
//if (toTank) { throw (new Exception()); }
|
|
break;
|
|
}
|
|
#elif BADGER_MALA_TRAT || TORINO50
|
|
switch (regulValveNo)
|
|
{
|
|
case 1:
|
|
case 2:
|
|
Div1sim = toTank;
|
|
break;
|
|
case 3:
|
|
case 4:
|
|
Div2sim = toTank;
|
|
break;
|
|
default:
|
|
if (toTank) { throw (new Exception()); }
|
|
break;
|
|
}
|
|
#elif BADGER_VELKA_TRAT
|
|
switch (regulValveNo)
|
|
{
|
|
case 7:
|
|
case 2:
|
|
Div1sim = toTank;
|
|
break;
|
|
case 3:
|
|
Div2sim = toTank;
|
|
break;
|
|
default:
|
|
if (toTank) { throw (new Exception()); }
|
|
break;
|
|
}
|
|
#elif CEVAK_PT40_272 || MURES_PT40 || FUZHOU_40 || SLM_50 || MALTA_WSD25
|
|
switch (regulValveNo)
|
|
{
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
Div1sim = toTank;
|
|
break;
|
|
default:
|
|
if (toTank) { /* throw (new Exception()); */ }
|
|
break;
|
|
}
|
|
#elif TORUN_PT50_2015 || TURA_IPERL
|
|
switch (regulValveNo)
|
|
{
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
Div1sim = toTank;
|
|
break;
|
|
case 4:
|
|
case 5:
|
|
Div2sim = toTank;
|
|
break;
|
|
case 6:
|
|
Div3sim = toTank;
|
|
break;
|
|
default:
|
|
if (toTank) { throw (new Exception()); }
|
|
break;
|
|
}
|
|
#elif TURA_SPECIAL
|
|
switch (regulValveNo)
|
|
{
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
Div1sim = toTank;
|
|
break;
|
|
case 4:
|
|
case 5:
|
|
Div2sim = toTank;
|
|
break;
|
|
case 6:
|
|
Div3sim = toTank;
|
|
break;
|
|
default:
|
|
if (toTank) { throw (new Exception()); }
|
|
break;
|
|
}
|
|
#else
|
|
switch (regulValveNo)
|
|
{
|
|
case 1: Div1sim = toTank; break;
|
|
case 2: Div2sim = toTank; break;
|
|
default:
|
|
if (toTank) { throw (new Exception()); }
|
|
break;
|
|
}
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get the simulated flow in [m3/h].
|
|
/// </summary>
|
|
/// <returns>Simulated flow [m3/h]</returns>
|
|
public static float GetSimFlow()
|
|
{
|
|
switch (refFlowmtrNo)
|
|
{
|
|
case 1: return ((SimRoute & Path1) == Path1) ? Flow1sim : 0;
|
|
case 2: return ((SimRoute & Path2) == Path2) ? Flow2sim : 0;
|
|
case 3: return ((SimRoute & Path3) == Path3) ? Flow3sim : 0;
|
|
case 4: return (((SimRoute & Path4) == Path4) ? Flow4sim : 0) +
|
|
(((SimRoute & Path5) == Path5) ? Flow5sim : 0);
|
|
default: return 0;
|
|
}
|
|
}
|
|
|
|
|
|
/// <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 static void UpdateSimFlow(float targetFlow)
|
|
{
|
|
float A = 0.7f; /// higher value -> slower regulation
|
|
float B = 1.0f - A;
|
|
|
|
switch (regulValveNo)
|
|
{
|
|
case 1: Flow1sim = A * Flow1sim + B * targetFlow; break;
|
|
case 2: Flow2sim = A * Flow2sim + B * targetFlow; break;
|
|
case 3: Flow3sim = A * Flow3sim + B * targetFlow; break;
|
|
case 4: Flow4sim = A * Flow4sim + B * targetFlow; break;
|
|
case 5: Flow5sim = A * Flow5sim + B * targetFlow; break;
|
|
case 6: Flow6sim = A * Flow6sim + B * targetFlow; break;
|
|
default: break;
|
|
}
|
|
}
|
|
}
|
|
}
|