private static bool Add1dLoadsWithAppId(string entityKeyword, string loadCaseKeyword, IEnumerable <GsaLoadBeamUdl> gsaLoads, ref List <Structural1DLoad> structural1DLoads) { var gsaGroups = gsaLoads.GroupBy(gl => new { ApplicationId = gl.ApplicationId.Substring(0, gl.ApplicationId.IndexOf("_")), gl.LoadCaseIndex }); foreach (var group in gsaGroups) { var gList = group.ToList(); var applicationId = gList[0].ApplicationId.Substring(0, gList[0].ApplicationId.IndexOf("_")); var name = (gList.Any(gl => !string.IsNullOrEmpty(gl.Name))) ? gList.FirstOrDefault(gl => !string.IsNullOrEmpty(gl.Name)).Name : ""; //Assume the element refs are the same for those with application IDs - so just take the indices of the first record and resolve them to application IDs for entities var elementRefs = gList[0].Entities.Select(ei => Initialiser.AppResources.Cache.GetApplicationId(entityKeyword, ei)).Where(aid => !string.IsNullOrEmpty(aid)).ToList(); var loadCaseRef = Initialiser.AppResources.Cache.GetApplicationId(loadCaseKeyword, gList[0].LoadCaseIndex.Value); var loadings = gList.Select(gl => Helper.GsaLoadToLoading(gl.LoadDirection, gl.Load.Value)).ToList(); var combinedLoading = new StructuralVectorSix(Enumerable.Range(0, 6).Select(i => loadings.Sum(l => l.Value[i]))); var load = new Structural1DLoad() { ApplicationId = applicationId, Name = name, ElementRefs = elementRefs, LoadCaseRef = loadCaseRef, Loading = combinedLoading }; structural1DLoads.Add(load); } return(true); }
public static string ToNative(this Structural1DLoad load) { return(new GSA1DLoad() { Value = load }.SetGWACommand()); }
public static string ToNative(this Structural1DLoad load) { return((Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis) ? new GSA1DLoadAnalysisLayer() { Value = load }.SetGWACommand() : new GSA1DLoadDesignLayer() { Value = load }.SetGWACommand()); }
public static string ToNative(this Structural1DLoad load) { if (string.IsNullOrEmpty(load.ApplicationId) && !Helper.IsValidLoading(load.Loading)) { return(""); } //Note: only LOAD_BEAM_UDL is supported at this stage var keyword = GsaRecord.GetKeyword <GsaLoadBeam>(); var gwaSetCommandType = GsaRecord.GetGwaSetCommandType <GsaLoadBeam>(); var streamId = Initialiser.AppResources.Cache.LookupStream(load.ApplicationId); var loadCaseIndex = Initialiser.AppResources.Cache.ResolveIndex(GsaRecord.GetKeyword <GsaLoadCase>(), load.LoadCaseRef); var entityKeyword = (Initialiser.AppResources.Settings.TargetLayer == GSATargetLayer.Design) ? GsaRecord.GetKeyword <GsaMemb>() : GsaRecord.GetKeyword <GsaEl>(); var entityIndices = Initialiser.AppResources.Cache.LookupIndices(entityKeyword, load.ElementRefs).Where(i => i.HasValue).Select(i => i.Value).ToList(); 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 GsaLoadBeamUdl() { Index = index, ApplicationId = applicationId, StreamId = streamId, Name = load.Name, LoadDirection = k, Load = loadingDict[k], Projected = false, AxisRefType = LoadBeamAxisRefType.Global, LoadCaseIndex = loadCaseIndex, Entities = entityIndices }; if (gsaLoad.Gwa(out var gwa, false)) { foreach (var gwaLine in gwa) { Initialiser.AppResources.Cache.Upsert(keyword, index, gwaLine, streamId, applicationId, gwaSetCommandType); } } } return(""); }
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).OrderBy(i => i).ToList(); this.SubGWACommand.AddRange(elems.Select(n => n.GWACommand)); } } else if (Initialiser.Settings.TargetLayer == GSATargetLayer.Design) { var targetGroups = Helper.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 = Helper.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; }
private static bool Add1dLoadsWithoutAppId(string keyword, string axisKeyword, string entityKeyword, string loadCaseKeyword, IEnumerable <GsaLoadBeamUdl> gsaLoads, ref List <Structural1DLoad> structural1DLoads) { var gsaGroups = gsaLoads.GroupBy(gl => gl.LoadCaseIndex).Select(g => g.OfType <GsaLoadBeamUdl>().ToList()).ToList(); foreach (var gsaGroup in gsaGroups) { //This is the group which might have axes, so if this is true, then they need to be transformed var transformedGsaLoads = new List <StructuralVectorSix>(); var uniqueLoadings = new List <StructuralVectorSix>(); var uniqueToLoadingsList = new Dictionary <int, List <int> >(); var glByIndex = gsaGroup.Where(gl => gl.Index.HasValue).ToDictionary(gl => gl.Index.Value, gl => gl); foreach (var gl in gsaGroup) { if (!gl.Index.HasValue || gl.Index == 0) { continue; } var loading = Helper.GsaLoadToLoading(gl.LoadDirection, gl.Load.Value); if (gl.AxisRefType == LoadBeamAxisRefType.Reference && gl.AxisIndex.HasValue && gl.AxisIndex.Value > 0) { var axisGwa = Initialiser.AppResources.Cache.GetGwa(axisKeyword, gl.AxisIndex.Value); if (axisGwa != null && axisGwa.Count() > 0 && string.IsNullOrEmpty(axisGwa.First())) { return(false); } var gsaAxis = new GsaAxis(); gsaAxis.FromGwa(axisGwa.First()); var loadAxis = (StructuralAxis)gsaAxis.ToSpeckle(); //Converts from loads on an axis to their global equivalent loading.TransformOntoAxis(loadAxis); } int uniqueLoadingIndex; 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); } if (!uniqueToLoadingsList.ContainsKey(uniqueLoadingIndex)) { uniqueToLoadingsList.Add(uniqueLoadingIndex, new List <int>()); } uniqueToLoadingsList[uniqueLoadingIndex].Add(gl.Index.Value); } } foreach (var ul in uniqueToLoadingsList.Keys) { var entityIndices = uniqueToLoadingsList[ul].SelectMany(ei => glByIndex[ei].Entities).Distinct().OrderBy(n => n).ToList(); var elementRefs = entityIndices.Select(ei => Initialiser.AppResources.Cache.GetApplicationId(entityKeyword, ei)).Where(aid => !string.IsNullOrEmpty(aid)).ToList(); var loadCaseRef = (gsaGroup.First().LoadCaseIndex.HasValue) ? Initialiser.AppResources.Cache.GetApplicationId(loadCaseKeyword, gsaGroup.First().LoadCaseIndex.Value) : null; var load = new Structural1DLoad() { ApplicationId = SpeckleStructuralGSA.Helper.FormatApplicationId(keyword, uniqueToLoadingsList[ul]), Name = gsaGroup.First().Name, ElementRefs = elementRefs, LoadCaseRef = loadCaseRef, Loading = uniqueLoadings[ul] }; structural1DLoads.Add(load); } } return(true); }