// 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.Linq; using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Properties; namespace Ringtoets.Common.Data.Structures { /// /// Base class that holds generic structures calculation input parameters. /// /// The type of structure contained by the input. public abstract class StructuresInputBase : CloneableObservable, IStructuresCalculationInput, IUseBreakWater, IUseForeshore, IHasForeshoreProfile where T : StructureBase { private const int structureNormalOrientationNumberOfDecimals = 2; private static readonly Range structureNormalOrientationValidityRange = new Range(new RoundedDouble(structureNormalOrientationNumberOfDecimals), new RoundedDouble(structureNormalOrientationNumberOfDecimals, 360)); private NormalDistribution modelFactorSuperCriticalFlow; private LogNormalDistribution allowedLevelIncreaseStorage; private VariationCoefficientLogNormalDistribution storageStructureArea; private LogNormalDistribution flowWidthAtBottomProtection; private VariationCoefficientLogNormalDistribution criticalOvertoppingDischarge; private NormalDistribution widthFlowApertures; private VariationCoefficientLogNormalDistribution stormDuration; private T structure; private RoundedDouble structureNormalOrientation; private double failureProbabilityStructureWithErosion; private ForeshoreProfile foreshoreProfile; /// /// Creates a new instance of the class. /// protected StructuresInputBase() { modelFactorSuperCriticalFlow = new NormalDistribution(2) { Mean = (RoundedDouble) 1.1, StandardDeviation = (RoundedDouble) 0.03 }; stormDuration = new VariationCoefficientLogNormalDistribution(2) { Mean = (RoundedDouble) 6.0, CoefficientOfVariation = (RoundedDouble) 0.25 }; structureNormalOrientation = new RoundedDouble(structureNormalOrientationNumberOfDecimals); allowedLevelIncreaseStorage = new LogNormalDistribution(2); storageStructureArea = new VariationCoefficientLogNormalDistribution(2); flowWidthAtBottomProtection = new LogNormalDistribution(2); criticalOvertoppingDischarge = new VariationCoefficientLogNormalDistribution(2); failureProbabilityStructureWithErosion = 1.0; widthFlowApertures = new NormalDistribution(2); SetDefaultCommonStructureSchematizationProperties(); SynchronizeForeshoreProfileInput(); } #region Model factors /// /// Gets or sets the model factor for the super critical flow. /// /// Only sets the mean. public NormalDistribution ModelFactorSuperCriticalFlow { get { return modelFactorSuperCriticalFlow; } set { modelFactorSuperCriticalFlow.Mean = value.Mean; } } #endregion /// /// Gets the value true if the parameters of the instance of /// that are derived from /// match the properties of ; /// or false if this is not the case, or if there is no /// assigned. /// public abstract bool IsStructureInputSynchronized { get; } /// /// Gets or sets if the illustration points should be calculated. /// public bool ShouldIllustrationPointsBeCalculated { get; set; } /// /// Gets or sets the structure. /// public T Structure { get { return structure; } set { structure = value; if (structure == null) { SetDefaultCommonStructureSchematizationProperties(); } SynchronizeStructureInput(); } } /// /// Applies the properties of the to the /// parameters of the instance of . /// /// When no structure is present, the input parameters are set to default values. public abstract void SynchronizeStructureInput(); public override object Clone() { var clone = (StructuresInputBase) base.Clone(); clone.modelFactorSuperCriticalFlow = (NormalDistribution) ModelFactorSuperCriticalFlow.Clone(); clone.allowedLevelIncreaseStorage = (LogNormalDistribution) AllowedLevelIncreaseStorage.Clone(); clone.storageStructureArea = (VariationCoefficientLogNormalDistribution) StorageStructureArea.Clone(); clone.flowWidthAtBottomProtection = (LogNormalDistribution) FlowWidthAtBottomProtection.Clone(); clone.criticalOvertoppingDischarge = (VariationCoefficientLogNormalDistribution) CriticalOvertoppingDischarge.Clone(); clone.widthFlowApertures = (NormalDistribution) WidthFlowApertures.Clone(); clone.stormDuration = (VariationCoefficientLogNormalDistribution) StormDuration.Clone(); clone.BreakWater = (BreakWater) BreakWater.Clone(); return clone; } private void SetDefaultCommonStructureSchematizationProperties() { StructureNormalOrientation = RoundedDouble.NaN; AllowedLevelIncreaseStorage = new LogNormalDistribution { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }; StorageStructureArea = new VariationCoefficientLogNormalDistribution { Mean = RoundedDouble.NaN, CoefficientOfVariation = RoundedDouble.NaN }; FlowWidthAtBottomProtection = new LogNormalDistribution { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }; CriticalOvertoppingDischarge = new VariationCoefficientLogNormalDistribution { Mean = RoundedDouble.NaN, CoefficientOfVariation = RoundedDouble.NaN }; WidthFlowApertures = new NormalDistribution { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }; } #region Hydraulic data /// /// Gets or sets the hydraulic boundary location. /// public HydraulicBoundaryLocation HydraulicBoundaryLocation { get; set; } /// /// Gets or sets the storm duration. /// [h] /// /// Only sets the mean. public VariationCoefficientLogNormalDistribution StormDuration { get { return stormDuration; } set { stormDuration.Mean = value.Mean; } } #endregion #region Schematization /// /// Gets or sets the orientation of the normal of the structure. /// [degrees] /// ///Thrown when the value of the orientation /// is not in the interval [0, 360]. public RoundedDouble StructureNormalOrientation { get { return structureNormalOrientation; } set { RoundedDouble newStructureNormalOrientation = value.ToPrecision(structureNormalOrientation.NumberOfDecimalPlaces); if (!double.IsNaN(newStructureNormalOrientation) && !structureNormalOrientationValidityRange.InRange(newStructureNormalOrientation)) { throw new ArgumentOutOfRangeException(null, string.Format(Resources.Orientation_Value_needs_to_be_in_Range_0_, structureNormalOrientationValidityRange)); } structureNormalOrientation = newStructureNormalOrientation; } } /// /// Gets or sets the allowed increase of level for storage. /// [m] /// public LogNormalDistribution AllowedLevelIncreaseStorage { get { return allowedLevelIncreaseStorage; } set { allowedLevelIncreaseStorage.Mean = value.Mean; allowedLevelIncreaseStorage.StandardDeviation = value.StandardDeviation; } } /// /// Gets or sets the storage structure area. /// [m^2] /// public VariationCoefficientLogNormalDistribution StorageStructureArea { get { return storageStructureArea; } set { storageStructureArea.Mean = value.Mean; storageStructureArea.CoefficientOfVariation = value.CoefficientOfVariation; } } /// /// Gets or sets the flow width at the bottom protection. /// [m] /// public LogNormalDistribution FlowWidthAtBottomProtection { get { return flowWidthAtBottomProtection; } set { flowWidthAtBottomProtection.Mean = value.Mean; flowWidthAtBottomProtection.StandardDeviation = value.StandardDeviation; } } /// /// Gets or sets the critical overtopping discharge per meter. /// [m^3/s/m] /// public VariationCoefficientLogNormalDistribution CriticalOvertoppingDischarge { get { return criticalOvertoppingDischarge; } set { criticalOvertoppingDischarge.Mean = value.Mean; criticalOvertoppingDischarge.CoefficientOfVariation = value.CoefficientOfVariation; } } /// /// Gets or sets the failure probability of structure given erosion. /// [1/year] /// /// Thrown when the value of the probability /// is not in the interval [0, 1]. public double FailureProbabilityStructureWithErosion { get { return failureProbabilityStructureWithErosion; } set { ProbabilityHelper.ValidateProbability(value, null, Resources.FailureProbability_Value_needs_to_be_in_Range_0_); failureProbabilityStructureWithErosion = value; } } /// /// Gets or sets the width of flow apertures. /// [m] /// public NormalDistribution WidthFlowApertures { get { return widthFlowApertures; } set { widthFlowApertures.Mean = value.Mean; widthFlowApertures.StandardDeviation = value.StandardDeviation; } } #endregion #region Foreshore profile /// /// Gets or sets the foreshore profile. /// public ForeshoreProfile ForeshoreProfile { get { return foreshoreProfile; } set { foreshoreProfile = value; SynchronizeForeshoreProfileInput(); } } public bool UseBreakWater { get; set; } public BreakWater BreakWater { get; private set; } public bool UseForeshore { get; set; } public RoundedPoint2DCollection ForeshoreGeometry { get { return foreshoreProfile != null ? foreshoreProfile.Geometry : new RoundedPoint2DCollection(2, Enumerable.Empty()); } } private static BreakWater GetDefaultBreakWater() { return new BreakWater(BreakWaterType.Dam, 0.0); } public void ClearStructure() { Structure = null; } public bool IsForeshoreProfileInputSynchronized { get { return foreshoreProfile != null && UseForeshore == foreshoreProfile.Geometry.Count() > 1 && UseBreakWater == foreshoreProfile.HasBreakWater && BreakWater.Equals(foreshoreProfile.HasBreakWater ? foreshoreProfile.BreakWater : GetDefaultBreakWater()); } } public void SynchronizeForeshoreProfileInput() { if (foreshoreProfile == null) { UseForeshore = false; UseBreakWater = false; BreakWater = GetDefaultBreakWater(); } else { UseForeshore = foreshoreProfile.Geometry.Count() > 1; UseBreakWater = foreshoreProfile.HasBreakWater; BreakWater = foreshoreProfile.HasBreakWater ? new BreakWater(foreshoreProfile.BreakWater.Type, foreshoreProfile.BreakWater.Height) : GetDefaultBreakWater(); } } #endregion } }