コード例 #1
0
        public void OpenComponentTest()
        {
            // create the component
            var comp = new GhSA.Components.OpenModel();

            comp.CreateAttributes();

            // input parameter
            // set filename to be openend
            string file = GhSA.Util.Gsa.InstallationFolderPath.GetPath + "\\Samples\\Steel\\Steel_Design_Simple.gwb";

            Component.SetInput(comp, file);

            // Get output from component
            GsaModelGoo output = (GsaModelGoo)Component.GetOutput(comp);

            // cast from -goo to Gsa-GH data type
            GsaModel model = new GsaModel();

            output.CastTo(ref model);

            Assert.AreEqual(file, model.FileName);
            Assert.IsNotNull(model.GUID);

            // set testmodel to be used by other tests
            TestModel = model;
        }
コード例 #2
0
 public static GsaModel MergeModel(List <GsaModel> models)
 {
     if (models != null)
     {
         if (models.Count > 1)
         {
             GsaModel model = new GsaModel();
             models.Reverse();
             for (int i = 0; i < models.Count - 1; i++)
             {
                 model = MergeModel(model, models[i].Clone());
             }
             GsaModel clone = models[models.Count - 1].Clone();
             clone = MergeModel(clone, model);
             return(clone);
         }
         else
         {
             if (models.Count > 0)
             {
                 return(models[0].Clone());
             }
         }
     }
     return(null);
 }
コード例 #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaModel gsaModel = new GsaModel();

            if (DA.GetData(0, ref gsaModel))
            {
                Model model = gsaModel.Model;

                //Tasks and cases output
                List <string> taskList        = new List <string>();
                List <string> descriptionList = new List <string>();
                List <string> caseNameList    = new List <string>();
                List <int>    analysisIdList  = new List <int>();

                //Tasks
                foreach (int key in model.AnalysisTasks().Keys)
                {
                    model.AnalysisTasks().TryGetValue(key, out AnalysisTask analTask);
                    taskList.Add(analTask.Name);
                }

                foreach (int key in model.Results().Keys)
                {
                    descriptionList.Add(model.AnalysisCaseDescription(key));
                    caseNameList.Add(model.AnalysisCaseName(key));
                    analysisIdList.Add(key);
                }

                DA.SetDataList(0, taskList);
                DA.SetDataList(1, caseNameList);
                DA.SetDataList(3, descriptionList);
                DA.SetDataList(2, analysisIdList);
            }
        }
コード例 #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Model model = new Model();

            model.Open(fileName);
            GsaModel gsaModel = new GsaModel
            {
                Model = model
            };

            DA.SetData(0, gsaModel);
        }
コード例 #5
0
        public void TestOpenModel()
        {
            // create new GH-GSA model
            GsaModel m = new GsaModel();

            // get the GSA install path
            string installPath = GhSA.Util.Gsa.InstallationFolderPath.GetPath;

            // open existing GSA model (steel design sample)
            ReturnValue returnValue = m.Model.Open(installPath + "\\Samples\\Steel\\Steel_Design_Simple.gwb");

            Assert.AreSame(ReturnValue.GS_OK.ToString(), returnValue.ToString());
        }
コード例 #6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Model            model    = new Model();
            GsaModel         gsaModel = new GsaModel();
            GH_ObjectWrapper gh_typ   = new GH_ObjectWrapper();

            if (DA.GetData(0, ref gh_typ))
            {
                if (gh_typ == null)
                {
                    return;
                }
                if (gh_typ.Value is GsaModelGoo)
                {
                    gh_typ.CastTo(ref gsaModel);
                    gsaSaveModel = gsaModel.Model;
                    Message      = "";
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model");
                    return;
                }

                if (!usersetFileName)
                {
                    if (gsaModel.FileName != "")
                    {
                        fileName = gsaModel.FileName;
                    }
                }

                string tempfile = "";
                if (DA.GetData(2, ref tempfile))
                {
                    fileName = tempfile;
                }

                bool save = false;
                if (DA.GetData(1, ref save))
                {
                    if (save)
                    {
                        Message = gsaSaveModel.SaveAs(fileName).ToString();
                    }
                }

                DA.SetData(0, new GsaModelGoo(gsaModel));
            }
        }
コード例 #7
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaModel gsaModel = new GsaModel();

            if (DA.GetData(0, ref gsaModel))
            {
                Model model = gsaModel.Model;

                List <GsaSectionGoo> sections = Util.Gsa.FromGSA.GetSections(model.Sections());
                List <GsaProp2dGoo>  prop2Ds  = Util.Gsa.FromGSA.GetProp2ds(model.Prop2Ds());
                // spring import missing in GsaAPI. To be implemented

                DA.SetDataList(0, sections);
                DA.SetDataList(1, prop2Ds);
            }
        }
コード例 #8
0
        public void TestSaveModel()
        {
            // create new GH-GSA model
            GsaModel m = new GsaModel();

            // get the GSA install path
            string installPath = GhSA.Util.Gsa.InstallationFolderPath.GetPath;

            // open existing GSA model (steel design sample)
            m.Model.Open(installPath + "\\Samples\\Steel\\Steel_Design_Simple.gwb");

            // save file to temp location
            string      tempfilename = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Oasys") + "GSA-Grasshopper_temp.gwb";
            ReturnValue returnValue  = m.Model.SaveAs(tempfilename);

            Assert.AreSame(ReturnValue.GS_OK.ToString(), returnValue.ToString());
        }
コード例 #9
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaModel gsaModel = new GsaModel();

            if (DA.GetData(0, ref gsaModel))
            {
                // import lists
                string nodeList = "all";
                if (DA.GetData(1, ref nodeList))
                {
                    nodeList = nodeList.ToString();
                }
                string elemList = "all";
                if (DA.GetData(2, ref elemList))
                {
                    elemList = elemList.ToString();
                }
                string memList = "all";
                if (DA.GetData(3, ref memList))
                {
                    memList = memList.ToString();
                }

                Model model = new Model();
                model = gsaModel.Model;

                bool graft = false;
                if (_mode == FoldMode.Graft)
                {
                    graft = true;
                }
                List <GsaNode> nodes = Util.Gsa.GsaImport.GsaGetPoint(model, nodeList);
                Tuple <DataTree <GsaElement1dGoo>, DataTree <GsaElement2dGoo> > elementTuple = Util.Gsa.GsaImport.GsaGetElem(model, elemList, graft);
                Tuple <DataTree <GsaMember1dGoo>, DataTree <GsaMember2dGoo> >   memberTuple  = Util.Gsa.GsaImport.GsaGetMemb(model, memList, graft);

                List <GsaNodeGoo> gsaNodes = nodes.ConvertAll(x => new GsaNodeGoo(x));

                DA.SetDataList(0, gsaNodes);
                DA.SetDataTree(1, elementTuple.Item1);
                DA.SetDataTree(2, elementTuple.Item2);
                DA.SetDataTree(3, memberTuple.Item1);
                DA.SetDataTree(4, memberTuple.Item2);
            }
        }
コード例 #10
0
        public void TestDuplicateModel()
        {
            // create new GH-GSA model
            GsaModel m = new GsaModel();

            // get the GSA install path
            string installPath = GhSA.Util.Gsa.InstallationFolderPath.GetPath;

            // open existing GSA model (steel design sample)
            ReturnValue returnValue = m.Model.Open(installPath + "\\Samples\\Steel\\Steel_Design_Simple.gwb");

            // get original GUID
            Guid originalGUID = m.GUID;

            // duplicate model
            GsaModel dup = m.Duplicate();

            // get duplicated GUID
            Guid dupGUID = dup.GUID;

            Assert.AreNotEqual(dupGUID, originalGUID);
        }
コード例 #11
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaModel gsaModel = new GsaModel();

            if (DA.GetData(0, ref gsaModel))
            {
                Model model = new Model();
                model = gsaModel.Model;

                List <GsaLoadGoo> gravity = Util.Gsa.FromGSA.GetGravityLoads(model.GravityLoads());
                List <GsaLoadGoo> node    = Util.Gsa.FromGSA.GetNodeLoads(model);
                List <GsaLoadGoo> beam    = Util.Gsa.FromGSA.GetBeamLoads(model.BeamLoads());
                List <GsaLoadGoo> face    = Util.Gsa.FromGSA.GetFaceLoads(model.FaceLoads());

                IReadOnlyDictionary <int, GridSurface> srfDict = model.GridSurfaces();
                IReadOnlyDictionary <int, GridPlane>   plnDict = model.GridPlanes();
                IReadOnlyDictionary <int, Axis>        axDict  = model.Axes();
                List <GsaLoadGoo> point = Util.Gsa.FromGSA.GetGridPointLoads(model.GridPointLoads(), srfDict, plnDict, axDict);
                List <GsaLoadGoo> line  = Util.Gsa.FromGSA.GetGridLineLoads(model.GridLineLoads(), srfDict, plnDict, axDict);
                List <GsaLoadGoo> area  = Util.Gsa.FromGSA.GetGridAreaLoads(model.GridAreaLoads(), srfDict, plnDict, axDict);

                List <GsaGridPlaneSurfaceGoo> gps = new List <GsaGridPlaneSurfaceGoo>();

                foreach (int key in srfDict.Keys)
                {
                    gps.Add(new GsaGridPlaneSurfaceGoo(Util.Gsa.FromGSA.GetGridPlaneSurface(srfDict, plnDict, axDict, key)));
                }

                DA.SetDataList(0, gravity);
                DA.SetDataList(1, node);
                DA.SetDataList(2, beam);
                DA.SetDataList(3, face);
                DA.SetDataList(4, point);
                DA.SetDataList(5, line);
                DA.SetDataList(6, area);
                DA.SetDataList(7, gps);
            }
        }
