Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/gsagh 438 updated Elem2d Force and moments component #592

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 101 additions & 94 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]);
break;

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

Expand Down Expand Up @@ -96,13 +99,18 @@ 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]);


kpne marked this conversation as resolved.
Show resolved Hide resolved
_dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.ForcePerLength));
_selectedItems.Add(ForcePerLength.GetAbbreviation(_forceUnit));

Expand Down Expand Up @@ -158,9 +166,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;
}

var outX = new DataTree<GH_UnitNumber>();
var outY = new DataTree<GH_UnitNumber>();
var outXy = new DataTree<GH_UnitNumber>();
Expand All @@ -172,19 +185,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 +201,91 @@ 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>> vals
= result.Element2dForces.ResultSubset(elementIds);
IEntity2dResultSubset<IEntity2dQuantity<IShear2d>, IShear2d, ResultVector2<Entity2dExtremaKey>> valsShear = result.Element2dShearForces.ResultSubset(elementIds);
IEntity2dResultSubset<IEntity2dQuantity<IMoment2d>, IMoment2d, ResultTensor2AroundAxis<Entity2dExtremaKey>> valsMoments = result.Element2dMoments.ResultSubset(elementIds);
kpne marked this conversation as resolved.
Show resolved Hide resolved

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, vals.Subset.Values.First().Count).ToList();
}

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;
if (_selectedItems[0] == ExtremaHelper.Vector6Displacements[0]) {
kpne marked this conversation as resolved.
Show resolved Hide resolved
foreach (KeyValuePair<int, Collection<IEntity2dQuantity<IForce2d>>> kvp in vals.Subset) {
foreach (int p in permutations) {
var path = new GH_Path(result.CaseId, 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);
}
}

Parallel.For(0, 3, thread => // split computation in three for xyz and xxyyzz and shear
kpne marked this conversation as resolved.
Show resolved Hide resolved
{
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;
}

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);
}

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);

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);
}

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);

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);
}

break;
}
foreach (KeyValuePair<int, Collection<IEntity2dQuantity<IShear2d>>> kvp in valsShear.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);
}
});
}
foreach (KeyValuePair<int, Collection<IEntity2dQuantity<IMoment2d>>> kvp in valsMoments.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);
}
}
} else {
Entity2dExtremaKey forceKey = ExtremaHelper.Force2dExtremaKey(vals, _selectedItems[0]);
if (forceKey != null) {
kpne marked this conversation as resolved.
Show resolved Hide resolved
IForce2d extrema = vals.GetExtrema(forceKey);
int perm = result.CaseType == CaseType.AnalysisCase ? 0 : 1;
var path = new GH_Path(result.CaseId, forceKey.Permutation + perm, forceKey.Id);
outX.Add(new GH_UnitNumber(extrema.Nx.ToUnit(_forceUnit)), path);
outY.Add(new GH_UnitNumber(extrema.Ny.ToUnit(_forceUnit)), path);
outXy.Add(new GH_UnitNumber(extrema.Nxy.ToUnit(_forceUnit)), path);
}

Entity2dExtremaKey shearKey
= ExtremaHelper.ShearForce2dExtremaKey(valsShear, _selectedItems[0]);
if (shearKey != null) {
IShear2d extrema = valsShear.GetExtrema(shearKey);
int perm = result.CaseType == CaseType.AnalysisCase ? 0 : 1;
var path = new GH_Path(result.CaseId, shearKey.Permutation + perm, shearKey.Id);
outQx.Add(new GH_UnitNumber(extrema.Qx.ToUnit(_forceUnit)), path);
outQy.Add(new GH_UnitNumber(extrema.Qy.ToUnit(_forceUnit)), path);
}

Entity2dExtremaKey momentKey
= ExtremaHelper.Moment2dExtremaKey(valsMoments, _selectedItems[0]);
if (momentKey != null) {
IMoment2d extrema = valsMoments.GetExtrema(momentKey);
int perm = result.CaseType == CaseType.AnalysisCase ? 0 : 1;
var path = new GH_Path(result.CaseId, momentKey.Permutation + perm, momentKey.Id);
outXx.Add(new GH_UnitNumber(extrema.Mx.ToUnit(_momentUnit)), path);
outYy.Add(new GH_UnitNumber(extrema.My.ToUnit(_momentUnit)), path);
outXxyy.Add(new GH_UnitNumber(extrema.Mxy.ToUnit(_momentUnit)), path);
outWaxx.Add(new GH_UnitNumber(extrema.My.ToUnit(_momentUnit)), path);
outWayy.Add(new GH_UnitNumber(extrema.WoodArmerY.ToUnit(_momentUnit)), path);
}
}

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

da.SetDataTree(0, outX);
Expand All @@ -301,9 +303,14 @@ List<GsaResultsValues> vals
}

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
44 changes: 43 additions & 1 deletion 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 @@ -410,5 +424,33 @@ internal static U Force2dExtremaKey<T1, T2, U>(
_ => throw new ArgumentException("Extrema case not found"),
};
}
internal static U Moment2dExtremaKey<T1, T2, U>(
IEntity2dResultSubset<T1, T2, ResultTensor2AroundAxis<U>> resultSet, string key)
where T1 : IEntity2dQuantity<T2> where T2 : IResultItem {
return key switch {
"Max Mx" => resultSet.Max.Mx,
"Max My" => resultSet.Max.My,
"Max Mxy" => resultSet.Max.Mxy,
"Max WoodArmerX" => resultSet.Max.WoodArmerX,
"Max WoodArmerY" => resultSet.Max.WoodArmerY,
"Min Mx" => resultSet.Min.Mx,
"Min My" => resultSet.Min.My,
"Min Mxy" => resultSet.Min.Mxy,
"Min WoodArmerX" => resultSet.Min.WoodArmerX,
"Min WoodArmerY" => resultSet.Min.WoodArmerY,
_ => throw new ArgumentException("Extrema case not found"),
};
}
internal static U ShearForce2dExtremaKey<T1, T2, U>(
IEntity2dResultSubset<T1, T2, ResultVector2<U>> resultSet, string key)
where T1 : IEntity2dQuantity<T2> where T2 : IResultItem {
return key switch {
"Max Qx" => resultSet.Max.Qx,
"Max Qy" => resultSet.Max.Qy,
"Min Qx" => resultSet.Min.Qx,
"Min Qy" => resultSet.Min.Qy,
_ => throw new ArgumentException("Extrema case not found"),
};
}
}
}
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