Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/DesignCalculator.cs =================================================================== diff -u -r3790 -r3873 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/DesignCalculator.cs (.../DesignCalculator.cs) (revision 3790) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/DesignCalculator.cs (.../DesignCalculator.cs) (revision 3873) @@ -55,14 +55,7 @@ { progressDelegate?.Invoke(0); damProjectData.DesignCalculations = new List(); - if (damProjectData.CalculationMessages == null) - { - damProjectData.CalculationMessages = new List(); - } - else - { - damProjectData.CalculationMessages.Clear(); - } + PrepareCalculationMessages(damProjectData); // Prepare the designCalculatorTasks var designCalculatorTasks = new List(); @@ -79,48 +72,70 @@ } else { - for (int subSoilScenarioIndex = 0; subSoilScenarioIndex < location.Segment.SoilProfileProbabilities.Count; subSoilScenarioIndex++) + relevantCombinationsCount = DetermineRelevantCombinations(damProjectData, location, designCalculatorTasks, relevantCombinationsCount); + } + } + + HandleRelevantCombinations(damProjectData, relevantCombinationsCount, designCalculatorTasks); + } + + private int DetermineRelevantCombinations(DamProjectData damProjectData, Location location, + List designCalculatorTasks, int relevantCombinationsCount) + { + for (int subSoilScenarioIndex = 0; + subSoilScenarioIndex < location.Segment.SoilProfileProbabilities.Count; + subSoilScenarioIndex++) + { + // Check if the subSoilScenario is applicable for the failuremechanism that is being calculated + if (location.Segment.SoilProfileProbabilities[subSoilScenarioIndex].SegmentFailureMechanismType.HasValue && + (location.Segment.SoilProfileProbabilities[subSoilScenarioIndex].SegmentFailureMechanismType.Value.In( + ConversionHelper.ConvertToSegmentFailureMechanismType(damProjectData.DamProjectCalculationSpecification + .CurrentSpecification.FailureMechanismSystemType), + SegmentFailureMechanismType.All))) + { + var soiProfileProbability = location.Segment.SoilProfileProbabilities[subSoilScenarioIndex]; + for (int designScenarioIndex = 0; designScenarioIndex < location.Scenarios.Count; designScenarioIndex++) { - // Check if the subSoilScenario is applicable for the failuremechanism that is being calculated - if (location.Segment.SoilProfileProbabilities[subSoilScenarioIndex].SegmentFailureMechanismType.HasValue && - (location.Segment.SoilProfileProbabilities[subSoilScenarioIndex].SegmentFailureMechanismType.Value.In( - ConversionHelper.ConvertToSegmentFailureMechanismType(damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType), - SegmentFailureMechanismType.All))) + DesignScenario designScenario = location.Scenarios[designScenarioIndex]; + designScenario.Location = location; + var projectPath = damProjectData.ProjectPath != "" + ? damProjectData.ProjectPath + : Directory.GetCurrentDirectory(); + var designResults = new List(); + var calculationMessages = new List(); + designCalculatorTasks.Add(new DesignCalculatorTask() { - var soiProfileProbability = location.Segment.SoilProfileProbabilities[subSoilScenarioIndex]; - for (int designScenarioIndex = 0; designScenarioIndex < location.Scenarios.Count; designScenarioIndex++) - { - DesignScenario designScenario = location.Scenarios[designScenarioIndex]; - designScenario.Location = location; - var projectPath = damProjectData.ProjectPath != "" ? damProjectData.ProjectPath : Directory.GetCurrentDirectory(); - var designResults = new List(); - var calculationMessages = new List(); - designCalculatorTasks.Add(new DesignCalculatorTask() - { - Location = location, - SoiProfileProbability = soiProfileProbability, - DesignScenario = designScenario, - ProjectPath = projectPath, - CalculationMap = damProjectData.CalculationMap, - FailureMechanismeCalculationSpecification = damProjectData.DamProjectCalculationSpecification.CurrentSpecification.Copy(), - DesignResults = designResults, - CalculationMessages = calculationMessages - }); - } - relevantCombinationsCount++; - } + Location = location, + SoiProfileProbability = soiProfileProbability, + DesignScenario = designScenario, + ProjectPath = projectPath, + CalculationMap = damProjectData.CalculationMap, + FailureMechanismeCalculationSpecification = + damProjectData.DamProjectCalculationSpecification.CurrentSpecification.Copy(), + DesignResults = designResults, + CalculationMessages = calculationMessages + }); } + + relevantCombinationsCount++; } } + return relevantCombinationsCount; + } + + private void HandleRelevantCombinations(DamProjectData damProjectData, int relevantCombinationsCount, + List designCalculatorTasks) + { if (relevantCombinationsCount > 0) { // Perform the calculation - Parallel.Run(designCalculatorTasks, RunDesignCalculatorTask, progressDelegate, damProjectData.MaxCalculationCores); - foreach (var desigCalculatorTask in designCalculatorTasks) + Parallel.Run(designCalculatorTasks, RunDesignCalculatorTask, progressDelegate, + damProjectData.MaxCalculationCores); + foreach (var designCalculatorTask in designCalculatorTasks) { - damProjectData.CalculationMessages.AddRange(desigCalculatorTask.CalculationMessages); - damProjectData.DesignCalculations.AddRange(desigCalculatorTask.DesignResults); + damProjectData.CalculationMessages.AddRange(designCalculatorTask.CalculationMessages); + damProjectData.DesignCalculations.AddRange(designCalculatorTask.DesignResults); } } else @@ -130,12 +145,25 @@ MessageType = LogMessageType.Error, Subject = null, Message = string.Format(Resources.DesignCalculatorNoSegmentsWithFailureMechanismTypePresent, - damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType.ToString()) + damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType + .ToString()) }; damProjectData.CalculationMessages.Add(logMessage); } } + private void PrepareCalculationMessages(DamProjectData damProjectData) + { + if (damProjectData.CalculationMessages == null) + { + damProjectData.CalculationMessages = new List(); + } + else + { + damProjectData.CalculationMessages.Clear(); + } + } + private void RunDesignCalculatorTask(object designCalculatorTask) { DesignCalculatorTask task = (DesignCalculatorTask)designCalculatorTask; @@ -177,29 +205,7 @@ SurfaceLine2 orgLocationSurfaceLine = null; try { - // Make sure that in case of AdaptGeometry (and RedesignDikeHeight), the surface line is adapted for the given DTH BEFORE the call to Prepare as - // otherwise the Prepare will be done on the original surface line which is wrong. - if (analysisType == AnalysisType.AdaptGeometry && damKernelInput.Location.RedesignDikeHeight) - { - double? dikeHeight = location.SurfaceLine.GetDikeHeight(); - if (dikeHeight.HasValue) - { - if (designScenario.DikeTableHeight > dikeHeight.Value) - { - orgLocationSurfaceLine = location.SurfaceLine.FullDeepClone(); - // Redesign the surfaceline to the desired Dike Table Height - var surfaceLineHeightAdapter = - new SurfaceLineHeightAdapter(location.SurfaceLine, location, designScenario.PolderLevel); - SurfaceLine2 adaptedSurfaceLine = - surfaceLineHeightAdapter.ConstructNewSurfaceLine( - designScenario.DikeTableHeight ?? - location.SurfaceLine.GetDefaultDikeTableHeight() ?? 0); - designScenario.SetRedesignedSurfaceLine(damKernelInput.SubSoilScenario.SoilProfile1D, - damKernelInput.SubSoilScenario.SoilProfile2D, adaptedSurfaceLine); - damKernelInput.Location.SurfaceLine = adaptedSurfaceLine; - } - } - } + orgLocationSurfaceLine = AdaptSurfaceLineWhenNeededForDesign(location, designScenario, analysisType, damKernelInput); PrepareResult prepareResult = kernelWrapper.Prepare(damKernelInput, 0, out kernelDataInput, out kernelDataOutput); @@ -270,6 +276,37 @@ } } + private SurfaceLine2 AdaptSurfaceLineWhenNeededForDesign(Location location, DesignScenario designScenario, + AnalysisType analysisType, DamKernelInput damKernelInput) + { + SurfaceLine2 orgLocationSurfaceLine = null; + // Make sure that in case of AdaptGeometry (and RedesignDikeHeight), the surface line is adapted for the given DTH BEFORE the call to Prepare as + // otherwise the Prepare will be done on the original surface line which is wrong. + if (analysisType == AnalysisType.AdaptGeometry && damKernelInput.Location.RedesignDikeHeight) + { + double? dikeHeight = location.SurfaceLine.GetDikeHeight(); + if (dikeHeight.HasValue) + { + if (designScenario.DikeTableHeight > dikeHeight.Value) + { + orgLocationSurfaceLine = location.SurfaceLine.FullDeepClone(); + // Redesign the surface line to the desired Dike Table Height + var surfaceLineHeightAdapter = + new SurfaceLineHeightAdapter(location.SurfaceLine, location, designScenario.PolderLevel); + SurfaceLine2 adaptedSurfaceLine = + surfaceLineHeightAdapter.ConstructNewSurfaceLine( + designScenario.DikeTableHeight ?? + location.SurfaceLine.GetDefaultDikeTableHeight() ?? 0); + designScenario.SetRedesignedSurfaceLine(damKernelInput.SubSoilScenario.SoilProfile1D, + damKernelInput.SubSoilScenario.SoilProfile2D, adaptedSurfaceLine); + damKernelInput.Location.SurfaceLine = adaptedSurfaceLine; + } + } + } + + return orgLocationSurfaceLine; + } + /// /// Performs the design calculation /// Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Standard/ObjectExtensions.cs =================================================================== diff -u -r3522 -r3873 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Standard/ObjectExtensions.cs (.../ObjectExtensions.cs) (revision 3522) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Standard/ObjectExtensions.cs (.../ObjectExtensions.cs) (revision 3873) @@ -369,7 +369,10 @@ { v = value.ToString().Replace("\0", " "); } - catch { } + catch + { + throw new ConversionException(type, value.ToString(), e); + } throw new ConversionException(type, v, e); }