/// <summary>
        /// Creates an instance of <see cref="OvertoppingRateCalculationInput"/> for calculation purposes.
        /// </summary>
        /// <param name="calculation">The calculation containing the input for the overtopping rate calculation.</param>
        /// <param name="generalInput">The general grass cover erosion inwards calculation input parameters.</param>
        /// <param name="hydraulicBoundaryDatabaseFilePath">The path which points to the hydraulic boundary database file.</param>
        /// <param name="usePreprocessor">Indicator whether to use the preprocessor in the calculation.</param>
        /// <returns>A new <see cref="OvertoppingRateCalculationInput"/> instance.</returns>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="hydraulicBoundaryDatabaseFilePath"/>
        /// contains invalid characters.</exception>
        /// <exception cref="CriticalFileReadException">Thrown when:
        /// <list type="bullet">
        /// <item>No settings database file could be found at the location of <paramref name="hydraulicBoundaryDatabaseFilePath"/>
        /// 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>
        private static OvertoppingRateCalculationInput CreateOvertoppingRateInput(GrassCoverErosionInwardsCalculation calculation,
                                                                                  GeneralGrassCoverErosionInwardsInput generalInput,
                                                                                  string hydraulicBoundaryDatabaseFilePath,
                                                                                  bool usePreprocessor)
        {
            var overtoppingRateCalculationInput = new OvertoppingRateCalculationInput(calculation.InputParameters.HydraulicBoundaryLocation.Id,
                                                                                      calculation.InputParameters.OvertoppingRateTargetProbability,
                                                                                      calculation.InputParameters.Orientation,
                                                                                      ParseProfilePoints(calculation.InputParameters.DikeGeometry),
                                                                                      HydraRingInputParser.ParseForeshore(calculation.InputParameters),
                                                                                      HydraRingInputParser.ParseBreakWater(calculation.InputParameters),
                                                                                      calculation.InputParameters.DikeHeight,
                                                                                      generalInput.CriticalOvertoppingModelFactor,
                                                                                      generalInput.FbFactor.Mean,
                                                                                      generalInput.FbFactor.StandardDeviation,
                                                                                      generalInput.FbFactor.LowerBoundary,
                                                                                      generalInput.FbFactor.UpperBoundary,
                                                                                      generalInput.FnFactor.Mean,
                                                                                      generalInput.FnFactor.StandardDeviation,
                                                                                      generalInput.FnFactor.LowerBoundary,
                                                                                      generalInput.FnFactor.UpperBoundary,
                                                                                      generalInput.OvertoppingModelFactor,
                                                                                      generalInput.FrunupModelFactor.Mean,
                                                                                      generalInput.FrunupModelFactor.StandardDeviation,
                                                                                      generalInput.FrunupModelFactor.LowerBoundary,
                                                                                      generalInput.FrunupModelFactor.UpperBoundary,
                                                                                      generalInput.FshallowModelFactor.Mean,
                                                                                      generalInput.FshallowModelFactor.StandardDeviation,
                                                                                      generalInput.FshallowModelFactor.LowerBoundary,
                                                                                      generalInput.FshallowModelFactor.UpperBoundary);

            HydraRingSettingsDatabaseHelper.AssignSettingsFromDatabase(overtoppingRateCalculationInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor);

            return(overtoppingRateCalculationInput);
        }
