Ejemplo n.º 1
0
        protected override void SolveInstance(IGH_DataAccess da)
        {
            var secStruc = da.GetDataTree <IGH_Goo>(0);
            var ctrlList = da.GetDataList <string>(1);

            var sections = new Dictionary <int, GH_Section>();

            foreach (var it in secStruc.AllData(true))
            {
                if (it is GH_Section)
                {
                    var ghSec = it as GH_Section;
                    if (!sections.ContainsKey(ghSec.Value.Id))
                    {
                        sections.Add(ghSec.Value.Id, ghSec);
                    }
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Data conversion failed from " + it.TypeName + " to GH_Section.");
                }
            }

            var ctrlListNotEmpty = ctrlList.Where(ctrl => !string.IsNullOrEmpty(ctrl));

            int unitSet = 0;

            if (sections.Any())
            {
                unitSet = sections.First().Value.Value.GetUnitSet();
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("+PROG AQUA");
            sb.AppendLine("HEAD");
            sb.AppendLine("PAGE UNII " + unitSet);
            if (ctrlListNotEmpty.Any())
            {
                foreach (var ctrl in ctrlListNotEmpty)
                {
                    sb.AppendLine(ctrl);
                }
            }
            else
            {
                sb.AppendLine("CTRL REST 1");
            }

            sb.AppendLine();

            foreach (var kvp in sections)
            {
                var secUnitSet = kvp.Value.Value.GetUnitSet();
                if (secUnitSet != unitSet)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Section " + kvp.Value.Value.Id + ": " + kvp.Value.Value.Name + " has different unit than other sections.");
                }
                else
                {
                    var res = kvp.Value.Value.GetSectionDefinition(sb);
                    if (res.Item1 != GH_RuntimeMessageLevel.Blank)
                    {
                        AddRuntimeMessage(res.Item1, res.Item2);
                    }
                }
            }

            sb.AppendLine("END");

            // create output objects
            var aquaModel = new gh_sofistik.General.SofistikModel()
            {
                CadInp = sb.ToString(), ModelType = gh_sofistik.General.SofistikModelType.AQUA
            };
            var ghAquaModel = new gh_sofistik.General.GH_SofistikModel()
            {
                Value = aquaModel
            };
            // create GH_Structure and use SetDataTree so output has always one branch with index {0}
            var outStruc = new GH_Structure <gh_sofistik.General.GH_SofistikModel>();

            outStruc.Append(ghAquaModel);
            da.SetDataTree(0, outStruc);
        }
