Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs =================================================================== diff -u -raaeb6b78529e3c46c5035b6bad846b53ec64f1ca -r16697317b00bb5ffe52baee7d9e91b42ba1cf743 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision aaeb6b78529e3c46c5035b6bad846b53ec64f1ca) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision 16697317b00bb5ffe52baee7d9e91b42ba1cf743) @@ -214,37 +214,6 @@ } } - private static string[] ValidateInput(GrassCoverErosionInwardsInput inputParameters, IAssessmentSection assessmentSection) - { - var validationResult = new List(); - - string validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(assessmentSection.HydraulicBoundaryDatabase.FilePath); - if (!string.IsNullOrEmpty(validationProblem)) - { - validationResult.Add(validationProblem); - return validationResult.ToArray(); - } - - if (inputParameters.HydraulicBoundaryLocation == null) - { - validationResult.Add(RingtoetsCommonServiceResources.CalculationService_ValidateInput_No_hydraulic_boundary_location_selected); - } - - if (inputParameters.DikeProfile == null) - { - validationResult.Add(RingtoetsCommonServiceResources.CalculationService_ValidateInput_No_dike_profile_selected); - } - else - { - validationResult.AddRange(new NumericInputRule(inputParameters.Orientation, ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonForms.Orientation_DisplayName)).Validate()); - validationResult.AddRange(new NumericInputRule(inputParameters.DikeHeight, ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonForms.DikeHeight_DisplayName)).Validate()); - } - - validationResult.AddRange(new UseBreakWaterRule(inputParameters).Validate()); - - return validationResult.ToArray(); - } - private int CreateCalculators(GrassCoverErosionInwardsCalculation calculation, string hlcdDirectory) { var numberOfCalculators = 1; @@ -266,11 +235,6 @@ return numberOfCalculators; } - private void NotifyProgress(string stepName, int currentStepNumber, int totalStepNumber) - { - OnProgress?.Invoke(stepName, currentStepNumber, totalStepNumber); - } - /// /// Performs an overtopping calculation. /// @@ -297,6 +261,106 @@ Resources.GrassCoverErosionInwardsCalculationService_Overtopping); } + private SubCalculationAssessmentOutput CalculateDikeHeight(GrassCoverErosionInwardsCalculation calculation, + IAssessmentSection assessmentSection, + GeneralGrassCoverErosionInwardsInput generalInput, + double failureMechanismContribution, + string hydraulicBoundaryDatabaseFilePath, + int numberOfCalculators) + { + if (dikeHeightCalculator == null) + { + return null; + } + + NotifyProgress(string.Format(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Executing_calculation_of_type_0, + Resources.GrassCoverErosionInwardsCalculationService_DikeHeight), + 2, numberOfCalculators); + + double norm = calculation.InputParameters.DikeHeightCalculationType == DikeHeightCalculationType.CalculateByAssessmentSectionNorm + ? assessmentSection.FailureMechanismContribution.Norm + : RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability( + assessmentSection.FailureMechanismContribution.Norm, + failureMechanismContribution, + generalInput.N); + + DikeHeightCalculationInput dikeHeightCalculationInput = CreateDikeHeightInput(calculation, norm, + generalInput, + hydraulicBoundaryDatabaseFilePath); + + var dikeHeightCalculated = true; + + try + { + PerformCalculation(() => dikeHeightCalculator.Calculate(dikeHeightCalculationInput), + () => dikeHeightCalculator.LastErrorFileContent, + () => dikeHeightCalculator.OutputDirectory, + calculation.Name, + Resources.GrassCoverErosionInwardsCalculationService_DikeHeight); + } + catch (HydraRingCalculationException) + { + dikeHeightCalculated = false; + } + + if (canceled || !dikeHeightCalculated) + { + return null; + } + + return CreateDikeHeightAssessmentOutput(calculation.Name, dikeHeightCalculationInput.Beta, norm); + } + + private SubCalculationAssessmentOutput CalculateOvertoppingRate(GrassCoverErosionInwardsCalculation calculation, + IAssessmentSection assessmentSection, + GeneralGrassCoverErosionInwardsInput generalInput, + double failureMechanismContribution, + string hydraulicBoundaryDatabaseFilePath, + int numberOfCalculators) + { + if (overtoppingRateCalculator == null) + { + return null; + } + + NotifyProgress(string.Format(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Executing_calculation_of_type_0, + Resources.GrassCoverErosionInwardsCalculationService_OvertoppingRate), + numberOfCalculators, numberOfCalculators); + + double norm = calculation.InputParameters.OvertoppingRateCalculationType == OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm + ? assessmentSection.FailureMechanismContribution.Norm + : RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability( + assessmentSection.FailureMechanismContribution.Norm, + failureMechanismContribution, + generalInput.N); + + OvertoppingRateCalculationInput overtoppingRateCalculationInput = CreateOvertoppingRateInput(calculation, norm, + generalInput, + hydraulicBoundaryDatabaseFilePath); + + var overtoppingRateCalculated = true; + + try + { + PerformCalculation(() => overtoppingRateCalculator.Calculate(overtoppingRateCalculationInput), + () => overtoppingRateCalculator.LastErrorFileContent, + () => overtoppingRateCalculator.OutputDirectory, + calculation.Name, + Resources.GrassCoverErosionInwardsCalculationService_DikeHeight); + } + catch (HydraRingCalculationException) + { + overtoppingRateCalculated = false; + } + + if (canceled || !overtoppingRateCalculated) + { + return null; + } + + return CreateOvertoppingRateAssessmentOutput(calculation.Name, overtoppingRateCalculationInput.Beta, norm); + } + private void PerformCalculation(Action performCalculation, Func getLastErrorFileContent, Func getOutputDirectory, @@ -412,56 +476,6 @@ return overtoppingCalculationInput; } - private SubCalculationAssessmentOutput CalculateDikeHeight(GrassCoverErosionInwardsCalculation calculation, - IAssessmentSection assessmentSection, - GeneralGrassCoverErosionInwardsInput generalInput, - double failureMechanismContribution, - string hydraulicBoundaryDatabaseFilePath, - int numberOfCalculators) - { - if (dikeHeightCalculator == null) - { - return null; - } - - NotifyProgress(string.Format(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Executing_calculation_of_type_0, - Resources.GrassCoverErosionInwardsCalculationService_DikeHeight), - 2, numberOfCalculators); - - double norm = calculation.InputParameters.DikeHeightCalculationType == DikeHeightCalculationType.CalculateByAssessmentSectionNorm - ? assessmentSection.FailureMechanismContribution.Norm - : RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability( - assessmentSection.FailureMechanismContribution.Norm, - failureMechanismContribution, - generalInput.N); - - DikeHeightCalculationInput dikeHeightCalculationInput = CreateDikeHeightInput(calculation, norm, - generalInput, - hydraulicBoundaryDatabaseFilePath); - - var dikeHeightCalculated = true; - - try - { - PerformCalculation(() => dikeHeightCalculator.Calculate(dikeHeightCalculationInput), - () => dikeHeightCalculator.LastErrorFileContent, - () => dikeHeightCalculator.OutputDirectory, - calculation.Name, - Resources.GrassCoverErosionInwardsCalculationService_DikeHeight); - } - catch (HydraRingCalculationException) - { - dikeHeightCalculated = false; - } - - if (canceled || !dikeHeightCalculated) - { - return null; - } - - return CreateDikeHeightAssessmentOutput(calculation.Name, dikeHeightCalculationInput.Beta, norm); - } - /// /// Creates the input for a dike height calculation. /// @@ -518,77 +532,6 @@ } /// - /// Creates 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 SubCalculationAssessmentOutput CalculateOvertoppingRate(GrassCoverErosionInwardsCalculation calculation, - IAssessmentSection assessmentSection, - GeneralGrassCoverErosionInwardsInput generalInput, - double failureMechanismContribution, - string hydraulicBoundaryDatabaseFilePath, - int numberOfCalculators) - { - if (overtoppingRateCalculator == null) - { - return null; - } - - NotifyProgress(string.Format(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Executing_calculation_of_type_0, - Resources.GrassCoverErosionInwardsCalculationService_OvertoppingRate), - numberOfCalculators, numberOfCalculators); - - double norm = calculation.InputParameters.OvertoppingRateCalculationType == OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm - ? assessmentSection.FailureMechanismContribution.Norm - : RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability( - assessmentSection.FailureMechanismContribution.Norm, - failureMechanismContribution, - generalInput.N); - - OvertoppingRateCalculationInput overtoppingRateCalculationInput = CreateOvertoppingRateInput(calculation, norm, - generalInput, - hydraulicBoundaryDatabaseFilePath); - - bool overtoppingRateCalculated = CalculateOvertoppingRate(overtoppingRateCalculationInput, calculation.Name); - - if (canceled) - { - return null; - } - - if (overtoppingRateCalculated) - { - return CreateOvertoppingRateAssessmentOutput(calculation.Name, overtoppingRateCalculationInput.Beta, norm); - } - - return null; - } - - /// /// Creates the input for a overtopping rate calculation. /// /// The that holds all the information required to perform the calculation. @@ -643,54 +586,32 @@ } /// - /// Performs the overtopping rate calculation. + /// Creates the output of a dike height calculation. /// - /// The input of the overtopping rate calculation. /// The name of the calculation. - /// True when the calculation was successful. False otherwise. - private bool CalculateOvertoppingRate(OvertoppingRateCalculationInput overtoppingRateCalculationInput, string calculationName) + /// 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) { - var exceptionThrown = false; - var overtoppingRateCalculated = false; - if (!canceled) - { - try - { - overtoppingRateCalculator.Calculate(overtoppingRateCalculationInput); - } - catch (HydraRingCalculationException) - { - if (!canceled) - { - string lastErrorContent = overtoppingRateCalculator.LastErrorFileContent; - if (string.IsNullOrEmpty(lastErrorContent)) - { - log.ErrorFormat(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_overtopping_rate_grass_cover_erosion_inwards_0_calculation_no_error_report, calculationName); - } - else - { - log.ErrorFormat(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_overtopping_rate_grass_cover_erosion_inwards_0_calculation_click_details_for_last_error_report_1, calculationName, lastErrorContent); - } + double dikeHeight = dikeHeightCalculator.DikeHeight; + double reliability = dikeHeightCalculator.ReliabilityIndex; + double probability = StatisticsConverter.ReliabilityToProbability(reliability); - exceptionThrown = true; - } - } - finally - { - string lastErrorFileContent = overtoppingRateCalculator.LastErrorFileContent; - if (CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, lastErrorFileContent)) - { - log.ErrorFormat(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_overtopping_rate_grass_cover_erosion_inwards_0_calculation_click_details_for_last_error_report_1, calculationName, lastErrorFileContent); - } - if (!exceptionThrown && string.IsNullOrEmpty(lastErrorFileContent)) - { - overtoppingRateCalculated = true; - } + CalculationConvergence converged = RingtoetsCommonDataCalculationService.GetCalculationConvergence(dikeHeightCalculator.Converged); - log.InfoFormat(Resources.GrassCoverErosionInwardsCalculationService_CalculateOvertoppingRate_calculation_temporary_directory_can_be_found_on_location_0, dikeHeightCalculator.OutputDirectory); - } + if (converged != CalculationConvergence.CalculatedConverged) + { + log.Warn(string.Format(Resources.GrassCoverErosionInwardsCalculationService_DikeHeight_calculation_for_calculation_0_not_converged, calculationName)); } - return overtoppingRateCalculated; + + return new SubCalculationAssessmentOutput(dikeHeight, targetProbability, + targetReliability, probability, reliability, + converged); } /// @@ -726,5 +647,41 @@ { return roughnessProfilePoints.Select(roughnessPoint => new HydraRingRoughnessProfilePoint(roughnessPoint.Point.X, roughnessPoint.Point.Y, roughnessPoint.Roughness)); } + + private static string[] ValidateInput(GrassCoverErosionInwardsInput inputParameters, IAssessmentSection assessmentSection) + { + var validationResult = new List(); + + string validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(assessmentSection.HydraulicBoundaryDatabase.FilePath); + if (!string.IsNullOrEmpty(validationProblem)) + { + validationResult.Add(validationProblem); + return validationResult.ToArray(); + } + + if (inputParameters.HydraulicBoundaryLocation == null) + { + validationResult.Add(RingtoetsCommonServiceResources.CalculationService_ValidateInput_No_hydraulic_boundary_location_selected); + } + + if (inputParameters.DikeProfile == null) + { + validationResult.Add(RingtoetsCommonServiceResources.CalculationService_ValidateInput_No_dike_profile_selected); + } + else + { + validationResult.AddRange(new NumericInputRule(inputParameters.Orientation, ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonForms.Orientation_DisplayName)).Validate()); + validationResult.AddRange(new NumericInputRule(inputParameters.DikeHeight, ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonForms.DikeHeight_DisplayName)).Validate()); + } + + validationResult.AddRange(new UseBreakWaterRule(inputParameters).Validate()); + + return validationResult.ToArray(); + } + + private void NotifyProgress(string stepName, int currentStepNumber, int totalStepNumber) + { + OnProgress?.Invoke(stepName, currentStepNumber, totalStepNumber); + } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Properties/Resources.Designer.cs =================================================================== diff -u -raaeb6b78529e3c46c5035b6bad846b53ec64f1ca -r16697317b00bb5ffe52baee7d9e91b42ba1cf743 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision aaeb6b78529e3c46c5035b6bad846b53ec64f1ca) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 16697317b00bb5ffe52baee7d9e91b42ba1cf743) @@ -113,27 +113,6 @@ } /// - /// Looks up a localized string similar to De overslagdebiet berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken. - ///{1}. - /// - internal static string GrassCoverErosionInwardsCalculationService_Calculate_Error_in_overtopping_rate_grass_cover_erosion_inwards_0_calculation_click_details_for_last_error_report_1 { - get { - return ResourceManager.GetString("GrassCoverErosionInwardsCalculationService_Calculate_Error_in_overtopping_rate_gr" + - "ass_cover_erosion_inwards_0_calculation_click_details_for_last_error_report_1", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to De overslagdebiet berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Er is geen foutrapport beschikbaar.. - /// - internal static string GrassCoverErosionInwardsCalculationService_Calculate_Error_in_overtopping_rate_grass_cover_erosion_inwards_0_calculation_no_error_report { - get { - return ResourceManager.GetString("GrassCoverErosionInwardsCalculationService_Calculate_Error_in_overtopping_rate_gr" + - "ass_cover_erosion_inwards_0_calculation_no_error_report", resourceCulture); - } - } - - /// /// Looks up a localized string similar to Uitvoeren {0} berekening. /// internal static string GrassCoverErosionInwardsCalculationService_Calculate_Executing_calculation_of_type_0 { @@ -144,16 +123,6 @@ } /// - /// Looks up a localized string similar to Overslagdebiet berekening is uitgevoerd op de tijdelijke locatie '{0}'. Gedetailleerde invoer en uitvoer kan in de bestanden op deze locatie worden gevonden.. - /// - internal static string GrassCoverErosionInwardsCalculationService_CalculateOvertoppingRate_calculation_temporary_directory_can_be_found_on_location_0 { - get { - return ResourceManager.GetString("GrassCoverErosionInwardsCalculationService_CalculateOvertoppingRate_calculation_t" + - "emporary_directory_can_be_found_on_location_0", resourceCulture); - } - } - - /// /// Looks up a localized string similar to dijkhoogte. /// internal static string GrassCoverErosionInwardsCalculationService_DikeHeight { Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Properties/Resources.resx =================================================================== diff -u -raaeb6b78529e3c46c5035b6bad846b53ec64f1ca -r16697317b00bb5ffe52baee7d9e91b42ba1cf743 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Properties/Resources.resx (.../Resources.resx) (revision aaeb6b78529e3c46c5035b6bad846b53ec64f1ca) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Properties/Resources.resx (.../Resources.resx) (revision 16697317b00bb5ffe52baee7d9e91b42ba1cf743) @@ -120,26 +120,16 @@ De {0} berekening voor grasbekleding erosie kruin en binnentalud '{1}' is niet gelukt. Er is geen foutrapport beschikbaar. - - De overslagdebiet berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Er is geen foutrapport beschikbaar. - De {0} berekening is uitgevoerd op de tijdelijke locatie '{1}'. Gedetailleerde invoer en uitvoer kan in de bestanden op deze locatie worden gevonden. - - Overslagdebiet berekening is uitgevoerd op de tijdelijke locatie '{0}'. Gedetailleerde invoer en uitvoer kan in de bestanden op deze locatie worden gevonden. - Uitvoeren {0} berekening De {0} berekening voor grasbekleding erosie kruin en binnentalud '{1}' is niet gelukt. Bekijk het foutrapport door op details te klikken. {2} - - De overslagdebiet berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken. -{1} - De dijkhoogte berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet geconvergeerd.