Skip to content

Commit

Permalink
GSAGH-488 displacements for result diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
tlmnrnhrdt committed Apr 17, 2024
1 parent f694d6f commit e284bf9
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 56 deletions.
77 changes: 64 additions & 13 deletions GsaGH/Components/6_Display/ResultDiagrams.cs
Expand Up @@ -22,14 +22,15 @@
using OasysUnits;
using OasysUnits.Units;
using Rhino.Geometry;
using AngleUnit = OasysUnits.Units.AngleUnit;
using DiagramType = GsaAPI.DiagramType;
using ForceUnit = OasysUnits.Units.ForceUnit;
using LengthUnit = OasysUnits.Units.LengthUnit;
using Line = GsaAPI.Line;

namespace GsaGH.Components {
/// <summary>
/// Component to get Element1D results
/// Component to get Element1D result diagrams
/// </summary>
public class ResultDiagrams : GH_OasysDropDownComponent {
public override Guid ComponentGuid => new Guid("7ae7ac36-f811-4c20-911f-ddb119f45644");
Expand All @@ -38,6 +39,7 @@ public class ResultDiagrams : GH_OasysDropDownComponent {
protected override Bitmap Icon => Resources.ResultDiagrams;

private string _case = string.Empty;
private AngleUnit _angleUnit = DefaultUnits.AngleUnit;
private LengthUnit _lengthUnit = DefaultUnits.LengthUnitResult;
private ForceUnit _forceUnit = DefaultUnits.ForceUnit;
private MomentUnit _momentUnit = DefaultUnits.MomentUnit;
Expand All @@ -47,9 +49,13 @@ public class ResultDiagrams : GH_OasysDropDownComponent {
"Displays GSA 1D Element Result Diagram", CategoryName.Name(), SubCategoryName.Cat6()) { }

public override bool Read(GH_IReader reader) {
string angle = string.Empty;
_angleUnit = reader.TryGetString("angle", ref angle)
? (AngleUnit)UnitsHelper.Parse(typeof(AngleUnit), angle)
: DefaultUnits.AngleUnit;
string length = string.Empty;
_lengthUnit = reader.TryGetString("length", ref length)
? (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), length)
_lengthUnit = reader.TryGetString("length", ref length)
? (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), length)
: DefaultUnits.LengthUnitResult;
_forceUnit = (ForceUnit)UnitsHelper.Parse(typeof(ForceUnit), reader.GetString("force"));
_momentUnit = (MomentUnit)UnitsHelper.Parse(typeof(MomentUnit), reader.GetString("moment"));
Expand Down Expand Up @@ -89,6 +95,7 @@ public class ResultDiagrams : GH_OasysDropDownComponent {
}

public override bool Write(GH_IWriter writer) {
writer.SetString("angle", Angle.GetAbbreviation(_angleUnit));
writer.SetString("length", Length.GetAbbreviation(_lengthUnit));
writer.SetString("force", Force.GetAbbreviation(_forceUnit));
writer.SetString("moment", Moment.GetAbbreviation(_momentUnit));
Expand All @@ -103,6 +110,8 @@ public class ResultDiagrams : GH_OasysDropDownComponent {

Menu_AppendSeparator(menu);

ToolStripMenuItem angleUnitsMenu = GenerateToolStripMenuItem.GetSubMenuItem("Angle",
EngineeringUnits.Angle, Angle.GetAbbreviation(_angleUnit), UpdateAngle);
ToolStripMenuItem lengthUnitsMenu = GenerateToolStripMenuItem.GetSubMenuItem("Length",
EngineeringUnits.Length, Length.GetAbbreviation(_lengthUnit), UpdateLength);
ToolStripMenuItem forceUnitsMenu = GenerateToolStripMenuItem.GetSubMenuItem("Force",
Expand All @@ -115,6 +124,7 @@ public class ResultDiagrams : GH_OasysDropDownComponent {
var unitsMenu = new ToolStripMenuItem("Select Units", Resources.ModelUnits);

unitsMenu.DropDownItems.AddRange(new ToolStripItem[] {
angleUnitsMenu,
lengthUnitsMenu,
forceUnitsMenu,
momentUnitsMenu,
Expand All @@ -140,10 +150,10 @@ public class ResultDiagrams : GH_OasysDropDownComponent {
"Force",
"Stress",
});
_selectedItems.Add(_dropDownItems[0][0]);
_dropDownItems.Add(Mappings._diagramTypeMappingDisplacement.Select(item => item.Description)
_selectedItems.Add(_dropDownItems[0][1]);
_dropDownItems.Add(Mappings._diagramTypeMappingForce.Select(item => item.Description)
.ToList());
_selectedItems.Add(_dropDownItems[1][3]);
_selectedItems.Add(_dropDownItems[1][5]); // Myy

_isInitialised = true;
}
Expand Down Expand Up @@ -181,8 +191,10 @@ public class ResultDiagrams : GH_OasysDropDownComponent {
Message = Moment.GetAbbreviation(_momentUnit);
} else if (IsStress()) {
Message = Pressure.GetAbbreviation(_stressUnit);
} else if (IsDisplacement()) {
} else if (IsTranslation()) {
Message = Length.GetAbbreviation(_lengthUnit);
} else if (IsRotation()) {
Message = Angle.GetAbbreviation(_angleUnit);
} else {
Message = "Error";
this.AddRuntimeError("Cannot get unit for selected diagramType!");
Expand Down Expand Up @@ -256,8 +268,27 @@ public class ResultDiagrams : GH_OasysDropDownComponent {
da.GetData(4, ref color);

double lengthScaleFactor = UnitConverter.Convert(1, Length.BaseUnit, lengthUnit);
bool doubleArrow = false;
bool isDisplacement = false;
if (_selectedItems[0] == "Displacement") {
isDisplacement = true;
if (IsTranslation()) {
color = Color.FromArgb(102, 220, 103);
} else {
color = Color.FromArgb(184, 46, 46);
doubleArrow = true;
}
}

foreach (Line item in linesFromModel) {
diagramLines.Add(new GsaDiagramGoo(new GsaLineDiagram(item, lengthScaleFactor, color)));
if (isDisplacement) {
var anchor = new Point3d(item.Start.X, item.Start.Y, item.Start.Z);
// direction is reversed since GsaVectorDiagram has been implemented for reaction forces, needs refactoring!
var direction = new Vector3d(item.Start.X - item.End.X, item.Start.Y - item.End.Y, item.Start.Z - item.End.Z);
diagramLines.Add(new GsaDiagramGoo(new GsaVectorDiagram(anchor, direction, doubleArrow, color)));
} else {
diagramLines.Add(new GsaDiagramGoo(new GsaLineDiagram(item, lengthScaleFactor, color)));
}
}

bool showAnnotations = true;
Expand All @@ -276,6 +307,7 @@ public class ResultDiagrams : GH_OasysDropDownComponent {

PostHog.Diagram("Result", result.CaseType, _selectedItems[0], type.ToString(), Parameters.EntityType.Element);
}

protected override void UpdateUIFromSelectedItems() {
if (_dropDownItems[0].Count == 2) {
_dropDownItems[0].Insert(0, "Displacement");
Expand Down Expand Up @@ -338,8 +370,10 @@ public class ResultDiagrams : GH_OasysDropDownComponent {
unitScaleFactor = UnitConverter.Convert(1, Pressure.BaseUnit, _stressUnit);
} else if (IsMoment()) {
unitScaleFactor = UnitConverter.Convert(1, Moment.BaseUnit, _momentUnit);
}else if (IsDisplacement()) {
} else if (IsTranslation()) {
unitScaleFactor = UnitConverter.Convert(1, Length.BaseUnit, _lengthUnit);
} else if (IsRotation()) {
unitScaleFactor = UnitConverter.Convert(1, Angle.BaseUnit, _angleUnit);
} else {
this.AddRuntimeError("Not supported diagramType!");
}
Expand Down Expand Up @@ -398,23 +432,34 @@ public class ResultDiagrams : GH_OasysDropDownComponent {
return isStress;
}

private bool IsDisplacement() {
bool isDisplacement = false;
private bool IsTranslation() {
bool isTranslation = false;
DiagramType type = GetDiagramType();
switch (type) {
case DiagramType.TranslationUx:
case DiagramType.TranslationUy:
case DiagramType.TranslationUz:
case DiagramType.ResolvedTranslationU:
isTranslation = true;
break;
}

return isTranslation;
}

private bool IsRotation() {
bool isRotation = false;
DiagramType type = GetDiagramType();
switch (type) {
case DiagramType.RotationRxx:
case DiagramType.RotationRyy:
case DiagramType.RotationRzz:
case DiagramType.ResolvedRotationR:
isDisplacement = true;
isRotation = true;
break;
}

return isDisplacement;
return isRotation;
}

private DiagramType GetDiagramType() {
Expand Down Expand Up @@ -463,5 +508,11 @@ public class ResultDiagrams : GH_OasysDropDownComponent {
ExpirePreview(true);
base.UpdateUI();
}

internal void UpdateAngle(string unit) {
_angleUnit = (AngleUnit)UnitsHelper.Parse(typeof(AngleUnit), unit);
ExpirePreview(true);
base.UpdateUI();
}
}
}
32 changes: 16 additions & 16 deletions GsaGH/Helpers/GsaAPI/Mappings.cs
Expand Up @@ -213,22 +213,22 @@ internal static class Mappings {

internal static readonly IList<DiagramTypeMapping> _diagramTypeMappingDisplacement
= new List<DiagramTypeMapping>() {
new DiagramTypeMapping("Translation Ux", DiagramType.TranslationUx,
ApiDiagramType.TranslationUx),
new DiagramTypeMapping("Translation Uy", DiagramType.TranslationUy,
ApiDiagramType.TranslationUy),
new DiagramTypeMapping("Translation Uz", DiagramType.TranslationUz,
ApiDiagramType.TranslationUz),
new DiagramTypeMapping("Res. Translation U", DiagramType.ResolvedTranslationU,
ApiDiagramType.ResolvedTranslationU),
new DiagramTypeMapping("Rotation Rxx", DiagramType.RotationRxx,
ApiDiagramType.RotationRxx),
new DiagramTypeMapping("Rotation Ryy", DiagramType.RotationRyy,
ApiDiagramType.RotationRyy),
new DiagramTypeMapping("Rotation Rzz", DiagramType.RotationRxx,
ApiDiagramType.RotationRzz),
new DiagramTypeMapping("Res. Rotation R", DiagramType.ResolvedRotationR,
ApiDiagramType.ResolvedRotationR),
new DiagramTypeMapping("Elem. Trans. Ux", DiagramType.TranslationUx,
ApiDiagramType.TranslationUx),
new DiagramTypeMapping("Elem. Trans. Uy", DiagramType.TranslationUy,
ApiDiagramType.TranslationUy),
new DiagramTypeMapping("Elem. Trans. Uz", DiagramType.TranslationUz,
ApiDiagramType.TranslationUz),
new DiagramTypeMapping("Res. Trans. U", DiagramType.ResolvedTranslationU,
ApiDiagramType.ResolvedTranslationU),
new DiagramTypeMapping("Elem. Rot. Rxx", DiagramType.RotationRxx,
ApiDiagramType.RotationRxx),
new DiagramTypeMapping("Elem. Rot. Ryy", DiagramType.RotationRyy,
ApiDiagramType.RotationRyy),
new DiagramTypeMapping("Elem. Rot. Rzz", DiagramType.RotationRxx,
ApiDiagramType.RotationRzz),
new DiagramTypeMapping("Res. Rot. R", DiagramType.ResolvedRotationR,
ApiDiagramType.ResolvedRotationR),
};

internal static readonly IList<DiagramTypeMapping> _diagramTypeMappingAssemblyDisplacement
Expand Down
1 change: 1 addition & 0 deletions GsaGH/Parameters/6_Display/GsaVectorDiagram.cs
Expand Up @@ -28,6 +28,7 @@ public override BoundingBox Boundingbox
internal GsaVectorDiagram(Point3d anchor, Vector3d direction, bool doubleArrow, Color color) {
AnchorPoint = anchor;
Direction = direction;
_doubleArrow = doubleArrow;

DisplayLine = CreateReactionForceLine(anchor, direction);
Value = direction;
Expand Down
22 changes: 6 additions & 16 deletions GsaGHTests/3_Components/6_Display/AssemblyResultDiagramsTests.cs
Expand Up @@ -11,17 +11,16 @@ namespace GsaGHTests.Components.Display {
public class AssemblyResultDiagramsTests {
[Fact]
public void UpdateForceTest() {
var comp = new ResultDiagrams();
var comp = new AssemblyResultDiagrams();
GsaResult result = GsaResultTests.AnalysisCaseResult(GsaFile.AssemblyByStorey, 1);
ComponentTestHelper.SetInput(comp, new GsaResultGoo(result));
comp.SetSelected(0, 1); // force
comp.SetSelected(0, 3); // Force
comp.SetSelected(1, 0); // Axial force
comp.UpdateForce("MN");
comp.Params.Output[0].CollectData();
Assert.Equal("MN", comp.Message);
}


[Fact]
public void UpdateLengthTest() {
var comp = new AssemblyResultDiagrams();
Expand All @@ -35,23 +34,14 @@ public class AssemblyResultDiagramsTests {

[Fact]
public void UpdateMomentTest() {
var comp = new ResultDiagrams();
var comp = new AssemblyResultDiagrams();
GsaResult result = GsaResultTests.AnalysisCaseResult(GsaFile.AssemblyByStorey, 1);
ComponentTestHelper.SetInput(comp, new GsaResultGoo(result));
comp.SetSelected(0, 1);
comp.UpdateMoment("MN·m");
comp.SetSelected(0, 3); // Force
comp.SetSelected(1, 4); // Moment Myy
comp.UpdateMoment("MN·m");
comp.Params.Output[0].CollectData();
Assert.Equal("MN·m", comp.Message);
}
[Fact]
public void UpdateStressTest() {
var comp = new ResultDiagrams();
GsaResult result = GsaResultTests.AnalysisCaseResult(GsaFile.AssemblyByStorey, 1);
ComponentTestHelper.SetInput(comp, new GsaResultGoo(result));
comp.SetSelected(0, 2);
comp.UpdateStress("mPa");
comp.Params.Output[0].CollectData();
Assert.Equal("mPa", comp.Message);
}
}
}
30 changes: 21 additions & 9 deletions GsaGHTests/3_Components/6_Display/ResultDiagramsTests.cs
Expand Up @@ -13,7 +13,7 @@ namespace GsaGHTests.Components.Display {
public class ResultDiagramsTests {
[Fact]
public void CombinationCaseWithMultiplePermutationsMessageTests() {
var caseResult = (GsaResult)GsaResultTests.CombinationCaseResult(GsaFile.SteelDesignComplex, 2, new List<int>() { 1, 2, 3, });
GsaResult caseResult = GsaResultTests.CombinationCaseResult(GsaFile.SteelDesignComplex, 2, new List<int>() { 1, 2, 3, });

var comp = new ResultDiagrams();
ComponentTestHelper.SetInput(comp, new GsaResultGoo(caseResult));
Expand All @@ -27,9 +27,9 @@ public class ResultDiagramsTests {
[Fact]
public void UpdateForceTest() {
var comp = new ResultDiagrams();
var result = (GsaResult)GsaResultTests.AnalysisCaseResult(GsaFile.SteelDesignComplex, 1);
GsaResult result = GsaResultTests.AnalysisCaseResult(GsaFile.SteelDesignComplex, 1);
ComponentTestHelper.SetInput(comp, new GsaResultGoo(result));
comp.SetSelected(0, 1); // force
comp.SetSelected(0, 1); // Force
comp.SetSelected(1, 0); // Axial force
comp.UpdateForce("MN");
comp.Params.Output[0].CollectData();
Expand All @@ -39,9 +39,9 @@ public class ResultDiagramsTests {
[Fact]
public void UpdateStressTest() {
var comp = new ResultDiagrams();
var result = (GsaResult)GsaResultTests.AnalysisCaseResult(GsaFile.SteelDesignComplex, 1);
GsaResult result = GsaResultTests.AnalysisCaseResult(GsaFile.SteelDesignComplex, 1);
ComponentTestHelper.SetInput(comp, new GsaResultGoo(result));
comp.SetSelected(0, 2); // stress
comp.SetSelected(0, 2); // Stress
comp.UpdateStress("kPa");
comp.Params.Output[0].CollectData();
Assert.Equal("kPa", comp.Message);
Expand All @@ -50,9 +50,9 @@ public class ResultDiagramsTests {
[Fact]
public void UpdateMomentTest() {
var comp = new ResultDiagrams();
var result = (GsaResult)GsaResultTests.AnalysisCaseResult(GsaFile.SteelDesignComplex, 1);
GsaResult result = GsaResultTests.AnalysisCaseResult(GsaFile.SteelDesignComplex, 1);
ComponentTestHelper.SetInput(comp, new GsaResultGoo(result));
comp.SetSelected(0, 1); // force
comp.SetSelected(0, 1); // Force
comp.UpdateMoment("MN·m");
comp.Params.Output[0].CollectData();
Assert.Equal("MN·m", comp.Message);
Expand All @@ -61,12 +61,24 @@ public class ResultDiagramsTests {
[Fact]
public void UpdateLengthTest() {
var comp = new ResultDiagrams();
var result = (GsaResult)GsaResultTests.AnalysisCaseResult(GsaFile.SteelDesignComplex, 1);
GsaResult result = GsaResultTests.AnalysisCaseResult(GsaFile.SteelDesignComplex, 1);
ComponentTestHelper.SetInput(comp, new GsaResultGoo(result));
comp.SetSelected(0, 0); // displacement
comp.SetSelected(0, 0); // Displacement
comp.UpdateLength("cm");
comp.Params.Output[0].CollectData();
Assert.Equal("cm", comp.Message);
}

[Fact]
public void UpdateAngleTest() {
var comp = new ResultDiagrams();
GsaResult result = GsaResultTests.AnalysisCaseResult(GsaFile.SteelDesignComplex, 1);
ComponentTestHelper.SetInput(comp, new GsaResultGoo(result));
comp.SetSelected(0, 0); // Displacement
comp.SetSelected(1, 4);
comp.UpdateAngle("rad");
comp.Params.Output[0].CollectData();
Assert.Equal("rad", comp.Message);
}
}
}
3 changes: 1 addition & 2 deletions GsaGHTests/3_Components/ComponentsTests.cs
Expand Up @@ -6,7 +6,6 @@
namespace GsaGHTests.Components {
[Collection("GrasshopperFixture collection")]
public class ComponentsTests {

[Theory]
// Model
[InlineData(typeof(CreateList), 1)]
Expand Down Expand Up @@ -142,7 +141,7 @@ public class ComponentsTests {
[InlineData(typeof(BeamForcesAndMoments), "All", "Min |Myz|")]
[InlineData(typeof(BeamStrainEnergyDensity), "All", "Min")]
[InlineData(typeof(Contour1dResults), "Displacement", "Steel Design")]
[InlineData(typeof(ResultDiagrams), "Displacement", "Stress")]
[InlineData(typeof(ResultDiagrams), "Force", "Stress")]
[InlineData(typeof(Contour2dResults), "Displacement", "Footfall")]
[InlineData(typeof(Element2dDisplacements), "All", "Min |R|")]
[InlineData(typeof(Element2dForcesAndMoments), "kN/m", "kipf/ft", 1)]
Expand Down

0 comments on commit e284bf9

Please sign in to comment.