Skip to content

Commit

Permalink
GsaGH-435 1d contour update (#595)
Browse files Browse the repository at this point in the history
* updated component Elem2d Forces and Moments

* fix

* fix extrema helper

* wip

* wip

* fix footfall

* fix unit tests

* fix deserialisation

* #595 (comment)

---------

Co-authored-by: DominikaLos <[email protected]>
  • Loading branch information
kpne and DominikaLos authored Nov 29, 2023
1 parent aadcdfb commit a208e5b
Show file tree
Hide file tree
Showing 9 changed files with 590 additions and 376 deletions.
803 changes: 457 additions & 346 deletions GsaGH/Components/6_Display/Contour1dResults.cs

Large diffs are not rendered by default.

13 changes: 2 additions & 11 deletions GsaGH/Components/6_Display/Contour3dResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ private enum FoldMode {
private List<string> _legendValues;
private List<int> _legendValuesPosY;
private LengthUnit _lengthResultUnit = DefaultUnits.LengthUnitResult;
private LengthUnit _lengthUnit = DefaultUnits.LengthUnitGeometry;
private double _maxValue = 1000;
private double _minValue;
private FoldMode _mode = FoldMode.Displacement;
Expand Down Expand Up @@ -148,7 +147,6 @@ public override bool Read(GH_IReader reader) {
_legendScale = reader.GetDouble("legendScale");
}

_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), reader.GetString("model"));
_lengthResultUnit
= (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), reader.GetString("length"));
_stressUnitResult
Expand Down Expand Up @@ -260,7 +258,6 @@ public override bool Write(GH_IWriter writer) {
writer.SetDouble("val", _defScale);
writer.SetDouble("legendScale", _legendScale);
writer.SetBoolean("legend", _showLegend);
writer.SetString("model", Length.GetAbbreviation(_lengthUnit));
writer.SetString("length", Length.GetAbbreviation(_lengthResultUnit));
writer.SetString("stress", Pressure.GetAbbreviation(_stressUnitResult));
return base.Write(writer);
Expand Down Expand Up @@ -413,6 +410,7 @@ protected override void SolveInternal(IGH_DataAccess da) {
this.AddRuntimeError($"Model contains no results for elements in list '{elementlist}'");
return;

Check warning on line 411 in GsaGH/Components/6_Display/Contour3dResults.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/6_Display/Contour3dResults.cs#L410-L411

Added lines #L410 - L411 were not covered by tests
};
LengthUnit lengthUnit = result.Model.ModelUnit;

var ghColours = new List<GH_Colour>();
var colors = new List<Color>();
Expand Down Expand Up @@ -471,7 +469,7 @@ protected override void SolveInternal(IGH_DataAccess da) {
dmin = displacements.GetExtrema(displacements.Min.Xyz).Xyz.As(_lengthResultUnit);
translationSelector = (r) => r.Xyz.ToUnit(_lengthResultUnit);
valuesXyz = ResultsUtility.GetResultResultanTranslation(
displacements.Subset, _lengthUnit, permutation);
displacements.Subset, lengthUnit, permutation);
break;
}

