Skip to content

Commit

Permalink
merge epic branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristjan Nielsen committed Nov 2, 2023
2 parents a533927 + 7e85b4b commit 8fb7587
Show file tree
Hide file tree
Showing 21 changed files with 1,567 additions and 272 deletions.
83 changes: 53 additions & 30 deletions GsaGH/Parameters/5_Results/2_Results/GsaResult2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,49 @@ public class GsaResult2 : IGsaResult {
// Caches
public IElement1dResultCache<IElement1dDisplacement, IDisplacement, ResultVector6<Element1dExtremaKey>> BeamDisplacements { get; private set; }
public INodeResultCache<IDisplacement, ResultVector6<NodeExtremaKey>> NodeDisplacements { get; private set; }

// Other members
public int CaseId { get; set; }
public string CaseName { get; set; }
public GsaModel Model { get; set; }
public List<int> SelectedPermutationIds { get; set; }
public CaseType CaseType { get; set; }
public INodeResultCache<IDisplacement, ResultVector6<NodeExtremaKey>> NodeDisplacements {
get;
private set;
}
public INodeResultCache<IInternalForce, ResultVector6<NodeExtremaKey>> NodeReactionForces {
get;
private set;
}
public INodeResultCache<IInternalForce, ResultVector6<NodeExtremaKey>> NodeSpringForces {
get;
private set;
}

// temp conversion from old class
internal GsaResult2(GsaResult result) {
Model = result.Model;
CaseType = result.CaseType;
CaseId = result.CaseId;
switch (CaseType) {
switch (result.CaseType) {
case CaseType.AnalysisCase:
BeamDisplacements = new Element1dDisplacementCache(result.AnalysisCaseResult);
NodeDisplacements = new NodeDisplacementCache(result.AnalysisCaseResult);
InitialiseAnalysisCaseResults(result.Model, result.AnalysisCaseResult, result.CaseId);
break;

case CaseType.CombinationCase:
SelectedPermutationIds = result.SelectedPermutationIds;
BeamDisplacements = new Element1dDisplacementCache(result.CombinationCaseResult);
NodeDisplacements = new NodeDisplacementCache(result.CombinationCaseResult);
InitialiseCombinationsCaseResults(result.Model, result.CombinationCaseResult,
result.CaseId, result.SelectedPermutationIds);
break;
}
}

internal GsaResult2(GsaModel model, AnalysisCaseResult result, int caseId) {
Model = model;
CaseType = CaseType.AnalysisCase;
CaseId = caseId;
CaseName = model.Model.AnalysisCaseName(CaseId);
NodeDisplacements = new NodeDisplacementCache(result);
InitialiseAnalysisCaseResults(model, result, caseId);
}

internal GsaResult2(
GsaModel model, CombinationCaseResult result, int caseId, IEnumerable<int> permutations) {
Model = model;
CaseType = CaseType.CombinationCase;
CaseId = caseId;
SelectedPermutationIds = permutations.OrderBy(x => x).ToList();
NodeDisplacements = new NodeDisplacementCache(result);
InitialiseCombinationsCaseResults(model, result, caseId, permutations.OrderBy(x => x));
}

// Other members
public int CaseId { get; set; }
public string CaseName { get; set; }
public GsaModel Model { get; set; }
public List<int> SelectedPermutationIds { get; set; }
public CaseType CaseType { get; set; }

public override string ToString() {
string txt = string.Empty;
switch (CaseType) {
Expand All @@ -78,7 +77,7 @@ internal ReadOnlyCollection<int> NodeIds(string nodeList) {
var entityList = new EntityList() {
Definition = nodeList,
Type = GsaAPI.EntityType.Node,
Name = "node"
Name = "node",
};
return Model.Model.ExpandList(entityList);
}
Expand All @@ -87,7 +86,7 @@ internal ReadOnlyCollection<int> ElementIds(string elementList) {
var entityList = new EntityList() {
Definition = elementList,
Type = GsaAPI.EntityType.Element,
Name = "elem"
Name = "elem",
};
return Model.Model.ExpandList(entityList);
}
Expand All @@ -96,9 +95,33 @@ internal ReadOnlyCollection<int> MemberIds(string memberList) {
var entityList = new EntityList() {
Definition = memberList,
Type = GsaAPI.EntityType.Member,
Name = "mem"
Name = "mem",
};
return Model.Model.ExpandList(entityList);
}

private void InitialiseAnalysisCaseResults(
GsaModel model, AnalysisCaseResult result, int caseId) {
Model = model;
CaseType = CaseType.AnalysisCase;
CaseId = caseId;
CaseName = model.Model.AnalysisCaseName(CaseId);

NodeDisplacements = new NodeDisplacementCache(result);
NodeReactionForces = new NodeReactionForceCache(result, model.Model);
NodeSpringForces = new NodeSpringForceCache(result);
}

private void InitialiseCombinationsCaseResults(
GsaModel model, CombinationCaseResult result, int caseId, IEnumerable<int> permutations) {
Model = model;
CaseType = CaseType.CombinationCase;
CaseId = caseId;
SelectedPermutationIds = permutations.ToList();

NodeDisplacements = new NodeDisplacementCache(result);
NodeReactionForces = new NodeReactionForceCache(result, model.Model);
NodeSpringForces = new NodeSpringForceCache(result);
}
}
}
83 changes: 83 additions & 0 deletions GsaGH/Parameters/5_Results/3_Caches/NodeReactionForceCache.cs
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 GsaGH/Parameters/5_Results/3_Caches/NodeSpringForceCache.cs
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));
}
}
}
26 changes: 26 additions & 0 deletions GsaGH/Parameters/5_Results/4_Subsets/NodeForceSubset.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;

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];
}
}
}
25 changes: 13 additions & 12 deletions GsaGH/Parameters/5_Results/6_Quantities/InternalForce.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
using GsaAPI;
using OasysUnits;
using OasysUnits.Units;
using ForceUnit = OasysUnits.Units.ForceUnit;
using MomentUnit = OasysUnits.Units.MomentUnit;

