public static List <List <EnvironmentalMetric> > GetElementEnvironmentalMetric(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.");
            }

            List <List <EnvironmentalMetric> > metric = epd.Select(x => x.EnvironmentalMetric).ToList();

            if (metric.Count() <= 0)
            {
                BH.Engine.Reflection.Compute.RecordError("No Environmental Metrics could be found.");
            }

            return(metric);
        }
        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));
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }

        /***************************************************/
    }
Beispiel #6
0
        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());
        }
Beispiel #7
0
        public static List <IEnvironmentalProductDeclarationData> 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 <IEnvironmentalProductDeclarationData> epd = elementM.IMaterialComposition().Materials.Select(x => x.Properties.Where(y => y is IEnvironmentalProductDeclarationData).FirstOrDefault() as IEnvironmentalProductDeclarationData).ToList();

            if (epd == null)
            {
                BH.Engine.Reflection.Compute.RecordError("No EPD Material was found within the object's MaterialComposition.");
            }

            return(epd);
        }
Beispiel #8
0
        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);
        }
        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 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);
        }
Beispiel #12
0
        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());
        }