-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tilman Reinhardt
committed
Oct 27, 2023
1 parent
0ddf403
commit df1cea2
Showing
8 changed files
with
165 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
GsaGH/Parameters/5_Results/3_Caches/BeamDisplacementCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
GsaGH/Parameters/5_Results/6_Quantities/BeamDisplacement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
// } | ||
//} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
GsaGH/Parameters/5_Results/7_QuantityInterfaces/IBeamDisplacement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |