Exemple #1
0
 public Substance(string name, SubstanceType type, string casNo, SubstanceFormula formula, double molarWeight, CriticalPropertiesAndAccentricFactor criticalProps)
 {
     this.name          = name;
     this.type          = type;
     this.casRegistryNo = casNo;
     this.formula       = formula;
     this.molarWeight   = molarWeight;
     this.IsUserDefined = false;
     this.criticalProps = criticalProps;
 }
Exemple #2
0
        private void ExtractCoeffs()
        {
            FileStream fsRead = null;

            try {
                char[]   separator1     = { '>' };
                char[]   separator2     = { '<' };
                char[]   emptySeparator = { ' ' };
                char[]   separators     = { '>', '<' };
                string[] subStrs;
                string[] subSubStrs;
                string   formula;
                string   name;
                string   casRegestryNo;
                double   a, b, c, d = 1, e = 1, f, g, bp = 1;
                double   molarWeight, freezingPoint, boilingPoint, criticalT, criticalP, criticalV, criticalComp, accentricF;
                molarWeight = freezingPoint = boilingPoint = criticalT = criticalP = criticalV = criticalComp = accentricF = -2147483D;
                double        minTemp = 1, maxTemp = 1;
                StringBuilder sb;
                CriticalPropertiesAndAccentricFactor criticalProps;
                Substance               substance;
                YawsGasCpCorrelation    gasCpCorrelation;
                YawsLiquidCpCorrelation liquidCpCorrelation;
                YawsGasThermalConductivityCorrelation    gasKCorrelation;
                YawsLiquidThermalConductivityCorrelation liquidKCorrelation;
                YawsGasViscosityCorrelation    gasViscCorrelation;
                YawsLiquidViscosityCorrelation liquidViscCorrelation;
                YawsLiquidDensityCorrelation   liquidDensityCorrelation;
                YawsEvaporationHeatCorrelation evapHeatCorrelation;
                YawsVaporPressureCorrelation   vapPressureCorrelation;
                YawsSurfaceTensionCorrelation  surfaceTensionCorrelation;

                string       line1, line2, line3, line4, line5, line6, line7, line8, line9, line10, line11, lineTemp;
                string       tmpStrOld = "";
                string       tmpStr;
                int          number;
                StreamReader reader;

                foreach (object fullFileName in listBoxFiles.Items)
                {
                    fsRead = new FileStream((string)fullFileName, FileMode.Open, FileAccess.Read);
                    reader = new StreamReader(fsRead);
                    line1  = reader.ReadLine();
                    while (!reader.EndOfStream)
                    {
                        line2 = reader.ReadLine();
                        if (line1.Contains("<TD class=BorderHelper>") && line2.Contains("<TD class=BorderHelper noWrap>"))
                        {
                            substanceFormula = new SubstanceFormula();

                            subStrs = line1.Split(separator1);
                            sb      = new StringBuilder();
                            for (int i = 1; i < subStrs.Length - 1; i++)
                            {
                                subSubStrs = subStrs[i].Split(separator2);
                                sb.Append(subSubStrs[0]);
                                tmpStr = subSubStrs[0];
                                if (char.IsDigit(tmpStr[0]))
                                {
                                    number = int.Parse(tmpStr);
                                    substanceFormula.AddElement(tmpStrOld, number);
                                }
                                else
                                {
                                    if (!tmpStr.Equals(" "))
                                    {
                                        tmpStr = Parse(tmpStr.TrimEnd());
                                    }
                                    if (i == (subStrs.Length - 2) && !tmpStr.Equals(" ") && !tmpStr.Equals(""))
                                    {
                                        substanceFormula.AddElement(tmpStr, 1);
                                    }
                                }
                                tmpStrOld = tmpStr;
                            }
                            formula = sb.ToString();

                            if (!line2.Contains("</TD>"))
                            {
                                lineTemp = reader.ReadLine();
                                line2    = line2 + lineTemp;
                            }

                            if (!line2.Contains("<I>"))
                            {
                                subStrs = line2.Split(separators);
                                name    = subStrs[2];
                            }
                            else
                            {
                                subStrs = line2.Split(separators);
                                sb      = new StringBuilder();
                                for (int i = 2; i < subStrs.Length; i++)
                                {
                                    if (!(subStrs[i].Equals("") || subStrs[i].Equals("I") || subStrs[i].Equals("/I") || subStrs[i].Equals("/TD")))
                                    {
                                        sb.Append(subStrs[i]);
                                    }
                                }
                                name = sb.ToString();
                            }
                            name = name.TrimEnd(emptySeparator);

                            line3   = reader.ReadLine();
                            subStrs = line3.Split(separators);
                            if (subStrs[2].Contains("&"))
                            {
                                casRegestryNo = "";
                            }
                            else
                            {
                                casRegestryNo = subStrs[2];
                            }

                            line4   = reader.ReadLine();
                            subStrs = line4.Split(separators);
                            a       = double.Parse(subStrs[2]);
                            if (thermProp == ThermProp.CriticalProp)
                            {
                                molarWeight = a;
                            }

                            line5   = reader.ReadLine();
                            subStrs = line5.Split(separators);
                            if (subStrs[2].Contains("&"))
                            {
                                b = -2147483D;
                            }
                            else
                            {
                                b = double.Parse(subStrs[2]);
                            }
                            if (thermProp == ThermProp.CriticalProp)
                            {
                                freezingPoint = b;
                            }

                            line6   = reader.ReadLine();
                            subStrs = line6.Split(separators);
                            if (subStrs[2].Contains("&"))
                            {
                                c = -2147483D;;
                            }
                            else
                            {
                                c = double.Parse(subStrs[2]);
                            }
                            if (thermProp == ThermProp.CriticalProp)
                            {
                                boilingPoint = c;
                            }

                            line7   = reader.ReadLine();
                            subStrs = line7.Split(separators);
                            if (subStrs[2].Contains("&"))
                            {
                                d = -2147483D;
                            }
                            else
                            {
                                d = double.Parse(subStrs[2]);
                            }
                            if (thermProp == ThermProp.EvapHeat || thermProp == ThermProp.GasVisc ||
                                thermProp == ThermProp.GasK || thermProp == ThermProp.LiquidK ||
                                thermProp == ThermProp.SurfaceTension)
                            {
                                minTemp = d;
                            }
                            else if (thermProp == ThermProp.CriticalProp)
                            {
                                criticalT = d;
                            }

                            line8   = reader.ReadLine();
                            subStrs = line8.Split(separators);
                            if (subStrs[2].Contains("&"))
                            {
                                e = -2147483D;
                            }
                            else
                            {
                                e = double.Parse(subStrs[2]);
                            }

                            if (thermProp == ThermProp.EvapHeat || thermProp == ThermProp.GasVisc ||
                                thermProp == ThermProp.GasK || thermProp == ThermProp.LiquidK ||
                                thermProp == ThermProp.SurfaceTension)
                            {
                                maxTemp = e;
                            }
                            else if (thermProp == ThermProp.LiquidCp || thermProp == ThermProp.LiquidDensity || thermProp == ThermProp.LiquidVisc)
                            {
                                minTemp = e;
                            }
                            else if (thermProp == ThermProp.CriticalProp)
                            {
                                criticalP = 1.0e5 * e;//convert from bar to Pa.sec
                            }

                            line9   = reader.ReadLine();
                            subStrs = line9.Split(separators);
                            if (!subStrs[2].Contains("&"))
                            {
                                f = double.Parse(subStrs[2]);
                            }
                            else
                            {
                                f = -2147483D;
                            }
                            if (thermProp == ThermProp.EvapHeat)
                            {
                                bp = f;
                            }
                            else if (thermProp == ThermProp.CriticalProp)
                            {
                                criticalV = f * 1.0e-6;        //convert from cm3/mol to m3/mol
                                line9     = reader.ReadLine(); //skip critical density
                            }
                            else if (thermProp == ThermProp.GasCp || thermProp == ThermProp.VapPressure)
                            {
                                minTemp = f;
                            }
                            else if (thermProp == ThermProp.LiquidCp || thermProp == ThermProp.LiquidDensity || thermProp == ThermProp.LiquidVisc)
                            {
                                maxTemp = f;
                            }

                            line10  = reader.ReadLine();
                            subStrs = line10.Split(separators);
                            if (!subStrs[2].Contains("&"))
                            {
                                g = double.Parse(subStrs[2]);
                            }
                            else
                            {
                                g = -2147483D;
                            }

                            if (thermProp == ThermProp.CriticalProp)
                            {
                                criticalComp = g;
                            }
                            else if (thermProp == ThermProp.GasCp || thermProp == ThermProp.VapPressure)
                            {
                                maxTemp = g;
                            }

                            line11  = reader.ReadLine();
                            subStrs = line11.Split(separators);
                            if (thermProp == ThermProp.CriticalProp)
                            {
                                if (!subStrs[2].Contains("&"))
                                {
                                    accentricF = double.Parse(subStrs[2]);
                                }
                                else
                                {
                                    accentricF = -2147483D;
                                }
                            }

                            if (thermProp == ThermProp.CriticalProp)
                            {
                                criticalProps = new CriticalPropertiesAndAccentricFactor(freezingPoint, boilingPoint, criticalT, criticalP, criticalV, criticalComp, accentricF);
                                substance     = new Substance(name, substanceType, casRegestryNo, substanceFormula, molarWeight, criticalProps);
                                substanceList.Add(substance);
                            }
                            else if (thermProp == ThermProp.GasCp)
                            {
                                gasCpCorrelation = new YawsGasCpCorrelation(name, a, b, c, d, e, minTemp, maxTemp);
                                gasCpCorrList.Add(gasCpCorrelation);
                            }
                            else if (thermProp == ThermProp.LiquidCp)
                            {
                                liquidCpCorrelation = new YawsLiquidCpCorrelation(name, a, b, c, d, minTemp, maxTemp);
                                liquidCpCorrList.Add(liquidCpCorrelation);
                            }
                            else if (thermProp == ThermProp.EvapHeat)
                            {
                                evapHeatCorrelation = new YawsEvaporationHeatCorrelation(name, a, b, c, minTemp, maxTemp, bp);
                                evapHeatCorrList.Add(evapHeatCorrelation);
                            }
                            else if (thermProp == ThermProp.VapPressure)
                            {
                                vapPressureCorrelation = new YawsVaporPressureCorrelation(name, a, b, c, d, e, minTemp, maxTemp);
                                vapPressureCorrList.Add(vapPressureCorrelation);
                            }
                            else if (thermProp == ThermProp.LiquidDensity)
                            {
                                liquidDensityCorrelation = new YawsLiquidDensityCorrelation(name, a, b, c, d, minTemp, maxTemp);
                                liquidDensityCorrList.Add(liquidDensityCorrelation);
                            }
                            else if (thermProp == ThermProp.GasVisc)
                            {
                                gasViscCorrelation = new YawsGasViscosityCorrelation(name, a, b, c, minTemp, maxTemp);
                                gasViscCorrList.Add(gasViscCorrelation);
                            }
                            else if (thermProp == ThermProp.LiquidVisc)
                            {
                                liquidViscCorrelation = new YawsLiquidViscosityCorrelation(name, a, b, c, d, minTemp, maxTemp);
                                liquidViscCorrList.Add(liquidViscCorrelation);
                            }
                            else if (thermProp == ThermProp.GasK)
                            {
                                gasKCorrelation = new YawsGasThermalConductivityCorrelation(name, a, b, c, minTemp, maxTemp);
                                gasKCorrList.Add(gasKCorrelation);
                            }
                            else if (thermProp == ThermProp.LiquidK)
                            {
                                liquidKCorrelation = new YawsLiquidThermalConductivityCorrelation(name, a, b, c, minTemp, maxTemp);
                                liquidKCorrList.Add(liquidKCorrelation);
                            }
                            else if (thermProp == ThermProp.SurfaceTension)
                            {
                                surfaceTensionCorrelation = new YawsSurfaceTensionCorrelation(name, a, b, c, minTemp, maxTemp);
                                surfaceTensionCorrList.Add(surfaceTensionCorrelation);
                            }
                        }
                        line1 = line2;
                    }
                    reader.Close();
                    fsRead.Close();
                }
            }
            catch (Exception ex) {
                Console.WriteLine("The process failed: {0}", ex.ToString());
            }
            finally {
                if (fsRead != null)
                {
                    fsRead.Close();
                }
            }
        }