Ejemplo n.º 1
0
        public static void Populate(ISimulationObject obj, DynamicLayout container)
        {
            var su = obj.GetFlowsheet().FlowsheetOptions.SelectedUnitSystem;
            var nf = obj.GetFlowsheet().FlowsheetOptions.NumberFormat;

            var recycle = (EnergyRecycle)obj;

            s.CreateAndAddLabelRow(container, "Object Details");

            s.CreateAndAddTwoLabelsRow(container, "Status", obj.GraphicObject.Active ? "Active" : "Inactive");

            s.CreateAndAddStringEditorRow(container, "Name", obj.GraphicObject.Tag, (TextBox arg3, EventArgs ev) =>
            {
                obj.GraphicObject.Tag = arg3.Text;
            });
            container.CreateAndAddTextBoxRow("N0", "Maximum Iterations", recycle.MaximumIterations,
                                             (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    recycle.MaximumIterations = int.Parse(sender.Text);
                }
            });
            container.CreateAndAddLabelRow("Convergence Tolerances");
            container.CreateAndAddTextBoxRow(nf, "Energy Flow", cv.ConvertFromSI(su.heatflow, recycle.ConvergenceParameters.Energy),
                                             (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    recycle.ConvergenceParameters.Energy = cv.ConvertToSI(su.heatflow, sender.Text.ToDoubleFromCurrent());
                }
            });
        }
Ejemplo n.º 2
0
        public static void Populate(ISimulationObject obj, DynamicLayout container)
        {
            var su = obj.GetFlowsheet().FlowsheetOptions.SelectedUnitSystem;
            var nf = obj.GetFlowsheet().FlowsheetOptions.NumberFormat;

            var recycle = (Recycle)obj;

            s.CreateAndAddLabelRow(container, "Object Details");

            s.CreateAndAddTwoLabelsRow(container, "Status", obj.GraphicObject.Active ? "Active" : "Inactive");

            s.CreateAndAddStringEditorRow(container, "Name", obj.GraphicObject.Tag, (TextBox arg3, EventArgs ev) =>
            {
                obj.GraphicObject.Tag = arg3.Text;
            });

            container.CreateAndAddLabelRow("Convergence Control");
            container.CreateAndAddCheckBoxRow("Converge using global solver",
                                              recycle.AccelerationMethod == Interfaces.Enums.AccelMethod.GlobalBroyden,
                                              (sender, e) => { if (sender.Checked.GetValueOrDefault())
                                                               {
                                                                   recycle.AccelerationMethod = Interfaces.Enums.AccelMethod.GlobalBroyden;
                                                               }
                                                               else
                                                               {
                                                                   recycle.AccelerationMethod = Interfaces.Enums.AccelMethod.None;
                                                               } });
            container.CreateAndAddLabelRow("Convergence Tolerances");
            container.CreateAndAddTextBoxRow(nf, "Mass Flow", cv.ConvertFromSI(su.massflow, recycle.ConvergenceParameters.VazaoMassica),
                                             (sender, e) => {
                if (sender.Text.IsValidDouble())
                {
                    recycle.ConvergenceParameters.VazaoMassica = cv.ConvertToSI(su.massflow, sender.Text.ToDoubleFromCurrent());
                }
            });
            container.CreateAndAddTextBoxRow(nf, "Temperature", cv.ConvertFromSI(su.deltaT, recycle.ConvergenceParameters.Temperatura),
                                             (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    recycle.ConvergenceParameters.Temperatura = cv.ConvertToSI(su.deltaT, sender.Text.ToDoubleFromCurrent());
                }
            });
            container.CreateAndAddTextBoxRow(nf, "Pressure", cv.ConvertFromSI(su.deltaP, recycle.ConvergenceParameters.Pressao),
                                             (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    recycle.ConvergenceParameters.Pressao = cv.ConvertToSI(su.deltaP, sender.Text.ToDoubleFromCurrent());
                }
            });
        }
