Skip to content

Commit

Permalink
GsaGH-407 extrema node displacement (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpne authored Oct 27, 2023
2 parents fbdc8e7 + f68ae29 commit 328a412
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 21 deletions.
49 changes: 49 additions & 0 deletions GsaGH/Components/5_Results/Helpers/ExtremaHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using GsaGH.Parameters.Results;
using System.Collections.ObjectModel;

namespace GsaGH.Components.Helpers {
internal class ExtremaHelper {
internal static readonly ReadOnlyCollection<string> Vector6Displacements = new ReadOnlyCollection<string>(new[] {
"All",
"Max Ux",
"Max Uy",
"Max Uz",
"Max |U|",
"Max Rxx",
"Max Ryy",
"Max Rzz",
"Max |R|",
"Min Ux",
"Min Uy",
"Min Uz",
"Min |U|",
"Min Rxx",
"Min Ryy",
"Min Rzz",
"Min |R|",
});

internal static U ExtremaKey<T, U>(INodeResultSubset<T, ResultVector6<U>> resultSet, string key)
where T : IResultItem {
return key switch {
"Max Ux" => resultSet.Max.X,
"Max Uy" => resultSet.Max.Y,
"Max Uz" => resultSet.Max.Z,
"Max |U|" => resultSet.Max.Xyz,
"Max Rxx" => resultSet.Max.Xx,
"Max Ryy" => resultSet.Max.Yy,
"Max Rzz" => resultSet.Max.Zz,
"Max |R|" => resultSet.Max.Xxyyzz,
"Min Ux" => resultSet.Min.X,
"Min Uy" => resultSet.Min.Y,
"Min Uz" => resultSet.Min.Z,
"Min |U|" => resultSet.Min.Xyz,
"Min Rxx" => resultSet.Min.Xx,
"Min Ryy" => resultSet.Min.Yy,
"Min Rzz" => resultSet.Min.Zz,
"Min |R|" => resultSet.Min.Xxyyzz,
_ => throw new System.ArgumentException("Extrema case not found"),
};

Check warning on line 46 in GsaGH/Components/5_Results/Helpers/ExtremaHelper.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/Helpers/ExtremaHelper.cs#L29-L46

Added lines #L29 - L46 were not covered by tests
}
}
}
58 changes: 41 additions & 17 deletions GsaGH/Components/5_Results/NodeDisplacements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public NodeDisplacements() : base("Node Displacements", "NodeDisp",

public override void SetSelected(int i, int j) {
_selectedItems[i] = _dropDownItems[i][j];
_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), _selectedItems[i]);
_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), _selectedItems[1]);
base.UpdateUI();
}

Expand All @@ -56,12 +56,16 @@ public override void VariableParameterMaintenance() {

protected override void InitialiseDropdowns() {
_spacerDescriptions = new List<string>(new[] {
"Type",
"Unit",
});

_dropDownItems = new List<List<string>>();
_selectedItems = new List<string>();

_dropDownItems.Add(ExtremaHelper.Vector6Displacements.ToList());
_selectedItems.Add(_dropDownItems[0][0]);

_dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Length));
_selectedItems.Add(Length.GetAbbreviation(_lengthUnit));

