Ejemplo n.º 1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Mesh ghmesh = new GH_Mesh();

            if (DA.GetData(0, ref ghmesh))
            {
                if (ghmesh == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Mesh input is null");
                }
                Mesh mesh = new Mesh();
                if (GH_Convert.ToMesh(ghmesh, ref mesh, GH_Conversion.Both))
                {
                    GsaElement2d elem = new GsaElement2d(mesh);

                    // 1 section
                    GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                    GsaProp2d        prop2d = new GsaProp2d();
                    if (DA.GetData(1, ref gh_typ))
                    {
                        if (gh_typ.Value is GsaProp2dGoo)
                        {
                            gh_typ.CastTo(ref prop2d);
                        }
                        else
                        {
                            if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                            {
                                for (int i = 0; i < elem.Elements.Count; i++)
                                {
                                    elem.Elements[i].Property = idd;
                                }
                                prop2d = null;
                            }
                            else
                            {
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer");
                                return;
                            }
                        }
                    }
                    else
                    {
                        prop2d = null;
                    }

                    List <GsaProp2d> prop2Ds = new List <GsaProp2d>();
                    for (int i = 0; i < elem.Elements.Count; i++)
                    {
                        prop2Ds.Add(prop2d);
                    }
                    elem.Properties = prop2Ds;

                    DA.SetData(0, new GsaElement2dGoo(elem));
                }
Ejemplo n.º 2
0
        public static void ConvertElement2D(GsaElement2d element2d,
                                            ref Dictionary <int, Element> existingElements, ref int elementidcounter,
                                            ref Dictionary <int, Node> existingNodes, ref int nodeidcounter,
                                            ref Dictionary <int, Prop2D> existingProp2Ds, ref Dictionary <Guid, int> prop2d_guid)
        {
            List <Point3d> meshVerticies = element2d.Topology;

            //Loop through all faces in mesh to update topology list to fit model nodes
            for (int i = 0; i < element2d.Elements.Count; i++)
            {
                Element    apiMeshElement  = element2d.Elements[i];
                List <int> meshVertexIndex = element2d.TopoInt[i];

                List <int> topo = new List <int>(); // temp topologylist

                //Loop through topology
                for (int j = 0; j < meshVertexIndex.Count; j++)
                {
                    int id = Nodes.GetExistingNodeID(existingNodes, meshVerticies[meshVertexIndex[j]]);
                    if (id > 0)
                    {
                        topo.Add(id);
                    }
                    else
                    {
                        existingNodes.Add(nodeidcounter, Nodes.NodeFromPoint(meshVerticies[meshVertexIndex[j]]));
                        topo.Add(nodeidcounter);
                        nodeidcounter++;
                    }
                }
                //update topology in Element
                apiMeshElement.Topology = new ReadOnlyCollection <int>(topo.ToList());

                // section
                if (apiMeshElement.Property == 0)
                {
                    apiMeshElement.Property = Prop2ds.ConvertProp2d(element2d.Properties[i], ref existingProp2Ds, ref prop2d_guid);
                }


                // set api element in dictionary
                if (element2d.ID[i] > 0) // if the ID is larger than 0 than means the ID has been set and we sent it to the known list
                {
                    existingElements[element2d.ID[i]] = apiMeshElement;
                }
                else
                {
                    existingElements.Add(elementidcounter, apiMeshElement);
                    elementidcounter++;
                }
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Mesh ghmesh = new GH_Mesh();

            if (DA.GetData(0, ref ghmesh))
            {
                Mesh mesh = new Mesh();
                if (GH_Convert.ToMesh(ghmesh, ref mesh, GH_Conversion.Both))
                {
                    GsaElement2d elem = new GsaElement2d(mesh);

                    // 1 section
                    GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                    GsaProp2d        prop2d = new GsaProp2d();
                    if (DA.GetData(1, ref gh_typ))
                    {
                        if (gh_typ.Value is GsaProp2d)
                        {
                            gh_typ.CastTo(ref prop2d);
                        }
                        else if (gh_typ.Value is GH_Number)
                        {
                            if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both))
                            {
                                prop2d.ID = idd;
                            }
                        }
                    }
                    else
                    {
                        prop2d.ID = 1;
                    }
                    List <GsaProp2d> prop2Ds = new List <GsaProp2d>();
                    for (int i = 0; i < elem.Elements.Count; i++)
                    {
                        prop2Ds.Add(prop2d);
                    }
                    elem.Properties = prop2Ds;

                    DA.SetData(0, new GsaElement2dGoo(elem));
                }
            }
        }
Ejemplo n.º 4
0
        public static void ConvertElement2D(List <GsaElement2d> element2ds,
                                            ref Dictionary <int, Element> existingElements, ref int elementidcounter,
                                            ref Dictionary <int, Node> existingNodes,
                                            ref Dictionary <int, Prop2D> existingProp2Ds, ref Dictionary <Guid, int> prop2d_guid,
                                            GrasshopperAsyncComponent.WorkerInstance workerInstance = null,
                                            Action <string, double> ReportProgress = null)
        {
            // create a counter for creating new elements, nodes and properties
            int nodeidcounter   = (existingNodes.Count > 0) ? existingNodes.Keys.Max() + 1 : 1;
            int prop2didcounter = (existingProp2Ds.Count > 0) ? existingProp2Ds.Keys.Max() + 1 : 1; //checking the existing model

            // Elem2ds
            if (element2ds != null)
            {
                for (int i = 0; i < element2ds.Count; i++)
                {
                    if (workerInstance != null)
                    {
                        if (workerInstance.CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }
                        ReportProgress("Elem2D ", (double)i / (element2ds.Count - 1));
                    }


                    if (element2ds[i] != null)
                    {
                        GsaElement2d element2d = element2ds[i];

                        ConvertElement2D(element2d,
                                         ref existingElements, ref elementidcounter,
                                         ref existingNodes, ref nodeidcounter,
                                         ref existingProp2Ds, ref prop2d_guid);
                    }
                }
            }
            if (workerInstance != null)
            {
                ReportProgress("Elem2D assembled", -2);
            }
        }