コード例 #12
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Model to work on
            GsaModel in_Model = new GsaModel();

            // Get Model
            GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

            if (DA.GetData(0, ref gh_typ))
            {
                #region Inputs
                if (gh_typ.Value is GsaModelGoo)
                {
                    gh_typ.CastTo(ref in_Model);
                    if (gsaModel != null)
                    {
                        if (in_Model.GUID != gsaModel.GUID)
                        {
                            gsaModel   = in_Model;
                            getresults = true;
                        }
                    }
                    else
                    {
                        gsaModel = in_Model;
                    }
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model");
                    return;
                }

                // Get analysis case
                GH_Integer gh_aCase = new GH_Integer();
                DA.GetData(1, ref gh_aCase);
                GH_Convert.ToInt32(gh_aCase, out int tempanalCase, GH_Conversion.Both);

                // Get element filter list
                GH_String gh_elList = new GH_String();
                DA.GetData(2, ref gh_elList);
                GH_Convert.ToString(gh_elList, out string tempelemList, GH_Conversion.Both);

                // Get number of divisions
                GH_Integer gh_Div = new GH_Integer();
                DA.GetData(3, ref gh_Div);
                GH_Convert.ToInt32(gh_Div, out int temppositionsCount, GH_Conversion.Both);

                // Get colours
                List <Grasshopper.Kernel.Types.GH_Colour> gh_Colours = new List <Grasshopper.Kernel.Types.GH_Colour>();
                List <System.Drawing.Color> colors = new List <System.Drawing.Color>();
                if (DA.GetDataList(4, gh_Colours))
                {
                    for (int i = 0; i < gh_Colours.Count; i++)
                    {
                        System.Drawing.Color color = new System.Drawing.Color();
                        GH_Convert.ToColor(gh_Colours[i], out color, GH_Conversion.Both);
                        colors.Add(color);
                    }
                }
                Grasshopper.GUI.Gradient.GH_Gradient gH_Gradient = UI.Colour.Stress_Gradient(colors);

                // Get scalar
                GH_Number gh_Scale = new GH_Number();
                DA.GetData(5, ref gh_Scale);
                double scale = 1;
                GH_Convert.ToDouble(gh_Scale, out scale, GH_Conversion.Both);
                #endregion

                #region get results?
                // check if we must get results or just update display
                if (analCase == 0 || analCase != tempanalCase)
                {
                    analCase   = tempanalCase;
                    getresults = true;
                }

                if (elemList == "" || elemList != tempelemList)
                {
                    elemList   = tempelemList;
                    getresults = true;
                }

                if (positionsCount == 0 || positionsCount != temppositionsCount)
                {
                    positionsCount = temppositionsCount;
                    getresults     = true;
                }
                #endregion

                #region Create results output
                if (getresults)
                {
                    #region Get results from GSA
                    // ### Get results ###
                    //Get analysis case from model
                    AnalysisCaseResult analysisCaseResult = null;
                    gsaModel.Model.Results().TryGetValue(analCase, out analysisCaseResult);
                    if (analysisCaseResult == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No results exist for Analysis Case " + analCase + " in file");
                        return;
                    }
                    IReadOnlyDictionary <int, Element1DResult> globalResults = analysisCaseResult.Element1DResults(elemList, positionsCount);
                    IReadOnlyDictionary <int, Element>         elems         = gsaModel.Model.Elements(elemList);
                    IReadOnlyDictionary <int, Node>            nodes         = gsaModel.Model.Nodes();
                    #endregion


                    // ### Loop through results ###
                    // clear existing result lists
                    xyz_out      = new DataTree <Vector3d>();
                    xxyyzz_out   = new DataTree <Vector3d>();
                    segmentlines = new DataTree <Line>();

                    List <int> elemID       = new List <int>();
                    List <int> parentMember = new List <int>();

                    // maximum and minimum result values for colouring later
                    dmax_x      = 0;
                    dmax_y      = 0;
                    dmax_z      = 0;
                    dmax_xx     = 0;
                    dmax_yy     = 0;
                    dmax_zz     = 0;
                    dmax_xyz    = 0;
                    dmax_xxyyzz = 0;
                    dmin_x      = 0;
                    dmin_y      = 0;
                    dmin_z      = 0;
                    dmin_xx     = 0;
                    dmin_yy     = 0;
                    dmin_zz     = 0;
                    dmin_xyz    = 0;
                    dmin_xxyyzz = 0;

                    double unitfactorxyz    = 1;
                    double unitfactorxxyyzz = 1;

                    foreach (int key in globalResults.Keys)
                    {
                        // lists for results
                        Element1DResult elementResults;
                        globalResults.TryGetValue(key, out elementResults);
                        List <Double6>  values = new List <Double6>();
                        List <Vector3d> xyz    = new List <Vector3d>();
                        List <Vector3d> xxyyzz = new List <Vector3d>();

                        // list for element geometry and info
                        Element element = new Element();
                        elems.TryGetValue(key, out element);
                        Node start = new Node();
                        nodes.TryGetValue(element.Topology[0], out start);
                        Node end = new Node();
                        nodes.TryGetValue(element.Topology[1], out end);
                        Line ln = new Line(
                            new Point3d(start.Position.X, start.Position.Y, start.Position.Z),
                            new Point3d(end.Position.X, end.Position.Y, end.Position.Z));
                        elemID.Add(key);
                        parentMember.Add(element.ParentMember.Member);

                        // set the result type dependent on user selection in dropdown
                        switch (_mode)
                        {
                        case (FoldMode.Displacement):
                            values           = elementResults.Displacement.ToList();
                            unitfactorxyz    = 0.001;
                            unitfactorxxyyzz = 1;
                            break;

                        case (FoldMode.Force):
                            values           = elementResults.Force.ToList();
                            unitfactorxyz    = 1000;
                            unitfactorxxyyzz = 1000;
                            break;
                        }

                        // prepare the line segments
                        int         segments       = Math.Max(1, values.Count - 1); // number of segment lines is 1 less than number of points
                        int         segment        = 0;                             // counter for segments
                        List <Line> segmentedlines = new List <Line>();

                        // loop through the results
                        foreach (Double6 result in values)
                        {
                            // update max and min values
                            if (result.X / unitfactorxyz > dmax_x)
                            {
                                dmax_x = result.X / unitfactorxyz;
                            }
                            if (result.Y / unitfactorxyz > dmax_y)
                            {
                                dmax_y = result.Y / unitfactorxyz;
                            }
                            if (result.Z / unitfactorxyz > dmax_z)
                            {
                                dmax_z = result.Z / unitfactorxyz;
                            }
                            if (Math.Sqrt(Math.Pow(result.X, 2) + Math.Pow(result.Y, 2) + Math.Pow(result.Z, 2)) / unitfactorxyz > dmax_xyz)
                            {
                                dmax_xyz = Math.Sqrt(Math.Pow(result.X, 2) + Math.Pow(result.Y, 2) + Math.Pow(result.Z, 2)) / unitfactorxyz;
                            }

                            if (result.XX / unitfactorxxyyzz > dmax_xx)
                            {
                                dmax_xx = result.XX / unitfactorxxyyzz;
                            }
                            if (result.YY / unitfactorxxyyzz > dmax_yy)
                            {
                                dmax_yy = result.YY / unitfactorxxyyzz;
                            }
                            if (result.ZZ / unitfactorxxyyzz > dmax_zz)
                            {
                                dmax_zz = result.ZZ / unitfactorxxyyzz;
                            }
                            if (Math.Sqrt(Math.Pow(result.XX, 2) + Math.Pow(result.YY, 2) + Math.Pow(result.ZZ, 2)) / unitfactorxxyyzz > dmax_xxyyzz)
                            {
                                dmax_xxyyzz = Math.Sqrt(Math.Pow(result.XX, 2) + Math.Pow(result.YY, 2) + Math.Pow(result.ZZ, 2)) / unitfactorxxyyzz;
                            }

                            if (result.X / unitfactorxyz < dmin_x)
                            {
                                dmin_x = result.X / unitfactorxyz;
                            }
                            if (result.Y / unitfactorxyz < dmin_y)
                            {
                                dmin_y = result.Y / unitfactorxyz;
                            }
                            if (result.Z / unitfactorxyz < dmin_z)
                            {
                                dmin_z = result.Z / unitfactorxyz;
                            }
                            if (Math.Sqrt(Math.Pow(result.X, 2) + Math.Pow(result.Y, 2) + Math.Pow(result.Z, 2)) / unitfactorxyz < dmin_xyz)
                            {
                                dmin_xyz = Math.Sqrt(Math.Pow(result.X, 2) + Math.Pow(result.Y, 2) + Math.Pow(result.Z, 2)) / unitfactorxyz;
                            }

                            if (result.XX / unitfactorxxyyzz < dmin_xx)
                            {
                                dmin_xx = result.XX / unitfactorxxyyzz;
                            }
                            if (result.YY / unitfactorxxyyzz < dmin_yy)
                            {
                                dmin_yy = result.YY / unitfactorxxyyzz;
                            }
                            if (result.ZZ / unitfactorxxyyzz < dmin_zz)
                            {
                                dmin_zz = result.ZZ / unitfactorxxyyzz;
                            }
                            if (Math.Sqrt(Math.Pow(result.XX, 2) + Math.Pow(result.YY, 2) + Math.Pow(result.ZZ, 2)) / unitfactorxxyyzz < dmin_xxyyzz)
                            {
                                dmin_xxyyzz = Math.Sqrt(Math.Pow(result.XX, 2) + Math.Pow(result.YY, 2) + Math.Pow(result.ZZ, 2)) / unitfactorxxyyzz;
                            }

                            // add the values to the vector lists
                            xyz.Add(new Vector3d(result.X / unitfactorxyz, result.Y / unitfactorxyz, result.Z / unitfactorxyz));
                            xxyyzz.Add(new Vector3d(result.XX / unitfactorxxyyzz, result.YY / unitfactorxxyyzz, result.ZZ / unitfactorxxyyzz));

                            // create ResultLines
                            if (segment < segments)
                            {
                                Line segmentline = new Line(
                                    ln.PointAt((double)segment / segments),
                                    ln.PointAt((double)(segment + 1) / segments)
                                    );
                                segment++;
                                segmentedlines.Add(segmentline);
                            }
                        }
                        // add the vector list to the out tree
                        xyz_out.AddRange(xyz, new GH_Path(key - 1));
                        xxyyzz_out.AddRange(xxyyzz, new GH_Path(key - 1));
                        segmentlines.AddRange(segmentedlines, new GH_Path(key - 1));
                    }
                    getresults = false;
                }
                #endregion

                #region Result line values
                // ### Coloured Result Lines ###

                // round max and min to reasonable numbers
                double dmax = 0;
                double dmin = 0;
                switch (_disp)
                {
                case (DisplayValue.X):
                    dmax = dmax_x;
                    dmin = dmin_x;
                    break;

                case (DisplayValue.Y):
                    dmax = dmax_y;
                    dmin = dmin_y;
                    break;

                case (DisplayValue.Z):
                    dmax = dmax_z;
                    dmin = dmin_z;
                    break;

                case (DisplayValue.resXYZ):
                    dmax = dmax_xyz;
                    dmin = dmin_xyz;
                    break;

                case (DisplayValue.XX):
                    dmax = dmax_xx;
                    dmin = dmin_xx;
                    break;

                case (DisplayValue.YY):
                    dmax = dmax_yy;
                    dmin = dmin_yy;
                    break;

                case (DisplayValue.ZZ):
                    dmax = dmax_zz;
                    dmin = dmin_zz;
                    break;

                case (DisplayValue.resXXYYZZ):
                    dmax = dmax_xxyyzz;
                    dmin = dmin_xxyyzz;
                    break;
                }

                List <double> rounded = Util.Gsa.ResultHelper.SmartRounder(dmax, dmin);
                dmax = rounded[0];
                dmin = rounded[1];

                // Loop through segmented lines and set result colour into ResultLine format
                DataTree <ResultLine>           lines_out = new DataTree <ResultLine>();
                DataTree <System.Drawing.Color> col_out   = new DataTree <System.Drawing.Color>();


                foreach (GH_Path path in segmentlines.Paths)
                {
                    List <ResultLine>           lns = new List <ResultLine>();
                    List <System.Drawing.Color> col = new List <System.Drawing.Color>();

                    List <Line> segmentedlines = segmentlines.Branch(path);

                    for (int j = 0; j < segmentedlines.Count; j++)
                    {
                        if (!(dmin == 0 & dmax == 0))
                        {
                            Vector3d startTranslation = new Vector3d(0, 0, 0);
                            Vector3d endTranslation   = new Vector3d(0, 0, 0);

                            double t1 = 0;
                            double t2 = 0;

                            // pick the right value to display
                            switch (_disp)
                            {
                            case (DisplayValue.X):
                                t1 = xyz_out[path, j].X;
                                t2 = xyz_out[path, j + 1].X;
                                startTranslation.X = t1 * Value / 1000;
                                endTranslation.X   = t2 * Value / 1000;
                                break;

                            case (DisplayValue.Y):
                                t1 = xyz_out[path, j].Y;
                                t2 = xyz_out[path, j + 1].Y;
                                startTranslation.Y = t1 * Value / 1000;
                                endTranslation.Y   = t2 * Value / 1000;
                                break;

                            case (DisplayValue.Z):
                                t1 = xyz_out[path, j].Z;
                                t2 = xyz_out[path, j + 1].Z;
                                startTranslation.Z = t1 * Value / 1000;
                                endTranslation.Z   = t2 * Value / 1000;
                                break;

                            case (DisplayValue.resXYZ):
                                t1 = Math.Sqrt(Math.Pow(xyz_out[path, j].X, 2) + Math.Pow(xyz_out[path, j].Y, 2) + Math.Pow(xyz_out[path, j].Z, 2));
                                t2 = Math.Sqrt(Math.Pow(xyz_out[path, j + 1].X, 2) + Math.Pow(xyz_out[path, j + 1].Y, 2) + Math.Pow(xyz_out[path, j + 1].Z, 2));
                                startTranslation.X = xyz_out[path, j].X * Value / 1000;
                                endTranslation.X   = xyz_out[path, j + 1].X * Value / 1000;
                                startTranslation.Y = xyz_out[path, j].Y * Value / 1000;
                                endTranslation.Y   = xyz_out[path, j + 1].Y * Value / 1000;
                                startTranslation.Z = xyz_out[path, j].Z * Value / 1000;
                                endTranslation.Z   = xyz_out[path, j + 1].Z * Value / 1000;
                                break;

                            case (DisplayValue.XX):
                                t1 = xxyyzz_out[path, j].X;
                                t2 = xxyyzz_out[path, j + 1].X;
                                break;

                            case (DisplayValue.YY):
                                t1 = xxyyzz_out[path, j].Y;
                                t2 = xxyyzz_out[path, j + 1].Y;
                                break;

                            case (DisplayValue.ZZ):
                                t1 = xxyyzz_out[path, j].Z;
                                t2 = xxyyzz_out[path, j + 1].Z;
                                break;

                            case (DisplayValue.resXXYYZZ):
                                t1 = Math.Sqrt(Math.Pow(xxyyzz_out[path, j].X, 2) + Math.Pow(xxyyzz_out[path, j].Y, 2) + Math.Pow(xxyyzz_out[path, j].Z, 2));
                                t2 = Math.Sqrt(Math.Pow(xxyyzz_out[path, j + 1].X, 2) + Math.Pow(xxyyzz_out[path, j + 1].Y, 2) + Math.Pow(xxyyzz_out[path, j + 1].Z, 2));
                                break;
                            }
                            Point3d start = new Point3d(segmentedlines[j].PointAt(0));
                            start.Transform(Transform.Translation(startTranslation));
                            Point3d end = new Point3d(segmentedlines[j].PointAt(1));
                            end.Transform(Transform.Translation(endTranslation));
                            Line segmentline = new Line(start, end);

                            //normalised value between -1 and 1
                            double tnorm1 = 2 * (t1 - dmin) / (dmax - dmin) - 1;
                            double tnorm2 = 2 * (t2 - dmin) / (dmax - dmin) - 1;

                            // get colour for that normalised value

                            System.Drawing.Color valcol1 = double.IsNaN(tnorm1) ? System.Drawing.Color.Black : gH_Gradient.ColourAt(tnorm1);
                            System.Drawing.Color valcol2 = double.IsNaN(tnorm2) ? System.Drawing.Color.Black : gH_Gradient.ColourAt(tnorm2);

                            // set the size of the line ends for ResultLine class. Size is calculated from 0-base, so not a normalised value between extremes
                            float size1 = (t1 >= 0 && dmax != 0) ?
                                          Math.Max(2, (float)(t1 / dmax * scale)) :
                                          Math.Max(2, (float)(Math.Abs(t1) / Math.Abs(dmin) * scale));
                            if (double.IsNaN(size1))
                            {
                                size1 = 1;
                            }
                            float size2 = (t2 >= 0 && dmax != 0) ?
                                          Math.Max(2, (float)(t2 / dmax * scale)) :
                                          Math.Max(2, (float)(Math.Abs(t2) / Math.Abs(dmin) * scale));
                            if (double.IsNaN(size2))
                            {
                                size2 = 1;
                            }

                            // add our special resultline to the list of lines
                            lns.Add(new ResultLine(segmentline, t1, t2, valcol1, valcol2, size1, size2));

                            // add the colour to the colours list
                            col.Add(valcol1);
                            if (j == segmentedlines.Count - 1)
                            {
                                col.Add(valcol2);
                            }
                        }
                    }
                    lines_out.AddRange(lns, path);
                    col_out.AddRange(col, path);
                }
                #endregion

                #region Legend
                // ### Legend ###
                // loop through number of grip points in gradient to create legend

                //Find Colour and Values for legend output
                List <double> ts = new List <double>();
                List <System.Drawing.Color> cs = new List <System.Drawing.Color>();

                for (int i = 0; i < gH_Gradient.GripCount; i++)
                {
                    double t   = dmin + (dmax - dmin) / ((double)gH_Gradient.GripCount - 1) * (double)i;
                    double scl = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(t))) + 1);
                    scl = Math.Max(scl, 1);
                    t   = scl * Math.Round(t / scl, 3);
                    ts.Add(t);

                    System.Drawing.Color gradientcolour = gH_Gradient.ColourAt(2 * (double)i / ((double)gH_Gradient.GripCount - 1) - 1);
                    cs.Add(gradientcolour);
                }
                #endregion

                // set outputs
                DA.SetDataTree(0, xyz_out);
                DA.SetDataTree(1, xxyyzz_out);
                DA.SetDataTree(2, lines_out);
                DA.SetDataTree(3, col_out);
                DA.SetDataList(4, cs);
                DA.SetDataList(5, ts);
            }
        }
