BHoM / BHoM_Engine

Internal manipulation of the BHoM
GNU Lesser General Public License v3.0
26 stars 12 forks source link

Structure_Engine: PanelToFEMesh does not work when lines have differing directions #3360

Open peterjamesnugent opened 3 weeks ago

peterjamesnugent commented 3 weeks ago

Description:

PanelToFEMesh does not give sufficient results when point ordering is not sorted along the curve.

Steps to reproduce:

Test file.

Expected behaviour:

FEMesh to be reproduced with correct geometry from Panel.

Test file(s):

https://burohappold.sharepoint.com/:u:/s/BHoM/EW7jAkBEjXJLkQms-JGmrF0BvlpHxA0_H-mVl_42zf0HtA?e=keCf04

peterjamesnugent commented 3 weeks ago

The unit tests also need to be updated, as they are currently empty.

Code to replace PanelToFEMesh once beta is released: ` [Description("Converts a Panel with three or four control points to a FEMesh with a single Face. This is not a method to discretise a Panel, it simply converts a simple Panel to an identical feMesh.")] [Input("panel", "Panel to be converted to a FEMesh.")] [Output("feMesh", "FEMesh converted from a Panel.")]

   public static FEMesh PanelToFEMesh(this Panel panel, double tolerance = Tolerance.MacroDistance)
   {
       if (panel.IsNull())
       {
           return null;
       }
       if (!panel.IsPlanar(true, tolerance))
       {
           Base.Compute.RecordError("Panel is not planar and therefore cannot be converted to an FEMesh.");
           return null;
       }
       if (panel.Openings.Count > 0)
       {
           Base.Compute.RecordError("This method does not support Panels with Openings");
           return null;
       }

       List<Edge> edges = panel.ExternalEdges;
       if (edges.Count > 4)
       {
           Base.Compute.RecordError("Panel contains more than 4 Edges");
           return null;
       }

       List<Point> points = new List<Point>();
       List<ICurve> curves = new List<ICurve>();
       foreach (Edge edge in edges)
       {
           ICurve curve = edge.Curve;
           points.AddRange(curve.ControlPoints());
           curves.Add(curve);
       }
       points = points.CullDuplicates(tolerance);
       int count = points.Count;
       points = points.ISortAlongCurve(Geometry.Compute.IJoin(curves)[0]);

       Face face = new Face();
       if (count > 4)
       {
           Base.Compute.RecordError("Panel contains more than four control points.");
           return null;
       }
       if (count == 4)
       {
           face = Geometry.Create.Face(0, 1, 2, 3);
       }
       else if (count == 3)
       {
           face = Geometry.Create.Face(0, 1, 2);
       }

       List<Face> faces = new List<Face>() { face };

       Mesh mesh = Geometry.Create.Mesh(points, faces);
       FEMesh feMesh = new FEMesh();
       feMesh = Create.FEMesh(mesh, null, null, panel.Name);

       if (panel.Property != null)
       {
           feMesh.Property = panel.Property;
       }
       if (panel.Tags.Count > 0)
       {
           feMesh.Tags = panel.Tags;
       }

       return feMesh;

   }
   /***************************************************/`