From fbb5a9144461c8096d32b8e3e1e240befa9ee950 Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Fri, 6 Oct 2023 14:14:47 +0200 Subject: [PATCH 1/4] add double.NaN check for all result imports --- .../GsaAPI/Results/AnalysisCaseQuantities.cs | 177 +++++++++++----- .../Results/CombinationCaseQuantities.cs | 189 +++++++++++++----- .../Helpers/GsaAPI/Results/QuantityResults.cs | 37 ++-- 3 files changed, 289 insertions(+), 114 deletions(-) diff --git a/GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs b/GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs index c7d770258..f75816f52 100644 --- a/GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs +++ b/GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs @@ -39,8 +39,13 @@ internal static GsaResultsValues GetElement1DResultValues( ReadOnlyCollection values = elementResults.Force; Parallel.For(0, values.Count, i => { Double6 result = values[i]; - xyzRes[i] = GetQuantityResult(result, forceUnit, true); - xxyyzzRes[i] = GetQuantityResult(result, momentUnit, true); + if (!double.IsNaN(values[i].X) && !double.IsNaN(values[i].Y) && !double.IsNaN(values[i].Z)) { + xyzRes[i] = GetQuantityResult(result, forceUnit, true); + } + + if (!double.IsNaN(values[i].XX) && !double.IsNaN(values[i].YY) && !double.IsNaN(values[i].ZZ)) { + xxyyzzRes[i] = GetQuantityResult(result, momentUnit, true); + } }); r.XyzResults.TryAdd(key, xyzRes); r.XxyyzzResults.TryAdd(key, xxyyzzRes); @@ -105,8 +110,13 @@ internal static GsaResultsValues GetElement1DResultValues( ReadOnlyCollection values = elementResults.Displacement; Parallel.For(0, values.Count, i => { Double6 result = values[i]; - xyzRes[i] = GetQuantityResult(result, resultLengthUnit); - xxyyzzRes[i] = GetQuantityResult(result, AngleUnit.Radian); + if (!double.IsNaN(values[i].X) && !double.IsNaN(values[i].Y) && !double.IsNaN(values[i].Z)) { + xyzRes[i] = GetQuantityResult(result, resultLengthUnit); + } + + if (!double.IsNaN(values[i].XX) && !double.IsNaN(values[i].YY) && !double.IsNaN(values[i].ZZ)) { + xxyyzzRes[i] = GetQuantityResult(result, AngleUnit.Radian); + } }); r.XyzResults.TryAdd(key, xyzRes); r.XxyyzzResults.TryAdd(key, xxyyzzRes); @@ -141,16 +151,25 @@ internal static GsaResultsValues GetElement2DResultValues( return; } - if (i < stresses.Count) { + if (i < stresses.Count && !double.IsNaN(stresses[i].XX) && + !double.IsNaN(stresses[i].YY) && !double.IsNaN(stresses[i].ZZ)) { xyzRes[i] = GetQuantityResult(stresses[i], stressUnit); - } else { + } else if (!double.IsNaN(stresses[i].XY) && !double.IsNaN(stresses[i].YZ) + && !double.IsNaN(stresses[i].ZX)) { xxyyzzRes[i - stresses.Count] = GetQuantityResult(stresses[i - stresses.Count], stressUnit, true); } }); - xyzRes[stresses.Count] - = GetQuantityResult(stresses[0], stressUnit); // add centre point at the end - xxyyzzRes[stresses.Count] = GetQuantityResult(stresses[0], stressUnit, true); + + if (!double.IsNaN(stresses[0].XX) && !double.IsNaN(stresses[0].YY) + && !double.IsNaN(stresses[0].ZZ)) { + xyzRes[stresses.Count] = GetQuantityResult(stresses[0], stressUnit); // add centre point at the end + } + + if (!double.IsNaN(stresses[0].XY) && !double.IsNaN(stresses[0].YZ) + && !double.IsNaN(stresses[0].ZX)) { + xxyyzzRes[stresses.Count] = GetQuantityResult(stresses[0], stressUnit, true); + } r.XyzResults.TryAdd(key, xyzRes); r.XxyyzzResults.TryAdd(key, xxyyzzRes); @@ -180,9 +199,16 @@ internal static GsaResultsValues GetElement2DResultValues( xxyyzzRes.AsParallel().AsOrdered(); ReadOnlyCollection shears = elementResults.Shear; - Parallel.For(1, shears.Count, i => xyzRes[i] = GetQuantityResult(shears[i], forceUnit)); - xyzRes[shears.Count] - = GetQuantityResult(shears[0], forceUnit); // add centre point at the end + Parallel.For(1, shears.Count, i => { + if (!double.IsNaN(shears[i].X) && !double.IsNaN(shears[i].Y)) { + xyzRes[i] = GetQuantityResult(shears[i], forceUnit); + } + }); + + if (!double.IsNaN(shears[0].X) && !double.IsNaN(shears[0].Y)) { + // add centre point at the end + xyzRes[shears.Count] = GetQuantityResult(shears[0], forceUnit); + } r.XyzResults.TryAdd(key, xyzRes); r.XxyyzzResults.TryAdd(key, xxyyzzRes); @@ -220,15 +246,26 @@ internal static GsaResultsValues GetElement2DResultValues( return; } - if (i < forces.Count) { + if (i < forces.Count && !double.IsNaN(forces[i].XX) && !double.IsNaN(forces[i].YY) + && !double.IsNaN(forces[i].XY)) { xyzRes[i] = GetQuantityResult(forces[i], forceUnit); - } else { + } else if (!double.IsNaN(moments[i - forces.Count].XX) + && !double.IsNaN(moments[i - forces.Count].YY) + && !double.IsNaN(moments[i - forces.Count].XY)) { xxyyzzRes[i - forces.Count] = GetQuantityResult(moments[i - forces.Count], momentUnit); } }); - xyzRes[forces.Count] - = GetQuantityResult(forces[0], forceUnit); // add centre point at the end - xxyyzzRes[moments.Count] = GetQuantityResult(moments[0], momentUnit); + + if (!double.IsNaN(forces[0].XX) && !double.IsNaN(forces[0].YY) + && !double.IsNaN(forces[0].XY)) { + // add centre point at the end + xyzRes[forces.Count] = GetQuantityResult(forces[0], forceUnit); + } + + if (!double.IsNaN(moments[0].XX) && !double.IsNaN(moments[0].YY) + && !double.IsNaN(moments[0].XY)) { + xxyyzzRes[moments.Count] = GetQuantityResult(moments[0], momentUnit); + } Parallel.ForEach(xxyyzzRes.Keys, i => { xyzRes[i].Xyz = new Force( @@ -272,15 +309,24 @@ internal static GsaResultsValues GetElement2DResultValues( return; } - if (i < disp.Count) { + if (i < disp.Count && !double.IsNaN(disp[i].X) && !double.IsNaN(disp[i].Y) + && !double.IsNaN(disp[i].Z)) { xyzRes[i] = GetQuantityResult(disp[i], resultLengthUnit); - } else { + } else if (!double.IsNaN(disp[i - disp.Count].XX) + && !double.IsNaN(disp[i - disp.Count].YY) + && !double.IsNaN(disp[i - disp.Count].ZZ)) { xxyyzzRes[i - disp.Count] = GetQuantityResult(disp[i - disp.Count], AngleUnit.Radian); } }); - xyzRes[disp.Count] - = GetQuantityResult(disp[0], resultLengthUnit); // add centre point at the end - xxyyzzRes[disp.Count - disp.Count] = GetQuantityResult(disp[0], AngleUnit.Radian); + + if (!double.IsNaN(disp[0].X) && !double.IsNaN(disp[0].Y) && !double.IsNaN(disp[0].Z)) { + // add centre point at the end + xyzRes[disp.Count] = GetQuantityResult(disp[0], resultLengthUnit); + } + + if (!double.IsNaN(disp[0].XX) && !double.IsNaN(disp[0].YY) && !double.IsNaN(disp[0].ZZ)) { + xxyyzzRes[disp.Count] = GetQuantityResult(disp[0], AngleUnit.Radian); + } r.XyzResults.TryAdd(key, xyzRes); r.XxyyzzResults.TryAdd(key, xxyyzzRes); @@ -308,10 +354,17 @@ internal static GsaResultsValues GetElement3DResultValues( xyzRes.AsParallel().AsOrdered(); ReadOnlyCollection transVals = elementResults.Displacement; - Parallel.For(1, transVals.Count, - i => xyzRes[i] = GetQuantityResult(transVals[i], resultLengthUnit)); - xyzRes[transVals.Count] - = GetQuantityResult(transVals[0], resultLengthUnit); // add centre point at the end + Parallel.For(1, transVals.Count, i => { + if (!double.IsNaN(transVals[i].X) && !double.IsNaN(transVals[i].Y) && !double.IsNaN(transVals[i].Z)) { + xyzRes[i] = GetQuantityResult(transVals[i], resultLengthUnit); + } + }); + + if (!double.IsNaN(transVals[0].X) && !double.IsNaN(transVals[0].Y) && !double.IsNaN(transVals[0].Z)) { + // add centre point at the end + xyzRes[transVals.Count] = GetQuantityResult(transVals[0], resultLengthUnit); + } + r.XyzResults.TryAdd(key, xyzRes); }); @@ -344,16 +397,27 @@ internal static GsaResultsValues GetElement3DResultValues( return; } - if (i < stressVals.Count) { + if (i < stressVals.Count && !double.IsNaN(stressVals[i].XX) + && !double.IsNaN(stressVals[i].YY) && !double.IsNaN(stressVals[i].ZZ)) { xyzRes[i] = GetQuantityResult(stressVals[i], stressUnit); - } else { + } else if (!double.IsNaN(stressVals[i - stressVals.Count].XY) + && !double.IsNaN(stressVals[i - stressVals.Count].YZ) + && !double.IsNaN(stressVals[i - stressVals.Count].ZX)) { xxyyzzRes[i - stressVals.Count] = GetQuantityResult(stressVals[i - stressVals.Count], stressUnit, true); } }); - xyzRes[stressVals.Count] - = GetQuantityResult(stressVals[0], stressUnit); // add centre point at the end - xxyyzzRes[stressVals.Count] = GetQuantityResult(stressVals[0], stressUnit, true); + + if (!double.IsNaN(stressVals[0].XX) + && !double.IsNaN(stressVals[0].YY) && !double.IsNaN(stressVals[0].ZZ)) { + // add centre point at the end + xyzRes[stressVals.Count] = GetQuantityResult(stressVals[0], stressUnit); + } + + if (!double.IsNaN(stressVals[0].XY) + && !double.IsNaN(stressVals[0].YZ) && !double.IsNaN(stressVals[0].ZX)) { + xxyyzzRes[stressVals.Count] = GetQuantityResult(stressVals[0], stressUnit, true); + } r.XyzResults.TryAdd(key, xyzRes); r.XxyyzzResults.TryAdd(key, xxyyzzRes); @@ -389,12 +453,17 @@ internal static GsaResultsValues GetNodeReactionForceResultValues( } } - var xyz = new ConcurrentDictionary(); - xyz.TryAdd(0, GetQuantityResult(values, forceUnit)); - r.XyzResults.TryAdd(nodeId, xyz); - var xxyyzz = new ConcurrentDictionary(); - xxyyzz.TryAdd(0, GetQuantityResult(values, momentUnit)); - r.XxyyzzResults.TryAdd(nodeId, xxyyzz); + if (!double.IsNaN(values.X) && !double.IsNaN(values.Y) && !double.IsNaN(values.Z)) { + var xyz = new ConcurrentDictionary(); + xyz.TryAdd(0, GetQuantityResult(values, forceUnit)); + r.XyzResults.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, momentUnit)); + r.XxyyzzResults.TryAdd(nodeId, xxyyzz); + } }); r.UpdateMinMax(); @@ -417,12 +486,17 @@ internal static GsaResultsValues GetNodeResultValues( NodeResult result = globalResults[nodeId]; Double6 values = result.Displacement; - var xyz = new ConcurrentDictionary(); - xyz.TryAdd(0, GetQuantityResult(values, resultLengthUnit)); - r.XyzResults.TryAdd(nodeId, xyz); - var xxyyzz = new ConcurrentDictionary(); - xxyyzz.TryAdd(0, GetQuantityResult(values, AngleUnit.Radian)); - r.XxyyzzResults.TryAdd(nodeId, xxyyzz); + 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); + } + + 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); + } }); r.UpdateMinMax(); @@ -456,12 +530,17 @@ internal static GsaResultsValues GetNodeSpringForceResultValues( } } - var xyz = new ConcurrentDictionary(); - xyz.TryAdd(0, GetQuantityResult(values, forceUnit)); - r.XyzResults.TryAdd(nodeId, xyz); - var xxyyzz = new ConcurrentDictionary(); - xxyyzz.TryAdd(0, GetQuantityResult(values, momentUnit)); - r.XxyyzzResults.TryAdd(nodeId, xxyyzz); + if (!double.IsNaN(values.X) && !double.IsNaN(values.Y) && !double.IsNaN(values.Z)) { + var xyz = new ConcurrentDictionary(); + xyz.TryAdd(0, GetQuantityResult(values, forceUnit)); + r.XyzResults.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, momentUnit)); + r.XxyyzzResults.TryAdd(nodeId, xxyyzz); + } }); r.UpdateMinMax(); diff --git a/GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs b/GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs index 6329f4c7a..4282d93dc 100644 --- a/GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs +++ b/GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs @@ -56,8 +56,15 @@ internal static ConcurrentDictionary GetElement1DResultVa xxyyzzRes.AsParallel().AsOrdered(); Parallel.For(0, values.Count, i => { - xyzRes.TryAdd(i, GetQuantityResult(values[i], forceUnit, true)); - xxyyzzRes.TryAdd(i, GetQuantityResult(values[i], momentUnit, true)); + if (!double.IsNaN(values[i].X) && !double.IsNaN(values[i].Y) + && !double.IsNaN(values[i].Z)) { + xyzRes.TryAdd(i, GetQuantityResult(values[i], forceUnit, true)); + } + + if (!double.IsNaN(values[i].XX) && !double.IsNaN(values[i].YY) + && !double.IsNaN(values[i].ZZ)) { + xxyyzzRes.TryAdd(i, GetQuantityResult(values[i], momentUnit, true)); + } }); r.XyzResults.TryAdd(key, xyzRes); r.XxyyzzResults.TryAdd(key, xxyyzzRes); @@ -161,8 +168,15 @@ internal static ConcurrentDictionary GetElement1DResultVa xxyyzzRes.AsParallel().AsOrdered(); Parallel.For(0, values.Count, i => { - xyzRes.TryAdd(i, GetQuantityResult(values[i], resultLengthUnit)); - xxyyzzRes.TryAdd(i, GetQuantityResult(values[i], AngleUnit.Radian)); + if (!double.IsNaN(values[i].X) && !double.IsNaN(values[i].Y) + && !double.IsNaN(values[i].Z)) { + xyzRes.TryAdd(i, GetQuantityResult(values[i], resultLengthUnit)); + } + + if (!double.IsNaN(values[i].XX) && !double.IsNaN(values[i].YY) + && !double.IsNaN(values[i].ZZ)) { + xxyyzzRes.TryAdd(i, GetQuantityResult(values[i], AngleUnit.Radian)); + } }); r.XyzResults.TryAdd(key, xyzRes); r.XxyyzzResults.TryAdd(key, xxyyzzRes); @@ -213,12 +227,25 @@ internal static ConcurrentDictionary GetElement2DResultVa xxyyzzRes.AsParallel().AsOrdered(); Parallel.For(1, values.Count, i => { - xyzRes.TryAdd(i, GetQuantityResult(values[i], stressUnit)); - xxyyzzRes.TryAdd(i, GetQuantityResult(values[i], stressUnit, true)); + if (!double.IsNaN(values[i].XX) && !double.IsNaN(values[i].YY) + && !double.IsNaN(values[i].ZZ)) { + xyzRes.TryAdd(i, GetQuantityResult(values[i], stressUnit)); + } + + if (!double.IsNaN(values[i].XY) && !double.IsNaN(values[i].YZ) + && !double.IsNaN(values[i].ZX)) { + xxyyzzRes.TryAdd(i, GetQuantityResult(values[i], stressUnit, true)); + } }); - xyzRes.TryAdd(values.Count, - GetQuantityResult(values[0], stressUnit)); // add centre point last - xxyyzzRes.TryAdd(values.Count, GetQuantityResult(values[0], stressUnit, true)); + if (!double.IsNaN(values[0].XX) && !double.IsNaN(values[0].YY) + && !double.IsNaN(values[0].ZZ)) { + xyzRes.TryAdd(values.Count, GetQuantityResult(values[0], stressUnit)); // add centre point last + } + + if (!double.IsNaN(values[0].XY) && !double.IsNaN(values[0].YZ) + && !double.IsNaN(values[0].ZX)) { + xxyyzzRes.TryAdd(values.Count, GetQuantityResult(values[0], stressUnit, true)); + } r.XyzResults.TryAdd(key, xyzRes); r.XxyyzzResults.TryAdd(key, xxyyzzRes); @@ -266,10 +293,17 @@ internal static ConcurrentDictionary GetElement2DResultVa var xyzRes = new ConcurrentDictionary(); xyzRes.AsParallel().AsOrdered(); - Parallel.For(1, values.Count, - i => xyzRes.TryAdd(i, GetQuantityResult(values[i], forceUnit))); - xyzRes.TryAdd(values.Count, - GetQuantityResult(values[0], forceUnit)); // add centre point last + Parallel.For(1, values.Count, i => { + if (!double.IsNaN(values[i].X) && !double.IsNaN(values[i].Y)) { + xyzRes.TryAdd(i, GetQuantityResult(values[i], forceUnit)); + } + }); + + if (!double.IsNaN(values[0].X) && !double.IsNaN(values[0].Y)) { + // add centre point last + xyzRes.TryAdd(values.Count, GetQuantityResult(values[0], forceUnit)); + } + r.XyzResults.TryAdd(key, xyzRes); }); r.UpdateMinMax(); @@ -320,12 +354,27 @@ internal static ConcurrentDictionary GetElement2DResultVa xxyyzzRes.AsParallel().AsOrdered(); Parallel.For(1, forceValues.Count, i => { - xyzRes.TryAdd(i, GetQuantityResult(forceValues[i], forceUnit)); - xxyyzzRes.TryAdd(i, GetQuantityResult(momentValues[i], momentUnit)); + if (!double.IsNaN(forceValues[i].XX) && !double.IsNaN(forceValues[i].YY) + && !double.IsNaN(forceValues[i].XY)) { + xyzRes.TryAdd(i, GetQuantityResult(forceValues[i], forceUnit)); + } + + if (!double.IsNaN(momentValues[i].XX) && !double.IsNaN(momentValues[i].YY) + && !double.IsNaN(momentValues[i].XY)) { + xxyyzzRes.TryAdd(i, GetQuantityResult(momentValues[i], momentUnit)); + } }); - xyzRes.TryAdd(forceValues.Count, - GetQuantityResult(forceValues[0], forceUnit)); // add centre point last - xxyyzzRes.TryAdd(forceValues.Count, GetQuantityResult(momentValues[0], momentUnit)); + + if (!double.IsNaN(forceValues[0].XX) && !double.IsNaN(forceValues[0].YY) + && !double.IsNaN(forceValues[0].XY)) { + xyzRes.TryAdd(forceValues.Count, + GetQuantityResult(forceValues[0], forceUnit)); // add centre point last + } + + if (!double.IsNaN(momentValues[0].XX) && !double.IsNaN(momentValues[0].YY) + && !double.IsNaN(momentValues[0].XY)) { + xxyyzzRes.TryAdd(forceValues.Count, GetQuantityResult(momentValues[0], momentUnit)); + } Parallel.ForEach(xxyyzzRes.Keys, i => { xyzRes[i].Xyz = new Force( @@ -384,8 +433,14 @@ internal static ConcurrentDictionary GetElement2DResultVa xxyyzzRes.AsParallel().AsOrdered(); Parallel.For(1, values.Count, i => { - xyzRes.TryAdd(i, GetQuantityResult(values[i], resultLengthUnit)); - xxyyzzRes.TryAdd(i, GetQuantityResult(values[i], AngleUnit.Radian)); + if (!double.IsNaN(values[i].X) && !double.IsNaN(values[i].Y) && !double.IsNaN(values[i].Z)) { + xyzRes.TryAdd(i, GetQuantityResult(values[i], resultLengthUnit)); + } + + if (!double.IsNaN(values[i].XX) && !double.IsNaN(values[i].YY) + && !double.IsNaN(values[i].ZZ)) { + xxyyzzRes.TryAdd(i, GetQuantityResult(values[i], AngleUnit.Radian)); + } }); xyzRes.TryAdd(values.Count, GetQuantityResult(values[0], resultLengthUnit)); // add centre point last @@ -436,10 +491,17 @@ internal static ConcurrentDictionary GetElement3DResultVa var xyzRes = new ConcurrentDictionary(); xyzRes.AsParallel().AsOrdered(); - Parallel.For(1, values.Count, - i => xyzRes.TryAdd(i, GetQuantityResult(values[i], lengthUnit))); - xyzRes[values.Count] - = GetQuantityResult(values[0], lengthUnit); // add centre point at the end + Parallel.For(1, values.Count, i => { + if (!double.IsNaN(values[i].X) && !double.IsNaN(values[i].Y) + && !double.IsNaN(values[i].Z)) { + xyzRes.TryAdd(i, GetQuantityResult(values[i], lengthUnit)); + } + }); + if (!double.IsNaN(values[0].X) && !double.IsNaN(values[0].Y) + && !double.IsNaN(values[0].Z)) { + xyzRes[values.Count] = GetQuantityResult(values[0], lengthUnit); // add centre point at the end + } + r.XyzResults.TryAdd(key, xyzRes); }); r.UpdateMinMax(); @@ -488,12 +550,26 @@ internal static ConcurrentDictionary GetElement3DResultVa xxyyzzRes.AsParallel().AsOrdered(); Parallel.For(1, values.Count, i => { - xyzRes.TryAdd(i, GetQuantityResult(values[i], stressUnit)); - xxyyzzRes.TryAdd(i, GetQuantityResult(values[i], stressUnit, true)); + if (!double.IsNaN(values[i].XX) && !double.IsNaN(values[i].YY) + && !double.IsNaN(values[i].ZZ)) { + xyzRes.TryAdd(i, GetQuantityResult(values[i], stressUnit)); + } + + if (!double.IsNaN(values[i].XY) && !double.IsNaN(values[i].YZ) + && !double.IsNaN(values[i].ZX)) { + xxyyzzRes.TryAdd(i, GetQuantityResult(values[i], stressUnit, true)); + } }); - xyzRes[values.Count] - = GetQuantityResult(values[0], stressUnit); // add centre point at the end - xxyyzzRes[values.Count] = GetQuantityResult(values[0], stressUnit, true); + if (!double.IsNaN(values[0].XX) && !double.IsNaN(values[0].YY) + && !double.IsNaN(values[0].ZZ)) { + // add centre point at the end + xyzRes[values.Count] = GetQuantityResult(values[0], stressUnit); + } + + if (!double.IsNaN(values[0].XY) && !double.IsNaN(values[0].YZ) + && !double.IsNaN(values[0].ZX)) { + xxyyzzRes[values.Count] = GetQuantityResult(values[0], stressUnit, true); + } r.XyzResults.TryAdd(key, xyzRes); r.XxyyzzResults.TryAdd(key, xxyyzzRes); @@ -541,18 +617,23 @@ internal static ConcurrentDictionary GetNodeReactionForce Double6 values = result.Reaction; if (supportnodeIDs != null && !supportnodeIDs.Contains(nodeId)) { - if (values.X == 0 & values.Y == 0 & values.Z == 0 & values.XX == 0 & values.YY == 0 - & values.ZZ == 0) { + if (values.X == 0 & values.Y == 0 & values.Z == 0 + & values.XX == 0 & values.YY == 0 & values.ZZ == 0) { return; } } - var xyz = new ConcurrentDictionary(); - xyz.TryAdd(0, GetQuantityResult(values, forceUnit)); - r.XyzResults.TryAdd(nodeId, xyz); - var xxyyzz = new ConcurrentDictionary(); - xxyyzz.TryAdd(0, GetQuantityResult(values, momentUnit)); - r.XxyyzzResults.TryAdd(nodeId, xxyyzz); + if (!double.IsNaN(values.X) && !double.IsNaN(values.Y) && !double.IsNaN(values.Z)) { + var xyz = new ConcurrentDictionary(); + xyz.TryAdd(0, GetQuantityResult(values, forceUnit)); + r.XyzResults.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, momentUnit)); + r.XxyyzzResults.TryAdd(nodeId, xxyyzz); + } }); r.UpdateMinMax(); @@ -592,12 +673,17 @@ internal static ConcurrentDictionary GetNodeResultValues( NodeResult result = results[permutationId - 1]; Double6 values = result.Displacement; - var xyz = new ConcurrentDictionary(); - xyz.TryAdd(0, GetQuantityResult(values, resultLengthUnit)); - r.XyzResults.TryAdd(nodeId, xyz); - var xxyyzz = new ConcurrentDictionary(); - xxyyzz.TryAdd(0, GetQuantityResult(values, AngleUnit.Radian)); - r.XxyyzzResults.TryAdd(nodeId, xxyyzz); + 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); + } + + 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); + } }); r.UpdateMinMax(); @@ -649,12 +735,17 @@ internal static ConcurrentDictionary GetNodeSpringForceRe } } - var xyz = new ConcurrentDictionary(); - xyz.TryAdd(0, GetQuantityResult(values, forceUnit)); - r.XyzResults.TryAdd(nodeId, xyz); - var xxyyzz = new ConcurrentDictionary(); - xxyyzz.TryAdd(0, GetQuantityResult(values, momentUnit)); - r.XxyyzzResults.TryAdd(nodeId, xxyyzz); + if (!double.IsNaN(values.X) && !double.IsNaN(values.Y) && !double.IsNaN(values.Z)) { + var xyz = new ConcurrentDictionary(); + xyz.TryAdd(0, GetQuantityResult(values, forceUnit)); + r.XyzResults.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, momentUnit)); + r.XxyyzzResults.TryAdd(nodeId, xxyyzz); + } }); r.UpdateMinMax(); diff --git a/GsaGH/Helpers/GsaAPI/Results/QuantityResults.cs b/GsaGH/Helpers/GsaAPI/Results/QuantityResults.cs index 072e53dd2..72309e4b4 100644 --- a/GsaGH/Helpers/GsaAPI/Results/QuantityResults.cs +++ b/GsaGH/Helpers/GsaAPI/Results/QuantityResults.cs @@ -29,6 +29,10 @@ internal static GsaResultQuantity GetQuantityResult( } internal static GsaResultQuantity GetQuantityResult(double result, EnergyUnit unit) { + if (double.IsNaN(result)) { + return new GsaResultQuantity(); + } + IQuantity x = new Energy(new Energy(result, EnergyUnit.Joule).As(unit), unit); return new GsaResultQuantity() { @@ -84,34 +88,35 @@ double pyth internal static GsaResultQuantity GetQuantityResult(Double6 result, AngleUnit unit) { IQuantity x; - if ( - !double.IsNaN(result - .XX)) // TO-DO: GSA-5351 remove NaN and Infinity values from GsaAPI results - { - x = !double.IsInfinity(result.XX) ? - new Angle(new Angle(result.XX, AngleUnit.Radian).As(unit), unit) : - (IQuantity)(double.IsPositiveInfinity(result.XX) ? new Angle(360, AngleUnit.Degree) : - new Angle(-360, AngleUnit.Degree)); + if (!double.IsNaN(result.XX)) { + // TO-DO: GSA-5351 remove NaN and Infinity values from GsaAPI results + x = !double.IsInfinity(result.XX) + ? new Angle(new Angle(result.XX, AngleUnit.Radian).As(unit), unit) + : (IQuantity)(double.IsPositiveInfinity(result.XX) + ? new Angle(360, AngleUnit.Degree) + : new Angle(-360, AngleUnit.Degree)); } else { x = new Angle(0, unit); } IQuantity y; if (!double.IsNaN(result.YY)) { - y = !double.IsInfinity(result.YY) ? - new Angle(new Angle(result.YY, AngleUnit.Radian).As(unit), unit) : - (IQuantity)(double.IsPositiveInfinity(result.YY) ? new Angle(360, AngleUnit.Degree) : - new Angle(-360, AngleUnit.Degree)); + y = !double.IsInfinity(result.YY) + ? new Angle(new Angle(result.YY, AngleUnit.Radian).As(unit), unit) + : (IQuantity)(double.IsPositiveInfinity(result.YY) + ? new Angle(360, AngleUnit.Degree) + : new Angle(-360, AngleUnit.Degree)); } else { y = new Angle(0, unit); } IQuantity z; if (!double.IsNaN(result.ZZ)) { - z = !double.IsInfinity(result.ZZ) ? - new Angle(new Angle(result.ZZ, AngleUnit.Radian).As(unit), unit) : - (IQuantity)(double.IsPositiveInfinity(result.ZZ) ? new Angle(360, AngleUnit.Degree) : - new Angle(-360, AngleUnit.Degree)); + z = !double.IsInfinity(result.ZZ) + ? new Angle(new Angle(result.ZZ, AngleUnit.Radian).As(unit), unit) + : (IQuantity)(double.IsPositiveInfinity(result.ZZ) + ? new Angle(360, AngleUnit.Degree) + : new Angle(-360, AngleUnit.Degree)); } else { z = new Angle(0, unit); } From 2eef142562d008d571f103a4db82e47ef5be8887 Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Fri, 6 Oct 2023 15:05:15 +0200 Subject: [PATCH 2/4] fix wrong index --- GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs | 5 +++-- GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs b/GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs index f75816f52..39f2291a4 100644 --- a/GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs +++ b/GsaGH/Helpers/GsaAPI/Results/AnalysisCaseQuantities.cs @@ -154,8 +154,9 @@ internal static GsaResultsValues GetElement2DResultValues( if (i < stresses.Count && !double.IsNaN(stresses[i].XX) && !double.IsNaN(stresses[i].YY) && !double.IsNaN(stresses[i].ZZ)) { xyzRes[i] = GetQuantityResult(stresses[i], stressUnit); - } else if (!double.IsNaN(stresses[i].XY) && !double.IsNaN(stresses[i].YZ) - && !double.IsNaN(stresses[i].ZX)) { + } else if (!double.IsNaN(stresses[i - stresses.Count].XY) + && !double.IsNaN(stresses[i - stresses.Count].YZ) + && !double.IsNaN(stresses[i - stresses.Count].ZX)) { xxyyzzRes[i - stresses.Count] = GetQuantityResult(stresses[i - stresses.Count], stressUnit, true); } diff --git a/GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs b/GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs index 4282d93dc..e6f4dc135 100644 --- a/GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs +++ b/GsaGH/Helpers/GsaAPI/Results/CombinationCaseQuantities.cs @@ -493,12 +493,12 @@ internal static ConcurrentDictionary GetElement3DResultVa Parallel.For(1, values.Count, i => { if (!double.IsNaN(values[i].X) && !double.IsNaN(values[i].Y) - && !double.IsNaN(values[i].Z)) { + && !double.IsNaN(values[i].Z)) { xyzRes.TryAdd(i, GetQuantityResult(values[i], lengthUnit)); } }); if (!double.IsNaN(values[0].X) && !double.IsNaN(values[0].Y) - && !double.IsNaN(values[0].Z)) { + && !double.IsNaN(values[0].Z)) { xyzRes[values.Count] = GetQuantityResult(values[0], lengthUnit); // add centre point at the end } From 9867c5370d78104e72037954996b19b5db06a23f Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Fri, 6 Oct 2023 15:05:40 +0200 Subject: [PATCH 3/4] loop over verticy count instead of result count after GsaAPI returns more 3d results --- GsaGH/Components/6_Display/Contour3dResults.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/GsaGH/Components/6_Display/Contour3dResults.cs b/GsaGH/Components/6_Display/Contour3dResults.cs index 514e68e3c..c476fbe89 100644 --- a/GsaGH/Components/6_Display/Contour3dResults.cs +++ b/GsaGH/Components/6_Display/Contour3dResults.cs @@ -458,6 +458,10 @@ protected override void SolveInternal(IGH_DataAccess da) { ReadOnlyDictionary elems = result.Model.Model.Elements(elementlist); ReadOnlyDictionary nodes = result.Model.Model.Nodes(); + if (elems.Count == 0) { + this.AddRuntimeError($"Model contains no results for elements in list '{elementlist}'"); + return; + }; ConcurrentDictionary> xyzResults = res.XyzResults; @@ -676,9 +680,8 @@ ConcurrentDictionary> xxyyzzRe break; } - for (int i = 0; i < vals.Count - 1; - i++) // start at i=0, now the last index is the centre point in GsaAPI output so to count -1 - { + // start at i=0, now the last index is the centre point in GsaAPI output so to count -1 + for (int i = 0; i < tempmesh.Vertices.Count; i++) { double tnorm = (2 * (vals[i].Value - dmin) / (dmax - dmin)) - 1; Color col = double.IsNaN(tnorm) ? Color.Transparent : ghGradient.ColourAt(tnorm); tempmesh.VertexColors.Add(col); From c4fa90da63d86a164c20d3c3857a61e896afb44e Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Fri, 6 Oct 2023 15:06:01 +0200 Subject: [PATCH 4/4] check if elements/nodes exist and return early if not --- GsaGH/Components/6_Display/Contour1dResults.cs | 4 ++++ GsaGH/Components/6_Display/Contour2dResults.cs | 4 ++++ GsaGH/Components/6_Display/ContourNodeResults.cs | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/GsaGH/Components/6_Display/Contour1dResults.cs b/GsaGH/Components/6_Display/Contour1dResults.cs index 01a1ae35d..00e7d0a18 100644 --- a/GsaGH/Components/6_Display/Contour1dResults.cs +++ b/GsaGH/Components/6_Display/Contour1dResults.cs @@ -585,6 +585,10 @@ var footfallType var elems = new ConcurrentDictionary(result.Model.Model.Elements(elementlist)); var nodes = new ConcurrentDictionary(result.Model.Model.Nodes()); + if (elems.Count == 0) { + this.AddRuntimeError($"Model contains no results for elements in list '{elementlist}'"); + return; + }; ConcurrentDictionary> xyzResults = res.XyzResults; diff --git a/GsaGH/Components/6_Display/Contour2dResults.cs b/GsaGH/Components/6_Display/Contour2dResults.cs index 93c69b810..7048aad0f 100644 --- a/GsaGH/Components/6_Display/Contour2dResults.cs +++ b/GsaGH/Components/6_Display/Contour2dResults.cs @@ -634,6 +634,10 @@ var footfallType ReadOnlyDictionary elems = result.Model.Model.Elements(elementlist); ReadOnlyDictionary nodes = result.Model.Model.Nodes(); + if (elems.Count == 0) { + this.AddRuntimeError($"Model contains no results for elements in list '{elementlist}'"); + return; + }; ConcurrentDictionary> xyzResults = _isShear ? resShear.XyzResults : res.XyzResults; diff --git a/GsaGH/Components/6_Display/ContourNodeResults.cs b/GsaGH/Components/6_Display/ContourNodeResults.cs index d115e742a..f842ee4fa 100644 --- a/GsaGH/Components/6_Display/ContourNodeResults.cs +++ b/GsaGH/Components/6_Display/ContourNodeResults.cs @@ -502,6 +502,10 @@ var footfallType } ReadOnlyDictionary nodes = result.Model.Model.Nodes(nodeList); + if (nodes.Count == 0) { + this.AddRuntimeError($"Model contains no results for nodes in list '{nodeList}'"); + return; + } ConcurrentDictionary> xyzResults = res.XyzResults;