/// <summary> /// Performs a piping calculation based on the supplied <see cref="ProbabilisticPipingCalculation"/> and sets <see cref="ProbabilisticPipingCalculation.Output"/> /// if the calculation was successful. Error and status information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="ProbabilisticPipingCalculation"/> that holds all the information required to perform the calculation.</param> /// <param name="generalInput">The <see cref="GeneralPipingInput"/> to derive values from during the calculation.</param> /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> with the /// hydraulic boundary calculation settings.</param> /// <param name="sectionLength">The length of the section the calculation belongs to.</param> /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="generalInput"/> /// or <paramref name="calculationSettings"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path /// contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list></exception> /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception> internal void Calculate(ProbabilisticPipingCalculation calculation, GeneralPipingInput generalInput, HydraulicBoundaryCalculationSettings calculationSettings, double sectionLength) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } if (calculationSettings == null) { throw new ArgumentNullException(nameof(calculationSettings)); } string hydraulicBoundaryDatabaseFilePath = calculationSettings.HydraulicBoundaryDatabaseFilePath; bool usePreprocessor = !string.IsNullOrEmpty(calculationSettings.PreprocessorDirectory); HydraRingCalculationSettings hydraRingCalculationSettings = HydraRingCalculationSettingsFactory.CreateSettings(calculationSettings); profileSpecificCalculator = HydraRingCalculatorFactory.Instance.CreatePipingCalculator( hydraRingCalculationSettings); sectionSpecificCalculator = HydraRingCalculatorFactory.Instance.CreatePipingCalculator( hydraRingCalculationSettings); CalculationServiceHelper.LogCalculationBegin(); try { IPartialProbabilisticPipingOutput profileSpecificOutput = CalculateProfileSpecific( calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor); if (canceled) { return; } IPartialProbabilisticPipingOutput sectionSpecificOutput = CalculateSectionSpecific( calculation, generalInput, sectionLength, hydraulicBoundaryDatabaseFilePath, usePreprocessor); if (canceled) { return; } calculation.Output = new ProbabilisticPipingOutput(sectionSpecificOutput, profileSpecificOutput); } finally { CalculationServiceHelper.LogCalculationEnd(); profileSpecificCalculator = null; sectionSpecificCalculator = null; } }
/// <summary> /// Performs a wave conditions calculation for the wave impact on asphalt failure mechanism based on the supplied /// <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation"/> and sets /// <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation.Output"/> if the calculation was successful. /// Error and status information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation"/> that holds all the information required to perform the calculation.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that holds information about the target probability used in the calculation.</param> /// <param name="generalWaveConditionsInput">Calculation input parameters that apply to all <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation"/> instances.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="assessmentSection"/> /// or <paramref name="generalWaveConditionsInput"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list> /// </exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the target probability or /// calculated probability falls outside the [0.0, 1.0] range and is not <see cref="double.NaN"/>.</exception> /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception> public void Calculate(WaveImpactAsphaltCoverWaveConditionsCalculation calculation, IAssessmentSection assessmentSection, GeneralWaveConditionsInput generalWaveConditionsInput) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (generalWaveConditionsInput == null) { throw new ArgumentNullException(nameof(generalWaveConditionsInput)); } CalculationServiceHelper.LogCalculationBegin(); RoundedDouble a = generalWaveConditionsInput.A; RoundedDouble b = generalWaveConditionsInput.B; RoundedDouble c = generalWaveConditionsInput.C; double targetProbability = WaveConditionsInputHelper.GetTargetProbability(calculation.InputParameters, assessmentSection); RoundedDouble assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(calculation.InputParameters, assessmentSection); CurrentCalculationType = Resources.WaveImpactAsphaltCover_DisplayName; TotalWaterLevelCalculations = calculation.InputParameters.GetWaterLevels(assessmentLevel).Count(); try { IEnumerable <WaveConditionsOutput> outputs = CalculateWaveConditions(calculation.InputParameters, assessmentLevel, a, b, c, targetProbability, assessmentSection.HydraulicBoundaryDatabase); if (!Canceled) { calculation.Output = new WaveImpactAsphaltCoverWaveConditionsOutput(outputs); } } finally { CalculationServiceHelper.LogCalculationEnd(); } }
/// <summary> /// Performs a piping calculation based on the supplied <see cref="SemiProbabilisticPipingCalculation"/> and sets /// <see cref="SemiProbabilisticPipingCalculation.Output"/> if the calculation was successful. Error and status /// information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="SemiProbabilisticPipingCalculation"/> to base the input for the calculation upon.</param> /// <param name="generalInput">The <see cref="GeneralPipingInput"/> to derive values from during the calculation.</param> /// <param name="normativeAssessmentLevel">The normative assessment level to use in case the manual assessment level is not applicable.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/> or <paramref name="generalInput"/> is <c>null</c>.</exception> /// <exception cref="PipingCalculatorException">Thrown when an unexpected error occurred during the calculation.</exception> /// <remarks>Consider calling <see cref="Validate"/> first to see if calculation is possible.</remarks> public static void Calculate(SemiProbabilisticPipingCalculation calculation, GeneralPipingInput generalInput, RoundedDouble normativeAssessmentLevel) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } CalculationServiceHelper.LogCalculationBegin(); try { PipingCalculatorResult pipingResult = new PipingCalculator(CreateInputFromData(calculation.InputParameters, generalInput, normativeAssessmentLevel), PipingSubCalculatorFactory.Instance).Calculate(); calculation.Output = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties { UpliftFactorOfSafety = pipingResult.UpliftFactorOfSafety, HeaveFactorOfSafety = pipingResult.HeaveFactorOfSafety, SellmeijerFactorOfSafety = pipingResult.SellmeijerFactorOfSafety, UpliftEffectiveStress = pipingResult.UpliftEffectiveStress, HeaveGradient = pipingResult.HeaveGradient, SellmeijerCreepCoefficient = pipingResult.SellmeijerCreepCoefficient, SellmeijerCriticalFall = pipingResult.SellmeijerCriticalFall, SellmeijerReducedFall = pipingResult.SellmeijerReducedFall }); } catch (PipingCalculatorException e) { CalculationServiceHelper.LogExceptionAsError(RiskeerCommonServiceResources.CalculationService_Calculate_unexpected_error, e); throw; } finally { CalculationServiceHelper.LogCalculationEnd(); } }
/// <summary> /// Performs a structures calculation based on the supplied <see cref="StructuresCalculation{T}"/> and sets <see cref="StructuresCalculation{T}.Output"/> /// if the calculation was successful. Error and status information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="StructuresCalculation{T}"/> that holds all the information required to perform the calculation.</param> /// <param name="generalInput">General calculation parameters that are the same across all calculations.</param> /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> with the /// hydraulic boundary calculation settings.</param> /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path /// contains invalid characters.</exception> /// <exception cref="InvalidEnumArgumentException">Thrown when an unexpected /// enum value is encountered.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list></exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs while performing the calculation.</exception> public void Calculate(StructuresCalculation <TStructureInput> calculation, TGeneralInput generalInput, HydraulicBoundaryCalculationSettings calculationSettings) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } if (calculationSettings == null) { throw new ArgumentNullException(nameof(calculationSettings)); } TCalculationInput input = CreateInput(calculation.InputParameters, generalInput, calculationSettings.HydraulicBoundaryDatabaseFilePath, !string.IsNullOrEmpty(calculationSettings.PreprocessorDirectory)); calculator = HydraRingCalculatorFactory.Instance.CreateStructuresCalculator <TCalculationInput>( HydraRingCalculationSettingsFactory.CreateSettings(calculationSettings)); string calculationName = calculation.Name; CalculationServiceHelper.LogCalculationBegin(); var exceptionThrown = false; try { PerformCalculation(calculation, input); } catch (HydraRingCalculationException) { if (!canceled) { string lastErrorFileContent = calculator.LastErrorFileContent; string message = string.IsNullOrEmpty(lastErrorFileContent) ? messageProvider.GetCalculationFailedMessage(calculationName) : messageProvider.GetCalculationFailedWithErrorReportMessage(calculationName, lastErrorFileContent); log.Error(message); exceptionThrown = true; throw; } } finally { string lastErrorFileContent = calculator.LastErrorFileContent; bool errorOccurred = CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { log.Error(messageProvider.GetCalculationFailedWithErrorReportMessage(calculationName, lastErrorFileContent)); } log.Info(messageProvider.GetCalculationPerformedMessage(calculator.OutputDirectory)); CalculationServiceHelper.LogCalculationEnd(); if (errorOccurred) { throw new HydraRingCalculationException(lastErrorFileContent); } } }
/// <summary> /// Performs a grass cover erosion inwards calculation based on the supplied <see cref="GrassCoverErosionInwardsCalculation"/> /// and sets <see cref="GrassCoverErosionInwardsCalculation.Output"/> if the calculation was successful. Error and status /// information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="GrassCoverErosionInwardsCalculation"/> that holds all the information required to perform the calculation.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that holds information about the target probability used in the calculation.</param> /// <param name="generalInput">Calculation input parameters that apply to all <see cref="GrassCoverErosionInwardsCalculation"/> instances.</param> /// <exception cref="ArgumentNullException">Thrown when one of the following parameters is <c>null</c>: /// <list type="bullet"> /// <item><paramref name="calculation"/></item> /// <item><paramref name="assessmentSection"/></item> /// <item><paramref name="generalInput"/></item> /// </list></exception> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list> /// </exception> /// <exception cref="SecurityException">Thrown when the temporary working directory can't be accessed due to missing permissions.</exception> /// <exception cref="IOException">Thrown when the specified path is not valid, the network name is not known /// or an I/O error occurred while opening the file.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when the directory can't be created due to missing /// the required permissions.</exception> /// <exception cref="NotSupportedException">Thrown when <see cref="HydraRingCalculationInput.FailureMechanismType"/> /// is not the same with already added input.</exception> /// <exception cref="Win32Exception">Thrown when there was an error in opening the associated file /// or the wait setting could not be accessed.</exception> /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception> internal void Calculate(GrassCoverErosionInwardsCalculation calculation, IAssessmentSection assessmentSection, GeneralGrassCoverErosionInwardsInput generalInput) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } HydraulicBoundaryCalculationSettings calculationSettings = HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase); int numberOfCalculators = CreateCalculators(calculation, calculationSettings); string hydraulicBoundaryDatabaseFilePath = calculationSettings.HydraulicBoundaryDatabaseFilePath; bool usePreprocessor = !string.IsNullOrEmpty(calculationSettings.PreprocessorDirectory); CalculationServiceHelper.LogCalculationBegin(); try { OvertoppingOutput overtoppingOutput = CalculateOvertopping(calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor, numberOfCalculators); if (canceled) { return; } DikeHeightOutput dikeHeightOutput = CalculateDikeHeight(calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor, numberOfCalculators); if (canceled) { return; } OvertoppingRateOutput overtoppingRateOutput = CalculateOvertoppingRate(calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor, numberOfCalculators); if (canceled) { return; } calculation.Output = new GrassCoverErosionInwardsOutput( overtoppingOutput, dikeHeightOutput, overtoppingRateOutput); } finally { CalculationServiceHelper.LogCalculationEnd(); overtoppingCalculator = null; dikeHeightCalculator = null; overtoppingRateCalculator = null; } }
/// <summary> /// Performs a wave conditions calculation for the stability of stone revetment failure mechanism based on the supplied /// <see cref="StabilityStoneCoverWaveConditionsCalculation"/> and sets /// <see cref="StabilityStoneCoverWaveConditionsCalculation.Output"/> if the calculation was successful. /// Error and status information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="StabilityStoneCoverWaveConditionsCalculation"/> that holds all the information required to perform the calculation.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that holds information about the target probability used in the calculation.</param> /// <param name="generalWaveConditionsInput">Calculation input parameters that apply to all <see cref="StabilityStoneCoverWaveConditionsCalculation"/> instances.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="assessmentSection"/> /// or <paramref name="generalWaveConditionsInput"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list> /// </exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the target probability or /// calculated probability falls outside the [0.0, 1.0] range and is not <see cref="double.NaN"/>.</exception> /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception> public void Calculate(StabilityStoneCoverWaveConditionsCalculation calculation, IAssessmentSection assessmentSection, GeneralStabilityStoneCoverWaveConditionsInput generalWaveConditionsInput) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (generalWaveConditionsInput == null) { throw new ArgumentNullException(nameof(generalWaveConditionsInput)); } StabilityStoneCoverWaveConditionsInput calculationInput = calculation.InputParameters; StabilityStoneCoverWaveConditionsCalculationType calculationType = calculationInput.CalculationType; if (!Enum.IsDefined(typeof(StabilityStoneCoverWaveConditionsCalculationType), calculationType)) { throw new InvalidEnumArgumentException(nameof(calculationType), (int)calculationType, typeof(StabilityStoneCoverWaveConditionsCalculationType)); } CalculationServiceHelper.LogCalculationBegin(); double targetProbability = WaveConditionsInputHelper.GetTargetProbability(calculationInput, assessmentSection); RoundedDouble assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(calculationInput, assessmentSection); int waterLevelCount = calculationInput.GetWaterLevels(assessmentLevel).Count(); TotalWaterLevelCalculations = calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both ? waterLevelCount * 2 : waterLevelCount; try { IEnumerable <WaveConditionsOutput> blocksOutputs = null; if (calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both || calculationType == StabilityStoneCoverWaveConditionsCalculationType.Blocks) { CurrentCalculationType = Resources.StabilityStoneCoverWaveConditions_Blocks_DisplayName; blocksOutputs = CalculateBlocks(calculation, assessmentSection, assessmentLevel, generalWaveConditionsInput.GeneralBlocksWaveConditionsInput, targetProbability); } if (Canceled) { return; } IEnumerable <WaveConditionsOutput> columnsOutputs = null; if (calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both || calculationType == StabilityStoneCoverWaveConditionsCalculationType.Columns) { CurrentCalculationType = Resources.StabilityStoneCoverWaveConditions_Columns_DisplayName; columnsOutputs = CalculateColumns(calculation, assessmentSection, assessmentLevel, generalWaveConditionsInput.GeneralColumnsWaveConditionsInput, targetProbability); } if (!Canceled) { calculation.Output = CreateOutput(calculationType, blocksOutputs, columnsOutputs); } } finally { CalculationServiceHelper.LogCalculationEnd(); } }
/// <summary> /// Performs the provided <see cref="DuneLocationCalculation"/> and sets its output if the calculation is successful. /// Error and status information is logged during the execution of the operation. /// </summary> /// <param name="duneLocationCalculation">The <see cref="DuneLocationCalculation"/> to perform.</param> /// <param name="targetProbability">The target probability to use during the calculation.</param> /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> with the /// hydraulic boundary calculation settings.</param> /// <param name="messageProvider">The object which is used to build log messages.</param> /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks> /// <exception cref="ArgumentNullException">Thrown when <paramref name="duneLocationCalculation"/>, /// <paramref name="calculationSettings"/> or <paramref name="messageProvider"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when: /// <list type="bullet"> /// <item>The hydraulic boundary location database file path contains invalid characters.</item> /// <item>The contribution of the failure mechanism is zero.</item> /// <item>The target probability or the calculated probability falls outside the [0.0, 1.0] /// range and is not <see cref="double.NaN"/>.</item> /// </list></exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list></exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs while performing /// the calculation.</exception> public void Calculate(DuneLocationCalculation duneLocationCalculation, double targetProbability, HydraulicBoundaryCalculationSettings calculationSettings, ICalculationMessageProvider messageProvider) { if (duneLocationCalculation == null) { throw new ArgumentNullException(nameof(duneLocationCalculation)); } if (calculationSettings == null) { throw new ArgumentNullException(nameof(calculationSettings)); } if (messageProvider == null) { throw new ArgumentNullException(nameof(messageProvider)); } DuneLocation duneLocation = duneLocationCalculation.DuneLocation; string duneLocationName = duneLocation.Name; CalculationServiceHelper.LogCalculationBegin(); HydraRingCalculationSettings hydraRingCalculationSettings = HydraRingCalculationSettingsFactory.CreateSettings(calculationSettings); calculator = HydraRingCalculatorFactory.Instance.CreateDunesBoundaryConditionsCalculator(hydraRingCalculationSettings); var exceptionThrown = false; try { DunesBoundaryConditionsCalculationInput calculationInput = CreateInput(duneLocation, targetProbability, calculationSettings); calculator.Calculate(calculationInput); if (string.IsNullOrEmpty(calculator.LastErrorFileContent)) { duneLocationCalculation.Output = CreateDuneLocationCalculationOutput(duneLocationName, calculationInput.Beta, targetProbability, messageProvider); } } catch (HydraRingCalculationException) { if (!canceled) { string lastErrorContent = calculator.LastErrorFileContent; log.Error(string.IsNullOrEmpty(lastErrorContent) ? messageProvider.GetCalculationFailedMessage(duneLocationName) : messageProvider.GetCalculationFailedWithErrorReportMessage(duneLocationName, lastErrorContent)); exceptionThrown = true; throw; } } finally { string lastErrorFileContent = calculator.LastErrorFileContent; bool hasErrorOccurred = CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (hasErrorOccurred) { log.Error(messageProvider.GetCalculationFailedWithErrorReportMessage(duneLocationName, lastErrorFileContent)); } log.InfoFormat(Resources.DuneLocationCalculationService_Calculate_Calculation_temporary_directory_can_be_found_on_location_0, calculator.OutputDirectory); CalculationServiceHelper.LogCalculationEnd(); if (hasErrorOccurred) { throw new HydraRingCalculationException(lastErrorFileContent); } } }
/// <summary> /// Performs a wave conditions calculation for the grass cover erosion outwards failure mechanism based on the supplied /// <see cref="GrassCoverErosionOutwardsWaveConditionsCalculation"/> and sets /// <see cref="GrassCoverErosionOutwardsWaveConditionsCalculation.Output"/> if the calculation was successful. /// Error and status information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="GrassCoverErosionOutwardsWaveConditionsCalculation"/> that holds all the information required to perform the calculation.</param> /// <param name="failureMechanism">The grass cover erosion outwards failure mechanism, which contains general parameters that apply to all /// <see cref="GrassCoverErosionOutwardsWaveConditionsCalculation"/> instances.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that holds information about the target probability used in the calculation.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="failureMechanism"/> /// or <paramref name="assessmentSection"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when: /// <list type="bullet"> /// <item>the hydraulic boundary database file path contains invalid characters.</item> /// <item><paramref name="failureMechanism"/> has no (0) contribution.</item> /// </list></exception> /// <exception cref="InvalidEnumArgumentException">Thrown when an unexpected /// enum value is encountered.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list> /// </exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the target probability or /// calculated probability falls outside the [0.0, 1.0] range and is not <see cref="double.NaN"/>.</exception> /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception> /// <exception cref="NotSupportedException">Thrown when <see cref="GrassCoverErosionOutwardsWaveConditionsCalculationType"/> /// is a valid value, but unsupported.</exception> public void Calculate(GrassCoverErosionOutwardsWaveConditionsCalculation calculation, GrassCoverErosionOutwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } GrassCoverErosionOutwardsWaveConditionsInput calculationInput = calculation.InputParameters; GrassCoverErosionOutwardsWaveConditionsCalculationType calculationType = calculationInput.CalculationType; if (!Enum.IsDefined(typeof(GrassCoverErosionOutwardsWaveConditionsCalculationType), calculationType)) { throw new InvalidEnumArgumentException(nameof(calculationType), (int)calculationType, typeof(GrassCoverErosionOutwardsWaveConditionsCalculationType)); } CalculationServiceHelper.LogCalculationBegin(); RoundedDouble assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(calculationInput, assessmentSection); double targetProbability = WaveConditionsInputHelper.GetTargetProbability(calculationInput, assessmentSection); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; DetermineTotalWaterLevelCalculations(calculationInput, assessmentLevel); try { IEnumerable <WaveConditionsOutput> waveRunUpOutput = null; if (ShouldCalculateWaveRunUp(calculationType)) { CurrentCalculationType = Resources.GrassCoverErosionOutwardsWaveConditions_WaveRunUp_DisplayName; waveRunUpOutput = CalculateWaveRunUp(calculation, failureMechanism, hydraulicBoundaryDatabase, assessmentLevel, targetProbability); } if (Canceled) { return; } IEnumerable <WaveConditionsOutput> waveImpactOutput = null; if (ShouldCalculateWaveImpact(calculationType)) { CurrentCalculationType = Resources.GrassCoverErosionOutwardsWaveConditions_WaveImpact_DisplayName; waveImpactOutput = CalculateWaveImpact(calculation, failureMechanism, hydraulicBoundaryDatabase, assessmentLevel, targetProbability); } IEnumerable <WaveConditionsOutput> waveImpactWithWaveDirectionOutput = null; if (ShouldCalculateWaveImpactWithWaveDirection(calculationType)) { CurrentCalculationType = Resources.GrassCoverErosionOutwardsWaveConditions_WaveImpactWithWaveDirection_DisplayName; waveImpactWithWaveDirectionOutput = CalculateWaveImpactWithWaveDirection(calculation, failureMechanism, hydraulicBoundaryDatabase, assessmentLevel, targetProbability); } if (!Canceled) { calculation.Output = CreateOutput(calculationType, waveRunUpOutput, waveImpactOutput, waveImpactWithWaveDirectionOutput); } } finally { CalculationServiceHelper.LogCalculationEnd(); } }
/// <summary> /// Performs a macro stability inwards calculation based on the supplied <see cref="MacroStabilityInwardsCalculation"/> /// and sets <see cref="MacroStabilityInwardsCalculation.Output"/> based on the result if the calculation was successful. /// Error and status information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="MacroStabilityInwardsCalculation"/> to base the input for the calculation upon.</param> /// <param name="generalInput">General calculation parameters that are the same across all calculations.</param> /// <param name="normativeAssessmentLevel">The normative assessment level to use in case the manual assessment level is not applicable.</param> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> /// <exception cref="UpliftVanCalculatorException">Thrown when an error (both expected or unexpected) occurred during the calculation.</exception> /// <remarks>Consider calling <see cref="Validate"/> first to see if calculation is possible.</remarks> public static void Calculate(MacroStabilityInwardsCalculation calculation, GeneralMacroStabilityInwardsInput generalInput, RoundedDouble normativeAssessmentLevel) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } UpliftVanCalculatorResult macroStabilityInwardsResult; CalculationServiceHelper.LogCalculationBegin(); try { IUpliftVanCalculator calculator = GetCalculator(calculation, generalInput, normativeAssessmentLevel); macroStabilityInwardsResult = calculator.Calculate(); } catch (UpliftVanCalculatorException e) { var stringBuilder = new StringBuilder(); stringBuilder.AppendLine(Resources.MacroStabilityInwardsCalculationService_Calculate_Kernel_provides_messages); foreach (MacroStabilityInwardsKernelMessage kernelMessage in e.KernelMessages) { stringBuilder.AppendLine(string.Format(Resources.MacroStabilityInwardsCalculationService_Calculate_LogMessageType_0_LogMessage_1, kernelMessage.Type, kernelMessage.Message)); } CalculationServiceHelper.LogExceptionAsError($"{RiskeerCommonServiceResources.CalculationService_Calculate_unexpected_error} {stringBuilder}", e); CalculationServiceHelper.LogCalculationEnd(); throw; } if (macroStabilityInwardsResult.CalculationMessages.Any(cm => cm.Type == MacroStabilityInwardsKernelMessageType.Error)) { CalculationServiceHelper.LogMessagesAsError(new[] { CreateAggregatedLogMessage(Resources.MacroStabilityInwardsCalculationService_Calculate_Errors_in_MacroStabilityInwards_calculation, macroStabilityInwardsResult) }); CalculationServiceHelper.LogCalculationEnd(); throw new UpliftVanCalculatorException(); } if (macroStabilityInwardsResult.CalculationMessages.Any()) { CalculationServiceHelper.LogMessagesAsWarning(new[] { CreateAggregatedLogMessage(Resources.MacroStabilityInwardsCalculationService_Calculate_Warnings_in_MacroStabilityInwards_calculation, macroStabilityInwardsResult) }); } calculation.Output = new MacroStabilityInwardsOutput( MacroStabilityInwardsSlidingCurveConverter.Convert(macroStabilityInwardsResult.SlidingCurveResult), MacroStabilityInwardsSlipPlaneUpliftVanConverter.Convert(macroStabilityInwardsResult.CalculationGridResult), new MacroStabilityInwardsOutput.ConstructionProperties { FactorOfStability = macroStabilityInwardsResult.FactorOfStability, ForbiddenZonesXEntryMin = macroStabilityInwardsResult.ForbiddenZonesXEntryMin, ForbiddenZonesXEntryMax = macroStabilityInwardsResult.ForbiddenZonesXEntryMax }); CalculationServiceHelper.LogCalculationEnd(); }