From 6cfab49bed8fd0dd167604b2d88cd92f83949259 Mon Sep 17 00:00:00 2001 From: DominikaLos Date: Tue, 10 Oct 2023 16:03:19 +0200 Subject: [PATCH] gsagh-391 first step --- .../Components/5_Results/NodeDisplacements.cs | 38 ++--- .../GsaAPI/Results/AnalysisCaseQuantities.cs | 54 ++++--- .../Results/CombinationCaseQuantities.cs | 20 +-- GsaGH/Parameters/5_Results/GsaResult.cs | 12 +- .../Parameters/5_Results/GsaResultQuantity.cs | 2 +- .../Parameters/5_Results/GsaResultsValues.cs | 56 ++++--- ...antities.cs => GsaDisplacementQuantity.cs} | 26 ++- .../5_Results/Quantities/IAngleQuantity.cs | 14 ++ .../Quantities/IDisplacementQuantity.cs | 4 + .../5_Results/Quantities/ILengthQuantity.cs | 14 ++ .../5_Results/Quantities/IResultQuantity.cs | 4 + .../5_Results/Values/GsaDisplacementValues.cs | 151 ++++++++++++++++++ .../5_Results/Values/IResultValues.cs | 29 ++++ .../5_Results/GsaResultAnalysisCaseTests.cs | 2 +- 14 files changed, 319 insertions(+), 107 deletions(-) rename GsaGH/Parameters/5_Results/Quantities/{GsaDisplacementQuantities.cs => GsaDisplacementQuantity.cs} (77%) create mode 100644 GsaGH/Parameters/5_Results/Quantities/IAngleQuantity.cs create mode 100644 GsaGH/Parameters/5_Results/Quantities/IDisplacementQuantity.cs create mode 100644 GsaGH/Parameters/5_Results/Quantities/ILengthQuantity.cs create mode 100644 GsaGH/Parameters/5_Results/Quantities/IResultQuantity.cs create mode 100644 GsaGH/Parameters/5_Results/Values/GsaDisplacementValues.cs create mode 100644 GsaGH/Parameters/5_Results/Values/IResultValues.cs diff --git a/GsaGH/Components/5_Results/NodeDisplacements.cs b/GsaGH/Components/5_Results/NodeDisplacements.cs index 3dd7dec85..5d50484db 100644 --- a/GsaGH/Components/5_Results/NodeDisplacements.cs +++ b/GsaGH/Components/5_Results/NodeDisplacements.cs @@ -134,7 +134,7 @@ protected override void SolveInternal(IGH_DataAccess da) { return; } - List vals = result.NodeDisplacementValues(nodeList, _lengthUnit); + List vals = result.NodeDisplacementValues(nodeList, _lengthUnit); List permutations = result.SelectedPermutationIds ?? new List() { 1, @@ -157,29 +157,19 @@ protected override void SolveInternal(IGH_DataAccess da) { Parallel.For(0, 2, item => // split into two tasks { - switch (item) { - case 0: - foreach (int id in vals[perm - 1].Ids) { - // there is only one result per node - GsaResultQuantity values = vals[perm - 1].XyzResults[id][0]; - // use ToUnit to capture changes in dropdown - transX.Add(new GH_UnitNumber(values.X.ToUnit(_lengthUnit))); - transY.Add(new GH_UnitNumber(values.Y.ToUnit(_lengthUnit))); - transZ.Add(new GH_UnitNumber(values.Z.ToUnit(_lengthUnit))); - transXyz.Add(new GH_UnitNumber(values.Xyz.ToUnit(_lengthUnit))); - } - break; - - case 1: - foreach (int id in vals[perm - 1].Ids) { - // there is only one result per node - GsaResultQuantity values = vals[perm - 1].XxyyzzResults[id][0]; - rotX.Add(new GH_UnitNumber(values.X)); - rotY.Add(new GH_UnitNumber(values.Y)); - rotZ.Add(new GH_UnitNumber(values.Z)); - rotXyz.Add(new GH_UnitNumber(values.Xyz)); - } - break; + foreach (int id in vals[perm - 1].Ids) { + // there is only one result per node + Parameters._5_Results.Quantities.IDisplacementQuantity values = vals[perm - 1].Results[id][0]; + // use ToUnit to capture changes in dropdown + transX.Add(new GH_UnitNumber(values.X.ToUnit(_lengthUnit))); + transY.Add(new GH_UnitNumber(values.Y.ToUnit(_lengthUnit))); + transZ.Add(new GH_UnitNumber(values.Z.ToUnit(_lengthUnit))); + transXyz.Add(new GH_UnitNumber(values.Xyz.ToUnit(_lengthUnit))); + // there is only one result per node + rotX.Add(new GH_UnitNumber(values.X)); + rotY.Add(new GH_UnitNumber(values.Y)); + rotZ.Add(new GH_UnitNumber(values.Z)); + rotXyz.Add(new GH_UnitNumber(values.Xyz)); } }); diff --git a/GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs b/GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs index 39f2291a4..8fcc3c835 100644 --- a/GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs +++ b/GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs @@ -1,12 +1,14 @@ -using System; +using GsaAPI; +using GsaGH.Parameters; +using GsaGH.Parameters._5_Results.Quantities; +using OasysUnits; +using OasysUnits.Units; +using System; using System.Collections.Concurrent; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; -using GsaAPI; -using GsaGH.Parameters; -using OasysUnits; -using OasysUnits.Units; +using static GsaGH.Parameters.GsaResultsValues; using AngleUnit = OasysUnits.Units.AngleUnit; using EnergyUnit = OasysUnits.Units.EnergyUnit; using ForceUnit = OasysUnits.Units.ForceUnit; @@ -26,7 +28,7 @@ internal static GsaResultsValues GetElement1DResultValues( ReadOnlyDictionary globalResults, ForceUnit forceUnit, MomentUnit momentUnit) { var r = new GsaResultsValues { - Type = GsaResultsValues.ResultType.Force, + Type = ResultType.Force, }; Parallel.ForEach(globalResults.Keys, key => { @@ -66,7 +68,7 @@ internal static GsaResultsValues GetElement1DResultValues( ReadOnlyDictionary globalResults, EnergyUnit energyUnit, bool average = false) { var r = new GsaResultsValues { - Type = GsaResultsValues.ResultType.StrainEnergy, + Type = ResultType.StrainEnergy, }; Parallel.ForEach(globalResults.Keys, key => { @@ -97,7 +99,7 @@ internal static GsaResultsValues GetElement1DResultValues( internal static GsaResultsValues GetElement1DResultValues( ReadOnlyDictionary globalResults, LengthUnit resultLengthUnit) { var r = new GsaResultsValues { - Type = GsaResultsValues.ResultType.Displacement, + Type = ResultType.Displacement, }; Parallel.ForEach(globalResults.Keys, key => { @@ -135,7 +137,7 @@ internal static GsaResultsValues GetElement1DResultValues( internal static GsaResultsValues GetElement2DResultValues( ReadOnlyDictionary globalResults, PressureUnit stressUnit) { var r = new GsaResultsValues { - Type = GsaResultsValues.ResultType.Stress, + Type = ResultType.Stress, }; Parallel.ForEach(globalResults.Keys, key => { @@ -189,7 +191,7 @@ internal static GsaResultsValues GetElement2DResultValues( internal static GsaResultsValues GetElement2DResultValues( ReadOnlyDictionary globalResults, ForcePerLengthUnit forceUnit) { var r = new GsaResultsValues { - Type = GsaResultsValues.ResultType.Shear, + Type = ResultType.Shear, }; Parallel.ForEach(globalResults.Keys, key => { @@ -230,7 +232,7 @@ internal static GsaResultsValues GetElement2DResultValues( ReadOnlyDictionary globalResults, ForcePerLengthUnit forceUnit, ForceUnit momentUnit) { var r = new GsaResultsValues { - Type = GsaResultsValues.ResultType.Force, + Type = ResultType.Force, }; Parallel.ForEach(globalResults.Keys, key => { @@ -294,7 +296,7 @@ internal static GsaResultsValues GetElement2DResultValues( internal static GsaResultsValues GetElement2DResultValues( ReadOnlyDictionary globalResults, LengthUnit resultLengthUnit) { var r = new GsaResultsValues { - Type = GsaResultsValues.ResultType.Displacement, + Type = ResultType.Displacement, }; Parallel.ForEach(globalResults.Keys, key => { @@ -346,7 +348,7 @@ internal static GsaResultsValues GetElement2DResultValues( internal static GsaResultsValues GetElement3DResultValues( ReadOnlyDictionary globalResults, LengthUnit resultLengthUnit) { var r = new GsaResultsValues { - Type = GsaResultsValues.ResultType.Displacement, + Type = ResultType.Displacement, }; Parallel.ForEach(globalResults.Keys, key => { @@ -382,7 +384,7 @@ internal static GsaResultsValues GetElement3DResultValues( internal static GsaResultsValues GetElement3DResultValues( ReadOnlyDictionary globalResults, PressureUnit stressUnit) { var r = new GsaResultsValues { - Type = GsaResultsValues.ResultType.Stress, + Type = ResultType.Stress, }; Parallel.ForEach(globalResults.Keys, key => { @@ -440,7 +442,7 @@ internal static GsaResultsValues GetNodeReactionForceResultValues( ReadOnlyDictionary globalResults, ForceUnit forceUnit, MomentUnit momentUnit, ConcurrentBag supportnodeIDs = null) { var r = new GsaResultsValues { - Type = GsaResultsValues.ResultType.Force, + Type = ResultType.Force, }; Parallel.ForEach(globalResults.Keys, nodeId => { @@ -477,26 +479,26 @@ internal static GsaResultsValues GetNodeReactionForceResultValues( /// /// /// - internal static GsaResultsValues GetNodeResultValues( + internal static GsaDisplacementValues GetNodeResultValues( ReadOnlyDictionary globalResults, LengthUnit resultLengthUnit) { - var r = new GsaResultsValues { - Type = GsaResultsValues.ResultType.Force, + var r = new GsaDisplacementValues { + Type = ResultType.Displacement, }; Parallel.ForEach(globalResults.Keys, nodeId => { NodeResult result = globalResults[nodeId]; Double6 values = result.Displacement; - + var quantities = new GsaDisplacementQuantity(values, resultLengthUnit, AngleUnit.Radian); if (!double.IsNaN(values.X) && !double.IsNaN(values.Y) && !double.IsNaN(values.Z)) { - var xyz = new ConcurrentDictionary(); - xyz.TryAdd(0, GetQuantityResult(values, resultLengthUnit)); - r.XyzResults.TryAdd(nodeId, xyz); + var xyz = new ConcurrentDictionary(); + xyz.TryAdd(0, quantities); + r.Results.TryAdd(nodeId, xyz); } if (!double.IsNaN(values.XX) && !double.IsNaN(values.YY) && !double.IsNaN(values.ZZ)) { - var xxyyzz = new ConcurrentDictionary(); - xxyyzz.TryAdd(0, GetQuantityResult(values, AngleUnit.Radian)); - r.XxyyzzResults.TryAdd(nodeId, xxyyzz); + var xxyyzz = new ConcurrentDictionary(); + xxyyzz.TryAdd(0, quantities); + r.Results.TryAdd(nodeId, xxyyzz); } }); @@ -517,7 +519,7 @@ internal static GsaResultsValues GetNodeSpringForceResultValues( ReadOnlyDictionary globalResults, ForceUnit forceUnit, MomentUnit momentUnit, ConcurrentBag supportnodeIDs = null) { var r = new GsaResultsValues { - Type = GsaResultsValues.ResultType.Force, + Type = ResultType.Force, }; Parallel.ForEach(globalResults.Keys, nodeId => { diff --git a/GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs b/GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs index e6f4dc135..f52c7ecb6 100644 --- a/GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs +++ b/GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using GsaAPI; using GsaGH.Parameters; +using GsaGH.Parameters._5_Results.Quantities; using OasysUnits; using OasysUnits.Units; using AngleUnit = OasysUnits.Units.AngleUnit; @@ -650,10 +651,10 @@ internal static ConcurrentDictionary GetNodeReactionForce /// /// list of permutations, input an empty list to get all permutations /// - internal static ConcurrentDictionary GetNodeResultValues( + internal static ConcurrentDictionary GetNodeResultValues( ReadOnlyDictionary> globalResults, LengthUnit resultLengthUnit, List permutations) { - var rs = new ConcurrentDictionary(); + var rs = new ConcurrentDictionary(); if (permutations.Count == 0) { permutations = Enumerable.Range(1, globalResults[globalResults.Keys.First()].Count) @@ -664,7 +665,7 @@ internal static ConcurrentDictionary GetNodeResultValues( Parallel.For(0, permutationCount, index => { int permutationId = permutations[index]; - var r = new GsaResultsValues { + var r = new GsaDisplacementValues { Type = GsaResultsValues.ResultType.Displacement, }; @@ -672,17 +673,18 @@ internal static ConcurrentDictionary GetNodeResultValues( ReadOnlyCollection results = globalResults[nodeId]; NodeResult result = results[permutationId - 1]; Double6 values = result.Displacement; + var quantities = new GsaDisplacementQuantity(values, resultLengthUnit, AngleUnit.Radian); if (!double.IsNaN(values.X) && !double.IsNaN(values.Y) && !double.IsNaN(values.Z)) { - var xyz = new ConcurrentDictionary(); - xyz.TryAdd(0, GetQuantityResult(values, resultLengthUnit)); - r.XyzResults.TryAdd(nodeId, xyz); + var xyz = new ConcurrentDictionary(); + xyz.TryAdd(0, quantities); + r.Results.TryAdd(nodeId, xyz); } if (!double.IsNaN(values.XX) && !double.IsNaN(values.YY) && !double.IsNaN(values.ZZ)) { - var xxyyzz = new ConcurrentDictionary(); - xxyyzz.TryAdd(0, GetQuantityResult(values, AngleUnit.Radian)); - r.XxyyzzResults.TryAdd(nodeId, xxyyzz); + var xxyyzz = new ConcurrentDictionary(); + xxyyzz.TryAdd(0, quantities); + r.Results.TryAdd(nodeId, xxyyzz); } }); diff --git a/GsaGH/Parameters/5_Results/GsaResult.cs b/GsaGH/Parameters/5_Results/GsaResult.cs index 5dc918291..c70a3595f 100644 --- a/GsaGH/Parameters/5_Results/GsaResult.cs +++ b/GsaGH/Parameters/5_Results/GsaResult.cs @@ -139,8 +139,8 @@ internal Dictionary> /// Append to this dictionary to chache results /// key = elementList /// - internal Dictionary ACaseNodeDisplacementValues { get; set; } - = new Dictionary(); + internal Dictionary ACaseNodeDisplacementValues { get; set; } + = new Dictionary(); /// /// Analysis Case Node Footfall Result VALUES Dictionary /// Append to this dictionary to chache results @@ -302,9 +302,9 @@ internal Dictionary> /// key = elementList /// value = Dictionary(permutationID, permutationsResults) /// - internal Dictionary> + internal Dictionary> ComboNodeDisplacementValues { get; set; } - = new Dictionary>(); + = new Dictionary>(); /// /// Combination Case Node Reaction Force Result VALUES Dictionary /// Append to this dictionary to chache results @@ -924,7 +924,7 @@ internal List Element3DStressValues( /// /// /// - internal List NodeDisplacementValues( + internal List NodeDisplacementValues( string nodelist, LengthUnit lengthUnit) { if (nodelist.ToLower() == "all" || nodelist == string.Empty) { nodelist = "All"; @@ -940,7 +940,7 @@ internal List NodeDisplacementValues( ResultHelper.GetNodeResultValues(ACaseNodeResults[nodelist], lengthUnit)); } - return new List { + return new List { ACaseNodeDisplacementValues[nodelist], }; } diff --git a/GsaGH/Parameters/5_Results/GsaResultQuantity.cs b/GsaGH/Parameters/5_Results/GsaResultQuantity.cs index b9e62f508..e444125cc 100644 --- a/GsaGH/Parameters/5_Results/GsaResultQuantity.cs +++ b/GsaGH/Parameters/5_Results/GsaResultQuantity.cs @@ -1,7 +1,7 @@ using OasysUnits; namespace GsaGH.Parameters { - internal class GsaResultQuantity { + public class GsaResultQuantity { internal IQuantity X { get; set; } internal IQuantity Xyz { get; set; } internal IQuantity Y { get; set; } diff --git a/GsaGH/Parameters/5_Results/GsaResultsValues.cs b/GsaGH/Parameters/5_Results/GsaResultsValues.cs index a4a9c4454..38502d835 100644 --- a/GsaGH/Parameters/5_Results/GsaResultsValues.cs +++ b/GsaGH/Parameters/5_Results/GsaResultsValues.cs @@ -1,17 +1,21 @@ -using System; +using GsaAPI; +using GsaGH.Parameters._5_Results.Quantities; +using GsaGH.Parameters._5_Results.Values; +using OasysUnits; +using Rhino.Geometry; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using GsaAPI; -using OasysUnits; -using Rhino.Geometry; using AngleUnit = OasysUnits.Units.AngleUnit; using LengthUnit = OasysUnits.Units.LengthUnit; namespace GsaGH.Parameters { - internal class GsaResultsValues { - internal enum ResultType { + + + public class GsaResultsValues : IResultValues { + public enum ResultType { Displacement, Force, Stress, @@ -19,25 +23,24 @@ internal enum ResultType { StrainEnergy, Footfall, } - - internal IQuantity DmaxX { get; set; } - internal IQuantity DmaxXx { get; set; } - internal IQuantity DmaxXxyyzz { get; set; } - internal IQuantity DmaxXyz { get; set; } - internal IQuantity DmaxY { get; set; } - internal IQuantity DmaxYy { get; set; } - internal IQuantity DmaxZ { get; set; } - internal IQuantity DmaxZz { get; set; } - internal IQuantity DminX { get; set; } - internal IQuantity DminXx { get; set; } - internal IQuantity DminXxyyzz { get; set; } - internal IQuantity DminXyz { get; set; } - internal IQuantity DminY { get; set; } - internal IQuantity DminYy { get; set; } - internal IQuantity DminZ { get; set; } - internal IQuantity DminZz { get; set; } - internal ResultType Type { get; set; } - internal List Ids => XyzResults.Keys.OrderBy(x => x).ToList(); + public IQuantity DmaxX { get; set; } + public IQuantity DmaxXx { get; set; } + public IQuantity DmaxXxyyzz { get; set; } + public IQuantity DmaxXyz { get; set; } + public IQuantity DmaxY { get; set; } + public IQuantity DmaxYy { get; set; } + public IQuantity DmaxZ { get; set; } + public IQuantity DmaxZz { get; set; } + public IQuantity DminX { get; set; } + public IQuantity DminXx { get; set; } + public IQuantity DminXxyyzz { get; set; } + public IQuantity DminXyz { get; set; } + public IQuantity DminY { get; set; } + public IQuantity DminYy { get; set; } + public IQuantity DminZ { get; set; } + public IQuantity DminZz { get; set; } + public ResultType Type { get; set; } + public List Ids => XyzResults.Keys.OrderBy(x => x).ToList(); internal ConcurrentDictionary> XxyyzzResults { get; set; } @@ -49,6 +52,7 @@ internal ConcurrentDictionary> internal ConcurrentDictionary> XyzResults { get; set; } = new ConcurrentDictionary>(); + public ConcurrentDictionary> Results { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } internal GsaResultsValues() { } @@ -170,4 +174,4 @@ internal void UpdateMinMax() { } } } -} +} \ No newline at end of file diff --git a/GsaGH/Parameters/5_Results/Quantities/GsaDisplacementQuantities.cs b/GsaGH/Parameters/5_Results/Quantities/GsaDisplacementQuantity.cs similarity index 77% rename from GsaGH/Parameters/5_Results/Quantities/GsaDisplacementQuantities.cs rename to GsaGH/Parameters/5_Results/Quantities/GsaDisplacementQuantity.cs index 89a822b64..088227df3 100644 --- a/GsaGH/Parameters/5_Results/Quantities/GsaDisplacementQuantities.cs +++ b/GsaGH/Parameters/5_Results/Quantities/GsaDisplacementQuantity.cs @@ -1,28 +1,26 @@ using GsaAPI; using OasysUnits; -using Rhino.Commands; using System; -using System.IO; using AngleUnit = OasysUnits.Units.AngleUnit; using LengthUnit = OasysUnits.Units.LengthUnit; namespace GsaGH.Parameters._5_Results.Quantities { - public class GsaDisplacementQuantities { - internal Length X { get; set; } - internal Length Xyz { get; set; } - internal Length Y { get; set; } - internal Length Z { get; set; } - internal Angle Xx { get; set; } - internal Angle Xxyyzz { get; set; } - internal Angle Yy { get; set; } - internal Angle Zz { get; set; } + public class GsaDisplacementQuantity : IDisplacementQuantity { + public Length X { get; private set; } + public Length Xyz { get; private set; } + public Length Y { get; private set; } + public Length Z { get; private set; } + public Angle Xx { get; private set; } + public Angle Xxyyzz { get; private set; } + public Angle Yy { get; private set; } + public Angle Zz { get; private set; } - internal GsaDisplacementQuantities(Double6 result, LengthUnit LUnit, AngleUnit AUnit) { + internal GsaDisplacementQuantity(Double6 result, LengthUnit LUnit, AngleUnit AUnit) { SetLengthUnit(result, LUnit); SetAngleUnit(result, AUnit); } - private void SetLengthUnit(Double6 result, LengthUnit unit) { + public void SetLengthUnit(Double6 result, LengthUnit unit) { X = new Length(new Length(result.X, LengthUnit.Meter).As(unit), unit); Y = new Length(new Length(result.Y, LengthUnit.Meter).As(unit), unit); Z = new Length(new Length(result.Z, LengthUnit.Meter).As(unit), unit); @@ -31,7 +29,7 @@ double pyth Xyz = new Length(new Length(pyth, LengthUnit.Meter).As(unit), unit); } - private void SetAngleUnit(Double6 result, AngleUnit unit) { + public void SetAngleUnit(Double6 result, AngleUnit unit) { IQuantity x; if (!double.IsNaN(result.XX)) // TO-DO: GSA-5351 remove NaN and Infinity values from GsaAPI results { diff --git a/GsaGH/Parameters/5_Results/Quantities/IAngleQuantity.cs b/GsaGH/Parameters/5_Results/Quantities/IAngleQuantity.cs new file mode 100644 index 000000000..0b579df14 --- /dev/null +++ b/GsaGH/Parameters/5_Results/Quantities/IAngleQuantity.cs @@ -0,0 +1,14 @@ +using GsaAPI; +using OasysUnits; +using AngleUnit = OasysUnits.Units.AngleUnit; + +namespace GsaGH.Parameters._5_Results.Quantities { + public interface IAngleQuantity : IResultQuantity { + public Angle Xx { get; } + public Angle Xxyyzz { get; } + public Angle Yy { get; } + public Angle Zz { get; } + + public void SetAngleUnit(Double6 result, AngleUnit unit); + } +} diff --git a/GsaGH/Parameters/5_Results/Quantities/IDisplacementQuantity.cs b/GsaGH/Parameters/5_Results/Quantities/IDisplacementQuantity.cs new file mode 100644 index 000000000..74343c615 --- /dev/null +++ b/GsaGH/Parameters/5_Results/Quantities/IDisplacementQuantity.cs @@ -0,0 +1,4 @@ +namespace GsaGH.Parameters._5_Results.Quantities { + public interface IDisplacementQuantity : ILengthQuantity, IAngleQuantity { + } +} diff --git a/GsaGH/Parameters/5_Results/Quantities/ILengthQuantity.cs b/GsaGH/Parameters/5_Results/Quantities/ILengthQuantity.cs new file mode 100644 index 000000000..84ffc1e4b --- /dev/null +++ b/GsaGH/Parameters/5_Results/Quantities/ILengthQuantity.cs @@ -0,0 +1,14 @@ +using GsaAPI; +using OasysUnits; +using LengthUnit = OasysUnits.Units.LengthUnit; + +namespace GsaGH.Parameters._5_Results.Quantities { + public interface ILengthQuantity : IResultQuantity{ + public Length X { get; } + public Length Xyz { get; } + public Length Y { get; } + public Length Z { get; } + + public void SetLengthUnit(Double6 result, LengthUnit unit); + } +} diff --git a/GsaGH/Parameters/5_Results/Quantities/IResultQuantity.cs b/GsaGH/Parameters/5_Results/Quantities/IResultQuantity.cs new file mode 100644 index 000000000..eb440ec78 --- /dev/null +++ b/GsaGH/Parameters/5_Results/Quantities/IResultQuantity.cs @@ -0,0 +1,4 @@ +namespace GsaGH.Parameters._5_Results.Quantities { + public interface IResultQuantity { + } +} diff --git a/GsaGH/Parameters/5_Results/Values/GsaDisplacementValues.cs b/GsaGH/Parameters/5_Results/Values/GsaDisplacementValues.cs new file mode 100644 index 000000000..271d92be9 --- /dev/null +++ b/GsaGH/Parameters/5_Results/Values/GsaDisplacementValues.cs @@ -0,0 +1,151 @@ +using GsaAPI; +using GsaGH.Parameters._5_Results.Quantities; +using GsaGH.Parameters._5_Results.Values; +using OasysUnits; +using Rhino.Geometry; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace GsaGH.Parameters { + // For now, to be refactored + public class GsaDisplacementValues: GsaResultsValues, IResultValues{ + new public Length DmaxX { get; set; } + new public Angle DmaxXx { get; set; } + new public Angle DmaxXxyyzz { get; set; } + new public Length DmaxXyz { get; set; } + new public Length DmaxY { get; set; } + new public Angle DmaxYy { get; set; } + new public Length DmaxZ { get; set; } + new public Angle DmaxZz { get; set; } + new public Length DminX { get; set; } + new public Angle DminXx { get; set; } + new public Angle DminXxyyzz { get; set; } + new public Length DminXyz { get; set; } + new public Length DminY { get; set; } + new public Angle DminYy { get; set; } + new public Length DminZ { get; set; } + new public Angle DminZz { get; set; } + new public ResultType Type { get; set; } + new public List Ids => Results.Keys.OrderBy(x => x).ToList(); + + new public ConcurrentDictionary> + Results { get; set; } + = new ConcurrentDictionary>(); + + internal GsaDisplacementValues() { } + + new internal void CoordinateTransformationTo(Plane plane, Model model) { + // coordinate transformation + Parallel.ForEach(Results.Keys, elementId => { + var localAxes = new LocalAxes(model.ElementDirectionCosine(elementId)); + var local = new Plane(Point3d.Origin, localAxes.X, localAxes.Y); + // 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); + + if (angle > Math.PI) { + angle -= 2 * Math.PI; + } + + foreach (IDisplacementQuantity results in Results[elementId].Values) { + var displacements = new Point3d(results.X.Value, results.Y.Value, results.Z.Value); + displacements.Transform(Transform.Rotation(angle, axis, Point3d.Origin)); + var rotations = new Point3d(results.Xx.Value, results.Yy.Value, results.Zz.Value); + rotations.Transform(Transform.Rotation(angle, axis, Point3d.Origin)); + + var value = new Double6(displacements.X, displacements.Y, displacements.Z, rotations.X, rotations.Y, rotations.Z); + results.SetLengthUnit(value, results.X.Unit); + results.SetAngleUnit(value, results.Xx.Unit); + } + }); + } + + new internal void UpdateMinMax() { + if (Results.Count > 0) { + DmaxX = Results.AsParallel().Select(list => list.Value.Values.Select(res => res.X).Max()) + .Max(); + DmaxY = Results.AsParallel().Select(list => list.Value.Values.Select(res => res.Y).Max()) + .Max(); + try { + DmaxZ = Results.AsParallel() + .Select(list => list.Value.Values.Select(res => res.Z).Max()).Max(); + } catch (Exception) { + // shear does not set this value + } + + try { + DmaxXyz = Results.AsParallel() + .Select(list => list.Value.Values.Select(res => res.Xyz).Max()).Max(); + } catch (Exception) { + // resultant may not always be computed + } + + DminX = Results.AsParallel().Select(list => list.Value.Values.Select(res => res.X).Min()) + .Min(); + DminY = Results.AsParallel().Select(list => list.Value.Values.Select(res => res.Y).Min()) + .Min(); + try { + DminZ = Results.AsParallel() + .Select(list => list.Value.Values.Select(res => res.Z).Min()).Min(); + } catch (Exception) { + // shear does not set this value + } + + try { + DminXyz = Results.AsParallel() + .Select(list => list.Value.Values.Select(res => res.Xyz).Min()).Min(); + } catch (Exception) { + // resultant may not always be computed + } + } + + if (Results.Count <= 0) { + return; + } + + { + try { + DmaxXx = Results.AsParallel() + .Select(list => list.Value.Values.Select(res => res.Xx).Max()).Max(); + DmaxYy = Results.AsParallel() + .Select(list => list.Value.Values.Select(res => res.Yy).Max()).Max(); + DmaxZz = Results.AsParallel() + .Select(list => list.Value.Values.Select(res => res.Zz).Max()).Max(); + } catch (Exception) { + // some cases doesnt compute xxyyzz results at all + } + + try { + DmaxXxyyzz = Results.AsParallel() + .Select(list => list.Value.Values.Select(res => res.Xxyyzz).Max()).Max(); + } catch (Exception) { + // resultant may not always be computed + } + + try { + DminXx = Results.AsParallel() + .Select(list => list.Value.Values.Select(res => res.Xx).Min()).Min(); + DminYy = Results.AsParallel() + .Select(list => list.Value.Values.Select(res => res.Yy).Min()).Min(); + DminZz = Results.AsParallel() + .Select(list => list.Value.Values.Select(res => res.Zz).Min()).Min(); + } catch (Exception) { + // some cases doesnt compute xxyyzz results at all + } + + try { + DminXxyyzz = Results.AsParallel() + .Select(list => list.Value.Values.Select(res => res.Xxyyzz).Min()).Min(); + } catch (Exception) { + // resultant may not always be computed + } + } + } + } +} diff --git a/GsaGH/Parameters/5_Results/Values/IResultValues.cs b/GsaGH/Parameters/5_Results/Values/IResultValues.cs new file mode 100644 index 000000000..af5ad7eef --- /dev/null +++ b/GsaGH/Parameters/5_Results/Values/IResultValues.cs @@ -0,0 +1,29 @@ +using System.Collections.Concurrent; +using System.Collections.Generic; +using static GsaGH.Parameters.GsaResultsValues; + +namespace GsaGH.Parameters._5_Results.Values { + public interface IResultValues { + public T1 DmaxX { get; set; } + public T2 DmaxXx { get; set; } + public T2 DmaxXxyyzz { get; set; } + public T1 DmaxXyz { get; set; } + public T1 DmaxY { get; set; } + public T2 DmaxYy { get; set; } + public T1 DmaxZ { get; set; } + public T2 DmaxZz { get; set; } + public T1 DminX { get; set; } + public T2 DminXx { get; set; } + public T2 DminXxyyzz { get; set; } + public T1 DminXyz { get; set; } + public T1 DminY { get; set; } + public T2 DminYy { get; set; } + public T1 DminZ { get; set; } + public T2 DminZz { get; set; } + public ResultType Type { get; set; } + public List Ids { get; } + + public ConcurrentDictionary> + Results { get; set; } + } +} diff --git a/GsaGHTests/1_BaseParameters/5_Results/GsaResultAnalysisCaseTests.cs b/GsaGHTests/1_BaseParameters/5_Results/GsaResultAnalysisCaseTests.cs index 4d5f0a59d..b27c79ccd 100644 --- a/GsaGHTests/1_BaseParameters/5_Results/GsaResultAnalysisCaseTests.cs +++ b/GsaGHTests/1_BaseParameters/5_Results/GsaResultAnalysisCaseTests.cs @@ -41,7 +41,7 @@ public void GsaResultAnalysisCaseDisplacementXTest() { Assert.Equal(CaseType.AnalysisCase, result.Type); string nodeList = "442 to 468"; - List resultValues = + List resultValues = result.NodeDisplacementValues(nodeList, LengthUnit.Millimeter); var expectedIds = result.Model.Model.Nodes(nodeList).Keys.ToList();