public static Dictionary <string, Types.Material> LoadFromFile(string filename, List <LifecycleStage> stages) { Dictionary <string, Types.Material> LoadedMaterials = new Dictionary <string, Material>(); if (System.IO.File.Exists(filename)) { string[] data = System.IO.File.ReadAllLines(filename); for (int i = 1; i < data.Length; i++) { string[] fields = data[i].Split(','); if (fields.Length == 19) { UnitDouble <Types.LCA.CO2e> GWP = new UnitDouble <LCA.CO2e>(0); UnitDouble <Types.LCA.kgSO2> Acidification = new UnitDouble <LCA.kgSO2>(0); UnitDouble <Types.LCA.MJ> DepletionOfNonrenewbles = new UnitDouble <LCA.MJ>(0); UnitDouble <Types.LCA.kgCFC11> DepletionOfOzoneLayer = new UnitDouble <LCA.kgCFC11>(0); UnitDouble <Types.LCA.kgPhostphate> Eutrophication = new UnitDouble <LCA.kgPhostphate>(0); UnitDouble <Types.LCA.kgNOx> FormationTroposphericOzone = new UnitDouble <LCA.kgNOx>(0); foreach (LifecycleStage stage in stages) { GWP += new UnitDouble <Types.LCA.CO2e>(double.Parse(fields[1 + stage.Column])); Acidification += new UnitDouble <Types.LCA.kgSO2>(double.Parse(fields[4 + stage.Column])); DepletionOfNonrenewbles += new UnitDouble <Types.LCA.MJ>(double.Parse(fields[7 + stage.Column])); DepletionOfOzoneLayer += new UnitDouble <Types.LCA.kgCFC11>(double.Parse(fields[10 + stage.Column])); Eutrophication += new UnitDouble <Types.LCA.kgPhostphate>(double.Parse(fields[13 + stage.Column])); FormationTroposphericOzone += new UnitDouble <Types.LCA.kgNOx>(double.Parse(fields[16 + stage.Column])); } Tortuga.Types.Material material = new Material() { Name = fields[0], Description = "", Stages = stages, Source = DataSource.File, GlobalWarmingPotential = GWP, Acidification = Acidification, DepletionOfNonrenewbles = DepletionOfNonrenewbles, DepletionOfOzoneLayer = DepletionOfOzoneLayer, Eutrophication = Eutrophication, FormationTroposphericOzone = FormationTroposphericOzone, }; LoadedMaterials.Add(material.Name, material); } } } return(LoadedMaterials); }
public void CopyFrom(Material source) { this.Acidification = source.Acidification; this.GlobalWarmingPotential = source.GlobalWarmingPotential; this.Eutrophication = source.Eutrophication; this.FormationTroposphericOzone = source.FormationTroposphericOzone; this.DepletionOfNonrenewbles = source.DepletionOfNonrenewbles; this.DepletionOfOzoneLayer = source.DepletionOfOzoneLayer; this.Stages = source.Stages; }
public void LoadData(string url) { switch (this.Source) { case DataSource.Oekobaudat: System.Net.WebClient client = new System.Net.WebClient(); string data = client.DownloadString(url + "/resource/processes/" + this.ID + "?format=xml"); XmlDocument xml = new XmlDocument(); xml.LoadXml(data); XmlNamespaceManager manager = new XmlNamespaceManager(xml.NameTable); manager.AddNamespace("p", "http://lca.jrc.it/ILCD/Process"); manager.AddNamespace("epd", "http://www.iai.kit.edu/EPD/2013"); manager.AddNamespace("common", "http://lca.jrc.it/ILCD/Common"); manager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); this.GlobalWarmingPotential = new UnitDouble <LCA.CO2e>(0); this.Acidification = new UnitDouble <LCA.kgSO2>(0); this.DepletionOfNonrenewbles = new UnitDouble <LCA.MJ>(0); this.DepletionOfOzoneLayer = new UnitDouble <LCA.kgCFC11>(0); this.Eutrophication = new UnitDouble <LCA.kgPhostphate>(0); this.FormationTroposphericOzone = new UnitDouble <LCA.kgNOx>(0); XmlNodeList xnList = xml.SelectNodes("//p:LCIAResults", manager); foreach (XmlNode child in xnList[0].ChildNodes) { if (child.ChildNodes[0].ChildNodes.Count == 1) { Dictionary <string, double> values = new Dictionary <string, double>(); string Name = child.ChildNodes[0].ChildNodes[0].InnerText; foreach (XmlNode inner in child.ChildNodes) { if (inner.Name == "common:other") { foreach (XmlNode vals in inner.ChildNodes) { if (vals.Name == "epd:amount") { double tmp = 0; if (!double.TryParse(vals.InnerText, out tmp)) { tmp = 0; } if (!values.ContainsKey(vals.Attributes[0].Value)) { values.Add(vals.Attributes[0].Value, tmp); } else { values[vals.Attributes[0].Value] += tmp; } } } } foreach (Tortuga.Types.LifecycleStage stage in this.Stages) { double actualVal = 0; if (!values.ContainsKey(stage.Name)) { if (stage.Name == "A1-A3") { if (values.ContainsKey("A1")) { actualVal += values["A1"]; } if (values.ContainsKey("A2")) { actualVal += values["A2"]; } if (values.ContainsKey("A3")) { actualVal += values["A3"]; } } } else { actualVal = values[stage.Name]; } if (Name.Contains("(GWP)")) { this.GlobalWarmingPotential += new UnitDouble <LCA.CO2e>(actualVal); } if (Name.Contains("(AP)")) { this.Acidification += new UnitDouble <LCA.kgSO2>(actualVal); } if (Name.Contains("(ADPF)")) { this.DepletionOfNonrenewbles += new UnitDouble <LCA.MJ>(actualVal); } if (Name.Contains("(OPD)")) { this.DepletionOfOzoneLayer += new UnitDouble <LCA.kgCFC11>(actualVal); } if (Name.Contains("(ADPE)")) { this.Eutrophication += new UnitDouble <LCA.kgPhostphate>(actualVal); } if (Name.Contains("(POCP)")) { this.FormationTroposphericOzone += new UnitDouble <LCA.kgNOx>(actualVal); } } } } } break; case DataSource.Quartz: this.GlobalWarmingPotential = new UnitDouble <LCA.CO2e>(0); this.Acidification = new UnitDouble <LCA.kgSO2>(0); this.DepletionOfNonrenewbles = new UnitDouble <LCA.MJ>(0); this.DepletionOfOzoneLayer = new UnitDouble <LCA.kgCFC11>(0); this.Eutrophication = new UnitDouble <LCA.kgPhostphate>(0); this.FormationTroposphericOzone = new UnitDouble <LCA.kgNOx>(0); Quartz.Data qdata = Tortuga.Quartz.Document.LoadRootObject(this.ID); foreach (LifecycleStage stage in this.Stages) { List <Quartz.LcaData> res = null; if (stage.Name == "A1-A3") { res = qdata.environmental.lcaResults.inUse; } if (stage.Name == "C3") { res = qdata.environmental.lcaResults.cradleToGate; } if (stage.Name == "D") { res = qdata.environmental.lcaResults.endOfLife; } if (res != null) { if (res[2].value != null) { this.GlobalWarmingPotential += new UnitDouble <Types.LCA.CO2e>(double.Parse(res[2].value)); } if (res[0].value != null) { this.Acidification += new UnitDouble <Types.LCA.kgSO2>(double.Parse(res[0].value)); } if (res[5].value != null) { this.DepletionOfNonrenewbles += new UnitDouble <Types.LCA.MJ>(double.Parse(res[5].value)); } if (res[3].value != null) { this.DepletionOfOzoneLayer += new UnitDouble <Types.LCA.kgCFC11>(double.Parse(res[3].value)); } if (res[1].value != null) { this.Eutrophication += new UnitDouble <Types.LCA.kgPhostphate>(double.Parse(res[1].value)); } if (res[4].value != null) { this.FormationTroposphericOzone += new UnitDouble <Types.LCA.kgNOx>(double.Parse(res[4].value)); } } } break; } }