Esempio n. 1
0
        /*public override bool IsSolveReady() {
         * bool isReady = false;
         * if (inlet is DryingStream) {
         *    DryingStream dsInlet = inlet as DryingStream;
         *    if (dsInlet.MassFlowRateDryBase.HasValue && dsInlet.Temperature.HasValue &&
         *       dsInlet.MoistureContentDryBase.HasValue) {
         *       isReady = true;
         *    }
         * }
         *
         * return isReady;
         * }*/

        public override void Execute(bool propagate)
        {
            isBeingExecuted = true;
            //if (IsSolveReady() && inlet is DryingStream) {
            if (inlet is DryingStream)
            {
                DryingStream dsInlet  = inlet as DryingStream;
                DryingStream dsOutlet = outlet as DryingStream;

                if (dsInlet.Pressure.HasValue && !dsOutlet.Pressure.HasValue)
                {
                    dsOutlet.Pressure.Value = dsInlet.Pressure.Value;
                }
                //else if (dsOutlet.Pressure.HasValue && !dsInlet.Pressure.HasValue) {
                //   dsInlet.Pressure.Value = dsOutlet.Pressure.Value;
                //}

                if (inlet is DryingMaterialStream)
                {
                    BalanceDryingMaterialStreamSpecificHeat(inlet as DryingMaterialStream, outlet as DryingMaterialStream);
                }
                double oldMassFlowDryBasisValue;
                double oldTemperatureValue;
                double oldMoistureContentDryBasisValue;
                double newMassFlowDryBasisValue        = dsInlet.MassFlowRateDryBase.Value;
                double newTemperatureValue             = dsInlet.Temperature.Value;
                double newMoistureContentDryBasisValue = dsInlet.MoistureContentDryBase.Value;

                if (!dsInlet.MassFlowRateDryBase.HasValue)
                {
                    newMassFlowDryBasisValue = 0.000;
                }
                if (!dsInlet.Temperature.HasValue)
                {
                    newTemperatureValue = 274.15;
                }
                if (!dsInlet.MoistureContentDryBase.HasValue)
                {
                    newMoistureContentDryBasisValue = 0.0000;
                }

                int counter = 0;
                do
                {
                    counter++;
                    dsOutlet.MassFlowRateDryBase.Value    = newMassFlowDryBasisValue;
                    dsOutlet.Temperature.Value            = newTemperatureValue;
                    dsOutlet.MoistureContentDryBase.Value = newMoistureContentDryBasisValue;
                    oldMassFlowDryBasisValue        = newMassFlowDryBasisValue;
                    oldTemperatureValue             = newTemperatureValue;
                    oldMoistureContentDryBasisValue = newMoistureContentDryBasisValue;

                    dsOutlet.HasBeenModified(true);
                    newMassFlowDryBasisValue        = dsInlet.MassFlowRateDryBase.Value;
                    newTemperatureValue             = dsInlet.Temperature.Value;
                    newMoistureContentDryBasisValue = dsInlet.MoistureContentDryBase.Value;
                    //newMassFlowDryBasisValue = oldMassFlowDryBasisValue + 0.75 * (dsInlet.MassFlowRateDryBase.Value - oldMassFlowDryBasisValue);
                    //newTemperatureValue = oldTemperatureValue + 0.75 * (dsInlet.Temperature.Value - oldTemperatureValue);
                    //newMoistureContentDryBasisValue = oldMoistureContentDryBasisValue + 0.75 * (dsInlet.MoistureContentDryBase.Value - oldMoistureContentDryBasisValue);
                } while ((Math.Abs((newMassFlowDryBasisValue - oldMassFlowDryBasisValue) / oldMassFlowDryBasisValue) > 1.0e-8 ||
                          Math.Abs((newTemperatureValue - oldTemperatureValue) / oldTemperatureValue) > 1.0e-6 ||
                          Math.Abs((newMoistureContentDryBasisValue - oldMoistureContentDryBasisValue) / oldMoistureContentDryBasisValue) > 1.0e-6) &&
                         counter < 500);

                if (counter == 500)
                {
                    solveState = SolveState.SolveFailed;
                }
                else
                {
                    if (inlet.HasSolvedAlready && outlet.HasSolvedAlready)
                    {
                        solveState = SolveState.Solved;
                    }
                    //debug code
                    Trace.WriteLine(this.name + "Number of Iterations" + counter);
                    //debug code
                }

                dsOutlet.Pressure.State               = VarState.Calculated;
                dsOutlet.Temperature.State            = VarState.Calculated;
                dsOutlet.MassFlowRateDryBase.State    = VarState.Calculated;
                dsOutlet.MoistureContentDryBase.State = VarState.Calculated;
                dsOutlet.OnSolveComplete(solveState);//has to call this so that the calculated state is updated on the uI
            }

            isBeingExecuted = false;
            OnSolveComplete(solveState);
        }