コード例 #13
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);
        }
コード例 #14
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
        }
コード例 #15
0
        public static GsaModel MergeModel(GsaModel mainModel, GsaModel appendModel)
        {
            // open the copyfrom model
            Model model = appendModel.Model;

            // get dictionaries from model
            IReadOnlyDictionary <int, Node>    nDict = model.Nodes();
            IReadOnlyDictionary <int, Element> eDict = model.Elements();
            IReadOnlyDictionary <int, Member>  mDict = model.Members();
            IReadOnlyDictionary <int, Section> sDict = model.Sections();
            IReadOnlyDictionary <int, Prop2D>  pDict = model.Prop2Ds();

            // get nodes
            List <GsaNodeGoo> goonodes = Util.Gsa.FromGSA.GetNodes(nDict, model);
            // convert from Goo-type
            List <GsaNode> nodes = goonodes.Select(n => n.Value).ToList();

            // change all members in List's ID to 0;
            nodes.Select(c => { c.ID = 0; return(c); }).ToList();

            // get elements
            Tuple <List <GsaElement1dGoo>, List <GsaElement2dGoo>, List <GsaElement3dGoo> > elementTuple
                = Util.Gsa.FromGSA.GetElements(eDict, nDict, sDict, pDict);
            // convert from Goo-type
            List <GsaElement1d> elem1ds = elementTuple.Item1.Select(n => n.Value).ToList();

            // change all members in List's ID to 0;
            elem1ds.Select(c => { c.ID = 0; return(c); }).ToList();
            // convert from Goo-type
            List <GsaElement2d> elem2ds = elementTuple.Item2.Select(n => n.Value).ToList();

            // change all members in List's ID to 0;
            foreach (var elem2d in elem2ds)
            {
                elem2d.ID.Select(c => { c = 0; return(c); }).ToList();
            }
            // convert from Goo-type
            List <GsaElement3d> elem3ds = elementTuple.Item3.Select(n => n.Value).ToList();

            // change all members in List's ID to 0;
            foreach (var elem3d in elem3ds)
            {
                elem3d.ID.Select(c => { c = 0; return(c); }).ToList();
            }

            // get members
            Tuple <List <GsaMember1dGoo>, List <GsaMember2dGoo>, List <GsaMember3dGoo> > memberTuple
                = Util.Gsa.FromGSA.GetMembers(mDict, nDict, sDict, pDict);
            // convert from Goo-type
            List <GsaMember1d> mem1ds = memberTuple.Item1.Select(n => n.Value).ToList();

            // change all members in List's ID to 0;
            mem1ds.Select(c => { c.ID = 0; return(c); }).ToList();
            // convert from Goo-type
            List <GsaMember2d> mem2ds = memberTuple.Item2.Select(n => n.Value).ToList();

            // change all members in List's ID to 0;
            mem2ds.Select(c => { c.ID = 0; return(c); }).ToList();

            // get properties
            List <GsaSectionGoo> goosections = FromGSA.GetSections(sDict);
            // convert from Goo-type
            List <GsaSection> sections = goosections.Select(n => n.Value).ToList();

            // change all members in List's ID to 0;
            sections.Select(c => { c.ID = 0; return(c); }).ToList();
            List <GsaProp2dGoo> gooprop2Ds = FromGSA.GetProp2ds(pDict);
            // convert from Goo-type
            List <GsaProp2d> prop2Ds = gooprop2Ds.Select(n => n.Value).ToList();

            // change all members in List's ID to 0;
            prop2Ds.Select(c => { c.ID = 0; return(c); }).ToList();

            // get loads
            List <GsaLoadGoo> gooloads = new List <GsaLoadGoo>();

            gooloads.AddRange(FromGSA.GetGravityLoads(model.GravityLoads()));
            gooloads.AddRange(FromGSA.GetNodeLoads(model));
            gooloads.AddRange(FromGSA.GetBeamLoads(model.BeamLoads()));
            gooloads.AddRange(FromGSA.GetFaceLoads(model.FaceLoads()));

            IReadOnlyDictionary <int, GridSurface> srfDict = model.GridSurfaces();
            IReadOnlyDictionary <int, GridPlane>   plnDict = model.GridPlanes();
            IReadOnlyDictionary <int, Axis>        axDict  = model.Axes();

            gooloads.AddRange(FromGSA.GetGridPointLoads(model.GridPointLoads(), srfDict, plnDict, axDict));
            gooloads.AddRange(FromGSA.GetGridLineLoads(model.GridLineLoads(), srfDict, plnDict, axDict));
            gooloads.AddRange(FromGSA.GetGridAreaLoads(model.GridAreaLoads(), srfDict, plnDict, axDict));
            List <GsaLoad> loads = gooloads.Select(n => n.Value).ToList();

            // get grid plane surfaces
            List <GsaGridPlaneSurfaceGoo> gpsgoo = new List <GsaGridPlaneSurfaceGoo>();

            foreach (int key in srfDict.Keys)
            {
                gpsgoo.Add(new GsaGridPlaneSurfaceGoo(Util.Gsa.FromGSA.GetGridPlaneSurface(srfDict, plnDict, axDict, key)));
            }
            // convert from Goo-type
            List <GsaGridPlaneSurface> gps = gpsgoo.Select(n => n.Value).ToList();

            // return new assembled model
            mainModel.Model = Assemble.AssembleModel(mainModel, nodes, elem1ds, elem2ds, elem3ds, mem1ds, mem2ds, null, sections, prop2Ds, loads, gps);
            return(mainModel);
        }