namespace GsaGH.Parameters.Results {
public class InternalForce : IInternalForce {

internal InternalForce(Double6 result) {
X = new Force(result.X, ForceUnit.Newton);
Y = new Force(result.Y, ForceUnit.Newton);
Z = new Force(result.Z, ForceUnit.Newton);
Xyz = QuantityUtility.PythagoreanQuadruple(X, Y, Z);
Xx = new Moment(result.XX, MomentUnit.NewtonMeter);
Yy = new Moment(result.YY, MomentUnit.NewtonMeter);
Zz = new Moment(result.ZZ, MomentUnit.NewtonMeter);
Xxyyzz = QuantityUtility.PythagoreanQuadruple(Xx, Yy, Zz);
}

public Force X { get; internal set; }
public Force Y { get; internal set; }
public Force Z { get; internal set; }
Expand All @@ -13,16 +25,5 @@ public class InternalForce : IInternalForce {
public Moment Yy { get; internal set; }
public Moment Zz { get; internal set; }
public Moment Xxyyzz { get; internal set; }

internal InternalForce(Double6 result) {
X = new Force(result.X, ForceUnit.Newton);
Y = new Force(result.Y, ForceUnit.Newton);
Z = new Force(result.Z, ForceUnit.Newton);
Xyz = QuantityUtility.PythagoreanTriple(Y, Z);
Xx = new Moment(result.XX, MomentUnit.NewtonMeter);
Yy = new Moment(result.XX, MomentUnit.NewtonMeter);
Zz = new Moment(result.XX, MomentUnit.NewtonMeter);
Xxyyzz = QuantityUtility.PythagoreanTriple(Yy, Zz);
}
}
}
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,
}
}
Loading

0 comments on commit 8fb7587

Please sign in to comment.