Skip to content

Commit

Permalink
GSAGH-366 beam displacements
Browse files Browse the repository at this point in the history
  • Loading branch information
Tilman Reinhardt committed Oct 27, 2023
1 parent 0ddf403 commit df1cea2
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 6 deletions.
10 changes: 6 additions & 4 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 @@ -100,7 +102,7 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) {
}

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

string elementlist = "All";

Expand Down Expand Up @@ -130,15 +132,15 @@ protected override void SolveInternal(IGH_DataAccess da) {
}

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

List<GsaResultsValues> vals
= result.Element1DDisplacementValues(elementlist, positionsCount, -1, _lengthUnit);
ReadOnlyCollection<int> elementIds = result.ElementIds(elementlist);
IBeamResultSubset<IBeamDisplacement, ResultVector6<NodeExtremaKey>> resultSet = result.BeamDisplacements.ResultSubset(elementIds, positionsCount);

List<int> permutations = result.SelectedPermutationIds is null ? new List<int>() {
1,
Expand Down
7 changes: 5 additions & 2 deletions GsaGH/Parameters/5_Results/2_Results/GsaResult2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace GsaGH.Parameters.Results {

public class GsaResult2 : IGsaResult {
// Caches
public INodeResultCache<IDisplacement, NodeExtremaVector6> NodeDisplacements { get; private set; }
public IBeamResultCache<IBeamDisplacement, ResultVector6<NodeExtremaKey>> BeamDisplacements { get; private set; }
public INodeResultCache<IDisplacement, ResultVector6<NodeExtremaKey>> NodeDisplacements { get; private set; }

// Other members
public int CaseId { get; set; }
Expand All @@ -24,11 +25,13 @@ internal GsaResult2(GsaResult result) {
CaseId = result.CaseId;
switch (CaseType) {
case CaseType.AnalysisCase:
BeamDisplacements = new BeamDisplacementCache(result.AnalysisCaseResult);
NodeDisplacements = new NodeDisplacementCache(result.AnalysisCaseResult);
break;

case CaseType.CombinationCase:
SelectedPermutationIds = result.SelectedPermutationIds;
BeamDisplacements = new BeamDisplacementCache(result.CombinationCaseResult);
NodeDisplacements = new NodeDisplacementCache(result.CombinationCaseResult);
break;
}
Expand Down Expand Up @@ -98,4 +101,4 @@ internal ReadOnlyCollection<int> MemberIds(string memberList) {
return Model.Model.ExpandList(entityList);
}
}
}
}
61 changes: 61 additions & 0 deletions GsaGH/Parameters/5_Results/3_Caches/BeamDisplacementCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Eto.Forms;
using GsaAPI;

namespace GsaGH.Parameters.Results {
public class BeamDisplacementCache : IBeamResultCache<IBeamDisplacement, ResultVector6<NodeExtremaKey>> {
public IApiResult ApiResult { get; set; }

public ConcurrentDictionary<int, Collection<IBeamDisplacement>> Cache { get; }
= new ConcurrentDictionary<int, Collection<IBeamDisplacement>>();

internal BeamDisplacementCache(AnalysisCaseResult result) {
ApiResult = new ApiResult(result);
}

internal BeamDisplacementCache(CombinationCaseResult result) {
ApiResult = new ApiResult(result);
}

public IBeamResultSubset<IBeamDisplacement, ResultVector6<NodeExtremaKey>> ResultSubset(ICollection<int> elementIds, int positionCount) {

var positions = Enumerable.Range(0, positionCount).Select(i => (double)i / (positionCount - 1)).ToList();

return ResultSubset(elementIds, new ReadOnlyCollection<double>(positions));
}

public IBeamResultSubset<IBeamDisplacement, ResultVector6<NodeExtremaKey>> ResultSubset(ICollection<int> elementIds, ReadOnlyCollection<double> positions) {
ConcurrentBag<int> missingIds = Cache.GetMissingKeys(elementIds);
if (missingIds.Count > 0) {
string elementList = string.Join(" ", missingIds);
switch (ApiResult.Result) {
case AnalysisCaseResult analysisCase:
ReadOnlyDictionary<int, ReadOnlyCollection<Double6>> aCaseResults = analysisCase.Element1dDisplacement(elementList, positions);
Parallel.ForEach(missingIds, nodeId => {
var res = new BeamDisplacement(aCaseResults[nodeId], positions);
Cache.TryAdd(nodeId, new Collection<IBeamDisplacement>() { res });
});
break;

case CombinationCaseResult combinationCase:
ReadOnlyDictionary<int, ReadOnlyCollection<ReadOnlyCollection<Double6>>> cCaseResults = combinationCase.Element1dDisplacement(elementList, positions);
Parallel.ForEach(missingIds, nodeId => {
var permutationResults = new Collection<IBeamDisplacement>();
foreach (ReadOnlyCollection<Double6> permutationResult in cCaseResults[nodeId]) {
permutationResults.Add(new BeamDisplacement(permutationResult, positions));
}

Cache.TryAdd(nodeId, permutationResults);
});
break;
}
}

return new BeamDisplacements(Cache.GetSubset(elementIds));
}
}
}
12 changes: 12 additions & 0 deletions GsaGH/Parameters/5_Results/3_Caches/IBeamResultCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace GsaGH.Parameters.Results {
public interface IBeamResultCache<T1, T2> where T1 : IResultItem {
IApiResult ApiResult { get; }
ConcurrentDictionary<int, Collection<T1>> Cache { get; }
IBeamResultSubset<T1, T2> ResultSubset(ICollection<int> elementIds, int positionCount);
IBeamResultSubset<T1, T2> ResultSubset(ICollection<int> elementIds, ReadOnlyCollection<double> positions);
}
}
26 changes: 26 additions & 0 deletions GsaGH/Parameters/5_Results/4_Subsets/BeamDisplacements.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using OasysUnits;

namespace GsaGH.Parameters.Results {
public class BeamDisplacements : IBeamResultSubset<IBeamDisplacement, ResultVector6<NodeExtremaKey>> {
public ResultVector6<NodeExtremaKey> Max { get; private set; }
public ResultVector6<NodeExtremaKey> Min { get; private set; }
public IList<int> Ids { get; private set; }

public ConcurrentDictionary<int, Collection<IBeamDisplacement>> Subset { get; }
= new ConcurrentDictionary<int, Collection<IBeamDisplacement>>();

public BeamDisplacements(ConcurrentDictionary<int, Collection<IBeamDisplacement>> results) {
Subset = results;
Ids = results.Keys.OrderBy(x => x).ToList();
(Max, Min) = results.Extrema();
}

public IBeamDisplacement GetExtrema(NodeExtremaKey key) {
return Subset[key.Id][key.Permutation];
}
}
}
18 changes: 18 additions & 0 deletions GsaGH/Parameters/5_Results/4_Subsets/IBeamResultSubset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace GsaGH.Parameters.Results {
public interface IBeamResultSubset<T1, T2> where T1 : IResultItem {
T2 Max { get; }
T2 Min { get; }
IList<int> Ids { get; }
/// <summary>
/// <para> Key = Node Id
/// </para>
/// Value = Collection of results, one for each permutation. Collection will have 1 item in case of AnalysisCase
/// </summary>
ConcurrentDictionary<int, Collection<T1>> Subset { get; }
T1 GetExtrema(NodeExtremaKey key);
}
}
30 changes: 30 additions & 0 deletions GsaGH/Parameters/5_Results/6_Quantities/BeamDisplacement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using GsaAPI;

namespace GsaGH.Parameters.Results {
public class BeamDisplacement : IBeamDisplacement {
public ICollection<IDisplacement> Displacements { get; }
public ICollection<double> Positions { get; }

internal BeamDisplacement(ICollection<Double6> result, ICollection<double> positions) {
foreach (Double6 item in result) {
Displacements.Add(new Displacement(item));
}
Positions = positions;
}

//private Angle CreateAngle(double val) {
// // TO-DO: GSA-5351 remove NaN and Infinity values from GsaAPI results
// if (!double.IsNaN(val)) {
// return !double.IsInfinity(val)
// ? new Angle(val, AngleUnit.Radian)
// : (double.IsPositiveInfinity(val)
// ? new Angle(360, AngleUnit.Degree)
// : new Angle(-360, AngleUnit.Degree));
// } else {
// return Angle.Zero;
// }
//}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Collections.Generic;

namespace GsaGH.Parameters.Results {
public interface IBeamDisplacement : IResultItem {
ICollection<IDisplacement> Displacements { get; }
}
}

0 comments on commit df1cea2

Please sign in to comment.