public static List <double> GetElementDensity(this IElementM elementM) { List <double> density = new List <double>(); if (elementM == null) { return(new List <double>()); } density = elementM.IMaterialComposition().Materials.Where(x => x != null).Select(x => { var epd = x.Properties.Where(y => y is IEnvironmentalProductDeclarationData).FirstOrDefault() as IEnvironmentalProductDeclarationData; if (epd != null) { return(epd.Density); } else { BH.Engine.Reflection.Compute.RecordError($"No density was provided for material name {epd.Name}."); return(0); } }).ToList(); return(density); }
public static List <EnvironmentalMetric> GetEnvironmentalMetric(this IElementM elementM) { List <EnvironmentalMetric> em = new List <EnvironmentalMetric>(); if (elementM == null) { return(new List <EnvironmentalMetric>()); } List <oM.Physical.Materials.Material> material = elementM.IMaterialComposition().Materials.ToList(); List <EnvironmentalMetric> metrics = new List <EnvironmentalMetric>(); foreach (var m in material) { List <EnvironmentalProductDeclaration> epds = m.Properties.Where(x => x is EnvironmentalProductDeclaration).Cast <EnvironmentalProductDeclaration>().ToList(); foreach (var e in epds) { List <EnvironmentalMetric> me = epds.SelectMany(x => x.EnvironmentalMetric).ToList(); metrics.AddRange(me); } } return(metrics); }
public static List <QuantityType> GetQuantityType(this IElementM elementM) { List <QuantityType> qt = new List <QuantityType>(); if (elementM == null) { return new List <QuantityType> { QuantityType.Undefined } } ; qt = elementM.IMaterialComposition().Materials.Where(x => x != null).Select(x => { var epd = x.Properties.Where(y => y is EnvironmentalProductDeclaration).FirstOrDefault() as EnvironmentalProductDeclaration; if (epd != null) { return(epd.QuantityType); } return(QuantityType.Undefined); }).ToList(); return(qt); } /***************************************************/ }
public static double ISolidVolume(this IElementM elementM) { if (elementM == null) { BH.Engine.Reflection.Compute.RecordError("Cannot query the solid volume of a null element."); return(0); } return((double)Reflection.Compute.RunExtensionMethod(elementM, "SolidVolume")); }
public static double Mass(this IElementM elementM) { if (elementM == null) { BH.Engine.Reflection.Compute.RecordError("Cannot query the mass of a null element."); return(0); } MaterialComposition mat = elementM.IMaterialComposition(); return(elementM.ISolidVolume() * mat.Materials.Zip(mat.Ratios, (m, r) => r * m.Density()).Sum()); }
public static List <string> GetElementMaterial(this IElementM elementM) { List <string> mat = new List <string>(); if (elementM == null) { return(null); } mat = Matter.Query.IMaterialComposition(elementM).Materials.Select(x => x.Name).ToList(); return(mat); }
public static List <double> GetQuantityTypeValue(this IElementM elementM, QuantityType type) { if (elementM == null) { return(new List <double>()); } List <double> qtv = elementM.IMaterialComposition().Materials.Select(x => { var epd = x.Properties.Where(y => y is EnvironmentalProductDeclaration).FirstOrDefault() as EnvironmentalProductDeclaration; if (epd != null && epd.QuantityType == type) { return(epd.QuantityTypeValue); } return(1); }).Where(x => x != null).ToList(); return(qtv); }
public static List <EnvironmentalProductDeclaration> GetElementEpd(this IElementM elementM) { if (elementM == null) { BH.Engine.Reflection.Compute.RecordError("No IElementM was provided."); } if (elementM.IMaterialComposition() == null) { BH.Engine.Reflection.Compute.RecordError("The provided element does not have a MaterialComposition."); } List <EnvironmentalProductDeclaration> epd = elementM.IMaterialComposition().Materials.Select(x => x.Properties.Where(y => y is EnvironmentalProductDeclaration).FirstOrDefault() as EnvironmentalProductDeclaration).ToList(); if (epd == null) { BH.Engine.Reflection.Compute.RecordError("No EPD Material was found within the object's MaterialComposition."); } return(epd); }
public static List <double> GetEvaluationValue(this IElementM elementM, EnvironmentalProductDeclarationField field, List <LifeCycleAssessmentPhases> phases, QuantityType type, bool exactMatch = false) { if (elementM == null) { return(new List <double>()); } List <double> quantityTypeValue = elementM.GetQuantityTypeValue(type); List <double> epdVal = elementM.IMaterialComposition().Materials.Select(x => { var epd = x.Properties.Where(y => y is EnvironmentalProductDeclaration).FirstOrDefault() as EnvironmentalProductDeclaration; if (epd.QuantityType == type && (epd.EnvironmentalMetric.Where(z => z.Phases.Where(a => phases.Contains(a)).Count() != 0).FirstOrDefault() != null)) { return(GetEvaluationValue(epd, field, phases, exactMatch)); } else { return(double.NaN); } }).ToList(); //Division of GWP constant by QTV List <double> normalisedEpdVal = new List <double>(); for (int x = 0; x < epdVal.Count; x++) { if (double.IsNaN(epdVal[x])) { normalisedEpdVal.Add(double.NaN); } else { normalisedEpdVal.Add(epdVal[x] / quantityTypeValue[x]); } } return(normalisedEpdVal); }
public static List <double> GetEvaluationValue(this IElementM elementM, EnvironmentalProductDeclarationField field, QuantityType type) { if (elementM == null) { return(new List <double>()); } List <double> quantityTypeValue = elementM.GetQuantityTypeValue(type); List <double> epdVal = elementM.IMaterialComposition().Materials.Select(x => { var epd = x.Properties.Where(y => y is IEnvironmentalProductDeclarationData).FirstOrDefault() as IEnvironmentalProductDeclarationData; if (epd.QuantityType == type) { return(GetEvaluationValue(epd, field)); } else { return(double.NaN); } }).ToList(); //Division of GWP constant by QTV List <double> normalisedEpdVal = new List <double>(); for (int x = 0; x < epdVal.Count; x++) { if (double.IsNaN(epdVal[x])) { normalisedEpdVal.Add(double.NaN); } else { normalisedEpdVal.Add(epdVal[x] / quantityTypeValue[x]); } } return(normalisedEpdVal); }
public static List <List <LifeCycleAssessmentPhases> > GetEPDPhases(this IElementM elementM) { // Element null check if (elementM == null) { BH.Engine.Reflection.Compute.RecordError("No IElementM was provided."); return(new List <List <LifeCycleAssessmentPhases> >()); } // Get all the epds from the elements List <EnvironmentalProductDeclaration> epd = GetElementEpd(elementM); if (epd == null) { BH.Engine.Reflection.Compute.RecordError($"No EPDs could be found within element {elementM.GetType()}."); return(new List <List <LifeCycleAssessmentPhases> >()); } // Get list of all EPD EnvironmentalMetrics List <EnvironmentalMetric> metrics = (List <EnvironmentalMetric>)epd.Select(x => x.EnvironmentalMetric); if (metrics.Count() <= 0) { BH.Engine.Reflection.Compute.RecordError($"No environmental metrics could be found within element {elementM.GetType()}."); return(new List <List <LifeCycleAssessmentPhases> >()); } // Get list of all Phases List <List <LifeCycleAssessmentPhases> > phases = metrics.Select(x => x.Phases).Distinct().ToList(); if (phases.Count <= 0) { BH.Engine.Reflection.Compute.RecordError("No Phases have been found within the EPD."); return(new List <List <LifeCycleAssessmentPhases> >()); } return(phases); }
public static List <double> GetEPDDensity(this IElementM elementM) { // Element null check if (elementM == null) { BH.Engine.Reflection.Compute.RecordError("No element was provided. Returning NaN."); return(new List <double>()); } // EPD Fragment null check List <EnvironmentalProductDeclaration> elementEpd = GetElementEpd(elementM); if (elementEpd.Count() <= 0) { BH.Engine.Reflection.Compute.RecordError("No EPDs could be found within any elements. Returning NaN. \n" + "Have you tried MapEPD to set your desired EPD?"); return(new List <double>()); } // Get list of all EPD Fragments -- Cast to IBHoMObject fails List <EPDDensity> densityFragment = elementEpd.SelectMany(a => Base.Query.GetAllFragments(a, typeof(EPDDensity)).Cast <EPDDensity>()).ToList(); if (densityFragment.Count() <= 0) { BH.Engine.Reflection.Compute.RecordError("No Density fragments could be found on the provided EPD. Have you tried adding an EPDDensity fragment?"); return(new List <double>()); } // Get list of all EPD Density Values from fragments List <double> density = densityFragment.Select(x => x).Select(y => y.Density).ToList(); if (density == null) { BH.Engine.Reflection.Compute.RecordWarning("No density data could be found. Please review any EPDDensity fragments used on the EPD."); return(new List <double>()); } return(density); }
public static double DepletionOfAbioticResources(IElementM elementM, IEnvironmentalProductDeclarationData epd) { QuantityType qt = epd.QuantityType; if (qt != QuantityType.Mass) { Reflection.Compute.RecordError("This method only works with Mass-based QuantityType EPDs. Please provide a different EPD."); return(double.NaN); } else { double volume = elementM.ISolidVolume(); double density = epd.Density; double depletionOfAbioticResources = System.Convert.ToDouble(epd.DepletionOfAbioticResources); if (volume <= 0 || volume == double.NaN) { Reflection.Compute.RecordError("Volume cannot be calculated from object " + ((IBHoMObject)elementM).BHoM_Guid); return(double.NaN); } if (density <= 0 || density == double.NaN) { Reflection.Compute.RecordError("EPD does not contain a value for Density"); return(double.NaN); } if (depletionOfAbioticResources <= 0 || depletionOfAbioticResources == double.NaN) { Reflection.Compute.RecordError("EPD does not contain a value for DepletionOfAbioticResources"); return(double.NaN); } return(volume * density * depletionOfAbioticResources); } /***************************************************/ }
private static GlobalWarmingPotentialResult EvaluateEnvironmentalProductDeclarationByArea(IElementM elementM = null, EnvironmentalProductDeclarationField field = EnvironmentalProductDeclarationField.GlobalWarmingPotential) { if (elementM is IElement2D) { BH.Engine.Reflection.Compute.RecordNote($"Thickness properties for Area-based calculations are set according to the EPD properties of object {elementM.GetType()}, not the construction."); double area = (elementM as IElement2D).Area(); List <double> epdVal = elementM.GetEvaluationValue(field, QuantityType.Area); List <double> gwpByMaterial = new List <double>(); for (int x = 0; x < epdVal.Count; x++) { if (double.IsNaN(epdVal[x])) { gwpByMaterial.Add(double.NaN); } else { gwpByMaterial.Add(epdVal[x] * area); } } if (epdVal == null || epdVal.Where(x => !double.IsNaN(x)).Sum() <= 0) { BH.Engine.Reflection.Compute.RecordError($"No value for {field} can be found within the supplied EPD."); return(null); } if (area <= 0 || area == double.NaN) { BH.Engine.Reflection.Compute.RecordError("Area cannot be calculated from object " + ((IBHoMObject)elementM).BHoM_Guid); return(null); } double quantity = gwpByMaterial.Where(x => !double.IsNaN(x)).Sum(); return(new GlobalWarmingPotentialResult(((IBHoMObject)elementM).BHoM_Guid, field, 0, ObjectScope.Undefined, ObjectCategory.Undefined, Query.GetElementEpd(elementM), quantity)); } else { BH.Engine.Reflection.Compute.RecordError("Area-based evaluations are not supported for objects of type: " + elementM.GetType() + "."); return(null); } }
public static MaterialComposition IMaterialComposition(this IElementM elementM) { return(Reflection.Compute.RunExtensionMethod(elementM, "MaterialComposition") as MaterialComposition); }
public static double ISolidVolume(this IElementM elementM) { return((double)Reflection.Compute.RunExtensionMethod(elementM, "SolidVolume")); }
private static EnvironmentalMetricResult EvaluateEnvironmentalProductDeclarationByVolume(IElementM elementM, List <LifeCycleAssessmentPhases> phases, EnvironmentalProductDeclarationField field = EnvironmentalProductDeclarationField.GlobalWarmingPotential, bool exactMatch = false) { List <double> epdVal = elementM.GetEvaluationValue(field, phases, QuantityType.Volume, exactMatch); double volume = elementM.ISolidVolume(); List <double> volumeByRatio = elementM.IMaterialComposition().Ratios.Select(x => volume * x).ToList(); List <double> gwpByMaterial = new List <double>(); for (int x = 0; x < epdVal.Count; x++) { if (double.IsNaN(epdVal[x])) { gwpByMaterial.Add(double.NaN); } else { gwpByMaterial.Add(epdVal[x] * volumeByRatio[x]); } } if (epdVal == null || epdVal.Where(x => !double.IsNaN(x)).Sum() <= 0) { BH.Engine.Reflection.Compute.RecordError($"No value for {field} can be found within the supplied EPD."); return(null); } if (volume <= 0) { BH.Engine.Reflection.Compute.RecordError("Volume cannot be calculated from object " + ((IBHoMObject)elementM).BHoM_Guid); return(null); } double quantity = gwpByMaterial.Where(x => !double.IsNaN(x)).Sum(); return(new EnvironmentalMetricResult(((IBHoMObject)elementM).BHoM_Guid, field, 0, ObjectScope.Undefined, ObjectCategory.Undefined, phases, Query.GetElementEpd(elementM), quantity, field)); }
private static EnvironmentalMetricResult EvaluateEnvironmentalProductDeclarationByMass(IElementM elementM, List <LifeCycleAssessmentPhases> phases, EnvironmentalProductDeclarationField field = EnvironmentalProductDeclarationField.GlobalWarmingPotential, bool exactMatch = false) { double volume = elementM.ISolidVolume(); List <double> epdVal = elementM.GetEvaluationValue(field, phases, QuantityType.Mass, exactMatch); List <double> gwpByMaterial = new List <double>(); List <double> volumeByRatio = elementM.IMaterialComposition().Ratios.Select(x => volume * x).ToList(); List <double> densityOfMassEpd = Query.GetEPDDensity(elementM); List <double> massOfObj = new List <double>(); if (densityOfMassEpd == null) { BH.Engine.Reflection.Compute.RecordError("Density could not be found. Material density is required for all objects using Mass-based evaluations."); return(null); } for (int x = 0; x < volumeByRatio.Count; x++) { massOfObj.Add(volumeByRatio[x] * densityOfMassEpd[x]); } for (int x = 0; x < epdVal.Count; x++) { if (double.IsNaN(epdVal[x])) { gwpByMaterial.Add(double.NaN); } else { gwpByMaterial.Add(epdVal[x] * massOfObj[x]); } } if (epdVal == null || epdVal.Where(x => !double.IsNaN(x)).Sum() <= 0) { BH.Engine.Reflection.Compute.RecordError($"No value for {field} can be found within the supplied EPD."); return(null); } double quantity = gwpByMaterial.Where(x => !double.IsNaN(x)).Sum(); return(new EnvironmentalMetricResult(((IBHoMObject)elementM).BHoM_Guid, field, 0, ObjectScope.Undefined, ObjectCategory.Undefined, phases, Query.GetElementEpd(elementM), quantity, field)); }
public static double Mass(this IElementM elementM) { MaterialComposition mat = elementM.IMaterialComposition(); return(elementM.ISolidVolume() * mat.Materials.Zip(mat.Ratios, (m, r) => r * m.Density()).Sum()); }
public static LifeCycleAssessmentElementResult EvaluateEnvironmentalProductDeclaration(IElementM elementM, List <LifeCycleAssessmentPhases> phases, EnvironmentalProductDeclarationField field = EnvironmentalProductDeclarationField.GlobalWarmingPotential, bool exactMatch = false) { double value = 0; EnvironmentalMetricResult resultValue = null; List <QuantityType> qts = elementM.GetQuantityType(); qts = qts.Distinct().ToList(); foreach (QuantityType qt in qts) { switch (qt) { case QuantityType.Undefined: BH.Engine.Reflection.Compute.RecordError("The object's EPD QuantityType is Undefined and cannot be evaluated."); return(null); case QuantityType.Area: BH.Engine.Reflection.Compute.RecordNote("Evaluating object type: " + elementM.GetType() + " based on EPD Area QuantityType."); var evalByArea = EvaluateEnvironmentalProductDeclarationByArea(elementM, phases, field, exactMatch); value += evalByArea.Quantity; if (resultValue == null) { resultValue = evalByArea; } break; case QuantityType.Ampere: BH.Engine.Reflection.Compute.RecordError("Ampere QuantityType is currently not supported."); return(null); case QuantityType.Item: BH.Engine.Reflection.Compute.RecordError("Length QuantityType is currently not supported. Try a different EPD with QuantityType values of either Area, Volume, or Mass."); return(null); case QuantityType.Length: BH.Engine.Reflection.Compute.RecordNote("Evaluating object type: " + elementM.GetType() + " based on EPD Length QuantityType."); var evalByLength = EvaluateEnvironmentalProductDeclarationByLength(elementM, phases, field, exactMatch); value += evalByLength.Quantity; if (resultValue == null) { resultValue = evalByLength; } break; case QuantityType.Mass: BH.Engine.Reflection.Compute.RecordNote("Evaluating object type: " + elementM.GetType() + " based on EPD Mass QuantityType."); var evalByMass = EvaluateEnvironmentalProductDeclarationByMass(elementM, phases, field, exactMatch); value += evalByMass.Quantity; if (resultValue == null) { resultValue = evalByMass; } break; case QuantityType.Watt: BH.Engine.Reflection.Compute.RecordError("Watt QuantityType is currently not supported."); return(null); case QuantityType.VoltAmps: BH.Engine.Reflection.Compute.RecordError("VoltAmps QuantityType is currently not supported."); return(null); case QuantityType.Volume: BH.Engine.Reflection.Compute.RecordNote("Evaluating object type: " + elementM.GetType() + " based on EPD Volume QuantityType."); var evalByVolume = EvaluateEnvironmentalProductDeclarationByVolume(elementM, phases, field, exactMatch); value += evalByVolume.Quantity; if (resultValue == null) { resultValue = evalByVolume; } break; case QuantityType.VolumetricFlowRate: BH.Engine.Reflection.Compute.RecordError("VolumetricFlowRate QuantityType is currently not supported."); return(null); default: BH.Engine.Reflection.Compute.RecordWarning("The object you have provided does not contain an EPD Material Fragment."); return(null); } } resultValue.Quantity = value; resultValue.EnvironmentalProductDeclaration = elementM.GetElementEpd(); return(resultValue); }
private static GlobalWarmingPotentialResult EvaluateEnvironmentalProductDeclarationByLength(IElementM elementM = null, EnvironmentalProductDeclarationField field = EnvironmentalProductDeclarationField.GlobalWarmingPotential) { if (elementM is IElement1D) { double length = (elementM as IElement1D).Length(); List <double> epdVal = elementM.GetEvaluationValue(field, QuantityType.Length); List <double> gwpByMaterial = new List <double>(); for (int x = 0; x < epdVal.Count; x++) { if (double.IsNaN(epdVal[x])) { gwpByMaterial.Add(double.NaN); } else { gwpByMaterial.Add(epdVal[x] * length); } } if (epdVal == null || epdVal.Where(x => !double.IsNaN(x)).Sum() <= 0) { BH.Engine.Reflection.Compute.RecordError($"No value for {field} can be found within the supplied EPD."); return(null); } if (length <= 0 || length == double.NaN) { BH.Engine.Reflection.Compute.RecordError("Length cannot be calculated from object " + ((IBHoMObject)elementM).BHoM_Guid); return(null); } double quantity = gwpByMaterial.Where(x => !double.IsNaN(x)).Sum(); return(new GlobalWarmingPotentialResult(((IBHoMObject)elementM).BHoM_Guid, field, 0, ObjectScope.Undefined, ObjectCategory.Undefined, Query.GetElementEpd(elementM), quantity)); } else { BH.Engine.Reflection.Compute.RecordError("Length-based evaluations are not supported for objects of type: " + elementM.GetType() + "."); return(null); } }