Expand Down Expand Up @@ -551,7 +549,6 @@ protected override void SolveInternal(IGH_DataAccess da) {
values.AsParallel().AsOrdered();
var verticies = new ConcurrentDictionary<int, Point3dList>();
verticies.AsParallel().AsOrdered();
LengthUnit lengthUnit = result.Model.ModelUnit;

Parallel.ForEach(elems.Keys, key => {
Element element = elems[key];
Expand Down Expand Up @@ -779,12 +776,6 @@ internal void UpdateLength(string unit) {
base.UpdateUI();
}

internal void UpdateModel(string unit) {
_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), unit);
ExpirePreview(true);
base.UpdateUI();
}

internal void UpdateStress(string unit) {
_stressUnitResult = (PressureUnit)UnitsHelper.Parse(typeof(PressureUnit), unit);
ExpirePreview(true);
Expand Down
4 changes: 1 addition & 3 deletions GsaGH/Components/6_Display/ContourNodeResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,7 @@ protected override void SolveInternal(IGH_DataAccess da) {
_resType = string.Empty;

var ghTyp = new GH_ObjectWrapper();
if (!da.GetData(0, ref ghTyp)) {
return;
}
da.GetData(0, ref ghTyp);

switch (ghTyp?.Value) {
case GsaResultGoo goo:
Expand Down
42 changes: 42 additions & 0 deletions GsaGH/Helpers/Quarterion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using GsaAPI;
using GsaGH.Parameters;
using GsaGH.Parameters.Results;
using Rhino.Geometry;
using System;
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;

namespace GsaGH.Helpers {
public static class Quarterion {
internal static Entity1dDisplacements CoordinateTransformationTo(ConcurrentDictionary<int, Collection<IEntity1dDisplacement>> displacementSubset, Plane plane, Model model) {
var values = new ConcurrentDictionary<int, Collection<IEntity1dDisplacement>>();
Parallel.ForEach(displacementSubset, kvp => {
var localAxes = new LocalAxes(model.ElementDirectionCosine(kvp.Key));
var local = new Plane(Point3d.Origin, localAxes.X, localAxes.Y);
var q = Quaternion.Rotation(plane, local);
q.GetRotation(out double angle, out Vector3d axis);
if (angle > Math.PI) {
angle -= 2 * Math.PI;
}

var permutationResults = new Collection<IEntity1dDisplacement>();
foreach (IEntity1dDisplacement permutation in kvp.Value) {
var results = new Collection<Double6>();
foreach (IDisplacement result in permutation.Results.Values) {
var d = new Point3d(result.X.Meters, result.Y.Meters, result.Z.Meters);
d.Transform(Transform.Rotation(angle, axis, Point3d.Origin));
var r = new Point3d(result.Xx.Radians, result.Yy.Radians, result.Zz.Radians);
r.Transform(Transform.Rotation(angle, axis, Point3d.Origin));
results.Add(new Double6(d.X, d.Y, d.Z, r.X, r.Y, r.Z));
}
permutationResults.Add(new Entity1dDisplacement(new ReadOnlyCollection<Double6>(results),
new ReadOnlyCollection<double>(permutation.Results.Keys.ToList())));
}
values.TryAdd(kvp.Key, permutationResults);
});
return new Entity1dDisplacements(values);
}
}
}
33 changes: 33 additions & 0 deletions GsaGH/Parameters/5_Results/4_Subsets/Entity1dResultsUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using OasysUnits;
using OasysUnits.Units;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;

namespace GsaGH.Parameters.Results {
public static partial class ResultsUtility {
public static ConcurrentDictionary<int, List<IQuantity>> GetResultComponent<T1, T2>(
ConcurrentDictionary<int, Collection<T1>> subset, Func<T2, IQuantity> selector, int permutation = 0)
where T1 : IEntity1dQuantity<T2> where T2 : IResultItem {
var vals = new ConcurrentDictionary<int, List<IQuantity>>();
Parallel.ForEach(subset, kvp =>
vals.TryAdd(kvp.Key, kvp.Value[permutation].Results.Values.Select(selector).ToList()));
return vals;
}

public static ConcurrentDictionary<int, (List<double> x, List<double> y, List<double> z)> GetResultResultanTranslation(
ConcurrentDictionary<int, Collection<IEntity1dDisplacement>> subset, LengthUnit unit, int permutation = 0) {
var vals = new ConcurrentDictionary<int, (List<double> x, List<double> y, List<double> z)>();
Parallel.ForEach(subset, kvp =>
vals.TryAdd(kvp.Key, (
kvp.Value[permutation].Results.Values.Select(r => r.X.As(unit)).ToList(),
kvp.Value[permutation].Results.Values.Select(r => r.Y.As(unit)).ToList(),
kvp.Value[permutation].Results.Values.Select(r => r.Z.As(unit)).ToList()
)));
return vals;
}
}
}
40 changes: 40 additions & 0 deletions GsaGH/Parameters/5_Results/4_Subsets/ResultsUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using GsaAPI;
using OasysUnits;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;

namespace GsaGH.Parameters.Results {
public static partial class ResultsUtility {
internal static (ConcurrentDictionary<int, List<IQuantity>> values, ICollection<int> nodeIds)
MapNodeResultToElements<T1, T2>(
ReadOnlyDictionary<int, Element> elements, INodeResultCache<T1, T2> nodeResultsCache,
Func<T1, IQuantity> selector, int permutation = 0) where T1 : IResultItem {
var vals = new ConcurrentDictionary<int, List<IQuantity>>();
var topology = new ConcurrentBag<int>();
Parallel.ForEach(elements, kvp => {
var list = new List<IQuantity>();
IDictionary<int, Collection<T1>> subset = nodeResultsCache.ResultSubset(kvp.Value.Topology).Subset;
if (subset.Count == 0) {
return;

Check warning on line 22 in GsaGH/Parameters/5_Results/4_Subsets/ResultsUtility.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Parameters/5_Results/4_Subsets/ResultsUtility.cs#L22

Added line #L22 was not covered by tests
}

foreach (int nodeId in kvp.Value.Topology) {
list.Add(subset[nodeId].Select(selector).ElementAt(permutation));
topology.Add(nodeId);
}

if (kvp.Value.Topology.Count > 2) {
list.Add(list.Average(list[0].Unit));
}

vals.TryAdd(kvp.Key, list);
});

return (vals, topology.Distinct().ToList());
}
}
}
4 changes: 1 addition & 3 deletions GsaGH/Parameters/5_Results/GsaResultsValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ internal void CoordinateTransformationTo(Plane plane, Model model) {
// create quaternion from two planes
var q = Quaternion.Rotation(plane, local);

double angle = new double();
var axis = new Vector3d();
q.GetRotation(out angle, out axis);
q.GetRotation(out double angle, out Vector3d axis);

Check warning on line 67 in GsaGH/Parameters/5_Results/GsaResultsValues.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Parameters/5_Results/GsaResultsValues.cs#L67

Added line #L67 was not covered by tests

if (angle > Math.PI) {
angle -= 2 * Math.PI;
Expand Down
20 changes: 14 additions & 6 deletions GsaGHTests/3_Components/6_Display/Contour1dResultsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ public void DefaultDropSelectionsTest() {
Assert.Equal("Moment Myy", comp._selectedItems[1]);

comp.SetSelected(0, 2);
Assert.Equal("Stress", comp._selectedItems[0]);
Assert.Equal("Combined, C1", comp._selectedItems[1]);

comp.SetSelected(0, 3);
Assert.Equal("Derived Stress", comp._selectedItems[0]);
Assert.Equal("Von Mises", comp._selectedItems[1]);

comp.SetSelected(0, 4);
Assert.Equal("Strain Energy", comp._selectedItems[0]);
Assert.Equal("Average", comp._selectedItems[1]);

comp.SetSelected(0, 3);
comp.SetSelected(0, 5);
Assert.Equal("Footfall", comp._selectedItems[0]);
Assert.Equal("Resonant", comp._selectedItems[1]);

Expand Down Expand Up @@ -80,7 +88,7 @@ public void DrawViewportMeshesAndWiresTest() {
public void DrawViewportMeshesAndWiresFootfallTest() {
var comp = new Contour1dResults();
ComponentTestHelper.SetInput(comp, GsaResultTests.NodeAndElement1dFootfallResultsMother());
SetSelectedDrawViewportMeshesAndWiresTest(comp, 0, 3);
SetSelectedDrawViewportMeshesAndWiresTest(comp, 0, 5);
SetSelectedDrawViewportMeshesAndWiresTest(comp, 1, 0);
SetSelectedDrawViewportMeshesAndWiresTest(comp, 1, 1);
}
Expand All @@ -107,17 +115,17 @@ public void UpdateLengthTest() {
}

[Fact]
public void UpdateModelTest() {
public void UpdateMomentTest() {
var comp = new Contour1dResults();
ComponentTestHelper.SetInput(comp, GsaResultTests.NodeAndElement1dCombinationResultsMother());
comp.UpdateModel("mm");
comp.UpdateMoment("N·cm");
}

[Fact]
public void UpdateMomentTest() {
public void UpdateStressTest() {
var comp = new Contour1dResults();
ComponentTestHelper.SetInput(comp, GsaResultTests.NodeAndElement1dCombinationResultsMother());
comp.UpdateMoment("N·cm");
comp.UpdateStress("MPa");
}

[Fact]
Expand Down
7 changes: 0 additions & 7 deletions GsaGHTests/3_Components/6_Display/Contour3dResultsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ public void UpdateLengthTest() {
comp.UpdateLength("mm");
}

[Fact]
public void UpdateModelTest() {
var comp = new Contour3dResults();
ComponentTestHelper.SetInput(comp, GsaResultTests.NodeAndElement3dCombinationResultsMother());
comp.UpdateModel("mm");
}

[Fact]
public void UpdateStressTest() {
var comp = new Contour3dResults();
Expand Down

0 comments on commit a208e5b

Please sign in to comment.