コード例 #16
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Model to work on
            GsaModel gsaModel = new GsaModel();

            // Get Model
            GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

            if (DA.GetData(0, ref gh_typ))
            {
                #region Inputs
                if (gh_typ.Value is GsaModelGoo)
                {
                    gh_typ.CastTo(ref gsaModel);
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model");
                    return;
                }

                // Get analysis case
                GH_Integer gh_aCase = new GH_Integer();
                DA.GetData(1, ref gh_aCase);
                int analCase = 1;
                GH_Convert.ToInt32(gh_aCase, out analCase, GH_Conversion.Both);
                #endregion

                #region Get results from GSA
                // ### Get results ###
                //Get analysis case from model
                AnalysisCaseResult analysisCaseResult = null;
                gsaModel.Model.Results().TryGetValue(analCase, out analysisCaseResult);
                if (analysisCaseResult == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No results exist for Analysis Case " + analCase + " in file");
                    return;
                }
                #endregion

                double unitfactorForce  = 1000;
                double unitfactorMoment = 1000;

                Vector3d force = new Vector3d(
                    analysisCaseResult.Global.TotalLoad.X / unitfactorForce,
                    analysisCaseResult.Global.TotalLoad.Y / unitfactorForce,
                    analysisCaseResult.Global.TotalLoad.Z / unitfactorForce);

                Vector3d moment = new Vector3d(
                    analysisCaseResult.Global.TotalLoad.XX / unitfactorMoment,
                    analysisCaseResult.Global.TotalLoad.YY / unitfactorMoment,
                    analysisCaseResult.Global.TotalLoad.ZZ / unitfactorMoment);

                Vector3d reaction = new Vector3d(
                    analysisCaseResult.Global.TotalReaction.X / unitfactorForce,
                    analysisCaseResult.Global.TotalReaction.Y / unitfactorForce,
                    analysisCaseResult.Global.TotalReaction.Z / unitfactorForce);

                Vector3d reactionmoment = new Vector3d(
                    analysisCaseResult.Global.TotalReaction.XX / unitfactorMoment,
                    analysisCaseResult.Global.TotalReaction.YY / unitfactorMoment,
                    analysisCaseResult.Global.TotalReaction.ZZ / unitfactorMoment);

                Vector3d effMass = new Vector3d(
                    analysisCaseResult.Global.EffectiveMass.X,
                    analysisCaseResult.Global.EffectiveMass.Y,
                    analysisCaseResult.Global.EffectiveMass.Z);

                Vector3d effStiff;
                if (analysisCaseResult.Global.EffectiveInertia != null)
                {
                    effStiff = new Vector3d(
                        analysisCaseResult.Global.EffectiveInertia.X,
                        analysisCaseResult.Global.EffectiveInertia.Y,
                        analysisCaseResult.Global.EffectiveInertia.Z);
                }
                else
                {
                    effStiff = new Vector3d();
                }

                Vector3d modal = new Vector3d(
                    analysisCaseResult.Global.ModalMass,
                    analysisCaseResult.Global.ModalStiffness,
                    analysisCaseResult.Global.ModalGeometricStiffness);

                DA.SetData(0, force);
                DA.SetData(1, moment);
                DA.SetData(2, reaction);
                DA.SetData(3, reactionmoment);
                DA.SetData(4, effMass);
                DA.SetData(5, effStiff);
                DA.SetData(6, analysisCaseResult.Global.Mode);
                DA.SetData(7, modal);
                DA.SetData(8, analysisCaseResult.Global.Frequency);
                DA.SetData(9, analysisCaseResult.Global.LoadFactor);
            }
        }
