FlowMetersInParallel : StartStatistics(test), UpdateStatistics(delta), StopStatistics( )
This commit is contained in:
@@ -19,9 +19,9 @@ namespace TBF.Rig.Uni.FlowMetersInParallel
|
||||
readonly FlowMeterCfg flowMeterCfg;
|
||||
|
||||
UniCB uniCB;
|
||||
IFlowMeterSingle flowMeter1;
|
||||
IFlowMeterSingle flowMeter2;
|
||||
IFlowMeterSingle flowMeter3;
|
||||
IFlowMeterSingle flowMtr1;
|
||||
IFlowMeterSingle flowMtr2;
|
||||
IFlowMeterSingle flowMtr3;
|
||||
double nominalFlow;
|
||||
double nominalFreq;
|
||||
double ltrPerPulse;
|
||||
@@ -39,77 +39,15 @@ namespace TBF.Rig.Uni.FlowMetersInParallel
|
||||
public double MsrdValLimLo { get { return flowMeterCfg.MsrdValLimLo; } set { flowMeterCfg.MsrdValLimLo = value; } }
|
||||
public double MsrdValLimHi { get { return flowMeterCfg.MsrdValLimHi; } set { flowMeterCfg.MsrdValLimHi = value; } }
|
||||
|
||||
double[] refFreq; /// 0..sum, 1..I11, 2..I12, 3..I13
|
||||
int[] refPulses;
|
||||
|
||||
public double LtrPerPulseCorrected(double flow, float temperature)
|
||||
{
|
||||
return LtrPerPulse;
|
||||
|
||||
//log.DebugFormat("LtrPerPulseCorrected({0}, {1}) started", flow, rangeIx);
|
||||
|
||||
//refFreq[0] = uniCB.RefFrequency;
|
||||
//refFreq[1] = uniCB.RefFrequency1;
|
||||
//refFreq[2] = uniCB.RefFrequency2;
|
||||
//refFreq[3] = uniCB.RefFrequency3;
|
||||
//log.DebugFormat("refFreq[] = ({0}, {1}, {2}, {3})", refFreq[0], refFreq[1], refFreq[2], refFreq[3]);
|
||||
|
||||
//refPulses[0] = uniCB.RefPulses;
|
||||
//refPulses[1] = uniCB.RefPulses1;
|
||||
//refPulses[2] = uniCB.RefPulses2;
|
||||
//refPulses[3] = uniCB.RefPulses3;
|
||||
//log.DebugFormat("refPulses[] = ({0}, {1}, {2}, {3})", refPulses[0], refPulses[1], refPulses[2], refPulses[3]);
|
||||
|
||||
//double flow1, flow2, flow3;
|
||||
//double contribution1, contribution2, contribution3;
|
||||
//if (refPulses[0] != 0)
|
||||
//{
|
||||
// /// Division by zero prevented inside this 'if'
|
||||
// double ltrPerPulseCorrected = 0;
|
||||
// if (flowMeter1 != null)
|
||||
// {
|
||||
// double ratio = (double)refPulses[flowMeter1.Idx1] / (double)refPulses[0];
|
||||
// flow1 = flow * ratio;
|
||||
// contribution1 = flowMeter1.LtrPerPulseCorrected(flow1, rangeIx) * ratio;
|
||||
// ltrPerPulseCorrected += contribution1;
|
||||
// log.DebugFormat("flowmeter1 = {0}, flow1 = {1}, contribution1 = {2}", flowMeter1.Name, flow1, contribution1);
|
||||
// }
|
||||
// if (flowMeter2 != null)
|
||||
// {
|
||||
// double ratio = (double)refPulses[flowMeter2.Idx1] / (double)refPulses[0];
|
||||
// flow2 = flow * ratio;
|
||||
// contribution2 = flowMeter2.LtrPerPulseCorrected(flow2, rangeIx) * ratio;
|
||||
// ltrPerPulseCorrected += contribution2;
|
||||
// log.DebugFormat("flowmeter2 = {0}, flow2 = {1}, contribution2 = {2}", flowMeter2.Name, flow2, contribution2);
|
||||
// }
|
||||
// if (flowMeter3 != null)
|
||||
// {
|
||||
// double ratio = (double)refPulses[flowMeter3.Idx1] / (double)refPulses[0];
|
||||
// flow3 = flow * ratio;
|
||||
// contribution3 = flowMeter3.LtrPerPulseCorrected(flow3, rangeIx) * ratio;
|
||||
// ltrPerPulseCorrected += contribution3;
|
||||
// log.DebugFormat("flowmeter3 = {0}, flow3 = {1}, contribution3 = {2}", flowMeter3.Name, flow3, contribution3);
|
||||
// }
|
||||
|
||||
// log.DebugFormat("LtrPerPulseCorrected() returns {0}", ltrPerPulseCorrected);
|
||||
// return ltrPerPulseCorrected;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// log.DebugFormat("LtrPerPulseCorrected() returns 1");
|
||||
// return 1;
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
public bool MsrmntAvailable
|
||||
{
|
||||
get
|
||||
{
|
||||
bool result = true;
|
||||
if (flowMeter1 != null) result = result && flowMeter1.MsrmntAvailable;
|
||||
if (flowMeter2 != null) result = result && flowMeter2.MsrmntAvailable;
|
||||
if (flowMeter3 != null) result = result && flowMeter3.MsrmntAvailable;
|
||||
if (flowMtr1 != null) result = result && flowMtr1.MsrmntAvailable;
|
||||
if (flowMtr2 != null) result = result && flowMtr2.MsrmntAvailable;
|
||||
if (flowMtr3 != null) result = result && flowMtr3.MsrmntAvailable;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -122,11 +60,7 @@ namespace TBF.Rig.Uni.FlowMetersInParallel
|
||||
public string AltString { get { return "Invalid format"; } }
|
||||
|
||||
|
||||
public FlowMeter()
|
||||
{
|
||||
refFreq = new double[4];
|
||||
refPulses = new int[4];
|
||||
}
|
||||
public FlowMeter() { }
|
||||
|
||||
public FlowMeter(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
||||
: base(cfg)
|
||||
@@ -139,33 +73,33 @@ namespace TBF.Rig.Uni.FlowMetersInParallel
|
||||
uniCB = TbfComponents.FindComponent(flowMeterCfg.ParentName) as UniCB;
|
||||
if (uniCB == null) throw new Exception("Cannot find " + Name + " parent");
|
||||
|
||||
if (!string.IsNullOrEmpty(flowMeterCfg.Flowmeter1)) flowMeter1 = TbfComponents.FindComponent(flowMeterCfg.Flowmeter1) as IFlowMeterSingle;
|
||||
if (!string.IsNullOrEmpty(flowMeterCfg.Flowmeter2)) flowMeter2 = TbfComponents.FindComponent(flowMeterCfg.Flowmeter2) as IFlowMeterSingle;
|
||||
if (!string.IsNullOrEmpty(flowMeterCfg.Flowmeter3)) flowMeter3 = TbfComponents.FindComponent(flowMeterCfg.Flowmeter3) as IFlowMeterSingle;
|
||||
if (!string.IsNullOrEmpty(flowMeterCfg.Flowmeter1)) flowMtr1 = TbfComponents.FindComponent(flowMeterCfg.Flowmeter1) as IFlowMeterSingle;
|
||||
if (!string.IsNullOrEmpty(flowMeterCfg.Flowmeter2)) flowMtr2 = TbfComponents.FindComponent(flowMeterCfg.Flowmeter2) as IFlowMeterSingle;
|
||||
if (!string.IsNullOrEmpty(flowMeterCfg.Flowmeter3)) flowMtr3 = TbfComponents.FindComponent(flowMeterCfg.Flowmeter3) as IFlowMeterSingle;
|
||||
|
||||
nominalFlow = 0;
|
||||
flowMetersCount = 0;
|
||||
flowMetersBitfield = 0;
|
||||
|
||||
if (flowMeter1 != null)
|
||||
if (flowMtr1 != null)
|
||||
{
|
||||
nominalFlow += flowMeter1.NominalFlow;
|
||||
nominalFreq += flowMeter1.NominalFreq;
|
||||
flowMetersBitfield |= (4 << flowMeter1.Idx1);
|
||||
nominalFlow += flowMtr1.NominalFlow;
|
||||
nominalFreq += flowMtr1.NominalFreq;
|
||||
flowMetersBitfield |= (4 << flowMtr1.Idx1);
|
||||
flowMetersCount++;
|
||||
}
|
||||
if (flowMeter2 != null)
|
||||
if (flowMtr2 != null)
|
||||
{
|
||||
nominalFlow += flowMeter2.NominalFlow;
|
||||
nominalFreq += flowMeter2.NominalFreq;
|
||||
flowMetersBitfield |= (4 << flowMeter2.Idx1);
|
||||
nominalFlow += flowMtr2.NominalFlow;
|
||||
nominalFreq += flowMtr2.NominalFreq;
|
||||
flowMetersBitfield |= (4 << flowMtr2.Idx1);
|
||||
flowMetersCount++;
|
||||
}
|
||||
if (flowMeter3 != null)
|
||||
if (flowMtr3 != null)
|
||||
{
|
||||
nominalFlow += flowMeter3.NominalFlow;
|
||||
nominalFreq += flowMeter3.NominalFreq;
|
||||
flowMetersBitfield |= (4 << flowMeter3.Idx1);
|
||||
nominalFlow += flowMtr3.NominalFlow;
|
||||
nominalFreq += flowMtr3.NominalFreq;
|
||||
flowMetersBitfield |= (4 << flowMtr3.Idx1);
|
||||
flowMetersCount++;
|
||||
}
|
||||
if (flowMetersCount == 0) throw new Exception("Missing flowmeters");
|
||||
@@ -174,9 +108,6 @@ namespace TBF.Rig.Uni.FlowMetersInParallel
|
||||
|
||||
ltrPerPulse = nominalFlow / (3.6 * nominalFreq); /// Nominal freq. is sum of particular nominal frquencies
|
||||
|
||||
refFreq = new double[4];
|
||||
refPulses = new int[4];
|
||||
|
||||
log.FatalFormat("{0} initialized: {1} nom.flow={2} m3/h nom.freq={3} Hz bitfield=0x{4:X2}",
|
||||
Name, this, nominalFlow, nominalFreq, flowMetersBitfield);
|
||||
}
|
||||
@@ -211,5 +142,60 @@ namespace TBF.Rig.Uni.FlowMetersInParallel
|
||||
{
|
||||
return new ReadFlowOp(this, ref flow, flowDone);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double flowRawSum;
|
||||
double flowSum;
|
||||
int timeSum;
|
||||
int rng1;
|
||||
int rng2;
|
||||
int rng3;
|
||||
|
||||
public void StartStatistics(Config.Entities.Test test)
|
||||
{
|
||||
flowRawSum = 0;
|
||||
flowSum = 0;
|
||||
timeSum = 0;
|
||||
|
||||
if (flowMtr1 != null) rng1 = Math.Max(0, flowMtr1.GetRange(test.TempLimLo, test.TempLimHi));
|
||||
if (flowMtr2 != null) rng2 = Math.Max(0, flowMtr2.GetRange(test.TempLimLo, test.TempLimHi));
|
||||
if (flowMtr3 != null) rng3 = Math.Max(0, flowMtr3.GetRange(test.TempLimLo, test.TempLimHi));
|
||||
}
|
||||
|
||||
public void UpdateStatistics(int timeDelta)
|
||||
{
|
||||
double tempFlow;
|
||||
if (flowMtr1 != null)
|
||||
{
|
||||
flowRawSum += timeDelta * (tempFlow = flowMtr1.ReadFlow());
|
||||
flowSum += timeDelta * flowMtr1.CorrectedFlow(tempFlow, rng1); ;
|
||||
}
|
||||
if (flowMtr2 != null)
|
||||
{
|
||||
flowRawSum += timeDelta * (tempFlow = flowMtr2.ReadFlow());
|
||||
flowSum += timeDelta * flowMtr2.CorrectedFlow(tempFlow, rng2); ;
|
||||
}
|
||||
if (flowMtr3 != null)
|
||||
{
|
||||
flowRawSum += timeDelta * (tempFlow = flowMtr3.ReadFlow());
|
||||
flowSum += timeDelta * flowMtr3.CorrectedFlow(tempFlow, rng3); ;
|
||||
}
|
||||
|
||||
timeSum += timeDelta;
|
||||
}
|
||||
|
||||
public void StopStatistics()
|
||||
{
|
||||
flowRawSum /= Convert.ToDouble(timeSum);
|
||||
flowSum /= Convert.ToDouble(timeSum);
|
||||
log.WarnFormat("StopStatistics() flowRawSum = {0:F3} m3/h flowSum = {1:F3} m3/h", flowRawSum, flowSum);
|
||||
}
|
||||
|
||||
public double LtrPerPulseCorrected(double flow, float temperature)
|
||||
{
|
||||
double ltrPerPulseCorrected = (flowRawSum == 0) ? LtrPerPulse : LtrPerPulse * flowSum / flowRawSum;
|
||||
log.WarnFormat("LtrPerPulseCorrected() flow = {0:F3} m3/h flowRawSum = {1:F3} m3/h flowSum = {2:F3} m3/h temperature = {3:F1} C ltrPerPulseCorrected = {4}", flow, flowRawSum, flowSum, temperature, ltrPerPulseCorrected);
|
||||
return ltrPerPulseCorrected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user