Ejemplo n.º 3
0
        void Initialize()
        {
            var su  = SimObject.GetFlowsheet().FlowsheetOptions.SelectedUnitSystem;
            var nf  = SimObject.GetFlowsheet().FlowsheetOptions.NumberFormat;
            var nff = SimObject.GetFlowsheet().FlowsheetOptions.FractionNumberFormat;

            s.CreateAndAddLabelRow(container, "Dynamic Properties Editor");

            s.CreateAndAddDescriptionRow(container, "Property values are updated/stored as they are changed/edited. There's no need to press ENTER to commit the changes.");

            switch (SimObject.GraphicObject.ObjectType)
            {
            case ObjectType.MaterialStream:
                container.CreateAndAddDropDownRow("Dynamic Specification",
                                                  SimObject.DynamicsSpec.GetEnumNames(), (int)SimObject.DynamicsSpec, (dd, e) => {
                    SimObject.DynamicsSpec = dd.SelectedIndex.ToEnum <Interfaces.Enums.Dynamics.DynamicsSpecType>();
                    SimObject.GetFlowsheet().UpdateInterface();
                });
                break;
            }

            var col1 = (IDictionary <string, object>)SimObject.ExtraProperties;
            var col2 = (IDictionary <string, object>)SimObject.ExtraPropertiesDescriptions;
            var col3 = (IDictionary <string, object>)SimObject.ExtraPropertiesUnitTypes;

            foreach (var p in col1)
            {
                if (col2.ContainsKey(p.Key) && col3.ContainsKey(p.Key))
                {
                    string unitsstring = "";
                    try
                    {
                        var utype = col3[p.Key];
                        Interfaces.Enums.UnitOfMeasure eval = (Interfaces.Enums.UnitOfMeasure)System.Enum.ToObject(typeof(Interfaces.Enums.UnitOfMeasure), utype);
                        unitsstring = su.GetCurrentUnits(eval);
                    }
                    catch { }
                    container.CreateAndAddTextBoxRow("G", unitsstring != "" ? p.Key + " (" + unitsstring + ")" : p.Key,
                                                     p.Value.ToString().ToDoubleFromCurrent(),
                                                     (tb, e) => {
                        try
                        {
                            col1[p.Key]  = tb.Text.ToDoubleFromCurrent();
                            tb.TextColor = Colors.Blue;
                        }
                        catch
                        {
                            tb.TextColor = Colors.Red;
                        }
                    });
                    container.CreateAndAddDescriptionRow(col2[p.Key].ToString());
                    container.CreateAndAddEmptySpace();
                }
            }

            s.CreateAndAddEmptySpace(container);
            s.CreateAndAddEmptySpace(container);
        }
