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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
        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);
        }
        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);
        }