Esempio n. 1
0
        public static void ConvertMember1D(GsaMember1d member1d,
                                           ref Dictionary <int, Member> existingMembers, ref int memberidcounter,
                                           ref Dictionary <int, Node> existingNodes, ref int nodeidcounter,
                                           ref Dictionary <int, Section> existingSections, ref Dictionary <Guid, int> sections_guid)
        {
            Member apiMember = member1d.Member;

            // update topology list to fit model nodes
            string topo = "";

            // Loop through the topology list
            for (int j = 0; j < member1d.Topology.Count; j++)
            {
                string  topologyType = member1d.TopologyType[j];
                Point3d pt           = member1d.Topology[j];
                if (j > 0)
                {
                    if (topologyType == "" | topologyType == " ")
                    {
                        topo += " ";
                    }
                    else
                    {
                        topo += topologyType.ToLower() + " "; // add topology type (nothing or "a") in front of node id
                    }
                }

                int id = Nodes.GetExistingNodeID(existingNodes, pt);
                if (id > 0)
                {
                    topo += id;
                }
                else
                {
                    existingNodes.Add(nodeidcounter, Nodes.NodeFromPoint(pt));
                    topo += nodeidcounter;
                    nodeidcounter++;
                }

                if (j != member1d.Topology.Count - 1)
                {
                    topo += " ";
                }
            }
            // set topology in api member
            apiMember.Topology = string.Copy(topo);

            // Section
            if (apiMember.Property == 0)
            {
                apiMember.Property = Sections.ConvertSection(member1d.Section, ref existingSections, ref sections_guid);
            }

            // set apimember in dictionary
            if (member1d.ID > 0) // if the ID is larger than 0 than means the ID has been set and we sent it to the known list
            {
                existingMembers[member1d.ID] = apiMember;
            }
            else
            {
                existingMembers.Add(memberidcounter, apiMember);
                memberidcounter++;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Method to assemble full GSA model
        /// </summary>
        /// <param name="model">Existing models to be merged</param>
        /// <param name="nodes">List of nodes with properties like support conditions</param>
        /// <param name="elem1ds">List of 1D elements. Nodes at end-points will automatically be added to the model, using existing nodes in model within tolerance. Section will automatically be added to model</param>
        /// <param name="elem2ds">List of 2D elements. Nodes at mesh-verticies will automatically be added to the model, using existing nodes in model within tolerance. Prop2d will automatically be added to model</param>
        /// <param name="elem3ds">List of 3D elements. Nodes at mesh-verticies will automatically be added to the model, using existing nodes in model within tolerance</param>
        /// <param name="mem1ds">List of 1D members. Topology nodes will automatically be added to the model, using existing nodes in model within tolerance. Section will automatically be added to model</param>
        /// <param name="mem2ds">List of 2D members. Topology nodes will automatically be added to the model, using existing nodes in model within tolerance. Prop2d will automatically be added to model</param>
        /// <param name="mem3ds">List of 3D members. Topology nodes will automatically be added to the model, using existing nodes in model within tolerance</param>
        /// <param name="sections">List of Sections</param>
        /// <param name="prop2Ds">List of 2D Properties</param>
        /// <param name="loads">List of Loads. For Grid loads the Axis, GridPlane and GridSurface will automatically be added to the model using existing objects where possible within tolerance.</param>
        /// <param name="gridPlaneSurfaces">List of GridPlaneSurfaces</param>
        /// <param name="workerInstance">Optional input for AsyncComponents</param>
        /// <param name="ReportProgress">Optional input for AsyncComponents</param>
        /// <returns></returns>
        public static Model AssembleModel(GsaModel model, List <GsaNode> nodes,
                                          List <GsaElement1d> elem1ds, List <GsaElement2d> elem2ds, List <GsaElement3d> elem3ds,
                                          List <GsaMember1d> mem1ds, List <GsaMember2d> mem2ds, List <GsaMember3d> mem3ds,
                                          List <GsaSection> sections, List <GsaProp2d> prop2Ds,
                                          List <GsaLoad> loads, List <GsaGridPlaneSurface> gridPlaneSurfaces,
                                          GrasshopperAsyncComponent.WorkerInstance workerInstance = null,
                                          Action <string, double> ReportProgress = null
                                          )
        {
            // Set model to work on
            Model gsa = new Model();

            if (model != null)
            {
                gsa = model.Model;
            }

            #region Nodes
            // ### Nodes ###
            // We take out the existing nodes in the model and work on that dictionary

            // Get existing nodes
            IReadOnlyDictionary <int, Node> gsaNodes = gsa.Nodes();
            Dictionary <int, Node>          apinodes = gsaNodes.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            // Get existing axes
            IReadOnlyDictionary <int, Axis> gsaAxes = gsa.Axes();
            Dictionary <int, Axis>          apiaxes = gsaAxes.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            // Set / add nodes to dictionary
            Nodes.ConvertNode(nodes, ref apinodes, ref apiaxes, workerInstance, ReportProgress);
            #endregion

            #region Properties
            // ### Sections ###
            // list to keep track of duplicated sextions
            Dictionary <Guid, int> sections_guid = new Dictionary <Guid, int>();

            // Get existing sections
            IReadOnlyDictionary <int, Section> gsaSections = gsa.Sections();
            Dictionary <int, Section>          apisections = gsaSections.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            // add / set sections
            Sections.ConvertSection(sections, ref apisections, ref sections_guid, workerInstance, ReportProgress);

            // ### Prop2ds ###
            // list to keep track of duplicated sextions
            Dictionary <Guid, int> prop2d_guid = new Dictionary <Guid, int>();
            // Get existing prop2ds
            IReadOnlyDictionary <int, Prop2D> gsaProp2ds = gsa.Prop2Ds();
            Dictionary <int, Prop2D>          apiprop2ds = gsaProp2ds.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            // add / set prop2ds
            Prop2ds.ConvertProp2d(prop2Ds, ref apiprop2ds, ref prop2d_guid, workerInstance, ReportProgress);
            #endregion

            #region Elements
            // ### Elements ###
            // We take out the existing elements in the model and work on that dictionary

            // Get existing elements
            IReadOnlyDictionary <int, Element> gsaElems = gsa.Elements();
            Dictionary <int, Element>          elems    = gsaElems.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            // create a counter for creating new elements
            int newElementID = (elems.Count > 0) ? elems.Keys.Max() + 1 : 1; //checking the existing model

            // as both elem1d and elem2d will be set in the same table, we check the highest ID that may have
            // been set in the incoming elements and start appending from there to avoid accidentially overwriting
            if (elem1ds != null)
            {
                if (elem1ds.Count > 0)
                {
                    int existingElem1dMaxID = elem1ds.Max(x => x.ID); // max ID in new Elem1ds
                    if (existingElem1dMaxID > newElementID)
                    {
                        newElementID = existingElem1dMaxID + 1;
                    }
                }
            }
            if (elem2ds != null)
            {
                if (elem2ds.Count > 0)
                {
                    int existingElem2dMaxID = elem2ds.Max(x => x.ID.Max()); // max ID in new Elem2ds
                    if (existingElem2dMaxID > newElementID)
                    {
                        newElementID = existingElem2dMaxID + 1;
                    }
                }
            }

            // Set / add 1D elements to dictionary
            Elements.ConvertElement1D(elem1ds, ref elems, ref newElementID, ref apinodes, ref apisections, ref sections_guid, workerInstance, ReportProgress);

            // Set / add 2D elements to dictionary
            Elements.ConvertElement2D(elem2ds, ref elems, ref newElementID, ref apinodes, ref apiprop2ds, ref prop2d_guid, workerInstance, ReportProgress);

            // Set / add 3D elements to dictionary
            Elements.ConvertElement3D(elem3ds, ref elems, ref newElementID, ref apinodes, workerInstance, ReportProgress);
            #endregion

            #region Members
            // ### Members ###
            // We take out the existing members in the model and work on that dictionary

            // Get existing members
            IReadOnlyDictionary <int, Member> gsaMems = gsa.Members();
            Dictionary <int, Member>          mems    = gsaMems.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            // create a counter for creating new members
            int newMemberID = (mems.Count > 0) ? mems.Keys.Max() + 1 : 1; //checking the existing model

            // as both mem1d, mem2d and mem3dwill be set in the same table, we check the highest ID that may have
            // been set in the incoming elements and start appending from there to avoid accidentially overwriting
            if (mem1ds != null)
            {
                if (mem1ds.Count > 0)
                {
                    int existingMem1dMaxID = mem1ds.Max(x => x.ID); // max ID in new Elem1ds
                    if (existingMem1dMaxID > newMemberID)
                    {
                        newMemberID = existingMem1dMaxID + 1;
                    }
                }
            }

            if (mem2ds != null)
            {
                if (mem2ds.Count > 0)
                {
                    int existingMem2dMaxID = mem2ds.Max(x => x.ID); // max ID in new Elem2ds
                    if (existingMem2dMaxID > newMemberID)
                    {
                        newMemberID = existingMem2dMaxID + 1;
                    }
                }
            }

            if (mem3ds != null)
            {
                if (mem3ds.Count > 0)
                {
                    int existingMem3dMaxID = mem3ds.Max(x => x.ID); // max ID in new Elem2ds
                    if (existingMem3dMaxID > newMemberID)
                    {
                        newMemberID = existingMem3dMaxID + 1;
                    }
                }
            }

            // Set / add 1D members to dictionary
            Members.ConvertMember1D(mem1ds, ref mems, ref newMemberID, ref apinodes, ref apisections, ref sections_guid, workerInstance, ReportProgress);

            // Set / add 2D members to dictionary
            Members.ConvertMember2D(mem2ds, ref mems, ref newMemberID, ref apinodes, ref apiprop2ds, ref prop2d_guid, workerInstance, ReportProgress);

            // Set / add 3D members to dictionary
            Members.ConvertMember3D(mem3ds, ref mems, ref newMemberID, ref apinodes, workerInstance, ReportProgress);
            #endregion

            #region Loads
            // ### Loads ###
            // We let the existing loads (if any) survive and just add new loads

            // Get existing loads
            List <GravityLoad>   gravityLoads     = new List <GravityLoad>();
            List <NodeLoad>      nodeLoads_node   = new List <NodeLoad>();
            List <NodeLoad>      nodeLoads_displ  = new List <NodeLoad>();
            List <NodeLoad>      nodeLoads_settle = new List <NodeLoad>();
            List <BeamLoad>      beamLoads        = new List <BeamLoad>();
            List <FaceLoad>      faceLoads        = new List <FaceLoad>();
            List <GridPointLoad> gridPointLoads   = new List <GridPointLoad>();
            List <GridLineLoad>  gridLineLoads    = new List <GridLineLoad>();
            List <GridAreaLoad>  gridAreaLoads    = new List <GridAreaLoad>();

            IReadOnlyDictionary <int, GridPlane> gsaGPln       = gsa.GridPlanes();
            Dictionary <int, GridPlane>          apiGridPlanes = gsaGPln.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            IReadOnlyDictionary <int, GridSurface> gsaGSrf         = gsa.GridSurfaces();
            Dictionary <int, GridSurface>          apiGridSurfaces = gsaGSrf.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            // lists to keep track of duplicated grid planes and grid surfaces
            Dictionary <Guid, int> gp_guid = new Dictionary <Guid, int>();
            Dictionary <Guid, int> gs_guid = new Dictionary <Guid, int>();

            // Set / add Grid plane surfaces - do this first to set any GridPlane and GridSurfaces with IDs.
            Loads.ConvertGridPlaneSurface(gridPlaneSurfaces, ref apiaxes, ref apiGridPlanes, ref apiGridSurfaces,
                                          ref gp_guid, ref gs_guid, workerInstance, ReportProgress);

            // Set / add loads to lists
            Loads.ConvertLoad(loads, ref gravityLoads, ref nodeLoads_node, ref nodeLoads_displ, ref nodeLoads_settle,
                              ref beamLoads, ref faceLoads, ref gridPointLoads, ref gridLineLoads, ref gridAreaLoads,
                              ref apiaxes, ref apiGridPlanes, ref apiGridSurfaces, ref gp_guid, ref gs_guid,
                              workerInstance, ReportProgress);
            #endregion



            #region set stuff in model
            if (workerInstance != null)
            {
                if (workerInstance.CancellationToken.IsCancellationRequested)
                {
                    return(null);
                }
            }
            //nodes
            ReadOnlyDictionary <int, Node> setnodes = new ReadOnlyDictionary <int, Node>(apinodes);
            gsa.SetNodes(setnodes);
            //elements
            ReadOnlyDictionary <int, Element> setelem = new ReadOnlyDictionary <int, Element>(elems);
            gsa.SetElements(setelem);
            //members
            ReadOnlyDictionary <int, Member> setmem = new ReadOnlyDictionary <int, Member>(mems);
            gsa.SetMembers(setmem);
            //gravity load
            ReadOnlyCollection <GravityLoad> setgrav = new ReadOnlyCollection <GravityLoad>(gravityLoads);
            gsa.AddGravityLoads(setgrav);
            //node loads
            ReadOnlyCollection <NodeLoad> setnode_disp = new ReadOnlyCollection <NodeLoad>(nodeLoads_displ);
            gsa.AddNodeLoads(NodeLoadType.APPL_DISP, setnode_disp);
            ReadOnlyCollection <NodeLoad> setnode_node = new ReadOnlyCollection <NodeLoad>(nodeLoads_node);
            gsa.AddNodeLoads(NodeLoadType.NODE_LOAD, setnode_node);
            ReadOnlyCollection <NodeLoad> setnode_setl = new ReadOnlyCollection <NodeLoad>(nodeLoads_settle);
            gsa.AddNodeLoads(NodeLoadType.SETTLEMENT, setnode_setl);
            //beam loads
            ReadOnlyCollection <BeamLoad> setbeam = new ReadOnlyCollection <BeamLoad>(beamLoads);
            gsa.AddBeamLoads(setbeam);
            //face loads
            ReadOnlyCollection <FaceLoad> setface = new ReadOnlyCollection <FaceLoad>(faceLoads);
            gsa.AddFaceLoads(setface);
            //grid point loads
            ReadOnlyCollection <GridPointLoad> setpoint = new ReadOnlyCollection <GridPointLoad>(gridPointLoads);
            gsa.AddGridPointLoads(setpoint);
            //grid line loads
            ReadOnlyCollection <GridLineLoad> setline = new ReadOnlyCollection <GridLineLoad>(gridLineLoads);
            gsa.AddGridLineLoads(setline);
            //grid area loads
            ReadOnlyCollection <GridAreaLoad> setarea = new ReadOnlyCollection <GridAreaLoad>(gridAreaLoads);
            gsa.AddGridAreaLoads(setarea);
            //axes
            ReadOnlyDictionary <int, Axis> setax = new ReadOnlyDictionary <int, Axis>(apiaxes);
            gsa.SetAxes(setax);
            //gridplanes
            ReadOnlyDictionary <int, GridPlane> setgp = new ReadOnlyDictionary <int, GridPlane>(apiGridPlanes);
            gsa.SetGridPlanes(setgp);
            //gridsurfaces
            ReadOnlyDictionary <int, GridSurface> setgs = new ReadOnlyDictionary <int, GridSurface>(apiGridSurfaces);
            gsa.SetGridSurfaces(setgs);
            //sections
            ReadOnlyDictionary <int, Section> setsect = new ReadOnlyDictionary <int, Section>(apisections);
            gsa.SetSections(setsect);
            //prop2ds
            ReadOnlyDictionary <int, Prop2D> setpr2d = new ReadOnlyDictionary <int, Prop2D>(apiprop2ds);
            gsa.SetProp2Ds(setpr2d);


            if (workerInstance != null)
            {
                ReportProgress("Model assembled", -2);
            }
            #endregion

            return(gsa);
        }