Ejemplo n.º 2
0
        protected override void SolveInstance(IGH_DataAccess da)
        {
            var ldStruc  = da.GetDataTree <IGH_GeometricGoo>(0);
            var lcStruc  = da.GetDataTree <IGH_Goo>(1);
            var textList = da.GetDataList <string>(2);

            // get load case definitions
            var all_loads = new List <IGS_Load>();

            foreach (var it in ldStruc.AllData(true))
            {
                if (it is IGS_Load)
                {
                    all_loads.Add(it as IGS_Load);
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Data conversion failed from " + it.TypeName + " to IGS_Load.");
                }
            }

            // extract load case headers
            var load_cases = new Dictionary <int, string>();

            foreach (var it in lcStruc.AllData(true))
            {
                if (it is GS_LoadCase)
                {
                    var ilc = it as GS_LoadCase;
                    if (ilc.Value.Id != 0)
                    {
                        load_cases.Add(ilc.Value.Id, ilc.Value.ToCadinp().Trim());
                    }
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Data conversion failed from " + it.TypeName + " to GS_LoadCase.");
                }
            }

            // calc unit conversion factor and scale-transform
            var  currentUnitSystem = Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem;
            bool scaleUnit         = currentUnitSystem != Rhino.UnitSystem.Meters;
            var  unitFactor        = Rhino.RhinoMath.UnitScale(currentUnitSystem, Rhino.UnitSystem.Meters);
            var  tU = Transform.Scale(Point3d.Origin, unitFactor);

            var sb = new StringBuilder();

            sb.AppendLine("+PROG SOFILOAD");
            sb.AppendLine("HEAD");
            sb.AppendLine("PAGE UNII 0"); // export always in SOFiSTiK database units
            sb.AppendLine();

            if (!all_loads.Any() && !load_cases.Any())
            {
                sb.AppendLine("LC 1 FACD 1.0");
            }

            string[,] load_types = { { "PXX", "PYY", "PZZ", "PX", "PY", "PZ" }, { "MXX", "MYY", "MZZ", "MX", "MY", "MZ" }, { "WXX", "WYY", "WZZ", "WX", "WY", "WZ" }, { "DXX", "DYY", "DZZ", "DX", "DY", "DZ" } };

            foreach (var lc_loads in all_loads.GroupBy(ld => ld.LoadCase).OrderBy(ig => ig.Key))
            {
                if (lc_loads.Count() == 0)
                {
                    continue;
                }

                if (load_cases.TryGetValue(lc_loads.Key, out var lc_definition))
                {
                    sb.AppendLine(lc_definition);
                    load_cases.Remove(lc_loads.Key);
                }
                else
                {
                    sb.AppendFormat("LC {0}", lc_loads.Key);
                    sb.AppendLine();
                }

                foreach (var ld in lc_loads)
                {
                    if (ld is GS_PointLoad)
                    {
                        var pl = ld as GS_PointLoad;

                        //string id_string = pl.LoadCase.ToString();
                        string ref_string = (!(pl.ReferencePoint is null)) && pl.ReferencePoint.Id > 0 ? "NODE" : "AUTO";
                        string no_string  = (!(pl.ReferencePoint is null)) && pl.ReferencePoint.Id > 0 ? pl.ReferencePoint.Id.ToString() : "-";
                        int    type_off   = pl.UseHostLocal ? 3 : 0;

                        var plGeo = pl.Value.Duplicate() as Point;
                        if (scaleUnit)
                        {
                            plGeo.Transform(tU);
                        }

                        for (int i = 0; i < 3; ++i)
                        {
                            if (Math.Abs(pl.Forces[i]) > 1.0E-6)
                            {
                                sb.AppendFormat("POIN {0} {1}", ref_string, no_string);
                                sb.AppendFormat(" TYPE {0} {1:F6}", load_types[0, i + type_off], pl.Forces[i]);
                                AppendLoadGeometry(sb, plGeo);
                                sb.AppendLine();
                            }
                        }

                        for (int i = 0; i < 3; ++i)
                        {
                            if (Math.Abs(pl.Moments[i]) > 1.0E-6)
                            {
                                sb.AppendFormat("POIN {0} {1}", ref_string, no_string);
                                sb.AppendFormat(" TYPE {0} {1:F6}", load_types[1, i + type_off], pl.Moments[i]);
                                AppendLoadGeometry(sb, plGeo);
                                sb.AppendLine();
                            }
                        }

                        for (int i = 0; i < 3; ++i)
                        {
                            if (Math.Abs(pl.Displacement[i]) > 1.0E-6)
                            {
                                sb.AppendFormat("POIN {0} {1}", ref_string, no_string);
                                sb.AppendFormat(" TYPE {0} {1:F6}", load_types[2, i + type_off], scaleUnit ? pl.Displacement[i] * unitFactor : pl.Displacement[i]);
                                AppendLoadGeometry(sb, plGeo);
                                sb.AppendLine();
                            }
                        }

                        for (int i = 0; i < 3; ++i)
                        {
                            if (Math.Abs(pl.DisplacementRotational[i]) > 1.0E-6)
                            {
                                sb.AppendFormat("POIN {0} {1}", ref_string, no_string);
                                sb.AppendFormat(" TYPE {0} {1:F6}", load_types[3, i + type_off], pl.DisplacementRotational[i] * 1000);
                                AppendLoadGeometry(sb, plGeo);
                                sb.AppendLine();
                            }
                        }
                    }
                    else if (ld is GS_LineLoad)
                    {
                        var ll = ld as GS_LineLoad;

                        bool hosted = (!(ll.ReferenceLine is null)) && ll.ReferenceLine.Id > 0;

                        string cmd_string = ll.Value.IsLinear() ? "LINE" : "CURV";
                        string ref_string = hosted ? "SLN" : "AUTO";
                        string no_string  = hosted ? ll.ReferenceLine.Id.ToString() : "-";
                        int    type_off   = ll.UseHostLocal ? 3 : 0;

                        var points = new List <Point3d>();
                        if (!hosted)
                        {
                            var crvGeo = ll.Value.DuplicateCurve();
                            if (scaleUnit)
                            {
                                crvGeo.Transform(tU);
                            }
                            points = GetCurvePolygon(crvGeo);
                        }

                        for (int i = 0; i < 3; ++i)
                        {
                            if (Math.Abs(ll.Forces[i]) > 1.0E-6)
                            {
                                sb.AppendFormat("{0} {1} {2}", cmd_string, ref_string, no_string);
                                sb.AppendFormat(" TYPE {0} {1:F6}", load_types[0, i + type_off], ll.Forces[i]);
                                AppendLoadGeometry(sb, points);
                                sb.AppendLine();
                            }
                        }

                        for (int i = 0; i < 3; ++i)
                        {
                            if (Math.Abs(ll.Moments[i]) > 1.0E-6)
                            {
                                sb.AppendFormat("{0} {1} {2}", cmd_string, ref_string, no_string);
                                sb.AppendFormat(" TYPE {0} {1:F6}", load_types[1, i + type_off], ll.Moments[i]);
                                AppendLoadGeometry(sb, points);
                                sb.AppendLine();
                            }
                        }
                    }
                    else if (ld is GS_AreaLoad)
                    {
                        var al = ld as GS_AreaLoad;

                        bool hosted = (!(al.ReferenceArea is null)) && al.ReferenceArea.Id > 0;

                        string cmd_string = "AREA";
                        string ref_string = hosted ? "SAR" : "AUTO";
                        string no_string  = hosted ? al.ReferenceArea.Id.ToString() : "-";
                        int    type_off   = al.UseHostLocal ? 3 : 0;

                        var brpGeo = al.Value.DuplicateBrep();
                        if (scaleUnit)
                        {
                            brpGeo.Transform(tU);
                        }

                        foreach (var fc in brpGeo.Faces)
                        {
                            // checks and preparations
                            fc.ShrinkFace(BrepFace.ShrinkDisableSide.ShrinkAllSides);

                            if (fc.IsClosed(0) || fc.IsClosed(1))
                            {
                                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "A given Surface is closed in one direction.\nSuch surfaces cannot be handled properly and need to be split.");
                            }

                            var points = hosted ? new List <Point3d>() : GetFacePolygon(fc);

                            if (points.Count > 63)
                            {
                                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Boundary of area load is too complex to be resolved properly.\nPlease simplify given brep geometry or use structural area as input.");
                                points.RemoveRange(63, points.Count - 63);
                            }

                            for (int i = 0; i < 3; ++i)
                            {
                                if (Math.Abs(al.Forces[i]) > 1.0E-6)
                                {
                                    sb.AppendFormat("{0} {1} {2}", cmd_string, ref_string, no_string);
                                    sb.AppendFormat(" TYPE {0} {1:F6}", load_types[0, i + type_off], al.Forces[i]);
                                    AppendLoadGeometry(sb, points);
                                    sb.AppendLine();
                                }
                            }

                            for (int i = 0; i < 3; ++i)
                            {
                                if (Math.Abs(al.Moments[i]) > 1.0E-6)
                                {
                                    sb.AppendFormat("{0} {1} {2}", cmd_string, ref_string, no_string);
                                    sb.AppendFormat(" TYPE {0} {1:F6}", load_types[1, i + type_off], al.Moments[i]);
                                    AppendLoadGeometry(sb, points);
                                    sb.AppendLine();
                                }
                            }
                        }
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unsupported type encountered: " + ld.TypeName);
                    }
                    sb.AppendLine();
                }
            }

            // write load case definitions not being considered before
            foreach (var ilc in load_cases)
            {
                sb.Append(ilc.Value);
                sb.AppendLine();
            }


            // add additional text
            foreach (var text in textList)
            {
                if (!string.IsNullOrEmpty(text))
                {
                    sb.AppendLine(text);
                }
            }

            sb.AppendLine();

            sb.AppendLine("END");

            // create output objects
            var loadModel = new gh_sofistik.General.SofistikModel()
            {
                CadInp = sb.ToString(), ModelType = gh_sofistik.General.SofistikModelType.SofiLOAD
            };
            var ghLoadModel = new gh_sofistik.General.GH_SofistikModel()
            {
                Value = loadModel
            };
            // create GH_Structure and use SetDataTree so output has always one branch with index {0}
            var outStruc = new GH_Structure <gh_sofistik.General.GH_SofistikModel>();

            outStruc.Append(ghLoadModel);
            da.SetDataTree(0, outStruc);
        }
