Exemplo n.º 1
0
        /// <inheritdoc/>
        public string ToDelimitedString()
        {
            CultureInfo culture = CultureInfo.CurrentCulture;

            return(string.Format(
                       culture,
                       StringHelper.StringFormatSequence(0, 21, Configuration.FieldSeparator),
                       Id,
                       SubstanceIdentifier?.ToDelimitedString(),
                       SubstanceStatus != null ? string.Join(Configuration.FieldRepeatSeparator, SubstanceStatus.Select(x => x.ToDelimitedString())) : null,
                       SubstanceType?.ToDelimitedString(),
                       InventoryContainerIdentifier?.ToDelimitedString(),
                       ContainerCarrierIdentifier?.ToDelimitedString(),
                       PositionOnCarrier?.ToDelimitedString(),
                       InitialQuantity.HasValue ? InitialQuantity.Value.ToString(Consts.NumericFormat, culture) : null,
                       CurrentQuantity.HasValue ? CurrentQuantity.Value.ToString(Consts.NumericFormat, culture) : null,
                       AvailableQuantity.HasValue ? AvailableQuantity.Value.ToString(Consts.NumericFormat, culture) : null,
                       ConsumptionQuantity.HasValue ? ConsumptionQuantity.Value.ToString(Consts.NumericFormat, culture) : null,
                       QuantityUnits?.ToDelimitedString(),
                       ExpirationDateTime.HasValue ? ExpirationDateTime.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null,
                       FirstUsedDateTime.HasValue ? FirstUsedDateTime.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null,
                       OnBoardStabilityDuration,
                       TestFluidIdentifiers != null ? string.Join(Configuration.FieldRepeatSeparator, TestFluidIdentifiers.Select(x => x.ToDelimitedString())) : null,
                       ManufacturerLotNumber,
                       ManufacturerIdentifier?.ToDelimitedString(),
                       SupplierIdentifier?.ToDelimitedString(),
                       OnBoardStabilityTime?.ToDelimitedString(),
                       TargetValue?.ToDelimitedString()
                       ).TrimEnd(Configuration.FieldSeparator.ToCharArray()));
        }
Exemplo n.º 2
0
        public override void SetObjectData()
        {
            base.SetObjectData();
            int persistedClassVersion = info.GetInt32("ClassPersistenceVersionSubstance");

            this.name          = info.GetString("Name");
            this.molarWeight   = info.GetDouble("MolarWeight");
            this.isUserDefined = info.GetBoolean("IsUserDefined");
            this.type          = (SubstanceType)info.GetValue("Type", typeof(SubstanceType));
            //this.casRegistryNo = (int)info.GetValue("CasRegistryNo", typeof(int));
            //this.formula = (string)info.GetValue("Formula", typeof(string));
            //this.propsAndCoeffs = info.GetValue("PropsAndCoeffs", typeof(ThermalPropsAndCoeffs)) as ThermalPropsAndCoeffs;
            //this.criticalProps = info.GetValue("CriticalProps", typeof(CriticalProperties)) as CriticalProperties;
            if (persistedClassVersion == 1)
            {
                int casNo = info.GetInt32("CasRegistryNo");
                this.casRegistryNo = casNo.ToString();
            }

            if (persistedClassVersion >= 2)
            {
                this.casRegistryNo = info.GetString("CasRegistryNo");
                //this.htmlTaggedName = info.GetString("HtmlTaggedName");
                this.formula = (SubstanceFormula)RecallStorableObject("Formula", typeof(SubstanceFormula));
                this.criticalPropsAndAcentricFactor = (CriticalPropsAndAcentricFactor)RecallStorableObject("CriticalPropsAndAcentricFactor", typeof(CriticalPropsAndAcentricFactor));
            }
        }
Exemplo n.º 3
0
        private void comboBoxExtractorType_SelectedIndexChanged(object sender, EventArgs e)
        {
            int idx = comboBoxExtractorType.SelectedIndex;

            extractorType = (ExtractorType)idx;
            if (extractorType == ExtractorType.Yaws)
            {
                fileFilter = "htm files (*.htm)|*.htm";
            }
            else
            {
                fileFilter = "htm files (*.html)|*.html";
            }

            if (extractorType == ExtractorType.Perrys)
            {
                comboBoxSubstanceType.Visible = false;
            }
            else if (extractorType == ExtractorType.YawsOrganic)
            {
                comboBoxSubstanceType.Visible = false;
                substanceType = SubstanceType.Organic;
                thermPropType = ThermPropType.CriticalProp;
            }
            else
            {
                comboBoxSubstanceType.Visible = true;
                thermPropType = ThermPropType.CriticalProp;
            }
        }
Exemplo n.º 4
0
        private void CreateGenericFoodSubstance(string name, SubstanceType type)
        {
            Substance substance = new Substance(name, type, false);

            genericFoodSubstanceList.Add(substance);
            allSubstanceList.Add(substance);
        }
Exemplo n.º 5
0
        private void CreateMaterialSubstance(string name, SubstanceType type)
        {
            Substance substance = new Substance(name, type, false);

            materialSubstanceList.Add(substance);
            allSubstanceList.Add(substance);
        }
