Skip to content

Commit

Permalink
find missing positions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristjan Nielsen committed Nov 3, 2023
1 parent 1eda6a3 commit 855b458
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
20 changes: 20 additions & 0 deletions GsaGH/Parameters/5_Results/3_Caches/CacheUtility.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;

namespace GsaGH.Parameters.Results {
Expand All @@ -16,6 +17,25 @@ public static ConcurrentBag<int> GetMissingKeys<T>(
return missingIds;
}

public static ConcurrentBag<int> GetMissingKeysAndPositions<T1, T2>(
this IDictionary<int, Collection<T1>> existing, ICollection<int> newKeys, ReadOnlyCollection<double> positions)
where T1 : IElement1dQuantity<T2> where T2 : IResultItem {
var missingIds = new ConcurrentBag<int>();
Parallel.ForEach(newKeys, key => {
if (!existing.ContainsKey(key)) {
missingIds.Add(key);
} else {
foreach (double position in positions) {
if (!existing[key][0].Results.ContainsKey(position)) {
missingIds.Add(key);

Check warning on line 30 in GsaGH/Parameters/5_Results/3_Caches/CacheUtility.cs

View check run for this annotation

Codecov / codecov/patch

GsaGH/Parameters/5_Results/3_Caches/CacheUtility.cs#L30

Added line #L30 was not covered by tests
}
}
}
});

return missingIds;
}

public static ConcurrentDictionary<int, T> GetSubset<T>(this IDictionary<int, T> dictionary,
ICollection<int> keys) {
var subset = new ConcurrentDictionary<int, T>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using GsaAPI;

namespace GsaGH.Parameters.Results {
public class Element1dDisplacementCache
public class Element1dDisplacementCache
: IElement1dResultCache<IElement1dDisplacement, IDisplacement, ResultVector6<Element1dExtremaKey>> {
public IApiResult ApiResult { get; set; }

Expand All @@ -22,29 +22,30 @@ internal Element1dDisplacementCache(CombinationCaseResult result) {
ApiResult = new ApiResult(result);
}

public IElement1dResultSubset<IElement1dDisplacement, IDisplacement, ResultVector6<Element1dExtremaKey>>
public IElement1dResultSubset<IElement1dDisplacement, IDisplacement, ResultVector6<Element1dExtremaKey>>
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 IElement1dResultSubset<IElement1dDisplacement, IDisplacement, ResultVector6<Element1dExtremaKey>>
public IElement1dResultSubset<IElement1dDisplacement, IDisplacement, ResultVector6<Element1dExtremaKey>>
ResultSubset(ICollection<int> elementIds, ReadOnlyCollection<double> positions) {
ConcurrentBag<int> missingIds = Cache.GetMissingKeys(elementIds);
ConcurrentBag<int> missingIds
= Cache.GetMissingKeysAndPositions<IElement1dDisplacement, IDisplacement>(elementIds, positions);
if (missingIds.Count > 0) {
string elementList = string.Join(" ", missingIds);
switch (ApiResult.Result) {
case AnalysisCaseResult analysisCase:
ReadOnlyDictionary<int, ReadOnlyCollection<Double6>> aCaseResults
ReadOnlyDictionary<int, ReadOnlyCollection<Double6>> aCaseResults
= analysisCase.Element1dDisplacement(elementList, positions);
Parallel.ForEach(missingIds, elementId => Cache.AddOrUpdate(
elementId, Element1dResultsFactory.CreateBeamDisplacements(aCaseResults[elementId], positions),
(key, oldValue) => oldValue.AddMissingPositions(aCaseResults[elementId], positions)));
break;

case CombinationCaseResult combinationCase:
ReadOnlyDictionary<int, ReadOnlyCollection<ReadOnlyCollection<Double6>>> cCaseResults
ReadOnlyDictionary<int, ReadOnlyCollection<ReadOnlyCollection<Double6>>> cCaseResults
= combinationCase.Element1dDisplacement(elementList, positions);
Parallel.ForEach(missingIds, elementId => Cache.AddOrUpdate(
elementId, Element1dResultsFactory.CreateBeamDisplacements(cCaseResults[elementId], positions),
Expand Down

0 comments on commit 855b458

Please sign in to comment.