Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs =================================================================== diff -u -rb63c17a1ec42d980aad2b4e19664fd5414fb995e -re664365292d72b7003b642dacdd4e887e4ddceba --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision b63c17a1ec42d980aad2b4e19664fd5414fb995e) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision e664365292d72b7003b642dacdd4e887e4ddceba) @@ -57,6 +57,7 @@ public OnProgressChanged OnProgress; private IOvertoppingCalculator overtoppingCalculator; private IDikeHeightCalculator dikeHeightCalculator; + private IOvertoppingRateCalculator overtoppingRateCalculator; private bool canceled; /// @@ -85,6 +86,7 @@ { overtoppingCalculator?.Cancel(); dikeHeightCalculator?.Cancel(); + overtoppingRateCalculator?.Cancel(); canceled = true; } @@ -151,51 +153,47 @@ } var totalSteps = 1; - string calculationName = calculation.Name; string hlcdDirectory = Path.GetDirectoryName(hydraulicBoundaryDatabaseFilePath); SubCalculationAssessmentOutput dikeHeightOutput = null; SubCalculationAssessmentOutput overtoppingRateOutput = null; - bool calculateDikeHeight = calculation.InputParameters.DikeHeightCalculationType != DikeHeightCalculationType.NoCalculation; - if (calculateDikeHeight) + if (calculation.InputParameters.DikeHeightCalculationType != DikeHeightCalculationType.NoCalculation) { + dikeHeightCalculator = HydraRingCalculatorFactory.Instance.CreateDikeHeightCalculator(hlcdDirectory); totalSteps++; } - bool calculateOvertoppingRate = calculation.InputParameters.OvertoppingRateCalculationType != OvertoppingRateCalculationType.NoCalculation; - if (calculateOvertoppingRate) + if (calculation.InputParameters.OvertoppingRateCalculationType != OvertoppingRateCalculationType.NoCalculation) { totalSteps++; + overtoppingRateCalculator = HydraRingCalculatorFactory.Instance.CreateOvertoppingRateCalculator(hlcdDirectory); } NotifyProgress(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Executing_overtopping_calculation, 1, totalSteps); - CalculationServiceHelper.LogCalculationBeginTime(calculationName); + CalculationServiceHelper.LogCalculationBeginTime(calculation.Name); overtoppingCalculator = HydraRingCalculatorFactory.Instance.CreateOvertoppingCalculator(hlcdDirectory); - OvertoppingCalculationInput overtoppingCalculationInput = CreateOvertoppingInput(calculation, generalInput, hydraulicBoundaryDatabaseFilePath); try { - CalculateOvertopping(overtoppingCalculationInput, calculationName); + CalculateOvertopping(calculation, generalInput, hydraulicBoundaryDatabaseFilePath); if (canceled) { return; } - if (calculateDikeHeight) + if (dikeHeightCalculator != null) { NotifyProgress(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Executing_dikeheight_calculation, 2, totalSteps); - dikeHeightCalculator = HydraRingCalculatorFactory.Instance.CreateDikeHeightCalculator(hlcdDirectory); - double norm = GetProbabilityToUse(assessmentSection.FailureMechanismContribution.Norm, generalInput, failureMechanismContribution, calculation.InputParameters.DikeHeightCalculationType); DikeHeightCalculationInput dikeHeightCalculationInput = CreateDikeHeightInput(calculation, norm, generalInput, hydraulicBoundaryDatabaseFilePath); - bool dikeHeightCalculated = CalculateDikeHeight(dikeHeightCalculationInput, calculationName); + bool dikeHeightCalculated = CalculateDikeHeight(dikeHeightCalculationInput, calculation.Name); if (canceled) { @@ -204,7 +202,7 @@ if (dikeHeightCalculated) { - dikeHeightOutput = CreateDikeHeightAssessmentOutput(calculationName, dikeHeightCalculationInput.Beta, norm); + dikeHeightOutput = CreateDikeHeightAssessmentOutput(calculation.Name, dikeHeightCalculationInput.Beta, norm); } } @@ -221,63 +219,25 @@ } finally { - CalculationServiceHelper.LogCalculationEndTime(calculationName); - } - } + CalculationServiceHelper.LogCalculationEndTime(calculation.Name); - /// - /// Create the output of a dike height calculation. - /// - /// The name of the calculation. - /// The target reliability for the calculation. - /// The target probability for the calculation. - /// A . - /// Thrown when - /// or the calculated probability falls outside the [0.0, 1.0] range and is not . - private SubCalculationAssessmentOutput CreateDikeHeightAssessmentOutput(string calculationName, - double targetReliability, - double targetProbability) - { - double dikeHeight = dikeHeightCalculator.DikeHeight; - double reliability = dikeHeightCalculator.ReliabilityIndex; - double probability = StatisticsConverter.ReliabilityToProbability(reliability); - - CalculationConvergence converged = RingtoetsCommonDataCalculationService.GetCalculationConvergence(dikeHeightCalculator.Converged); - - if (converged != CalculationConvergence.CalculatedConverged) - { - log.Warn(string.Format(Resources.GrassCoverErosionInwardsCalculationService_DikeHeight_calculation_for_calculation_0_not_converged, calculationName)); + overtoppingCalculator = null; + dikeHeightCalculator = null; + overtoppingRateCalculator = null; } - - return new SubCalculationAssessmentOutput(dikeHeight, targetProbability, - targetReliability, probability, reliability, - converged); } - private static double GetProbabilityToUse(double assessmentSectionNorm, GeneralGrassCoverErosionInwardsInput generalInput, - double failureMechanismContribution, DikeHeightCalculationType calculateDikeHeight) - { - return calculateDikeHeight == DikeHeightCalculationType.CalculateByAssessmentSectionNorm - ? assessmentSectionNorm - : RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability( - assessmentSectionNorm, - failureMechanismContribution, - generalInput.N); - } - - private void NotifyProgress(string stepName, int currentStepNumber, int totalStepNumber) - { - OnProgress?.Invoke(stepName, currentStepNumber, totalStepNumber); - } - /// /// Performs an overtopping calculation. /// - /// The input of the calculation. - /// The name of the calculation. + /// The calculation containing the input for the overtopping calculation. + /// The general grass cover erosion inwards calculation input parameters. + /// The path which points to the hydraulic boundary database file. /// Thrown when an error occurs while performing the calculation. - private void CalculateOvertopping(OvertoppingCalculationInput overtoppingCalculationInput, string calculationName) + private void CalculateOvertopping(GrassCoverErosionInwardsCalculation calculation, GeneralGrassCoverErosionInwardsInput generalInput, string hydraulicBoundaryDatabaseFilePath) { + OvertoppingCalculationInput overtoppingCalculationInput = CreateOvertoppingInput(calculation, generalInput, hydraulicBoundaryDatabaseFilePath); + var exceptionThrown = false; try @@ -291,11 +251,11 @@ string lastErrorContent = overtoppingCalculator.LastErrorFileContent; if (string.IsNullOrEmpty(lastErrorContent)) { - log.ErrorFormat(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_grass_cover_erosion_inwards_0_calculation_no_error_report, calculationName); + log.ErrorFormat(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_grass_cover_erosion_inwards_0_calculation_no_error_report, calculation.Name); } else { - log.ErrorFormat(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_grass_cover_erosion_inwards_0_calculation_click_details_for_last_error_report_1, calculationName, lastErrorContent); + log.ErrorFormat(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_grass_cover_erosion_inwards_0_calculation_click_details_for_last_error_report_1, calculation.Name, lastErrorContent); } exceptionThrown = true; @@ -308,7 +268,7 @@ bool errorOccurred = CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { - log.ErrorFormat(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_grass_cover_erosion_inwards_0_calculation_click_details_for_last_error_report_1, calculationName, lastErrorFileContent); + log.ErrorFormat(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_grass_cover_erosion_inwards_0_calculation_click_details_for_last_error_report_1, calculation.Name, lastErrorFileContent); } log.InfoFormat(Resources.GrassCoverErosionInwardsCalculationService_CalculateOvertopping_calculation_temporary_directory_can_be_found_on_location_0, overtoppingCalculator.OutputDirectory); @@ -321,6 +281,51 @@ } /// + /// Create the output of a dike height calculation. + /// + /// The name of the calculation. + /// The target reliability for the calculation. + /// The target probability for the calculation. + /// A . + /// Thrown when + /// or the calculated probability falls outside the [0.0, 1.0] range and is not . + private SubCalculationAssessmentOutput CreateDikeHeightAssessmentOutput(string calculationName, + double targetReliability, + double targetProbability) + { + double dikeHeight = dikeHeightCalculator.DikeHeight; + double reliability = dikeHeightCalculator.ReliabilityIndex; + double probability = StatisticsConverter.ReliabilityToProbability(reliability); + + CalculationConvergence converged = RingtoetsCommonDataCalculationService.GetCalculationConvergence(dikeHeightCalculator.Converged); + + if (converged != CalculationConvergence.CalculatedConverged) + { + log.Warn(string.Format(Resources.GrassCoverErosionInwardsCalculationService_DikeHeight_calculation_for_calculation_0_not_converged, calculationName)); + } + + return new SubCalculationAssessmentOutput(dikeHeight, targetProbability, + targetReliability, probability, reliability, + converged); + } + + private static double GetProbabilityToUse(double assessmentSectionNorm, GeneralGrassCoverErosionInwardsInput generalInput, + double failureMechanismContribution, DikeHeightCalculationType calculateDikeHeight) + { + return calculateDikeHeight == DikeHeightCalculationType.CalculateByAssessmentSectionNorm + ? assessmentSectionNorm + : RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability( + assessmentSectionNorm, + failureMechanismContribution, + generalInput.N); + } + + private void NotifyProgress(string stepName, int currentStepNumber, int totalStepNumber) + { + OnProgress?.Invoke(stepName, currentStepNumber, totalStepNumber); + } + + /// /// Performs the dike height calculation. /// /// The input of the dike height calculation. Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsCalculationServiceTest.cs =================================================================== diff -u -r8cb270db5fbcb82f19d6f3a390f083e9e0516d8c -re664365292d72b7003b642dacdd4e887e4ddceba --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsCalculationServiceTest.cs (.../GrassCoverErosionInwardsCalculationServiceTest.cs) (revision 8cb270db5fbcb82f19d6f3a390f083e9e0516d8c) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsCalculationServiceTest.cs (.../GrassCoverErosionInwardsCalculationServiceTest.cs) (revision e664365292d72b7003b642dacdd4e887e4ddceba) @@ -732,19 +732,8 @@ // Assert Assert.IsNull(calculation.Output); - - if (cancelBeforeDikeHeightCalculationStarts) - { - Assert.IsTrue(overToppingCalculator.IsCanceled); - - // dikeheightCalculator is initialized after the overtopping calculation successfully finishes. - Assert.IsFalse(dikeHeightCalculator.IsCanceled); - } - else - { - Assert.IsTrue(overToppingCalculator.IsCanceled); - Assert.IsTrue(dikeHeightCalculator.IsCanceled); - } + Assert.IsTrue(overToppingCalculator.IsCanceled); + Assert.IsTrue(dikeHeightCalculator.IsCanceled); } }