Ejemplo n.º 3
0
        protected override void SolveInstance(IGH_DataAccess da)
        {
            // var modulString = da.GetData<string>(0);
            var lcStruc     = da.GetDataTree <GH_Integer>(0);
            var threadCount = da.GetData <int>(1);
            var ctrlList    = da.GetDataList <string>(2);

            var lcList = new List <int>();

            foreach (var it in lcStruc.AllData(true))
            {
                if (it is GH_Integer)
                {
                    lcList.Add((it as GH_Integer).Value);
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Data conversion failed from " + it.TypeName + " to GH_Integer.");
                }
            }

            bool isASE = true;
            // if (!string.IsNullOrEmpty(modulString) && modulString.ToLower() == "feabench")
            // {
            //    isASE = false;
            // }

            var sb = new StringBuilder();

            sb.AppendLine("+PROG " + (isASE ? "ASE" : "FEABENCH"));
            sb.AppendLine("HEAD");
            sb.AppendLine("PAGE UNII 0");
            if (threadCount != -1)
            {
                sb.AppendLine("CTRL CORE " + threadCount.ToString());
            }
            if (isASE)
            {
                sb.AppendLine("CTRL SOLV 4");
            }

            // add control string
            foreach (var ctrl in ctrlList)
            {
                if (!string.IsNullOrEmpty(ctrl))
                {
                    sb.AppendLine(ctrl);
                }
            }

            sb.AppendLine();

            if (lcList.Count == 0)
            {
                sb.AppendLine("LC ALL");
            }
            else
            {
                foreach (var lc in lcList)
                {
                    sb.AppendLine("LC " + lc.ToString());
                }
            }

            sb.AppendLine();

            sb.AppendLine("END");

            // create output objects
            var analysisModel = new gh_sofistik.General.SofistikModel()
            {
                CadInp = sb.ToString(), ModelType = gh_sofistik.General.SofistikModelType.Analysis
            };
            var ghAnalysisModel = new gh_sofistik.General.GH_SofistikModel()
            {
                Value = analysisModel
            };
            // create GH_Structure and use SetDataTree so output has always one branch with index {0}
            var outStruc = new GH_Structure <gh_sofistik.General.GH_SofistikModel>();

            outStruc.Append(ghAnalysisModel);
            da.SetDataTree(0, outStruc);
        }