Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align with changes to the physical material and methods #287

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using BH.oM.Physical.Materials;
using BH.Engine.Matter;
using BH.Engine.LifeCycleAssessment.Objects;
using BH.oM.LifeCycleAssessment.MaterialFragments;

namespace BH.Engine.LifeCycleAssessment
{
Expand All @@ -39,21 +40,26 @@ public static partial class Compute
/**** Public Methods ****/
/***************************************************/

[PreviousVersion("6.0", "BH.Engine.LifeCycleAssessment.Compute.EvaluateEnvironmentalProductDeclaration(BH.oM.Dimensional.IElementM, System.Collections.Generic.List<BH.oM.LifeCycleAssessment.LifeCycleAssessmentPhases>, BH.oM.LifeCycleAssessment.EnvironmentalProductDeclarationField, System.Boolean)")]
[Description("This method calculates the results of any selected metric within an Environmental Product Declaration. For example for an EPD of QuantityType Volume, results will reflect the objects volume * EPD Field metric.")]
[Input("elementM", "This is a BHoM object used to calculate EPD metric. This obj must have an EPD MaterialFragment applied to the object.")]
[Input("phases", "Provide phases of life you wish to evaluate. Phases of life must be documented within EPDs for this method to work.")]
[Input("field", "Filter the provided EnvironmentalProductDeclaration by selecting one of the provided metrics for calculation. This method also accepts multiple fields simultaneously.")]
[Input("exactMatch", "If true, the evaluation method will force an exact LCA phase match to solve for.")]
[Output("result", "A LifeCycleElementResult that contains the LifeCycleAssessment data for the input object.")]
public static LifeCycleAssessmentElementResult EvaluateEnvironmentalProductDeclaration(IElementM elementM, List<LifeCycleAssessmentPhases> phases, EnvironmentalProductDeclarationField field = EnvironmentalProductDeclarationField.GlobalWarmingPotential, bool exactMatch = false)
public static LifeCycleAssessmentElementResult EvaluateEnvironmentalProductDeclaration(IElementM elementM, List<LifeCycleAssessmentPhases> phases, EnvironmentalProductDeclarationField field = EnvironmentalProductDeclarationField.GlobalWarmingPotential, bool exactMatch = false, List<Material> templateMaterials = null, bool prioritiseTemplate = true)
{
double value = 0;
EnvironmentalMetricResult resultValue = null;
MaterialComposition mc = elementM.IMaterialComposition();
MaterialComposition mc = elementM.MappedMaterialComposition(templateMaterials, true, prioritiseTemplate);

List<QuantityType> qts = elementM.GetQuantityType(mc);

qts = qts.Distinct().ToList();
List<QuantityType> qts = mc.Materials.Where(x => x != null).Select(x =>
{
var epd = x.Properties.OfType<EnvironmentalProductDeclaration>().FirstOrDefault();
if (epd != null)
return epd.QuantityType;
return QuantityType.Undefined;
}).Distinct().ToList();

foreach (QuantityType qt in qts)
{
Expand Down Expand Up @@ -115,8 +121,8 @@ public static LifeCycleAssessmentElementResult EvaluateEnvironmentalProductDecla
resultValue.EnvironmentalProductDeclaration = elementM.GetElementEpd(mc);
return resultValue;
}
/***************************************************/

/***************************************************/

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ private static EnvironmentalMetricResult EvaluateEnvironmentalProductDeclaration
{
double volume = elementM.ISolidVolume();
List<double> gwpByMaterial = new List<double>();
List<Material> matList = materialComposition.Materials.ToList();

List<double> epdVals = elementM.GetEvaluationValue(field, phases, QuantityType.Mass, materialComposition, exactMatch);
if (epdVals == null || epdVals.Where(x => !double.IsNaN(x)).Sum() <= 0)
Expand All @@ -60,27 +59,31 @@ private static EnvironmentalMetricResult EvaluateEnvironmentalProductDeclaration
return null;
}

for (int i = 0; i < matList.Count(); i++)
for (int i = 0; i < materialComposition.Materials.Count; i++)
{
double density;
List<EnvironmentalProductDeclaration> materialEPDs = matList[i].Properties.OfType<EnvironmentalProductDeclaration>().ToList();
List<EnvironmentalProductDeclaration> materialEPDs = materialComposition.Materials[i].Properties.OfType<EnvironmentalProductDeclaration>().ToList();
if (materialEPDs.Any(x => x.QuantityType == QuantityType.Mass))
{
double volumeOfMaterial = materialComposition.Ratios[i] * volume;
List<double> densityOfMassEpd = materialEPDs.Where(x => x.QuantityType == QuantityType.Mass).First().GetEPDDensity();
if (densityOfMassEpd == null || densityOfMassEpd.Count() == 0)
double density = materialComposition.Materials[i].Density;
if (double.IsNaN(density))
{
BH.Engine.Base.Compute.RecordError("Density could not be found. Add DensityFragment for all objects using Mass-based QuantityType EPDs.");
Engine.Base.Compute.RecordError($"Density of material {materialComposition.Materials[i].Name} is not set (NaN). Ensure all materials have densities assigned when computing {field} for mass-based {nameof(QuantityType)}s.");
return null;
}
else if (density == 0)
{
Engine.Base.Compute.RecordWarning($"Density of material {materialComposition.Materials[i].Name} is 0 and will lead to no contribution to the computation of {field}.");
gwpByMaterial.Add(0);
}
else
density = densityOfMassEpd[0];

double massOfObj = volumeOfMaterial * density;
if (double.IsNaN(epdVals[i]))
gwpByMaterial.Add(double.NaN);
else
gwpByMaterial.Add(epdVals[i] * massOfObj);
{
double massOfObj = volumeOfMaterial * density;
if (double.IsNaN(epdVals[i]))
gwpByMaterial.Add(double.NaN);
else
gwpByMaterial.Add(epdVals[i] * massOfObj);
}
}
}
ScopeType scope = BH.Engine.LifeCycleAssessment.Query.GetElementScope(elementM);
Expand Down