Exemplo n.º 6
0
        public void GenerateContextMenu()
        {
            CutContextMenu = new ContextMenu();

            if (EventDefinitionManager.CanActionCopyFromViewport(Cut.ParentActor.Name, Cut.Name))
            {
                MenuItem CopyItem = new MenuItem()
                {
                    Header = "Copy Camera from Viewport"
                };
                CopyItem.Click += (x, y) =>
                {
                    CopyCameraFromViewportEventArgs NewArgs = new CopyCameraFromViewportEventArgs();
                    NewArgs.RequestingCut = this;

                    Cut.ParentActor.ParentEvent.OnCutRequestCopyFromViewport(NewArgs);
                };

                CutContextMenu.Items.Add(CopyItem);
                CutContextMenu.Items.Add(new Separator());
            }

            if (EventDefinitionManager.CanActionCopyStartFromViewport(Cut.ParentActor.Name, Cut.Name))
            {
                MenuItem CopyItem = new MenuItem()
                {
                    Header = "Copy Start Camera from Viewport"
                };
                CopyItem.Click += (x, y) =>
                {
                    CopyCameraFromViewportEventArgs NewArgs = new CopyCameraFromViewportEventArgs();
                    NewArgs.RequestingCut = this;
                    NewArgs.IsStart       = true;

                    Cut.ParentActor.ParentEvent.OnCutRequestCopyFromViewport(NewArgs);
                };

                CutContextMenu.Items.Add(CopyItem);
                CutContextMenu.Items.Add(new Separator());
            }

            Dictionary <string, string> properties = EventDefinitionManager.GetPropertiesForAction(Cut.ParentActor.Name, Cut.Name);

            foreach (KeyValuePair <string, string> prop_str in properties)
            {
                string        SubDefault = "";
                SubstanceType SubType    = EventDefinitionManager.GetPropertyTypeAndDefaultValue(Cut.ParentActor.Name, Cut.Name, prop_str.Key, out SubDefault);

                CutContextMenu.Items.Add(new MenuItem()
                {
                    Header           = prop_str.Key,
                    Command          = CreatePropertyCommand,
                    CommandParameter = new Tuple <string, string, SubstanceType>(prop_str.Value, SubDefault, SubType)
                });
            }
        }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
0
 public Substance(string name, SubstanceType type, string casNo, SubstanceFormula formula, double molWt,
       CriticalPropsAndAcentricFactor criticalPropsAndAcentricFactor) {
    this.name = name;
    //htmlTaggedName = null;
    this.type = type;
    this.casRegistryNo = casNo;
    this.formula = formula;
    this.molarWeight = molWt;
    this.IsUserDefined = false;
    this.criticalPropsAndAcentricFactor = criticalPropsAndAcentricFactor;
 }
Exemplo n.º 9
0
 public Substance(string name, SubstanceType type, int casNo, string formula, double molWt,
                  ThermalPropsAndCoeffs propsAndCoeffs, CriticalProperties criticalProps)
 {
     this.name           = name;
     this.type           = type;
     this.casRegistryNo  = casNo;
     this.formula        = formula;
     this.molarWeight    = molWt;
     this.IsUserDefined  = false;
     this.propsAndCoeffs = propsAndCoeffs;
     this.criticalProps  = criticalProps;
 }
Exemplo n.º 10
0
        private void substanceTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            int idx = substanceTypeComboBox.SelectedIndex;

            if (idx == 0)
            {
                substanceType = SubstanceType.Inorganic;
            }
            else if (idx == 1)
            {
                substanceType = SubstanceType.Organic;
            }
        }
Exemplo n.º 11
0
        public static SubstanceType GetSubstanceTypeAsEnum(string typeStr)
        {
            SubstanceType typeEnum = SubstanceType.Unknown;

            if (typeStr.Equals(SubstancesControl.STR_SUBSTANCE_TYPE_ORGANIC))
            {
                typeEnum = SubstanceType.Organic;
            }
            else if (typeStr.Equals(SubstancesControl.STR_SUBSTANCE_TYPE_INORGANIC))
            {
                typeEnum = SubstanceType.Inorganic;
            }
            return(typeEnum);
        }
Exemplo n.º 12
0
        public static string GetSubstanceTypeAsString(SubstanceType typeEnum)
        {
            string typeStr = "";

            if (typeEnum == SubstanceType.Organic)
            {
                typeStr = SubstancesControl.STR_SUBSTANCE_TYPE_ORGANIC;
            }
            else if (typeEnum == SubstanceType.Inorganic)
            {
                typeStr = SubstancesControl.STR_SUBSTANCE_TYPE_INORGANIC;
            }
            return(typeStr);
        }
Exemplo n.º 13
0
        public IList GetMoistureSubstanceList(SubstanceType type)
        {
            ArrayList retList = new ArrayList();

            foreach (Substance s in moistureSubstanceList)
            {
                if (s.SubstanceType == type)
                {
                    retList.Add(s);
                }
            }

            return(retList);
        }
Exemplo n.º 14
0
        public IList GetMoistureSubstanceList(bool isUserDefined, SubstanceType type)
        {
            ArrayList retList = new ArrayList();

            foreach (Substance s in moistureSubstanceList)
            {
                if (s.IsUserDefined == isUserDefined && s.SubstanceType == type)
                {
                    retList.Add(s);
                }
            }

            return(retList);
        }
Exemplo n.º 15
0
        public Substance(EndianBinaryReader reader)
        {
            Name = new string(reader.ReadChars(32)).Trim('\0');

            reader.SkipInt32();

            Type = (SubstanceType)reader.ReadInt32();

            m_ElementIndex       = reader.ReadInt32();
            m_ElementCount       = reader.ReadInt32();
            m_NextSubstanceIndex = reader.ReadInt32();

            reader.Skip(12);
        }
