コード例 #1
0
ファイル: PRWS.cs プロジェクト: up2038292/dwsim6
        private void ReadParameters()
        {
            char pathsep = System.IO.Path.DirectorySeparatorChar;

            NRTL_IPData[] nrtlipc = null;
            FileHelperEngine <NRTL_IPData> fh1 = new FileHelperEngine <NRTL_IPData>();

            using (System.IO.Stream filestr = System.Reflection.Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("DWSIM.Thermodynamics.AdvancedEOS.Data.nrtl.dat"))
            {
                using (System.IO.StreamReader t = new System.IO.StreamReader(filestr))
                {
                    nrtlipc = fh1.ReadStream(t);
                }
            }

            ChemSepHelper.ChemSepIDConverter csdb = new ChemSepHelper.ChemSepIDConverter();

            //load ChemSep database interactions
            foreach (NRTL_IPData nrtlip in nrtlipc)
            {
                if (this.InteractionParametersNRTL.ContainsKey(csdb.GetDWSIMName(nrtlip.ID1.ToString()).ToString()))
                {
                    if (!this.InteractionParametersNRTL[csdb.GetDWSIMName(nrtlip.ID1.ToString()).ToString()].ContainsKey(csdb.GetDWSIMName(nrtlip.ID2.ToString()).ToString()))
                    {
                        this.InteractionParametersNRTL[csdb.GetDWSIMName(nrtlip.ID1.ToString()).ToString()].Add(csdb.GetDWSIMName(nrtlip.ID2.ToString()).ToString(), (NRTL_IPData)nrtlip.Clone());
                    }
                    if (!this.InteractionParametersNRTL[csdb.GetDWSIMName(nrtlip.ID1.ToString()).ToString()].ContainsKey(csdb.GetCSName(nrtlip.ID2.ToString()).ToString()))
                    {
                        this.InteractionParametersNRTL[csdb.GetDWSIMName(nrtlip.ID1.ToString()).ToString()].Add(csdb.GetCSName(nrtlip.ID2.ToString()).ToString(), (NRTL_IPData)nrtlip.Clone());
                    }
                }
                else
                {
                    this.InteractionParametersNRTL.Add(csdb.GetDWSIMName(nrtlip.ID1.ToString()).ToString(), new Dictionary <string, NRTL_IPData>());
                    this.InteractionParametersNRTL[csdb.GetDWSIMName(nrtlip.ID1.ToString()).ToString()].Add(csdb.GetDWSIMName(nrtlip.ID2.ToString()).ToString(), (NRTL_IPData)nrtlip.Clone());
                    if (!this.InteractionParametersNRTL[csdb.GetDWSIMName(nrtlip.ID1.ToString()).ToString()].ContainsKey(csdb.GetCSName(nrtlip.ID2.ToString()).ToString()))
                    {
                        this.InteractionParametersNRTL[csdb.GetDWSIMName(nrtlip.ID1.ToString()).ToString()].Add(csdb.GetCSName(nrtlip.ID2.ToString()).ToString(), (NRTL_IPData)nrtlip.Clone());
                    }
                }
            }

            foreach (NRTL_IPData nrtlip in nrtlipc)
            {
                if (this.InteractionParametersNRTL.ContainsKey(csdb.GetCSName(nrtlip.ID1.ToString()).ToString()))
                {
                    if (!this.InteractionParametersNRTL[csdb.GetCSName(nrtlip.ID1.ToString()).ToString()].ContainsKey(csdb.GetCSName(nrtlip.ID2.ToString()).ToString()))
                    {
                        this.InteractionParametersNRTL[csdb.GetCSName(nrtlip.ID1.ToString()).ToString()].Add(csdb.GetCSName(nrtlip.ID2.ToString()).ToString(), (NRTL_IPData)nrtlip.Clone());
                    }
                    if (!this.InteractionParametersNRTL[csdb.GetCSName(nrtlip.ID1.ToString()).ToString()].ContainsKey(csdb.GetDWSIMName(nrtlip.ID2.ToString()).ToString()))
                    {
                        this.InteractionParametersNRTL[csdb.GetCSName(nrtlip.ID1.ToString()).ToString()].Add(csdb.GetDWSIMName(nrtlip.ID2.ToString()).ToString(), (NRTL_IPData)nrtlip.Clone());
                    }
                }
                else
                {
                    this.InteractionParametersNRTL.Add(csdb.GetCSName(nrtlip.ID1.ToString()).ToString(), new Dictionary <string, NRTL_IPData>());
                    this.InteractionParametersNRTL[csdb.GetCSName(nrtlip.ID1.ToString()).ToString()].Add(csdb.GetCSName(nrtlip.ID2.ToString()).ToString(), (NRTL_IPData)nrtlip.Clone());
                    if (!this.InteractionParametersNRTL[csdb.GetCSName(nrtlip.ID1.ToString()).ToString()].ContainsKey(csdb.GetDWSIMName(nrtlip.ID2.ToString()).ToString()))
                    {
                        this.InteractionParametersNRTL[csdb.GetCSName(nrtlip.ID1.ToString()).ToString()].Add(csdb.GetDWSIMName(nrtlip.ID2.ToString()).ToString(), (NRTL_IPData)nrtlip.Clone());
                    }
                }
            }

            System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.InvariantCulture;

            //load user database interactions
            if ((GlobalSettings.Settings.UserInteractionsDatabases != null))
            {
                foreach (string IPDBPath in GlobalSettings.Settings.UserInteractionsDatabases)
                {
                    BaseClasses.InteractionParameter[] Interactions = null;
                    try
                    {
                        Interactions = Databases.UserIPDB.ReadInteractions(IPDBPath, "NRTL");
                        foreach (BaseClasses.InteractionParameter IP in Interactions)
                        {
                            NRTL_IPData IPD = new NRTL_IPData();
                            IPD.A12     = Convert.ToDouble(IP.Parameters["A12"], ci);
                            IPD.A21     = Convert.ToDouble(IP.Parameters["A21"], ci);
                            IPD.alpha12 = Convert.ToDouble(IP.Parameters["alpha12"], ci);
                            IPD.comment = IP.Description;

                            if (this.InteractionParameters.ContainsKey(IP.Comp1))
                            {
                                if (this.InteractionParametersNRTL[IP.Comp1].ContainsKey(IP.Comp2))
                                {
                                }
                                else
                                {
                                    this.InteractionParametersNRTL[IP.Comp1].Add(IP.Comp2, (NRTL_IPData)IPD.Clone());
                                }
                            }
                            else
                            {
                                this.InteractionParametersNRTL.Add(IP.Comp1, new Dictionary <string, NRTL_IPData>());
                                this.InteractionParametersNRTL[IP.Comp1].Add(IP.Comp2, (NRTL_IPData)IPD.Clone());
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }


            nrtlipc = null;
            fh1     = null;

            PR_IPData[] pripc = null;
            FileHelperEngine <PR_IPData> fh2 = new FileHelperEngine <PR_IPData>();

            using (System.IO.Stream filestr = System.Reflection.Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("DWSIM.Thermodynamics.AdvancedEOS.Data.pr_ip.dat"))
            {
                using (System.IO.StreamReader t = new System.IO.StreamReader(filestr))
                {
                    pripc = fh2.ReadStream(t);
                }
            }

            foreach (PR_IPData prip in pripc)
            {
                var c1 = csdb.GetCSName(prip.ID1.ToString()).ToString();
                var c2 = csdb.GetCSName(prip.ID2.ToString()).ToString();
                if (this.InteractionParameters.ContainsKey(c1))
                {
                    if (this.InteractionParameters[c1].ContainsKey(c2))
                    {
                    }
                    else
                    {
                        this.InteractionParameters[c1].Add(c2, new PHSC_IP()
                        {
                            Compound1 = c1, Compound2 = c2, kij = prip.kij
                        });
                    }
                }
                else
                {
                    this.InteractionParameters.Add(c1, new Dictionary <string, PHSC_IP>());
                    this.InteractionParameters[c1].Add(c2, new PHSC_IP()
                    {
                        Compound1 = c1, Compound2 = c2, kij = prip.kij
                    });
                }
            }
            foreach (PR_IPData prip in pripc)
            {
                var c1 = csdb.GetCSName(prip.ID1.ToString()).ToString();
                var c2 = csdb.GetCSName(prip.ID2.ToString()).ToString();
                if (this.InteractionParameters.ContainsKey(c1))
                {
                    if (this.InteractionParameters[c1].ContainsKey(c2))
                    {
                    }
                    else
                    {
                        this.InteractionParameters[c1].Add(c2, new PHSC_IP()
                        {
                            Compound1 = c1, Compound2 = c2, kij = prip.kij
                        });
                    }
                }
                else
                {
                    this.InteractionParameters.Add(c1, new Dictionary <string, PHSC_IP>());
                    this.InteractionParameters[c1].Add(c2, new PHSC_IP()
                    {
                        Compound1 = c1, Compound2 = c2, kij = prip.kij
                    });
                }
            }
            pripc = null;
            fh2   = null;
        }
コード例 #2
0
ファイル: PRWS.cs プロジェクト: up2038292/dwsim6
        public override bool LoadData(List <System.Xml.Linq.XElement> data)
        {
            base.LoadData(data);

            System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.InvariantCulture;

            foreach (XElement xel in (from xel2 in data where xel2.Name == "InteractionParametersPR" select xel2).SingleOrDefault().Elements().ToList())
            {
                PHSC_IP ip = new PHSC_IP
                {
                    Compound1 = xel.Attribute("Compound1").Value,
                    Compound2 = xel.Attribute("Compound2").Value,
                    kij       = double.Parse(xel.Attribute("Value").Value, ci)
                };
                Dictionary <string, PHSC_IP> dic = new Dictionary <string, PHSC_IP>();
                dic.Add(xel.Attribute("Compound1").Value, ip);
                if (!this.InteractionParameters.ContainsKey(xel.Attribute("Compound1").Value))
                {
                    this.InteractionParameters.Add(xel.Attribute("Compound1").Value, dic);
                }
                else
                {
                    if (!this.InteractionParameters[xel.Attribute("Compound1").Value].ContainsKey(xel.Attribute("Compound2").Value))
                    {
                        this.InteractionParameters[xel.Attribute("Compound1").Value].Add(xel.Attribute("Compound2").Value, ip);
                    }
                    else
                    {
                        this.InteractionParameters[xel.Attribute("Compound1").Value][xel.Attribute("Compound2").Value] = ip;
                    }
                }
            }

            foreach (XElement xel in (from xel2 in data where xel2.Name == "InteractionParametersNRTL" select xel2).SingleOrDefault().Elements().ToList())
            {
                NRTL_IPData ip = new NRTL_IPData
                {
                    ID1     = xel.Attribute("Compound1").Value,
                    ID2     = xel.Attribute("Compound2").Value,
                    A12     = double.Parse(xel.Attribute("A12").Value, ci),
                    A21     = double.Parse(xel.Attribute("A21").Value, ci),
                    alpha12 = double.Parse(xel.Attribute("alpha12").Value, ci)
                };
                Dictionary <string, NRTL_IPData> dic = new Dictionary <string, NRTL_IPData>();
                dic.Add(xel.Attribute("Compound1").Value, ip);
                if (!this.InteractionParametersNRTL.ContainsKey(xel.Attribute("Compound1").Value))
                {
                    this.InteractionParametersNRTL.Add(xel.Attribute("Compound1").Value, dic);
                }
                else
                {
                    if (!this.InteractionParametersNRTL[xel.Attribute("Compound1").Value].ContainsKey(xel.Attribute("Compound2").Value))
                    {
                        this.InteractionParametersNRTL[xel.Attribute("Compound1").Value].Add(xel.Attribute("Compound2").Value, ip);
                    }
                    else
                    {
                        this.InteractionParametersNRTL[xel.Attribute("Compound1").Value][xel.Attribute("Compound2").Value] = ip;
                    }
                }
            }

            return(true);
        }