// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic; using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Service; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Service.Properties; using Ringtoets.HydraRing.Calculation.Data; using Ringtoets.HydraRing.Calculation.Data.Input.Structures; using Ringtoets.HydraRing.Calculation.Data.Output; using Ringtoets.HydraRing.Calculation.Parsers; using Ringtoets.HydraRing.Calculation.Services; using Ringtoets.HydraRing.IO; using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources; namespace Ringtoets.HeightStructures.Service { /// /// Service that provides methods for performing Hydra-Ring calculations for height structures calculations. /// public static class HeightStructuresCalculationService { private static readonly ILog log = LogManager.GetLogger(typeof(HeightStructuresCalculationService)); /// /// Performs validation over the values on the given . Error and status information is logged during /// the execution of the operation. /// /// The for which to validate the values. /// The for which to validate the values. /// Truec> if has no validation errors; Falsec> otherwise. public static bool Validate(HeightStructuresCalculation calculation, IAssessmentSection assessmentSection) { return CalculationServiceHelper.PerformValidation(calculation.Name, () => ValidateInput(calculation.InputParameters, assessmentSection)); } /// /// Performs a height structures calculation 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 directory of the HLCD file that should be used for performing the calculation. /// The to create input with. /// The id of the ring to perform the calculation for. /// The to create the input with for the calculation. /// A on a successful calculation, null otherwise. internal static ExceedanceProbabilityCalculationOutput Calculate(HeightStructuresCalculation calculation, string hlcdDirectory, FailureMechanismSection failureMechanismSection, string ringId, GeneralHeightStructuresInput generalInput) { StructuresOvertoppingCalculationInput input = CreateInput(calculation, failureMechanismSection, generalInput); var exceedanceProbabilityCalculationParser = new ExceedanceProbabilityCalculationParser(); CalculationServiceHelper.PerformCalculation( calculation.Name, () => { HydraRingCalculationService.PerformCalculation( hlcdDirectory, ringId, HydraRingTimeIntegrationSchemeType.FerryBorgesCastanheta, HydraRingUncertaintiesType.All, input, new [] { exceedanceProbabilityCalculationParser }); VerifyOutput(exceedanceProbabilityCalculationParser.Output, calculation.Name); }); return exceedanceProbabilityCalculationParser.Output; } private static void VerifyOutput(ExceedanceProbabilityCalculationOutput output, string name) { if (output == null) { log.ErrorFormat(Resources.HeightStructuresCalculationService_Calculate_Error_in_height_structures_0_calculation, name); } } private static StructuresOvertoppingCalculationInput CreateInput(HeightStructuresCalculation calculation, FailureMechanismSection failureMechanismSection, GeneralHeightStructuresInput generalInput) { return new StructuresOvertoppingCalculationInput( calculation.InputParameters.HydraulicBoundaryLocation.Id, new HydraRingSection(1, failureMechanismSection.Name, failureMechanismSection.GetSectionLength(), calculation.InputParameters.OrientationOfTheNormalOfTheStructure), generalInput.GravitationalAcceleration, generalInput.ModelFactorOvertoppingFlow.Mean, generalInput.ModelFactorOvertoppingFlow.StandardDeviation, calculation.InputParameters.LevelOfCrestOfStructure.Mean, calculation.InputParameters.LevelOfCrestOfStructure.StandardDeviation, calculation.InputParameters.OrientationOfTheNormalOfTheStructure, calculation.InputParameters.ModelFactorOvertoppingSuperCriticalFlow.Mean, calculation.InputParameters.ModelFactorOvertoppingSuperCriticalFlow.StandardDeviation, calculation.InputParameters.AllowableIncreaseOfLevelForStorage.Mean, calculation.InputParameters.AllowableIncreaseOfLevelForStorage.StandardDeviation, generalInput.ModelFactorForStorageVolume.Mean, generalInput.ModelFactorForStorageVolume.StandardDeviation, calculation.InputParameters.StorageStructureArea.Mean, calculation.InputParameters.StorageStructureArea.GetVariationCoefficient(), generalInput.ModelFactorForIncomingFlowVolume, calculation.InputParameters.FlowWidthAtBottomProtection.Mean, calculation.InputParameters.FlowWidthAtBottomProtection.StandardDeviation, calculation.InputParameters.CriticalOvertoppingDischarge.Mean, calculation.InputParameters.CriticalOvertoppingDischarge.GetVariationCoefficient(), calculation.InputParameters.FailureProbabilityOfStructureGivenErosion, calculation.InputParameters.WidthOfFlowApertures.Mean, calculation.InputParameters.WidthOfFlowApertures.GetVariationCoefficient(), calculation.InputParameters.DeviationOfTheWaveDirection, calculation.InputParameters.StormDuration.Mean, calculation.InputParameters.StormDuration.GetVariationCoefficient()); } private static string[] ValidateInput(HeightStructuresInput inputParameters, IAssessmentSection assessmentSection) { List validationResult = new List(); if (inputParameters.HydraulicBoundaryLocation == null) { validationResult.Add(RingtoetsCommonServiceResources.CalculationService_ValidateInput_No_hydraulic_boundary_location_selected); } var validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(assessmentSection.HydraulicBoundaryDatabase.FilePath); if (!string.IsNullOrEmpty(validationProblem)) { validationResult.Add(validationProblem); } return validationResult.ToArray(); } } }