Ejemplo n.º 5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaElement2d gsaElement2d = new GsaElement2d();

            if (DA.GetData(0, ref gsaElement2d))
            {
                if (gsaElement2d == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Element2D input is null");
                }
                GsaElement2d elem = gsaElement2d.Duplicate();

                // #### inputs ####

                // no good way of updating location of mesh on the fly //
                // suggest users re-create from scratch //

                // 1 ID
                List <GH_Integer> ghID   = new List <GH_Integer>();
                List <int>        in_ids = new List <int>();
                if (DA.GetDataList(1, ghID))
                {
                    for (int i = 0; i < ghID.Count; i++)
                    {
                        if (i > elem.Elements.Count)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "ID input List Length is longer than number of elements." + System.Environment.NewLine + "Excess ID's have been ignored");
                            continue;
                        }
                        if (GH_Convert.ToInt32(ghID[i], out int id, GH_Conversion.Both))
                        {
                            if (in_ids.Contains(id))
                            {
                                if (id > 0)
                                {
                                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "ID input(" + i + ") = " + id + " already exist in your input list." + System.Environment.NewLine + "You must provide a list of unique IDs, or set ID = 0 if you want to let GSA handle the numbering");
                                    continue;
                                }
                            }
                            in_ids.Add(id);
                        }
                    }
                }

                // 2 section
                List <GH_ObjectWrapper> gh_types   = new List <GH_ObjectWrapper>();
                List <GsaProp2d>        in_prop2Ds = new List <GsaProp2d>();
                if (DA.GetDataList(2, gh_types))
                {
                    for (int i = 0; i < gh_types.Count; i++)
                    {
                        if (i > elem.Elements.Count)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "PA input List Length is longer than number of elements." + System.Environment.NewLine + "Excess PA's have been ignored");
                        }
                        GH_ObjectWrapper gh_typ = gh_types[i];
                        GsaProp2d        prop2d = new GsaProp2d();
                        if (gh_typ.Value is GsaProp2dGoo)
                        {
                            gh_typ.CastTo(ref prop2d);
                            in_prop2Ds.Add(prop2d);
                            elem.Elements[i].Property = 0;
                        }
                        else
                        {
                            if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                            {
                                elem.Elements[i].Property = idd;
                                elem.Properties[i]        = null;
                            }
                            else
                            {
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer");
                                return;
                            }
                        }
                    }
Ejemplo n.º 6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Brep ghbrep = new GH_Brep();

            if (DA.GetData(0, ref ghbrep))
            {
                if (ghbrep == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Brep input is null");
                }
                Brep brep = new Brep();
                if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both))
                {
                    // 1 Points
                    List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>();
                    List <Point3d>          pts      = new List <Point3d>();
                    List <GsaNode>          nodes    = new List <GsaNode>();
                    if (DA.GetDataList(1, gh_types))
                    {
                        for (int i = 0; i < gh_types.Count; i++)
                        {
                            Point3d pt = new Point3d();
                            if (gh_types[i].Value is GsaNodeGoo)
                            {
                                GsaNode gsanode = new GsaNode();
                                gh_types[i].CastTo(ref gsanode);
                                nodes.Add(gsanode);
                            }
                            else if (GH_Convert.ToPoint3d(gh_types[i].Value, ref pt, GH_Conversion.Both))
                            {
                                pts.Add(pt);
                            }
                            else
                            {
                                string type = gh_types[i].Value.GetType().ToString();
                                type = type.Replace("GhSA.Parameters.", "");
                                type = type.Replace("Goo", "");
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert incl. Point/Node input parameter of type " +
                                                  type + " to point or node");
                            }
                        }
                    }

                    // 2 Curves
                    gh_types = new List <GH_ObjectWrapper>();
                    List <Curve>       crvs   = new List <Curve>();
                    List <GsaMember1d> mem1ds = new List <GsaMember1d>();
                    if (DA.GetDataList(2, gh_types))
                    {
                        for (int i = 0; i < gh_types.Count; i++)
                        {
                            Curve crv = null;
                            if (gh_types[i].Value is GsaMember1dGoo)
                            {
                                GsaMember1d gsamem1d = new GsaMember1d();
                                gh_types[i].CastTo(ref gsamem1d);
                                mem1ds.Add(gsamem1d);
                            }
                            else if (GH_Convert.ToCurve(gh_types[i].Value, ref crv, GH_Conversion.Both))
                            {
                                crvs.Add(crv);
                            }
                            else
                            {
                                string type = gh_types[i].Value.GetType().ToString();
                                type = type.Replace("GhSA.Parameters.", "");
                                type = type.Replace("Goo", "");
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert incl. Curve/Mem1D input parameter of type " +
                                                  type + " to curve or 1D Member");
                            }
                        }
                    }

                    // 4 mesh size
                    GH_Number ghmsz    = new GH_Number();
                    double    meshSize = 0;
                    if (DA.GetData(4, ref ghmsz))
                    {
                        GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both);
                        meshSize = m_size;
                    }

                    // build new element2d with brep, crv and pts
                    GsaElement2d elem2d = new GsaElement2d(brep, crvs, pts, meshSize, mem1ds, nodes);

                    // 3 section
                    GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                    GsaProp2d        prop2d = new GsaProp2d();
                    if (DA.GetData(3, ref gh_typ))
                    {
                        if (gh_typ.Value is GsaProp2dGoo)
                        {
                            gh_typ.CastTo(ref prop2d);
                        }
                        else
                        {
                            if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                            {
                                prop2d.ID = idd;
                            }
                            else
                            {
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer");
                                return;
                            }
                        }
                    }
                    else
                    {
                        prop2d.ID = 1;
                    }
                    List <GsaProp2d> prop2Ds = new List <GsaProp2d>();
                    for (int i = 0; i < elem2d.Elements.Count; i++)
                    {
                        prop2Ds.Add(prop2d);
                    }
                    elem2d.Properties = prop2Ds;

                    DA.SetData(0, new GsaElement2dGoo(elem2d));
                }