Example #2
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var random           = new Random(21);
            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism
            {
                InAssembly   = random.NextBoolean(),
                GeneralInput =
                {
                    ApplyLengthEffectInSection = random.NextBoolean()
                }
            };

            // Call
            var properties = new GrassCoverErosionInwardsFailureMechanismProperties(failureMechanism);

            // Assert
            Assert.IsInstanceOf <GrassCoverErosionInwardsFailureMechanismPropertiesBase>(properties);
            Assert.AreEqual(failureMechanism.Name, properties.Name);
            Assert.AreEqual(failureMechanism.Code, properties.Code);
            Assert.AreEqual(failureMechanism.InAssembly, properties.InAssembly);

            GeneralGrassCoverErosionInwardsInput generalInput = failureMechanism.GeneralInput;

            Assert.AreEqual(2, properties.N.NumberOfDecimalPlaces);
            Assert.AreEqual(generalInput.N,
                            properties.N,
                            properties.N.GetAccuracy());
            Assert.AreEqual(generalInput.ApplyLengthEffectInSection, properties.ApplyLengthEffectInSection);
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            // Call
            var properties = new GrassCoverErosionInwardsFailureMechanismProperties(
                failureMechanism);

            // Assert
            Assert.IsInstanceOf <GrassCoverErosionInwardsFailureMechanismPropertiesBase>(properties);
            Assert.AreEqual(failureMechanism.Name, properties.Name);
            Assert.AreEqual(failureMechanism.Code, properties.Code);

            GeneralGrassCoverErosionInwardsInput generalInput = failureMechanism.GeneralInput;

            Assert.AreEqual(generalInput.FbFactor.Mean, properties.FbFactor.Mean);
            Assert.AreEqual(generalInput.FbFactor.StandardDeviation, properties.FbFactor.StandardDeviation);

            Assert.AreEqual(generalInput.FnFactor.Mean, properties.FnFactor.Mean);
            Assert.AreEqual(generalInput.FnFactor.StandardDeviation, properties.FnFactor.StandardDeviation);

            Assert.AreEqual(generalInput.FrunupModelFactor.Mean, properties.FrunupModelFactor.Mean);
            Assert.AreEqual(generalInput.FrunupModelFactor.StandardDeviation, properties.FrunupModelFactor.StandardDeviation);

            Assert.AreEqual(generalInput.FshallowModelFactor.Mean, properties.FshallowModelFactor.Mean);
            Assert.AreEqual(generalInput.FshallowModelFactor.StandardDeviation, properties.FshallowModelFactor.StandardDeviation);
        }
Example #4
0
        public void N_SetValidValue_UpdatesValue(double value)
        {
            // Setup
            var generalGrassCoverErosionInwardsInput = new GeneralGrassCoverErosionInwardsInput();

            // Call
            generalGrassCoverErosionInwardsInput.N = (RoundedDouble)value;

            // Assert
            Assert.AreEqual(2, generalGrassCoverErosionInwardsInput.N.NumberOfDecimalPlaces);
            Assert.AreEqual(value, generalGrassCoverErosionInwardsInput.N, generalGrassCoverErosionInwardsInput.N.GetAccuracy());
        }
Example #5
0
        public void Read_EntityNull_ThrowsArgumentNullException()
        {
            // Setup
            var generalInput = new GeneralGrassCoverErosionInwardsInput();

            // Call
            TestDelegate test = () => ((GrassCoverErosionInwardsFailureMechanismMetaEntity)null).Read(generalInput);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(test);

            Assert.AreEqual("entity", exception.ParamName);
        }
Example #6
0
        public void N_SetValueOutsideValidRange_ThrowArgumentOutOfRangeException(double value)
        {
            // Setup
            var generalGrassCoverErosionInwardsInput = new GeneralGrassCoverErosionInwardsInput();

            // Call
            TestDelegate test = () => generalGrassCoverErosionInwardsInput.N = (RoundedDouble)value;

            // Assert
            const string expectedMessage = "De waarde voor 'N' moet in het bereik [1,00, 20,00] liggen.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentOutOfRangeException>(test, expectedMessage);
        }
