void Initialize() { container.CreateAndAddLabelRow("Reaction ID"); container.CreateAndAddStringEditorRow2("Name", "", rx.Name, (sender, e) => { rx.Name = sender.Text; }); container.CreateAndAddLabelRow("Compounds and Stoichiometry (Include / Name / Stoich. Coeff. / Direct Order Exponent / Reverse Order Exponent)"); var compcontainer = new DynamicLayout(); compcontainer.BackgroundColor = Colors.White; Double val; foreach (ICompoundConstantProperties comp in flowsheet.SelectedCompounds.Values) { var chk = new CheckBox() { Text = comp.Name, Checked = (rx.Components.ContainsKey(comp.Name) ? true : false) }; chk.CheckedChanged += (sender, e) => { if (!rx.Components.ContainsKey(comp.Name)) { rx.Components.Add(comp.Name, new DWSIM.Thermodynamics.BaseClasses.ReactionStoichBase(comp.Name, 0, false, 0, 0)); } else { rx.Components.Remove(comp.Name); } UpdateEquation(); }; var sc = new TextBox() { Width = 30, Text = (rx.Components.ContainsKey(comp.Name) ? rx.Components[comp.Name].StoichCoeff.ToString() : 0.0f.ToString()) }; sc.TextChanged += (sender, e) => { if (Double.TryParse(sc.Text.ToString(), out val)) { sc.TextColor = SystemColors.ControlText; if (!rx.Components.ContainsKey(comp.Name)) { rx.Components.Add(comp.Name, new DWSIM.Thermodynamics.BaseClasses.ReactionStoichBase(comp.Name, Double.Parse(sc.Text), false, 0, 0)); } else { rx.Components[comp.Name].StoichCoeff = double.Parse(sc.Text); } UpdateEquation(); } else { sc.TextColor = Colors.Red; } }; var txtdo = new TextBox() { Width = 30, Text = (rx.Components.ContainsKey(comp.Name) ? rx.Components[comp.Name].DirectOrder.ToString() : 0.0f.ToString()) }; txtdo.TextChanged += (sender, e) => { if (Double.TryParse(txtdo.Text.ToString(), out val)) { txtdo.TextColor = SystemColors.ControlText; if (!rx.Components.ContainsKey(comp.Name)) { rx.Components.Add(comp.Name, new DWSIM.Thermodynamics.BaseClasses.ReactionStoichBase(comp.Name, 0, false, Double.Parse(txtdo.Text), 0)); } else { rx.Components[comp.Name].DirectOrder = double.Parse(txtdo.Text); } UpdateEquation(); } else { txtdo.TextColor = Colors.Red; } }; var txtro = new TextBox() { Width = 30, Text = (rx.Components.ContainsKey(comp.Name) ? rx.Components[comp.Name].ReverseOrder.ToString() : 0.0f.ToString()) }; txtro.TextChanged += (sender, e) => { if (Double.TryParse(txtro.Text.ToString(), out val)) { txtro.TextColor = SystemColors.ControlText; if (!rx.Components.ContainsKey(comp.Name)) { rx.Components.Add(comp.Name, new DWSIM.Thermodynamics.BaseClasses.ReactionStoichBase(comp.Name, 0, false, 0, Double.Parse(txtro.Text))); } else { rx.Components[comp.Name].ReverseOrder = double.Parse(txtro.Text); } UpdateEquation(); } else { txtro.TextColor = Colors.Red; } }; compcontainer.Add(new TableRow(chk, null, sc, txtdo, txtro)); } container.CreateAndAddControlRow(compcontainer); container.CreateAndAddEmptySpace(); var comps = flowsheet.SelectedCompounds.Values.Select((x) => x.Name).ToList(); comps.Insert(0, ""); container.CreateAndAddLabelRow("Base Compound"); var basecompselector = container.CreateAndAddDropDownRow("Base Compound", comps, 0, null); var basecomp = rx.Components.Values.Where((x) => x.IsBaseReactant).FirstOrDefault(); if (basecomp != null) { basecompselector.SelectedIndex = comps.IndexOf(basecomp.CompName); } else { basecompselector.SelectedIndex = 0; } basecompselector.SelectedIndexChanged += (sender, e) => { if (rx.Components.ContainsKey(comps[basecompselector.SelectedIndex])) { foreach (var rxc in rx.Components.Values) { rxc.IsBaseReactant = false; } rx.Components[comps[basecompselector.SelectedIndex]].IsBaseReactant = true; rx.BaseReactant = comps[basecompselector.SelectedIndex]; } }; container.CreateAndAddLabelRow("Reaction Balance"); txtEquation = container.CreateAndAddLabelRow2(""); container.CreateAndAddLabelRow("Reaction Phase"); var rxphaseselector = container.CreateAndAddDropDownRow("Reaction Phase", Shared.StringArrays.reactionphase().ToList(), 0, null); switch (rx.ReactionPhase) { case Interfaces.Enums.PhaseName.Vapor: rxphaseselector.SelectedIndex = (0); break; case Interfaces.Enums.PhaseName.Liquid: rxphaseselector.SelectedIndex = (1); break; case Interfaces.Enums.PhaseName.Mixture: rxphaseselector.SelectedIndex = (2); break; } rxphaseselector.SelectedIndexChanged += (sender, e) => { switch (rxphaseselector.SelectedIndex) { case 0: rx.ReactionPhase = Interfaces.Enums.PhaseName.Vapor; break; case 1: rx.ReactionPhase = Interfaces.Enums.PhaseName.Liquid; break; case 2: rx.ReactionPhase = Interfaces.Enums.PhaseName.Mixture; break; } }; container.CreateAndAddLabelRow("Reaction Basis"); var rxbasisselector = container.CreateAndAddDropDownRow("Reaction Basis", Shared.StringArrays.reactionbasis().ToList(), 0, null); switch (rx.ReactionBasis) { case Interfaces.Enums.ReactionBasis.Activity: rxphaseselector.SelectedIndex = (0); break; case Interfaces.Enums.ReactionBasis.Fugacity: rxphaseselector.SelectedIndex = (1); break; case Interfaces.Enums.ReactionBasis.MassConc: rxphaseselector.SelectedIndex = (2); break; case Interfaces.Enums.ReactionBasis.MassFrac: rxphaseselector.SelectedIndex = (3); break; case Interfaces.Enums.ReactionBasis.MolarConc: rxphaseselector.SelectedIndex = (4); break; case Interfaces.Enums.ReactionBasis.MolarFrac: rxphaseselector.SelectedIndex = (5); break; case Interfaces.Enums.ReactionBasis.PartialPress: rxphaseselector.SelectedIndex = (6); break; } rxbasisselector.SelectedIndexChanged += (sender, e) => { switch (rxbasisselector.SelectedIndex) { case 0: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.Activity; break; case 1: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.Fugacity; break; case 2: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.MassConc; break; case 3: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.MassFrac; break; case 4: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.MolarConc; break; case 5: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.MolarFrac; break; case 6: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.PartialPress; break; } }; container.CreateAndAddLabelRow("Kinetic Parameters"); container.CreateAndAddLabelRow2("Direct and Reverse Reactions Velocity Constants (k = A*exp(-E/RT), E in J/mol and T in K)"); container.CreateAndAddStringEditorRow2("Direct Reaction A", "", rx.A_Forward.ToString(), (sender, e) => { if (Double.TryParse(sender.Text.ToString(), out val)) { sender.TextColor = SystemColors.ControlText; rx.A_Forward = double.Parse(sender.Text); } else { sender.TextColor = Colors.Red; } }); container.CreateAndAddStringEditorRow2("Direct Reaction E", "", rx.E_Forward.ToString(), (sender, e) => { if (Double.TryParse(sender.Text.ToString(), out val)) { sender.TextColor = SystemColors.ControlText; rx.E_Forward = double.Parse(sender.Text); } else { sender.TextColor = Colors.Red; } }); container.CreateAndAddStringEditorRow2("Reverse Reaction A", "", rx.A_Reverse.ToString(), (sender, e) => { if (Double.TryParse(sender.Text.ToString(), out val)) { sender.TextColor = SystemColors.ControlText; rx.A_Reverse = double.Parse(sender.Text); } else { sender.TextColor = Colors.Red; } }); container.CreateAndAddStringEditorRow2("Reverse Reaction E", "", rx.E_Reverse.ToString(), (sender, e) => { if (Double.TryParse(sender.Text.ToString(), out val)) { sender.TextColor = SystemColors.ControlText; rx.E_Reverse = double.Parse(sender.Text); } else { sender.TextColor = Colors.Red; } }); container.CreateAndAddLabelRow("Units"); var us = new DWSIM.SharedClasses.SystemsOfUnits.Units(); var units = us.GetUnitSet(Interfaces.Enums.UnitOfMeasure.molar_conc); units.AddRange(us.GetUnitSet(Interfaces.Enums.UnitOfMeasure.mass_conc)); units.AddRange(us.GetUnitSet(Interfaces.Enums.UnitOfMeasure.pressure)); units.Insert(0, ""); container.CreateAndAddDropDownRow("Basis Units (Base Compound)", units, units.IndexOf(rx.ConcUnit), (sender, e) => rx.ConcUnit = sender.SelectedValue.ToString()); container.CreateAndAddDropDownRow("Velocity Units", units, units.IndexOf(rx.VelUnit), (sender, e) => rx.VelUnit = sender.SelectedValue.ToString()); UpdateEquation(); }
void Initialize() { rxcontainer = new DynamicLayout(); rscontainer = new DynamicLayout(); if (flowsheet.ReactionSets.Count == 0) { flowsheet.ReactionSets.Add("DefaultSet", new ReactionSet("DefaultSet", "Default Set", "")); } container.CreateAndAddLabelRow("Reactions"); CreateReactionsList(); container.CreateAndAddControlRow(rxcontainer); container.CreateAndAddLabelRow("Add a Reaction"); var btnAddConv = container.CreateAndAddLabelAndButtonRow("Add New Conversion Reaction", "New Conversion Reaction", null, (sender, e) => { var _rx = new Reaction("NewConvReac", Guid.NewGuid().ToString(), "") { ReactionType = Interfaces.Enums.ReactionType.Conversion }; var myview = s.GetDefaultContainer(); var cre = new ConversionReaction(flowsheet, _rx, myview); Form alert = null; myview.CreateAndAddTwoButtonsRow("Cancel", null, "Add", null, (sender2, e2) => alert.Close(), (sender2, e2) => { _rx = (Reaction)cre.rx; flowsheet.Reactions.Add(_rx.ID, _rx); flowsheet.ReactionSets["DefaultSet"].Reactions.Add(_rx.ID, new ReactionSetBase(_rx.ID, 0, true)); CreateReactionsList(); alert.Close(); }); alert = s.GetDefaultEditorForm("Add Conversion Reaction", 500, 400, myview); alert.Shown += (s1, e1) => { myview.Invalidate(); alert.Height = myview.Height + 40; }; alert.Topmost = true; alert.Show(); }); var btnAddEq = container.CreateAndAddLabelAndButtonRow("Add New Equilibrium Reaction", "New Equilibrium Reaction", null, (sender, e) => { var _rx = new Reaction("NewEqReac", Guid.NewGuid().ToString(), "") { ReactionType = Interfaces.Enums.ReactionType.Equilibrium }; var myview = s.GetDefaultContainer(); var cre = new EquilibriumReaction(flowsheet, _rx, myview); Form alert = null; myview.CreateAndAddTwoButtonsRow("Cancel", null, "Add", null, (sender2, e2) => alert.Close(), (sender2, e2) => { _rx = (Reaction)cre.rx; flowsheet.Reactions.Add(_rx.ID, _rx); flowsheet.ReactionSets["DefaultSet"].Reactions.Add(_rx.ID, new ReactionSetBase(_rx.ID, 0, true)); CreateReactionsList(); alert.Close(); }); alert = s.GetDefaultEditorForm("Add Equilibrium Reaction", 500, 400, myview); alert.Shown += (s1, e1) => { myview.Invalidate(); alert.Height = myview.Height + 40; }; alert.Topmost = true; alert.Show(); }); var btnAddKin = container.CreateAndAddLabelAndButtonRow("Add New Kinetic Reaction", "New Kinetic Reaction", null, (sender, e) => { var _rx = new Reaction("NewKinReac", Guid.NewGuid().ToString(), "") { ReactionType = Interfaces.Enums.ReactionType.Kinetic }; var myview = s.GetDefaultContainer(); var cre = new KineticReaction(flowsheet, _rx, myview); Form alert = null; myview.CreateAndAddTwoButtonsRow("Cancel", null, "Add", null, (sender2, e2) => alert.Close(), (sender2, e2) => { _rx = (Reaction)cre.rx; flowsheet.Reactions.Add(_rx.ID, _rx); flowsheet.ReactionSets["DefaultSet"].Reactions.Add(_rx.ID, new ReactionSetBase(_rx.ID, 0, true)); CreateReactionsList(); alert.Close(); }); alert = s.GetDefaultEditorForm("Add Kinetic Reaction", 850, 760, myview); alert.Shown += (s1, e1) => { myview.Invalidate(); alert.Height = myview.Height + 40; }; alert.Topmost = true; alert.Show(); }); var btnAddHC = container.CreateAndAddLabelAndButtonRow("Add New Heterogeneous Catalytic Reaction", "New HetCat Reaction", null, (sender, e) => { var _rx = new Reaction("NewHetCatReac", Guid.NewGuid().ToString(), "") { ReactionType = Interfaces.Enums.ReactionType.Heterogeneous_Catalytic }; var myview = s.GetDefaultContainer(); var cre = new HetCatReaction(flowsheet, _rx, myview); Form alert = null; myview.CreateAndAddTwoButtonsRow("Cancel", null, "Add", null, (sender2, e2) => alert.Close(), (sender2, e2) => { _rx = (Reaction)cre.rx; flowsheet.Reactions.Add(_rx.ID, _rx); flowsheet.ReactionSets["DefaultSet"].Reactions.Add(_rx.ID, new ReactionSetBase(_rx.ID, 0, true)); CreateReactionsList(); alert.Close(); }); alert = s.GetDefaultEditorForm("Add Heterogeneous Catalytic Reaction", 850, 690, myview); alert.Shown += (s1, e1) => { myview.Invalidate(); alert.Height = myview.Height + 40; }; alert.Topmost = true; alert.Show(); }); container.CreateAndAddEmptySpace(); container.CreateAndAddLabelRow("Reaction Sets"); container.CreateAndAddControlRow(rscontainer); container.CreateAndAddLabelRow("Add a Reaction Set"); container.CreateAndAddLabelAndButtonRow("Add New Reaction Set", "New Reaction Set", null, (sender, e) => { var rsid = Guid.NewGuid().ToString(); flowsheet.ReactionSets.Add(rsid, new ReactionSet(rsid, "NewReactionSet", "")); flowsheet.UpdateEditorPanels.Invoke(); CreateReactionSetsList(); }); CreateReactionSetsList(); }
void Initialize() { container.CreateAndAddLabelRow("Reaction ID"); container.CreateAndAddStringEditorRow2("Name", "", rx.Name, (sender, e) => { rx.Name = sender.Text; }); container.CreateAndAddLabelRow("Compounds and Stoichiometry (Include / Name / Stoich. Coeff.)"); var compcontainer = new DynamicLayout(); compcontainer.BackgroundColor = Colors.White; Double val; foreach (ICompoundConstantProperties comp in flowsheet.SelectedCompounds.Values) { var chk = new CheckBox() { Text = comp.Name, Checked = (rx.Components.ContainsKey(comp.Name) ? true : false) }; chk.CheckedChanged += (sender, e) => { if (!rx.Components.ContainsKey(comp.Name)) { rx.Components.Add(comp.Name, new DWSIM.Thermodynamics.BaseClasses.ReactionStoichBase(comp.Name, 0, false, 0, 0)); } else { rx.Components.Remove(comp.Name); } UpdateEquation(); }; var sc = new TextBox() { Width = (int)(sf * 50), Text = (rx.Components.ContainsKey(comp.Name) ? rx.Components[comp.Name].StoichCoeff.ToString() : 0.0f.ToString()) }; sc.TextChanged += (sender, e) => { if (Double.TryParse(sc.Text.ToString(), out val)) { sc.TextColor = SystemColors.ControlText; if (!rx.Components.ContainsKey(comp.Name)) { rx.Components.Add(comp.Name, new DWSIM.Thermodynamics.BaseClasses.ReactionStoichBase(comp.Name, Double.Parse(sc.Text), false, 0, 0)); } else { rx.Components[comp.Name].StoichCoeff = double.Parse(sc.Text); } UpdateEquation(); } else { sc.TextColor = Colors.Red; } }; compcontainer.Add(new TableRow(chk, null, sc)); } container.CreateAndAddControlRow(compcontainer); container.CreateAndAddEmptySpace(); var comps = flowsheet.SelectedCompounds.Values.Select((x) => x.Name).ToList(); comps.Insert(0, ""); container.CreateAndAddLabelRow("Base Compound"); var basecompselector = container.CreateAndAddDropDownRow("Base Compound", comps, 0, null); var basecomp = rx.Components.Values.Where((x) => x.IsBaseReactant).FirstOrDefault(); if (basecomp != null) { basecompselector.SelectedIndex = comps.IndexOf(basecomp.CompName); } else { basecompselector.SelectedIndex = 0; } basecompselector.SelectedIndexChanged += (sender, e) => { if (rx.Components.ContainsKey(comps[basecompselector.SelectedIndex])) { foreach (var rxc in rx.Components.Values) { rxc.IsBaseReactant = false; } rx.Components[comps[basecompselector.SelectedIndex]].IsBaseReactant = true; rx.BaseReactant = comps[basecompselector.SelectedIndex]; } }; container.CreateAndAddLabelRow("Reaction Balance"); txtEquation = container.CreateAndAddLabelRow2(""); container.CreateAndAddLabelRow("Reaction Phase"); var rxphaseselector = container.CreateAndAddDropDownRow("Reaction Phase", Shared.StringArrays.reactionphase().ToList(), 0, null); switch (rx.ReactionPhase) { case Interfaces.Enums.PhaseName.Vapor: rxphaseselector.SelectedIndex = (0); break; case Interfaces.Enums.PhaseName.Liquid: rxphaseselector.SelectedIndex = (1); break; case Interfaces.Enums.PhaseName.Mixture: rxphaseselector.SelectedIndex = (2); break; } rxphaseselector.SelectedIndexChanged += (sender, e) => { switch (rxphaseselector.SelectedIndex) { case 0: rx.ReactionPhase = Interfaces.Enums.PhaseName.Vapor; break; case 1: rx.ReactionPhase = Interfaces.Enums.PhaseName.Liquid; break; case 2: rx.ReactionPhase = Interfaces.Enums.PhaseName.Mixture; break; } }; UpdateEquation(); }
void Initialize() { container.CreateAndAddLabelRow("Reaction ID"); container.CreateAndAddStringEditorRow2("Name", "", rx.Name, (sender, e) => { rx.Name = sender.Text; }); container.CreateAndAddLabelRow("Compounds and Stoichiometry (Include / Name / Heat of Formation (kJ/kg) / Stoich. Coeff.)"); var compcontainer = new DynamicLayout(); //compcontainer.BackgroundColor = Colors.White; Double val; foreach (ICompoundConstantProperties comp in flowsheet.SelectedCompounds.Values) { var chk = new CheckBox() { Text = comp.Name, Checked = (rx.Components.ContainsKey(comp.Name) ? true : false) }; chk.CheckedChanged += (sender, e) => { if (!rx.Components.ContainsKey(comp.Name)) { rx.Components.Add(comp.Name, new DWSIM.Thermodynamics.BaseClasses.ReactionStoichBase(comp.Name, 0, false, 0, 0)); } else { rx.Components.Remove(comp.Name); } UpdateEquation(); }; var sc = new TextBox() { Width = (int)(sf * 50), Text = (rx.Components.ContainsKey(comp.Name) ? rx.Components[comp.Name].StoichCoeff.ToString() : 0.0f.ToString()) }; sc.TextChanged += (sender, e) => { if (Double.TryParse(sc.Text.ToString(), out val)) { sc.TextColor = SystemColors.ControlText; if (!rx.Components.ContainsKey(comp.Name)) { rx.Components.Add(comp.Name, new DWSIM.Thermodynamics.BaseClasses.ReactionStoichBase(comp.Name, Double.Parse(sc.Text), false, 0, 0)); } else { rx.Components[comp.Name].StoichCoeff = double.Parse(sc.Text); } UpdateEquation(); } else { sc.TextColor = Colors.Red; } }; var hf = new TextBox() { Enabled = false, Width = (int)(sf * 100), Text = comp.IG_Enthalpy_of_Formation_25C.ToString("N2") }; compcontainer.Add(new TableRow(chk, null, hf, sc)); } container.CreateAndAddControlRow(compcontainer); container.CreateAndAddEmptySpace(); var comps = flowsheet.SelectedCompounds.Values.Select((x) => x.Name).ToList(); comps.Insert(0, ""); container.CreateAndAddLabelRow("Base Compound"); var basecompselector = container.CreateAndAddDropDownRow("Base Compound", comps, 0, null); var basecomp = rx.Components.Values.Where((x) => x.IsBaseReactant).FirstOrDefault(); if (basecomp != null) { basecompselector.SelectedIndex = comps.IndexOf(basecomp.CompName); } else { basecompselector.SelectedIndex = 0; } basecompselector.SelectedIndexChanged += (sender, e) => { if (rx.Components.ContainsKey(comps[basecompselector.SelectedIndex])) { foreach (var rxc in rx.Components.Values) { rxc.IsBaseReactant = false; } rx.Components[comps[basecompselector.SelectedIndex]].IsBaseReactant = true; rx.BaseReactant = comps[basecompselector.SelectedIndex]; } }; container.CreateAndAddLabelRow("Reaction Balance"); txtEquation = container.CreateAndAddLabelRow2(""); container.CreateAndAddLabelRow("Reaction Phase"); var rxphaseselector = container.CreateAndAddDropDownRow("Reaction Phase", Shared.StringArrays.reactionphase().ToList(), 0, null); switch (rx.ReactionPhase) { case Interfaces.Enums.PhaseName.Mixture: rxphaseselector.SelectedIndex = 0; break; case Interfaces.Enums.PhaseName.Vapor: rxphaseselector.SelectedIndex = 1; break; case Interfaces.Enums.PhaseName.Liquid: rxphaseselector.SelectedIndex = 2; break; } rxphaseselector.SelectedIndexChanged += (sender, e) => { switch (rxphaseselector.SelectedIndex) { case 0: rx.ReactionPhase = Interfaces.Enums.PhaseName.Mixture; break; case 1: rx.ReactionPhase = Interfaces.Enums.PhaseName.Vapor; break; case 2: rx.ReactionPhase = Interfaces.Enums.PhaseName.Liquid; break; } }; container.CreateAndAddLabelRow("Reaction Basis"); var rxbasisselector = container.CreateAndAddDropDownRow("Reaction Basis", Shared.StringArrays.reactionbasis().ToList(), 0, null); switch (rx.ReactionBasis) { case Interfaces.Enums.ReactionBasis.Activity: rxbasisselector.SelectedIndex = (0); break; case Interfaces.Enums.ReactionBasis.Fugacity: rxbasisselector.SelectedIndex = (1); break; case Interfaces.Enums.ReactionBasis.MassConc: rxbasisselector.SelectedIndex = (2); break; case Interfaces.Enums.ReactionBasis.MassFrac: rxbasisselector.SelectedIndex = (3); break; case Interfaces.Enums.ReactionBasis.MolarConc: rxbasisselector.SelectedIndex = (4); break; case Interfaces.Enums.ReactionBasis.MolarFrac: rxbasisselector.SelectedIndex = (5); break; case Interfaces.Enums.ReactionBasis.PartialPress: rxbasisselector.SelectedIndex = (6); break; } rxbasisselector.SelectedIndexChanged += (sender, e) => { switch (rxbasisselector.SelectedIndex) { case 0: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.Activity; break; case 1: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.Fugacity; break; case 2: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.MassConc; break; case 3: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.MassFrac; break; case 4: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.MolarConc; break; case 5: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.MolarFrac; break; case 6: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.PartialPress; break; } }; container.CreateAndAddLabelRow("Rate Expressions"); container.CreateAndAddLabelRow2("Reaction Rate Numerator Expression:"); container.CreateAndAddMultilineTextBoxRow(rx.RateEquationNumerator, false, false, (sender, e) => rx.RateEquationNumerator = sender.Text); container.CreateAndAddLabelRow2("Reaction Rate Denominator Expression:"); container.CreateAndAddMultilineTextBoxRow(rx.RateEquationDenominator, false, false, (sender, e) => rx.RateEquationDenominator = sender.Text); container.CreateAndAddDescriptionRow("Reaction Rate (r) = f(T, Ri, Pi) = Numerator / Denominator"); container.CreateAndAddDescriptionRow("Expression Variables: Temperature (T) in K, reactant amounts (R1, R2, ..., Rn) and product amounts (P1, P2, ..., Pn in the selected amount units, Reaction Rate (r) in the selected velocity units."); container.CreateAndAddLabelRow("Units"); var us = new DWSIM.SharedClasses.SystemsOfUnits.Units(); var units = us.GetUnitSet(Interfaces.Enums.UnitOfMeasure.molar_conc); units.AddRange(us.GetUnitSet(Interfaces.Enums.UnitOfMeasure.mass_conc)); units.AddRange(us.GetUnitSet(Interfaces.Enums.UnitOfMeasure.pressure)); units.Insert(0, ""); container.CreateAndAddDropDownRow("Amount Units", units, units.IndexOf(rx.ConcUnit), (sender, e) => rx.ConcUnit = sender.SelectedValue.ToString()); var units2 = us.GetUnitSet(Interfaces.Enums.UnitOfMeasure.reac_rate_heterog); units2.Insert(0, ""); container.CreateAndAddDropDownRow("Velocity Units", units2, units2.IndexOf(rx.VelUnit), (sender, e) => rx.VelUnit = sender.SelectedValue.ToString()); UpdateEquation(); }
void Initialize() { container.CreateAndAddLabelRow("Reaction Set Details"); var txt1 = container.CreateAndAddStringEditorRow2("Name", "", rset.Name, (sender, e) => { rset.Name = sender.Text; }); txt1.Enabled = (rset.ID != "DefaultSet"); var txt2 = container.CreateAndAddStringEditorRow2("Description", "", rset.Description, (sender, e) => { rset.Description = sender.Text; }); txt2.Enabled = (rset.ID != "DefaultSet"); container.CreateAndAddLabelRow("Reaction Active in Set / Reaction Name / Sequence #)"); var compcontainer = new DynamicLayout(); //compcontainer.BackgroundColor = Colors.White; Double val; foreach (IReaction item in flowsheet.Reactions.Values) { var chk = new CheckBox() { Text = item.Name, Checked = (rset.Reactions.ContainsKey(item.ID) ? rset.Reactions[item.ID].IsActive : false) }; chk.CheckedChanged += (sender, e) => { if (!rset.Reactions.ContainsKey(item.ID)) { rset.Reactions.Add(item.ID, new DWSIM.Thermodynamics.BaseClasses.ReactionSetBase(item.ID, 0, chk.Checked.GetValueOrDefault())); } else { rset.Reactions[item.ID].IsActive = chk.Checked.GetValueOrDefault(); } }; var sc = new TextBox() { Width = 50, Text = (rset.Reactions.ContainsKey(item.ID) ? (rset.Reactions[item.ID].Rank.ToString()) : 0.0f.ToString()) }; sc.TextChanged += (sender, e) => { if (Double.TryParse(sc.Text.ToString(), out val)) { sc.TextColor = SystemColors.ControlText; if (!rset.Reactions.ContainsKey(item.ID)) { rset.Reactions.Add(item.ID, new DWSIM.Thermodynamics.BaseClasses.ReactionSetBase(item.ID, int.Parse(sc.Text), true)); } else { rset.Reactions[item.ID].Rank = int.Parse(sc.Text); } } else { sc.TextColor = Colors.Red; } }; compcontainer.Add(new TableRow(chk, null, sc)); } container.CreateAndAddControlRow(compcontainer); container.CreateAndAddEmptySpace(); }
void Initialize() { container.CreateAndAddLabelRow("Reaction ID"); container.CreateAndAddStringEditorRow2("Name", "", rx.Name, (sender, e) => { rx.Name = sender.Text; }); container.CreateAndAddLabelRow("Compounds and Stoichiometry (Include / Name / Heat of Formation (kJ/kg) / Stoich. Coeff.)"); var compcontainer = new DynamicLayout(); //compcontainer.BackgroundColor = Colors.White; Double val; foreach (ICompoundConstantProperties comp in flowsheet.SelectedCompounds.Values) { var chk = new CheckBox() { Text = comp.Name, Checked = (rx.Components.ContainsKey(comp.Name) ? true : false) }; chk.CheckedChanged += (sender, e) => { if (!rx.Components.ContainsKey(comp.Name)) { rx.Components.Add(comp.Name, new DWSIM.Thermodynamics.BaseClasses.ReactionStoichBase(comp.Name, 0, false, 0, 0)); } else { rx.Components.Remove(comp.Name); } UpdateEquation(); }; var sc = new TextBox() { Width = (int)(sf * 50), Text = (rx.Components.ContainsKey(comp.Name) ? rx.Components[comp.Name].StoichCoeff.ToString() : 0.0f.ToString()) }; sc.TextChanged += (sender, e) => { if (Double.TryParse(sc.Text.ToString(), out val)) { sc.TextColor = SystemColors.ControlText; if (!rx.Components.ContainsKey(comp.Name)) { rx.Components.Add(comp.Name, new DWSIM.Thermodynamics.BaseClasses.ReactionStoichBase(comp.Name, Double.Parse(sc.Text), false, 0, 0)); } else { rx.Components[comp.Name].StoichCoeff = double.Parse(sc.Text); } UpdateEquation(); } else { sc.TextColor = Colors.Red; } }; var hf = new TextBox() { Enabled = false, Width = (int)(sf * 100), Text = comp.IG_Enthalpy_of_Formation_25C.ToString("N2") }; compcontainer.Add(new TableRow(chk, null, hf, sc)); } container.CreateAndAddControlRow(compcontainer); container.CreateAndAddEmptySpace(); var comps = flowsheet.SelectedCompounds.Values.Select((x) => x.Name).ToList(); comps.Insert(0, ""); container.CreateAndAddLabelRow("Base Compound"); var basecompselector = container.CreateAndAddDropDownRow("Base Compound", comps, 0, null); var basecomp = rx.Components.Values.Where((x) => x.IsBaseReactant).FirstOrDefault(); if (basecomp != null) { basecompselector.SelectedIndex = comps.IndexOf(basecomp.CompName); } else { basecompselector.SelectedIndex = 0; } basecompselector.SelectedIndexChanged += (sender, e) => { if (rx.Components.ContainsKey(comps[basecompselector.SelectedIndex])) { foreach (var rxc in rx.Components.Values) { rxc.IsBaseReactant = false; } rx.Components[comps[basecompselector.SelectedIndex]].IsBaseReactant = true; rx.BaseReactant = comps[basecompselector.SelectedIndex]; UpdateEquation(); } }; container.CreateAndAddLabelRow("Reaction Balance"); txtEquation = container.CreateAndAddLabelRow2(""); container.CreateAndAddLabelRow("Temperature Limits"); var nf = flowsheet.FlowsheetOptions.NumberFormat; var su = flowsheet.FlowsheetOptions.SelectedUnitSystem; container.CreateAndAddTextBoxRow(nf, "Minimum Temperature (" + su.temperature + ")", rx.Tmin.ConvertFromSI(su.temperature), (sender, e) => { if (sender.Text.IsValidDouble()) { rx.Tmin = sender.Text.ToDoubleFromCurrent().ConvertToSI(su.temperature); } }); container.CreateAndAddTextBoxRow(nf, "Maximum Temperature (" + su.temperature + ")", rx.Tmax.ConvertFromSI(su.temperature), (sender, e) => { if (sender.Text.IsValidDouble()) { rx.Tmax = sender.Text.ToDoubleFromCurrent().ConvertToSI(su.temperature); } }); container.CreateAndAddTextBoxRow(nf, "Approach (" + su.temperature + ")", rx.Approach.ConvertFromSI(su.temperature), (sender, e) => { if (sender.Text.IsValidDouble()) { rx.Approach = sender.Text.ToDoubleFromCurrent().ConvertToSI(su.temperature); } }); container.CreateAndAddLabelRow("Reaction Basis"); var rxbasisselector = container.CreateAndAddDropDownRow("Reaction Basis", Shared.StringArrays.reactionbasis().ToList(), 0, null); switch (rx.ReactionBasis) { case Interfaces.Enums.ReactionBasis.Activity: rxbasisselector.SelectedIndex = (0); break; case Interfaces.Enums.ReactionBasis.Fugacity: rxbasisselector.SelectedIndex = (1); break; case Interfaces.Enums.ReactionBasis.MassConc: rxbasisselector.SelectedIndex = (2); break; case Interfaces.Enums.ReactionBasis.MassFrac: rxbasisselector.SelectedIndex = (3); break; case Interfaces.Enums.ReactionBasis.MolarConc: rxbasisselector.SelectedIndex = (4); break; case Interfaces.Enums.ReactionBasis.MolarFrac: rxbasisselector.SelectedIndex = (5); break; case Interfaces.Enums.ReactionBasis.PartialPress: rxbasisselector.SelectedIndex = (6); break; } rxbasisselector.SelectedIndexChanged += (sender, e) => { switch (rxbasisselector.SelectedIndex) { case 0: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.Activity; break; case 1: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.Fugacity; break; case 2: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.MassConc; break; case 3: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.MassFrac; break; case 4: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.MolarConc; break; case 5: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.MolarFrac; break; case 6: rx.ReactionBasis = Interfaces.Enums.ReactionBasis.PartialPress; break; } }; container.CreateAndAddLabelRow("Reaction Phase"); var rxphaseselector = container.CreateAndAddDropDownRow("Reaction Phase", Shared.StringArrays.reactionphase().ToList(), 0, null); switch (rx.ReactionPhase) { case Interfaces.Enums.PhaseName.Mixture: rxphaseselector.SelectedIndex = (0); break; case Interfaces.Enums.PhaseName.Vapor: rxphaseselector.SelectedIndex = (1); break; case Interfaces.Enums.PhaseName.Liquid: rxphaseselector.SelectedIndex = (2); break; } rxphaseselector.SelectedIndexChanged += (sender, e) => { switch (rxphaseselector.SelectedIndex) { case 0: rx.ReactionPhase = Interfaces.Enums.PhaseName.Mixture; break; case 1: rx.ReactionPhase = Interfaces.Enums.PhaseName.Vapor; break; case 2: rx.ReactionPhase = Interfaces.Enums.PhaseName.Liquid; break; } }; UpdateEquation(); }
public PIDTuningTool(Shared.Flowsheet fs, DynamicsIntegratorControl intcontrol) : base() { Flowsheet = fs; intc = intcontrol; Padding = new Eto.Drawing.Padding(5); Spacing = new Size(5, 5); Padding = new Eto.Drawing.Padding(5); Spacing = new Size(10, 10); var leftcontainer = new DynamicLayout { Width = 300 }; leftcontainer.CreateAndAddLabelRow("Schedule"); var schlist = Flowsheet.DynamicsManager.ScheduleList.Values.ToList(); var cbSchedule = leftcontainer.CreateAndAddDropDownRow("Schedule", schlist.Select((x) => x.Description).ToList(), 0, (dd, e) => schedule = schlist[dd.SelectedIndex]); leftcontainer.CreateAndAddLabelRow("Controllers"); leftcontainer.CreateAndAddDescriptionRow("Select the PID Controllers to tune."); var listb = new CheckBoxList() { Height = 200 }; foreach (var obj in Flowsheet.SimulationObjects.Values.Where((x) => x.ObjectClass == Interfaces.Enums.SimulationObjectClass.Controllers)) { listb.Items.Add(obj.GraphicObject.Tag, obj.Name); } leftcontainer.CreateAndAddControlRow(listb); leftcontainer.CreateAndAddNumericEditorRow("Maximum Iterations", iterations, 5, 100, 0, (ns, e) => { iterations = (int)ns.Value; }); var btnRun = leftcontainer.CreateAndAddButtonRow("Begin Tuning", null, null); var btnCancel = leftcontainer.CreateAndAddButtonRow("Cancel", null, (btn, e) => Abort = true); txtResults = new TextArea { ReadOnly = true, Wrap = true }; Rows.Add(new TableRow(leftcontainer, new Scrollable { Content = txtResults })); btnRun.Click += (s, e) => { Flowsheet.RunCodeOnUIThread(() => { txtResults.Text = ""; if (!Flowsheet.DynamicMode) { txtResults.Text += "Error: Dynamic Mode is not activated. Activate Dynamic Mode and try again."; return; } intc.cbsc.SelectedIndex = cbSchedule.SelectedIndex; var schedule = Flowsheet.DynamicsManager.ScheduleList[Flowsheet.DynamicsManager.CurrentSchedule]; List <OptSimplexBoundVariable> vars = new List <OptSimplexBoundVariable>(); List <PIDController> controllers = new List <PIDController>(); foreach (var item in listb.SelectedKeys) { var controller = (PIDController)Flowsheet.SimulationObjects[item]; controllers.Add(controller); vars.Add(new OptSimplexBoundVariable(controller.Kp, 0.0, controller.Kp * 10)); vars.Add(new OptSimplexBoundVariable(controller.Ki, 0.0, 100.0)); vars.Add(new OptSimplexBoundVariable(controller.Kd, 0.0, 100.0)); } btnRun.Enabled = false; btnCancel.Enabled = true; Simplex simplex = new Simplex(); simplex.MaxFunEvaluations = iterations; Abort = false; int counter = 1; if (schedule.InitialFlowsheetStateID == "" | schedule.UseCurrentStateAsInitial) { txtResults.Text += "The selected schedule must have a valid initial state to start from."; btnRun.Enabled = true; btnCancel.Enabled = false; return; } var result = simplex.ComputeMin(x => { if (Abort) { return(0.0); } Flowsheet.RunCodeOnUIThread(() => { txtResults.Text += (string.Format("Beginning Iteration #{0}...\n", counter)); }); intc.RestoreState(schedule.InitialFlowsheetStateID); var i = 0; foreach (var controller in controllers) { controller.Kp = x[i]; controller.Ki = x[i + 1]; controller.Kd = x[i + 2]; Flowsheet.RunCodeOnUIThread(() => { txtResults.Text += (string.Format("Controller: {0} - Kp = {1}, Ki = {2}, Kd = {3}\n", controller.GraphicObject.Tag, controller.Kp, controller.Ki, controller.Kd)); }); i += 3; } intc.RunIntegrator(false, true); var totalerror = controllers.Select(c => c.CumulativeError).ToArray().AbsSumY(); Flowsheet.RunCodeOnUIThread(() => { txtResults.Text += (string.Format("Total Error: {0}\n", totalerror)); txtResults.CaretIndex = txtResults.Text.Length - 1; }); Application.Instance.RunIteration(); counter += 1; return(totalerror); }, vars.ToArray()); if (Abort) { txtResults.Text += (string.Format("Tuning aborted by the user. Results:\n")); } else { txtResults.Text += (string.Format("Tuning finished successfully. Results:\n")); } var j = 0; foreach (var controller in controllers) { controller.Kp = result[j]; controller.Ki = result[j + 1]; controller.Kd = result[j + 2]; txtResults.Text += (string.Format("Controller: {0} - Kp = {1}, Ki = {2}, Kd = {3}\n", controller.GraphicObject.Tag, controller.Kp, controller.Ki, controller.Kd)); j += 3; } btnRun.Enabled = true; btnCancel.Enabled = false; Flowsheet.UpdateInterface(); }); }; }