コード例 #1
0
 public static string ToNative(this Structural0DLoad load)
 {
     return(new GSA0DLoad()
     {
         Value = load
     }.SetGWACommand());
 }
コード例 #2
0
        private static bool Add0dLoadsWithAppId(string nodeKeyword, string loadCaseKeyword, IEnumerable <GsaLoadNode> gsaLoads,
                                                List <GSANode> gsaNodes, ref List <Structural0DLoad> structural0DLoads, ref List <int> nodeIndicesReferenced)
        {
            var summaries = new List <D0LoadingSummary>();

            //All loads here have an application ID and axis is set to GLOBAL
            foreach (var gl in gsaLoads)
            {
                //Assume an underscore is the end of the original Application ID of the Speckle object that created up to 6 rows of 0D loads
                var appId            = gl.ApplicationId.Substring(0, gl.ApplicationId.IndexOf("_"));
                var relevantGsaNodes = gsaNodes.Where(n => gl.NodeIndices.Any(ni => ni == n.GSAId)).ToList();
                foreach (var n in relevantGsaNodes)
                {
                    summaries.Add(new D0LoadingSummary(gl.Index.Value, gl.LoadCaseIndex, n.GSAId)
                    {
                        ApplicationId = appId
                    });
                }
            }

            var groups = summaries.GroupBy(s => new { s.LoadCaseIndex, s.ApplicationId });

            var allNodeIndices = nodeIndicesReferenced.ToList();

            foreach (var group in groups)
            {
                var indices     = group.Select(i => i.Index).Distinct().ToList();
                var nodeIndices = group.Select(i => i.NodeIndex).Where(i => i != null).Distinct().ToList();
                allNodeIndices.AddRange(nodeIndices.Where(ni => ni.HasValue && !allNodeIndices.Contains(ni.Value)).Select(ni => ni.Value));
                var nodeRefs        = nodeIndices.Select(ni => SpeckleStructuralGSA.Helper.GetApplicationId(nodeKeyword, ni.Value)).OrderBy(r => r).ToList();
                var loadCaseRef     = SpeckleStructuralGSA.Helper.GetApplicationId(loadCaseKeyword, group.First().LoadCaseIndex.Value);
                var applicationId   = group.First().ApplicationId;
                var name            = string.Join("-", group.Where(i => !string.IsNullOrEmpty(i.Name)).Select(i => i.Name));
                var loadings        = indices.Select(i => gsaLoads.First(l => l.Index == i)).Select(gl => Helper.GsaLoadToLoading(gl.LoadDirection, gl.Value.Value)).ToList();
                var combinedLoading = new StructuralVectorSix(Enumerable.Range(0, 6).Select(i => loadings.Sum(l => l.Value[i])));
                var obj             = new Structural0DLoad()
                {
                    ApplicationId = applicationId, Loading = combinedLoading, NodeRefs = nodeRefs, LoadCaseRef = loadCaseRef
                };
                if (!string.IsNullOrEmpty(name))
                {
                    obj.Name = name;
                }
                Helper.AddCustomStructuralProperty(obj, indices.Count() == 1 ? "NativeId" : "NativeIds",
                                                   indices.Count() == 1 ? (object)indices.First().ToString() : indices.Select(i => i.ToString()).ToList());
                structural0DLoads.Add(obj);
            }

            nodeIndicesReferenced = allNodeIndices;

            return(true);
        }
コード例 #3
0
        public static string ToNative(this Structural0DLoad load)
        {
            if (string.IsNullOrEmpty(load.ApplicationId) && !Helper.IsValidLoading(load.Loading))
            {
                return("");
            }

            var keyword         = GsaRecord.GetKeyword <GsaLoadNode>();
            var nodeKeyword     = GsaRecord.GetKeyword <GsaNode>();
            var loadCaseKeyword = GsaRecord.GetKeyword <GsaLoadCase>();

            var nodeIndices       = Initialiser.AppResources.Cache.LookupIndices(nodeKeyword, load.NodeRefs).Where(x => x.HasValue).Select(x => x.Value).OrderBy(i => i).ToList();
            var loadCaseIndex     = Initialiser.AppResources.Cache.ResolveIndex(loadCaseKeyword, load.LoadCaseRef);
            var streamId          = Initialiser.AppResources.Cache.LookupStream(load.ApplicationId);
            var gwaSetCommandType = GsaRecord.GetGwaSetCommandType <GsaLoadNode>();

            var gwaList     = new List <string>();
            var loadingDict = Helper.ExplodeLoading(load.Loading);

            foreach (var k in loadingDict.Keys)
            {
                var applicationId = string.Join("_", load.ApplicationId, k.ToString());
                var index         = Initialiser.AppResources.Cache.ResolveIndex(keyword, applicationId);
                var gsaLoad       = new GsaLoadNode()
                {
                    Index         = index,
                    ApplicationId = applicationId,
                    StreamId      = streamId,
                    Name          = load.Name,
                    LoadDirection = k,
                    Value         = loadingDict[k],
                    GlobalAxis    = true,
                    NodeIndices   = nodeIndices,
                    LoadCaseIndex = loadCaseIndex
                };
                if (gsaLoad.Gwa(out var gwa, false))
                {
                    Initialiser.AppResources.Cache.Upsert(keyword, index, gwa.First(), streamId, applicationId, gwaSetCommandType);
                }
            }

            return("");
        }