Exemplo n.º 16
0
        public static SubstanceType GetPropertyTypeAndDefaultValue(string actor_name, string action_name, string prop_name, out string default_value)
        {
            default_value = "";
            SubstanceType sub = SubstanceType.Float;

            EventActorDefinition def = m_EventActorDefinitions[actor_name];

            if (def == null)
            {
                return(sub);
            }

            for (int i = 0; i < def.Actions.Length; i++)
            {
                if (def.Actions[i].ActionName == action_name)
                {
                    foreach (EventPropertyDefinition p in def.Actions[i].Properties)
                    {
                        if (p.PropertyName == prop_name)
                        {
                            switch (p.Type)
                            {
                            case "Integer":
                                sub = SubstanceType.Int;
                                break;

                            case "Float":
                                sub = SubstanceType.Float;
                                break;

                            case "Vector3":
                                sub = SubstanceType.Vec3;
                                break;

                            case "String":
                                sub = SubstanceType.String;
                                break;
                            }

                            default_value = p.Default;
                        }
                    }

                    break;
                }
            }

            return(sub);
        }
Exemplo n.º 17
0
        //Yaws' Chemical Properties
        //calculated value unit is w/m.K, t unit is K
        public double GetThermalConductivity(double t, SubstanceType substanceType)
        {
            double k = 0.0;

            if (substanceType == SubstanceType.Organic)
            {
                double logKLiq = a + b * Math.Pow((1.0 - t / c), 2.0 / 7.0);
                k = Math.Pow(10, logKLiq);
            }
            else if (substanceType == SubstanceType.Inorganic)
            {
                k = a + b * t + c * t * t;
            }

            return(k);
        }
Exemplo n.º 18
0
        public override void SetObjectData()
        {
            base.SetObjectData();
            int persistedClassVersion = (int)info.GetValue("ClassPersistenceVersionSubstance", typeof(int));

            if (persistedClassVersion == 1)
            {
                this.name           = (string)info.GetValue("Name", typeof(string));
                this.casRegistryNo  = (int)info.GetValue("CasRegistryNo", typeof(int));
                this.formula        = (string)info.GetValue("Formula", typeof(string));
                this.molarWeight    = (double)info.GetValue("MolarWeight", typeof(double));
                this.isUserDefined  = (bool)info.GetValue("IsUserDefined", typeof(bool));
                this.type           = (SubstanceType)info.GetValue("Type", typeof(SubstanceType));
                this.propsAndCoeffs = info.GetValue("PropsAndCoeffs", typeof(ThermalPropsAndCoeffs)) as ThermalPropsAndCoeffs;
                this.criticalProps  = info.GetValue("CriticalProps", typeof(CriticalProperties)) as CriticalProperties;
            }
        }
Exemplo n.º 19
0
        private void ReadSubstances(EndianBinaryReader reader, int substance_offset, int substance_count)
        {
            reader.BaseStream.Seek(0, SeekOrigin.Begin);
            m_SubstanceData = new SubstanceData(reader);

            reader.BaseStream.Seek(substance_offset, SeekOrigin.Begin);
            for (int i = 0; i < substance_count; i++)
            {
                reader.BaseStream.Seek(36, SeekOrigin.Current);
                SubstanceType sub_type = (SubstanceType)reader.ReadInt32();
                reader.BaseStream.Seek(-40, SeekOrigin.Current);

                switch (sub_type)
                {
                case SubstanceType.Float:
                    Substance <ObservableCollection <PrimitiveBinding <float> > > float_sub = new Substance <ObservableCollection <PrimitiveBinding <float> > >(reader, m_SubstanceData.GetFloatData);
                    m_Substances.Add(float_sub);
                    break;

                case SubstanceType.Int:
                    Substance <ObservableCollection <PrimitiveBinding <int> > > int_sub = new Substance <ObservableCollection <PrimitiveBinding <int> > >(reader, m_SubstanceData.GetIntData);
                    m_Substances.Add(int_sub);
                    break;

                case SubstanceType.String:
                    Substance <PrimitiveBinding <string> > string_sub = new Substance <PrimitiveBinding <string> >(reader, m_SubstanceData.GetStringData);
                    m_Substances.Add(string_sub);
                    break;

                case SubstanceType.Vec3:
                    Substance <ObservableCollection <BindingVector3> > vec3_sub = new Substance <ObservableCollection <BindingVector3> >(reader, m_SubstanceData.GetVec3Data);
                    m_Substances.Add(vec3_sub);
                    break;
                }
            }

            foreach (Substance s in m_Substances)
            {
                s.AssignNextSubstance(m_Substances);
            }
        }