コード例 #17
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaModel         gsaModel = new GsaModel();
            GH_ObjectWrapper gh_typ   = new GH_ObjectWrapper();

            if (DA.GetData(0, ref gh_typ))
            {
                if (gh_typ.Value is GsaModelGoo)
                {
                    gh_typ.CastTo(ref gsaModel);
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model");
                    return;
                }

                //GsaModel in_Model = gsaModel.Clone();
                Model model = gsaModel.Model;

                // import lists
                string nodeList = "all";
                if (DA.GetData(1, ref nodeList))
                {
                    nodeList = nodeList.ToString();
                }
                string elemList = "all";
                if (DA.GetData(2, ref elemList))
                {
                    elemList = elemList.ToString();
                }
                string memList = "all";
                if (DA.GetData(3, ref memList))
                {
                    memList = memList.ToString();
                }


                // get dictionaries from model
                IReadOnlyDictionary <int, Node>    nDict = model.Nodes();
                IReadOnlyDictionary <int, Element> eDict = model.Elements(elemList);
                IReadOnlyDictionary <int, Member>  mDict = model.Members(memList);
                IReadOnlyDictionary <int, Section> sDict = model.Sections();
                IReadOnlyDictionary <int, Prop2D>  pDict = model.Prop2Ds();

                IReadOnlyDictionary <int, Node> out_nDict = (nodeList == "all") ? nDict : model.Nodes(nodeList);

                // create nodes
                List <GsaNodeGoo> nodes = Util.Gsa.FromGSA.GetNodes(out_nDict, model);
                // create elements
                Tuple <List <GsaElement1dGoo>, List <GsaElement2dGoo>, List <GsaElement3dGoo> > elementTuple
                    = Util.Gsa.FromGSA.GetElements(eDict, nDict, sDict, pDict);
                // create members
                Tuple <List <GsaMember1dGoo>, List <GsaMember2dGoo>, List <GsaMember3dGoo> > memberTuple
                    = Util.Gsa.FromGSA.GetMembers(mDict, nDict, sDict, pDict);

                DA.SetDataList(0, nodes);

                DA.SetDataList(1, elementTuple.Item1);
                DA.SetDataList(2, elementTuple.Item2);
                DA.SetDataList(3, elementTuple.Item3);

                DA.SetDataList(4, memberTuple.Item1);
                DA.SetDataList(5, memberTuple.Item2);
                DA.SetDataList(6, memberTuple.Item3);

                element2ds = elementTuple.Item2;
            }
        }
コード例 #18
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Model to work on
            GsaModel in_Model = new GsaModel();

            // Get Model
            GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

            if (DA.GetData(0, ref gh_typ))
            {
                #region Inputs
                if (gh_typ.Value is GsaModelGoo)
                {
                    gh_typ.CastTo(ref in_Model);
                    if (gsaModel != null)
                    {
                        if (in_Model.GUID != gsaModel.GUID)
                        {
                            gsaModel   = in_Model;
                            getresults = true;
                        }
                    }
                    else
                    {
                        gsaModel = in_Model;
                    }
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model");
                    return;
                }

                // Get analysis case
                GH_Integer gh_aCase = new GH_Integer();
                DA.GetData(1, ref gh_aCase);
                GH_Convert.ToInt32(gh_aCase, out int tempanalCase, GH_Conversion.Both);

                // Get element filter list
                GH_String gh_elList = new GH_String();
                DA.GetData(2, ref gh_elList);
                GH_Convert.ToString(gh_elList, out string tempelemList, GH_Conversion.Both);

                // Get colours
                List <Grasshopper.Kernel.Types.GH_Colour> gh_Colours = new List <Grasshopper.Kernel.Types.GH_Colour>();
                List <System.Drawing.Color> colors = new List <System.Drawing.Color>();
                if (DA.GetDataList(3, gh_Colours))
                {
                    for (int i = 0; i < gh_Colours.Count; i++)
                    {
                        System.Drawing.Color color = new System.Drawing.Color();
                        GH_Convert.ToColor(gh_Colours[i], out color, GH_Conversion.Both);
                        colors.Add(color);
                    }
                }
                Grasshopper.GUI.Gradient.GH_Gradient gH_Gradient = UI.Colour.Stress_Gradient(colors);

                #endregion

                #region get results?
                // check if we must get results or just update display
                if (analCase == 0 || analCase != tempanalCase)
                {
                    analCase   = tempanalCase;
                    getresults = true;
                }

                if (elemList == "" || elemList != tempelemList)
                {
                    elemList   = tempelemList;
                    getresults = true;
                }

                #endregion

                #region Create results output
                if (getresults)
                {
                    #region Get results from GSA
                    // ### Get results ###
                    //Get analysis case from model
                    AnalysisCaseResult analysisCaseResult = null;
                    gsaModel.Model.Results().TryGetValue(analCase, out analysisCaseResult);
                    if (analysisCaseResult == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No results exist for Analysis Case " + analCase + " in file");
                        return;
                    }
                    IReadOnlyDictionary <int, Element3DResult> globalResults = analysisCaseResult.Element3DResults(elemList);

                    #endregion

                    // ### Loop through results ###
                    // clear existing result lists
                    xyz_out    = new DataTree <Vector3d>();
                    xxyyzz_out = new DataTree <Vector3d>();

                    // maximum and minimum result values for colouring later
                    dmax_x      = 0;
                    dmax_y      = 0;
                    dmax_z      = 0;
                    dmax_xx     = 0;
                    dmax_yy     = 0;
                    dmax_zz     = 0;
                    dmax_xyz    = 0;
                    dmax_xxyyzz = 0;
                    dmin_x      = 0;
                    dmin_y      = 0;
                    dmin_z      = 0;
                    dmin_xx     = 0;
                    dmin_yy     = 0;
                    dmin_zz     = 0;
                    dmin_xyz    = 0;
                    dmin_xxyyzz = 0;
                    keys        = new List <int>();

                    double unitfactorxyz    = 1;
                    double unitfactorxxyyzz = 1;

                    foreach (int key in globalResults.Keys)
                    {
                        keys.Add(key);

                        // lists for results
                        Element3DResult elementResults;
                        if (globalResults.TryGetValue(key, out elementResults))
                        {
                            List <Vector3d> xyz    = new List <Vector3d>();
                            List <Vector3d> xxyyzz = new List <Vector3d>();

                            switch (_mode)
                            {
                            case FoldMode.Displacement:
                                unitfactorxyz = 0.001;
                                List <Double3> trans_vals = elementResults.Displacement.ToList();
                                foreach (Double3 val in trans_vals)
                                {
                                    Vector3d valxyz = new Vector3d
                                    {
                                        X = val.X / unitfactorxyz,
                                        Y = val.Y / unitfactorxyz,
                                        Z = val.Z / unitfactorxyz
                                    };
                                    xyz.Add(valxyz);
                                }
                                break;

                            case FoldMode.Stress:
                                unitfactorxxyyzz = 1000000;

                                List <Tensor3> stress_vals = elementResults.Stress.ToList();
                                foreach (Tensor3 val in stress_vals)
                                {
                                    Vector3d valxxyyzz = new Vector3d
                                    {
                                        X = val.XX / unitfactorxxyyzz,
                                        Y = val.YY / unitfactorxxyyzz,
                                        Z = val.ZZ / unitfactorxxyyzz
                                    };

                                    Vector3d valxyyzzx = new Vector3d
                                    {
                                        X = val.XY / unitfactorxxyyzz,
                                        Y = val.YZ / unitfactorxxyyzz,
                                        Z = val.ZX / unitfactorxxyyzz
                                    };

                                    xyz.Add(valxxyyzz);
                                    xxyyzz.Add(valxyyzzx);
                                }
                                break;
                            }

                            // update max and min values
                            dmax_x = Math.Max(xyz.Max(val => val.X), dmax_x);
                            dmax_y = Math.Max(xyz.Max(val => val.Y), dmax_y);
                            dmax_z = Math.Max(xyz.Max(val => val.Z), dmax_z);

                            dmax_xyz = Math.Max(
                                xyz.Max(val =>
                                        Math.Sqrt(
                                            Math.Pow(val.X, 2) +
                                            Math.Pow(val.Y, 2) +
                                            Math.Pow(val.Z, 2))),
                                dmax_xyz);

                            dmin_x = Math.Min(xyz.Min(val => val.X), dmin_x);
                            dmin_y = Math.Min(xyz.Min(val => val.Y), dmin_y);
                            dmin_z = Math.Min(xyz.Min(val => val.Z), dmin_z);

                            if (_mode == FoldMode.Stress)
                            {
                                dmax_xx = Math.Max(xxyyzz.Max(val => val.X), dmax_xx);
                                dmax_yy = Math.Max(xxyyzz.Max(val => val.Y), dmax_yy);
                                dmax_zz = Math.Max(xxyyzz.Max(val => val.Z), dmax_zz);

                                dmin_xx = Math.Min(xxyyzz.Min(val => val.X), dmin_xx);
                                dmin_yy = Math.Min(xxyyzz.Min(val => val.Y), dmin_yy);
                                dmin_zz = Math.Min(xxyyzz.Min(val => val.Z), dmin_zz);
                            }

                            // add vector lists to main lists
                            xyz_out.AddRange(xyz, new GH_Path(key - 1));
                            xxyyzz_out.AddRange(xxyyzz, new GH_Path(key - 1));
                        }
                    }
                    getresults = false;
                }
                #endregion

                #region Result mesh values
                // ### Coloured Result Meshes ###

                // round max and min to reasonable numbers
                double dmax = 0;
                double dmin = 0;
                switch (_disp)
                {
                case (DisplayValue.X):
                    dmax = dmax_x;
                    dmin = dmin_x;
                    break;

                case (DisplayValue.Y):
                    dmax = dmax_y;
                    dmin = dmin_y;
                    break;

                case (DisplayValue.Z):
                    dmax = dmax_z;
                    dmin = dmin_z;
                    break;

                case (DisplayValue.resXYZ):
                    dmax = dmax_xyz;
                    dmin = dmin_xyz;
                    break;

                case (DisplayValue.XX):
                    dmax = dmax_xx;
                    dmin = dmin_xx;
                    break;

                case (DisplayValue.YY):
                    dmax = dmax_yy;
                    dmin = dmin_yy;
                    break;

                case (DisplayValue.ZZ):
                    dmax = dmax_zz;
                    dmin = dmin_zz;
                    break;

                case (DisplayValue.resXXYYZZ):
                    dmax = dmax_xxyyzz;
                    dmin = dmin_xxyyzz;
                    break;
                }

                List <double> rounded = Util.Gsa.ResultHelper.SmartRounder(dmax, dmin);
                dmax = rounded[0];
                dmin = rounded[1];

                #region create mesh
                // create mesh

                // get elements and nodes from model
                elemList = string.Join(" ", keys.ToList());
                IReadOnlyDictionary <int, Element> elems = gsaModel.Model.Elements(elemList);
                IReadOnlyDictionary <int, Node>    nodes = gsaModel.Model.Nodes();

                List <int>        elemID       = new List <int>();
                List <int>        parentMember = new List <int>();
                List <ResultMesh> resultMeshes = new List <ResultMesh>();
                List <Mesh>       meshes       = new List <Mesh>();

                // loop through elements
                foreach (int key in elems.Keys)
                {
                    elems.TryGetValue(key, out Element element);

                    Mesh tempmesh = GhSA.Util.Gsa.FromGSA.ConvertElement3D(element, nodes);
                    if (tempmesh == null)
                    {
                        continue;
                    }

                    List <Vector3d> transformation = null;
                    // add mesh colour
                    List <double> vals = new List <double>();

                    GH_Path path = new GH_Path(key - 1);

                    List <Vector3d> tempXYZ    = xyz_out.Branch(path);
                    List <Vector3d> tempXXYYZZ = xxyyzz_out.Branch(path);
                    switch (_disp)
                    {
                    case (DisplayValue.X):
                        vals           = tempXYZ.ConvertAll(val => val.X);
                        transformation = new List <Vector3d>();
                        for (int i = 0; i < vals.Count; i++)
                        {
                            transformation.Add(new Vector3d(vals[i] * Value / 1000, 0, 0));
                        }
                        break;

                    case (DisplayValue.Y):
                        vals           = tempXYZ.ConvertAll(val => val.Y);
                        transformation = new List <Vector3d>();
                        for (int i = 0; i < vals.Count; i++)
                        {
                            transformation.Add(new Vector3d(0, vals[i] * Value / 1000, 0));
                        }
                        break;

                    case (DisplayValue.Z):
                        vals           = tempXYZ.ConvertAll(val => val.Z);
                        transformation = new List <Vector3d>();
                        for (int i = 0; i < vals.Count; i++)
                        {
                            transformation.Add(new Vector3d(0, 0, vals[i] * Value / 1000));
                        }
                        break;

                    case (DisplayValue.resXYZ):
                        vals = tempXYZ.ConvertAll(val => (
                                                      Math.Sqrt(
                                                          Math.Pow(val.X, 2) +
                                                          Math.Pow(val.Y, 2) +
                                                          Math.Pow(val.Z, 2))));
                        transformation = tempXYZ.ConvertAll(vec => Vector3d.Multiply(Value / 1000, vec));
                        break;

                    case (DisplayValue.XX):
                        vals = tempXXYYZZ.ConvertAll(val => val.X);
                        break;

                    case (DisplayValue.YY):
                        vals = tempXXYYZZ.ConvertAll(val => val.Y);
                        break;

                    case (DisplayValue.ZZ):
                        vals = tempXXYYZZ.ConvertAll(val => val.Z);
                        break;

                    case (DisplayValue.resXXYYZZ):
                        vals = tempXXYYZZ.ConvertAll(val => (
                                                         Math.Sqrt(
                                                             Math.Pow(val.X, 2) +
                                                             Math.Pow(val.Y, 2) +
                                                             Math.Pow(val.Z, 2))));
                        break;
                    }

                    for (int i = 1; i < vals.Count; i++) // start at i=1 as the first index is the centre point in GsaAPI output
                    {
                        //normalised value between -1 and 1
                        double tnorm             = 2 * (vals[i] - dmin) / (dmax - dmin) - 1;
                        System.Drawing.Color col = (double.IsNaN(tnorm)) ? System.Drawing.Color.Transparent : gH_Gradient.ColourAt(tnorm);
                        tempmesh.VertexColors.Add(col);
                        if (transformation != null)
                        {
                            Point3f def = tempmesh.Vertices[i - 1];
                            def.Transform(Transform.Translation(transformation[i]));
                            tempmesh.Vertices[i - 1] = def;
                        }
                    }

                    ResultMesh resultMesh = new ResultMesh(tempmesh, vals);
                    meshes.Add(tempmesh);
                    resultMeshes.Add(resultMesh);
                    #endregion
                    elemID.Add(key);
                    parentMember.Add(element.ParentMember.Member);
                }

                #endregion

                #region Legend
                // ### Legend ###
                // loop through number of grip points in gradient to create legend

                //Find Colour and Values for legend output
                List <double> ts = new List <double>();
                List <System.Drawing.Color> cs = new List <System.Drawing.Color>();

                for (int i = 0; i < gH_Gradient.GripCount; i++)
                {
                    double t   = dmin + (dmax - dmin) / ((double)gH_Gradient.GripCount - 1) * (double)i;
                    double scl = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(t))) + 1);
                    scl = Math.Max(scl, 1);
                    t   = scl * Math.Round(t / scl, 3);
                    ts.Add(t);

                    System.Drawing.Color gradientcolour = gH_Gradient.ColourAt(2 * (double)i / ((double)gH_Gradient.GripCount - 1) - 1);
                    cs.Add(gradientcolour);
                }
                #endregion

                // set outputs
                int outind = 0;
                DA.SetDataTree(outind++, xyz_out);
                if (_mode == FoldMode.Stress)
                {
                    DA.SetDataTree(outind++, xxyyzz_out);
                }
                DA.SetDataList(outind++, resultMeshes);
                DA.SetDataList(outind++, cs);
                DA.SetDataList(outind++, ts);
            }
        }