コード例 #4
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;
        }
コード例 #5
0
        private static bool Add0dLoadsWithoutAppId(string keyword, string nodeKeyword, string loadCaseKeyword, IEnumerable <GsaLoadNode> gsaLoads,
                                                   List <GSANode> gsaNodes, ref List <Structural0DLoad> structural0DLoads, ref List <int> nodeIndicesReferenced)
        {
            var summaries      = new List <D0LoadingSummary>();
            var uniqueLoadings = new List <StructuralVectorSix>();

            foreach (var gl in gsaLoads.Where(l => l.Value != null))
            {
                var relevantGsaNodes = gsaNodes.Where(n => gl.NodeIndices.Any(ni => ni == n.GSAId)).ToList();
                foreach (var n in relevantGsaNodes)
                {
                    var loading            = Helper.GsaLoadToLoading(gl.LoadDirection, gl.Value.Value);
                    int?uniqueLoadingIndex = null;
                    if (!gl.GlobalAxis)
                    {
                        var loadAxis = (StructuralAxis)SpeckleStructuralGSA.Helper.Parse0DAxis(gl.AxisIndex.Value, out string _, n.Value.Value.ToArray());
                        if (!Helper.IsZeroAxis(loadAxis))
                        {
                            //Converts from loads on an axis to their global equivalent
                            loading.TransformOntoAxis(loadAxis);
                        }
                    }
                    if (loading != null)
                    {
                        var matching = uniqueLoadings.Where(k => k.Value.SequenceEqual(loading.Value));
                        if (matching.Count() > 0)
                        {
                            uniqueLoadingIndex = uniqueLoadings.IndexOf(matching.First());
                        }
                        else
                        {
                            uniqueLoadingIndex = uniqueLoadings.Count();
                            uniqueLoadings.Add(loading);
                        }
                    }

                    summaries.Add(new D0LoadingSummary(gl.Index.Value, gl.LoadCaseIndex, n.GSAId)
                    {
                        UniqueLoadingIndex = uniqueLoadingIndex, Name = gl.Name
                    });
                }
            }

            var groups = summaries.GroupBy(s => new { s.LoadCaseIndex, s.UniqueLoadingIndex });

            var allNodeIndices = nodeIndicesReferenced.ToList();

            foreach (var group in groups)
            {
                var indices     = group.Select(i => i.Index).Distinct().ToList();
                var nodeIndices = group.Select(i => i.NodeIndex).Where(i => i != null).Distinct().ToList();
                allNodeIndices.AddRange(nodeIndices.Where(ni => ni.HasValue && !allNodeIndices.Contains(ni.Value)).Select(ni => ni.Value));
                var nodeRefs      = nodeIndices.Select(ni => SpeckleStructuralGSA.Helper.GetApplicationId(nodeKeyword, ni.Value)).OrderBy(r => r).ToList();
                var loadCaseRef   = SpeckleStructuralGSA.Helper.GetApplicationId(loadCaseKeyword, group.First().LoadCaseIndex.Value);
                var applicationId = SpeckleStructuralGSA.Helper.FormatApplicationId(keyword, indices);
                var name          = string.Join("-", group.Where(i => !string.IsNullOrEmpty(i.Name)).Select(i => i.Name));
                var loading       = uniqueLoadings[group.First().UniqueLoadingIndex.Value];
                var obj           = new Structural0DLoad()
                {
                    ApplicationId = applicationId, Loading = loading, NodeRefs = nodeRefs, LoadCaseRef = loadCaseRef
                };
                if (!string.IsNullOrEmpty(name))
                {
                    obj.Name = name;
                }
                Helper.AddCustomStructuralProperty(obj, indices.Count() == 1 ? "NativeId" : "NativeIds",
                                                   indices.Count() == 1 ? (object)indices.First().ToString() : indices.Select(i => i.ToString()).ToList());
                structural0DLoads.Add(obj);
            }

            nodeIndicesReferenced = allNodeIndices;
            return(true);
        }