diff --git a/GsaGH/Parameters/5_Results/3_Caches/CacheUtility.cs b/GsaGH/Parameters/5_Results/3_Caches/CacheUtility.cs index 22c48f2c3..021b91bcc 100644 --- a/GsaGH/Parameters/5_Results/3_Caches/CacheUtility.cs +++ b/GsaGH/Parameters/5_Results/3_Caches/CacheUtility.cs @@ -1,5 +1,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Threading.Tasks; namespace GsaGH.Parameters.Results { @@ -16,6 +17,25 @@ public static ConcurrentBag GetMissingKeys( return missingIds; } + public static ConcurrentBag GetMissingKeysAndPositions( + this IDictionary> existing, ICollection newKeys, ReadOnlyCollection positions) + where T1 : IElement1dQuantity where T2 : IResultItem { + var missingIds = new ConcurrentBag(); + 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); + } + } + } + }); + + return missingIds; + } + public static ConcurrentDictionary GetSubset(this IDictionary dictionary, ICollection keys) { var subset = new ConcurrentDictionary(); diff --git a/GsaGH/Parameters/5_Results/3_Caches/Element1dDisplacementCache.cs b/GsaGH/Parameters/5_Results/3_Caches/Element1dDisplacementCache.cs index 0693393e0..f06dd8a2d 100644 --- a/GsaGH/Parameters/5_Results/3_Caches/Element1dDisplacementCache.cs +++ b/GsaGH/Parameters/5_Results/3_Caches/Element1dDisplacementCache.cs @@ -7,7 +7,7 @@ using GsaAPI; namespace GsaGH.Parameters.Results { - public class Element1dDisplacementCache + public class Element1dDisplacementCache : IElement1dResultCache> { public IApiResult ApiResult { get; set; } @@ -22,21 +22,22 @@ internal Element1dDisplacementCache(CombinationCaseResult result) { ApiResult = new ApiResult(result); } - public IElement1dResultSubset> + public IElement1dResultSubset> ResultSubset(ICollection elementIds, int positionCount) { var positions = Enumerable.Range(0, positionCount).Select( i => (double)i / (positionCount - 1)).ToList(); return ResultSubset(elementIds, new ReadOnlyCollection(positions)); } - public IElement1dResultSubset> + public IElement1dResultSubset> ResultSubset(ICollection elementIds, ReadOnlyCollection positions) { - ConcurrentBag missingIds = Cache.GetMissingKeys(elementIds); + ConcurrentBag missingIds + = Cache.GetMissingKeysAndPositions(elementIds, positions); if (missingIds.Count > 0) { string elementList = string.Join(" ", missingIds); switch (ApiResult.Result) { case AnalysisCaseResult analysisCase: - ReadOnlyDictionary> aCaseResults + ReadOnlyDictionary> aCaseResults = analysisCase.Element1dDisplacement(elementList, positions); Parallel.ForEach(missingIds, elementId => Cache.AddOrUpdate( elementId, Element1dResultsFactory.CreateBeamDisplacements(aCaseResults[elementId], positions), @@ -44,7 +45,7 @@ ReadOnlyDictionary> aCaseResults break; case CombinationCaseResult combinationCase: - ReadOnlyDictionary>> cCaseResults + ReadOnlyDictionary>> cCaseResults = combinationCase.Element1dDisplacement(elementList, positions); Parallel.ForEach(missingIds, elementId => Cache.AddOrUpdate( elementId, Element1dResultsFactory.CreateBeamDisplacements(cCaseResults[elementId], positions),