Skip to content

Commit

Permalink
null handling
Browse files Browse the repository at this point in the history
Removed a check that prevented getting MaterialComposition/VolumePerArea for Structural SurfaceProperties with no material, such as Layered properties.
  • Loading branch information
Josef Taylor authored and pawelbaran committed Aug 9, 2022
1 parent 62c4919 commit 1e50ffb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
6 changes: 6 additions & 0 deletions Physical_Engine/Query/MaterialComposition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ private static MaterialComposition MaterialComposition(this Construction prop)
if (prop.Layers.IsNullOrEmpty()) //.IsNullOrEmpty raises it's own error
return null;

if (prop.Layers.All(x => x.Material == null))
{
Compute.RecordError("Cannote evaluate MaterialComposition because all of the materials are null.");
return null;
}

if (prop.Layers.Any(x => x.Material == null))
{
Compute.RecordWarning("At least one Material in a Layered surface property was null. MaterialConstruction excludes this layer, assuming it is void space.");
Expand Down
8 changes: 8 additions & 0 deletions Structure_Engine/Query/Construction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public static Construction Construction(this Layered surfaceProperty)
if (surfaceProperty.IsNull())
return null;

if (surfaceProperty.Layers.All(x => x.Material == null))
Base.Compute.RecordWarning("None of the layers in surfaceProperty have a valid material. A Construction has been created, but its materials will also be null.");

List<oM.Physical.Constructions.Layer> layers = surfaceProperty.Layers.Select(x => Physical.Create.Layer(x.Name, Material(x.Material), x.Thickness)).ToList();

return Physical.Create.Construction(surfaceProperty.Name, layers);
Expand All @@ -93,7 +96,12 @@ public static Construction Construction(this ISurfaceProperty surfaceProperty)

MaterialComposition comp = surfaceProperty.IMaterialComposition();
double volume = surfaceProperty.IVolumePerArea();
if (volume == 0)
Base.Compute.RecordWarning("the SurfaceProperty has zero volume - a Construction has been created, but will also have zero volume.");

double thickness = surfaceProperty.ITotalThickness();
if (thickness == 0)
Base.Compute.RecordWarning("the SurfaceProperty has zero thickness - a Construction has been created, but will also have zero thickness.");

List<oM.Physical.Constructions.Layer> layers = new List<oM.Physical.Constructions.Layer>();

Expand Down
31 changes: 13 additions & 18 deletions Structure_Engine/Query/MaterialComposition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,9 @@ public static MaterialComposition MaterialComposition(this Bar bar)
[Output("materialComposition", "The kind of matter the AreaElement is composed of.")]
public static MaterialComposition MaterialComposition(this IAreaElement areaElement)
{
if (areaElement.IIsNull())
if (areaElement.IIsNull() || areaElement.Property.IsNull())
return null;

if (areaElement.Property == null || areaElement.Property.Material == null)
{
Engine.Base.Compute.RecordError("The areaElements MaterialComposition could not be calculated as no Material has been assigned.");
return null;
}

if (areaElement.FindFragment<PanelRebarIntent>() != null)
Engine.Base.Compute.RecordWarning("The areaElement has a PanelRebarIntent, which will not be included in the MaterialComposition. Please account for replacement of concrete volume with reinforcement externally.");

Expand Down Expand Up @@ -155,9 +149,15 @@ public static MaterialComposition MaterialComposition(this ConcreteSection prope
[Output("materialComposition", "The MaterialComposition of the SurfaceProperty.")]
public static MaterialComposition MaterialComposition(this Layered property, ReinforcementDensity reinforcementDensity = null)
{
if (property.IsNull())
if (property.IsNull() || property.Layers.All(x => x.Material.IsNull()))
return null;

if (property.Layers.All(x => x.Material == null)) //cull any null layers, raise a warning.
{
Base.Compute.RecordError("Cannote evaluate MaterialComposition because all of the materials are null.");
return null;
}

if (reinforcementDensity != null)
Base.Compute.RecordWarning("the layered property has a ReinforcementDensity which will not be included in the MaterialComposition, because it is not known which layer to replace. Please account for this reinforcement externally.");

Expand All @@ -176,10 +176,13 @@ public static MaterialComposition MaterialComposition(this Layered property, Rei
[Output("materialComposition", "The MaterialComposition of the SurfaceProperty.")]
public static MaterialComposition MaterialComposition(this CorrugatedDeck property, ReinforcementDensity reinforcementDensity = null)
{
if (property.IsNull() || property.Material.IsNull())
return null;

if (reinforcementDensity != null)
Base.Compute.RecordWarning("the CorrugatedDeck property has a ReinforcementDensity which will not be included in the MaterialComposition, because it is inconceivable.");

return property.IsNull() ? null : (MaterialComposition)Physical.Create.Material(property.Material);
return (MaterialComposition)Physical.Create.Material(property.Material);
}

/***************************************************/
Expand Down Expand Up @@ -246,7 +249,7 @@ public static MaterialComposition IMaterialComposition(this ISectionProperty pro
[Output("materialComposition", "The MaterialComposition of the SurfaceProperty.")]
public static MaterialComposition IMaterialComposition(this ISurfaceProperty property, ReinforcementDensity reinforcementDensity = null)
{
if (property.IsNull())
if (property.IsNull()) //Specific MaterialComposition(SurfaceProp) methods must check for material null- some properties ignore the base material.
return null;

return MaterialComposition(property as dynamic, reinforcementDensity);
Expand All @@ -273,10 +276,7 @@ private static MaterialComposition MaterialComposition(this ISectionProperty sec
private static MaterialComposition MaterialComposition(this ISurfaceProperty property, ReinforcementDensity reinforcementDensity = null)
{
if (property.IsNull() || property.Material.IsNull())
{
Engine.Base.Compute.RecordError("The MaterialComposition could not be queried as a Material was not assigned.");
return null;
}

if (reinforcementDensity == null)
return (MaterialComposition)Physical.Create.Material(property.Material);
Expand Down Expand Up @@ -319,11 +319,6 @@ private static MaterialComposition MaterialComposition(this IMaterialFragment ba

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






}
}

Expand Down

0 comments on commit 1e50ffb

Please sign in to comment.