Skip to content

Commit

Permalink
Task/gsagh 438 updated Elem2d Force and moments component (#592)
Browse files Browse the repository at this point in the history
* updated component Elem2d Forces and Moments

* fix
  • Loading branch information
DominikaLos authored Nov 29, 2023
1 parent 5413abf commit aadcdfb
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 100 deletions.
191 changes: 107 additions & 84 deletions GsaGH/Components/5_Results/Element2dForcesAndMoments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using GsaGH.Parameters.Results;
using GsaGH.Helpers.Import;

namespace GsaGH.Components {
/// <summary>
Expand All @@ -42,13 +45,13 @@ public Element2dForcesAndMoments() : base("Element 2D Forces and Moments", "Forc
public override void SetSelected(int i, int j) {
_selectedItems[i] = _dropDownItems[i][j];
switch (i) {
case 0:
case 1:
_forceUnit
= (ForcePerLengthUnit)UnitsHelper.Parse(typeof(ForcePerLengthUnit), _selectedItems[i]);
= (ForcePerLengthUnit)UnitsHelper.Parse(typeof(ForcePerLengthUnit), _selectedItems[1]);

Check warning on line 50 in GsaGH/Components/5_Results/Element2dForcesAndMoments.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/Element2dForcesAndMoments.cs#L50

Added line #L50 was not covered by tests
break;

case 1:
_momentUnit = (ForceUnit)UnitsHelper.Parse(typeof(ForceUnit), _selectedItems[i]);
case 2:
_momentUnit = (ForceUnit)UnitsHelper.Parse(typeof(ForceUnit), _selectedItems[2]);

Check warning on line 54 in GsaGH/Components/5_Results/Element2dForcesAndMoments.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/Element2dForcesAndMoments.cs#L54

Added line #L54 was not covered by tests
break;
}

Expand Down Expand Up @@ -96,13 +99,17 @@ public override void VariableParameterMaintenance() {

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

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

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

_dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.ForcePerLength));
_selectedItems.Add(ForcePerLength.GetAbbreviation(_forceUnit));

Expand Down Expand Up @@ -158,9 +165,14 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) {
}

protected override void SolveInternal(IGH_DataAccess da) {
var result = new GsaResult();
GsaResult2 result = null;
string elementlist = "All";

var ghTypes = new List<GH_ObjectWrapper>();
if (!da.GetDataList(0, ghTypes)) {
return;

Check warning on line 173 in GsaGH/Components/5_Results/Element2dForcesAndMoments.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/Element2dForcesAndMoments.cs#L173

Added line #L173 was not covered by tests
}

var outX = new DataTree<GH_UnitNumber>();
var outY = new DataTree<GH_UnitNumber>();
var outXy = new DataTree<GH_UnitNumber>();
Expand All @@ -172,19 +184,14 @@ protected override void SolveInternal(IGH_DataAccess da) {
var outWaxx = new DataTree<GH_UnitNumber>();
var outWayy = new DataTree<GH_UnitNumber>();

var ghTypes = new List<GH_ObjectWrapper>();
if (!da.GetDataList(0, ghTypes)) {
return;
}

foreach (GH_ObjectWrapper ghTyp in ghTypes) {
switch (ghTyp?.Value) {
case null:
this.AddRuntimeWarning("Input is null");
return;

case GsaResultGoo goo:
result = (GsaResult)goo.Value;
result = new GsaResult2((GsaResult)goo.Value);
elementlist = Inputs.GetElementListDefinition(this, da, 1, result.Model);
break;

Expand All @@ -193,97 +200,110 @@ protected override void SolveInternal(IGH_DataAccess da) {
return;
}

List<GsaResultsValues> vals
= result.Element2DForceValues(elementlist, _forceUnit, _momentUnit);
List<GsaResultsValues> valsShear = result.Element2DShearValues(elementlist, _forceUnit);
ReadOnlyCollection<int> elementIds = result.ElementIds(elementlist);
IEntity2dResultSubset<IEntity2dQuantity<IForce2d>, IForce2d, ResultTensor2InAxis<Entity2dExtremaKey>> forces
= result.Element2dForces.ResultSubset(elementIds);
IEntity2dResultSubset<IEntity2dQuantity<IShear2d>, IShear2d, ResultVector2<Entity2dExtremaKey>> shears = result.Element2dShearForces.ResultSubset(elementIds);
IEntity2dResultSubset<IEntity2dQuantity<IMoment2d>, IMoment2d, ResultTensor2AroundAxis<Entity2dExtremaKey>> moments = result.Element2dMoments.ResultSubset(elementIds);

List<int> permutations = result.SelectedPermutationIds ?? new List<int>() {
1,
};
if (permutations.Count == 1 && permutations[0] == -1) {
permutations = Enumerable.Range(1, vals.Count).ToList();
permutations = Enumerable.Range(1, forces.Subset.Values.First().Count).ToList();

Check warning on line 213 in GsaGH/Components/5_Results/Element2dForcesAndMoments.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/Element2dForcesAndMoments.cs#L213

Added line #L213 was not covered by tests
}

foreach (int perm in permutations) {
if (vals[perm - 1].XyzResults.Count == 0 & vals[perm - 1].XxyyzzResults.Count == 0) {
string acase = result.ToString().Replace('}', ' ').Replace('{', ' ');
this.AddRuntimeWarning("Case " + acase + " contains no Element2D results.");
continue;
}

Parallel.For(0, 3, thread => // split computation in three for xyz and xxyyzz and shear
{
if (_selectedItems[0] == ExtremaHelper.Elem2dForcesAndMoments[0]) {
Parallel.For(0, 3, thread => {
switch (thread) {
case 0: {
foreach (KeyValuePair<int, ConcurrentDictionary<int, GsaResultQuantity>> kvp in
vals[perm - 1].XyzResults) {
int elementId = kvp.Key;
ConcurrentDictionary<int, GsaResultQuantity> res = kvp.Value;
if (res.Count == 0) {
continue;
}

case 0:
foreach (KeyValuePair<int, Collection<IEntity2dQuantity<IForce2d>>> kvp in forces
.Subset) {
foreach (int p in permutations) {
var path = new GH_Path(result.CaseId,
result.SelectedPermutationIds == null ? 0 : perm, elementId);

outX.AddRange(res.Select(x => new GH_UnitNumber(x.Value.X.ToUnit(_forceUnit))),
path); // use ToUnit to capture changes in dropdown
outY.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Y.ToUnit(_forceUnit))),
path);
outXy.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Z.ToUnit(_forceUnit))),
path);
// Wood-Armer moment M*x is stored in .XYZ
outWaxx.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.Xyz.ToUnit(_momentUnit))), path);
result.SelectedPermutationIds == null ? 0 : p, kvp.Key);
outX.AddRange(
kvp.Value[p - 1].Results()
.Select(r => new GH_UnitNumber(r.Nx.ToUnit(_forceUnit))), path);
outY.AddRange(
kvp.Value[p - 1].Results()
.Select(r => new GH_UnitNumber(r.Ny.ToUnit(_forceUnit))), path);
outXy.AddRange(
kvp.Value[p - 1].Results()
.Select(r => new GH_UnitNumber(r.Nxy.ToUnit(_forceUnit))), path);
}

break;
}
case 1: {
foreach (KeyValuePair<int, ConcurrentDictionary<int, GsaResultQuantity>> kvp in
vals[perm - 1].XxyyzzResults) {
int elementId = kvp.Key;
ConcurrentDictionary<int, GsaResultQuantity> res = kvp.Value;
if (res.Count == 0) {
continue;
}

var path = new GH_Path(result.CaseId,
result.SelectedPermutationIds == null ? 0 : perm, elementId);
break;

outXx.AddRange(res.Select(x => new GH_UnitNumber(x.Value.X.ToUnit(_momentUnit))),
path); // always use [rad] units
outYy.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Y.ToUnit(_momentUnit))),
path);
outXxyy.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.Z.ToUnit(_momentUnit))), path);
// Wood-Armer moment M*y
outWayy.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.Xyz.ToUnit(_momentUnit))), path);
case 1:
foreach (KeyValuePair<int, Collection<IEntity2dQuantity<IShear2d>>> kvp in shears
.Subset) {
foreach (int p in permutations) {
var path = new GH_Path(result.CaseId,
result.SelectedPermutationIds == null ? 0 : p, kvp.Key);
outQx.AddRange(
kvp.Value[p - 1].Results()
.Select(r => new GH_UnitNumber(r.Qx.ToUnit(_forceUnit))), path);
outQy.AddRange(
kvp.Value[p - 1].Results()
.Select(r => new GH_UnitNumber(r.Qy.ToUnit(_forceUnit))), path);
}

break;
}
case 2: {
foreach (KeyValuePair<int, ConcurrentDictionary<int, GsaResultQuantity>> kvp in
valsShear[perm - 1].XyzResults) {
int elementId = kvp.Key;
ConcurrentDictionary<int, GsaResultQuantity> res = kvp.Value;

var path = new GH_Path(result.CaseId,
result.SelectedPermutationIds == null ? 0 : perm, elementId);
break;

outQx.AddRange(res.Select(x => new GH_UnitNumber(x.Value.X.ToUnit(_forceUnit))),
path); // always use [rad] units
outQy.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Y.ToUnit(_forceUnit))),
path);
case 2:
foreach (KeyValuePair<int, Collection<IEntity2dQuantity<IMoment2d>>> kvp in moments
.Subset) {
foreach (int p in permutations) {
var path = new GH_Path(result.CaseId,
result.SelectedPermutationIds == null ? 0 : p, kvp.Key);
outXx.AddRange(
kvp.Value[p - 1].Results()
.Select(r => new GH_UnitNumber(r.Mx.ToUnit(_momentUnit))), path);
outYy.AddRange(
kvp.Value[p - 1].Results()
.Select(r => new GH_UnitNumber(r.My.ToUnit(_momentUnit))), path);
outXxyy.AddRange(
kvp.Value[p - 1].Results()
.Select(r => new GH_UnitNumber(r.Mxy.ToUnit(_momentUnit))), path);
outWaxx.AddRange(
kvp.Value[p - 1].Results().Select(r
=> new GH_UnitNumber(r.WoodArmerX.ToUnit(_momentUnit))), path);
outWayy.AddRange(
kvp.Value[p - 1].Results().Select(r
=> new GH_UnitNumber(r.WoodArmerY.ToUnit(_momentUnit))), path);
}

break;
}