Esempio n. 2
0
        //protected override bool IsSolveReady() {
        //   bool isReady = false;
        //   if (inlet is DryingGasStream) {
        //      DryingGasStream dsInlet = inlet as DryingGasStream;
        //      DryingGasStream dsOutlet = outlet as DryingGasStream;
        //      if ((dsInlet.Pressure.HasValue || dsOutlet.Pressure.HasValue) &&
        //          (dsInlet.Temperature.HasValue || dsOutlet.Temperature.HasValue) &&
        //          (dsInlet.MassFlowRateDryBase.HasValue || dsOutlet.MassFlowRateDryBase.HasValue || dsInlet.MassFlowRate.HasValue || dsOutlet.MassFlowRate.HasValue) &&
        //          (dsInlet.MoistureContentDryBase.HasValue || dsOutlet.MoistureContentDryBase.HasValue || dsInlet.MoistureContentWetBase.HasValue || dsOutlet.MoistureContentWetBase.HasValue)) {
        //         isReady = true;
        //      }
        //   }
        //   else if (inlet is DryingMaterialStream) {
        //      DryingMaterialStream dsInlet = inlet as DryingMaterialStream;
        //      DryingMaterialStream dsOutlet = outlet as DryingMaterialStream;
        //      if (dsInlet.MaterialStateType == MaterialStateType.Liquid) {
        //         if ((dsInlet.Pressure.HasValue || dsOutlet.Pressure.HasValue) &&
        //            (dsInlet.Temperature.HasValue || dsOutlet.Temperature.HasValue) &&
        //            (dsInlet.MassFlowRateDryBase.HasValue || dsOutlet.MassFlowRateDryBase.HasValue || dsInlet.MassFlowRate.HasValue || dsOutlet.MassFlowRate.HasValue) &&
        //            (dsInlet.MoistureContentDryBase.HasValue || dsOutlet.MoistureContentDryBase.HasValue || dsInlet.MoistureContentWetBase.HasValue || dsOutlet.MoistureContentWetBase.HasValue || dsInlet.MassConcentration.HasValue || dsOutlet.MassConcentration.HasValue)) {
        //            isReady = true;
        //         }
        //      }
        //      else if (dsInlet.MaterialStateType == MaterialStateType.Solid) {
        //         if ((dsInlet.Temperature.HasValue || dsOutlet.Temperature.HasValue) &&
        //            (dsInlet.MassFlowRateDryBase.HasValue || dsOutlet.MassFlowRateDryBase.HasValue || dsInlet.MassFlowRate.HasValue || dsOutlet.MassFlowRate.HasValue) &&
        //            (dsInlet.MoistureContentDryBase.HasValue || dsOutlet.MoistureContentDryBase.HasValue || dsInlet.MoistureContentWetBase.HasValue || dsOutlet.MoistureContentWetBase.HasValue)) {
        //            isReady = true;
        //         }
        //      }
        //   }
        //   return isReady;
        //}

        public override void Execute(bool propagate)
        {
            //if (!IsSolveReady()) {
            //   return;
            //}

            isBeingExecuted = true;
            BalanceStreamComponents(inlet, outlet);

            if (inlet is DryingStream)
            {
                DryingStream dsInlet  = inlet as DryingStream;
                DryingStream dsOutlet = outlet as DryingStream;

                if (dsInlet.Pressure.HasValue && !dsOutlet.Pressure.HasValue)
                {
                    dsOutlet.Pressure.Value = dsInlet.Pressure.Value;
                }

                IList <ProcessVarDouble> inletVarList  = new List <ProcessVarDouble>();
                IList <ProcessVarDouble> outletVarList = new List <ProcessVarDouble>();
                IList <double>           newValueList  = new List <double>();

                if (dsInlet.MassFlowRateDryBase.HasValue && !dsOutlet.MassFlowRateDryBase.IsSpecifiedAndHasValue)
                {
                    inletVarList.Add(dsInlet.MassFlowRateDryBase);
                    outletVarList.Add(dsOutlet.MassFlowRateDryBase);
                    newValueList.Add(dsInlet.MassFlowRateDryBase.Value);
                }
                else if (dsInlet.MassFlowRate.HasValue && !dsOutlet.MassFlowRate.IsSpecifiedAndHasValue)
                {
                    inletVarList.Add(dsInlet.MassFlowRate);
                    outletVarList.Add(dsOutlet.MassFlowRate);
                    newValueList.Add(dsInlet.MassFlowRate.Value);
                }
                else if (!dsOutlet.MassFlowRateDryBase.IsSpecifiedAndHasValue)
                {
                    inletVarList.Add(dsInlet.MassFlowRateDryBase);
                    outletVarList.Add(dsOutlet.MassFlowRateDryBase);
                    double newValue = dsInlet.MassFlowRateDryBase.Value;
                    if (newValue == Constants.NO_VALUE)
                    {
                        newValue = 0.01;
                    }
                    newValueList.Add(newValue);
                }

                if (!dsOutlet.Temperature.IsSpecifiedAndHasValue)
                {
                    inletVarList.Add(dsInlet.Temperature);
                    outletVarList.Add(dsOutlet.Temperature);
                    double newValue = dsInlet.Temperature.Value;
                    if (newValue == Constants.NO_VALUE)
                    {
                        newValue = 274.15;
                    }
                    newValueList.Add(newValue);
                }

                if (dsInlet.MoistureContentDryBase.HasValue && !dsOutlet.MoistureContentDryBase.IsSpecifiedAndHasValue)
                {
                    inletVarList.Add(dsInlet.MoistureContentDryBase);
                    outletVarList.Add(dsOutlet.MoistureContentDryBase);
                    newValueList.Add(dsInlet.MoistureContentDryBase.Value);
                }
                else if (dsInlet.MoistureContentWetBase.HasValue && !dsOutlet.MoistureContentWetBase.IsSpecifiedAndHasValue)
                {
                    inletVarList.Add(dsInlet.MoistureContentWetBase);
                    outletVarList.Add(dsOutlet.MoistureContentWetBase);
                    newValueList.Add(dsInlet.MoistureContentWetBase.Value);
                }
                else if (!dsOutlet.MoistureContentDryBase.IsSpecifiedAndHasValue)
                {
                    inletVarList.Add(dsInlet.MoistureContentDryBase);
                    outletVarList.Add(dsOutlet.MoistureContentDryBase);
                    double newValue = dsInlet.MoistureContentDryBase.Value;
                    if (newValue == Constants.NO_VALUE)
                    {
                        newValue = 0.001;
                    }
                    newValueList.Add(newValue);
                }

                double[] oldValueList = new double[newValueList.Count];
                bool     isGreaterThanTolerance;
                int      counter = 0;
                do
                {
                    counter++;
                    isGreaterThanTolerance = false;
                    for (int i = 0; i < outletVarList.Count; i++)
                    {
                        outletVarList[i].Value = newValueList[i];
                        oldValueList[i]        = newValueList[i];
                    }

                    dsOutlet.HasBeenModified(true);
                    for (int j = 0; j < inletVarList.Count; j++)
                    {
                        newValueList[j] = inletVarList[j].Value;
                        if (Math.Abs((newValueList[j] - oldValueList[j]) / oldValueList[j]) > 1.0e-6)
                        {
                            isGreaterThanTolerance = true;
                            break;
                        }
                    }
                } while (isGreaterThanTolerance && counter < 500);

                if (counter == 500)
                {
                    currentSolveState = SolveState.SolveFailed;
                }
                else
                {
                    if (inlet.HasSolvedAlready && outlet.HasSolvedAlready)
                    {
                        currentSolveState = SolveState.Solved;
                    }
                    //debug code
                    Trace.WriteLine(this.name + "Number of Iterations" + counter);
                    //debug code
                }

                if (currentSolveState == SolveState.Solved)
                {
                    dsOutlet.Pressure.State = VarState.Calculated;
                    foreach (ProcessVarDouble outletVar in outletVarList)
                    {
                        outletVar.State = VarState.Calculated;
                    }
                }
                else if (currentSolveState == SolveState.NotSolved)
                {
                    if (dsOutlet.Pressure.IsSpecifiedAndHasValue)
                    {
                        dsOutlet.Pressure.Value = Constants.NO_VALUE;
                    }
                    foreach (ProcessVarDouble outletVar in outletVarList)
                    {
                        outletVar.Value = Constants.NO_VALUE;
                    }
                }

                dsOutlet.OnSolveComplete(currentSolveState);//has to call this so that the calculated state is updated on the UI
            }

            isBeingExecuted = false;
            OnSolveComplete(currentSolveState);
        }