Ejemplo n.º 4
0
        void Initialize()
        {
            double dummy = 0.0f;

            var su = flowsheet.FlowsheetOptions.SelectedUnitSystem;
            var nf = flowsheet.FlowsheetOptions.NumberFormat;

            if (section.TipoSegmento == "Tubulaosimples")
            {
                section.TipoSegmento = "Straight Tube Section";
            }

            var lblseg = container.CreateAndAddTwoLabelsRow("Segment", section.Indice.ToString());

            var spinnerType = container.CreateAndAddDropDownRow("Type", sectypes, Array.IndexOf(sectypes.ToArray(), section.TipoSegmento), (sender, e) => section.TipoSegmento = sectypes[sender.SelectedIndex]);
            var spinnerMat  = container.CreateAndAddDropDownRow("Material", materials, Array.IndexOf(materials.ToArray(), section.Material), (sender, e) => section.Material = materials[sender.SelectedIndex]);

            var txtIncrements = container.CreateAndAddTextBoxRow("N0", "Increments", section.Incrementos, (sender, e) => { if (double.TryParse(sender.Text.ToString(), out dummy))
                                                                                                                           {
                                                                                                                               section.Incrementos = int.Parse(sender.Text.ToString());
                                                                                                                           }
                                                                 });
            var txtLength = container.CreateAndAddTextBoxRow(nf, "Length" + " (" + su.distance + ")", cv.ConvertFromSI(su.distance, section.Comprimento), (sender, e) => { if (double.TryParse(sender.Text.ToString(), out dummy))
                                                                                                                                                                           {
                                                                                                                                                                               section.Comprimento = cv.ConvertToSI(su.distance, double.Parse(sender.Text.ToString()));
                                                                                                                                                                           }
                                                             });
            var txtElevation = container.CreateAndAddTextBoxRow(nf, "Elevation" + " (" + su.distance + ")", cv.ConvertFromSI(su.distance, section.Elevacao), (sender, e) => { if (double.TryParse(sender.Text.ToString(), out dummy))
                                                                                                                                                                              {
                                                                                                                                                                                  section.Elevacao = cv.ConvertToSI(su.distance, double.Parse(sender.Text.ToString()));
                                                                                                                                                                              }
                                                                });
            var txtED = container.CreateAndAddTextBoxRow(nf, "External Diameter" + " (" + su.diameter + ")", cv.Convert("in", su.diameter, section.DE), (sender, e) => { if (double.TryParse(sender.Text.ToString(), out dummy))
                                                                                                                                                                         {
                                                                                                                                                                             section.DE = cv.Convert(su.diameter, "in", double.Parse(sender.Text.ToString()));
                                                                                                                                                                         }
                                                         });
            var txtID = container.CreateAndAddTextBoxRow(nf, "Internal Diameter" + " (" + su.diameter + ")", cv.Convert("in", su.diameter, section.DI), (sender, e) => { if (double.TryParse(sender.Text.ToString(), out dummy))
                                                                                                                                                                         {
                                                                                                                                                                             section.DI = cv.Convert(su.diameter, "in", double.Parse(sender.Text.ToString()));
                                                                                                                                                                         }
                                                         });
        }