break;
}
});
} else {
Entity2dExtremaKey key = ExtremaHelper.Elem2dForcesAndMomentsExtremaKey(forces, moments, shears, _selectedItems[0]);

Check warning on line 284 in GsaGH/Components/5_Results/Element2dForcesAndMoments.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/Element2dForcesAndMoments.cs#L284

Added line #L284 was not covered by tests
if (key != null) {
IForce2d forceExtrema = forces.GetExtrema(key);

Check warning on line 286 in GsaGH/Components/5_Results/Element2dForcesAndMoments.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/Element2dForcesAndMoments.cs#L286

Added line #L286 was not covered by tests
int perm = result.CaseType == CaseType.AnalysisCase ? 0 : 1;
var path = new GH_Path(result.CaseId, key.Permutation + perm, key.Id);
outX.Add(new GH_UnitNumber(forceExtrema.Nx.ToUnit(_forceUnit)), path);
outY.Add(new GH_UnitNumber(forceExtrema.Ny.ToUnit(_forceUnit)), path);
outXy.Add(new GH_UnitNumber(forceExtrema.Nxy.ToUnit(_forceUnit)), path);

Check warning on line 291 in GsaGH/Components/5_Results/Element2dForcesAndMoments.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/Element2dForcesAndMoments.cs#L288-L291

Added lines #L288 - L291 were not covered by tests

IShear2d shearExtrema = shears.GetExtrema(key);
outQx.Add(new GH_UnitNumber(shearExtrema.Qx.ToUnit(_forceUnit)), path);
outQy.Add(new GH_UnitNumber(shearExtrema.Qy.ToUnit(_forceUnit)), path);

Check warning on line 295 in GsaGH/Components/5_Results/Element2dForcesAndMoments.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/Element2dForcesAndMoments.cs#L293-L295

Added lines #L293 - L295 were not covered by tests

IMoment2d momentExtrema = moments.GetExtrema(key);
outXx.Add(new GH_UnitNumber(momentExtrema.Mx.ToUnit(_momentUnit)), path);
outYy.Add(new GH_UnitNumber(momentExtrema.My.ToUnit(_momentUnit)), path);
outXxyy.Add(new GH_UnitNumber(momentExtrema.Mxy.ToUnit(_momentUnit)), path);
outWaxx.Add(new GH_UnitNumber(momentExtrema.My.ToUnit(_momentUnit)), path);
outWayy.Add(new GH_UnitNumber(momentExtrema.WoodArmerY.ToUnit(_momentUnit)), path);

Check warning on line 302 in GsaGH/Components/5_Results/Element2dForcesAndMoments.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/Element2dForcesAndMoments.cs#L297-L302

Added lines #L297 - L302 were not covered by tests
}
}

