Skip to content

Commit

Permalink
Merge pull request #217 from arup-group/GSAGH-153-1d-local-axis-compo…
Browse files Browse the repository at this point in the history
…nent-gives-

GSAGH-153-1d-local-axis-component-gives-
  • Loading branch information
tlmnrnhrdt authored Nov 28, 2022
2 parents 07a8cde + 296bd13 commit 3e1668b
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 170 deletions.
Binary file added ExampleFiles/Components/LocalAxes.gh
Binary file not shown.
29 changes: 21 additions & 8 deletions GsaGH/Components/0_Model/GetGeometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using OasysUnits.Serialization.JsonNet;
using OasysUnits.Units;
using Rhino.Geometry;
using System.Collections.ObjectModel;

namespace GsaGH.Components
{
Expand Down Expand Up @@ -90,8 +91,9 @@ public class SolveResults
internal ConcurrentBag<GsaMember2dGoo> Mem2ds { get; set; }
internal ConcurrentBag<GsaMember3dGoo> Mem3ds { get; set; }
}

SolveResults Compute(
ConcurrentDictionary<int, Node> allnDict,
ConcurrentDictionary<int, Node> allnDict,
ConcurrentDictionary<int, Axis> axDict,
ConcurrentDictionary<int, Node> nDict,
ConcurrentDictionary<int, Element> eDict,
Expand All @@ -100,7 +102,8 @@ SolveResults Compute(
ConcurrentDictionary<int, Prop2D> pDict,
ConcurrentDictionary<int, Prop3D> p3Dict,
ConcurrentDictionary<int, AnalysisMaterial> amDict,
ConcurrentDictionary<int, SectionModifier> modDict
ConcurrentDictionary<int, SectionModifier> modDict,
ConcurrentDictionary<int, ReadOnlyCollection<double>> localAxesDict
)
{
SolveResults results = new SolveResults();
Expand All @@ -121,7 +124,7 @@ ConcurrentDictionary<int, SectionModifier> modDict
{
// create elements
Tuple<ConcurrentBag<GsaElement1dGoo>, ConcurrentBag<GsaElement2dGoo>, ConcurrentBag<GsaElement3dGoo>> elementTuple
= Util.Gsa.FromGSA.GetElements(eDict, allnDict, sDict, pDict, p3Dict, amDict, modDict, LengthUnit);
= Util.Gsa.FromGSA.GetElements(eDict, allnDict, sDict, pDict, p3Dict, amDict, modDict, localAxesDict, LengthUnit);
results.Elem1ds = elementTuple.Item1;
results.Elem2ds = elementTuple.Item2;
Expand All @@ -132,7 +135,7 @@ Tuple<ConcurrentBag<GsaElement1dGoo>, ConcurrentBag<GsaElement2dGoo>, Concurrent
{
// create members
Tuple<ConcurrentBag<GsaMember1dGoo>, ConcurrentBag<GsaMember2dGoo>, ConcurrentBag<GsaMember3dGoo>> memberTuple
= Util.Gsa.FromGSA.GetMembers(mDict, allnDict, LengthUnit, sDict, pDict, p3Dict, this);
= Util.Gsa.FromGSA.GetMembers(mDict, allnDict, LengthUnit, sDict, pDict, p3Dict, localAxesDict, this);
results.Mem1ds = memberTuple.Item1;
results.Mem2ds = memberTuple.Item2;
Expand Down Expand Up @@ -293,8 +296,13 @@ protected override void SolveInstance(IGH_DataAccess data)
ConcurrentDictionary<int, AnalysisMaterial> amDict = new ConcurrentDictionary<int, AnalysisMaterial>(model.AnalysisMaterials());
ConcurrentDictionary<int, SectionModifier> modDict = new ConcurrentDictionary<int, SectionModifier>(model.SectionModifiers());

// populate local axes dictionary
ConcurrentDictionary<int, ReadOnlyCollection<double>> localAxesDict = new ConcurrentDictionary<int, ReadOnlyCollection<double>>();
foreach(int id in eDict.Keys)
localAxesDict.TryAdd(id, model.ElementDirectionCosine(id));

tsk = Task.Run(() => Compute(nDict, axDict, out_nDict,
eDict, mDict, sDict, pDict, p3Dict, amDict, modDict), CancelToken);
eDict, mDict, sDict, pDict, p3Dict, amDict, modDict, localAxesDict), CancelToken);
}
// Add a null task even if data collection fails. This keeps the
// list size in sync with the iterations
Expand Down Expand Up @@ -345,8 +353,13 @@ protected override void SolveInstance(IGH_DataAccess data)
ConcurrentDictionary<int, AnalysisMaterial> amDict = new ConcurrentDictionary<int, AnalysisMaterial>(model.AnalysisMaterials());
ConcurrentDictionary<int, SectionModifier> modDict = new ConcurrentDictionary<int, SectionModifier>(model.SectionModifiers());

// populate local axes dictionary
ConcurrentDictionary<int, ReadOnlyCollection<double>> localAxesDict = new ConcurrentDictionary<int, ReadOnlyCollection<double>>();
foreach (int id in eDict.Keys)
localAxesDict.TryAdd(id, model.ElementDirectionCosine(id));

results = Compute(nDict, axDict, out_nDict,
eDict, mDict, sDict, pDict, p3Dict, amDict, modDict);
eDict, mDict, sDict, pDict, p3Dict, amDict, modDict, localAxesDict);
}
else return;
}
Expand Down Expand Up @@ -603,7 +616,7 @@ public override void DrawViewportWires(IGH_PreviewArgs args)
public List<string> SpacerDescriptions;