Exemplo n.º 20
0
        override internal void ExtractCoeffs(ListBox listBox, SubstanceType substanceType, ThermPropType thermProp)
        {
            propList.Clear();
            ThermalPropCorrelationBase thermalPropCorrelation;

            string[] separatorsStr1 = { "</td>" };
            string[] separatorsStr2 = { "<i>", "</i>" };
            string   name;
            string   casRegestryNo;
            double   a, b, c, d = 1, e = 1;
            double   molarWeight, criticalRho, criticalT, criticalP, criticalV, criticalComp, accentricF;

            molarWeight = criticalRho = criticalT = criticalP = criticalV = criticalComp = accentricF = -2147483D;
            double minTemp = 1, maxTemp = 1;

            CriticalPropsAndAcentricFactor criticalProps;
            Substance        substance;
            SubstanceFormula substanceFormula;

            string line1, line2, lineTemp;
            int    fileNo      = 0;
            int    substanceNo = 0;
            string state       = "";

            int          counter;
            int          totalCounter = 0;
            StreamReader reader;
            FileStream   fsRead = null;

            try {
                foreach (object fullFileName in listBox.Items)
                {
                    fileNo++;
                    counter = 0;
                    fsRead  = new FileStream((string)fullFileName, FileMode.Open, FileAccess.Read);
                    reader  = new StreamReader(fsRead);
                    line1   = reader.ReadLine();
                    while (!reader.EndOfStream && counter < 50)
                    {
                        line2         = reader.ReadLine();
                        name          = "";
                        casRegestryNo = "";
                        if (thermProp != ThermPropType.CriticalProp && thermProp != ThermPropType.EnthalpyOfCombustion)
                        {
                            if (line1.Contains("<a border"))
                            {
                                counter++;

                                name = ExtractName(line2, separatorsStr1, separatorsStr2);

                                if (!(thermProp == ThermPropType.LiquidCp || thermProp == ThermPropType.SolidCp ||
                                      thermProp == ThermPropType.SurfaceTension))
                                {
                                    lineTemp      = reader.ReadLine().Trim();
                                    casRegestryNo = ExtractCasNo(lineTemp, separatorsStr1);
                                }
                                else
                                {
                                    lineTemp = reader.ReadLine();
                                }

                                lineTemp = reader.ReadLine(); //formula
                                if (thermProp == ThermPropType.LiquidCp || thermProp == ThermPropType.SolidCp ||
                                    thermProp == ThermPropType.SurfaceTension)
                                {
                                    lineTemp      = reader.ReadLine().Trim();
                                    casRegestryNo = ExtractCasNo(lineTemp, separatorsStr1);
                                }
                                else
                                {
                                    lineTemp = reader.ReadLine(); //molar weight
                                }

                                lineTemp = reader.ReadLine();
                                a        = ExtractValue(lineTemp, separatorsStr1);

                                lineTemp = reader.ReadLine();
                                b        = ExtractValue(lineTemp, separatorsStr1);

                                lineTemp = reader.ReadLine();
                                c        = ExtractValue(lineTemp, separatorsStr1);

                                if (a == -2147483D || b == -2147483D || c == -2147483D)
                                {
                                    line1 = line2;
                                    continue;
                                }

                                if (thermProp == ThermPropType.GasCp || thermProp == ThermPropType.LiquidCp ||
                                    thermProp == ThermPropType.VapPressure || thermProp == ThermPropType.LiquidDensity ||
                                    thermProp == ThermPropType.LiquidDensity || thermProp == ThermPropType.LiquidVisc)
                                {
                                    lineTemp = reader.ReadLine();
                                    d        = ExtractValue(lineTemp, separatorsStr1);

                                    if (d == -2147483D)
                                    {
                                        line1 = line2;
                                        continue;
                                    }
                                }

                                if (thermProp == ThermPropType.GasCp || thermProp == ThermPropType.VapPressure)
                                {
                                    lineTemp = reader.ReadLine();
                                    e        = ExtractValue(lineTemp, separatorsStr1);
                                    if (e == -2147483D)
                                    {
                                        line1 = line2;
                                        continue;
                                    }
                                }

                                lineTemp = reader.ReadLine();
                                minTemp  = ExtractValue(lineTemp, separatorsStr1);

                                lineTemp = reader.ReadLine();
                                maxTemp  = ExtractValue(lineTemp, separatorsStr1);

                                if (thermProp == ThermPropType.GasCp)
                                {
                                    thermalPropCorrelation = new YawsGasCpCorrelation(name, casRegestryNo, a, b, c, d, e, minTemp, maxTemp);
                                    propList.Add(thermalPropCorrelation);
                                }
                                else if (thermProp == ThermPropType.LiquidCp)
                                {
                                    thermalPropCorrelation = new YawsLiquidCpCorrelation(name, casRegestryNo, a, b, c, d, minTemp, maxTemp);
                                    propList.Add(thermalPropCorrelation);
                                }
                                else if (thermProp == ThermPropType.SolidCp)
                                {
                                    thermalPropCorrelation = new YawsSolidCpCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                    propList.Add(thermalPropCorrelation);
                                }
                                else if (thermProp == ThermPropType.EvapHeat)
                                {
                                    thermalPropCorrelation = new YawsEvaporationHeatCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                    propList.Add(thermalPropCorrelation);
                                }
                                else if (thermProp == ThermPropType.VapPressure)
                                {
                                    thermalPropCorrelation = new YawsVaporPressureCorrelation(name, casRegestryNo, a, b, c, d, e, minTemp, maxTemp);
                                    propList.Add(thermalPropCorrelation);
                                }
                                else if (thermProp == ThermPropType.LiquidDensity)
                                {
                                    thermalPropCorrelation = new YawsLiquidDensityCorrelation(name, casRegestryNo, a, b, c, d, minTemp, maxTemp);
                                    propList.Add(thermalPropCorrelation);
                                }
                                else if (thermProp == ThermPropType.GasVisc)
                                {
                                    thermalPropCorrelation = new YawsGasViscosityCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                    propList.Add(thermalPropCorrelation);
                                }
                                else if (thermProp == ThermPropType.LiquidVisc)
                                {
                                    thermalPropCorrelation = new YawsLiquidViscosityCorrelation(name, casRegestryNo, a, b, c, d, minTemp, maxTemp);
                                    propList.Add(thermalPropCorrelation);
                                }
                                else if (thermProp == ThermPropType.GasK)
                                {
                                    thermalPropCorrelation = new YawsGasThermalConductivityCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                    propList.Add(thermalPropCorrelation);
                                }
                                else if (thermProp == ThermPropType.LiquidK)
                                {
                                    //Liquid thermal conductivity of Yaws organic is different from Yaws
                                    thermalPropCorrelation = new YawsOrganicLiquidThermalConductivityCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                    propList.Add(thermalPropCorrelation);
                                }
                                else if (thermProp == ThermPropType.SurfaceTension)
                                {
                                    thermalPropCorrelation = new YawsSurfaceTensionCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                    propList.Add(thermalPropCorrelation);
                                }
                                else if (thermProp == ThermPropType.EnthalpyOfFormation)
                                {
                                    thermalPropCorrelation = new YawsEnthalpyOfFormationCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                    propList.Add(thermalPropCorrelation);
                                }
                            }

                            line1 = line2;
                        }
                        else
                        {
                            substanceNo = totalCounter + counter + 1;
                            if ((line1.StartsWith(substanceNo.ToString() + "</td><td") ||
                                 //since there is a duplicate for No. 3976 this condition must be added to handle it
                                 line1.StartsWith((substanceNo - 1).ToString() + "</td><td")) && counter < 50)
                            {
                                counter++;

                                name = ExtractName(line2, separatorsStr1, separatorsStr2);

                                lineTemp = reader.ReadLine();
                                if (thermProp != ThermPropType.EnthalpyOfCombustion)
                                {
                                    casRegestryNo = ExtractCasNo(lineTemp, separatorsStr1);
                                }
                                else
                                {
                                    while (!lineTemp.Contains("<a border"))
                                    {
                                        lineTemp = reader.ReadLine();
                                    }
                                }

                                lineTemp         = reader.ReadLine();
                                substanceFormula = ExtractSubstanceFormula(lineTemp);

                                //for debugging use only
                                //formula = sb.ToString();

                                lineTemp = reader.ReadLine();
                                if (thermProp != ThermPropType.EnthalpyOfCombustion)
                                {
                                    molarWeight = ExtractValue(lineTemp, separatorsStr1);
                                }
                                else
                                {
                                    casRegestryNo = ExtractCasNo(lineTemp, separatorsStr1);
                                }

                                lineTemp = reader.ReadLine();
                                if (thermProp != ThermPropType.EnthalpyOfCombustion)
                                {
                                    criticalT = ExtractValue(lineTemp, separatorsStr1);
                                }
                                else
                                {
                                    state = ExtractCasNo(lineTemp, separatorsStr1);
                                }

                                lineTemp  = reader.ReadLine();
                                criticalP = ExtractValue(lineTemp, separatorsStr1);//for EnthalpyOfCombustion this is the value for mole based
                                if (thermProp != ThermPropType.EnthalpyOfCombustion)
                                {
                                    if (criticalP != -2147483D)
                                    {
                                        criticalP *= 1.0e5;//convert from bar to Pa
                                    }
                                }

                                lineTemp  = reader.ReadLine();
                                criticalV = ExtractValue(lineTemp, separatorsStr1); //for EnthalpyOfCombustion this is the value for kg based
                                if (thermProp != ThermPropType.EnthalpyOfCombustion)
                                {
                                    if (criticalV != -2147483D)
                                    {
                                        criticalV *= 1.0e-6; //convert from cm3/mol to m3/mol
                                    }
                                }

                                lineTemp = reader.ReadLine(); //skip critical density since it can be obtained from critical volume and molar weight
                                //subStrs = lineTemp.Trim().Split(separators);
                                //criticalRho = double.Parse(subStrs[0]);

                                if (thermProp != ThermPropType.EnthalpyOfCombustion)
                                {
                                    lineTemp     = reader.ReadLine();
                                    criticalComp = ExtractValue(lineTemp, separatorsStr1);

                                    lineTemp   = reader.ReadLine();
                                    accentricF = ExtractValue(lineTemp, separatorsStr1);
                                }

                                if (thermProp == ThermPropType.EnthalpyOfCombustion)
                                {
                                    thermalPropCorrelation = new YawsEnthalpyOfCombustionCorrelation(name, casRegestryNo, state, criticalP, criticalV, 298.15);
                                    propList.Add(thermalPropCorrelation);
                                }
                                else
                                {
                                    criticalProps = new CriticalPropsAndAcentricFactor(criticalT, criticalP, criticalV, criticalComp, accentricF);
                                    substance     = new Substance(name, substanceType, casRegestryNo, substanceFormula, molarWeight, criticalProps);
                                    propList.Add(substance);
                                }
                            }

                            line1 = line2;
                        }
                    }

                    totalCounter = totalCounter + counter;

                    reader.Close();
                    fsRead.Close();
                }
            }
            catch (Exception ex) {
                Console.WriteLine("The process failed: {0}", ex.ToString());
            }
            finally {
                if (fsRead != null)
                {
                    fsRead.Close();
                }
            }

            PersistProp(GetFileName(thermProp), propList);
            UnpersistProp(GetFileName(thermProp));
        }
