// 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 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.Revetment.Service.Properties; using Ringtoets.WaveImpactAsphaltCover.Data; namespace Ringtoets.WaveImpactAsphaltCover.Service { /// /// Service that provides methods for performing Hydra-Ring wave conditions calculations for the wave impact on asphalt failure mechanism. /// public class WaveImpactAsphaltCoverWaveConditionsCalculationService : WaveConditionsCalculationServiceBase { /// /// 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 assessment level to use for determining water levels. /// 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(WaveImpactAsphaltCoverWaveConditionsCalculation calculation, RoundedDouble assessmentLevel, string hydraulicBoundaryDatabaseFilePath, string preprocessorDirectory) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } return ValidateWaveConditionsInput(calculation.InputParameters, assessmentLevel, hydraulicBoundaryDatabaseFilePath, preprocessorDirectory, Resources.WaveConditionsCalculationService_ValidateInput_default_DesignWaterLevel_name); } /// /// Performs a wave conditions calculation for the wave impact on asphalt 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(WaveImpactAsphaltCoverWaveConditionsCalculation calculation, IAssessmentSection assessmentSection, GeneralWaveConditionsInput 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 a = generalWaveConditionsInput.A; RoundedDouble b = generalWaveConditionsInput.B; RoundedDouble c = generalWaveConditionsInput.C; double norm = assessmentSection.GetNorm(calculation.InputParameters.CategoryType); string preprocessorDirectory = assessmentSection.HydraulicBoundaryDatabase.EffectivePreprocessorDirectory(); RoundedDouble assessmentLevel = assessmentSection.GetAssessmentLevel(calculation.InputParameters.HydraulicBoundaryLocation, calculation.InputParameters.CategoryType); TotalWaterLevelCalculations = calculation.InputParameters.GetWaterLevels(assessmentLevel).Count(); try { IEnumerable outputs = CalculateWaveConditions(calculation.InputParameters, assessmentLevel, a, b, c, norm, hlcdFilePath, preprocessorDirectory); if (!Canceled) { calculation.Output = new WaveImpactAsphaltCoverWaveConditionsOutput(outputs); } } finally { CalculationServiceHelper.LogCalculationEnd(); } } } }