Skip to content

Commit

Permalink
Updated new results
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristjan Nielsen committed Oct 17, 2023
1 parent 3a50700 commit bb438e0
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace GsaGH.Parameters.Results {
public class GsaDisplacementQuantity : IDisplacement {
public Length X { get; private set; }
public Length X { get; private set; }
public Length Xyz { get; private set; }
public Length Y { get; private set; }
public Length Z { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Parameters/5_Results/Quantities/ITranslation.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using OasysUnits;

namespace GsaGH.Parameters.Results {
public interface ITranslation {
public interface ITranslation : IResult {
public Length X { get; }
public Length Xyz { get; }
public Length Y { get; }
Expand Down
70 changes: 59 additions & 11 deletions GsaGH/Parameters/5_Results/ResultCollection/GsaNodeDisplacements.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,64 @@
using GsaGH.Parameters.Results;
using System;
using GsaAPI;
using GsaGH.Parameters.Results;
using OasysUnits;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;

namespace GsaGH.Parameters {

public class GsaNodeDisplacements : IResults<GsaDisplacementQuantity> {
public IResultDictionary<IResultCollection<GsaDisplacementQuantity>> ResultCache {
get => throw new NotImplementedException();
set => throw new NotImplementedException();
namespace GsaGH.Parameters.Results {
// For now, to be refactored
public class GsaNodeDisplacements : IResultSubset<IDisplacement> {
public IDisplacement Max { get; private set; }
public IDisplacement Min { get; private set; }
public List<int> Ids => Results.Keys.OrderBy(x => x).ToList();

/// <summary>
/// Combination Case Node Displacement Result VALUES Dictionary
/// Append to this dictionary to chache results
/// key = nodeId
/// value = Collection of permutations(permutationsResults)
/// </summary>
public ConcurrentDictionary<int, Collection<IDisplacement>> Results { get; }
= new ConcurrentDictionary<int, Collection<IDisplacement>>();

internal GsaNodeDisplacements(ReadOnlyDictionary<int, NodeResult> apiAnalysisCaseResults) {
Parallel.ForEach(apiAnalysisCaseResults.Keys, nodeId => {
var res = new GsaDisplacementQuantity(apiAnalysisCaseResults[nodeId].Displacement);
Results.TryAdd(nodeId, new Collection<IDisplacement>() { res });
});
UpdateMaxMin();
}

internal GsaNodeDisplacements(ReadOnlyDictionary<int, ReadOnlyCollection<NodeResult>> apiCombinationCaseResults) {
Parallel.ForEach(apiCombinationCaseResults.Keys, nodeId => {
var permutationResults = new Collection<IDisplacement>();
foreach (NodeResult permutationResult in apiCombinationCaseResults[nodeId]) {
permutationResults.Add(new GsaDisplacementQuantity(permutationResult.Displacement));
}

Results.TryAdd(nodeId, permutationResults);
});
UpdateMaxMin();
}

public IResultSubset<GsaDisplacementQuantity> GetResultSet(string definition) {
throw new NotImplementedException();
private void UpdateMaxMin() {
double maxX = Results.AsParallel().Select(list => list.Value.Select(res => res.X.Value).Max()).Max();
double maxY = Results.AsParallel().Select(list => list.Value.Select(res => res.Y.Value).Max()).Max();
double maxZ = Results.AsParallel().Select(list => list.Value.Select(res => res.Z.Value).Max()).Max();
double maxXx = Results.AsParallel().Select(list => list.Value.Select(res => res.Xx.Value).Max()).Max();
double maxYy = Results.AsParallel().Select(list => list.Value.Select(res => res.Yy.Value).Max()).Max();
double maxZz = Results.AsParallel().Select(list => list.Value.Select(res => res.Zz.Value).Max()).Max();
Max = new GsaDisplacementQuantity(new Double6(maxX, maxY, maxZ, maxXx, maxYy, maxZz));

double minX = Results.AsParallel().Select(list => list.Value.Select(res => res.X.Value).Min()).Min();
double minY = Results.AsParallel().Select(list => list.Value.Select(res => res.Y.Value).Min()).Min();
double minZ = Results.AsParallel().Select(list => list.Value.Select(res => res.Z.Value).Min()).Min();
double minXx = Results.AsParallel().Select(list => list.Value.Select(res => res.Xx.Value).Min()).Min();
double minYy = Results.AsParallel().Select(list => list.Value.Select(res => res.Yy.Value).Min()).Min();
double minZz = Results.AsParallel().Select(list => list.Value.Select(res => res.Zz.Value).Min()).Min();
Min = new GsaDisplacementQuantity(new Double6(minX, minY, minZ, minXx, minYy, minZz));
}
}
}
}
101 changes: 101 additions & 0 deletions GsaGH/Parameters/5_Results/ResultCollection/GsaResult2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using GsaAPI;
using GsaGH.Helpers;

namespace GsaGH.Parameters.Results {

public class GsaResult2 {
// API Global results
internal AnalysisCaseResult AnalysisCaseResult { get; set; }
internal CombinationCaseResult CombinationCaseResult { get; set; }

// API Node results (will not be needed after GSA-7517)
internal Dictionary<string, ReadOnlyDictionary<int, NodeResult>> AnalysisCaseNodeResults { get; set; }
= new Dictionary<string, ReadOnlyDictionary<int, NodeResult>>();

internal Dictionary<string, ReadOnlyDictionary<int, ReadOnlyCollection<NodeResult>>>
CombinationCaseNodeResults { get; set; }
= new Dictionary<string, ReadOnlyDictionary<int, ReadOnlyCollection<NodeResult>>>();

// Caches
internal Dictionary<string, GsaNodeDisplacements> NodeDisplacementCache { get; set; }
= new Dictionary<string, GsaNodeDisplacements>();

// Other members
internal int CaseId { get; set; }
internal string CaseName { get; set; }
internal GsaModel Model { get; set; }

internal List<int> SelectedPermutationIds { get; set; }
internal CaseType CaseType { get; set; }

public GsaResult2() { }

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

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

public override string ToString() {
string txt = string.Empty;
switch (CaseType) {
case CaseType.AnalysisCase:
txt = "A" + CaseId;
break;

case CaseType.CombinationCase:
txt = "C" + CaseId;
if (SelectedPermutationIds.Count > 0) {
txt = SelectedPermutationIds.Count > 1 ? txt + " P:" + SelectedPermutationIds.Count :
txt + " p" + SelectedPermutationIds[0];
}

break;
}

return txt.TrimSpaces();
}

internal GsaNodeDisplacements NodeDisplacementValues(string nodelist) {
if (nodelist.ToLower() == "all" || nodelist == string.Empty) {
nodelist = "All";
}

if (!NodeDisplacementCache.ContainsKey(nodelist)) {
switch (CaseType) {
case CaseType.AnalysisCase:
if (!AnalysisCaseNodeResults.ContainsKey(nodelist)) {
AnalysisCaseNodeResults.Add(nodelist, AnalysisCaseResult.NodeResults(nodelist));
}

NodeDisplacementCache.Add(nodelist, new GsaNodeDisplacements(AnalysisCaseNodeResults[nodelist]));
break;

case CaseType.CombinationCase:
if (!CombinationCaseNodeResults.ContainsKey(nodelist)) {
CombinationCaseNodeResults.Add(nodelist, CombinationCaseResult.NodeResults(nodelist));
}

NodeDisplacementCache.Add(nodelist, new GsaNodeDisplacements(CombinationCaseNodeResults[nodelist]));
break;
}
}

return NodeDisplacementCache[nodelist];
}
}
}

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions GsaGH/Parameters/5_Results/ResultCollection/INodeResult.cs

This file was deleted.

8 changes: 0 additions & 8 deletions GsaGH/Parameters/5_Results/ResultCollection/IQuad8Result.cs

This file was deleted.

5 changes: 0 additions & 5 deletions GsaGH/Parameters/5_Results/ResultCollection/IQuadResult.cs

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 7 additions & 4 deletions GsaGH/Parameters/5_Results/ResultCollection/IResultSubset.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace GsaGH.Parameters.Results {
public interface IResultSubset<IResult> : IResultDictionary<IResult> {
public IResult Max { get; set; }
public IResult Min { get; set; }
public interface IResultSubset<IResult> {
public IResult Max { get; }
public IResult Min { get; }
public List<int> Ids { get; }
public ConcurrentDictionary<int, Collection<IResult>> Results { get; }
}
}
6 changes: 0 additions & 6 deletions GsaGH/Parameters/5_Results/ResultCollection/IResults.cs

This file was deleted.

7 changes: 0 additions & 7 deletions GsaGH/Parameters/5_Results/ResultCollection/ITri6Result.cs

This file was deleted.

7 changes: 0 additions & 7 deletions GsaGH/Parameters/5_Results/ResultCollection/ITriResult.cs

This file was deleted.

0 comments on commit bb438e0

Please sign in to comment.