Example #7
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var fbFactor = new TruncatedNormalDistribution(2)
            {
                Mean = (RoundedDouble)4.75,
                StandardDeviation = (RoundedDouble)0.5,
                LowerBoundary     = (RoundedDouble)0.0,
                UpperBoundary     = (RoundedDouble)99.0
            };

            var fnFactor = new TruncatedNormalDistribution(2)
            {
                Mean = (RoundedDouble)2.6,
                StandardDeviation = (RoundedDouble)0.35,
                LowerBoundary     = (RoundedDouble)0.0,
                UpperBoundary     = (RoundedDouble)99.0
            };

            var fshallow = new TruncatedNormalDistribution(2)
            {
                Mean = (RoundedDouble)0.92,
                StandardDeviation = (RoundedDouble)0.24,
                LowerBoundary     = (RoundedDouble)0.0,
                UpperBoundary     = (RoundedDouble)99.0
            };

            var frunupModelFactor = new TruncatedNormalDistribution(2)
            {
                Mean = (RoundedDouble)1,
                StandardDeviation = (RoundedDouble)0.07,
                LowerBoundary     = (RoundedDouble)0.0,
                UpperBoundary     = (RoundedDouble)99.0
            };

            // Call
            var inputParameters = new GeneralGrassCoverErosionInwardsInput();

            // Assert
            Assert.AreEqual(2, inputParameters.N.NumberOfDecimalPlaces);
            Assert.AreEqual(2.0, inputParameters.N, inputParameters.N.GetAccuracy());
            Assert.IsFalse(inputParameters.ApplyLengthEffectInSection);

            DistributionAssert.AreEqual(fbFactor, inputParameters.FbFactor);
            DistributionAssert.AreEqual(fnFactor, inputParameters.FnFactor);
            DistributionAssert.AreEqual(fshallow, inputParameters.FshallowModelFactor);
            DistributionAssert.AreEqual(frunupModelFactor, inputParameters.FrunupModelFactor);

            Assert.AreEqual(1, inputParameters.CriticalOvertoppingModelFactor);
            Assert.AreEqual(1, inputParameters.OvertoppingModelFactor);
        }
        private OvertoppingRateOutput CalculateOvertoppingRate(GrassCoverErosionInwardsCalculation calculation,
                                                               GeneralGrassCoverErosionInwardsInput generalInput,
                                                               string hydraulicBoundaryDatabaseFilePath,
                                                               bool usePreprocessor,
                                                               int numberOfCalculators)
        {
            if (overtoppingRateCalculator == null)
            {
                return(null);
            }

            NotifyProgress(string.Format(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Executing_calculation_of_type_0,
                                         Resources.GrassCoverErosionInwardsCalculationService_OvertoppingRate),
                           numberOfCalculators, numberOfCalculators);

            OvertoppingRateCalculationInput overtoppingRateCalculationInput = CreateOvertoppingRateInput(
                calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor);

            var overtoppingRateCalculated = true;

            try
            {
                PerformCalculation(() => overtoppingRateCalculator.Calculate(overtoppingRateCalculationInput),
                                   () => overtoppingRateCalculator.LastErrorFileContent,
                                   () => overtoppingRateCalculator.OutputDirectory,
                                   calculation.Name,
                                   Resources.GrassCoverErosionInwardsCalculationService_OvertoppingRate);
            }
            catch (HydraRingCalculationException)
            {
                overtoppingRateCalculated = false;
            }

            if (canceled || !overtoppingRateCalculated)
            {
                return(null);
            }

            OvertoppingRateOutput output = CreateOvertoppingRateOutput(overtoppingRateCalculator,
                                                                       calculation.Name,
                                                                       overtoppingRateCalculationInput.Beta,
                                                                       calculation.InputParameters.OvertoppingRateTargetProbability,
                                                                       calculation.InputParameters.ShouldOvertoppingRateIllustrationPointsBeCalculated);

            return(output);
        }
