-
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
Showing
21 changed files
with
1,567 additions
and
272 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
83 changes: 83 additions & 0 deletions
83
GsaGH/Parameters/5_Results/3_Caches/NodeReactionForceCache.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,83 @@ | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using GsaAPI; | ||
|
||
namespace GsaGH.Parameters.Results { | ||
public class | ||
NodeReactionForceCache : INodeResultCache<IInternalForce, ResultVector6<NodeExtremaKey>> { | ||
internal ConcurrentBag<int> SupportNodeIds { get; private set; } | ||
|
||
internal NodeReactionForceCache(AnalysisCaseResult result, Model model) { | ||
ApiResult = new ApiResult(result); | ||
SetSupportNodeIds(model); | ||
} | ||
|
||
internal NodeReactionForceCache(CombinationCaseResult result, Model model) { | ||
ApiResult = new ApiResult(result); | ||
SetSupportNodeIds(model); | ||
} | ||
|
||
public IApiResult ApiResult { get; set; } | ||
public ConcurrentDictionary<int, Collection<IInternalForce>> Cache { get; } | ||
= new ConcurrentDictionary<int, Collection<IInternalForce>>(); | ||
|
||
public INodeResultSubset<IInternalForce, ResultVector6<NodeExtremaKey>> ResultSubset( | ||
ICollection<int> nodeIds) { | ||
ConcurrentBag<int> missingIds = Cache.GetMissingKeys(nodeIds); | ||
|
||
if (missingIds.Count > 0) { | ||
string nodelist = string.Join(" ", missingIds); | ||
switch (ApiResult.Result) { | ||
case AnalysisCaseResult analysisCase: | ||
ReadOnlyDictionary<int, NodeResult> aCaseResults = analysisCase.NodeResults(nodelist); | ||
Parallel.ForEach(missingIds, nodeId => { | ||
if (!SupportNodeIds.Contains(nodeId)) { | ||
return; | ||
} | ||
|
||
var res = new InternalForce(aCaseResults[nodeId].Reaction); | ||
Cache.TryAdd(nodeId, new Collection<IInternalForce>() { | ||
res, | ||
}); | ||
}); | ||
break; | ||
|
||
case CombinationCaseResult combinationCase: | ||
ReadOnlyDictionary<int, ReadOnlyCollection<NodeResult>> cCaseResults | ||
= combinationCase.NodeResults(nodelist); | ||
Parallel.ForEach(missingIds, nodeId => { | ||
if (!SupportNodeIds.Contains(nodeId)) { | ||
return; | ||
} | ||
|
||
var permutationResults = new Collection<IInternalForce>(); | ||
foreach (NodeResult permutationResult in cCaseResults[nodeId]) { | ||
permutationResults.Add(new InternalForce(permutationResult.Reaction)); | ||
} | ||
|
||
Cache.TryAdd(nodeId, permutationResults); | ||
}); | ||
break; | ||
} | ||
} | ||
|
||
return new NodeForceSubset(Cache.GetSubset(nodeIds)); | ||
} | ||
|
||
private void SetSupportNodeIds(Model model) { | ||
ConcurrentBag<int> supportnodeIDs = null; | ||
supportnodeIDs = new ConcurrentBag<int>(); | ||
ReadOnlyDictionary<int, Node> nodes = model.Nodes(); | ||
Parallel.ForEach(nodes, node => { | ||
NodalRestraint rest = node.Value.Restraint; | ||
if (rest.X || rest.Y || rest.Z || rest.XX || rest.YY || rest.ZZ) { | ||
supportnodeIDs.Add(node.Key); | ||
} | ||
}); | ||
SupportNodeIds = supportnodeIDs; | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
GsaGH/Parameters/5_Results/3_Caches/NodeSpringForceCache.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,58 @@ | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Threading.Tasks; | ||
using GsaAPI; | ||
|
||
namespace GsaGH.Parameters.Results { | ||
public class | ||
NodeSpringForceCache : INodeResultCache<IInternalForce, ResultVector6<NodeExtremaKey>> { | ||
|
||
internal NodeSpringForceCache(AnalysisCaseResult result) { | ||
ApiResult = new ApiResult(result); | ||
} | ||
|
||
internal NodeSpringForceCache(CombinationCaseResult result) { | ||
ApiResult = new ApiResult(result); | ||
} | ||
|
||
public IApiResult ApiResult { get; set; } | ||
public ConcurrentDictionary<int, Collection<IInternalForce>> Cache { get; } | ||
= new ConcurrentDictionary<int, Collection<IInternalForce>>(); | ||
|
||
public INodeResultSubset<IInternalForce, ResultVector6<NodeExtremaKey>> ResultSubset( | ||
ICollection<int> nodeIds) { | ||
ConcurrentBag<int> missingIds = Cache.GetMissingKeys(nodeIds); | ||
|
||
if (missingIds.Count > 0) { | ||
string nodelist = string.Join(" ", missingIds); | ||
switch (ApiResult.Result) { | ||
case AnalysisCaseResult analysisCase: | ||
ReadOnlyDictionary<int, NodeResult> aCaseResults = analysisCase.NodeResults(nodelist); | ||
Parallel.ForEach(missingIds, nodeId => { | ||
var res = new InternalForce(aCaseResults[nodeId].SpringForce); | ||
Cache.TryAdd(nodeId, new Collection<IInternalForce>() { | ||
res, | ||
}); | ||
}); | ||
break; | ||
|
||
case CombinationCaseResult combinationCase: | ||
ReadOnlyDictionary<int, ReadOnlyCollection<NodeResult>> cCaseResults | ||
= combinationCase.NodeResults(nodelist); | ||
Parallel.ForEach(missingIds, nodeId => { | ||
var permutationResults = new Collection<IInternalForce>(); | ||
foreach (NodeResult permutationResult in cCaseResults[nodeId]) { | ||
permutationResults.Add(new InternalForce(permutationResult.SpringForce)); | ||
} | ||
|
||
Cache.TryAdd(nodeId, permutationResults); | ||
}); | ||
break; | ||
} | ||
} | ||
|
||
return new NodeForceSubset(Cache.GetSubset(nodeIds)); | ||
} | ||
} | ||
} |
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; | ||
|
||
namespace GsaGH.Parameters.Results { | ||
public class NodeForceSubset : INodeResultSubset<IInternalForce, ResultVector6<NodeExtremaKey>> { | ||
|
||
public NodeForceSubset(IDictionary<int, Collection<IInternalForce>> results) { | ||
Subset = results; | ||
Ids = results.Keys.OrderBy(x => x).ToList(); | ||
(Max, Min) = results.Extrema(); | ||
} | ||
|
||
public ResultVector6<NodeExtremaKey> Max { get; private set; } | ||
public ResultVector6<NodeExtremaKey> Min { get; private set; } | ||
public IList<int> Ids { get; private set; } | ||
|
||
public IDictionary<int, Collection<IInternalForce>> Subset { get; } | ||
= new ConcurrentDictionary<int, Collection<IInternalForce>>(); | ||
|
||
public IInternalForce 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
12 changes: 12 additions & 0 deletions
12
GsaGHTests/1_BaseParameters/5_Results/Collections/NodeComponentHelperEnum.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,12 @@ | ||
namespace GsaGHTests.Parameters.Results { | ||
public enum NodeComponentHelperEnum { | ||
X, | ||
Y, | ||
Z, | ||
Xyz, | ||
Xx, | ||
Yy, | ||
Zz, | ||
Xxyyzz, | ||
} | ||
} |
Oops, something went wrong.