public bool IsInitialised;

private LengthUnit LengthUnit = DefaultUnits.LengthUnitGeometry;

public override void CreateAttributes()
Expand All @@ -614,7 +627,7 @@ public override void CreateAttributes()
m_attributes = new OasysGH.UI.DropDownComponentAttributes(this, SetSelected, DropDownItems, SelectedItems, SpacerDescriptions);
}

public void InitialiseDropdowns()
public void InitialiseDropdowns()
{
this.SpacerDescriptions = new List<string>(new string[]
{
Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Components/2_Geometry/EditElement1d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void RegisterInputParams(GH_InputParamManager pManager)
pManager.AddParameter(new GsaBool6Parameter(), "End release", "", "Set Release (Bool6) at End of Element", GH_ParamAccess.item);

pManager.AddAngleParameter("Orientation Angle", "⭮A", "Set Element Orientation Angle", GH_ParamAccess.item);
pManager.AddGenericParameter("Orientation Node", "⭮N", "Set Element Orientation Node", GH_ParamAccess.item);
pManager.AddParameter(new GsaNodeParameter(), "Orientation Node", "⭮N", "Set Element Orientation Node", GH_ParamAccess.item);

pManager.AddTextParameter("Name", "Na", "Set Element Name", GH_ParamAccess.item);
pManager.AddColourParameter("Colour", "Co", "Set Element Colour", GH_ParamAccess.item);
Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Components/2_Geometry/EditMember1d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected override void RegisterInputParams(GH_InputParamManager pManager)
pManager.AddParameter(new GsaBool6Parameter(), "Start release", "", "Set Release (Bool6) at Start of Member", GH_ParamAccess.item);
pManager.AddParameter(new GsaBool6Parameter(), "End release", "", "Set Release (Bool6) at End of Member", GH_ParamAccess.item);
pManager.AddAngleParameter("Orientation Angle", "⭮A", "Set Member Orientation Angle", GH_ParamAccess.item);
pManager.AddGenericParameter("Orientation Node", "⭮N", "Set Member Orientation Node", GH_ParamAccess.item);
pManager.AddParameter(new GsaNodeParameter(), "Orientation Node", "⭮N", "Set Member Orientation Node", GH_ParamAccess.item);
pManager.AddNumberParameter("Mesh Size in model units", "Ms", "Set Member Mesh Size", GH_ParamAccess.item);
pManager.AddBooleanParameter("Mesh With Others", "M/o", "Mesh with others?", GH_ParamAccess.item);
pManager.AddParameter(new GsaBucklingLengthFactorsParameter(), "Set " + GsaBucklingLengthFactorsGoo.Name, GsaBucklingLengthFactorsGoo.NickName, GsaBucklingLengthFactorsGoo.Description, GH_ParamAccess.item);
Expand Down
11 changes: 10 additions & 1 deletion GsaGH/Components/2_Geometry/ElemFromMem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
Expand Down Expand Up @@ -184,6 +185,13 @@ protected override void SolveInstance(IGH_DataAccess DA)
// extract nodes from model
ConcurrentBag<GsaNodeGoo> nodes = Util.Gsa.FromGSA.GetNodes(new ConcurrentDictionary<int, Node>(gsa.Nodes()), LengthUnit);

ConcurrentDictionary<int, Element> elementDict = new ConcurrentDictionary<int, Element>(gsa.Elements());

// populate local axes dictionary
ConcurrentDictionary<int, ReadOnlyCollection<double>> localAxesDict = new ConcurrentDictionary<int, ReadOnlyCollection<double>>();
foreach (int id in elementDict.Keys)
localAxesDict.TryAdd(id, gsa.ElementDirectionCosine(id));

// extract elements from model
Tuple<ConcurrentBag<GsaElement1dGoo>, ConcurrentBag<GsaElement2dGoo>, ConcurrentBag<GsaElement3dGoo>> elementTuple
= Util.Gsa.FromGSA.GetElements(
Expand All @@ -194,6 +202,7 @@ Tuple<ConcurrentBag<GsaElement1dGoo>, ConcurrentBag<GsaElement2dGoo>, Concurrent
new ConcurrentDictionary<int, Prop3D>(gsa.Prop3Ds()),
new ConcurrentDictionary<int, AnalysisMaterial>(gsa.AnalysisMaterials()),
new ConcurrentDictionary<int, SectionModifier>(gsa.SectionModifiers()),
localAxesDict,
LengthUnit);

// post process materials (as they currently have a bug when running parallel!)
Expand Down Expand Up @@ -363,7 +372,7 @@ public override void UpdateUIFromSelectedItems()
this.LengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), this.SelectedItems[0]);
base.UpdateUIFromSelectedItems();
}

public override void VariableParameterMaintenance()
{
string unitAbbreviation = Length.GetAbbreviation(this.LengthUnit);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
using GsaAPI;
using GsaGH.Parameters;
using GsaGH.Util.Gsa.ToGSA;
using OasysGH;
using OasysGH.Components;
using OasysUnits.Units;
using Rhino.Geometry;

namespace GsaGH.Components
{
/// <summary>
/// Component to edit a Node
/// </summary>
public class LocalAxis : GH_OasysComponent, IGH_PreviewObject
public class LocalAxes : GH_OasysComponent, IGH_PreviewObject
{
#region Name and Ribbon Layout
public override Guid ComponentGuid => new Guid("4a322b8e-031a-4c90-b8df-b32d162a3274");
public override GH_Exposure Exposure => GH_Exposure.quarternary | GH_Exposure.obscure;
public override OasysPluginInfo PluginInfo => GsaGH.PluginInfo.Instance;
protected override System.Drawing.Bitmap Icon => GsaGH.Properties.Resources.LocalAxes;

public LocalAxis() : base("Local Axis",
public LocalAxes() : base("Local Axis",
"Axis",
"Get Element1D or Member1D local axes",
Ribbon.CategoryName.Name(),
Expand Down Expand Up @@ -50,7 +56,7 @@ protected override void SolveInstance(IGH_DataAccess DA)
GsaElement1d elem = null;
Point3d midPt = new Point3d();
double size = 0;
Tuple<Vector3d, Vector3d, Vector3d> axes;
GsaLocalAxes axes;
if (gh_typ.Value is GsaMember1dGoo)
{
gh_typ.CastTo(ref mem);
Expand All @@ -60,6 +66,14 @@ protected override void SolveInstance(IGH_DataAccess DA)
return;
}
axes = mem.LocalAxes;
if (axes == null)
{
GsaModel model = new GsaModel();
model.Model = Util.Gsa.ToGSA.Assemble.AssembleModel(model, new List<GsaNode>(), new List<GsaElement1d>(), new List<GsaElement2d>(), new List<GsaElement3d>(), new List<GsaMember1d>() { mem }, new List<GsaMember2d>(), new List<GsaMember3d>(), new List<GsaSection>(), new List<GsaProp2d>(), new List<GsaProp3d>(), new List<GsaLoad>(), new List<GsaGridPlaneSurface>(), new List<GsaAnalysisTask>(), new List<GsaCombinationCase>(), LengthUnit.Meter);

axes = new GsaLocalAxes(model.Model.MemberDirectionCosine(1));
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Members´s local axes might deviate from the local axes in the assembled GSA model.");
}
midPt = mem.PolyCurve.PointAtNormalizedLength(0.5);
size = mem.PolyCurve.GetLength() * 0.05;
}
Expand All @@ -72,6 +86,14 @@ protected override void SolveInstance(IGH_DataAccess DA)
return;
}
axes = elem.LocalAxes;
if (axes == null)
{
GsaModel model = new GsaModel();
model.Model = Util.Gsa.ToGSA.Assemble.AssembleModel(model, new List<GsaNode>(), new List<GsaElement1d>() { elem }, new List<GsaElement2d>(), new List<GsaElement3d>(), new List<GsaMember1d>(), new List<GsaMember2d>(), new List<GsaMember3d>(), new List<GsaSection>(), new List<GsaProp2d>(), new List<GsaProp3d>(), new List<GsaLoad>(), new List<GsaGridPlaneSurface>(), new List<GsaAnalysisTask>(), new List<GsaCombinationCase>(), LengthUnit.Meter);

axes = new GsaLocalAxes(model.Model.ElementDirectionCosine(1));
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Element´s local axes might deviate from the local axes in the assembled GSA model.");
}
midPt = elem.Line.PointAtNormalizedLength(0.5);
size = elem.Line.GetLength() * 0.05;
}
Expand All @@ -80,15 +102,12 @@ protected override void SolveInstance(IGH_DataAccess DA)
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert input to Element1D or Member1D");
return;
}

Vector3d x = axes.Item1;
Vector3d y = axes.Item2;
Vector3d z = axes.Item3;

Vector3d x = axes.X;
Vector3d y = axes.Y;
Vector3d z = axes.Z;
DA.SetData(0, x);
DA.SetData(1, y);
DA.SetData(2, z);

previewXaxis = new Line(midPt, x, size);
previewYaxis = new Line(midPt, y, size);
previewZaxis = new Line(midPt, z, size);
Expand Down
9 changes: 7 additions & 2 deletions GsaGH/Helpers/Export/_GsaExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public static GsaModel MergeModel(GsaModel mainModel, GsaModel appendModel)
ConcurrentDictionary<int, AnalysisMaterial> amDict = new ConcurrentDictionary<int, AnalysisMaterial>(model.AnalysisMaterials());
ConcurrentDictionary<int, SectionModifier> modDict = new ConcurrentDictionary<int, SectionModifier>(model.SectionModifiers());

// populate local axes dictionary
ConcurrentDictionary<int, ReadOnlyCollection<double>> localAxesDict = new ConcurrentDictionary<int, ReadOnlyCollection<double>>();
foreach (int id in eDict.Keys)
localAxesDict.TryAdd(id, model.ElementDirectionCosine(id));

// get nodes
ConcurrentBag<GsaNodeGoo> goonodes = Util.Gsa.FromGSA.GetNodes(nDict, LengthUnit.Meter);
// convert from Goo-type
Expand All @@ -61,7 +66,7 @@ public static GsaModel MergeModel(GsaModel mainModel, GsaModel appendModel)

// get elements
Tuple<ConcurrentBag<GsaElement1dGoo>, ConcurrentBag<GsaElement2dGoo>, ConcurrentBag<GsaElement3dGoo>> elementTuple
= Util.Gsa.FromGSA.GetElements(eDict, nDict, sDict, pDict, p3Dict, amDict, modDict, LengthUnit.Meter);
= Util.Gsa.FromGSA.GetElements(eDict, nDict, sDict, pDict, p3Dict, amDict, modDict, localAxesDict, LengthUnit.Meter);
// convert from Goo-type
List<GsaElement1d> elem1ds = elementTuple.Item1.Select(n => n.Value).ToList();
// change all members in List's ID to 0;
Expand All @@ -79,7 +84,7 @@ Tuple<ConcurrentBag<GsaElement1dGoo>, ConcurrentBag<GsaElement2dGoo>, Concurrent

// get members
Tuple<ConcurrentBag<GsaMember1dGoo>, ConcurrentBag<GsaMember2dGoo>, ConcurrentBag<GsaMember3dGoo>> memberTuple
= Util.Gsa.FromGSA.GetMembers(mDict, nDict, LengthUnit.Meter, sDict, pDict, p3Dict);
= Util.Gsa.FromGSA.GetMembers(mDict, nDict, LengthUnit.Meter, sDict, pDict, p3Dict, localAxesDict);
// convert from Goo-type
List<GsaMember1d> mem1ds = memberTuple.Item1.Select(n => n.Value).ToList();
// change all members in List's ID to 0;
Expand Down
31 changes: 0 additions & 31 deletions GsaGH/Helpers/_Display.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,9 @@ namespace GsaGH.UI
/// <summary>
/// Colour class holding the main colours used in colour scheme.
/// Make calls to this class to be able to easy update colours.
///
/// </summary>
public class Display
{
public static Tuple<Vector3d, Vector3d, Vector3d> GetLocalPlane(PolyCurve crv, double t, double orientationAngle)
{
crv.PerpendicularFrameAt(t, out Plane pln);
pln.Rotate(orientationAngle, pln.Normal);

double absAngleToZ = Vector3d.VectorAngle(pln.Normal, Vector3d.ZAxis);
absAngleToZ %= Math.PI;

Vector3d outX = pln.ZAxis;
Vector3d outY;
if (absAngleToZ < 0.25 * Math.PI || absAngleToZ > 0.75 * Math.PI)
{
outY = new Vector3d(outX);
double angle;
if (outX.Z > 0)
angle = -0.5 * Math.PI;
else
angle = 0.5 * Math.PI;

if (!outY.Rotate(angle, pln.XAxis))
throw new Exception();
}
else
{
outY = pln.YAxis;
}
Vector3d outZ = Vector3d.CrossProduct(outX, outY);
return new Tuple<Vector3d, Vector3d, Vector3d>(outX, outY, outZ);
}

public static void Preview1D(PolyCurve crv, double angle_radian, GsaBool6 start, GsaBool6 end,
ref List<Line> greenLines20, ref List<Line> redLines10)
{
Expand Down
Loading

0 comments on commit 3e1668b

Please sign in to comment.