PostHog.Result(result.CaseType, 2, GsaResultsValues.ResultType.Force);
}

da.SetDataTree(0, outX);
Expand All @@ -294,16 +314,19 @@ List<GsaResultsValues> vals
da.SetDataTree(5, outXx);
da.SetDataTree(6, outYy);
da.SetDataTree(7, outXxyy);

PostHog.Result(result.CaseType, 2, GsaResultsValues.ResultType.Force);
da.SetDataTree(8, outWaxx);
da.SetDataTree(9, outWayy);
}

protected override void UpdateUIFromSelectedItems() {
if (_selectedItems.Count == 2) {
_spacerDescriptions.Insert(0, "Envelope");
_dropDownItems.Insert(0, ExtremaHelper.Elem2dForcesAndMoments.ToList());
_selectedItems.Insert(0, _dropDownItems[0][0]);
}
_forceUnit
= (ForcePerLengthUnit)UnitsHelper.Parse(typeof(ForcePerLengthUnit), _selectedItems[0]);
_momentUnit = (ForceUnit)UnitsHelper.Parse(typeof(ForceUnit), _selectedItems[1]);
= (ForcePerLengthUnit)UnitsHelper.Parse(typeof(ForcePerLengthUnit), _selectedItems[1]);
_momentUnit = (ForceUnit)UnitsHelper.Parse(typeof(ForceUnit), _selectedItems[2]);
base.UpdateUIFromSelectedItems();
}
}
Expand Down
50 changes: 40 additions & 10 deletions GsaGH/Components/5_Results/Helpers/ExtremaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,29 @@ internal static readonly ReadOnlyCollection<string> Vector3Translations
"Min |U|",
});