コード例 #19
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Model to work on
            GsaModel in_Model = new GsaModel();

            // Get Model
            GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

            if (DA.GetData(0, ref gh_typ))
            {
                #region Inputs
                if (gh_typ.Value is GsaModelGoo)
                {
                    gh_typ.CastTo(ref in_Model);
                    if (gsaModel != null)
                    {
                        if (in_Model.GUID != gsaModel.GUID)
                        {
                            gsaModel   = in_Model;
                            getresults = true;
                        }
                    }
                    else
                    {
                        gsaModel = in_Model;
                    }
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model");
                    return;
                }

                // Get analysis case
                GH_Integer gh_aCase = new GH_Integer();
                DA.GetData(1, ref gh_aCase);
                GH_Convert.ToInt32(gh_aCase, out int tempanalCase, GH_Conversion.Both);

                // Get node filter list
                GH_String gh_noList = new GH_String();
                DA.GetData(2, ref gh_noList);
                GH_Convert.ToString(gh_noList, out string tempnodeList, GH_Conversion.Both);

                // Get colours
                List <Grasshopper.Kernel.Types.GH_Colour> gh_Colours = new List <Grasshopper.Kernel.Types.GH_Colour>();
                List <System.Drawing.Color> colors = new List <System.Drawing.Color>();
                if (DA.GetDataList(3, gh_Colours))
                {
                    for (int i = 0; i < gh_Colours.Count; i++)
                    {
                        System.Drawing.Color color = new System.Drawing.Color();
                        GH_Convert.ToColor(gh_Colours[i], out color, GH_Conversion.Both);
                        colors.Add(color);
                    }
                }
                Grasshopper.GUI.Gradient.GH_Gradient gH_Gradient = UI.Colour.Stress_Gradient(colors);

                // Get scalar
                GH_Number gh_Scale = new GH_Number();
                DA.GetData(4, ref gh_Scale);
                double scale = 1;
                GH_Convert.ToDouble(gh_Scale, out scale, GH_Conversion.Both);
                #endregion

                #region get results?
                // check if we must get results or just update display
                if (analCase == 0 || analCase != tempanalCase)
                {
                    analCase   = tempanalCase;
                    getresults = true;
                }

                if (nodeList == "" || nodeList != tempnodeList)
                {
                    nodeList   = tempnodeList;
                    getresults = true;
                }
                #endregion

                if (getresults)
                {
                    #region Get results from GSA
                    // ### Get results ###
                    //Get analysis case from model
                    AnalysisCaseResult analysisCaseResult = null;
                    gsaModel.Model.Results().TryGetValue(analCase, out analysisCaseResult);
                    if (analysisCaseResult == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No results exist for Analysis Case " + analCase + " in file");
                        return;
                    }
                    IReadOnlyDictionary <int, NodeResult> results = analysisCaseResult.NodeResults(nodeList);
                    IReadOnlyDictionary <int, Node>       nodes   = gsaModel.Model.Nodes(nodeList);
                    #endregion

                    #region Create results output
                    // ### Loop through results ###
                    // clear any existing lists of vectors to output results in:
                    xyz    = new List <Vector3d>();
                    xxyyzz = new List <Vector3d>();

                    // maximum and minimum result values for colouring later
                    dmax_x      = 0;
                    dmax_y      = 0;
                    dmax_z      = 0;
                    dmax_xx     = 0;
                    dmax_yy     = 0;
                    dmax_zz     = 0;
                    dmax_xyz    = 0;
                    dmax_xxyyzz = 0;
                    dmin_x      = 0;
                    dmin_y      = 0;
                    dmin_z      = 0;
                    dmin_xx     = 0;
                    dmin_yy     = 0;
                    dmin_zz     = 0;
                    dmin_xyz    = 0;
                    dmin_xxyyzz = 0;

                    double unitfactorxyz    = 1;
                    double unitfactorxxyyzz = 1;

                    // if reaction type, then we reuse the nodeList to filter support nodes from the rest
                    if (_mode == FoldMode.Reaction)
                    {
                        nodeList = "";
                    }

                    foreach (var key in results.Keys)
                    {
                        NodeResult result;
                        Double6    values = null;

                        if (_mode == FoldMode.Reaction)
                        {
                            bool isSupport = false;
                            Node node      = new Node();
                            nodes.TryGetValue(key, out node);
                            NodalRestraint rest = node.Restraint;
                            if (rest.X || rest.Y || rest.Z || rest.XX || rest.YY || rest.ZZ)
                            {
                                isSupport = true;
                            }
                            if (!isSupport)
                            {
                                continue;
                            }
                            else
                            {
                                if (nodeList == "")
                                {
                                    nodeList = key.ToString();
                                }
                                else
                                {
                                    nodeList += " " + key;
                                }
                            }
                        }

                        results.TryGetValue(key, out result);
                        switch (_mode)
                        {
                        case (FoldMode.Displacement):
                            values           = result.Displacement;
                            unitfactorxyz    = 0.001;
                            unitfactorxxyyzz = 1;
                            break;

                        case (FoldMode.Reaction):
                            values           = result.Reaction;
                            unitfactorxyz    = 1000;
                            unitfactorxxyyzz = 1000;
                            break;

                        case (FoldMode.SpringForce):
                            values           = result.SpringForce;
                            unitfactorxyz    = 1000;
                            unitfactorxxyyzz = 1000;
                            break;

                        case (FoldMode.Constraint):
                            values = result.Constraint;
                            break;
                        }


                        // update max and min values
                        if (values.X / unitfactorxyz > dmax_x)
                        {
                            dmax_x = values.X / unitfactorxyz;
                        }
                        if (values.Y / unitfactorxyz > dmax_y)
                        {
                            dmax_y = values.Y / unitfactorxyz;
                        }
                        if (values.Z / unitfactorxyz > dmax_z)
                        {
                            dmax_z = values.Z / unitfactorxyz;
                        }
                        if (Math.Sqrt(Math.Pow(values.X, 2) + Math.Pow(values.Y, 2) + Math.Pow(values.Z, 2)) / unitfactorxyz > dmax_xyz)
                        {
                            dmax_xyz = Math.Sqrt(Math.Pow(values.X, 2) + Math.Pow(values.Y, 2) + Math.Pow(values.Z, 2)) / unitfactorxyz;
                        }

                        if (values.XX / unitfactorxxyyzz > dmax_xx)
                        {
                            dmax_xx = values.XX / unitfactorxxyyzz;
                        }
                        if (values.YY / unitfactorxxyyzz > dmax_yy)
                        {
                            dmax_yy = values.YY / unitfactorxxyyzz;
                        }
                        if (values.ZZ / unitfactorxxyyzz > dmax_zz)
                        {
                            dmax_zz = values.ZZ / unitfactorxxyyzz;
                        }
                        if (Math.Sqrt(Math.Pow(values.XX, 2) + Math.Pow(values.YY, 2) + Math.Pow(values.ZZ, 2)) / unitfactorxxyyzz > dmax_xxyyzz)
                        {
                            dmax_xxyyzz = Math.Sqrt(Math.Pow(values.XX, 2) + Math.Pow(values.YY, 2) + Math.Pow(values.ZZ, 2)) / unitfactorxxyyzz;
                        }

                        if (values.X / unitfactorxyz < dmin_x)
                        {
                            dmin_x = values.X / unitfactorxyz;
                        }
                        if (values.Y / unitfactorxyz < dmin_y)
                        {
                            dmin_y = values.Y / unitfactorxyz;
                        }
                        if (values.Z / unitfactorxyz < dmin_z)
                        {
                            dmin_z = values.Z / unitfactorxyz;
                        }
                        if (Math.Sqrt(Math.Pow(values.X, 2) + Math.Pow(values.Y, 2) + Math.Pow(values.Z, 2)) / unitfactorxyz < dmin_xyz)
                        {
                            dmin_xyz = Math.Sqrt(Math.Pow(values.X, 2) + Math.Pow(values.Y, 2) + Math.Pow(values.Z, 2)) / unitfactorxyz;
                        }

                        if (values.XX / unitfactorxxyyzz < dmin_xx)
                        {
                            dmin_xx = values.XX / unitfactorxxyyzz;
                        }
                        if (values.YY / unitfactorxxyyzz < dmin_yy)
                        {
                            dmin_yy = values.YY / unitfactorxxyyzz;
                        }
                        if (values.ZZ / unitfactorxxyyzz < dmin_zz)
                        {
                            dmin_zz = values.ZZ / unitfactorxxyyzz;
                        }
                        if (Math.Sqrt(Math.Pow(values.XX, 2) + Math.Pow(values.YY, 2) + Math.Pow(values.ZZ, 2)) / unitfactorxxyyzz < dmin_xxyyzz)
                        {
                            dmin_xxyyzz = Math.Sqrt(Math.Pow(values.XX, 2) + Math.Pow(values.YY, 2) + Math.Pow(values.ZZ, 2)) / unitfactorxxyyzz;
                        }

                        // add the values to the vector lists
                        xyz.Add(new Vector3d(values.X / unitfactorxyz, values.Y / unitfactorxyz, values.Z / unitfactorxyz));
                        xxyyzz.Add(new Vector3d(values.XX / unitfactorxxyyzz, values.YY / unitfactorxxyyzz, values.ZZ / unitfactorxxyyzz));
                    }
                    #endregion
                    getresults = false;
                }


                #region Result point values
                // ### Coloured Result Points ###

                // Get nodes for point location and restraint check in case of reaction force
                IReadOnlyDictionary <int, Node> nDict = gsaModel.Model.Nodes(nodeList);
                List <GsaNodeGoo> gsanodes            = Util.Gsa.FromGSA.GetNodes(nDict, gsaModel.Model);

                //Find Colour and Values for legend output

                List <double> ts = new List <double>();
                List <System.Drawing.Color> cs = new List <System.Drawing.Color>();

                // round max and min to reasonable numbers
                double dmax = 0;
                double dmin = 0;
                switch (_disp)
                {
                case (DisplayValue.X):
                    dmax = dmax_x;
                    dmin = dmin_x;
                    break;

                case (DisplayValue.Y):
                    dmax = dmax_y;
                    dmin = dmin_y;
                    break;

                case (DisplayValue.Z):
                    dmax = dmax_z;
                    dmin = dmin_z;
                    break;

                case (DisplayValue.resXYZ):
                    dmax = dmax_xyz;
                    dmin = dmin_xyz;
                    break;

                case (DisplayValue.XX):
                    dmax = dmax_xx;
                    dmin = dmin_xx;
                    break;

                case (DisplayValue.YY):
                    dmax = dmax_yy;
                    dmin = dmin_yy;
                    break;

                case (DisplayValue.ZZ):
                    dmax = dmax_zz;
                    dmin = dmin_zz;
                    break;

                case (DisplayValue.resXXYYZZ):
                    dmax = dmax_xxyyzz;
                    dmin = dmin_xxyyzz;
                    break;
                }

                List <double> rounded = Util.Gsa.ResultHelper.SmartRounder(dmax, dmin);
                dmax = rounded[0];
                dmin = rounded[1];

                // Loop through nodes and set result colour into ResultPoint format
                List <ResultPoint>          pts = new List <ResultPoint>();
                List <System.Drawing.Color> col = new List <System.Drawing.Color>();

                for (int i = 0; i < gsanodes.Count; i++)
                {
                    if (gsanodes[i].Value != null)
                    {
                        if (!(dmin == 0 & dmax == 0))
                        {
                            double   t           = 0;
                            Vector3d translation = new Vector3d(0, 0, 0);
                            // pick the right value to display
                            switch (_disp)
                            {
                            case (DisplayValue.X):
                                t             = xyz[i].X;
                                translation.X = t * Value / 1000;
                                break;

                            case (DisplayValue.Y):
                                t             = xyz[i].Y;
                                translation.Y = t * Value / 1000;
                                break;

                            case (DisplayValue.Z):
                                t             = xyz[i].Z;
                                translation.Z = t * Value / 1000;
                                break;

                            case (DisplayValue.resXYZ):
                                t             = Math.Sqrt(Math.Pow(xyz[i].X, 2) + Math.Pow(xyz[i].Y, 2) + Math.Pow(xyz[i].Z, 2));
                                translation.X = xyz[i].X * Value / 1000;
                                translation.Y = xyz[i].Y * Value / 1000;
                                translation.Z = xyz[i].Z * Value / 1000;
                                break;

                            case (DisplayValue.XX):
                                t = xxyyzz[i].X;
                                break;

                            case (DisplayValue.YY):
                                t = xxyyzz[i].Y;
                                break;

                            case (DisplayValue.ZZ):
                                t = xxyyzz[i].Z;
                                break;

                            case (DisplayValue.resXXYYZZ):
                                t = Math.Sqrt(Math.Pow(xxyyzz[i].X, 2) + Math.Pow(xxyyzz[i].Y, 2) + Math.Pow(xxyyzz[i].Z, 2));
                                break;
                            }

                            //normalised value between -1 and 1
                            double tnorm = 2 * (t - dmin) / (dmax - dmin) - 1;

                            // get colour for that normalised value
                            System.Drawing.Color valcol = gH_Gradient.ColourAt(tnorm);

                            // set the size of the point for ResultPoint class. Size is calculated from 0-base, so not a normalised value between extremes
                            float size = (t >= 0 && dmax != 0) ?
                                         Math.Max(2, (float)(t / dmax * scale)) :
                                         Math.Max(2, (float)(Math.Abs(t) / Math.Abs(dmin) * scale));

                            // create deflection point
                            Point3d def = new Point3d(gsanodes[i].Value.Point);
                            def.Transform(Transform.Translation(translation));

                            // add our special resultpoint to the list of points
                            pts.Add(new ResultPoint(def, t, valcol, size));

                            // add the colour to the colours list
                            col.Add(valcol);
                        }
                    }
                }
                #endregion

                #region Legend
                // ### Legend ###
                // loop through number of grip points in gradient to create legend
                for (int i = 0; i < gH_Gradient.GripCount; i++)
                {
                    double t   = dmin + (dmax - dmin) / ((double)gH_Gradient.GripCount - 1) * (double)i;
                    double scl = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(t))) + 1);
                    scl = Math.Max(scl, 1);
                    t   = scl * Math.Round(t / scl, 3);
                    ts.Add(t);

                    System.Drawing.Color gradientcolour = gH_Gradient.ColourAt(2 * (double)i / ((double)gH_Gradient.GripCount - 1) - 1);
                    cs.Add(gradientcolour);
                }
                #endregion

                // set outputs
                DA.SetDataList(0, xyz);
                DA.SetDataList(1, xxyyzz);
                DA.SetDataList(2, pts);
                DA.SetDataList(3, col);
                DA.SetDataList(4, cs);
                DA.SetDataList(5, ts);
            }
        }
