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.Gas) { list = SubstanceCatalog.GetInstance().GetGasSubstanceList(); } else if (this.substancesToShow == SubstancesToShow.Material) { list = SubstanceCatalog.GetInstance().GetMaterialSubstanceList(); } 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.Gas) { list = SubstanceCatalog.GetInstance().GetGasSubstanceList(userDef); } else if (this.substancesToShow == SubstancesToShow.Material) { list = SubstanceCatalog.GetInstance().GetMaterialSubstanceList(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.Gas) { list = SubstanceCatalog.GetInstance().GetGasSubstanceList(type); } else if (this.substancesToShow == SubstancesToShow.Material) { list = SubstanceCatalog.GetInstance().GetMaterialSubstanceList(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.Gas) { list = SubstanceCatalog.GetInstance().GetGasSubstanceList(userDef, type); } else if (this.substancesToShow == SubstancesToShow.Material) { list = SubstanceCatalog.GetInstance().GetMaterialSubstanceList(userDef, type); } else if (this.substancesToShow == SubstancesToShow.Moisture) { list = SubstanceCatalog.GetInstance().GetMoistureSubstanceList(userDef, type); } this.PopulateIt(list); } }
public AddOrEditDryingMaterialForm(DryingMaterial dryingMaterial, INumericFormat numericFormat) { // // Required for Windows Form Designer support // InitializeComponent(); this.inConstruction = true; this.iNumericFormat = numericFormat; // populate the moisture substance combobox IEnumerator en = SubstanceCatalog.GetInstance().GetMoistureSubstanceList().GetEnumerator(); while (en.MoveNext()) { Substance substance = (Substance)en.Current; this.comboBoxMoistureSubstance.Items.Add(substance); } this.comboBoxMoistureSubstance.SelectedIndex = 0; if (dryingMaterial == null) { // new this.isNew = true; this.Text = "New Drying Material"; this.dryingMaterialCache = new DryingMaterialCache(DryingMaterialCatalog.GetInstance()); this.textBoxName.Text = "New Drying Material"; // populate the material type combobox this.comboBoxType.Items.Add(DryingMaterialsControl.STR_MAT_TYPE_GENERIC_MATERIAL); this.comboBoxType.Items.Add(DryingMaterialsControl.STR_MAT_TYPE_GENERIC_FOOD); // this.comboBoxType.Items.Add(DryingMaterialsControl.STR_MAT_TYPE_SPECIAL_FOOD); this.comboBoxType.SelectedIndex = 0; string matTypeStr = this.comboBoxType.SelectedItem as string; MaterialType matTypeEnum = DryingMaterialsControl.GetDryingMaterialTypeAsEnum(matTypeStr); this.dryingMaterialCache.SetMaterialType(matTypeEnum); Substance subst = this.comboBoxMoistureSubstance.SelectedItem as Substance; this.dryingMaterialCache.MoistureSubstance = subst; } else { // edit this.isNew = false; this.Text = "Edit Drying Material"; this.dryingMaterialCache = new DryingMaterialCache(dryingMaterial, DryingMaterialCatalog.GetInstance()); this.textBoxName.Text = this.dryingMaterialCache.Name; // populate the material type combobox this.comboBoxType.Items.Add(DryingMaterialsControl.GetDryingMaterialTypeAsString(this.dryingMaterialCache.MaterialType)); this.comboBoxType.SelectedIndex = 0; this.comboBoxMoistureSubstance.SelectedItem = this.dryingMaterialCache.MoistureSubstance; } this.labelSpecificHeat.InitializeVariable(this.dryingMaterialCache.SpecificHeatOfAbsoluteDryMaterial); this.textBoxSpecificHeat.InitializeVariable(numericFormat, this.dryingMaterialCache.SpecificHeatOfAbsoluteDryMaterial); this.substancesControl.SubstancesToShow = SubstancesToShow.Material; this.dmComponentsControl.SetMaterialComponents(this.dryingMaterialCache, numericFormat); this.UpdateTheUI(this.dryingMaterialCache.MaterialType); this.dryingMaterialCache.MaterialTypeChanged += new MaterialTypeChangedEventHandler(dryingMaterialCache_MaterialTypeChanged); this.dryingMaterialCache.MoistureSubstanceChanged += new MoistureSubstanceChangedEventHandler(dryingMaterialCache_MoistureSubstanceChanged); this.substancesControl.ListViewSubstances.SelectedIndexChanged += new EventHandler(ListViewSubstances_SelectedIndexChanged); this.inConstruction = false; }
private void Solve() { SubstanceCatalog catalog = SubstanceCatalog.GetInstance(); Substance carbon = catalog.GetSubstance("carbon"); Substance hydrogen = catalog.GetSubstance("hydrogen"); Substance oxygen = catalog.GetSubstance("oxygen"); Substance sulfur = catalog.GetSubstance("sulfur"); Substance air = catalog.GetSubstance("air"); Substance carbonDioxide = catalog.GetSubstance("carbon dioxide"); Substance sulfurDioxide = catalog.GetSubstance("sulfur dioxide"); Substance water = catalog.GetSubstance("water"); Substance nitrogen = catalog.GetSubstance("nitrogen"); Substance argon = catalog.GetSubstance("argon"); //Substance ash = SubstanceCatalog.GetInstance().GetSubstance("ash"); double totalEenthalpyOfReactantInFuelInlet = 0; double moleFractionCarbon = 0; double moleFractionHydrogen = 0; double moleFractionSulfur = 0; double moleFractionOxygen = 0; //double massAsh = 0; double moleFractionCarbonDioxide = 0; double moleFractionNitrogen = 0; MaterialComponents components = fuelInlet.Components; MaterialComponent component; Substance mySubstance; double myMassFraction; if (fuelInlet is GenericFuelStream) { for (int i = 0; i < components.Count; i++) { component = components[i]; mySubstance = component.Substance; myMassFraction = component.MassFraction.Value; if (mySubstance == carbon) { moleFractionCarbon = myMassFraction / carbon.MolarWeight; } else if (mySubstance == hydrogen) { moleFractionHydrogen = 0.5 * myMassFraction / hydrogen.MolarWeight; } else if (mySubstance == oxygen) { moleFractionOxygen = myMassFraction / oxygen.MolarWeight; } else if (mySubstance == sulfur) { moleFractionSulfur = myMassFraction / sulfur.MolarWeight; } //else if (component.Substance == ash) { // massAsh = myMassFraction; //} } } else if (fuelInlet is DetailedFuelStream) { totalEenthalpyOfReactantInFuelInlet = 0; moleFractionCarbon = 0; moleFractionHydrogen = 0; moleFractionOxygen = 0; moleFractionSulfur = 0; SubstanceFormula formula; string[] elements; int elementCount; double t = fuelInlet.Temperature.Value; for (int i = 0; i < components.Count; i++) { component = components[i]; mySubstance = component.Substance; myMassFraction = component.MassFraction.Value; if (mySubstance == carbonDioxide) { moleFractionCarbonDioxide = myMassFraction / carbonDioxide.MolarWeight; } else if (mySubstance == nitrogen) { moleFractionNitrogen = myMassFraction / nitrogen.MolarWeight; } else { totalEenthalpyOfReactantInFuelInlet += myMassFraction * ThermalPropCalculator.Instance.CalculateEnthalpyOfFormation(t, mySubstance); formula = mySubstance.Formula; elements = formula.Elements; foreach (string element in elements) { elementCount = formula.GetElementCount(element); if (element == "C") { moleFractionCarbon += elementCount * myMassFraction / carbon.MolarWeight; } else if (element == "H") { moleFractionHydrogen += elementCount * 0.25 * myMassFraction / hydrogen.MolarWeight; } else if (element == "O") { moleFractionOxygen = elementCount * 0.5 * myMassFraction / oxygen.MolarWeight; } else if (element == "S") { moleFractionSulfur += elementCount * myMassFraction / sulfur.MolarWeight; } } } } } double fuelMassFlowRate = fuelInlet.MassFlowRate.Value; double moleFractionOxygenNeeded = moleFractionCarbon + moleFractionHydrogen + moleFractionSulfur - moleFractionOxygen; double totalExactOxygenMassNeeded = fuelMassFlowRate * moleFractionOxygenNeeded * oxygen.MolarWeight; double totalOxygenMoleNeeded = fuelMassFlowRate * moleFractionOxygenNeeded * (1.0 + excessAir.Value); double totalDryAirMassNeeded = totalOxygenMoleNeeded * air.MolarWeight / 0.21; double totalMoistureMassCarriedByInletAir = totalDryAirMassNeeded * airInlet.Humidity.Value; double totalAirMassNeeded = totalDryAirMassNeeded + totalMoistureMassCarriedByInletAir; Calculate(airInlet.MassFlowRate, totalAirMassNeeded); double totalMoitureGeneratedByReaction = fuelMassFlowRate * moleFractionHydrogen * water.MolarWeight; double totalMoistureInFlueGas = totalMoitureGeneratedByReaction + totalMoistureMassCarriedByInletAir; double totalDryFlueGas = totalDryAirMassNeeded + fuelMassFlowRate - totalMoitureGeneratedByReaction; double totalFlueGasGenerated = totalDryFlueGas + totalMoistureInFlueGas; Calculate(flueGasOutlet.MassFlowRate, totalFlueGasGenerated); double flueGasMoistureContentDryBase = totalMoistureInFlueGas / totalDryFlueGas; Calculate(flueGasOutlet.Humidity, flueGasMoistureContentDryBase); ArrayList componentList = new ArrayList(); double massFractionCarbonDioxide = fuelMassFlowRate * (moleFractionCarbon + moleFractionCarbonDioxide) * carbonDioxide.MolarWeight / totalDryFlueGas; componentList.Add(new MaterialComponent(carbonDioxide, massFractionCarbonDioxide)); double massFractionNitrogen = (totalDryAirMassNeeded * 0.78 + fuelMassFlowRate * moleFractionNitrogen) / totalDryFlueGas; componentList.Add(new MaterialComponent(nitrogen, massFractionNitrogen)); double massFractionSulfurDioxide = fuelMassFlowRate * moleFractionSulfur * sulfurDioxide.MolarWeight / totalDryFlueGas; componentList.Add(new MaterialComponent(sulfurDioxide, massFractionSulfurDioxide)); double massFractionOxygen = fuelMassFlowRate * moleFractionOxygenNeeded * excessAir.Value * oxygen.MolarWeight / totalDryFlueGas; componentList.Add(new MaterialComponent(oxygen, massFractionOxygen)); double massFractionArgon = totalDryAirMassNeeded * 0.01 / totalDryFlueGas; componentList.Add(new MaterialComponent(argon, massFractionArgon)); CompositeSubstance flueGas = new CompositeSubstance("Flue Gas", componentList); MaterialComponents flueGasComponents = new MaterialComponents(); flueGasComponents.Add(new MaterialComponent(flueGas, 1 / (1 + flueGasMoistureContentDryBase))); flueGasComponents.Add(new MaterialComponent(water, flueGasMoistureContentDryBase / (1 + flueGasMoistureContentDryBase))); flueGasOutlet.Components = flueGasComponents; double fuelInletEnthalpy = fuelMassFlowRate * fuelInlet.SpecificEnthalpy.Value; double airInletEnthalpy = totalAirMassNeeded * airInlet.SpecificEnthalpy.Value; double totalHeatGenerated = Constants.NO_VALUE; if (fuelInlet is GenericFuelStream) { GenericFuelStream gfs = fuelInlet as GenericFuelStream; if (gfs.HeatValue.HasValue) { //total heat genrate eaquls to heat value of the fuel times fuelMassFlowRate totalHeatGenerated = gfs.HeatValue.Value * fuelMassFlowRate; double totalFlueGasSpecificEnthalpy = (fuelInletEnthalpy + airInletEnthalpy + totalHeatGenerated) / totalFlueGasGenerated; Calculate(flueGasOutlet.SpecificEnthalpy, totalFlueGasSpecificEnthalpy); } } else if (fuelInlet is DetailedFuelStream) { HumidGasCalculator humidGasCalculator = new HumidGasCalculator(flueGas, water); ThermalPropCalculator propCalculator = ThermalPropCalculator.Instance; double totalEenthalpyOfProductCarbonDioxide; double totalEenthalpyOfProductWater; double totalEenthalpyOfProductSulfer; double totalEenthalpyOfProduct; double totalFlueGasSpecificEnthalpy; double t = fuelInlet.Temperature.Value;; totalEenthalpyOfReactantInFuelInlet *= fuelMassFlowRate; double totalEnthalpyOfReactantOxygen = totalExactOxygenMassNeeded * propCalculator.CalculateEnthalpyOfFormation(t, oxygen); double totalEenthalpyOfReactants = totalEenthalpyOfReactantInFuelInlet + totalEnthalpyOfReactantOxygen; double p = flueGasOutlet.Pressure.Value; double tNew = t; int counter = 0; do { counter++; t = tNew; totalEenthalpyOfProductCarbonDioxide = fuelMassFlowRate * moleFractionCarbon * propCalculator.CalculateEnthalpyOfFormation(t, carbonDioxide); totalEenthalpyOfProductWater = fuelMassFlowRate * moleFractionHydrogen * propCalculator.CalculateEnthalpyOfFormation(t, water); totalEenthalpyOfProductSulfer = fuelMassFlowRate * moleFractionSulfur * propCalculator.CalculateEnthalpyOfFormation(t, sulfurDioxide); totalEenthalpyOfProduct = totalEenthalpyOfProductCarbonDioxide + totalEenthalpyOfProductWater + totalEenthalpyOfProductSulfer; totalHeatGenerated = totalEenthalpyOfProduct - totalEenthalpyOfReactants; totalFlueGasSpecificEnthalpy = (fuelInletEnthalpy + airInletEnthalpy + totalHeatGenerated) / totalFlueGasGenerated; tNew = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(totalFlueGasSpecificEnthalpy, flueGasMoistureContentDryBase, p); } while (Math.Abs(tNew - t) < 1.0e-6 && counter < 100); if (counter == 100) { } Calculate(flueGasOutlet.Temperature, tNew); } }