Skip to content

Commit

Permalink
GsaGH-366 Results Refactor Epic (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpne authored Nov 13, 2023
2 parents 84693af + ba12949 commit 532c01a
Show file tree
Hide file tree
Showing 133 changed files with 7,477 additions and 563 deletions.
1 change: 0 additions & 1 deletion GsaGH/Components/1_Properties/Create2dProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using OasysGH;
using OasysGH.Components;
using OasysGH.Helpers;
using OasysGH.Parameters;
using OasysGH.Units;
using OasysGH.Units.Helpers;
using OasysUnits;
Expand Down
160 changes: 73 additions & 87 deletions GsaGH/Components/5_Results/BeamDisplacements.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -12,6 +13,7 @@
using GsaGH.Helpers;
using GsaGH.Helpers.GH;
using GsaGH.Parameters;
using GsaGH.Parameters.Results;
using GsaGH.Properties;
using OasysGH;
using OasysGH.Components;
Expand Down Expand Up @@ -40,7 +42,7 @@ public BeamDisplacements() : base("Beam Displacements", "BeamDisp",

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 @@ -55,12 +57,16 @@ public override void VariableParameterMaintenance() {

protected override void InitialiseDropdowns() {
_spacerDescriptions = new List<string>(new[] {
"Envelope",
"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 @@ -78,7 +84,6 @@ protected override void RegisterInputParams(GH_InputParamManager pManager) {

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

string note = ResultNotes.Note1dResults;

pManager.AddGenericParameter("Translations X [" + unitAbbreviation + "]", "Ux",
Expand All @@ -100,15 +105,16 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) {
}

protected override void SolveInternal(IGH_DataAccess da) {
var result = new GsaResult();

GsaResult2 result;
string elementlist = "All";

var ghDivisions = new GH_Integer();
da.GetData(2, ref ghDivisions);
GH_Convert.ToInt32(ghDivisions, out int positionsCount, GH_Conversion.Both);
positionsCount = Math.Abs(positionsCount) + 2; // taken absolute value and add 2 end points.

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

var outTransX = new DataTree<GH_UnitNumber>();
var outTransY = new DataTree<GH_UnitNumber>();
var outTransZ = new DataTree<GH_UnitNumber>();
Expand All @@ -118,95 +124,71 @@ protected override void SolveInternal(IGH_DataAccess da) {
var outRotZ = new DataTree<GH_UnitNumber>();
var outRotXyz = new DataTree<GH_UnitNumber>();

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

foreach (GH_ObjectWrapper ghTyp in ghTypes) {
if (ghTyp?.Value == null) {
this.AddRuntimeWarning("Input is null");
return;
}

if (ghTyp.Value is GsaResultGoo goo) {
result = goo.Value;
elementlist = Inputs.GetElementListDefinition(this, da, 1, result.Model);
} else {
this.AddRuntimeError("Error converting input to GSA Result");
return;
switch (ghTyp?.Value) {
case GsaResultGoo goo:
result = new GsaResult2((GsaResult)goo.Value);
elementlist = Inputs.GetElementListDefinition(this, da, 1, result.Model);
break;

case null:
this.AddRuntimeWarning("Input is null");
return;

default:
this.AddRuntimeError("Error converting input to GSA Result");
return;
}

List<GsaResultsValues> vals
= result.Element1DDisplacementValues(elementlist, positionsCount, -1, _lengthUnit);
ReadOnlyCollection<int> elementIds = result.ElementIds(elementlist);
IElement1dResultSubset<IElement1dDisplacement, IDisplacement, ResultVector6<Element1dExtremaKey>> resultSet =
result.Element1dDisplacements.ResultSubset(elementIds, positionsCount);

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

// loop through all permutations (analysis case will just have one)
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 Element1D results.");
continue;
}

Parallel.For(0, 2, thread => // split computation in two for xyz and xxyyzz
{
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);

outTransX.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.X.ToUnit(_lengthUnit))),
path); // use ToUnit to capture changes in dropdown
outTransY.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.Y.ToUnit(_lengthUnit))), path);
outTransZ.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.Z.ToUnit(_lengthUnit))), path);
outTransXyz.AddRange(
res.Select(x => new GH_UnitNumber(x.Value.Xyz.ToUnit(_lengthUnit))), 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);

outRotX.AddRange(res.Select(x => new GH_UnitNumber(x.Value.X)),
path); // always use [rad] units
outRotY.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Y)), path);
outRotZ.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Z)), path);
outRotXyz.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Xyz)), path);
}

break;
}
if (_selectedItems[0] == ExtremaHelper.Vector6Displacements[0]) {
foreach (KeyValuePair<int, Collection<IElement1dDisplacement>> kvp in resultSet.Subset) {
foreach (int p in permutations) {
var path = new GH_Path(result.CaseId, result.SelectedPermutationIds == null ? 0 : p, kvp.Key);
outTransX.AddRange(kvp.Value[p - 1].Results.Values.Select(
r => new GH_UnitNumber(r.X.ToUnit(_lengthUnit))), path);
outTransY.AddRange(kvp.Value[p - 1].Results.Values.Select(
r => new GH_UnitNumber(r.Y.ToUnit(_lengthUnit))), path);
outTransZ.AddRange(kvp.Value[p - 1].Results.Values.Select(
r => new GH_UnitNumber(r.Z.ToUnit(_lengthUnit))), path);
outTransXyz.AddRange(kvp.Value[p - 1].Results.Values.Select(
r => new GH_UnitNumber(r.Xyz.ToUnit(_lengthUnit))), path);
outRotX.AddRange(kvp.Value[p - 1].Results.Values.Select(
r => new GH_UnitNumber(r.Xx)), path);
outRotY.AddRange(kvp.Value[p - 1].Results.Values.Select(
r => new GH_UnitNumber(r.Yy)), path);
outRotZ.AddRange(kvp.Value[p - 1].Results.Values.Select(
r => new GH_UnitNumber(r.Zz)), path);
outRotXyz.AddRange(kvp.Value[p - 1].Results.Values.Select(
r => new GH_UnitNumber(r.Xxyyzz)), path);
}
});
}
} else {
Element1dExtremaKey key = ExtremaHelper.DisplacementExtremaKey(resultSet, _selectedItems[0]);
IDisplacement extrema = resultSet.GetExtrema(key);
int perm = result.CaseType == CaseType.AnalysisCase ? 0 : 1;
var path = new GH_Path(result.CaseId, key.Permutation + perm, key.Id);
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);
}

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

da.SetDataTree(0, outTransX);
Expand All @@ -217,12 +199,16 @@ List<GsaResultsValues> vals
da.SetDataTree(5, outRotY);
da.SetDataTree(6, outRotZ);
da.SetDataTree(7, outRotXyz);

PostHog.Result(result.Type, 1, GsaResultsValues.ResultType.Displacement);
}

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

_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), _selectedItems[1]);
base.UpdateUIFromSelectedItems();
}
}
Expand Down
Loading

0 comments on commit 532c01a

Please sign in to comment.