public string SetGWACommand()
        {
            if (this.Value == null)
            {
                return("");
            }

            var load = this.Value as Structural2DLoad;

            if (load.Loading == null)
            {
                return("");
            }

            var keyword = typeof(GSA2DLoad).GetGSAKeyword();

            List <int> elementRefs;
            List <int> groupRefs;

            if (Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis)
            {
                elementRefs = Initialiser.Cache.LookupIndices(typeof(GSA2DElement).GetGSAKeyword(), load.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
                groupRefs   = Initialiser.Cache.LookupIndices(typeof(GSA2DElementMesh).GetGSAKeyword(), load.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
            }
            else if (Initialiser.Settings.TargetLayer == GSATargetLayer.Design)
            {
                elementRefs = new List <int>();
                groupRefs   = Initialiser.Cache.LookupIndices(typeof(GSA2DMember).GetGSAKeyword(), load.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
            }
            else
            {
                return("");
            }

            var loadCaseRef = 0;

            try
            {
                loadCaseRef = Initialiser.Cache.LookupIndex(typeof(GSALoadCase).GetGSAKeyword(), load.LoadCaseRef).Value;
            }
            catch {
                loadCaseRef = Initialiser.Cache.ResolveIndex(typeof(GSALoadCase).GetGSAKeyword(), load.LoadCaseRef);
            }

            var direction = new string[3] {
                "X", "Y", "Z"
            };

            var gwaCommands = new List <string>();

            for (var i = 0; i < load.Loading.Value.Count(); i++)
            {
                if (load.Loading.Value[i] == 0)
                {
                    continue;
                }

                var index = Initialiser.Cache.ResolveIndex(typeof(GSA2DLoad).GetGSAKeyword());

                var ls = new List <string>
                {
                    "SET_AT",
                    index.ToString(),
                    keyword + ":" + HelperClass.GenerateSID(load),
                    load.Name == null || load.Name == "" ? " " : load.Name,
                    // TODO: This is a hack.
                    string.Join(" ", elementRefs.Select(x => x.ToString()).Concat(groupRefs.Select(x => "G" + x.ToString()))),
                    loadCaseRef.ToString(),
                    load.AxisType == StructuralLoadAxisType.Local ? "LOCAL" : "GLOBAL", // Axis
                    "CONS",                                                             // Type
                    "NO",                                                               // Projected
                    direction[i],
                    load.Loading.Value[i].ToString()
                };

                gwaCommands.Add(string.Join("\t", ls));
            }

            return(string.Join("\n", gwaCommands));
        }
예제 #2
0
        public void ParseGWACommand(List <GSANode> nodes)
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new Structural0DLoad();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter = 1; // Skip identifier

            obj.Name = pieces[counter++].Trim(new char[] { '"' });

            var targetNodeRefs = Initialiser.Interface.ConvertGSAList(pieces[counter++], SpeckleGSAInterfaces.GSAEntity.NODE);

            if (nodes != null)
            {
                var targetNodes = nodes
                                  .Where(n => targetNodeRefs.Contains(n.GSAId)).ToList();

                obj.NodeRefs = targetNodes.Select(n => (string)n.Value.ApplicationId).ToList();
                this.SubGWACommand.AddRange(targetNodes.Select(n => n.GWACommand));

                foreach (var n in targetNodes)
                {
                    n.ForceSend = true;
                }
            }

            obj.LoadCaseRef = HelperClass.GetApplicationId(typeof(GSALoadCase).GetGSAKeyword(), Convert.ToInt32(pieces[counter++]));

            var axis = pieces[counter++];

            this.Axis = axis == "GLOBAL" ? 0 : Convert.ToInt32(axis);

            obj.Loading = new StructuralVectorSix(new double[6]);
            var direction = pieces[counter++].ToLower();

            switch (direction.ToUpper())
            {
            case "X":
                obj.Loading.Value[0] = Convert.ToDouble(pieces[counter++]);
                break;

            case "Y":
                obj.Loading.Value[1] = Convert.ToDouble(pieces[counter++]);
                break;

            case "Z":
                obj.Loading.Value[2] = Convert.ToDouble(pieces[counter++]);
                break;

            case "XX":
                obj.Loading.Value[3] = Convert.ToDouble(pieces[counter++]);
                break;

            case "YY":
                obj.Loading.Value[4] = Convert.ToDouble(pieces[counter++]);
                break;

            case "ZZ":
                obj.Loading.Value[5] = Convert.ToDouble(pieces[counter++]);
                break;

            default:
                // TODO: Error case maybe?
                break;
            }

            this.Value = obj;
        }
        public string SetGWACommand()
        {
            if (this.Value == null)
            {
                return("");
            }

            var loading = this.Value as Structural2DThermalLoad;

            var keyword = typeof(GSA2DThermalLoading).GetGSAKeyword();

            var index = Initialiser.Cache.ResolveIndex(typeof(GSA2DThermalLoading).GetGSAKeyword(), loading.ApplicationId);

            var targetString = " ";

            if (loading.ElementRefs != null && loading.ElementRefs.Count() > 0)
            {
                if (Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis)
                {
                    var e2DIndices     = Initialiser.Cache.LookupIndices(typeof(GSA2DElement).GetGSAKeyword(), loading.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
                    var e2DMeshIndices = Initialiser.Cache.LookupIndices(typeof(GSA2DElementMesh).GetGSAKeyword(), loading.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
                    targetString = string.Join(" ",
                                               e2DIndices.Select(x => x.ToString())
                                               .Concat(e2DMeshIndices.Select(x => "G" + x.ToString()))
                                               );
                }
                else if (Initialiser.Settings.TargetLayer == GSATargetLayer.Design)
                {
                    var m2DIndices = Initialiser.Cache.LookupIndices(typeof(GSA2DMember).GetGSAKeyword(), loading.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
                    targetString = string.Join(" ",
                                               m2DIndices.Select(x => "G" + x.ToString()));
                }
            }

            var loadCaseRef = Initialiser.Cache.LookupIndex(typeof(GSALoadCase).GetGSAKeyword(), loading.LoadCaseRef);

            var loadingName = string.IsNullOrEmpty(loading.Name) ? " " : loading.Name;

            var ls = new List <string>
            {
                "SET_AT",
                index.ToString(),
                keyword + ":" + HelperClass.GenerateSID(loading),
                loadingName,  // Name
                targetString, //Elements
                (loadCaseRef.HasValue) ? loadCaseRef.Value.ToString() : "1",
            };

            if (loading.TopTemperature == loading.BottomTemperature)
            {
                ls.Add("CONS");
                ls.Add(loading.TopTemperature.ToString());
            }
            else
            {
                ls.Add("DZ");
                ls.Add(loading.TopTemperature.ToString());
                ls.Add(loading.BottomTemperature.ToString());
            }

            return(string.Join("\t", ls));
        }
        public void ParseGWACommand(List <GSA1DElement> elements, List <GSA1DMember> members)
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new Structural1DLoad();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter    = 0; // Skip identifier
            var identifier = pieces[counter++];

            obj.Name = pieces[counter++].Trim(new char[] { '"' });

            if (Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis)
            {
                var targetElements = Initialiser.Interface.ConvertGSAList(pieces[counter++], SpeckleGSAInterfaces.GSAEntity.ELEMENT);

                if (elements != null)
                {
                    var elems = elements.Where(n => targetElements.Contains(n.GSAId)).ToList();

                    obj.ElementRefs = elems.Select(n => (string)n.Value.ApplicationId).ToList();
                    this.SubGWACommand.AddRange(elems.Select(n => n.GWACommand));
                }
            }
            else if (Initialiser.Settings.TargetLayer == GSATargetLayer.Design)
            {
                var targetGroups = HelperClass.GetGroupsFromGSAList(pieces[counter++]);

                if (members != null)
                {
                    var membs = members.Where(m => targetGroups.Contains(m.Group)).ToList();

                    obj.ElementRefs = membs.Select(m => (string)m.Value.ApplicationId).ToList();
                    this.SubGWACommand.AddRange(membs.Select(n => n.GWACommand));
                }
            }

            obj.LoadCaseRef = HelperClass.GetApplicationId(typeof(GSALoadCase).GetGSAKeyword(), Convert.ToInt32(pieces[counter++]));

            var axis = pieces[counter++];

            this.Axis = axis == "GLOBAL" ? 0 : -1;// Convert.ToInt32(axis); // TODO: Assume local if not global

            this.Projected = pieces[counter++] == "YES";

            obj.Loading = new StructuralVectorSix(new double[6]);
            var direction = pieces[counter++].ToLower();

            double value = 0;

            // TODO: Only reads UDL load properly
            if (identifier.Contains("LOAD_BEAM_POINT.2"))
            {
                counter++; // Position
                counter++; // Value
                value = 0;
            }
            else if (identifier.Contains("LOAD_BEAM_UDL.2"))
            {
                value = Convert.ToDouble(pieces[counter++]);
            }
            else if (identifier.Contains("LOAD_BEAM_LINE.2"))
            {
                value  = Convert.ToDouble(pieces[counter++]);
                value += Convert.ToDouble(pieces[counter++]);
                value /= 2;
            }
            else if (identifier.Contains("LOAD_BEAM_PATCH.2"))
            {
                counter++; // Position
                value = Convert.ToDouble(pieces[counter++]);
                counter++; // Position
                value += Convert.ToDouble(pieces[counter++]);
                value /= 2;
            }
            else if (identifier.Contains("LOAD_BEAM_TRILIN.2"))
            {
                counter++; // Position
                value = Convert.ToDouble(pieces[counter++]);
                counter++; // Position
                value += Convert.ToDouble(pieces[counter++]);
                value /= 2;
            }
            else
            {
                value = 0;
            }

            switch (direction.ToUpper())
            {
            case "X":
                obj.Loading.Value[0] = value;
                break;

            case "Y":
                obj.Loading.Value[1] = value;
                break;

            case "Z":
                obj.Loading.Value[2] = value;
                break;

            case "XX":
                obj.Loading.Value[3] = value;
                break;

            case "YY":
                obj.Loading.Value[4] = value;
                break;

            case "ZZ":
                obj.Loading.Value[5] = value;
                break;

            default:
                // TODO: Error case maybe?
                break;
            }

            this.Value = obj;
        }
        public string SetGWACommand()
        {
            if (this.Value == null)
            {
                return("");
            }

            var loadCombo = this.Value as StructuralLoadCombo;

            var keyword = typeof(GSALoadCombo).GetGSAKeyword();

            var index = Initialiser.Cache.ResolveIndex(typeof(GSALoadCombo).GetGSAKeyword(), loadCombo.ApplicationId);

            var ls = new List <string>
            {
                "SET",
                keyword + ":" + HelperClass.GenerateSID(loadCombo),
                index.ToString(),
                loadCombo.Name == null || loadCombo.Name == "" ? " " : loadCombo.Name
            };

            var subLs = new List <string>();

            if (loadCombo.LoadTaskRefs != null)
            {
                for (var i = 0; i < loadCombo.LoadTaskRefs.Count(); i++)
                {
                    var loadTaskRef = Initialiser.Cache.LookupIndex(typeof(GSALoadTask).GetGSAKeyword(), loadCombo.LoadTaskRefs[i]);

                    if (loadTaskRef.HasValue)
                    {
                        subLs.Add((loadCombo.LoadTaskFactors != null && loadCombo.LoadTaskFactors.Count() > i)
              ? loadCombo.LoadTaskFactors[i].ToString() + "A" + loadTaskRef.Value.ToString()
              : "A" + loadTaskRef.Value.ToString());
                    }
                }
            }

            if (loadCombo.LoadComboRefs != null)
            {
                for (var i = 0; i < loadCombo.LoadComboRefs.Count(); i++)
                {
                    var loadComboRef = Initialiser.Cache.LookupIndex(typeof(GSALoadTask).GetGSAKeyword(), loadCombo.LoadComboRefs[i]);

                    if (loadComboRef.HasValue)
                    {
                        subLs.Add((loadCombo.LoadComboFactors != null && loadCombo.LoadComboFactors.Count() > i)
              ? loadCombo.LoadComboFactors[i].ToString() + "C" + loadComboRef.Value.ToString()
              : "C" + loadComboRef.Value.ToString());
                    }
                }
            }

            switch (loadCombo.ComboType)
            {
            case StructuralLoadComboType.LinearAdd:
                ls.Add(string.Join(" + ", subLs));
                break;

            case StructuralLoadComboType.Envelope:
                ls.Add(string.Join(" or ", subLs));
                break;

            default:
                ls.Add(string.Join(" + ", subLs));
                break;
            }

            return(string.Join("\t", ls));
        }
예제 #6
0
        public string SetGWACommand()
        {
            if (this.Value == null)
            {
                return("");
            }

            var load = this.Value as Structural2DLoadPanel;

            if (load.Loading == null)
            {
                return("");
            }

            var keyword = typeof(GSAGridAreaLoad).GetGSAKeyword();

            //There are no GSA types for these yet so use empty strings for the type names for the index
            var gridSurfaceIndex = Initialiser.Cache.ResolveIndex("GRID_SURFACE.1");
            var gridPlaneIndex   = Initialiser.Cache.ResolveIndex("GRID_PLANE.4");

            var loadCaseIndex = 0;

            try
            {
                loadCaseIndex = Initialiser.Cache.LookupIndex(typeof(GSALoadCase).GetGSAKeyword(), load.LoadCaseRef).Value;
            }
            catch { }

            var axis = HelperClass.Parse2DAxis(load.Value.ToArray());

            // Calculate elevation
            var elevation = (load.Value[0] * axis.Normal.Value[0] +
                             load.Value[1] * axis.Normal.Value[1] +
                             load.Value[2] * axis.Normal.Value[2]) /
                            Math.Sqrt(axis.Normal.Value[0] * axis.Normal.Value[0] +
                                      axis.Normal.Value[1] * axis.Normal.Value[1] +
                                      axis.Normal.Value[2] * axis.Normal.Value[2]);

            // Transform coordinate to new axis
            var transformed = HelperClass.MapPointsGlobal2Local(load.Value.ToArray(), axis);

            var ls = new List <string>();

            var direction = new string[3] {
                "X", "Y", "Z"
            };

            var gwaCommands = new List <string>();

            for (var i = 0; i < load.Loading.Value.Count(); i++)
            {
                if (load.Loading.Value[i] == 0)
                {
                    continue;
                }

                var index = Initialiser.Cache.ResolveIndex(typeof(GSAGridAreaLoad).GetGSAKeyword());

                ls.Clear();
                var subLs = new List <string>();
                for (var j = 0; j < transformed.Count(); j += 3)
                {
                    subLs.Add("(" + transformed[j].ToString() + "," + transformed[j + 1].ToString() + ")");
                }

                ls.AddRange(new string[] {
                    "SET_AT",
                    index.ToString(),
                    keyword + ":" + HelperClass.GenerateSID(load),
                    load.Name == null || load.Name == "" ? " " : load.Name,
                    gridSurfaceIndex.ToString(),
                    "POLYGON",
                    string.Join(" ", subLs),
                    loadCaseIndex.ToString(),
                    "GLOBAL",
                    "NO",
                    direction[i],
                    load.Loading.Value[i].ToString()
                });

                gwaCommands.Add(string.Join("\t", ls));
            }

            ls.Clear();
            ls.AddRange(new[] {
                "SET",
                "GRID_SURFACE.1",
                gridSurfaceIndex.ToString(),
                load.Name == null || load.Name == "" ? " " : load.Name,
                gridPlaneIndex.ToString(),
                "2",    // Dimension of elements to target
                "all",  // List of elements to target
                "0.01", // Tolerance
                "ONE",  // Span option
                "0"
            });         // Span angle
            gwaCommands.Add(string.Join("\t", ls));

            ls.Clear();
            HelperClass.SetAxis(axis, out int planeAxisIndex, out string planeAxisGwa, load.Name);
            if (planeAxisGwa.Length > 0)
            {
                gwaCommands.Add(planeAxisGwa);
            }

            ls.AddRange(new[] {
                "SET",
                "GRID_PLANE.4",
                gridPlaneIndex.ToString(),
                load.Name == null || load.Name == "" ? " " : load.Name,
                "GENERAL", // Type
                planeAxisIndex.ToString(),
                elevation.ToString(),
                "0", // Elevation above
                "0"
            });      // Elevation below
            gwaCommands.Add(string.Join("\t", ls));

            return(string.Join("\n", gwaCommands));
        }
        public string SetGWACommand()
        {
            if (this.Value == null)
            {
                return("");
            }

            var load = this.Value as Structural1DLoad;

            if (load.Loading == null)
            {
                return("");
            }

            var keyword = typeof(GSA1DLoad).GetGSAKeyword();

            List <int> elementRefs;
            List <int> groupRefs;

            if (Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis)
            {
                elementRefs = Initialiser.Cache.LookupIndices(typeof(GSA1DElement).GetGSAKeyword(), load.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
                groupRefs   = Initialiser.Cache.LookupIndices(typeof(GSA1DElementPolyline).GetGSAKeyword(), load.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
            }
            else if (Initialiser.Settings.TargetLayer == GSATargetLayer.Design)
            {
                elementRefs = new List <int>();
                groupRefs   = Initialiser.Cache.LookupIndices(typeof(GSA1DMember).GetGSAKeyword(), load.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
                groupRefs.AddRange(Initialiser.Cache.LookupIndices(typeof(GSA1DElementPolyline).GetGSAKeyword(), load.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList());
            }
            else
            {
                return("");
            }

            var loadCaseRef = 0;

            try
            {
                loadCaseRef = Initialiser.Cache.LookupIndex(typeof(GSALoadCase).GetGSAKeyword(), load.LoadCaseRef).Value;
            }
            catch {
                loadCaseRef = Initialiser.Cache.LookupIndex(typeof(GSALoadCase).GetGSAKeyword(), load.LoadCaseRef).Value;
            }

            var direction = new string[6] {
                "X", "Y", "Z", "XX", "YY", "ZZ"
            };

            var gwaCommands = new List <string>();

            for (var i = 0; i < load.Loading.Value.Count(); i++)
            {
                var ls = new List <string>();

                if (load.Loading.Value[i] == 0)
                {
                    continue;
                }

                var index = Initialiser.Cache.ResolveIndex(typeof(GSA1DLoad).GetGSAKeyword());

                ls.Add("SET_AT");
                ls.Add(index.ToString());
                ls.Add("LOAD_BEAM_UDL" + ":" + HelperClass.GenerateSID(load)); // TODO: Only writes to UDL load
                ls.Add(load.Name == null || load.Name == "" ? " " : load.Name);
                // TODO: This is a hack.
                ls.Add(string.Join(" ", elementRefs.Select(x => x.ToString()).Concat(groupRefs.Select(x => "G" + x.ToString()))));
                ls.Add(loadCaseRef.ToString());
                ls.Add("GLOBAL"); // Axis
                ls.Add("NO");     // Projected
                ls.Add(direction[i]);
                ls.Add(load.Loading.Value[i].ToString());

                gwaCommands.Add(string.Join("\t", ls));
            }

            return(string.Join("\n", gwaCommands));
        }
        public string SetGWACommand()
        {
            if (this.Value == null)
            {
                return("");
            }

            var loadCase = this.Value as StructuralLoadCase;

            var keyword = typeof(GSALoadCase).GetGSAKeyword();

            var index = Initialiser.Cache.ResolveIndex(typeof(GSALoadCase).GetGSAKeyword(), loadCase.ApplicationId);

            var ls = new List <string>
            {
                "SET",
                keyword + ":" + HelperClass.GenerateSID(loadCase),
                index.ToString(),
                loadCase.Name == null || loadCase.Name == "" ? " " : loadCase.Name
            };

            switch (loadCase.CaseType)
            {
            case StructuralLoadCaseType.Dead:
                ls.Add("DEAD");
                break;

            case StructuralLoadCaseType.Live:
                ls.Add("LC_VAR_IMP");
                break;

            case StructuralLoadCaseType.Wind:
                ls.Add("WIND");
                break;

            case StructuralLoadCaseType.Snow:
                ls.Add("SNOW");
                break;

            case StructuralLoadCaseType.Earthquake:
                ls.Add("SEISMIC");
                break;

            case StructuralLoadCaseType.Soil:
                ls.Add("LC_PERM_SOIL");
                break;

            case StructuralLoadCaseType.Thermal:
                ls.Add("LC_VAR_TEMP");
                break;

            default:
                ls.Add("LC_UNDEF");
                break;
            }
            ls.Add("1");        // Source
            ls.Add("~");        // Category
            ls.Add("NONE");     // Direction
            ls.Add("INC_BOTH"); // Include

            return(string.Join("\t", ls));
        }
예제 #9
0
        public string SetGWACommand()
        {
            if (this.Value == null)
            {
                return("");
            }

            var v = this.Value as Structural2DVoid;

            var keyword = typeof(GSA2DVoid).GetGSAKeyword();

            var index = Initialiser.Cache.ResolveIndex(keyword, v.ApplicationId);

            var ls = new List <string>
            {
                "SET",
                keyword + ":" + HelperClass.GenerateSID(v),
                index.ToString(),
                v.Name == null || v.Name == "" ? " " : v.Name,
                v.Colors == null || v.Colors.Count() < 1 ? "NO_RGB" : v.Colors[0].ArgbToHexColor().ToString(),
                "2D_VOID_CUTTER",
                "1", // Property reference
                "0"  // Group
            };
            var topo           = "";
            var prevNodeIndex  = -1;
            var connectivities = v.Edges();
            var coor           = new List <double>();

            if (connectivities.Count == 0)
            {
                return("");
            }

            foreach (var c in connectivities[0])
            {
                coor.AddRange(v.Vertices.Skip(c * 3).Take(3));
                var currIndex = HelperClass.NodeAt(v.Vertices[c * 3], v.Vertices[c * 3 + 1], v.Vertices[c * 3 + 2], Initialiser.Settings.CoincidentNodeAllowance);
                if (prevNodeIndex != currIndex)
                {
                    topo += currIndex.ToString() + " ";
                }
                prevNodeIndex = currIndex;
            }

            ls.Add(topo);
            ls.Add("0");      // Orientation node
            ls.Add("0");      // Angles
            ls.Add("1");      // Target mesh size
            ls.Add("MESH");   // TODO: What is this?
            ls.Add("LINEAR"); // Element type
            ls.Add("0");      // Fire
            ls.Add("0");      // Time 1
            ls.Add("0");      // Time 2
            ls.Add("0");      // Time 3
            ls.Add("0");      // TODO: What is this?
            ls.Add("ACTIVE"); // Dummy
            ls.Add("NO");     // Internal auto offset
            ls.Add("0");      // Offset z
            ls.Add("ALL");    // Exposure

            return(string.Join("\t", ls));
        }
예제 #10
0
        public void ParseGWACommand(List <GSANode> nodes, List <GSA1DElement> e1Ds, List <GSA2DElement> e2Ds, List <GSA1DMember> m1Ds, List <GSA2DMember> m2Ds)
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new StructuralAssembly();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter = 1; // Skip identifier

            this.GSAId        = Convert.ToInt32(pieces[counter++]);
            obj.ApplicationId = HelperClass.GetApplicationId(this.GetGSAKeyword(), this.GSAId);
            obj.Name          = pieces[counter++].Trim(new char[] { '"' });

            var targetEntity = pieces[counter++];

            var targetList = pieces[counter++];

            obj.ElementRefs = new List <string>();

            if (Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis)
            {
                if (targetEntity == "MEMBER")
                {
                    var memberList = Initialiser.Interface.ConvertGSAList(targetList, SpeckleGSAInterfaces.GSAEntity.MEMBER);
                    var match1D    = e1Ds.Where(e => memberList.Contains(Convert.ToInt32(e.Member)));
                    var match2D    = e2Ds.Where(e => memberList.Contains(Convert.ToInt32(e.Member)));
                    obj.ElementRefs.AddRange(match1D.Select(e => (e.Value as SpeckleObject).ApplicationId.ToString()));
                    obj.ElementRefs.AddRange(match2D.Select(e => (e.Value as SpeckleObject).ApplicationId.ToString()));
                    this.SubGWACommand.AddRange(match1D.Select(e => (e as IGSASpeckleContainer).GWACommand));
                    this.SubGWACommand.AddRange(match2D.Select(e => (e as IGSASpeckleContainer).GWACommand));
                }
                else if (targetEntity == "ELEMENT")
                {
                    var elementList = Initialiser.Interface.ConvertGSAList(targetList, SpeckleGSAInterfaces.GSAEntity.ELEMENT);
                    var match1D     = e1Ds.Where(e => elementList.Contains(e.GSAId));
                    var match2D     = e2Ds.Where(e => elementList.Contains(e.GSAId));
                    obj.ElementRefs.AddRange(match1D.Select(e => (e.Value as SpeckleObject).ApplicationId.ToString()));
                    obj.ElementRefs.AddRange(match2D.Select(e => (e.Value as SpeckleObject).ApplicationId.ToString()));
                    this.SubGWACommand.AddRange(match1D.Select(e => (e as IGSASpeckleContainer).GWACommand));
                    this.SubGWACommand.AddRange(match2D.Select(e => (e as IGSASpeckleContainer).GWACommand));
                }
            }
            else if (Initialiser.Settings.TargetLayer == GSATargetLayer.Design)
            {
                if (targetEntity == "MEMBER")
                {
                    var memberList = Initialiser.Interface.ConvertGSAList(targetList, SpeckleGSAInterfaces.GSAEntity.MEMBER);
                    var match1D    = m1Ds.Where(e => memberList.Contains(e.GSAId));
                    var match2D    = m2Ds.Where(e => memberList.Contains(e.GSAId));
                    obj.ElementRefs.AddRange(match1D.Select(e => (e.Value as SpeckleObject).ApplicationId.ToString()));
                    obj.ElementRefs.AddRange(match2D.Select(e => (e.Value as SpeckleObject).ApplicationId.ToString()));
                    this.SubGWACommand.AddRange(match1D.Select(e => (e as IGSASpeckleContainer).GWACommand));
                    this.SubGWACommand.AddRange(match2D.Select(e => (e as IGSASpeckleContainer).GWACommand));
                }
                else if (targetEntity == "ELEMENT")
                {
                    //Unlike all other classes, the layer relevant to sending is only determined by looking at a GWA parameter rather than a class attribute.
                    //Once this condition has been met, assign to null so it won't form part of the sender objects list
                    Value = null;
                    return;
                }
            }

            obj.Value = new List <double>();
            for (var i = 0; i < 2; i++)
            {
                var key  = pieces[counter++];
                var node = nodes.Where(n => n.GSAId == Convert.ToInt32(key)).FirstOrDefault();
                obj.Value.AddRange(node.Value.Value);
                this.SubGWACommand.Add(node.GWACommand);
            }
            var orientationNodeId = Convert.ToInt32(pieces[counter++]);
            var orientationNode   = nodes.Where(n => n.GSAId == orientationNodeId).FirstOrDefault();

            this.SubGWACommand.Add(orientationNode.GWACommand);
            obj.OrientationPoint = new SpecklePoint(orientationNode.Value.Value[0], orientationNode.Value.Value[1], orientationNode.Value.Value[2]);

            counter++; // Internal topology
            obj.Width = (Convert.ToDouble(pieces[counter++]) + Convert.ToDouble(pieces[counter++])) / 2;

            this.Value = obj;
        }
예제 #11
0
        /// <summary>
        /// Calculates the local axis of a 2D entity.
        /// </summary>
        /// <param name="coor">Entity coordinates</param>
        /// <param name="rotationAngle">Angle of rotation from default axis</param>
        /// <param name="isLocalAxis">Is axis calculated from local coordinates?</param>
        /// <returns>Axis</returns>
        public static StructuralAxis Parse2DAxis(double[] coor, double rotationAngle = 0, bool isLocalAxis = false)
        {
            Vector3D x;
            Vector3D y;
            Vector3D z;

            var nodes = new List <Vector3D>();

            for (var i = 0; i < coor.Length; i += 3)
            {
                nodes.Add(new Vector3D(coor[i], coor[i + 1], coor[i + 2]));
            }

            if (isLocalAxis)
            {
                if (nodes.Count == 3)
                {
                    x = Vector3D.Subtract(nodes[1], nodes[0]);
                    x.Normalize();
                    z = Vector3D.CrossProduct(x, Vector3D.Subtract(nodes[2], nodes[0]));
                    z.Normalize();
                    y = Vector3D.CrossProduct(z, x);
                    y.Normalize();
                }
                else if (nodes.Count == 4)
                {
                    x = Vector3D.Subtract(nodes[2], nodes[0]);
                    x.Normalize();
                    z = Vector3D.CrossProduct(x, Vector3D.Subtract(nodes[3], nodes[1]));
                    z.Normalize();
                    y = Vector3D.CrossProduct(z, x);
                    y.Normalize();
                }
                else
                {
                    // Default to QUAD method
                    x = Vector3D.Subtract(nodes[2], nodes[0]);
                    x.Normalize();
                    z = Vector3D.CrossProduct(x, Vector3D.Subtract(nodes[3], nodes[1]));
                    z.Normalize();
                    y = Vector3D.CrossProduct(z, x);
                    y.Normalize();
                }
            }
            else
            {
                x = Vector3D.Subtract(nodes[1], nodes[0]);
                x.Normalize();
                z = Vector3D.CrossProduct(x, Vector3D.Subtract(nodes[2], nodes[0]));
                z.Normalize();

                x = new Vector3D(1, 0, 0);
                x = Vector3D.Subtract(x, Vector3D.Multiply(Vector3D.DotProduct(x, z), z));

                if (x.Length == 0)
                {
                    x = new Vector3D(0, z.X > 0 ? -1 : 1, 0);
                }

                y = Vector3D.CrossProduct(z, x);

                x.Normalize();
                y.Normalize();
            }

            //Rotation
            var rotMat = HelperClass.RotationMatrix(z, rotationAngle * (Math.PI / 180));

            x = Vector3D.Multiply(x, rotMat);
            y = Vector3D.Multiply(y, rotMat);

            return(new StructuralAxis(
                       new StructuralVectorThree(new double[] { x.X, x.Y, x.Z }),
                       new StructuralVectorThree(new double[] { y.X, y.Y, y.Z }),
                       new StructuralVectorThree(new double[] { z.X, z.Y, z.Z })
                       ));
        }
예제 #12
0
        public string SetGWACommand()
        {
            if (this.Value == null)
            {
                return("");
            }

            var destType = typeof(GSAAssembly);

            var assembly = this.Value as StructuralAssembly;

            var keyword = destType.GetGSAKeyword();

            var index = Initialiser.Cache.ResolveIndex(keyword, assembly.ApplicationId);

            var targetString = " ";

            if (assembly.ElementRefs != null && assembly.ElementRefs.Count() > 0)
            {
                var polylineIndices = Initialiser.Cache.LookupIndices(typeof(GSA1DElementPolyline).GetGSAKeyword(), assembly.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
                if (Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis)
                {
                    var e1DIndices     = Initialiser.Cache.LookupIndices(typeof(GSA1DElement).GetGSAKeyword(), assembly.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
                    var e2DIndices     = Initialiser.Cache.LookupIndices(typeof(GSA2DElement).GetGSAKeyword(), assembly.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
                    var e2DMeshIndices = Initialiser.Cache.LookupIndices(typeof(GSA2DElementMesh).GetGSAKeyword(), assembly.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();

                    var indices = new List <int>(e1DIndices);
                    indices.AddRange(e2DIndices);
                    indices.AddRange(e2DMeshIndices);
                    indices = indices.Distinct().ToList();

                    targetString = string.Join(" ", indices.Select(x => x.ToString()));
                }
                else if (Initialiser.Settings.TargetLayer == GSATargetLayer.Design)
                {
                    var m1DIndices = Initialiser.Cache.LookupIndices(typeof(GSA1DMember).GetGSAKeyword(), assembly.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();
                    var m2DIndices = Initialiser.Cache.LookupIndices(typeof(GSA2DMember).GetGSAKeyword(), assembly.ElementRefs).Where(x => x.HasValue).Select(x => x.Value).ToList();

                    var indices = new List <int>(m1DIndices);
                    indices.AddRange(m2DIndices);
                    indices = indices.Distinct().ToList();

                    // TODO: Once assemblies can properly target members, this should target members explicitly
                    targetString = string.Join(" ", indices.Select(i => "G" + i.ToString()));
                }
            }

            var nodeIndices = new List <int>();

            for (var i = 0; i < assembly.Value.Count(); i += 3)
            {
                nodeIndices.Add(HelperClass.NodeAt(assembly.Value[i], assembly.Value[i + 1], assembly.Value[i + 2], Initialiser.Settings.CoincidentNodeAllowance));
            }

            var numPoints = (assembly.NumPoints == 0) ? 10 : assembly.NumPoints;

            //The width parameter is intentionally not being used here as the meaning doesn't map to the y coordinate parameter of the ASSEMBLY keyword
            //It is therefore to be ignored here for GSA purposes.

            var ls = new List <string>
            {
                "SET",
                keyword + ":" + HelperClass.GenerateSID(assembly),
                index.ToString(),
                string.IsNullOrEmpty(assembly.Name) ? "" : assembly.Name,
                // TODO: Once assemblies can properly target members, this should target members explicitly
                //Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis ? "ELEMENT" : "MEMBER",
                "ELEMENT",
                targetString,
                nodeIndices[0].ToString(),
                nodeIndices[1].ToString(),
                HelperClass.NodeAt(assembly.OrientationPoint.Value[0], assembly.OrientationPoint.Value[1], assembly.OrientationPoint.Value[2], Initialiser.Settings.CoincidentNodeAllowance).ToString(),
                "",                        //Empty list for int_topo as it assumed that the line is never curved
                assembly.Width.ToString(), //Y
                "0",                       //Z
                "LAGRANGE",
                "0",                       //Curve order - reserved for future use according to the documentation
                "POINTS",
                numPoints.ToString()       //Number of points
            };

            return(string.Join("\t", ls));
        }
        public void ParseGWACommand(List <GSA2DElement> elements, List <GSA2DMember> members)
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new Structural2DLoad();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter = 1; // Skip identifier

            obj.Name = pieces[counter++].Trim(new char[] { '"' });

            if (Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis)
            {
                var targetElements = Initialiser.Interface.ConvertGSAList(pieces[counter++], SpeckleGSAInterfaces.GSAEntity.ELEMENT);

                if (elements != null)
                {
                    var elems = elements.Where(n => targetElements.Contains(n.GSAId)).ToList();

                    obj.ElementRefs = elems.Select(n => (string)n.Value.ApplicationId).ToList();
                    this.SubGWACommand.AddRange(elems.Select(n => n.GWACommand));
                }
            }
            else if (Initialiser.Settings.TargetLayer == GSATargetLayer.Design)
            {
                var targetGroups = HelperClass.GetGroupsFromGSAList(pieces[counter++]);

                if (members != null)
                {
                    var membs = members.Where(m => targetGroups.Contains(m.Group)).ToList();

                    obj.ElementRefs = membs.Select(m => (string)m.Value.ApplicationId).ToList();
                    this.SubGWACommand.AddRange(membs.Select(n => n.GWACommand));
                }
            }

            obj.LoadCaseRef = HelperClass.GetApplicationId(typeof(GSALoadCase).GetGSAKeyword(), Convert.ToInt32(pieces[counter++]));

            var axis = pieces[counter++];

            this.Axis = axis == "GLOBAL" ? 0 : -1;// Convert.ToInt32(axis); // TODO: Assume local if not global

            obj.AxisType = (axis == "LOCAL") ? StructuralLoadAxisType.Local : StructuralLoadAxisType.Global;

            counter++; // Type. TODO: Skipping since we're taking the average

            this.Projected = pieces[counter++] == "YES";

            obj.Loading = new StructuralVectorThree(new double[3]);
            var direction = pieces[counter++].ToLower();

            var values = pieces.Skip(counter).Select(p => Convert.ToDouble(p)).ToArray();

            switch (direction.ToUpper())
            {
            case "X":
                obj.Loading.Value[0] = values.Average();
                break;

            case "Y":
                obj.Loading.Value[1] = values.Average();
                break;

            case "Z":
                obj.Loading.Value[2] = values.Average();
                break;

            default:
                // TODO: Error case maybe?
                break;
            }

            this.Value = obj;
        }
        public static SpeckleObject ToSpeckle(this GSA2DLoad dummyObject)
        {
            var newLines = ToSpeckleBase <GSA2DLoad>();

            var loads    = new List <GSA2DLoad>();
            var elements = (Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis) ? Initialiser.GSASenderObjects[typeof(GSA2DElement)].Cast <GSA2DElement>().ToList() : new List <GSA2DElement>();
            var members  = (Initialiser.Settings.TargetLayer == GSATargetLayer.Design) ? Initialiser.GSASenderObjects[typeof(GSA2DMember)].Cast <GSA2DMember>().ToList() : new List <GSA2DMember>();

            foreach (var p in newLines.Values)
            {
                var loadSubList = new List <GSA2DLoad>();

                // Placeholder load object to get list of elements and load values
                // Need to transform to axis so one load definition may be transformed to many
                var initLoad = new GSA2DLoad()
                {
                    GWACommand = p
                };
                initLoad.ParseGWACommand(elements, members);

                if (Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis)
                {
                    // Create load for each element applied
                    foreach (string nRef in initLoad.Value.ElementRefs)
                    {
                        var load = new GSA2DLoad
                        {
                            GWACommand    = initLoad.GWACommand,
                            SubGWACommand = new List <string>(initLoad.SubGWACommand)
                        };
                        load.Value.Name        = initLoad.Value.Name;
                        load.Value.LoadCaseRef = initLoad.Value.LoadCaseRef;

                        // Transform load to defined axis
                        var            elem     = elements.Where(e => e.Value.ApplicationId == nRef).First();
                        StructuralAxis loadAxis = HelperClass.Parse2DAxis(elem.Value.Vertices.ToArray(), 0, load.Axis != 0); // Assumes if not global, local
                        load.Value.Loading = initLoad.Value.Loading;

                        // Perform projection
                        if (load.Projected)
                        {
                            load.Value.Loading.Value[0] = 0;
                            load.Value.Loading.Value[1] = 0;
                        }
                        load.Value.Loading.TransformOntoAxis(loadAxis);

                        // If the loading already exists, add element ref to list
                        var match = loadSubList.Count() > 0 ? loadSubList.Where(l => l.Value.Loading.Equals(load.Value.Loading)).First() : null;
                        if (match != null)
                        {
                            match.Value.ElementRefs.Add(nRef);
                        }
                        else
                        {
                            load.Value.ElementRefs = new List <string>()
                            {
                                nRef
                            };
                            loadSubList.Add(load);
                        }
                    }
                }
                else if (Initialiser.Settings.TargetLayer == GSATargetLayer.Design)
                {
                    // Create load for each element applied
                    foreach (string nRef in initLoad.Value.ElementRefs)
                    {
                        var load = new GSA2DLoad
                        {
                            GWACommand    = initLoad.GWACommand,
                            SubGWACommand = new List <string>(initLoad.SubGWACommand),
                        };
                        load.Value.Name        = initLoad.Value.Name;
                        load.Value.LoadCaseRef = initLoad.Value.LoadCaseRef;

                        // Transform load to defined axis
                        var            memb     = members.Where(e => e.Value.ApplicationId == nRef).First();
                        StructuralAxis loadAxis = HelperClass.Parse2DAxis(memb.Value.Vertices.ToArray(), 0, load.Axis != 0); // Assumes if not global, local
                        load.Value.Loading = initLoad.Value.Loading;
                        load.Value.Loading.TransformOntoAxis(loadAxis);

                        // Perform projection
                        if (load.Projected)
                        {
                            load.Value.Loading.Value[0] = 0;
                            load.Value.Loading.Value[1] = 0;
                        }
                        load.Value.Loading.TransformOntoAxis(loadAxis);

                        // If the loading already exists, add element ref to list
                        var match = loadSubList.Count() > 0 ? loadSubList.Where(l => (l.Value.Loading.Value as List <double>).SequenceEqual(load.Value.Loading.Value as List <double>)).First() : null;
                        if (match != null)
                        {
                            match.Value.ElementRefs.Add(nRef);
                        }
                        else
                        {
                            load.Value.ElementRefs = new List <string>()
                            {
                                nRef
                            };
                            loadSubList.Add(load);
                        }
                    }
                }

                loads.AddRange(loadSubList);
            }

            Initialiser.GSASenderObjects[typeof(GSA2DLoad)].AddRange(loads);

            return((loads.Count() > 0) ? new SpeckleObject() : new SpeckleNull());
        }
예제 #15
0
        public string SetGWACommand()
        {
            if (this.Value == null)
            {
                return("");
            }

            var infl = this.Value as StructuralNodalInfluenceEffect;

            var keyword = typeof(GSANodalInfluenceEffect).GetGSAKeyword();

            var index = Initialiser.Cache.ResolveIndex(typeof(GSANodalInfluenceEffect).GetGSAKeyword(), infl.ApplicationId);

            var nodeRef = Initialiser.Cache.LookupIndex(typeof(GSANode).GetGSAKeyword(), infl.NodeRef);

            if (!nodeRef.HasValue)
            {
                return("");
            }

            var gwaCommands = new List <string>();

            HelperClass.SetAxis(infl.Axis, out var axisIndex, out var axisGwa, infl.Name);
            if (axisGwa.Length > 0)
            {
                gwaCommands.Add(axisGwa);
            }

            var direction = new string[6] {
                "X", "Y", "Z", "XX", "YY", "ZZ"
            };

            for (var i = 0; i < infl.Directions.Value.Count(); i++)
            {
                var ls = new List <string>
                {
                    "SET_AT",
                    index.ToString(),
                    keyword + ":" + HelperClass.GenerateSID(infl),
                    infl.Name == null || infl.Name == "" ? " " : infl.Name,
                    infl.GSAEffectGroup.ToString(),
                    nodeRef.Value.ToString(),
                    infl.Factor.ToString()
                };
                switch (infl.EffectType)
                {
                case StructuralInfluenceEffectType.Force:
                    ls.Add("FORCE");
                    break;

                case StructuralInfluenceEffectType.Displacement:
                    ls.Add("DISP");
                    break;

                default:
                    return("");
                }
                ls.Add(axisIndex.ToString());
                ls.Add(direction[i]);
                gwaCommands.Add(string.Join("\t", ls));
            }
            return(string.Join("\n", gwaCommands));
        }
예제 #16
0
        public string SetGWACommand()
        {
            if (this.Value == null)
            {
                return("");
            }

            var loadTask = this.Value as StructuralLoadTask;

            var keyword = typeof(GSALoadTask).GetGSAKeyword();

            var taskIndex = Initialiser.Cache.ResolveIndex("TASK.1", loadTask.ApplicationId);
            var index     = Initialiser.Cache.ResolveIndex(typeof(GSALoadTask).GetGSAKeyword(), loadTask.ApplicationId);

            var gwaCommands = new List <string>();

            var ls = new List <string>
            {
                // Set TASK
                "SET",
                "TASK.1" + ":" + HelperClass.GenerateSID(loadTask),
                taskIndex.ToString(),
                "", // Name
                "0" // Stage
            };

            switch (loadTask.TaskType)
            {
            case StructuralLoadTaskType.LinearStatic:
                ls.Add("GSS");
                ls.Add("STATIC");
                // Defaults:
                ls.Add("1");
                ls.Add("0");
                ls.Add("128");
                ls.Add("SELF");
                ls.Add("none");
                ls.Add("none");
                ls.Add("DRCMEFNSQBHU*");
                ls.Add("MIN");
                ls.Add("AUTO");
                ls.Add("0");
                ls.Add("0");
                ls.Add("0");
                ls.Add("NONE");
                ls.Add("FATAL");
                ls.Add("NONE");
                ls.Add("NONE");
                ls.Add("RAFT_LO");
                ls.Add("RESID_NO");
                ls.Add("0");
                ls.Add("1");
                break;

            case StructuralLoadTaskType.NonlinearStatic:
                ls.Add("GSRELAX");
                ls.Add("BUCKLING_NL");
                // Defaults:
                ls.Add("SINGLE");
                ls.Add("0");
                ls.Add("BEAM_GEO_YES");
                ls.Add("SHELL_GEO_NO");
                ls.Add("0.1");
                ls.Add("0.0001");
                ls.Add("0.1");
                ls.Add("CYCLE");
                ls.Add("100000");
                ls.Add("REL");
                ls.Add("0.0010000000475");
                ls.Add("0.0010000000475");
                ls.Add("DISP_CTRL_YES");
                ls.Add("0");
                ls.Add("1");
                ls.Add("0.01");
                ls.Add("LOAD_CTRL_NO");
                ls.Add("1");
                ls.Add("");
                ls.Add("10");
                ls.Add("100");
                ls.Add("RESID_NOCONV");
                ls.Add("DAMP_VISCOUS");
                ls.Add("0");
                ls.Add("0");
                ls.Add("1");
                ls.Add("1");
                ls.Add("1");
                ls.Add("1");
                ls.Add("AUTO_MASS_YES");
                ls.Add("AUTO_DAMP_YES");
                ls.Add("FF_SAVE_ELEM_FORCE_YES");
                ls.Add("FF_SAVE_SPACER_FORCE_TO_ELEM");
                ls.Add("DRCEFNSQBHU*");
                break;

            case StructuralLoadTaskType.Modal:
                ls.Add("GSS");
                ls.Add("MODAL");
                // Defaults:
                ls.Add("1");
                ls.Add("1");
                ls.Add("128");
                ls.Add("SELF");
                ls.Add("none");
                ls.Add("none");
                ls.Add("DRCMEFNSQBHU*");
                ls.Add("MIN");
                ls.Add("AUTO");
                ls.Add("0");
                ls.Add("0");
                ls.Add("0");
                ls.Add("NONE");
                ls.Add("FATAL");
                ls.Add("NONE");
                ls.Add("NONE");
                ls.Add("RAFT_LO");
                ls.Add("RESID_NO");
                ls.Add("0");
                ls.Add("1");
                break;

            default:
                ls.Add("GSS");
                ls.Add("STATIC");
                // Defaults:
                ls.Add("1");
                ls.Add("0");
                ls.Add("128");
                ls.Add("SELF");
                ls.Add("none");
                ls.Add("none");
                ls.Add("DRCMEFNSQBHU*");
                ls.Add("MIN");
                ls.Add("AUTO");
                ls.Add("0");
                ls.Add("0");
                ls.Add("0");
                ls.Add("NONE");
                ls.Add("FATAL");
                ls.Add("NONE");
                ls.Add("NONE");
                ls.Add("RAFT_LO");
                ls.Add("RESID_NO");
                ls.Add("0");
                ls.Add("1");
                break;
            }
            gwaCommands.Add(string.Join("\t", ls));

            // Set ANAL
            ls.Clear();
            ls.Add("SET");
            ls.Add(keyword + ":" + HelperClass.GenerateSID(loadTask));
            ls.Add(index.ToString());
            ls.Add(loadTask.Name == null || loadTask.Name == "" ? " " : loadTask.Name);
            ls.Add(taskIndex.ToString());
            if (loadTask.TaskType == StructuralLoadTaskType.Modal)
            {
                ls.Add("M1");
            }
            else
            {
                var subLs = new List <string>();
                for (var i = 0; i < loadTask.LoadCaseRefs.Count(); i++)
                {
                    var loadCaseRef = Initialiser.Cache.LookupIndex(typeof(GSALoadCase).GetGSAKeyword(), loadTask.LoadCaseRefs[i]);

                    if (loadCaseRef.HasValue)
                    {
                        if (loadTask.LoadFactors.Count() > i)
                        {
                            subLs.Add(loadTask.LoadFactors[i].ToString() + "L" + loadCaseRef.Value.ToString());
                        }
                        else
                        {
                            subLs.Add("L" + loadCaseRef.Value.ToString());
                        }
                    }
                }
                ls.Add(string.Join(" + ", subLs));
                gwaCommands.Add(string.Join("\t", ls));
            }
            return(string.Join("\n", gwaCommands));
        }
예제 #17
0
        public void ParseGWACommand(List <GSANode> nodes)
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new StructuralNodalInfluenceEffect();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter = 1; // Skip identifier

            obj.Name           = pieces[counter++].Trim(new char[] { '"' });
            obj.GSAEffectGroup = Convert.ToInt32(pieces[counter++]);

            var targetNodeRef = pieces[counter++];

            GSANode targetNode;

            if (nodes != null)
            {
                targetNode = nodes.Where(n => targetNodeRef == n.GSAId.ToString()).FirstOrDefault();

                obj.NodeRef = targetNode.Value.ApplicationId;

                this.SubGWACommand.Add(targetNode.GWACommand);

                targetNode.ForceSend = true;
            }
            else
            {
                return;
            }

            obj.Factor = Convert.ToDouble(pieces[counter++]);
            var effectType = pieces[counter++];

            switch (effectType)
            {
            case "DISP":
                obj.EffectType = StructuralInfluenceEffectType.Displacement;
                break;

            case "FORCE":
                obj.EffectType = StructuralInfluenceEffectType.Force;
                break;

            default:
                return;
            }

            var axis = pieces[counter++];

            if (axis == "GLOBAL")
            {
                obj.Axis = HelperClass.Parse0DAxis(0, Initialiser.Interface, out var temp);
            }
            else if (axis == "LOCAL")
            {
                obj.Axis = targetNode.Value.Axis;
            }
            else
            {
                obj.Axis = HelperClass.Parse0DAxis(Convert.ToInt32(axis), Initialiser.Interface, out string rec, targetNode.Value.Value.ToArray());
                if (rec != null)
                {
                    this.SubGWACommand.Add(rec);
                }
            }

            var dir = pieces[counter++];

            obj.Directions = new StructuralVectorBoolSix(new bool[6]);
            switch (dir.ToLower())
            {
            case "x":
                obj.Directions.Value[0] = true;
                break;

            case "y":
                obj.Directions.Value[1] = true;
                break;

            case "z":
                obj.Directions.Value[2] = true;
                break;

            case "xx":
                obj.Directions.Value[3] = true;
                break;

            case "yy":
                obj.Directions.Value[4] = true;
                break;

            case "zz":
                obj.Directions.Value[5] = true;
                break;
            }

            this.Value = obj;
        }
        public static SpeckleObject ToSpeckle(this GSA2DElementResult dummyObject)
        {
            if (Initialiser.Settings.Element2DResults.Count() == 0)
            {
                return(new SpeckleNull());
            }

            if (Initialiser.Settings.EmbedResults && !Initialiser.GSASenderObjects.ContainsKey(typeof(GSA2DElement)))
            {
                return(new SpeckleNull());
            }

            if (Initialiser.Settings.EmbedResults)
            {
                var elements = Initialiser.GSASenderObjects[typeof(GSA2DElement)].Cast <GSA2DElement>().ToList();

                foreach (var kvp in Initialiser.Settings.Element2DResults)
                {
                    foreach (var loadCase in Initialiser.Settings.ResultCases)
                    {
                        if (!Initialiser.Interface.CaseExist(loadCase))
                        {
                            continue;
                        }

                        foreach (var element in elements)
                        {
                            var id = element.GSAId;

                            if (element.Value.Result == null)
                            {
                                element.Value.Result = new Dictionary <string, object>();
                            }

                            var resultExport = Initialiser.Interface.GetGSAResult(id, kvp.Value.Item1, kvp.Value.Item2, kvp.Value.Item3, loadCase, Initialiser.Settings.ResultInLocalAxis ? "local" : "global");

                            if (resultExport == null || resultExport.Count() == 0)
                            {
                                continue;
                            }

                            if (!element.Value.Result.ContainsKey(loadCase))
                            {
                                element.Value.Result[loadCase] = new Structural2DElementResult()
                                {
                                    Value = new Dictionary <string, object>()
                                }
                            }
                            ;

                            // Let's split the dictionary into xxx_face and xxx_vertex
                            var faceDictionary = resultExport.ToDictionary(
                                x => x.Key,
                                x => new List <double>()
                            {
                                (x.Value as List <double>).Last()
                            } as object);
                            var vertexDictionary = resultExport.ToDictionary(
                                x => x.Key,
                                x => (x.Value as List <double>).Take((x.Value as List <double>).Count - 1).ToList() as object);

                            (element.Value.Result[loadCase] as Structural2DElementResult).Value[kvp.Key + "_face"]   = faceDictionary;
                            (element.Value.Result[loadCase] as Structural2DElementResult).Value[kvp.Key + "_vertex"] = vertexDictionary;
                        }
                    }
                }
            }
            else
            {
                Initialiser.GSASenderObjects[typeof(GSA2DElementResult)] = new List <object>();

                var results = new List <GSA2DElementResult>();

                var keyword = HelperClass.GetGSAKeyword(typeof(GSA2DElement));
                var gwa     = Initialiser.Cache.GetGwa(keyword);

                foreach (var kvp in Initialiser.Settings.Element2DResults)
                {
                    foreach (var loadCase in Initialiser.Settings.ResultCases)
                    {
                        if (!Initialiser.Interface.CaseExist(loadCase))
                        {
                            continue;
                        }

                        for (var i = 0; i < gwa.Count(); i++)
                        {
                            var record = gwa[i];

                            var pPieces = record.ListSplit("\t");
                            if (pPieces[4].ParseElementNumNodes() != 3 && pPieces[4].ParseElementNumNodes() != 4)
                            {
                                continue;
                            }

                            if (!int.TryParse(pPieces[1], out var id))
                            {
                                //Could not extract index
                                continue;
                            }

                            var resultExport = Initialiser.Interface.GetGSAResult(id, kvp.Value.Item1, kvp.Value.Item2, kvp.Value.Item3, loadCase, Initialiser.Settings.ResultInLocalAxis ? "local" : "global");

                            if (resultExport == null)
                            {
                                continue;
                            }

                            // Let's split the dictionary into xxx_face and xxx_vertex
                            var faceDictionary = resultExport.ToDictionary(
                                x => x.Key,
                                x => new List <double>()
                            {
                                (x.Value as List <double>).Last()
                            } as object);
                            var vertexDictionary = resultExport.ToDictionary(
                                x => x.Key,
                                x => (x.Value as List <double>).Take((x.Value as List <double>).Count - 1).ToList() as object);

                            var existingRes = results.FirstOrDefault(x => x.Value.TargetRef == id.ToString());
                            if (existingRes == null)
                            {
                                var newRes = new Structural2DElementResult()
                                {
                                    Value     = new Dictionary <string, object>(),
                                    TargetRef = HelperClass.GetApplicationId(typeof(GSA2DElement).GetGSAKeyword(), id),
                                    IsGlobal  = !Initialiser.Settings.ResultInLocalAxis,
                                };
                                newRes.Value[kvp.Key + "_face"]   = faceDictionary;
                                newRes.Value[kvp.Key + "_vertex"] = vertexDictionary;

                                newRes.GenerateHash();

                                results.Add(new GSA2DElementResult()
                                {
                                    Value = newRes
                                });
                            }
                            else
                            {
                                existingRes.Value.Value[kvp.Key + "_face"]   = faceDictionary;
                                existingRes.Value.Value[kvp.Key + "_vertex"] = vertexDictionary;
                            }
                        }
                    }
                }

                Initialiser.GSASenderObjects[typeof(GSA2DElementResult)].AddRange(results);
            }

            return(new SpeckleObject());
        }
예제 #19
0
        public void ParseGWACommand()
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new Structural2DLoadPanel();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter = 1; // Skip identifier

            obj.Name          = pieces[counter++].Trim(new char[] { '"' });
            obj.ApplicationId = HelperClass.GetApplicationId(this.GetGSAKeyword(), this.GSAId);

            HelperClass.GetGridPlaneRef(Convert.ToInt32(pieces[counter++]), out int gridPlaneRefRet, out string gridSurfaceRec);
            HelperClass.GetGridPlaneData(gridPlaneRefRet, out int gridPlaneAxis, out double gridPlaneElevation, out string gridPlaneRec);

            this.SubGWACommand.Add(gridSurfaceRec);
            this.SubGWACommand.Add(gridPlaneRec);

            string gwaRec = null;
            var    axis   = HelperClass.Parse0DAxis(gridPlaneAxis, Initialiser.Interface, out gwaRec);

            if (gwaRec != null)
            {
                this.SubGWACommand.Add(gwaRec);
            }
            double elevation = gridPlaneElevation;

            var polylineDescription = "";

            switch (pieces[counter++])
            {
            case "PLANE":
                // TODO: Do not handle for now
                return;

            case "POLYREF":
                var    polylineRef = pieces[counter++];
                string newRec      = null;
                HelperClass.GetPolylineDesc(Convert.ToInt32(polylineRef), out polylineDescription, out newRec);
                this.SubGWACommand.Add(newRec);
                break;

            case "POLYGON":
                polylineDescription = pieces[counter++];
                break;
            }
            var polyVals = HelperClass.ParsePolylineDesc(polylineDescription);

            for (var i = 2; i < polyVals.Length; i += 3)
            {
                polyVals[i] = elevation;
            }

            obj.Value  = HelperClass.MapPointsLocal2Global(polyVals, axis).ToList();
            obj.Closed = true;

            var loadCaseIndex = Convert.ToInt32(pieces[counter++]);

            if (loadCaseIndex > 0)
            {
                obj.LoadCaseRef = HelperClass.GetApplicationId(typeof(GSALoadCase).GetGSAKeyword(), loadCaseIndex);
            }

            var            loadAxisId   = 0;
            var            loadAxisData = pieces[counter++];
            StructuralAxis loadAxis;

            if (loadAxisData == "LOCAL")
            {
                loadAxis = axis;
            }
            else
            {
                loadAxisId = loadAxisData == "GLOBAL" ? 0 : Convert.ToInt32(loadAxisData);
                loadAxis   = HelperClass.Parse0DAxis(loadAxisId, Initialiser.Interface, out gwaRec);
                if (gwaRec != null)
                {
                    this.SubGWACommand.Add(gwaRec);
                }
            }
            var projected = pieces[counter++] == "YES";
            var direction = pieces[counter++];
            var value     = Convert.ToDouble(pieces[counter++]);

            obj.Loading = new StructuralVectorThree(new double[3]);
            switch (direction.ToUpper())
            {
            case "X":
                obj.Loading.Value[0] = value;
                break;

            case "Y":
                obj.Loading.Value[1] = value;
                break;

            case "Z":
                obj.Loading.Value[2] = value;
                break;

            default:
                // TODO: Error case maybe?
                break;
            }
            obj.Loading.TransformOntoAxis(loadAxis);

            if (projected)
            {
                var scale = (obj.Loading.Value[0] * axis.Normal.Value[0] +
                             obj.Loading.Value[1] * axis.Normal.Value[1] +
                             obj.Loading.Value[2] * axis.Normal.Value[2]) /
                            (axis.Normal.Value[0] * axis.Normal.Value[0] +
                             axis.Normal.Value[1] * axis.Normal.Value[1] +
                             axis.Normal.Value[2] * axis.Normal.Value[2]);

                obj.Loading = new StructuralVectorThree(axis.Normal.Value[0], axis.Normal.Value[1], axis.Normal.Value[2]);
                obj.Loading.Scale(scale);
            }

            this.Value = obj;
        }
        public string SetGWACommand(int group = 0)
        {
            if (this.Value == null)
            {
                return("");
            }

            var element = this.Value as Structural1DElement;

            var keyword = typeof(GSA1DElement).GetGSAKeyword();

            var index   = Initialiser.Cache.ResolveIndex(typeof(GSA1DElement).GetGSAKeyword(), element.ApplicationId);
            var propRef = 0;

            try
            {
                propRef = Initialiser.Cache.LookupIndex(typeof(GSA1DProperty).GetGSAKeyword(), element.PropertyRef).Value;
            }
            catch { }

            var ls = new List <string>
            {
                "SET",
                keyword + ":" + HelperClass.GenerateSID(element),
                index.ToString(),
                element.Name == null || element.Name == "" ? " " : element.Name,
                "NO_RGB",
                "BEAM", // Type
                propRef.ToString(),
                group.ToString()
            };

            for (var i = 0; i < element.Value.Count(); i += 3)
            {
                ls.Add(HelperClass.NodeAt(element.Value[i], element.Value[i + 1], element.Value[i + 2], Initialiser.Settings.CoincidentNodeAllowance).ToString());
            }
            ls.Add("0"); // Orientation Node
            try
            {
                ls.Add(HelperClass.Get1DAngle(element.Value.ToArray(), element.ZAxis).ToString());
            }
            catch { ls.Add("0"); }
            try
            {
                var subLs = new List <string>();
                if (element.EndRelease[0].Value.Any(x => x) || element.EndRelease[1].Value.Any(x => x))
                {
                    subLs.Add("RLS");

                    var end1 = "";

                    end1 += element.EndRelease[0].Value[0] ? "R" : "F";
                    end1 += element.EndRelease[0].Value[1] ? "R" : "F";
                    end1 += element.EndRelease[0].Value[2] ? "R" : "F";
                    end1 += element.EndRelease[0].Value[3] ? "R" : "F";
                    end1 += element.EndRelease[0].Value[4] ? "R" : "F";
                    end1 += element.EndRelease[0].Value[5] ? "R" : "F";

                    subLs.Add(end1);

                    var end2 = "";

                    end2 += element.EndRelease[1].Value[0] ? "R" : "F";
                    end2 += element.EndRelease[1].Value[1] ? "R" : "F";
                    end2 += element.EndRelease[1].Value[2] ? "R" : "F";
                    end2 += element.EndRelease[1].Value[3] ? "R" : "F";
                    end2 += element.EndRelease[1].Value[4] ? "R" : "F";
                    end2 += element.EndRelease[1].Value[5] ? "R" : "F";

                    subLs.Add(end2);

                    ls.AddRange(subLs);
                }
                else
                {
                    ls.Add("NO_RLS");
                }
            }
            catch { ls.Add("NO_RLS"); }

            try
            {
                var subLs = new List <string>
                {
                    element.Offset[0].Value[0].ToString(), // Offset x-start
                    element.Offset[1].Value[0].ToString(), // Offset x-end

                    element.Offset[0].Value[1].ToString(),
                    element.Offset[0].Value[2].ToString()
                };

                ls.AddRange(subLs);
            }
            catch
            {
                ls.Add("0");
                ls.Add("0");
                ls.Add("0");
                ls.Add("0");
            }

            //ls.Add("NORMAL"); // Action // TODO: EL.4 SUPPORT
            ls.Add((element.GSADummy.HasValue && element.GSADummy.Value) ? "DUMMY" : "");

            return(string.Join("\t", ls));
        }
        public static SpeckleObject ToSpeckle(this GSA1DLoad dummyObject)
        {
            var newLines = ToSpeckleBase <GSA1DLoad>();

            var loads    = new List <GSA1DLoad>();
            var elements = Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis ? Initialiser.GSASenderObjects[typeof(GSA1DElement)].Cast <GSA1DElement>().ToList() : new List <GSA1DElement>();
            var members  = Initialiser.Settings.TargetLayer == GSATargetLayer.Design ? Initialiser.GSASenderObjects[typeof(GSA1DMember)].Cast <GSA1DMember>().ToList() : new List <GSA1DMember>();

            foreach (var p in newLines.Values)
            {
                var loadSubList = new List <GSA1DLoad>();

                // Placeholder load object to get list of elements and load values
                // Need to transform to axis so one load definition may be transformed to many
                var initLoad = new GSA1DLoad()
                {
                    GWACommand = p
                };
                initLoad.ParseGWACommand(elements, members);

                if (Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis)
                {
                    // Create load for each element applied
                    foreach (string nRef in initLoad.Value.ElementRefs)
                    {
                        var load = new GSA1DLoad
                        {
                            GWACommand    = initLoad.GWACommand,
                            SubGWACommand = new List <string>(initLoad.SubGWACommand)
                        };
                        load.Value.Name        = initLoad.Value.Name;
                        load.Value.LoadCaseRef = initLoad.Value.LoadCaseRef;

                        // Transform load to defined axis
                        var            elem     = elements.Where(e => e.Value.ApplicationId == nRef).First();
                        StructuralAxis loadAxis = load.Axis == 0 ? new StructuralAxis(
                            new StructuralVectorThree(new double[] { 1, 0, 0 }),
                            new StructuralVectorThree(new double[] { 0, 1, 0 }),
                            new StructuralVectorThree(new double[] { 0, 0, 1 })) :
                                                  HelperClass.LocalAxisEntity1D(elem.Value.Value.ToArray(), elem.Value.ZAxis); // Assumes if not global, local
                        load.Value.Loading = initLoad.Value.Loading;
                        load.Value.Loading.TransformOntoAxis(loadAxis);

                        // Perform projection
                        if (load.Projected)
                        {
                            var loadDirection = new Vector3D(
                                load.Value.Loading.Value[0],
                                load.Value.Loading.Value[1],
                                load.Value.Loading.Value[2]);

                            if (loadDirection.Length > 0)
                            {
                                var axisX  = new Vector3D(elem.Value[5] - elem.Value[0], elem.Value[4] - elem.Value[1], elem.Value[3] - elem.Value[2]);
                                var angle  = Vector3D.AngleBetween(loadDirection, axisX);
                                var factor = Math.Sin(angle);
                                load.Value.Loading.Value[0] *= factor;
                                load.Value.Loading.Value[1] *= factor;
                                load.Value.Loading.Value[2] *= factor;
                            }
                        }

                        // If the loading already exists, add element ref to list
                        var match = loadSubList.Count() > 0 ? loadSubList.Where(l => (l.Value.Loading.Value as List <double>).SequenceEqual(load.Value.Loading.Value as List <double>)).First() : null;
                        if (match != null)
                        {
                            match.Value.ElementRefs.Add(nRef);
                        }
                        else
                        {
                            load.Value.ElementRefs = new List <string>()
                            {
                                nRef
                            };
                            loadSubList.Add(load);
                        }
                    }
                }
                else if (Initialiser.Settings.TargetLayer == GSATargetLayer.Design)
                {
                    // Create load for each element applied
                    foreach (string nRef in initLoad.Value.ElementRefs)
                    {
                        var load = new GSA1DLoad
                        {
                            GWACommand    = initLoad.GWACommand,
                            SubGWACommand = new List <string>(initLoad.SubGWACommand)
                        };
                        load.Value.Name        = initLoad.Value.Name;
                        load.Value.LoadCaseRef = initLoad.Value.LoadCaseRef;

                        // Transform load to defined axis
                        var            memb     = members.Where(e => e.Value.ApplicationId == nRef).First();
                        StructuralAxis loadAxis = load.Axis == 0 ? new StructuralAxis(
                            new StructuralVectorThree(new double[] { 1, 0, 0 }),
                            new StructuralVectorThree(new double[] { 0, 1, 0 }),
                            new StructuralVectorThree(new double[] { 0, 0, 1 })) :
                                                  HelperClass.LocalAxisEntity1D(memb.Value.Value.ToArray(), memb.Value.ZAxis); // Assumes if not global, local
                        load.Value.Loading = initLoad.Value.Loading;
                        load.Value.Loading.TransformOntoAxis(loadAxis);

                        // Perform projection
                        if (load.Projected)
                        {
                            var loadDirection = new Vector3D(
                                load.Value.Loading.Value[0],
                                load.Value.Loading.Value[1],
                                load.Value.Loading.Value[2]);

                            if (loadDirection.Length > 0)
                            {
                                var axisX  = new Vector3D(memb.Value[5] - memb.Value[0], memb.Value[4] - memb.Value[1], memb.Value[3] - memb.Value[2]);
                                var angle  = Vector3D.AngleBetween(loadDirection, axisX);
                                var factor = Math.Sin(angle);
                                load.Value.Loading.Value[0] *= factor;
                                load.Value.Loading.Value[1] *= factor;
                                load.Value.Loading.Value[2] *= factor;
                            }
                        }

                        // If the loading already exists, add element ref to list
                        var match = loadSubList.Count() > 0 ? loadSubList.Where(l => l.Value.Loading.Equals(load.Value.Loading)).First() : null;
                        if (match != null)
                        {
                            match.Value.ElementRefs.Add(nRef);
                        }
                        else
                        {
                            load.Value.ElementRefs = new List <string>()
                            {
                                nRef
                            };
                            loadSubList.Add(load);
                        }
                    }
                }

                loads.AddRange(loadSubList);
            }

            Initialiser.GSASenderObjects[typeof(GSA1DLoad)].AddRange(loads);

            return((loads.Count() > 0) ? new SpeckleObject() : new SpeckleNull());
        }
        public void ParseGWACommand(List <GSANode> nodes)
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new Structural1DElement();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter = 1; // Skip identifier

            this.GSAId        = Convert.ToInt32(pieces[counter++]);
            obj.ApplicationId = HelperClass.GetApplicationId(this.GetGSAKeyword(), this.GSAId);
            obj.Name          = pieces[counter++].Trim(new char[] { '"' });
            counter++; // Color

            var type = pieces[counter++];

            if (type == "BEAM")
            {
                obj.ElementType = Structural1DElementType.Beam;
            }
            else if (type == "COLUMN")
            {
                obj.ElementType = Structural1DElementType.Column;
            }
            else if (type == "CANTILEVER")
            {
                obj.ElementType = Structural1DElementType.Cantilever;
            }
            else
            {
                obj.ElementType = Structural1DElementType.Generic;
            }

            obj.PropertyRef = HelperClass.GetApplicationId(typeof(GSA1DProperty).GetGSAKeyword(), Convert.ToInt32(pieces[counter++]));
            this.Group      = Convert.ToInt32(pieces[counter++]); // Keep group for load targetting

            obj.Value = new List <double>();
            var nodeRefs = pieces[counter++].ListSplit(" ");

            for (var i = 0; i < nodeRefs.Length; i++)
            {
                var node = nodes.Where(n => n.GSAId == Convert.ToInt32(nodeRefs[i])).FirstOrDefault();
                obj.Value.AddRange(node.Value.Value);
                this.SubGWACommand.Add(node.GWACommand);
            }

            var orientationNodeRef = pieces[counter++];
            var rotationAngle      = Convert.ToDouble(pieces[counter++]);

            if (orientationNodeRef != "0")
            {
                var node = nodes.Where(n => n.GSAId == Convert.ToInt32(orientationNodeRef)).FirstOrDefault();
                obj.ZAxis = HelperClass.Parse1DAxis(obj.Value.ToArray(),
                                                    rotationAngle, node.Value.ToArray()).Normal as StructuralVectorThree;
                this.SubGWACommand.Add(node.GWACommand);
            }
            else
            {
                obj.ZAxis = HelperClass.Parse1DAxis(obj.Value.ToArray(), rotationAngle).Normal as StructuralVectorThree;
            }

            counter += 9; //Skip to end conditions

            obj.EndRelease = new List <StructuralVectorBoolSix>
            {
                ParseEndReleases(Convert.ToInt32(pieces[counter++])),
                ParseEndReleases(Convert.ToInt32(pieces[counter++]))
            };

            // Skip to offsets at fifth to last
            counter    = pieces.Length - 5;
            obj.Offset = new List <StructuralVectorThree>
            {
                new StructuralVectorThree(new double[3]),
                new StructuralVectorThree(new double[3])
            };

            obj.Offset[0].Value[0] = Convert.ToDouble(pieces[counter++]);
            obj.Offset[1].Value[0] = Convert.ToDouble(pieces[counter++]);

            obj.Offset[0].Value[1] = Convert.ToDouble(pieces[counter++]);
            obj.Offset[1].Value[1] = obj.Offset[0].Value[1];

            obj.Offset[0].Value[2] = Convert.ToDouble(pieces[counter++]);
            obj.Offset[1].Value[2] = obj.Offset[0].Value[2];

            this.Value = obj;
        }
        public void ParseGWACommand()
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new StructuralLoadCombo();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter = 1; // Skip identifier

            this.GSAId        = Convert.ToInt32(pieces[counter++]);
            obj.ApplicationId = HelperClass.GetApplicationId(this.GetGSAKeyword(), this.GSAId);
            obj.Name          = pieces[counter++];

            // Parse type
            var description = pieces[counter++];

            if (description.Contains("+"))
            {
                obj.ComboType = StructuralLoadComboType.LinearAdd;
            }
            else if (description.Contains("or"))
            {
                obj.ComboType = StructuralLoadComboType.Envelope;
            }
            else
            {
                obj.ComboType = StructuralLoadComboType.LinearAdd;
            }

            obj.LoadTaskRefs     = new List <string>();
            obj.LoadTaskFactors  = new List <double>();
            obj.LoadComboRefs    = new List <string>();
            obj.LoadComboFactors = new List <double>();

            // TODO: this only parses the super simple linear add descriptions
            try
            {
                var desc = HelperClass.ParseLoadDescription(description);

                foreach (var t in desc)
                {
                    switch (t.Item1[0])
                    {
                    case 'A':
                        obj.LoadTaskRefs.Add(HelperClass.GetApplicationId(typeof(GSALoadTask).GetGSAKeyword(), Convert.ToInt32(t.Item1.Substring(1))));
                        obj.LoadTaskFactors.Add(t.Item2);
                        break;

                    case 'C':
                        obj.LoadComboRefs.Add(HelperClass.GetApplicationId(typeof(GSALoadCombo).GetGSAKeyword(), Convert.ToInt32(t.Item1.Substring(1))));
                        obj.LoadComboFactors.Add(t.Item2);
                        break;
                    }
                }
            }
            catch
            {
            }

            this.Value = obj;
        }
        public void ParseGWACommand(List <GSANode> nodes)
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new Structural1DElement();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter = 1; // Skip identifier

            this.GSAId        = Convert.ToInt32(pieces[counter++]);
            obj.ApplicationId = HelperClass.GetApplicationId(this.GetGSAKeyword(), this.GSAId);

            obj.Name = pieces[counter++].Trim(new char[] { '"' });
            counter++; // Colour
            counter++; // Type
            obj.PropertyRef = HelperClass.GetApplicationId(typeof(GSA1DProperty).GetGSAKeyword(), Convert.ToInt32(pieces[counter++]));
            counter++; // Group

            obj.Value = new List <double>();
            for (var i = 0; i < 2; i++)
            {
                var key  = pieces[counter++];
                var node = nodes.Where(n => n.GSAId == Convert.ToInt32(key)).FirstOrDefault();
                obj.Value.AddRange(node.Value.Value);
                this.SubGWACommand.Add(node.GWACommand);
            }

            var orientationNodeRef = pieces[counter++];
            var rotationAngle      = Convert.ToDouble(pieces[counter++]);

            if (orientationNodeRef != "0")
            {
                var node = nodes.Where(n => n.GSAId == Convert.ToInt32(orientationNodeRef)).FirstOrDefault();
                obj.ZAxis = HelperClass.Parse1DAxis(obj.Value.ToArray(),
                                                    rotationAngle, node.Value.Value.ToArray()).Normal as StructuralVectorThree;
                this.SubGWACommand.Add(node.GWACommand);
            }
            else
            {
                obj.ZAxis = HelperClass.Parse1DAxis(obj.Value.ToArray(), rotationAngle).Normal as StructuralVectorThree;
            }


            if (pieces[counter++] != "NO_RLS")
            {
                var start = pieces[counter++];
                var end   = pieces[counter++];

                obj.EndRelease = new List <StructuralVectorBoolSix>
                {
                    new StructuralVectorBoolSix(new bool[6]),
                    new StructuralVectorBoolSix(new bool[6])
                };

                obj.EndRelease[0].Value[0] = ParseEndRelease(start[0], pieces, ref counter);
                obj.EndRelease[0].Value[1] = ParseEndRelease(start[1], pieces, ref counter);
                obj.EndRelease[0].Value[2] = ParseEndRelease(start[2], pieces, ref counter);
                obj.EndRelease[0].Value[3] = ParseEndRelease(start[3], pieces, ref counter);
                obj.EndRelease[0].Value[4] = ParseEndRelease(start[4], pieces, ref counter);
                obj.EndRelease[0].Value[5] = ParseEndRelease(start[5], pieces, ref counter);

                obj.EndRelease[1].Value[0] = ParseEndRelease(end[0], pieces, ref counter);
                obj.EndRelease[1].Value[1] = ParseEndRelease(end[1], pieces, ref counter);
                obj.EndRelease[1].Value[2] = ParseEndRelease(end[2], pieces, ref counter);
                obj.EndRelease[1].Value[3] = ParseEndRelease(end[3], pieces, ref counter);
                obj.EndRelease[1].Value[4] = ParseEndRelease(end[4], pieces, ref counter);
                obj.EndRelease[1].Value[5] = ParseEndRelease(end[5], pieces, ref counter);
            }
            else
            {
                obj.EndRelease = new List <StructuralVectorBoolSix>
                {
                    new StructuralVectorBoolSix(new bool[] { true, true, true, true, true, true }),
                    new StructuralVectorBoolSix(new bool[] { true, true, true, true, true, true })
                };
            }

            obj.Offset = new List <StructuralVectorThree>
            {
                new StructuralVectorThree(new double[3]),
                new StructuralVectorThree(new double[3])
            };

            obj.Offset[0].Value[0] = Convert.ToDouble(pieces[counter++]);
            obj.Offset[1].Value[0] = Convert.ToDouble(pieces[counter++]);

            obj.Offset[0].Value[1] = Convert.ToDouble(pieces[counter++]);
            obj.Offset[1].Value[1] = obj.Offset[0].Value[1];

            obj.Offset[0].Value[2] = Convert.ToDouble(pieces[counter++]);
            obj.Offset[1].Value[2] = obj.Offset[0].Value[2];

            //counter++; // Action // TODO: EL.4 SUPPORT
            counter++; // Dummy

            if (counter < pieces.Length)
            {
                Member = pieces[counter++];
            }

            this.Value = obj;
        }
예제 #25
0
        public static SpeckleObject ToSpeckle(this GSA0DLoad dummyObject)
        {
            var newLines = ToSpeckleBase <GSA0DLoad>();

            var loads = new List <GSA0DLoad>();

            var nodes = Initialiser.GSASenderObjects[typeof(GSANode)].Cast <GSANode>().ToList();


            foreach (var p in newLines.Values)
            {
                var loadSubList = new List <GSA0DLoad>();

                // Placeholder load object to get list of nodes and load values
                // Need to transform to axis so one load definition may be transformed to many
                var initLoad = new GSA0DLoad()
                {
                    GWACommand = p
                };
                initLoad.ParseGWACommand(nodes);

                // Raise node flag to make sure it gets sent
                foreach (var n in nodes.Where(n => initLoad.Value.NodeRefs.Contains(n.Value.ApplicationId)))
                {
                    n.ForceSend = true;
                }

                // Create load for each node applied
                foreach (string nRef in initLoad.Value.NodeRefs)
                {
                    var load = new GSA0DLoad
                    {
                        GWACommand    = initLoad.GWACommand,
                        SubGWACommand = new List <string>(initLoad.SubGWACommand)
                    };
                    load.Value.Name        = initLoad.Value.Name;
                    load.Value.LoadCaseRef = initLoad.Value.LoadCaseRef;

                    // Transform load to defined axis
                    var            node      = nodes.Where(n => (n.Value.ApplicationId == nRef)).First();
                    string         gwaRecord = null;
                    StructuralAxis loadAxis  = HelperClass.Parse0DAxis(initLoad.Axis, Initialiser.Interface, out gwaRecord, node.Value.Value.ToArray());
                    load.Value.Loading = initLoad.Value.Loading;
                    load.Value.Loading.TransformOntoAxis(loadAxis);

                    // If the loading already exists, add node ref to list
                    var match = loadSubList.Count() > 0 ? loadSubList.Where(l => (l.Value.Loading.Value as List <double>).SequenceEqual(load.Value.Loading.Value as List <double>)).First() : null;
                    if (match != null)
                    {
                        match.Value.NodeRefs.Add(nRef);
                        if (gwaRecord != null)
                        {
                            match.SubGWACommand.Add(gwaRecord);
                        }
                    }
                    else
                    {
                        load.Value.NodeRefs = new List <string>()
                        {
                            nRef
                        };
                        if (gwaRecord != null)
                        {
                            load.SubGWACommand.Add(gwaRecord);
                        }
                        loadSubList.Add(load);
                    }
                }

                loads.AddRange(loadSubList);
            }

            Initialiser.GSASenderObjects[typeof(GSA0DLoad)].AddRange(loads);

            return((loads.Count() > 0) ? new SpeckleObject() : new SpeckleNull());
        }
        public string SetGWACommand(int group = 0)
        {
            if (this.Value == null)
            {
                return("");
            }

            var member = this.Value as Structural1DElement;

            var keyword = typeof(GSA1DMember).GetGSAKeyword();

            var index   = Initialiser.Cache.ResolveIndex(typeof(GSA1DMember).GetGSAKeyword(), member.ApplicationId);
            var propRef = 0;

            try
            {
                propRef = (member.ElementType == Structural1DElementType.Spring)
          ? Initialiser.Cache.LookupIndex(typeof(GSASpringProperty).GetGSAKeyword(), member.PropertyRef).Value
          : Initialiser.Cache.LookupIndex(typeof(GSA1DProperty).GetGSAKeyword(), member.PropertyRef).Value;
            }
            catch { }

            var ls = new List <string>
            {
                "SET",
                keyword + ":" + HelperClass.GenerateSID(member),
                index.ToString(),
                member.Name == null || member.Name == "" ? " " : member.Name,
                "NO_RGB"
            };

            if (member.ElementType == Structural1DElementType.Beam)
            {
                ls.Add("BEAM");
            }
            else if (member.ElementType == Structural1DElementType.Column)
            {
                ls.Add("COLUMN");
            }
            else if (member.ElementType == Structural1DElementType.Cantilever)
            {
                ls.Add("CANTILEVER");
            }
            else
            {
                ls.Add("1D_GENERIC");
            }
            ls.Add(propRef.ToString());
            ls.Add(group != 0 ? group.ToString() : index.ToString()); // TODO: This allows for targeting of elements from members group
            var topo = "";

            for (var i = 0; i < member.Value.Count(); i += 3)
            {
                topo += HelperClass.NodeAt(member.Value[i], member.Value[i + 1], member.Value[i + 2], Initialiser.Settings.CoincidentNodeAllowance).ToString() + " ";
            }
            ls.Add(topo);
            ls.Add("0"); // Orientation node
            try
            {
                ls.Add(HelperClass.Get1DAngle(member.Value.ToArray(), member.ZAxis).ToString());
            }
            catch { ls.Add("0"); }
            //ls.Add(member.GSAMeshSize == 0 ? "0" : member.GSAMeshSize.ToString()); // Target mesh size
            ls.Add(member.GSAMeshSize == null ? "0" : member.GSAMeshSize.ToString());           // Target mesh size
            ls.Add("MESH");                                                                     // TODO: What is this?
            ls.Add((member.ElementType == Structural1DElementType.Spring) ? "SPRING" : "BEAM"); // Element type
            ls.Add("0");                                                                        // Fire
            ls.Add("0");                                                                        // Time 1
            ls.Add("0");                                                                        // Time 2
            ls.Add("0");                                                                        // Time 3
            ls.Add("0");                                                                        // Time 4
            ls.Add((member.GSADummy.HasValue && member.GSADummy.Value) ? "DUMMY" : "ACTIVE");

            try
            {
                if (member.EndRelease[0].Value.SequenceEqual(ParseEndReleases(1).Value))
                {
                    ls.Add("1");
                }
                else if (member.EndRelease[0].Value.SequenceEqual(ParseEndReleases(2).Value))
                {
                    ls.Add("2");
                }
                else if (member.EndRelease[0].Value.SequenceEqual(ParseEndReleases(3).Value))
                {
                    ls.Add("3");
                }
                else
                {
                    if (member.EndRelease[0].Value.Skip(3).Take(3).SequenceEqual(new bool[] { false, false, false }))
                    {
                        ls.Add("2");
                    }
                    else
                    {
                        ls.Add("1");
                    }
                }
            }
            catch { ls.Add("2"); }

            try
            {
                if (member.EndRelease[1].Value.SequenceEqual(ParseEndReleases(1).Value))
                {
                    ls.Add("1");
                }
                else if (member.EndRelease[1].Value.SequenceEqual(ParseEndReleases(2).Value))
                {
                    ls.Add("2");
                }
                else if (member.EndRelease[1].Value.SequenceEqual(ParseEndReleases(3).Value))
                {
                    ls.Add("3");
                }
                else
                {
                    if (member.EndRelease[1].Value.Skip(3).Take(3).SequenceEqual(new bool[] { false, false, false }))
                    {
                        ls.Add("2");
                    }
                    else
                    {
                        ls.Add("1");
                    }
                }
            }
            catch { ls.Add("2"); }

            ls.Add("AUTOMATIC"); // Effective length option
            ls.Add("0");         // Pool
            ls.Add("0");         // Height
            ls.Add("MAN");       // Auto offset 1
            ls.Add("MAN");       // Auto offset 2
            ls.Add("NO");        // Internal auto offset

            try
            {
                var subLs = new List <string>
                {
                    member.Offset[0].Value[0].ToString(), // Offset x-start
                    member.Offset[1].Value[0].ToString(), // Offset x-end

                    member.Offset[0].Value[1].ToString(),
                    member.Offset[0].Value[2].ToString()
                };

                ls.AddRange(subLs);
            }
            catch
            {
                ls.Add("0");
                ls.Add("0");
                ls.Add("0");
                ls.Add("0");
            }
            ls.Add("ALL"); // Exposure

            return(string.Join("\t", ls));
        }
        public static SpeckleObject ToSpeckle(this GSA1DElementResult dummyObject)
        {
            if (Initialiser.Settings.Element1DResults.Count() == 0)
            {
                return(new SpeckleNull());
            }

            if (Initialiser.Settings.EmbedResults && !Initialiser.GSASenderObjects.ContainsKey(typeof(GSA1DElement)))
            {
                return(new SpeckleNull());
            }

            if (Initialiser.Settings.EmbedResults)
            {
                var elements = Initialiser.GSASenderObjects[typeof(GSA1DElement)].Cast <GSA1DElement>().ToList();

                var entities = elements.Cast <IGSASpeckleContainer>().ToList();

                foreach (var kvp in Initialiser.Settings.Element1DResults)
                {
                    foreach (var loadCase in Initialiser.Settings.ResultCases)
                    {
                        if (!Initialiser.Interface.CaseExist(loadCase))
                        {
                            continue;
                        }

                        foreach (var entity in entities)
                        {
                            var id = entity.GSAId;

                            if (entity.Value.Result == null)
                            {
                                entity.Value.Result = new Dictionary <string, object>();
                            }

                            var resultExport = Initialiser.Interface.GetGSAResult(id, kvp.Value.Item1, kvp.Value.Item2, kvp.Value.Item3, loadCase, Initialiser.Settings.ResultInLocalAxis
                ? "local" : "global", Initialiser.Settings.Result1DNumPosition);

                            if (resultExport == null)
                            {
                                continue;
                            }

                            if (!entity.Value.Result.ContainsKey(loadCase))
                            {
                                entity.Value.Result[loadCase] = new Structural1DElementResult()
                                {
                                    Value = new Dictionary <string, object>()
                                }
                            }
                            ;

                            (entity.Value.Result[loadCase] as Structural1DElementResult).Value[kvp.Key] = resultExport;
                        }
                    }
                }

                // Linear interpolate the line values
                foreach (var entity in entities)
                {
                    var dX = (entity.Value.Value[3] - entity.Value.Value[0]) / (Initialiser.Settings.Result1DNumPosition + 1);
                    var dY = (entity.Value.Value[4] - entity.Value.Value[1]) / (Initialiser.Settings.Result1DNumPosition + 1);
                    var dZ = (entity.Value.Value[5] - entity.Value.Value[2]) / (Initialiser.Settings.Result1DNumPosition + 1);

                    var interpolatedVertices = new List <double>();
                    interpolatedVertices.AddRange((entity.Value.Value as List <double>).Take(3));

                    for (var i = 1; i <= Initialiser.Settings.Result1DNumPosition; i++)
                    {
                        interpolatedVertices.Add(interpolatedVertices[0] + dX * i);
                        interpolatedVertices.Add(interpolatedVertices[1] + dY * i);
                        interpolatedVertices.Add(interpolatedVertices[2] + dZ * i);
                    }

                    interpolatedVertices.AddRange((entity.Value.Value as List <double>).Skip(3).Take(3));

                    entity.Value.ResultVertices = interpolatedVertices;
                }
            }
            else
            {
                Initialiser.GSASenderObjects[typeof(GSA1DElementResult)] = new List <object>();

                var results = new List <GSA1DElementResult>();

                var keyword = HelperClass.GetGSAKeyword(typeof(GSA1DElement));
                var gwa     = Initialiser.Cache.GetGwa(keyword);

                foreach (var kvp in Initialiser.Settings.Element1DResults)
                {
                    foreach (var loadCase in Initialiser.Settings.ResultCases)
                    {
                        if (!Initialiser.Interface.CaseExist(loadCase))
                        {
                            continue;
                        }

                        for (var i = 0; i < gwa.Count(); i++)
                        {
                            var record = gwa[i];

                            var pPieces = record.ListSplit("\t");
                            if (pPieces[4].ParseElementNumNodes() != 2)
                            {
                                continue;
                            }

                            if (!int.TryParse(pPieces[1], out var id))
                            {
                                //Could not extract index
                                continue;
                            }

                            var resultExport = Initialiser.Interface.GetGSAResult(id, kvp.Value.Item1, kvp.Value.Item2, kvp.Value.Item3, loadCase, Initialiser.Settings.ResultInLocalAxis ? "local" : "global", Initialiser.Settings.Result1DNumPosition);

                            if (resultExport == null || resultExport.Count() == 0)
                            {
                                continue;
                            }

                            var existingRes = results.FirstOrDefault(x => x.Value.TargetRef == id.ToString());
                            if (existingRes == null)
                            {
                                var newRes = new Structural1DElementResult()
                                {
                                    Value     = new Dictionary <string, object>(),
                                    TargetRef = HelperClass.GetApplicationId(typeof(GSA1DElement).GetGSAKeyword(), id),
                                    IsGlobal  = !Initialiser.Settings.ResultInLocalAxis,
                                };
                                newRes.Value[kvp.Key] = resultExport;

                                newRes.GenerateHash();

                                results.Add(new GSA1DElementResult()
                                {
                                    Value = newRes
                                });
                            }
                            else
                            {
                                existingRes.Value.Value[kvp.Key] = resultExport;
                            }
                        }
                    }
                }

                Initialiser.GSASenderObjects[typeof(GSA1DElementResult)].AddRange(results);
            }

            return(new SpeckleObject());
        }
    public void ParseGWACommand(List<GSA1DElement> elements)
    {
      if (elements.Count() < 1)
        return;

      var elementsListCopy = new List<GSA1DElement>(elements);

      var obj = new Structural1DElementPolyline
      {
        ApplicationId = HelperClass.GetApplicationId(typeof(GSA1DElementPolyline).GetGSAKeyword(), GSAId),

        Value = new List<double>(),
        ElementApplicationId = new List<string>(),

        ElementType = elementsListCopy.First().Value.ElementType,
        PropertyRef = elementsListCopy.First().Value.PropertyRef,
        ZAxis = new List<StructuralVectorThree>(),
        EndRelease = new List<StructuralVectorBoolSix>(),
        Offset = new List<StructuralVectorThree>(),
        ResultVertices = new List<double>()
      };

      if (Initialiser.Settings.Element1DResults.Count > 0 && Initialiser.Settings.EmbedResults)
        obj.Result = new Dictionary<string, object>();

      // Match up coordinates
      var coordinates = new List<Tuple<string, string>>();

      foreach (var e in elementsListCopy)
        coordinates.Add( new Tuple<string, string>(
          string.Join(",", (e.Value.Value as List<double>).Take(3).Select(x => Math.Round(x, 4).ToString())),
          string.Join(",", (e.Value.Value as List<double>).Skip(3).Take(3).Select(x => Math.Round(x, 4).ToString()))
        ));

      // Find start coordinate
      var flatCoordinates = coordinates.SelectMany(x => new List<string>() { x.Item1, x.Item2 }).ToList();
      var uniqueCoordinates = flatCoordinates.Where(x => flatCoordinates.Count(y => y == x) == 1).ToList();

      var current = uniqueCoordinates[0];
      while(coordinates.Count > 0)
      {
        var matchIndex = 0;
        var reverseCoordinates = false;
        
        matchIndex = coordinates.FindIndex(x => x.Item1 == current);
        reverseCoordinates = false;
        if (matchIndex == -1)
        { 
          matchIndex = coordinates.FindIndex(x => x.Item2 == current);
          reverseCoordinates = true;
        }

        var element = elementsListCopy[matchIndex];

        obj.ElementApplicationId.Add(element.Value.ApplicationId);
        obj.ZAxis.Add(element.Value.ZAxis);

        if (obj.Value.Count == 0)
        {
          if (!reverseCoordinates)
          { 
            obj.Value.AddRange((element.Value.Value as List<double>).Take(3));
          }
          else
          { 
            obj.Value.AddRange((element.Value.Value as List<double>).Skip(3).Take(3));
          }
        }

        if (!reverseCoordinates)
        {
          current = string.Join(",", (element.Value.Value as List<double>).Skip(3).Take(3).Select(x => Math.Round(x, 4).ToString()));
          obj.Value.AddRange((element.Value.Value as List<double>).Skip(3).Take(3));
          obj.EndRelease.AddRange(element.Value.EndRelease);
          obj.Offset.AddRange(element.Value.Offset);

          if (Initialiser.Settings.Element1DResults.Count > 0 && Initialiser.Settings.EmbedResults)
            obj.ResultVertices.AddRange(element.Value.ResultVertices);
          else
            obj.ResultVertices.AddRange((element.Value.Value as List<double>));
        }
        else
        {
          current = string.Join(",", (element.Value.Value as List<double>).Take(3).Select(x => Math.Round(x, 4).ToString()));
          obj.Value.AddRange((element.Value.Value as List<double>).Take(3));
          obj.EndRelease.Add((element.Value.EndRelease as List<StructuralVectorBoolSix>).Last());
          obj.EndRelease.Add((element.Value.EndRelease as List<StructuralVectorBoolSix>).First());
          obj.Offset.Add((element.Value.Offset as List<StructuralVectorThree>).Last());
          obj.Offset.Add((element.Value.Offset as List<StructuralVectorThree>).First());

          if (Initialiser.Settings.Element1DResults.Count > 0 && Initialiser.Settings.EmbedResults)
            for (int i = element.Value.ResultVertices.Count - 3; i >= 0; i -= 3)
              obj.ResultVertices.AddRange((element.Value.ResultVertices as List<double>).Skip(i).Take(3));
          else
          {
            obj.ResultVertices.AddRange((element.Value.Value as List<double>).Skip(3).Take(3));
            obj.ResultVertices.AddRange((element.Value.Value as List<double>).Take(3));
          }
        }

        // Result merging
        if (obj.Result != null)
        {
          try
          { 
            foreach (string loadCase in element.Value.Result.Keys)
            {
              if (!obj.Result.ContainsKey(loadCase))
                obj.Result[loadCase] = new Structural1DElementResult()
                {
                  Value = new Dictionary<string, object>(),
                  IsGlobal = !Initialiser.Settings.ResultInLocalAxis,
                };

              var resultExport = element.Value.Result[loadCase] as Structural1DElementResult;

              if (resultExport != null)
              {
                foreach (var key in resultExport.Value.Keys)
                {
                  if (!(obj.Result[loadCase] as Structural1DElementResult).Value.ContainsKey(key))
                    (obj.Result[loadCase] as Structural1DElementResult).Value[key] = new Dictionary<string, object>(resultExport.Value[key] as Dictionary<string, object>);
                  else
                    foreach (var resultKey in ((obj.Result[loadCase] as Structural1DElementResult).Value[key] as Dictionary<string, object>).Keys)
                    {
                      var res = (resultExport.Value[key] as Dictionary<string, object>)[resultKey] as List<double>;
                      if (reverseCoordinates)
                        res.Reverse();
                      (((obj.Result[loadCase] as Structural1DElementResult).Value[key] as Dictionary<string, object>)[resultKey] as List<double>)
                        .AddRange(res);
                    }
                }
              }
              else
              {
                // UNABLE TO MERGE RESULTS
                obj.Result = null;
                break;
              }
            }
          }
          catch
          {
            // UNABLE TO MERGE RESULTS
            obj.Result = null;
          }
        }

        coordinates.RemoveAt(matchIndex);
        elementsListCopy.RemoveAt(matchIndex);

        this.SubGWACommand.Add(element.GWACommand);
        this.SubGWACommand.AddRange(element.SubGWACommand);
      }
      
      this.Value = obj;
    }
        public void ParseGWACommand(List <GSA2DElement> e2Ds, List <GSA2DMember> m2Ds)
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new Structural2DThermalLoad();

            var pieces = this.GWACommand.ListSplit("\t");

            var counter = 1; // Skip identifier

            obj.Name          = pieces[counter++];
            obj.ApplicationId = HelperClass.GetApplicationId(this.GetGSAKeyword(), this.GSAId);

            var elementList = pieces[counter++];

            obj.ElementRefs = new List <string>();

            if (Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis)
            {
                var elementId = Initialiser.Interface.ConvertGSAList(elementList, SpeckleGSAInterfaces.GSAEntity.ELEMENT);
                foreach (var id in elementId)
                {
                    IGSASpeckleContainer elem = e2Ds.Where(e => e.GSAId == id).FirstOrDefault();

                    if (elem == null)
                    {
                        continue;
                    }

                    obj.ElementRefs.Add((elem.Value as SpeckleObject).ApplicationId);
                    this.SubGWACommand.Add(elem.GWACommand);
                }
            }
            else
            {
                var groupIds = HelperClass.GetGroupsFromGSAList(elementList).ToList();
                foreach (var id in groupIds)
                {
                    var memb2Ds = m2Ds.Where(m => m.Group == id);

                    obj.ElementRefs.AddRange(memb2Ds.Select(m => (string)m.Value.ApplicationId));
                    this.SubGWACommand.AddRange(memb2Ds.Select(m => m.GWACommand));
                }
            }

            obj.LoadCaseRef = HelperClass.GetApplicationId(typeof(GSALoadCase).GetGSAKeyword(), Convert.ToInt32(pieces[counter++]));

            var loadingType = pieces[counter++];

            switch (loadingType)
            {
            case "CONS":
                obj.TopTemperature    = Convert.ToDouble(pieces[counter++]);
                obj.BottomTemperature = obj.TopTemperature;
                break;

            case "DZ":
                obj.TopTemperature    = Convert.ToDouble(pieces[counter++]);
                obj.BottomTemperature = Convert.ToDouble(pieces[counter++]);
                break;

            case "GEN":
                // GENERALIZE THIS TO AN AVERAGE
                for (var i = 0; i < 3; i++)
                {
                    obj.TopTemperature    += Convert.ToDouble(pieces[counter++]);
                    obj.BottomTemperature += Convert.ToDouble(pieces[counter++]);
                }
                obj.TopTemperature    /= 4;
                obj.BottomTemperature /= 4;
                break;
            }

            this.Value = obj;
        }
예제 #30
0
        public void ParseGWACommand(List <GSA2DElement> elements)
        {
            if (elements.Count() < 1)
            {
                return;
            }

            var obj = new Structural2DElementMesh
            {
                ApplicationId = HelperClass.GetApplicationId(typeof(GSA2DElementMesh).GetGSAKeyword(), GSAId),

                Vertices             = new List <double>(),
                Faces                = new List <int>(),
                ElementApplicationId = new List <string>(),

                ElementType = elements.First().Value.ElementType,
                PropertyRef = elements.First().Value.PropertyRef,
                Axis        = new List <StructuralAxis>(),
                Offset      = new List <double>()
            };

            if (Initialiser.Settings.Element2DResults.Count > 0 && Initialiser.Settings.EmbedResults)
            {
                obj.Result = new Dictionary <string, object>();
            }

            foreach (var e in elements)
            {
                var verticesOffset = obj.Vertices.Count() / 3;
                obj.Vertices.AddRange(e.Value.Vertices);
                obj.Faces.Add((e.Value.Faces as List <int>).First());
                obj.Faces.AddRange((e.Value.Faces as List <int>).Skip(1).Select(x => x + verticesOffset));

                obj.Axis.Add(e.Value.Axis);
                obj.Offset.Add(e.Value.Offset);

                obj.ElementApplicationId.Add(e.Value.ApplicationId);

                // Result merging
                if (obj.Result != null)
                {
                    try
                    {
                        foreach (string loadCase in e.Value.Result.Keys)
                        {
                            if (!obj.Result.ContainsKey(loadCase))
                            {
                                obj.Result[loadCase] = new Structural2DElementResult()
                                {
                                    Value    = new Dictionary <string, object>(),
                                    IsGlobal = !Initialiser.Settings.ResultInLocalAxis,
                                }
                            }
                            ;

                            var resultExport = e.Value.Result[loadCase] as Structural2DElementResult;

                            if (resultExport != null)
                            {
                                foreach (var key in resultExport.Value.Keys)
                                {
                                    if (!(obj.Result[loadCase] as Structural2DElementResult).Value.ContainsKey(key))
                                    {
                                        (obj.Result[loadCase] as Structural2DElementResult).Value[key] = new Dictionary <string, object>(resultExport.Value[key] as Dictionary <string, object>);
                                    }
                                    else
                                    {
                                        foreach (var resultKey in ((obj.Result[loadCase] as Structural2DElementResult).Value[key] as Dictionary <string, object>).Keys)
                                        {
                                            (((obj.Result[loadCase] as Structural2DElementResult).Value[key] as Dictionary <string, object>)[resultKey] as List <double>)
                                            .AddRange((resultExport.Value[key] as Dictionary <string, object>)[resultKey] as List <double>);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // UNABLE TO MERGE RESULTS
                                obj.Result = null;
                                break;
                            }
                        }
                    }
                    catch
                    {
                        // UNABLE TO MERGE RESULTS
                        obj.Result = null;
                    }
                }

                this.SubGWACommand.Add(e.GWACommand);
                this.SubGWACommand.AddRange(e.SubGWACommand);
            }

            this.Value = obj;
        }