Example #9
0
        public void Read_ValidEntity_ReturnGeneralGrassCoverErosionInwardsInput()
        {
            // Setup
            var random        = new Random();
            var inputToUpdate = new GeneralGrassCoverErosionInwardsInput();
            var entity        = new GrassCoverErosionInwardsFailureMechanismMetaEntity
            {
                N = random.NextRoundedDouble(1.0, 20.0),
                ApplyLengthEffectInSection = Convert.ToByte(random.NextBoolean())
            };

            // Call
            entity.Read(inputToUpdate);

            // Assert
            Assert.AreEqual(entity.N, inputToUpdate.N, inputToUpdate.N.GetAccuracy());
            Assert.AreEqual(Convert.ToBoolean(entity.ApplyLengthEffectInSection), inputToUpdate.ApplyLengthEffectInSection);
        }
        /// <summary>
        /// Performs an overtopping calculation.
        /// </summary>
        /// <param name="calculation">The calculation containing the input for the overtopping calculation.</param>
        /// <param name="generalInput">The general grass cover erosion inwards calculation input parameters.</param>
        /// <param name="hydraulicBoundaryDatabaseFilePath">The path which points to the hydraulic boundary database file.</param>
        /// <param name="usePreprocessor">Indicator whether to use the preprocessor in the calculation.</param>
        /// <param name="numberOfCalculators">The total number of calculations to perform.</param>
        /// <returns>A <see cref="OvertoppingOutput"/>.</returns>
        /// <exception cref="HydraRingCalculationException">Thrown when an error occurs while performing the calculation.</exception>
        private OvertoppingOutput CalculateOvertopping(GrassCoverErosionInwardsCalculation calculation,
                                                       GeneralGrassCoverErosionInwardsInput generalInput,
                                                       string hydraulicBoundaryDatabaseFilePath,
                                                       bool usePreprocessor,
                                                       int numberOfCalculators)
        {
            NotifyProgress(string.Format(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Executing_calculation_of_type_0,
                                         Resources.GrassCoverErosionInwardsCalculationService_Overtopping),
                           1, numberOfCalculators);

            OvertoppingCalculationInput overtoppingCalculationInput = CreateOvertoppingInput(calculation,
                                                                                             generalInput,
                                                                                             hydraulicBoundaryDatabaseFilePath,
                                                                                             usePreprocessor);

            PerformCalculation(() => overtoppingCalculator.Calculate(overtoppingCalculationInput),
                               () => overtoppingCalculator.LastErrorFileContent,
                               () => overtoppingCalculator.OutputDirectory,
                               calculation.Name,
                               Resources.GrassCoverErosionInwardsCalculationService_Overtopping);

            GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult = null;

            try
            {
                generalResult = calculation.InputParameters.ShouldOvertoppingOutputIllustrationPointsBeCalculated
                                    ? ConvertIllustrationPointsResult(overtoppingCalculator.IllustrationPointsResult,
                                                                      overtoppingCalculator.IllustrationPointsParserErrorMessage)
                                    : null;
            }
            catch (ArgumentException e)
            {
                log.Warn(string.Format(Resources.GrassCoverErosionInwardsCalculationService_CalculateOvertopping_Error_in_reading_illustrationPoints_for_CalculationName_0_overtopping_with_ErrorMessage_1,
                                       calculation.Name,
                                       e.Message));
            }

            var overtoppingOutput = new OvertoppingOutput(overtoppingCalculator.WaveHeight,
                                                          overtoppingCalculator.IsOvertoppingDominant,
                                                          overtoppingCalculator.ExceedanceProbabilityBeta,
                                                          generalResult);

            return(overtoppingOutput);
        }
        /// <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>
        /// Read the <see cref="GrassCoverErosionInwardsFailureMechanismMetaEntity"/> and use the information
        /// to update the <paramref name="input"/>.
        /// </summary>
        /// <param name="entity">The <see cref="GrassCoverErosionInwardsFailureMechanismMetaEntity"/> to use
        /// to update the <paramref name="input"/>.</param>
        /// <param name="input">The <see cref="GeneralGrassCoverErosionInwardsInput"/> to be updated.</param>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        internal static void Read(this GrassCoverErosionInwardsFailureMechanismMetaEntity entity, GeneralGrassCoverErosionInwardsInput input)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            input.N = (RoundedDouble)entity.N;
            input.ApplyLengthEffectInSection = Convert.ToBoolean(entity.ApplyLengthEffectInSection);
        }