コード例 #20
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;
                }
            }
コード例 #21
0
            public override void DoWork(Action <string, double> ReportProgress, Action Done)
            {
                #region DoWork
                if (hasInput)
                {
                    GsaModel analysisModel = null;
                    if (Models != null)
                    {
                        if (Models.Count > 0)
                        {
                            if (Models.Count > 1)
                            {
                                ReportProgress("Merging models...", -2);
                                analysisModel = Util.Gsa.ToGSA.Models.MergeModel(Models);
                                ReportProgress("Models merged", -1);
                            }
                            else
                            {
                                analysisModel = Models[0].Clone();
                                ReportProgress("Model cloned", -1);
                            }
                        }
                    }
                    if (analysisModel != null)
                    {
                        OutModel = analysisModel;
                    }
                    else
                    {
                        OutModel = new GsaModel();
                    }

                    // Assemble model
                    ReportProgress("Assembling model...", -2);
                    Model gsa = Util.Gsa.ToGSA.Assemble.AssembleModel(analysisModel, Nodes, Elem1ds, Elem2ds, Elem3ds, Mem1ds, Mem2ds, Mem3ds, Sections, Prop2Ds, Loads, GridPlaneSurfaces, this, ReportProgress);
                    if (gsa == null)
                    {
                        return;
                    }
                    ReportProgress("Model assembled", -1);

                    #region meshing
                    // Create elements from members
                    ReportProgress("Meshing", 0);
                    gsa.CreateElementsFromMembers();
                    ReportProgress("Model meshed", -1);
                    #endregion

                    #region analysis


                    //analysis
                    IReadOnlyDictionary <int, AnalysisTask> gsaTasks = gsa.AnalysisTasks();
                    if (gsaTasks.Count < 1)
                    {
                        ReportProgress("Model contains no Analysis Tasks", -255);
                        ReportProgress("Model assembled", -1);
                    }
                    else
                    {
                        foreach (KeyValuePair <int, AnalysisTask> task in gsaTasks)
                        {
                            if (CancellationToken.IsCancellationRequested)
                            {
                                return;
                            }
                            ReportProgress("Analysing Task " + task.Key.ToString(), -2);

                            bool analysis;
                            try
                            {
                                analysis = gsa.Analyse(task.Key);
                            }
                            catch (Exception)
                            {
                                throw;
                            }


                            if (!analysis)
                            {
                                component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Warning Analysis Case " + task.Key + " could not be analysed");
                                ReportProgress("Warning Analysis Case " + task.Key + " could not be analysed", -10);
                            }
                        }
                        ReportProgress("Model analysed", -1);
                    }

                    #endregion
                    OutModel.Model = gsa;
                    Done();
                }
                #endregion
            }
