Esempio n. 1
0
        public DataTable Render()
        {
            _streamTableData = new DataTable();

            if (Streams.Count == 0)
            {
                return(_streamTableData);
            }


            // _streamTableData.Columns.Add("Number", typeof(Int32));
            _streamTableData.Columns.Add("Property");
            _streamTableData.Columns.Add("Unit");

            var system = Streams.First().System;

            foreach (var stream in Streams.Distinct())
            {
                var col = _streamTableData.Columns.Add(stream.Name);
            }

            List <string> properties = new List <string> {
                "Temperature", "Pressure", "Enthalpy", "Vapour Fraction"
            };
            //List<string> properties = new List<string> { "Name", "From Unit", "From Port", "To Unit", "To Port", "", "Temperature", "Pressure", "Enthalpy", "Vapour Fraction" };
            List <string> propertyUnits = new List <string> {
                system.VariableFactory.Output.UnitDictionary[UnitsOfMeasure.PhysicalDimension.Temperature].Symbol,
                system.VariableFactory.Output.UnitDictionary[UnitsOfMeasure.PhysicalDimension.Pressure].Symbol,
                system.VariableFactory.Output.UnitDictionary[UnitsOfMeasure.PhysicalDimension.SpecificMolarEnthalpy].Symbol, ""
            };

            int     i = 0;
            DataRow workRow;

            for (i = 0; i < properties.Count; i++)
            {
                workRow = _streamTableData.NewRow();

                //workRow["Number"] = i;
                workRow["Property"] = properties[i];
                workRow["Unit"]     = propertyUnits[i];

                foreach (var stream in Streams)
                {
                    workRow[stream.Name] = GetStreamProperty(properties[i], stream);
                }
                _streamTableData.Rows.Add(workRow);
            }

            workRow = _streamTableData.NewRow();
            // workRow["Number"] = i++;
            workRow["Property"] = "Phase";
            workRow["Unit"]     = "";
            foreach (var stream in Streams)
            {
                workRow[stream.Name] = stream.State;
            }
            _streamTableData.Rows.Add(workRow);

            workRow = _streamTableData.NewRow();
            // workRow["Number"] = i++;
            _streamTableData.Rows.Add(workRow);

            var components = system.Components;

            // Molar flows
            if (PrintMolarVariables)
            {
                workRow = _streamTableData.NewRow();
                //   workRow["Number"] = i++;
                workRow["Property"] = "Total Molar Flow";
                workRow["Unit"]     = system.VariableFactory.Output.UnitDictionary[UnitsOfMeasure.PhysicalDimension.MolarFlow].Symbol;
                foreach (var stream in Streams)
                {
                    workRow[stream.Name] = stream.Mixed.TotalMolarflow.ValueInOutputUnit.ToString("0.000");
                }
                _streamTableData.Rows.Add(workRow);

                workRow = _streamTableData.NewRow();
                // workRow["Number"] = i++;
                workRow["Property"] = "";// "Component Molar Flows";
                _streamTableData.Rows.Add(workRow);


                for (int j = 0; j < components.Count; j++)
                {
                    workRow = _streamTableData.NewRow();
                    //   workRow["Number"] = i++;
                    workRow["Property"] = "ṅ [" + components[j].ID + "]";
                    workRow["Unit"]     = system.VariableFactory.Output.UnitDictionary[UnitsOfMeasure.PhysicalDimension.MolarFlow].Symbol;
                    foreach (var stream in Streams)
                    {
                        var value = stream.Mixed.ComponentMolarflow[j].ValueInOutputUnit;
                        if (value > 1e-8)
                        {
                            workRow[stream.Name] = value.ToString("0.000");
                        }
                        else
                        {
                            workRow[stream.Name] = null;
                        }
                    }
                    _streamTableData.Rows.Add(workRow);
                }

                //Molar fractions
                workRow = _streamTableData.NewRow();
                //  workRow["Number"] = i++;
                workRow["Property"] = "";// "Component Molar Fractions";
                _streamTableData.Rows.Add(workRow);


                for (int j = 0; j < components.Count; j++)
                {
                    workRow = _streamTableData.NewRow();
                    //    workRow["Number"] = i++;
                    workRow["Property"] = "x [" + components[j].ID + "]";
                    workRow["Unit"]     = "mol/mol";
                    foreach (var stream in Streams)
                    {
                        // workRow[stream.Name] = stream.Mixed.ComponentMolarFraction[j].ValueInSI.ToString("0.0000");

                        var value = stream.Mixed.ComponentMolarFraction[j].ValueInSI;
                        if (value > 1e-8)
                        {
                            workRow[stream.Name] = value.ToString("0.000");
                        }
                        else
                        {
                            workRow[stream.Name] = null;
                        }
                    }
                    _streamTableData.Rows.Add(workRow);
                }

                workRow = _streamTableData.NewRow();
                //  workRow["Number"] = i++;
                _streamTableData.Rows.Add(workRow);
            }



            // Mass flows
            workRow = _streamTableData.NewRow();
            // workRow["Number"] = i++;
            workRow["Property"] = "Total Mass Flow";
            workRow["Unit"]     = system.VariableFactory.Output.UnitDictionary[UnitsOfMeasure.PhysicalDimension.MassFlow].Symbol;
            foreach (var stream in Streams)
            {
                workRow[stream.Name] = stream.Mixed.TotalMassflow.ValueInOutputUnit.ToString("0.000");
            }
            _streamTableData.Rows.Add(workRow);

            workRow = _streamTableData.NewRow();
            //  workRow["Number"] = i++;
            workRow["Property"] = "";//"Component Mass Flows";
            _streamTableData.Rows.Add(workRow);

            for (int j = 0; j < components.Count; j++)
            {
                var sumForCompJ = Streams.Sum(s => s.Mixed.ComponentMassflow[j].ValueInOutputUnit);

                if (sumForCompJ > 1e-6 || !RemoveMissingComponents)
                {
                    workRow = _streamTableData.NewRow();
                    //       workRow["Number"] = i++;
                    workRow["Property"] = "" + components[j].ID + "";
                    workRow["Unit"]     = system.VariableFactory.Output.UnitDictionary[UnitsOfMeasure.PhysicalDimension.MassFlow].Symbol;
                    foreach (var stream in Streams)
                    {
                        // workRow[stream.Name] = stream.Mixed.ComponentMassflow[j].ValueInOutputUnit.ToString("0.000");

                        var value = stream.Mixed.ComponentMassflow[j].ValueInOutputUnit;
                        if (value > 1e-8)
                        {
                            workRow[stream.Name] = value.ToString("0.000");
                        }
                        else
                        {
                            workRow[stream.Name] = null;
                        }
                    }
                    _streamTableData.Rows.Add(workRow);
                }
            }

            //Mass fractions
            workRow = _streamTableData.NewRow();
            //   workRow["Number"] = i++;
            workRow["Property"] = "";//"Component Mass Fractions";
            _streamTableData.Rows.Add(workRow);
            for (int j = 0; j < components.Count; j++)
            {
                var sumForCompJ = Streams.Sum(s => s.Mixed.ComponentMassFraction[j].ValueInSI);

                if (sumForCompJ > 1e-6 || !RemoveMissingComponents)
                {
                    workRow = _streamTableData.NewRow();
                    //          workRow["Number"] = i++;
                    workRow["Property"] = "" + components[j].ID + "";
                    workRow["Unit"]     = "w-%";
                    foreach (var stream in Streams)
                    {
                        //workRow[stream.Name] = stream.Mixed.ComponentMassFraction[j].ValueInSI.ToString("P2");

                        var value = stream.Mixed.ComponentMassFraction[j].ValueInSI;
                        if (value > 1e-8)
                        {
                            workRow[stream.Name] = value.ToString("0.000");
                        }
                        else
                        {
                            workRow[stream.Name] = null;
                        }
                    }
                    _streamTableData.Rows.Add(workRow);
                }
            }
            return(_streamTableData);
        }