Expand All @@ -77,7 +81,6 @@ protected override void RegisterInputParams(GH_InputParamManager pManager) {

protected override void RegisterOutputParams(GH_OutputParamManager pManager) {
string unitAbbreviation = Length.GetAbbreviation(_lengthUnit);

string note = ResultNotes.NoteNodeResults;

pManager.AddGenericParameter("Translations X [" + unitAbbreviation + "]", "Ux",
Expand Down Expand Up @@ -126,7 +129,7 @@ protected override void SolveInternal(IGH_DataAccess da) {
}

ReadOnlyCollection<int> nodeIds = result.NodeIds(nodeList);
INodeResultSubset<IDisplacement, ResultVector6<NodeExtremaKey>> resultSet =
INodeResultSubset<IDisplacement, ResultVector6<NodeExtremaKey>> resultSet =
result.NodeDisplacements.ResultSubset(nodeIds);

List<int> permutations = result.SelectedPermutationIds ?? new List<int>() {
Expand All @@ -146,20 +149,35 @@ protected override void SolveInternal(IGH_DataAccess da) {
var outRotXyz = new DataTree<GH_UnitNumber>();
var outIDs = new DataTree<int>();

Parallel.ForEach(resultSet.Subset, kvp => {
foreach (int p in permutations) {
var path = new GH_Path(result.CaseId, result.SelectedPermutationIds == null ? 0 : p);
outTransX.Add(new GH_UnitNumber(kvp.Value[p - 1].X.ToUnit(_lengthUnit)), path);
outTransY.Add(new GH_UnitNumber(kvp.Value[p - 1].Y.ToUnit(_lengthUnit)), path);
outTransZ.Add(new GH_UnitNumber(kvp.Value[p - 1].Z.ToUnit(_lengthUnit)), path);
outTransXyz.Add(new GH_UnitNumber(kvp.Value[p - 1].Xyz.ToUnit(_lengthUnit)), path);
outRotX.Add(new GH_UnitNumber(kvp.Value[p - 1].Xx), path);
outRotY.Add(new GH_UnitNumber(kvp.Value[p - 1].Yy), path);
outRotZ.Add(new GH_UnitNumber(kvp.Value[p - 1].Zz), path);
outRotXyz.Add(new GH_UnitNumber(kvp.Value[p - 1].Xxyyzz), path);
outIDs.Add(kvp.Key, path);
if (_selectedItems[0] == ExtremaHelper.Vector6Displacements[0]) {
foreach (KeyValuePair<int, Collection<IDisplacement>> kvp in resultSet.Subset) {
foreach (int p in permutations) {
var path = new GH_Path(result.CaseId, result.SelectedPermutationIds == null ? 0 : p);
outTransX.Add(new GH_UnitNumber(kvp.Value[p - 1].X.ToUnit(_lengthUnit)), path);
outTransY.Add(new GH_UnitNumber(kvp.Value[p - 1].Y.ToUnit(_lengthUnit)), path);
outTransZ.Add(new GH_UnitNumber(kvp.Value[p - 1].Z.ToUnit(_lengthUnit)), path);
outTransXyz.Add(new GH_UnitNumber(kvp.Value[p - 1].Xyz.ToUnit(_lengthUnit)), path);
outRotX.Add(new GH_UnitNumber(kvp.Value[p - 1].Xx), path);
outRotY.Add(new GH_UnitNumber(kvp.Value[p - 1].Yy), path);
outRotZ.Add(new GH_UnitNumber(kvp.Value[p - 1].Zz), path);
outRotXyz.Add(new GH_UnitNumber(kvp.Value[p - 1].Xxyyzz), path);
outIDs.Add(kvp.Key, path);
}
}
});
} else {
NodeExtremaKey key = ExtremaHelper.ExtremaKey(resultSet, _selectedItems[0]);
IDisplacement extrema = resultSet.GetExtrema(key);
var path = new GH_Path(result.CaseId, key.Permutation);
outTransX.Add(new GH_UnitNumber(extrema.X.ToUnit(_lengthUnit)), path);
outTransY.Add(new GH_UnitNumber(extrema.Y.ToUnit(_lengthUnit)), path);
outTransZ.Add(new GH_UnitNumber(extrema.Z.ToUnit(_lengthUnit)), path);
outTransXyz.Add(new GH_UnitNumber(extrema.Xyz.ToUnit(_lengthUnit)), path);
outRotX.Add(new GH_UnitNumber(extrema.Xx), path);
outRotY.Add(new GH_UnitNumber(extrema.Yy), path);
outRotZ.Add(new GH_UnitNumber(extrema.Zz), path);
outRotXyz.Add(new GH_UnitNumber(extrema.Xxyyzz), path);
outIDs.Add(key.Id, path);

Check warning on line 179 in GsaGH/Components/5_Results/NodeDisplacements.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/NodeDisplacements.cs#L168-L179

Added lines #L168 - L179 were not covered by tests
}

da.SetDataTree(0, outTransX);
da.SetDataTree(1, outTransY);
Expand All @@ -176,7 +194,13 @@ protected override void SolveInternal(IGH_DataAccess da) {
}

protected override void UpdateUIFromSelectedItems() {
_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), _selectedItems[0]);
if (_selectedItems.Count == 1) {
_spacerDescriptions.Insert(0, "Type");
_dropDownItems.Insert(0, ExtremaHelper.Vector6Displacements.ToList());
_selectedItems.Insert(0, _dropDownItems[0][0]);
}

_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), _selectedItems[1]);
base.UpdateUIFromSelectedItems();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using OasysUnits;

namespace GsaGH.Parameters.Results {
public static class NodeExtremaKeyUtility {
public static class ExtremaKeyUtility {
public static (ResultVector6<NodeExtremaKey> Max, ResultVector6<NodeExtremaKey> Min) Extrema<T>(
this IDictionary<int, Collection<T>> subset) {

Expand All @@ -22,6 +22,11 @@ public static (ResultVector6<NodeExtremaKey> Max, ResultVector6<NodeExtremaKey>
UpdateExtrema<IDisplacement, Length, Angle>(displacement, nodeId, permutation,
ref maxValue, ref minValue, ref maxKey, ref minKey);
break;

case IInternalForce internalForce:
UpdateExtrema<IInternalForce, Force, Moment>(internalForce, nodeId, permutation,
ref maxValue, ref minValue, ref maxKey, ref minKey);

Check warning on line 28 in GsaGH/Parameters/5_Results/5_Extrema/ExtremaKeyUtility.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Parameters/5_Results/5_Extrema/ExtremaKeyUtility.cs#L27-L28

Added lines #L27 - L28 were not covered by tests
break;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Parameters/5_Results/5_Extrema/ResultVector6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ResultVector6() {
}

public ResultVector6(T initialValue) {
X = initialValue;
X = initialValue;
Y = initialValue;
Z = initialValue;
Xyz = initialValue;
Expand Down
4 changes: 2 additions & 2 deletions GsaGHTests/3_Components/ComponentsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class ComponentsTests {
[InlineData(typeof(Element3dStresses), 1)]
[InlineData(typeof(GlobalPerformanceResults), 3)]
[InlineData(typeof(ContourNodeResults), 2)]
[InlineData(typeof(NodeDisplacements), 1)]
[InlineData(typeof(NodeDisplacements), 2)]
[InlineData(typeof(ReactionForces), 2)]
[InlineData(typeof(ReactionForceDiagrams), 1)]
[InlineData(typeof(SelectResult), 2)]
Expand Down Expand Up @@ -130,7 +130,7 @@ public void WhenInitialiseDropdowns_ThenDropDownItems_ShouldBeNull(Type t) {
[InlineData(typeof(Element3dStresses), "MPa", "kipf/ft²")]
[InlineData(typeof(GlobalPerformanceResults), "t", "slug")]
[InlineData(typeof(ContourNodeResults), "Displacement", "Footfall")]
[InlineData(typeof(NodeDisplacements), "mm", "ft")]
[InlineData(typeof(NodeDisplacements), "All", "Min |R|")]
[InlineData(typeof(ReactionForces), "kN", "tf")]
[InlineData(typeof(ReactionForceDiagrams), "Resolved |F|", "Resolved |M|")]
[InlineData(typeof(SelectResult), "AnalysisCase", "Combination")]
Expand Down

0 comments on commit 328a412

Please sign in to comment.