Ejemplo n.º 7
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            #region GetData
            Models            = null;
            Nodes             = null;
            Elem1ds           = null;
            Elem2ds           = null;
            Elem3ds           = null;
            Mem1ds            = null;
            Mem2ds            = null;
            Mem3ds            = null;
            Loads             = null;
            Sections          = null;
            Prop2Ds           = null;
            GridPlaneSurfaces = null;

            // Get Model input
            List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>();
            if (DA.GetDataList(0, gh_types))
            {
                List <GsaModel> in_models = new List <GsaModel>();
                for (int i = 0; i < gh_types.Count; i++)
                {
                    GH_ObjectWrapper gh_typ = gh_types[i];
                    if (gh_typ == null)
                    {
                        Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input is null"); return;
                    }
                    if (gh_typ.Value is GsaModelGoo)
                    {
                        GsaModel in_model = new GsaModel();
                        gh_typ.CastTo(ref in_model);
                        in_models.Add(in_model);
                    }
                    else
                    {
                        string type = gh_typ.Value.GetType().ToString();
                        type = type.Replace("GhSA.Parameters.", "");
                        type = type.Replace("Goo", "");
                        Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert GSA input parameter of type " +
                                                       type + " to GsaModel");
                        return;
                    }
                }
                Models = in_models;
            }

            // Get Section Property input
            gh_types = new List <GH_ObjectWrapper>();
            if (DA.GetDataList(1, gh_types))
            {
                List <GsaSection> in_sect = new List <GsaSection>();
                List <GsaProp2d>  in_prop = new List <GsaProp2d>();
                for (int i = 0; i < gh_types.Count; i++)
                {
                    GH_ObjectWrapper gh_typ = gh_types[i];
                    if (gh_typ.Value is GsaSectionGoo)
                    {
                        GsaSection gsasection = new GsaSection();
                        gh_typ.CastTo(ref gsasection);
                        in_sect.Add(gsasection.Duplicate());
                    }
                    else if (gh_typ.Value is GsaProp2dGoo)
                    {
                        GsaProp2d gsaprop = new GsaProp2d();
                        gh_typ.CastTo(ref gsaprop);
                        in_prop.Add(gsaprop.Duplicate());
                    }
                    else
                    {
                        string type = gh_typ.Value.GetType().ToString();
                        type = type.Replace("GhSA.Parameters.", "");
                        type = type.Replace("Goo", "");
                        Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Prop input parameter of type " +
                                                       type + " to GsaSection or GsaProp2d");
                        return;
                    }
                }
                if (in_sect.Count > 0)
                {
                    Sections = in_sect;
                }
                if (in_prop.Count > 0)
                {
                    Prop2Ds = in_prop;
                }
            }

            // Get Geometry input
            gh_types = new List <GH_ObjectWrapper>();
            List <GsaNode>      in_nodes   = new List <GsaNode>();
            List <GsaElement1d> in_elem1ds = new List <GsaElement1d>();
            List <GsaElement2d> in_elem2ds = new List <GsaElement2d>();
            List <GsaElement3d> in_elem3ds = new List <GsaElement3d>();
            List <GsaMember1d>  in_mem1ds  = new List <GsaMember1d>();
            List <GsaMember2d>  in_mem2ds  = new List <GsaMember2d>();
            List <GsaMember3d>  in_mem3ds  = new List <GsaMember3d>();
            if (DA.GetDataList(2, gh_types))
            {
                for (int i = 0; i < gh_types.Count; i++)
                {
                    GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                    gh_typ = gh_types[i];
                    if (gh_typ.Value is GsaNodeGoo)
                    {
                        GsaNode gsanode = new GsaNode();
                        gh_typ.CastTo(ref gsanode);
                        in_nodes.Add(gsanode.Duplicate());
                    }
                    else if (gh_typ.Value is GsaElement1dGoo)
                    {
                        GsaElement1d gsaelem1 = new GsaElement1d();
                        gh_typ.CastTo(ref gsaelem1);
                        in_elem1ds.Add(gsaelem1.Duplicate());
                    }
                    else if (gh_typ.Value is GsaElement2dGoo)
                    {
                        GsaElement2d gsaelem2 = new GsaElement2d();
                        gh_typ.CastTo(ref gsaelem2);
                        in_elem2ds.Add(gsaelem2.Duplicate());
                    }
                    else if (gh_typ.Value is GsaElement3dGoo)
                    {
                        GsaElement3d gsaelem3 = new GsaElement3d();
                        gh_typ.CastTo(ref gsaelem3);
                        in_elem3ds.Add(gsaelem3.Duplicate());
                    }
                    else if (gh_typ.Value is GsaMember1dGoo)
                    {
                        GsaMember1d gsamem1 = new GsaMember1d();
                        gh_typ.CastTo(ref gsamem1);
                        in_mem1ds.Add(gsamem1.Duplicate());
                    }
                    else if (gh_typ.Value is GsaMember2dGoo)
                    {
                        GsaMember2d gsamem2 = new GsaMember2d();
                        gh_typ.CastTo(ref gsamem2);
                        in_mem2ds.Add(gsamem2.Duplicate());
                    }
                    else if (gh_typ.Value is GsaMember3dGoo)
                    {
                        GsaMember3d gsamem3 = new GsaMember3d();
                        gh_typ.CastTo(ref gsamem3);
                        in_mem3ds.Add(gsamem3.Duplicate());
                    }
                    else
                    {
                        string type = gh_typ.Value.GetType().ToString();
                        type = type.Replace("GhSA.Parameters.", "");
                        type = type.Replace("Goo", "");
                        Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input parameter of type " +
                                                       type + System.Environment.NewLine + " to Node, Element1D, Element2D, Element3D, Member1D, Member2D or Member3D");
                        return;
                    }
                }
                if (in_nodes.Count > 0)
                {
                    Nodes = in_nodes;
                }
                if (in_elem1ds.Count > 0)
                {
                    Elem1ds = in_elem1ds;
                }
                if (in_elem2ds.Count > 0)
                {
                    Elem2ds = in_elem2ds;
                }
                if (in_elem3ds.Count > 0)
                {
                    Elem3ds = in_elem3ds;
                }
                if (in_mem1ds.Count > 0)
                {
                    Mem1ds = in_mem1ds;
                }
                if (in_mem2ds.Count > 0)
                {
                    Mem2ds = in_mem2ds;
                }
                if (in_mem3ds.Count > 0)
                {
                    Mem3ds = in_mem3ds;
                }
            }


            // Get Loads input
            gh_types = new List <GH_ObjectWrapper>();
            if (DA.GetDataList(3, gh_types))
            {
                List <GsaLoad>             in_loads = new List <GsaLoad>();
                List <GsaGridPlaneSurface> in_gps   = new List <GsaGridPlaneSurface>();
                for (int i = 0; i < gh_types.Count; i++)
                {
                    GH_ObjectWrapper gh_typ = gh_types[i];
                    if (gh_typ.Value is GsaLoadGoo)
                    {
                        GsaLoad gsaload = null;
                        gh_typ.CastTo(ref gsaload);
                        in_loads.Add(gsaload.Duplicate());
                    }
                    else if (gh_typ.Value is GsaGridPlaneSurfaceGoo)
                    {
                        GsaGridPlaneSurface gsaGPS = new GsaGridPlaneSurface();
                        gh_typ.CastTo(ref gsaGPS);
                        in_gps.Add(gsaGPS.Duplicate());
                    }
                    else
                    {
                        string type = gh_typ.Value.GetType().ToString();
                        type = type.Replace("GhSA.Parameters.", "");
                        type = type.Replace("Goo", "");
                        Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Load input parameter of type " +
                                                       type + " to Load or GridPlaneSurface");
                        return;
                    }
                }
                if (in_loads.Count > 0)
                {
                    Loads = in_loads;
                }
                if (in_gps.Count > 0)
                {
                    GridPlaneSurfaces = in_gps;
                }
            }
            // manually add a warning if no input is set, as all inputs are optional
            if (Models == null & Nodes == null & Elem1ds == null & Elem2ds == null &
                Mem1ds == null & Mem2ds == null & Mem3ds == null & Sections == null
                & Prop2Ds == null & Loads == null & GridPlaneSurfaces == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data");
                return;
            }

            #endregion

            #region DoWork
            GsaModel analysisModel = null;
            if (Models != null)
            {
                if (Models.Count > 0)
                {
                    if (Models.Count > 1)
                    {
                        analysisModel = Util.Gsa.ToGSA.Models.MergeModel(Models);
                    }
                    else
                    {
                        analysisModel = Models[0].Clone();
                    }
                }
            }
            if (analysisModel != null)
            {
                OutModel = analysisModel;
            }
            else
            {
                OutModel = new GsaModel();
            }

            // Assemble model
            Model gsa = Util.Gsa.ToGSA.Assemble.AssembleModel(analysisModel, Nodes, Elem1ds, Elem2ds, Elem3ds, Mem1ds, Mem2ds, Mem3ds, Sections, Prop2Ds, Loads, GridPlaneSurfaces);
            //gsa.SaveAs(@"C:\Users\Kristjan.Nielsen\Desktop\test3.gwb");
            #region meshing
            // Create elements from members
            gsa.CreateElementsFromMembers();
            #endregion

            #region analysis

            //analysis
            IReadOnlyDictionary <int, AnalysisTask> gsaTasks = gsa.AnalysisTasks();
            if (gsaTasks.Count < 1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Model contains no Analysis Tasks");
            }

            foreach (KeyValuePair <int, AnalysisTask> task in gsaTasks)
            {
                if (!(gsa.Analyse(task.Key)))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Warning Analysis Case " + task.Key + " could not be analysed");
                }
            }

            #endregion
            OutModel.Model = gsa;

            //gsa.SaveAs("C:\\Users\\Kristjan.Nielsen\\Desktop\\GsaGH_test.gwb");
            #endregion

            #region SetData
            DA.SetData(0, new GsaModelGoo(OutModel));
            #endregion
        }