Exemplo n.º 21
0
        override internal void ExtractCoeffs(ListBox listBox, SubstanceType substanceType, ThermPropType thermProp)
        {
            if ((prevThermalProp != thermProp) || (prevThermalProp == thermProp && prevSubstanceType == substanceType))
            {
                propList.Clear();
            }

            ThermalPropCorrelationBase thermalPropCorrelation;

            string[] separatorsStr1 = { "<TD class=BorderHelper noWrap>", "<TD class=BorderBottomHelper noWrap>", "</TD>" };
            string[] separatorsStr2 = { "<I>", "</I>" };
            string[] separatorsStr3 = { "<TD class=BorderHelper>", "<TD class=BorderBottomHelper>", "</TD>" };
            string[] separatorsStr4 = { "<SUB>", "</SUB>" };

            string name;
            string casRegestryNo;
            string state = "";
            double a, b, c, d = 1, e = 1, f, g; //, bp = 1;
            double molarWeight, freezingPoint, boilingPoint, criticalT, criticalP, criticalV, criticalComp, acentricF;

            molarWeight = freezingPoint = boilingPoint = criticalT = criticalP = criticalV = criticalComp = acentricF = -2147483D;
            double minTemp = 1, maxTemp = 1;

            string line1, line2, line3, lineTemp;
            bool   isStartOfData;

            CriticalPropsAndAcentricFactor criticalProps;
            Substance        substance;
            SubstanceFormula substanceFormula;

            StreamReader reader;
            FileStream   fsRead = null;

            try {
                foreach (object fullFileName in listBox.Items)
                {
                    fsRead   = new FileStream((string)fullFileName, FileMode.Open, FileAccess.Read);
                    reader   = new StreamReader(fsRead);
                    lineTemp = reader.ReadLine().Trim();
                    line1    = lineTemp;
                    while (!reader.EndOfStream)
                    {
                        isStartOfData = false;
                        if (line1.StartsWith("<TD class=BorderHelper>") || line1.Contains("SUB"))
                        {
                            isStartOfData = true;
                            //need to repair the first line some times
                            if (!line1.EndsWith("</TD>"))
                            {
                                while (!line1.EndsWith("</TD>"))
                                {
                                    line1 += " " + reader.ReadLine().Trim();
                                }
                            }
                        }

                        line2 = reader.ReadLine().Trim();

                        //need to repair the second line some times
                        if (isStartOfData && line2.StartsWith("<TD class=BorderHelper") && !line2.EndsWith("</TD>"))
                        {
                            while (!line2.EndsWith("</TD>"))
                            {
                                line2 += " " + reader.ReadLine().Trim();
                            }
                        }

                        if (isStartOfData && (line2.StartsWith("<TD class=BorderHelper noWrap>") || line2.StartsWith("<TD class=BorderBottomHelper noWrap>")))
                        {
                            substanceFormula = ExtractFormula(line1, separatorsStr3, separatorsStr4);

                            name = ExtractName(line2, separatorsStr1, separatorsStr2);

                            line3         = reader.ReadLine().Trim();
                            casRegestryNo = ExtractCasNo(line3, separatorsStr3);

                            lineTemp = reader.ReadLine();
                            a        = 0;
                            if (thermProp == ThermPropType.EnthalpyOfCombustion)
                            {
                                state = ExtractCasNo(lineTemp, separatorsStr3);
                            }
                            else
                            {
                                a = ExtractValue(lineTemp, separatorsStr3);
                            }

                            if (thermProp == ThermPropType.CriticalProp)
                            {
                                molarWeight = a;
                            }

                            lineTemp = reader.ReadLine();
                            b        = ExtractValue(lineTemp, separatorsStr3);

                            if (thermProp == ThermPropType.CriticalProp)
                            {
                                freezingPoint = b;
                            }

                            lineTemp = reader.ReadLine();
                            c        = ExtractValue(lineTemp, separatorsStr3);

                            if (thermProp == ThermPropType.CriticalProp)
                            {
                                boilingPoint = c;
                            }


                            lineTemp = reader.ReadLine();
                            if (thermProp != ThermPropType.EnthalpyOfCombustion)
                            {
                                d = ExtractValue(lineTemp, separatorsStr3);
                            }
                            if (thermProp == ThermPropType.SolidCp || thermProp == ThermPropType.EvapHeat ||
                                thermProp == ThermPropType.GasVisc || thermProp == ThermPropType.GasK ||
                                thermProp == ThermPropType.LiquidK || thermProp == ThermPropType.SurfaceTension ||
                                thermProp == ThermPropType.EnthalpyOfFormation)
                            {
                                minTemp = d;
                            }
                            else if (thermProp == ThermPropType.CriticalProp)
                            {
                                criticalT = d;
                            }

                            lineTemp = reader.ReadLine();
                            if (thermProp != ThermPropType.EnthalpyOfCombustion)
                            {
                                e = ExtractValue(lineTemp, separatorsStr3);
                            }
                            if (thermProp == ThermPropType.SolidCp || thermProp == ThermPropType.EvapHeat ||
                                thermProp == ThermPropType.GasVisc || thermProp == ThermPropType.GasK ||
                                thermProp == ThermPropType.LiquidK || thermProp == ThermPropType.SurfaceTension ||
                                thermProp == ThermPropType.EnthalpyOfFormation)
                            {
                                maxTemp = e;
                            }
                            else if (thermProp == ThermPropType.LiquidCp || thermProp == ThermPropType.LiquidDensity || thermProp == ThermPropType.LiquidVisc)
                            {
                                minTemp = e;
                            }
                            else if (thermProp == ThermPropType.CriticalProp)
                            {
                                criticalP = 1.0e5 * e;//convert from bar to Pa
                            }

                            if (thermProp == ThermPropType.EvapHeat || thermProp == ThermPropType.CriticalProp ||
                                thermProp == ThermPropType.GasCp || thermProp == ThermPropType.VapPressure ||
                                thermProp == ThermPropType.LiquidCp || thermProp == ThermPropType.LiquidDensity ||
                                thermProp == ThermPropType.LiquidVisc)
                            {
                                lineTemp = reader.ReadLine();
                                f        = ExtractValue(lineTemp, separatorsStr3);

                                //if (thermProp == ThermProp.EvapHeat) {
                                //   bp = f;
                                //}
                                if (thermProp == ThermPropType.CriticalProp)
                                {
                                    criticalV = f * 1.0e-6;        //convert from cm3/mol to m3/mol
                                    lineTemp  = reader.ReadLine(); //skip critical density
                                }
                                else if (thermProp == ThermPropType.GasCp || thermProp == ThermPropType.VapPressure)
                                {
                                    minTemp = f;
                                }
                                else if (thermProp == ThermPropType.LiquidCp || thermProp == ThermPropType.LiquidDensity || thermProp == ThermPropType.LiquidVisc)
                                {
                                    maxTemp = f;
                                }
                            }

                            if (thermProp == ThermPropType.CriticalProp || thermProp == ThermPropType.GasCp ||
                                thermProp == ThermPropType.VapPressure)
                            {
                                lineTemp = reader.ReadLine();
                                g        = ExtractValue(lineTemp, separatorsStr3);

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

                            if (thermProp == ThermPropType.CriticalProp)
                            {
                                lineTemp  = reader.ReadLine();
                                acentricF = ExtractValue(lineTemp, separatorsStr3);
                            }

                            if (thermProp == ThermPropType.CriticalProp)
                            {
                                criticalProps = new CriticalPropsAndAcentricFactor(freezingPoint, boilingPoint, criticalT, criticalP, criticalV, criticalComp, acentricF);
                                substance     = new Substance(name, substanceType, casRegestryNo, substanceFormula, molarWeight, criticalProps);
                                propList.Add(substance);
                            }
                            else if (thermProp == ThermPropType.GasCp)
                            {
                                thermalPropCorrelation = new YawsGasCpCorrelation(name, casRegestryNo, a, b, c, d, e, minTemp, maxTemp);
                                propList.Add(thermalPropCorrelation);
                            }
                            else if (thermProp == ThermPropType.LiquidCp)
                            {
                                thermalPropCorrelation = new YawsLiquidCpCorrelation(name, casRegestryNo, a, b, c, d, minTemp, maxTemp);
                                propList.Add(thermalPropCorrelation);
                            }
                            else if (thermProp == ThermPropType.SolidCp)
                            {
                                thermalPropCorrelation = new YawsSolidCpCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                propList.Add(thermalPropCorrelation);
                            }
                            else if (thermProp == ThermPropType.EvapHeat)
                            {
                                thermalPropCorrelation = new YawsEvaporationHeatCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                propList.Add(thermalPropCorrelation);
                            }
                            else if (thermProp == ThermPropType.VapPressure)
                            {
                                thermalPropCorrelation = new YawsVaporPressureCorrelation(name, casRegestryNo, a, b, c, d, e, minTemp, maxTemp);
                                propList.Add(thermalPropCorrelation);
                            }
                            else if (thermProp == ThermPropType.LiquidDensity)
                            {
                                thermalPropCorrelation = new YawsLiquidDensityCorrelation(name, casRegestryNo, a, b, c, d, minTemp, maxTemp);
                                propList.Add(thermalPropCorrelation);
                            }
                            else if (thermProp == ThermPropType.GasVisc)
                            {
                                thermalPropCorrelation = new YawsGasViscosityCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                propList.Add(thermalPropCorrelation);
                            }
                            else if (thermProp == ThermPropType.LiquidVisc)
                            {
                                thermalPropCorrelation = new YawsLiquidViscosityCorrelation(name, casRegestryNo, a, b, c, d, minTemp, maxTemp);
                                propList.Add(thermalPropCorrelation);
                            }
                            else if (thermProp == ThermPropType.GasK)
                            {
                                thermalPropCorrelation = new YawsGasThermalConductivityCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                propList.Add(thermalPropCorrelation);
                            }
                            else if (thermProp == ThermPropType.LiquidK)
                            {
                                thermalPropCorrelation = new YawsLiquidSolidThermalConductivityCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                propList.Add(thermalPropCorrelation);
                            }
                            else if (thermProp == ThermPropType.SurfaceTension)
                            {
                                thermalPropCorrelation = new YawsSurfaceTensionCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                propList.Add(thermalPropCorrelation);
                            }
                            else if (thermProp == ThermPropType.EnthalpyOfFormation)
                            {
                                thermalPropCorrelation = new YawsEnthalpyOfFormationCorrelation(name, casRegestryNo, a, b, c, minTemp, maxTemp);
                                propList.Add(thermalPropCorrelation);
                            }
                            else if (thermProp == ThermPropType.EnthalpyOfCombustion)
                            {
                                thermalPropCorrelation = new YawsEnthalpyOfCombustionCorrelation(name, casRegestryNo, state, b, c, 298.15);
                                propList.Add(thermalPropCorrelation);
                            }
                        }
                        line1 = line2;
                    }
                    reader.Close();
                    fsRead.Close();
                }
            }
            catch (Exception ex) {
                Console.WriteLine("The process failed: {0}", ex.ToString());
            }
            finally {
                if (fsRead != null)
                {
                    fsRead.Close();
                }
            }

            //if (substanceType == SubstanceType.Inorganic) {
            PersistProp(GetFileName(thermProp), propList);
            UnpersistProp(GetFileName(thermProp));
            //}

            prevSubstanceType = substanceType;
            prevThermalProp   = thermProp;
        }
Exemplo n.º 22
0
 public Substance(string name, SubstanceType type, bool isUserDefined)
 {
     this.name          = name;
     this.type          = type;
     this.isUserDefined = isUserDefined;
 }
Exemplo n.º 23
0
 public Substance(string name, SubstanceType type)
 {
     Name = name;
     Type = type;
 }
Exemplo n.º 24
0
        private void comboBoxSubstanceType_SelectedIndexChanged(object sender, EventArgs e)
        {
            int idx = comboBoxSubstanceType.SelectedIndex;

            substanceType = (SubstanceType)idx;
        }
Exemplo n.º 25
0
        private void PopulateSubstanceList()
        {
            this.listViewSubstances.Items.Clear();
            string typeFilterStr    = this.comboBoxTypes.SelectedItem.ToString();
            string userDefFilterStr = this.comboBoxUserDef.SelectedItem.ToString();

            IList list = null;

            if (typeFilterStr.Equals(UI.STR_ALL) && userDefFilterStr.Equals(UI.STR_ALL))
            {
                if (this.substancesToShow == SubstancesToShow.All)
                {
                    list = SubstanceCatalog.GetInstance().GetSubstanceList();
                }
                else if (this.substancesToShow == SubstancesToShow.Material)
                {
                    list = SubstanceCatalog.GetInstance().GetMaterialSubstanceList();
                }
                //else if (this.substancesToShow == SubstancesToShow.Gas)
                //   list = SubstanceCatalog.GetInstance().GetGasSubstanceList();
                //else if (this.substancesToShow == SubstancesToShow.Moisture)
                //   list = SubstanceCatalog.GetInstance().GetMoistureSubstanceList();
                this.PopulateIt(list);
            }
            else if (typeFilterStr.Equals(UI.STR_ALL) && !userDefFilterStr.Equals(UI.STR_ALL))
            {
                bool userDef = UI.GetUserDefinedAsBool(userDefFilterStr);
                if (this.substancesToShow == SubstancesToShow.All)
                {
                    list = SubstanceCatalog.GetInstance().GetSubstanceList(userDef);
                }
                else if (this.substancesToShow == SubstancesToShow.Material)
                {
                    list = SubstanceCatalog.GetInstance().GetMaterialSubstanceList(userDef);
                }
                //else if (this.substancesToShow == SubstancesToShow.Gas)
                //   list = SubstanceCatalog.GetInstance().GetGasSubstanceList(userDef);
                //else if (this.substancesToShow == SubstancesToShow.Moisture)
                //   list = SubstanceCatalog.GetInstance().GetMoistureSubstanceList(userDef);
                this.PopulateIt(list);
            }
            else if (!typeFilterStr.Equals(UI.STR_ALL) && userDefFilterStr.Equals(UI.STR_ALL))
            {
                SubstanceType type = SubstancesControl.GetSubstanceTypeAsEnum(typeFilterStr);
                if (this.substancesToShow == SubstancesToShow.All)
                {
                    list = SubstanceCatalog.GetInstance().GetSubstanceList(type);
                }
                else if (this.substancesToShow == SubstancesToShow.Material)
                {
                    list = SubstanceCatalog.GetInstance().GetMaterialSubstanceList(type);
                }
                //else if (this.substancesToShow == SubstancesToShow.Gas)
                //   list = SubstanceCatalog.GetInstance().GetGasSubstanceList(type);
                //else if (this.substancesToShow == SubstancesToShow.Moisture)
                //   list = SubstanceCatalog.GetInstance().GetMoistureSubstanceList(type);
                this.PopulateIt(list);
            }
            else
            {
                bool          userDef = UI.GetUserDefinedAsBool(userDefFilterStr);
                SubstanceType type    = SubstancesControl.GetSubstanceTypeAsEnum(typeFilterStr);
                if (this.substancesToShow == SubstancesToShow.All)
                {
                    list = SubstanceCatalog.GetInstance().GetSubstanceList(userDef, type);
                }
                else if (this.substancesToShow == SubstancesToShow.Material)
                {
                    //   list = SubstanceCatalog.GetInstance().GetMaterialSubstanceList(userDef, type);
                    //else if (this.substancesToShow == SubstancesToShow.Gas)
                    //   list = SubstanceCatalog.GetInstance().GetGasSubstanceList(userDef, type);
                    //else if (this.substancesToShow == SubstancesToShow.Moisture)
                    //   list = SubstanceCatalog.GetInstance().GetMoistureSubstanceList(userDef, type);
                    this.PopulateIt(list);
                }
            }
        }
Exemplo n.º 26
0
 public void UpdateSubstance(SubstanceType substance, float amount)
 {
     substances[substance] = amount;
 }
Exemplo n.º 27
0
 public void ClearSubstance(SubstanceType substance)
 {
     substances[substance] = 0;
 }
Exemplo n.º 28
0
 public float GetSubstance(SubstanceType substance)
 {
     return(substances[substance]);
 }
Exemplo n.º 29
0
 public void AddSubstance(SubstanceType substance, float amount)
 {
     substances[substance] += amount;
 }
Exemplo n.º 30
0
 internal virtual void ExtractCoeffs(ListBox listBox, SubstanceType substanceType, ThermPropType thermalProp)
 {
 }