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 == "InteractionParameters" 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 == "CompoundParameters" select xel2).SingleOrDefault().Elements().ToList()) { PHSC_Param param = new PHSC_Param { Compound = xel.Attribute("Compound").Value, CAS_ID = xel.Attribute("CAS_ID").Value, V = double.Parse(xel.Attribute("V").Value, ci), A = double.Parse(xel.Attribute("A").Value, ci), E = double.Parse(xel.Attribute("E").Value, ci) }; if (!this.CompoundParameters.ContainsKey(xel.Attribute("Compound").Value)) { this.CompoundParameters.Add(xel.Attribute("Compound").Value, param); } else { this.CompoundParameters[xel.Attribute("Compound").Value] = param; } } return(true); }
private void PRWS_Editor_Load(object sender, EventArgs e) { Loaded = false; chkUseLK.Checked = PP.UseLeeKeslerEnthalpy; List <ICompoundConstantProperties> compounds; if (GlobalSettings.Settings.CAPEOPENMode) { compounds = PP._selectedcomps.Values.Select(x => (ICompoundConstantProperties)x).ToList(); } else { compounds = PP.Flowsheet.SelectedCompounds.Values.ToList(); } foreach (ICompoundConstantProperties cp in compounds) { gt0: if (PP.InteractionParameters.ContainsKey(cp.Name)) { foreach (ICompoundConstantProperties cp2 in compounds) { if (cp.Name != cp2.Name) { if (!PP.InteractionParameters[cp.Name].ContainsKey(cp2.Name)) { //check if collection has id2 as primary id if (PP.InteractionParameters.ContainsKey(cp2.Name)) { if (!PP.InteractionParameters[cp2.Name].ContainsKey(cp.Name)) { var ip = new PHSC_IP(); ip.Compound1 = cp.Name; ip.Compound2 = cp2.Name; PP.InteractionParameters[cp.CAS_Number].Add(cp2.CAS_Number, ip); dgvkij.Rows.Add(new object[] { cp.Name, cp2.Name, ip.kij }); } } } else { double a12 = PP.InteractionParameters[cp.Name][cp2.Name].kij; dgvkij.Rows.Add(new object[] { cp.Name, cp2.Name, a12 }); dgvkij.Rows[dgvkij.Rows.Count - 1].Cells[0].Tag = cp.Name; dgvkij.Rows[dgvkij.Rows.Count - 1].Cells[1].Tag = cp2.Name; } } } } else { PP.InteractionParameters.Add(cp.Name, new Dictionary <string, PHSC_IP>()); goto gt0; } } foreach (ICompoundConstantProperties cp in compounds) { gt2: if (PP.InteractionParametersNRTL.ContainsKey(cp.Name)) { foreach (ICompoundConstantProperties cp2 in compounds) { if (cp.Name != cp2.Name) { if (!PP.InteractionParametersNRTL[cp.Name].ContainsKey(cp2.Name)) { //check if collection has id2 as primary id if (PP.InteractionParametersNRTL.ContainsKey(cp2.Name)) { if (!PP.InteractionParametersNRTL[cp2.Name].ContainsKey(cp.Name)) { PP.InteractionParametersNRTL[cp.Name].Add(cp2.Name, new NRTL_IPData()); double a12 = PP.InteractionParametersNRTL[cp.Name][cp2.Name].A12; double a21 = PP.InteractionParametersNRTL[cp.Name][cp2.Name].A21; double alpha12 = PP.InteractionParametersNRTL[cp.Name][cp2.Name].alpha12; dgvnrtl.Rows.Add(new object[] { cp.Name, cp2.Name, a12, a21, alpha12 }); } } } else { double a12 = PP.InteractionParametersNRTL[cp.Name][cp2.Name].A12; double a21 = PP.InteractionParametersNRTL[cp.Name][cp2.Name].A21; double alpha12 = PP.InteractionParametersNRTL[cp.Name][cp2.Name].alpha12; dgvnrtl.Rows.Add(new object[] { cp.Name, cp2.Name, a12, a21, alpha12 }); dgvnrtl.Rows[dgvnrtl.Rows.Count - 1].Cells[0].Tag = cp.Name; dgvnrtl.Rows[dgvnrtl.Rows.Count - 1].Cells[1].Tag = cp2.Name; } } } } else { PP.InteractionParametersNRTL.Add(cp.Name, new Dictionary <string, NRTL_IPData>()); goto gt2; } } Loaded = true; }
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); }