コード例 #22
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Model model = new Model();

            GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

            if (DA.GetData(0, ref gh_typ))
            {
                if (gh_typ.Value is GH_String)
                {
                    string tempfile = "";
                    if (GH_Convert.ToString(gh_typ, out tempfile, GH_Conversion.Both))
                    {
                        fileName = tempfile;
                    }

                    if (!fileName.EndsWith(".gwb"))
                    {
                        fileName = fileName + ".gwb";
                    }

                    ReturnValue status = model.Open(fileName);

                    if (status == 0)
                    {
                        GsaModel gsaModel = new GsaModel
                        {
                            Model    = model,
                            FileName = fileName
                        };

                        Titles.GetTitlesFromGSA(model);

                        string mes = Path.GetFileName(fileName);
                        mes     = mes.Substring(0, mes.Length - 4);
                        Message = mes;
                        DA.SetData(0, new GsaModelGoo(gsaModel));
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to open Model" + System.Environment.NewLine + status.ToString());
                        return;
                    }
                }
                else if (gh_typ.Value is GsaAPI.Model)
                {
                    gh_typ.CastTo(ref model);
                    GsaModel gsaModel = new GsaModel
                    {
                        Model = model,
                    };

                    DA.SetData(0, new GsaModelGoo(gsaModel));
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to open Model");
                    return;
                }
            }
            else
            {
                ReturnValue status = model.Open(fileName);

                if (status == 0)
                {
                    GsaModel gsaModel = new GsaModel
                    {
                        Model    = model,
                        FileName = fileName
                    };

                    Titles.GetTitlesFromGSA(model);

                    string mes = Path.GetFileName(fileName);
                    mes     = mes.Substring(0, mes.Length - 4);
                    Message = mes;
                    DA.SetData(0, new GsaModelGoo(gsaModel));
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to open Model" + System.Environment.NewLine + status.ToString());
                    return;
                }
            }
        }
コード例 #23
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            #region inputs
            // Get Member1d input
            GH_ObjectWrapper        gh_typ   = new GH_ObjectWrapper();
            List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>();

            List <GsaNode> in_nodes = new List <GsaNode>();
            if (DA.GetDataList(0, gh_types))
            {
                for (int i = 0; i < gh_types.Count; i++)
                {
                    gh_typ = gh_types[i];
                    if (gh_typ.Value is GsaNodeGoo)
                    {
                        GsaNode gsanode = new GsaNode();
                        gh_typ.CastTo(ref gsanode);
                        in_nodes.Add(gsanode);
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in Node input");
                        return;
                    }
                }
            }

            List <GsaMember1d> in_mem1ds = new List <GsaMember1d>();
            if (DA.GetDataList(1, gh_types))
            {
                for (int i = 0; i < gh_types.Count; i++)
                {
                    gh_typ = gh_types[i];
                    if (gh_typ.Value is GsaMember1dGoo)
                    {
                        GsaMember1d gsamem1 = new GsaMember1d();
                        gh_typ.CastTo(ref gsamem1);
                        in_mem1ds.Add(gsamem1);
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in Mem1D input");
                        return;
                    }
                }
            }

            // Get Member2d input
            gh_types = new List <GH_ObjectWrapper>();
            List <GsaMember2d> in_mem2ds = new List <GsaMember2d>();
            if (DA.GetDataList(2, gh_types))
            {
                for (int i = 0; i < gh_types.Count; i++)
                {
                    gh_typ = gh_types[i];
                    if (gh_typ.Value is GsaMember2dGoo)
                    {
                        GsaMember2d gsamem2 = new GsaMember2d();
                        gh_typ.CastTo(ref gsamem2);
                        in_mem2ds.Add(gsamem2);
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in Mem2D input");
                        return;
                    }
                }
            }

            // Get Member3d input
            gh_types = new List <GH_ObjectWrapper>();
            List <GsaMember3d> in_mem3ds = new List <GsaMember3d>();
            if (DA.GetDataList(3, gh_types))
            {
                for (int i = 0; i < gh_types.Count; i++)
                {
                    gh_typ = gh_types[i];
                    if (gh_typ.Value is GsaMember3dGoo)
                    {
                        GsaMember3d gsamem3 = new GsaMember3d();
                        gh_typ.CastTo(ref gsamem3);
                        in_mem3ds.Add(gsamem3);
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in Mem3D input");
                        return;
                    }
                }
            }

            // manually add a warning if no input is set, as all three inputs are optional
            if (in_mem1ds.Count < 1 & in_mem2ds.Count < 1 & in_mem3ds.Count < 1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data");
            }
            #endregion

            // Assemble model
            Model gsa = Util.Gsa.ToGSA.Assemble.AssembleModel(null, in_nodes, null, null, null, in_mem1ds, in_mem2ds, in_mem3ds, null, null, null, null);

            #region meshing
            // Create elements from members
            gsa.CreateElementsFromMembers();
            #endregion

            // extract nodes from model
            List <GsaNodeGoo> nodes = Util.Gsa.FromGSA.GetNodes(gsa.Nodes(), gsa);

            // extract elements from model
            Tuple <List <GsaElement1dGoo>, List <GsaElement2dGoo>, List <GsaElement3dGoo> > elementTuple
                = Util.Gsa.FromGSA.GetElements(gsa.Elements(), gsa.Nodes(), gsa.Sections(), gsa.Prop2Ds());

            // expose internal model if anyone wants to use it
            GsaModel outModel = new GsaModel();
            outModel.Model = gsa;

            DA.SetDataList(0, nodes);
            DA.SetDataList(1, elementTuple.Item1);
            DA.SetDataList(2, elementTuple.Item2);
            DA.SetDataList(3, elementTuple.Item3);
            DA.SetData(4, new GsaModelGoo(outModel));

            // custom display settings for element2d mesh
            element2ds = elementTuple.Item2;
        }