Ejemplo n.º 8
0
            public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
            {
                #region GetData
                Models            = null;
                Nodes             = null;
                Elem1ds           = null;
                Elem2ds           = null;
                Elem3ds           = null;
                Mem1ds            = null;
                Mem2ds            = null;
                Mem3ds            = null;
                Loads             = null;
                Sections          = null;
                Prop2Ds           = null;
                GridPlaneSurfaces = null;
                OutModel          = null;
                component         = Params.Owner;

                // Get Model input
                List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>();
                if (DA.GetDataList(0, gh_types))
                {
                    List <GsaModel> in_models = new List <GsaModel>();
                    for (int i = 0; i < gh_types.Count; i++)
                    {
                        if (gh_types[i] == null)
                        {
                            return;
                        }
                        GH_ObjectWrapper gh_typ = gh_types[i];
                        if (gh_typ.Value is GsaModelGoo)
                        {
                            GsaModel in_model = new GsaModel();
                            gh_typ.CastTo(ref in_model);
                            in_models.Add(in_model);
                        }
                        else
                        {
                            string type = gh_typ.Value.GetType().ToString();
                            type = type.Replace("GhSA.Parameters.", "");
                            type = type.Replace("Goo", "");
                            Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert GSA input parameter of type " +
                                                           type + " to GsaModel");
                            return;
                        }
                    }
                    Models = in_models;
                }

                // Get Section Property input
                gh_types = new List <GH_ObjectWrapper>();
                if (DA.GetDataList(1, gh_types))
                {
                    List <GsaSection> in_sect = new List <GsaSection>();
                    List <GsaProp2d>  in_prop = new List <GsaProp2d>();
                    for (int i = 0; i < gh_types.Count; i++)
                    {
                        if (gh_types[i] == null)
                        {
                            return;
                        }
                        GH_ObjectWrapper gh_typ = gh_types[i];
                        if (gh_typ.Value is GsaSectionGoo)
                        {
                            GsaSection gsasection = new GsaSection();
                            gh_typ.CastTo(ref gsasection);
                            in_sect.Add(gsasection.Duplicate());
                        }
                        else if (gh_typ.Value is GsaProp2dGoo)
                        {
                            GsaProp2d gsaprop = new GsaProp2d();
                            gh_typ.CastTo(ref gsaprop);
                            in_prop.Add(gsaprop.Duplicate());
                        }
                        else
                        {
                            string type = gh_typ.Value.GetType().ToString();
                            type = type.Replace("GhSA.Parameters.", "");
                            type = type.Replace("Goo", "");
                            Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Prop input parameter of type " +
                                                           type + " to GsaSection or GsaProp2d");
                            return;
                        }
                    }
                    if (in_sect.Count > 0)
                    {
                        Sections = in_sect;
                    }
                    if (in_prop.Count > 0)
                    {
                        Prop2Ds = in_prop;
                    }
                }

                // Get Geometry input
                gh_types = new List <GH_ObjectWrapper>();
                List <GsaNode>      in_nodes   = new List <GsaNode>();
                List <GsaElement1d> in_elem1ds = new List <GsaElement1d>();
                List <GsaElement2d> in_elem2ds = new List <GsaElement2d>();
                List <GsaElement3d> in_elem3ds = new List <GsaElement3d>();
                List <GsaMember1d>  in_mem1ds  = new List <GsaMember1d>();
                List <GsaMember2d>  in_mem2ds  = new List <GsaMember2d>();
                List <GsaMember3d>  in_mem3ds  = new List <GsaMember3d>();
                if (DA.GetDataList(2, gh_types))
                {
                    for (int i = 0; i < gh_types.Count; i++)
                    {
                        if (gh_types[i] == null)
                        {
                            return;
                        }
                        GH_ObjectWrapper gh_typ = gh_types[i];
                        if (gh_typ.Value is GsaNodeGoo)
                        {
                            GsaNode gsanode = new GsaNode();
                            gh_typ.CastTo(ref gsanode);
                            in_nodes.Add(gsanode.Duplicate());
                        }
                        else if (gh_typ.Value is GsaElement1dGoo)
                        {
                            GsaElement1d gsaelem1 = new GsaElement1d();
                            gh_typ.CastTo(ref gsaelem1);
                            in_elem1ds.Add(gsaelem1.Duplicate());
                        }
                        else if (gh_typ.Value is GsaElement2dGoo)
                        {
                            GsaElement2d gsaelem2 = new GsaElement2d();
                            gh_typ.CastTo(ref gsaelem2);
                            in_elem2ds.Add(gsaelem2.Duplicate());
                        }
                        else if (gh_typ.Value is GsaElement3dGoo)
                        {
                            GsaElement3d gsaelem3 = new GsaElement3d();
                            gh_typ.CastTo(ref gsaelem3);
                            in_elem3ds.Add(gsaelem3.Duplicate());
                        }
                        else if (gh_typ.Value is GsaMember1dGoo)
                        {
                            GsaMember1d gsamem1 = new GsaMember1d();
                            gh_typ.CastTo(ref gsamem1);
                            in_mem1ds.Add(gsamem1.Duplicate());
                        }
                        else if (gh_typ.Value is GsaMember2dGoo)
                        {
                            GsaMember2d gsamem2 = new GsaMember2d();
                            gh_typ.CastTo(ref gsamem2);
                            in_mem2ds.Add(gsamem2.Duplicate());
                        }
                        else if (gh_typ.Value is GsaMember3dGoo)
                        {
                            GsaMember3d gsamem3 = new GsaMember3d();
                            gh_typ.CastTo(ref gsamem3);
                            in_mem3ds.Add(gsamem3.Duplicate());
                        }
                        else
                        {
                            string type = gh_typ.Value.GetType().ToString();
                            type = type.Replace("GhSA.Parameters.", "");
                            type = type.Replace("Goo", "");
                            Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input parameter of type " +
                                                           type + System.Environment.NewLine + " to Node, Element1D, Element2D, Element3D, Member1D, Member2D or Member3D");
                            return;
                        }
                    }
                    if (in_nodes.Count > 0)
                    {
                        Nodes = in_nodes;
                    }
                    if (in_elem1ds.Count > 0)
                    {
                        Elem1ds = in_elem1ds;
                    }
                    if (in_elem2ds.Count > 0)
                    {
                        Elem2ds = in_elem2ds;
                    }
                    if (in_elem3ds.Count > 0)
                    {
                        Elem3ds = in_elem3ds;
                    }
                    if (in_mem1ds.Count > 0)
                    {
                        Mem1ds = in_mem1ds;
                    }
                    if (in_mem2ds.Count > 0)
                    {
                        Mem2ds = in_mem2ds;
                    }
                    if (in_mem3ds.Count > 0)
                    {
                        Mem3ds = in_mem3ds;
                    }
                }


                // Get Loads input
                gh_types = new List <GH_ObjectWrapper>();
                if (DA.GetDataList(3, gh_types))
                {
                    List <GsaLoad>             in_loads = new List <GsaLoad>();
                    List <GsaGridPlaneSurface> in_gps   = new List <GsaGridPlaneSurface>();
                    for (int i = 0; i < gh_types.Count; i++)
                    {
                        if (gh_types[i] == null)
                        {
                            return;
                        }
                        GH_ObjectWrapper gh_typ = gh_types[i];
                        if (gh_typ.Value is GsaLoadGoo)
                        {
                            GsaLoad gsaload = null;
                            gh_typ.CastTo(ref gsaload);
                            in_loads.Add(gsaload.Duplicate());
                        }
                        else if (gh_typ.Value is GsaGridPlaneSurfaceGoo)
                        {
                            GsaGridPlaneSurface gsaGPS = new GsaGridPlaneSurface();
                            gh_typ.CastTo(ref gsaGPS);
                            in_gps.Add(gsaGPS.Duplicate());
                        }
                        else
                        {
                            string type = gh_typ.Value.GetType().ToString();
                            type = type.Replace("GhSA.Parameters.", "");
                            type = type.Replace("Goo", "");
                            Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Load input parameter of type " +
                                                           type + " to Load or GridPlaneSurface");
                            return;
                        }
                    }
                    if (in_loads.Count > 0)
                    {
                        Loads = in_loads;
                    }
                    if (in_gps.Count > 0)
                    {
                        GridPlaneSurfaces = in_gps;
                    }
                }

                #endregion

                // manually add a warning if no input is set, as all inputs are optional
                if (Models == null & Nodes == null & Elem1ds == null & Elem2ds == null &
                    Mem1ds == null & Mem2ds == null & Mem3ds == null & Sections == null
                    & Prop2Ds == null & Loads == null & GridPlaneSurfaces == null)
                {
                    hasInput = false;
                    Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data");
                    return;
                }
                else
                {
                    hasInput = true;
                }
            }