internal static readonly ReadOnlyCollection<string> Tensor2InAxis
internal static readonly ReadOnlyCollection<string> Elem2dForcesAndMoments
= new ReadOnlyCollection<string>(new[] {
"All",
"Max Nx",
"Max Ny",
"Max Nxy",
"Max Qx",
"Max Qy",
"Max Mx",
"Max My",
"Max Mxy",
"Max M*x",
"Max M*y",
"Min Nx",
"Min Ny",
"Min Nxy",
"Min Qx",
"Min Qy",
"Min Mx",
"Min My",
"Min Mxy",
"Min M*x",
"Min M*y",
});

internal static readonly ReadOnlyCollection<string> Tensor3Stresses
Expand Down Expand Up @@ -397,16 +411,32 @@ internal static U StressExtremaKey<T1, T2, U>(
};

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

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/Helpers/ExtremaHelper.cs#L398-L411

Added lines #L398 - L411 were not covered by tests
}

internal static U Force2dExtremaKey<T1, T2, U>(
IEntity2dResultSubset<T1, T2, ResultTensor2InAxis<U>> resultSet, string key)
where T1 : IEntity2dQuantity<T2> where T2 : IResultItem {
internal static U Elem2dForcesAndMomentsExtremaKey<T1, T2, T3, U>(
IEntity2dResultSubset<IEntity2dQuantity<T1>, T1, ResultTensor2InAxis<U>> resultSetForces,
IEntity2dResultSubset<IEntity2dQuantity<T2>, T2, ResultTensor2AroundAxis<U>> resultSetMoment,
IEntity2dResultSubset<IEntity2dQuantity<T3>, T3, ResultVector2<U>> resultSetShear,
string key) where T1 : IResultItem where T2 : IResultItem where T3 : IResultItem {
return key switch {
"Max Nx" => resultSet.Max.Nx,
"Max Ny" => resultSet.Max.Ny,
"Max Nxy" => resultSet.Max.Nxy,
"Min Nx" => resultSet.Min.Nx,
"Min Ny" => resultSet.Min.Ny,
"Min Nxy" => resultSet.Min.Nxy,
"Max Nx" => resultSetForces.Max.Nx,
"Max Ny" => resultSetForces.Max.Ny,
"Max Nxy" => resultSetForces.Max.Nxy,
"Min Nx" => resultSetForces.Min.Nx,
"Min Ny" => resultSetForces.Min.Ny,
"Min Nxy" => resultSetForces.Min.Nxy,
"Max Mx" => resultSetMoment.Max.Mx,
"Max My" => resultSetMoment.Max.My,
"Max Mxy" => resultSetMoment.Max.Mxy,
"Max M*x" => resultSetMoment.Max.WoodArmerX,
"Max M*y" => resultSetMoment.Max.WoodArmerY,
"Min Mx" => resultSetMoment.Min.Mx,
"Min My" => resultSetMoment.Min.My,
"Min Mxy" => resultSetMoment.Min.Mxy,
"Min M*x" => resultSetMoment.Min.WoodArmerX,
"Min M*y" => resultSetMoment.Min.WoodArmerY,
"Max Qx" => resultSetShear.Max.Qx,
"Max Qy" => resultSetShear.Max.Qy,
"Min Qx" => resultSetShear.Min.Qx,
"Min Qy" => resultSetShear.Min.Qy,
_ => throw new ArgumentException("Extrema case not found"),
};

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

View check run for this annotation

Codecov / codecov/patch

GsaGH/Components/5_Results/Helpers/ExtremaHelper.cs#L420-L441

Added lines #L420 - L441 were not covered by tests
}
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 @@ -48,7 +48,7 @@ public class ComponentsTests {
[InlineData(typeof(ResultDiagrams), 2)]
[InlineData(typeof(Contour2dResults), 2)]
[InlineData(typeof(Element2dDisplacements), 2)]
[InlineData(typeof(Element2dForcesAndMoments), 2)]
[InlineData(typeof(Element2dForcesAndMoments), 3)]
[InlineData(typeof(Element2dStresses), 2)]
[InlineData(typeof(Contour3dResults), 2)]
[InlineData(typeof(Element3dDisplacements), 2)]
Expand Down Expand Up @@ -126,7 +126,7 @@ public void WhenInitialiseDropdowns_ThenDropDownItems_ShouldBeNull(Type t) {
[InlineData(typeof(ResultDiagrams), "Force", "Stress")]
[InlineData(typeof(Contour2dResults), "Displacement", "Footfall")]
[InlineData(typeof(Element2dDisplacements), "All", "Min |R|")]
[InlineData(typeof(Element2dForcesAndMoments), "kN/m", "kipf/ft")]
[InlineData(typeof(Element2dForcesAndMoments), "kN/m", "kipf/ft", 1)]
[InlineData(typeof(Element2dStresses), "All", "Min zx")]
[InlineData(typeof(Contour3dResults), "Displacement", "Stress")]
[InlineData(typeof(Element3dDisplacements), "All", "Min |U|")]
Expand Down
4 changes: 2 additions & 2 deletions GsaGHTests/GsaGHTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Rhino.Inside" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit aadcdfb

Please sign in to comment.