Ejemplo n.º 5
0
        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 = (int)(sf * 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 = (int)(sf * 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 = (int)(sf * 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");

            var nf = flowsheet.FlowsheetOptions.NumberFormat;
            var su = flowsheet.FlowsheetOptions.SelectedUnitSystem;

            container.CreateAndAddTextBoxRow(nf, "Minimum 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", rx.Tmax.ConvertFromSI(su.temperature), (sender, e) => { if (sender.Text.IsValidDouble())
                                                                                                                                {
                                                                                                                                    rx.Tmax = sender.Text.ToDoubleFromCurrent().ConvertToSI(su.temperature);
                                                                                                                                }
                                             });

            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());

            var units2 = us.GetUnitSet(Interfaces.Enums.UnitOfMeasure.reac_rate);

            units2.Insert(0, "");

            container.CreateAndAddDropDownRow("Velocity Units", units2, units2.IndexOf(rx.VelUnit), (sender, e) => rx.VelUnit = sender.SelectedValue.ToString());

            UpdateEquation();
        }
Ejemplo n.º 6
0
        void Initialize()
        {
            var su = flowsheet.FlowsheetOptions.SelectedUnitSystem;
            var nf = flowsheet.FlowsheetOptions.NumberFormat;

            if (section.TipoSegmento == "Tubulaosimples")
            {
                section.TipoSegmento = "Straight Tube Section";
            }

            var lblseg = container.CreateAndAddTwoLabelsRow("Segment", section.Indice.ToString());

            container.CreateAndAddDropDownRow("Type", sectypes, Array.IndexOf(sectypes.ToArray(), section.TipoSegmento), (sender, e) => section.TipoSegmento = sectypes[sender.SelectedIndex]);
            var cbm = container.CreateAndAddDropDownRow("Material", materials, Array.IndexOf(materials.ToArray(), section.Material), (sender, e) => section.Material = materials[sender.SelectedIndex]);
            var tbr = container.CreateAndAddTextBoxRow("G8", "Rugosity " + " (" + su.distance + ") *", cv.ConvertFromSI(su.distance, section.PipeWallRugosity), (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                                                                                                 {
                                                                                                                                                                                     section.PipeWallRugosity = cv.ConvertToSI(su.distance, sender.Text.ParseExpressionToDouble());
                                                                                                                                                                                 }
                                                       });
            var tbtc = container.CreateAndAddStringEditorRow("Thermal Conductivity " + " (" + su.thermalConductivity + ") *", section.PipeWallThermalConductivityExpression, (sender, e) => { section.PipeWallThermalConductivityExpression = sender.Text.ToString(); });

            container.CreateAndAddTextBoxRow("N0", "Increments", section.Incrementos, (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                       {
                                                                                                           section.Incrementos = int.Parse(sender.Text.ToString());
                                                                                                       }
                                             });
            container.CreateAndAddTextBoxRow("N0", "Quantity", section.Quantidade, (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                    {
                                                                                                        section.Quantidade = int.Parse(sender.Text.ToString());
                                                                                                    }
                                             });
            container.CreateAndAddTextBoxRow(nf, "Length" + " (" + su.distance + ")", cv.ConvertFromSI(su.distance, section.Comprimento), (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                                                                           {
                                                                                                                                                               section.Comprimento = cv.ConvertToSI(su.distance, sender.Text.ParseExpressionToDouble());
                                                                                                                                                           }
                                             });
            container.CreateAndAddTextBoxRow(nf, "Elevation" + " (" + su.distance + ")", cv.ConvertFromSI(su.distance, section.Elevacao), (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                                                                           {
                                                                                                                                                               section.Elevacao = cv.ConvertToSI(su.distance, sender.Text.ParseExpressionToDouble());
                                                                                                                                                           }
                                             });
            container.CreateAndAddTextBoxRow(nf, "External Diameter" + " (" + su.diameter + ")", cv.Convert("in", su.diameter, section.DE), (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                                                                             {
                                                                                                                                                                 section.DE = cv.Convert(su.diameter, "in", sender.Text.ParseExpressionToDouble());
                                                                                                                                                             }
                                             });
            container.CreateAndAddTextBoxRow(nf, "Internal Diameter" + " (" + su.diameter + ")", cv.Convert("in", su.diameter, section.DI), (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                                                                             {
                                                                                                                                                                 section.DI = cv.Convert(su.diameter, "in", sender.Text.ParseExpressionToDouble());
                                                                                                                                                             }
                                             });
            container.CreateAndAddDescriptionRow("* Fields required/used only for User-Defined materials");
            tbr.ReadOnly  = section.Material != flowsheet.GetTranslatedString("UserDefined");
            tbtc.ReadOnly = tbr.ReadOnly;
            if (tbr.ReadOnly)
            {
                tbr.BackgroundColor  = Eto.Drawing.Colors.LightGrey;
                tbtc.BackgroundColor = Eto.Drawing.Colors.LightGrey;
            }
            else
            {
                tbr.BackgroundColor  = Eto.Drawing.SystemColors.ControlBackground;
                tbtc.BackgroundColor = Eto.Drawing.SystemColors.ControlBackground;
            }
            cbm.SelectedValueChanged += (sender, e) =>
            {
                if (cbm.SelectedValue.ToString() == flowsheet.GetTranslatedString("UserDefined"))
                {
                    tbr.ReadOnly         = false;
                    tbtc.ReadOnly        = false;
                    tbr.BackgroundColor  = Eto.Drawing.SystemColors.ControlBackground;
                    tbtc.BackgroundColor = Eto.Drawing.SystemColors.ControlBackground;
                    tbr.Text             = section.PipeWallRugosity.ConvertFromSI(su.distance).ToString(nf);
                    tbtc.Text            = section.PipeWallThermalConductivityExpression;
                    tbtc.TextAlignment   = TextAlignment.Left;
                }
                else
                {
                    tbr.ReadOnly         = true;
                    tbtc.ReadOnly        = true;
                    tbr.BackgroundColor  = Eto.Drawing.Colors.LightGrey;
                    tbtc.BackgroundColor = Eto.Drawing.Colors.LightGrey;
                    tbr.Text             = pipe.rugosidade(cbm.SelectedValue.ToString(), section).ConvertFromSI(su.distance).ToString(nf);
                    if (pipe.GraphicObject.InputConnectors[0].IsAttached)
                    {
                        var stream = (MaterialStream)flowsheet.SimulationObjects[pipe.GraphicObject.InputConnectors[0].AttachedConnector.AttachedFrom.Name];
                        tbtc.Text = pipe.k_parede(cbm.SelectedValue.ToString(), stream.GetTemperature(), section).ConvertFromSI(su.thermalConductivity).ToString(nf);
                    }
                    else
                    {
                        tbtc.Text = pipe.k_parede(cbm.SelectedValue.ToString(), 298.15, section).ConvertFromSI(su.thermalConductivity).ToString(nf);
                    }
                    tbtc.TextAlignment = TextAlignment.Right;
                }
            };
        }
Ejemplo n.º 7
0
        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("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.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();
        }
Ejemplo n.º 8
0
        void Initialize()
        {
            var su = flowsheet.FlowsheetOptions.SelectedUnitSystem;
            var nf = flowsheet.FlowsheetOptions.NumberFormat;

            if (section.TipoSegmento == "Tubulaosimples")
            {
                section.TipoSegmento = "Straight Tube Section";
            }

            var lblseg = container.CreateAndAddTwoLabelsRow("Segment", section.Indice.ToString());

            container.CreateAndAddDropDownRow("Type", sectypes, Array.IndexOf(sectypes.ToArray(), section.TipoSegmento), (sender, e) => section.TipoSegmento = sectypes[sender.SelectedIndex]);
            var cbm = container.CreateAndAddDropDownRow("Material", materials, Array.IndexOf(materials.ToArray(), section.Material), (sender, e) => section.Material = materials[sender.SelectedIndex]);
            var tbr = container.CreateAndAddTextBoxRow("G8", "Rugosity " + " (" + su.distance + ") *", cv.ConvertFromSI(su.distance, section.PipeWallRugosity), (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                                                                                                 {
                                                                                                                                                                                     section.PipeWallRugosity = cv.ConvertToSI(su.distance, sender.Text.ParseExpressionToDouble());
                                                                                                                                                                                 }
                                                       });
            var tbtc = container.CreateAndAddStringEditorRow("Thermal Conductivity " + " (" + su.thermalConductivity + ") *", section.PipeWallThermalConductivityExpression, (sender, e) => { section.PipeWallThermalConductivityExpression = sender.Text.ToString(); });

            container.CreateAndAddDescriptionRow("* Fields required/used only for User-Defined materials");
            container.CreateAndAddTextBoxRow("N0", "Increments", section.Incrementos, (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                       {
                                                                                                           section.Incrementos = int.Parse(sender.Text.ToString());
                                                                                                       }
                                             });
            container.CreateAndAddTextBoxRow("N0", "Quantity", section.Quantidade, (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                    {
                                                                                                        section.Quantidade = int.Parse(sender.Text.ToString());
                                                                                                    }
                                             });
            container.CreateAndAddTextBoxRow(nf, "Length" + " (" + su.distance + ")", cv.ConvertFromSI(su.distance, section.Comprimento), (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                                                                           {
                                                                                                                                                               section.Comprimento = cv.ConvertToSI(su.distance, sender.Text.ParseExpressionToDouble());
                                                                                                                                                           }
                                             });
            container.CreateAndAddTextBoxRow(nf, "Elevation" + " (" + su.distance + ")", cv.ConvertFromSI(su.distance, section.Elevacao), (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                                                                           {
                                                                                                                                                               section.Elevacao = cv.ConvertToSI(su.distance, sender.Text.ParseExpressionToDouble());
                                                                                                                                                           }
                                             });
            var edtb = container.CreateAndAddTextBoxRow(nf, "External Diameter" + " (" + su.diameter + ")", cv.Convert("in", su.diameter, section.DE), (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                                                                                        {
                                                                                                                                                                            section.DE = cv.Convert(su.diameter, "in", sender.Text.ParseExpressionToDouble());
                                                                                                                                                                        }
                                                        });
            var idtb = container.CreateAndAddTextBoxRow(nf, "Internal Diameter" + " (" + su.diameter + ")", cv.Convert("in", su.diameter, section.DI), (sender, e) => { if (sender.Text.IsValidDoubleExpression())
                                                                                                                                                                        {
                                                                                                                                                                            section.DI = cv.Convert(su.diameter, "in", sender.Text.ParseExpressionToDouble());
                                                                                                                                                                        }
                                                        });

            var ssizes = Pipe.GetStandardPipeSizes();

            var cmenussizes = new ContextMenu();

            foreach (var key in ssizes.Keys)
            {
                var mi = new ButtonMenuItem {
                    Text = key
                };
                foreach (var item in ssizes[key])
                {
                    var mi2 = new ButtonMenuItem
                    {
                        Text = item.StandardSizeDescription + " (OD = " +
                               item.ExternalDiameter_Inches + " in., ID = " +
                               item.InternalDiameter_Inches + " in.)"
                    };
                    mi2.Click += (s, e) =>
                    {
                        flowsheet.RunCodeOnUIThread(() =>
                        {
                            edtb.Text = item.ExternalDiameter_Inches.ConvertUnits("in", su.diameter).ToString(nf);
                            idtb.Text = item.InternalDiameter_Inches.ConvertUnits("in", su.diameter).ToString(nf);
                        });
                    };
                    mi.Items.Add(mi2);
                }
                cmenussizes.Items.Add(mi);
            }

            container.CreateAndAddButtonRow("Standard Pipe Sizes...", null, (btn, ev) =>
            {
                cmenussizes.Show(btn);
            });

            tbr.ReadOnly  = section.Material != flowsheet.GetTranslatedString("UserDefined");
            tbtc.ReadOnly = tbr.ReadOnly;
            if (tbr.ReadOnly)
            {
                tbr.BackgroundColor  = Eto.Drawing.Colors.LightGrey;
                tbtc.BackgroundColor = Eto.Drawing.Colors.LightGrey;
            }
            else
            {
                tbr.BackgroundColor  = Eto.Drawing.SystemColors.ControlBackground;
                tbtc.BackgroundColor = Eto.Drawing.SystemColors.ControlBackground;
            }
            cbm.SelectedValueChanged += (sender, e) =>
            {
                if (cbm.SelectedValue.ToString() == flowsheet.GetTranslatedString("UserDefined"))
                {
                    tbr.ReadOnly         = false;
                    tbtc.ReadOnly        = false;
                    tbr.BackgroundColor  = Eto.Drawing.SystemColors.ControlBackground;
                    tbtc.BackgroundColor = Eto.Drawing.SystemColors.ControlBackground;
                    tbr.Text             = section.PipeWallRugosity.ConvertFromSI(su.distance).ToString(nf);
                    tbtc.Text            = section.PipeWallThermalConductivityExpression;
                    tbtc.TextAlignment   = TextAlignment.Left;
                }
                else
                {
                    tbr.ReadOnly         = true;
                    tbtc.ReadOnly        = true;
                    tbr.BackgroundColor  = Eto.Drawing.Colors.LightGrey;
                    tbtc.BackgroundColor = Eto.Drawing.Colors.LightGrey;
                    tbr.Text             = pipe.GetRugosity(cbm.SelectedValue.ToString(), section).ConvertFromSI(su.distance).ToString(nf);
                    if (pipe.GraphicObject != null && pipe.GraphicObject.InputConnectors[0].IsAttached)
                    {
                        var stream = (MaterialStream)flowsheet.SimulationObjects[pipe.GraphicObject.InputConnectors[0].AttachedConnector.AttachedFrom.Name];
                        tbtc.Text = pipe.k_parede(cbm.SelectedValue.ToString(), stream.GetTemperature(), section).ConvertFromSI(su.thermalConductivity).ToString(nf);
                    }
                    else
                    {
                        tbtc.Text = pipe.k_parede(cbm.SelectedValue.ToString(), 298.15, section).ConvertFromSI(su.thermalConductivity).ToString(nf);
                    }
                    tbtc.TextAlignment = TextAlignment.Right;
                }
            };
        }