Ejemplo n.º 9
0
        public void TestCreateGsaElem2dFromMesh()
        {
            // create a list of corner points
            List <Point3d> pts = new List <Point3d>();

            pts.Add(new Point3d(-3, -4, 0));
            pts.Add(new Point3d(5, -2, 0));
            pts.Add(new Point3d(6, 7, 0));
            pts.Add(new Point3d(-1, 2, 0));
            pts.Add(pts[0]);                  // add initial point to close curve
            Polyline pol = new Polyline(pts); // create edge-crv from pts

            // create mesh from boundary curve
            Mesh mesh = Mesh.CreateFromPlanarBoundary(pol.ToPolylineCurve(), MeshingParameters.DefaultAnalysisMesh, 0.001);

            // create element
            GsaElement2d elem = new GsaElement2d(mesh);

            // set some element class members
            int elid  = 14;
            int secid = 3;

            for (int i = 0; i < elem.Elements.Count; i++)
            {
                elem.ID[i] = elid++;
                elem.Properties.Add(new GsaProp2d());
                elem.Properties[i].ID     = secid++;
                elem.Elements[i].Group    = 22;
                elem.Elements[i].IsDummy  = true;
                elem.Elements[i].Name     = "Shahin";
                elem.Elements[i].Offset.Z = 0.1;
                elem.Elements[i].Property = 3;
            }

            // check that topology responds to mesh verticies
            for (int i = 0; i < elem.Topology.Count; i++)
            {
                Assert.AreEqual(mesh.Vertices[i].X, elem.Topology[i].X);
                Assert.AreEqual(mesh.Vertices[i].Y, elem.Topology[i].Y);
                Assert.AreEqual(mesh.Vertices[i].Z, elem.Topology[i].Z);
            }

            // loop through all elements and make checks
            int chelid  = 14;
            int chsecid = 3;

            for (int i = 0; i < elem.Elements.Count; i++)
            {
                // check that element is tri or quad corrosponding to mesh face
                if (mesh.Faces[i].IsTriangle)
                {
                    Assert.IsTrue(elem.Elements[i].Type == ElementType.TRI3);
                }
                if (mesh.Faces[i].IsQuad)
                {
                    Assert.IsTrue(elem.Elements[i].Type == ElementType.QUAD4);
                }

                // check topology int indexing references the right topology points
                Point3d mPt = mesh.Vertices[mesh.Faces[i].A];    // face corner A pt
                Point3d ePt = elem.Topology[elem.TopoInt[i][0]]; // topology first pt
                Assert.AreEqual(mPt.X, ePt.X);
                Assert.AreEqual(mPt.Y, ePt.Y);
                Assert.AreEqual(mPt.Z, ePt.Z);

                mPt = mesh.Vertices[mesh.Faces[i].B];    // face corner B pt
                ePt = elem.Topology[elem.TopoInt[i][1]]; // topology second pt
                Assert.AreEqual(mPt.X, ePt.X);
                Assert.AreEqual(mPt.Y, ePt.Y);
                Assert.AreEqual(mPt.Z, ePt.Z);

                mPt = mesh.Vertices[mesh.Faces[i].C];    // face corner C pt
                ePt = elem.Topology[elem.TopoInt[i][2]]; // topology third pt
                Assert.AreEqual(mPt.X, ePt.X);
                Assert.AreEqual(mPt.Y, ePt.Y);
                Assert.AreEqual(mPt.Z, ePt.Z);

                if (elem.Elements[i].Type == ElementType.QUAD4)
                {
                    mPt = mesh.Vertices[mesh.Faces[i].D];    // face corner D pt
                    ePt = elem.Topology[elem.TopoInt[i][3]]; // topology fourth pt
                    Assert.AreEqual(mPt.X, ePt.X);
                    Assert.AreEqual(mPt.Y, ePt.Y);
                    Assert.AreEqual(mPt.Z, ePt.Z);
                }

                // check other members are valid
                Assert.AreEqual(chelid++, elem.ID[i]);
                Assert.AreEqual(chsecid++, elem.Properties[i].ID);
                Assert.AreEqual(22, elem.Elements[i].Group);
                Assert.IsTrue(elem.Elements[i].IsDummy);
                Assert.AreEqual("Shahin", elem.Elements[i].Name);
                Assert.AreEqual(0.1, elem.Elements[i].Offset.Z);
                Assert.AreEqual(3, elem.Elements[i].Property);
            }
        }
