// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using System.Linq; using Core.Common.Base.Data; using Core.Common.Base.IO; using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Service; using Ringtoets.HydraRing.Calculation.Exceptions; using Ringtoets.Revetment.Data; using Ringtoets.Revetment.Service; using Ringtoets.StabilityStoneCover.Data; using Ringtoets.StabilityStoneCover.Service.Properties; using RingtoetsRevetmentsServicesResources = Ringtoets.Revetment.Service.Properties.Resources; namespace Ringtoets.StabilityStoneCover.Service { /// /// Service that provides methods for performing Hydra-Ring wave conditions calculations for the stability of stone revetment failure mechanism. /// public class StabilityStoneCoverWaveConditionsCalculationService : WaveConditionsCalculationServiceBase { private readonly ILog log = LogManager.GetLogger(typeof(StabilityStoneCoverWaveConditionsCalculationService)); /// /// Performs validation over the input parameters. Error and status information is logged during the execution of the operation. /// /// The for which to validate the values. /// The file path of the hydraulic boundary database file which to validate. /// The preprocessor directory to validate. /// true if there were no validation errors; false otherwise. /// Thrown when is null. public static bool Validate(StabilityStoneCoverWaveConditionsCalculation calculation, string hydraulicBoundaryDatabaseFilePath, string preprocessorDirectory) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } return ValidateWaveConditionsInput( calculation.InputParameters, hydraulicBoundaryDatabaseFilePath, preprocessorDirectory, RingtoetsRevetmentsServicesResources.WaveConditionsCalculationService_ValidateInput_default_DesignWaterLevel_name); } /// /// Performs a wave conditions calculation for the stability of stone revetment failure mechanism based on the supplied /// and sets /// if the calculation was successful. /// Error and status information is logged during the execution of the operation. /// /// The that holds all the information required to perform the calculation. /// The that holds information about the norm used in the calculation. /// Calculation input parameters that apply to all instances. /// The path of the HLCD file that should be used for performing the calculation. /// Thrown when , /// or is null. /// Thrown when the contains invalid characters. /// Thrown when: /// /// No settings database file could be found at the location of /// with the same name. /// Unable to open settings database file. /// Unable to read required data from database file. /// /// /// Thrown when the target probability or /// calculated probability falls outside the [0.0, 1.0] range and is not . /// Thrown when an error occurs during parsing of the Hydra-Ring output. /// Thrown when an error occurs during the calculation. public void Calculate(StabilityStoneCoverWaveConditionsCalculation calculation, IAssessmentSection assessmentSection, GeneralStabilityStoneCoverWaveConditionsInput generalWaveConditionsInput, string hlcdFilePath) { 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 aBlocks = generalWaveConditionsInput.GeneralBlocksWaveConditionsInput.A; RoundedDouble bBlocks = generalWaveConditionsInput.GeneralBlocksWaveConditionsInput.B; RoundedDouble cBlocks = generalWaveConditionsInput.GeneralBlocksWaveConditionsInput.C; RoundedDouble aColumns = generalWaveConditionsInput.GeneralColumnsWaveConditionsInput.A; RoundedDouble bColumns = generalWaveConditionsInput.GeneralColumnsWaveConditionsInput.B; RoundedDouble cColumns = generalWaveConditionsInput.GeneralColumnsWaveConditionsInput.C; double norm = assessmentSection.FailureMechanismContribution.Norm; string preprocessorDirectory = assessmentSection.HydraulicBoundaryDatabase.EffectivePreprocessorDirectory(); TotalWaterLevelCalculations = calculation.InputParameters.WaterLevels.Count() * 2; try { log.InfoFormat(Resources.StabilityStoneCoverWaveConditionsCalculationService_Calculate_Calculation_for_blocks_started); IEnumerable blocksOutputs = CalculateWaveConditions(calculation.InputParameters, aBlocks, bBlocks, cBlocks, norm, hlcdFilePath, preprocessorDirectory); log.InfoFormat(Resources.StabilityStoneCoverWaveConditionsCalculationService_Calculate_Calculation_for_blocks_finished); IEnumerable columnsOutputs = null; if (!Canceled) { log.InfoFormat(Resources.StabilityStoneCoverWaveConditionsCalculationService_Calculate_Calculation_for_columns_started); columnsOutputs = CalculateWaveConditions(calculation.InputParameters, aColumns, bColumns, cColumns, norm, hlcdFilePath, preprocessorDirectory); log.InfoFormat(Resources.StabilityStoneCoverWaveConditionsCalculationService_Calculate_Calculation_for_columns_finished); } if (!Canceled) { calculation.Output = new StabilityStoneCoverWaveConditionsOutput(columnsOutputs, blocksOutputs); } } finally { CalculationServiceHelper.LogCalculationEnd(); } } } }