Ejemplo n.º 10
0
        public void TestDuplicateElem2d()
        {
            // create a list of corner points
            List <Point3d> pts = new List <Point3d>();

            pts.Add(new Point3d(0, 0, 0));
            pts.Add(new Point3d(0, 5, 0));
            pts.Add(new Point3d(5, 5, 0));
            pts.Add(new Point3d(5, 0, 0));
            pts.Add(pts[0]);                  // add initial point to close curve
            Polyline pol = new Polyline(pts); // create edge-crv from pts

            // create mesh from boundary curve
            Mesh mesh = Mesh.CreateFromPlanarBoundary(pol.ToPolylineCurve(), MeshingParameters.DefaultAnalysisMesh, 0.001);

            // create element
            GsaElement2d origi = new GsaElement2d(mesh);

            // set some element class members
            int elid  = 3;
            int secid = 4;

            for (int i = 0; i < origi.Elements.Count; i++)
            {
                origi.ID[i] = elid++;
                origi.Properties.Add(new GsaProp2d());
                origi.Properties[i].ID     = secid++;
                origi.Elements[i].Group    = 2;
                origi.Elements[i].IsDummy  = false;
                origi.Elements[i].Name     = "Esmaeil";
                origi.Elements[i].Offset.Z = -0.15;
                origi.Elements[i].Property = 1;
            }

            // create duplicate
            GsaElement2d dup = origi.Duplicate();

            // check that topology responds to duplicated mesh verticies
            for (int i = 0; i < dup.Topology.Count; i++)
            {
                Assert.AreEqual(mesh.Vertices[i].X, dup.Topology[i].X);
                Assert.AreEqual(mesh.Vertices[i].Y, dup.Topology[i].Y);
                Assert.AreEqual(mesh.Vertices[i].Z, origi.Topology[i].Z);
            }

            // loop through all elements and make on duplicated geometry
            for (int i = 0; i < dup.Elements.Count; i++)
            {
                // check that element is tri or quad corrosponding to mesh face
                if (mesh.Faces[i].IsTriangle)
                {
                    Assert.IsTrue(dup.Elements[i].Type == ElementType.TRI3);
                }
                if (mesh.Faces[i].IsQuad)
                {
                    Assert.IsTrue(dup.Elements[i].Type == ElementType.QUAD4);
                }

                // check topology int indexing references the right topology points
                Point3d mPt = mesh.Vertices[mesh.Faces[i].A];  // face corner A pt
                Point3d ePt = dup.Topology[dup.TopoInt[i][0]]; // topology first pt
                Assert.AreEqual(mPt.X, ePt.X);
                Assert.AreEqual(mPt.Y, ePt.Y);
                Assert.AreEqual(mPt.Z, ePt.Z);

                mPt = mesh.Vertices[mesh.Faces[i].B];  // face corner B pt
                ePt = dup.Topology[dup.TopoInt[i][1]]; // topology second pt
                Assert.AreEqual(mPt.X, ePt.X);
                Assert.AreEqual(mPt.Y, ePt.Y);
                Assert.AreEqual(mPt.Z, ePt.Z);

                mPt = mesh.Vertices[mesh.Faces[i].C];  // face corner C pt
                ePt = dup.Topology[dup.TopoInt[i][2]]; // topology third pt
                Assert.AreEqual(mPt.X, ePt.X);
                Assert.AreEqual(mPt.Y, ePt.Y);
                Assert.AreEqual(mPt.Z, ePt.Z);

                if (dup.Elements[i].Type == ElementType.QUAD4)
                {
                    mPt = mesh.Vertices[mesh.Faces[i].D];  // face corner D pt
                    ePt = dup.Topology[dup.TopoInt[i][3]]; // topology fourth pt
                    Assert.AreEqual(mPt.X, ePt.X);
                    Assert.AreEqual(mPt.Y, ePt.Y);
                    Assert.AreEqual(mPt.Z, ePt.Z);
                }
            }

            // make some changes to original
            elid  = 15;
            secid = 16;
            for (int i = 0; i < origi.Elements.Count; i++)
            {
                origi.ID[i]                = elid++;
                origi.Properties[i].ID     = secid++;
                origi.Elements[i].Group    = 4;
                origi.Elements[i].IsDummy  = true;
                origi.Elements[i].Name     = "Mani";
                origi.Elements[i].Offset.Z = -0.17;
                origi.Elements[i].Property = 2;
            }

            // check that duplicate maintains values
            int chelid  = 3;
            int chsecid = 4;

            for (int i = 0; i < dup.Elements.Count; i++)
            {
                // check other members are valid
                Assert.AreEqual(chelid++, dup.ID[i]);
                Assert.AreEqual(chsecid++, dup.Properties[i].ID);
                Assert.AreEqual(2, dup.Elements[i].Group);
                Assert.IsFalse(dup.Elements[i].IsDummy);
                Assert.AreEqual("Esmaeil", dup.Elements[i].Name);
                Assert.AreEqual(-0.15, dup.Elements[i].Offset.Z);
                Assert.AreEqual(1, dup.Elements[i].Property);
            }

            // check that values in original are changed
            chelid  = 15;
            chsecid = 16;
            for (int i = 0; i < origi.Elements.Count; i++)
            {
                // check other members are valid
                Assert.AreEqual(chelid++, origi.ID[i]);
                Assert.AreEqual(chsecid++, origi.Properties[i].ID);
                Assert.AreEqual(4, origi.Elements[i].Group);
                Assert.IsTrue(origi.Elements[i].IsDummy);
                Assert.AreEqual("Mani", origi.Elements[i].Name);
                Assert.AreEqual(-0.17, origi.Elements[i].Offset.Z);
                Assert.AreEqual(2, origi.Elements[i].Property);
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaElement2d gsaElement2d = new GsaElement2d();

            if (DA.GetData(0, ref gsaElement2d))
            {
                GsaElement2d elem = gsaElement2d.Duplicate();

                // #### inputs ####

                // no good way of updating location of mesh on the fly //
                // suggest users re-create from scratch //

                // 1 section
                List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>();
                if (DA.GetDataList(2, gh_types))
                {
                    for (int i = 0; i < gh_types.Count; i++)
                    {
                        GH_ObjectWrapper gh_typ = gh_types[i];
                        GsaProp2d        prop2d = new GsaProp2d();
                        if (gh_typ.Value is GsaProp2d)
                        {
                            gh_typ.CastTo(ref prop2d);
                        }
                        else if (gh_typ.Value is GH_Number)
                        {
                            if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both))
                            {
                                prop2d.ID = idd;
                            }
                        }
                        List <GsaProp2d> prop2Ds = new List <GsaProp2d>();
                        for (int j = 0; j < elem.Elements.Count; j++)
                        {
                            prop2Ds.Add(prop2d);
                        }
                        elem.Properties = prop2Ds;
                    }
                }


                // 2 offset
                List <GsaOffset> offset = new List <GsaOffset>();
                if (DA.GetDataList(2, offset))
                {
                    for (int i = 0; i < offset.Count; i++)
                    {
                        elem.Elements[i].Offset.Z = offset[i].Z;
                    }
                }

                // 3 element type / analysis order
                List <GH_Integer> ghinteg = new List <GH_Integer>();
                if (DA.GetDataList(3, ghinteg))
                {
                    for (int i = 0; i < ghinteg.Count; i++)
                    {
                        if (GH_Convert.ToInt32(ghinteg[i], out int type, GH_Conversion.Both))
                        {
                            //elem.Elements[i].Type = Util.Gsa.GsaToModel.Element2dType(type); Note: Type on 2D element should be analysis order - GsaAPI bug?
                        }
                    }
                }

                // 4 ID
                List <GH_Integer> ghID = new List <GH_Integer>();
                if (DA.GetDataList(4, ghID))
                {
                    for (int i = 0; i < ghID.Count; i++)
                    {
                        if (GH_Convert.ToInt32(ghID[i], out int id, GH_Conversion.Both))
                        {
                            elem.ID[i] = id;
                        }
                    }
                }

                // 5 name
                List <GH_String> ghnm = new List <GH_String>();
                if (DA.GetDataList(5, ghnm))
                {
                    for (int i = 0; i < ghnm.Count; i++)
                    {
                        if (GH_Convert.ToString(ghnm[i], out string name, GH_Conversion.Both))
                        {
                            elem.Elements[i].Name = name;
                        }
                    }
                }

                // 6 Group
                List <GH_Integer> ghgrp = new List <GH_Integer>();
                if (DA.GetDataList(6, ghgrp))
                {
                    for (int i = 0; i < ghgrp.Count; i++)
                    {
                        if (GH_Convert.ToInt32(ghgrp[i], out int grp, GH_Conversion.Both))
                        {
                            elem.Elements[i].Group = grp;
                        }
                    }
                }

                // 7 Colour
                List <GH_Colour> ghcol = new List <GH_Colour>();
                if (DA.GetDataList(7, ghcol))
                {
                    for (int i = 0; i < ghcol.Count; i++)
                    {
                        if (GH_Convert.ToColor(ghcol[i], out System.Drawing.Color col, GH_Conversion.Both))
                        {
                            elem.Elements[i].Colour = col;
                        }
                    }
                }


                // #### outputs ####

                DA.SetData(0, new GsaElement2dGoo(elem));
                DA.SetData(1, elem.Mesh);

                List <GsaOffset> offsets = new List <GsaOffset>();
                //List<int> anal = new List<int>();
                List <string> names  = new List <string>();
                List <int>    groups = new List <int>();
                List <System.Drawing.Color> colours = new List <System.Drawing.Color>();
                List <int> pmems = new List <int>();
                for (int i = 0; i < elem.Elements.Count; i++)
                {
                    GsaOffset offset1 = new GsaOffset
                    {
                        Z = elem.Elements[i].Offset.Z
                    };
                    offsets.Add(offset1);
                    //anal.Add(gsaElement2d.Elements[i].Type);
                    names.Add(elem.Elements[i].Name);
                    groups.Add(elem.Elements[i].Group);
                    colours.Add((System.Drawing.Color)elem.Elements[i].Colour);
                    try { pmems.Add(elem.Elements[i].ParentMember.Member); } catch (Exception) { pmems.Add(0); }
                    ;
                }
                DA.SetDataList(2, elem.Properties);
                DA.SetDataList(3, offsets);
                //DA.SetDataList(4, anal);
                DA.SetDataList(5, elem.ID);
                DA.SetDataList(6, names);
                DA.SetDataList(7, groups);
                DA.SetDataList(8, colours);
                DA.SetDataList(9, pmems);
            }
        }
        /// <summary>
        /// Method to import 1D and 2D Elements from a GSA model.
        /// Will output a tuple of GhSA GsaElement1d and GsaElement2d.
        /// Filter elements to import using elemList input;
        /// "all" or empty string ("") will import all elements. Default is "all"
        /// "Join" bool = true; will try to join 2D element mesh faces into a joined meshes.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="elemList"></param>
        /// <param name="join"></param>
        /// <returns></returns>
        public static Tuple <DataTree <GsaElement1dGoo>, DataTree <GsaElement2dGoo> > GsaGetElem(Model model, string elemList = "all", bool join = true)
        {
            // Create dictionaries to read list of elements and nodes:
            IReadOnlyDictionary <int, Element> eDict;

            eDict = model.Elements(elemList);
            IReadOnlyDictionary <int, Node> nDict;

            nDict = model.Nodes("all");
            IReadOnlyDictionary <int, Section> sDict;

            sDict = model.Sections();
            IReadOnlyDictionary <int, Prop2D> pDict;

            pDict = model.Prop2Ds();

            GsaElement2d elem2d = new GsaElement2d();

            // Create lists for Rhino lines and meshes
            DataTree <GsaElement1dGoo> elem1ds  = new DataTree <GsaElement1dGoo>();
            DataTree <GsaElement2dGoo> elem2ds  = new DataTree <GsaElement2dGoo>();
            DataTree <Element>         elements = new DataTree <Element>();
            DataTree <Mesh>            meshes   = new DataTree <Mesh>();
            List <Point3d>             pts      = new List <Point3d>();

            GH_Path path = new GH_Path();

            if (!join)
            {
                elem1ds.EnsurePath(0);
                elem2ds.EnsurePath(0);
                int max = eDict.Count;
                if (max > 0)
                {
                    //elem1ds.Branches[0].. = new List<GsaElement1dGoo>(max);
                    //elem2ds.Branches[0] = new List<GsaElement2dGoo>(max);
                    //for (int i = 0; i < eDict.Keys.ElementAt(max - 1); i++)
                    //{
                    //    elem1ds.Branches[0].Add(null);
                    //    elem2ds.Branches[0].Add(null);
                    //}
                }
            }

            // Loop through all nodes in Node dictionary and add points to Rhino point list
            foreach (var key in eDict.Keys)
            {
                if (eDict.TryGetValue(key, out Element elem))
                {
                    List <int> topo = elem.Topology.ToList();
                    int        prop = 0;
                    if (join)
                    {
                        prop = elem.Property - 1; // actually branch not property
                    }
                    // Beams (1D elements):
                    if (topo.Count == 2)
                    {
                        for (int i = 0; i <= 1; i++)
                        {
                            if (nDict.TryGetValue(topo[i], out Node node))
                            {
                                {
                                    var p = node.Position;
                                    pts.Add(new Point3d(p.X, p.Y, p.Z));
                                }
                                node.Dispose();
                            }
                        }
                        Line         line   = new Line(pts[0], pts[1]);
                        LineCurve    ln     = new LineCurve(line);
                        GsaElement1d elem1d = new GsaElement1d(ln)
                        {
                            Element = elem
                        };
                        elem1d.ReleaseStart = new GsaBool6()
                        {
                            X  = elem.Release(0).X,
                            Y  = elem.Release(0).Y,
                            Z  = elem.Release(0).Z,
                            XX = elem.Release(0).XX,
                            YY = elem.Release(0).YY,
                            ZZ = elem.Release(0).ZZ
                        };

                        elem1d.ReleaseEnd = new GsaBool6()
                        {
                            X  = elem.Release(1).X,
                            Y  = elem.Release(1).Y,
                            Z  = elem.Release(1).Z,
                            XX = elem.Release(1).XX,
                            YY = elem.Release(1).YY,
                            ZZ = elem.Release(1).ZZ
                        };

                        GsaSection section = new GsaSection
                        {
                            ID = elem.Property
                        };
                        Section tempSection = new Section();
                        if (sDict.TryGetValue(section.ID, out tempSection))
                        {
                            section.Section = tempSection;
                        }
                        elem1d.Section = section;
                        elem1d.ID      = key;

                        pts.Clear();
                        elem1ds.EnsurePath(prop);
                        path = new GH_Path(prop);
                        if (join)
                        {
                            elem1ds.Add(new GsaElement1dGoo(elem1d), path);
                        }
                        else
                        {
                            elem1ds.Insert(new GsaElement1dGoo(elem1d), path, key - 1);
                        }
                        //elem1ds[path, key - 1] = new GsaElement1dGoo(elem1d.Duplicate());
                    }

                    // Shells (2D elements)
                    if (topo.Count > 2) // & topo.Count < 5)
                    {
                        Mesh tempMesh = new Mesh();
                        // Get verticies:
                        for (int i = 0; i < topo.Count; i++)
                        {
                            if (nDict.TryGetValue(topo[i], out Node node))
                            {
                                {
                                    var p = node.Position;
                                    tempMesh.Vertices.Add(new Point3d(p.X, p.Y, p.Z));
                                }
                                node.Dispose();
                            }
                        }

                        // Create mesh face (Tri- or Quad):
                        if (topo.Count == 3)
                        {
                            tempMesh.Faces.AddFace(0, 1, 2);
                        }
                        if (topo.Count == 4)
                        {
                            tempMesh.Faces.AddFace(0, 1, 2, 3);
                        }
                        else
                        {
                            //it must be a TRI6 or a QUAD8
                            List <Point3f> tempPts = tempMesh.Vertices.ToList();
                            double         x = 0; double y = 0; double z = 0;
                            for (int i = 0; i < tempPts.Count; i++)
                            {
                                x += tempPts[i].X; y += tempPts[i].Y; z += tempPts[i].Z;
                            }
                            x /= tempPts.Count; y /= tempPts.Count; z /= tempPts.Count;
                            tempMesh.Vertices.Add(new Point3d(x, y, z));

                            if (topo.Count == 6)
                            {
                                tempMesh.Faces.AddFace(0, 3, 6);
                                tempMesh.Faces.AddFace(3, 1, 6);
                                tempMesh.Faces.AddFace(1, 4, 6);
                                tempMesh.Faces.AddFace(4, 2, 6);
                                tempMesh.Faces.AddFace(2, 5, 6);
                                tempMesh.Faces.AddFace(5, 0, 6);
                            }

                            if (topo.Count == 8)
                            {
                                tempMesh.Faces.AddFace(0, 4, 8, 7);
                                tempMesh.Faces.AddFace(1, 5, 8, 4);
                                tempMesh.Faces.AddFace(2, 6, 8, 5);
                                tempMesh.Faces.AddFace(3, 7, 8, 6);
                            }
                        }
                        List <int> ids = new List <int>
                        {
                            key
                        };

                        elem2d.ID = ids;

                        List <GsaProp2d> prop2Ds = new List <GsaProp2d>();
                        GsaProp2d        prop2d  = new GsaProp2d
                        {
                            ID = elem.Property
                        };
                        Prop2D tempProp = new Prop2D();
                        if (pDict.TryGetValue(prop2d.ID, out tempProp))
                        {
                            prop2d.Prop2d = tempProp;
                        }
                        prop2Ds.Add(prop2d);
                        elem2d.Properties = prop2Ds;


                        if (join)
                        {
                            meshes.EnsurePath(prop);
                            elements.EnsurePath(prop);
                            path = new GH_Path(prop);

                            meshes.Add(tempMesh.DuplicateMesh(), path);
                            elements.Add(elem, path);
                        }
                        else
                        {
                            elem2d = new GsaElement2d(tempMesh);
                            List <Element> elemProps = new List <Element>
                            {
                                elem
                            };
                            elem2d.Elements   = elemProps;
                            elem2d.Properties = prop2Ds;
                            elem2d.ID         = ids;
                            elem2ds.Insert(new GsaElement2dGoo(elem2d), path, key - 1);
                            //elem2ds[path, key - 1] = new GsaElement2dGoo(elem2d.Duplicate());
                            //elem2ds.Add(new GsaElement2dGoo(elem2d.Duplicate()));
                        }

                        tempMesh.Dispose();
                        elem.Dispose();
                    }
                }
            }

            if (join)
            {
                foreach (GH_Path ipath in meshes.Paths)
                {
                    //##### Join meshes #####

                    //List of meshes in each branch
                    List <Mesh> mList = meshes.Branch(ipath);

                    //new temp mesh
                    Mesh m = new Mesh();
                    //Append list of meshes (faster than appending each mesh one by one)
                    m.Append(mList);

                    //split mesh into connected pieces
                    Mesh[] meshy = m.SplitDisjointPieces();

                    //clear whatever is in the current branch (the list in mList)
                    meshes.Branch(ipath).Clear();
                    //rewrite new joined and split meshes to new list in same path:
                    for (int j = 0; j < meshy.Count(); j++)
                    {
                        meshes.Add(meshy[j], ipath);
                    }
                }
                foreach (GH_Path ipath in meshes.Paths)
                {
                    List <Mesh> mList = meshes.Branch(ipath);
                    foreach (Mesh mesh in mList)
                    {
                        elem2d = new GsaElement2d(mesh);
                        List <Element> elemProps = new List <Element>();
                        for (int i = 0; i < mesh.Faces.Count(); i++)
                        {
                            elemProps.Add(elements[ipath, 0]);
                        }
                        elem2d.Elements = elemProps;
                        List <GsaProp2d> prop2Ds = new List <GsaProp2d>();
                        GsaProp2d        prop2d  = new GsaProp2d
                        {
                            ID = ipath.Indices[0] + 1
                        };
                        Prop2D tempProp = new Prop2D();
                        if (pDict.TryGetValue(prop2d.ID, out tempProp))
                        {
                            prop2d.Prop2d = tempProp;
                        }
                        prop2Ds.Add(prop2d);
                        elem2d.Properties = prop2Ds;

                        elem2ds.Add(new GsaElement2dGoo(elem2d));
                    }
                }
            }

            return(new Tuple <DataTree <GsaElement1dGoo>, DataTree <GsaElement2dGoo> >(elem1ds, elem2ds));
        }