Exemplo n.º 1
0
        private void SetConfigurationTargetProbabilityProperty(WaveConditionsCalculationConfiguration configuration, WaveConditionsInput input)
        {
            if (input.WaterLevelType == WaveConditionsInputWaterLevelType.None)
            {
                return;
            }

            configuration.TargetProbability = WaveConditionsInputHelper.GetTargetProbability(input, assessmentSection);
        }
        public void GetTargetProbability_AssessmentSectionNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => WaveConditionsInputHelper.GetTargetProbability(new WaveConditionsInput(), null);

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

            Assert.AreEqual("assessmentSection", exception.ParamName);
        }
        /// <summary>
        /// Performs a wave conditions calculation for the wave impact on asphalt failure mechanism based on the supplied
        /// <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation"/>  and sets
        /// <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation.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="WaveImpactAsphaltCoverWaveConditionsCalculation"/> 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="generalWaveConditionsInput">Calculation input parameters that apply to all <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation"/> instances.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="assessmentSection"/>
        /// or <paramref name="generalWaveConditionsInput"/> is <c>null</c>.</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 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="ArgumentOutOfRangeException">Thrown when the target probability or
        /// calculated probability falls outside the [0.0, 1.0] range and is not <see cref="double.NaN"/>.</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>
        public void Calculate(WaveImpactAsphaltCoverWaveConditionsCalculation calculation,
                              IAssessmentSection assessmentSection,
                              GeneralWaveConditionsInput generalWaveConditionsInput)
        {
            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 targetProbability = WaveConditionsInputHelper.GetTargetProbability(calculation.InputParameters, assessmentSection);

            RoundedDouble assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(calculation.InputParameters, assessmentSection);

            CurrentCalculationType      = Resources.WaveImpactAsphaltCover_DisplayName;
            TotalWaterLevelCalculations = calculation.InputParameters.GetWaterLevels(assessmentLevel).Count();

            try
            {
                IEnumerable <WaveConditionsOutput> outputs = CalculateWaveConditions(calculation.InputParameters,
                                                                                     assessmentLevel,
                                                                                     a, b, c, targetProbability,
                                                                                     assessmentSection.HydraulicBoundaryDatabase);

                if (!Canceled)
                {
                    calculation.Output = new WaveImpactAsphaltCoverWaveConditionsOutput(outputs);
                }
            }
            finally
            {
                CalculationServiceHelper.LogCalculationEnd();
            }
        }
Exemplo n.º 4
0
        public override IEnumerable <ExportInfo> GetExportInfos()
        {
            yield return(new ExportInfo <WaveImpactAsphaltCoverCalculationGroupContext>
            {
                Name = context => RiskeerCommonFormsResources.WaveConditionsExporter_DisplayName,
                Extension = RiskeerCommonFormsResources.DataTypeDisplayName_csv_file_filter_Extension,
                CreateFileExporter = (context, filePath) =>
                {
                    IEnumerable <WaveImpactAsphaltCoverWaveConditionsCalculation> calculations = context.WrappedData.GetCalculations().Cast <WaveImpactAsphaltCoverWaveConditionsCalculation>();
                    return new WaveImpactAsphaltCoverWaveConditionsExporter(calculations, filePath, input =>
                                                                            WaveConditionsInputHelper.GetTargetProbability(input, context.AssessmentSection)
                                                                            .ToString(CultureInfo.InvariantCulture));
                },
                IsEnabled = context => context.WrappedData.GetCalculations().Cast <WaveImpactAsphaltCoverWaveConditionsCalculation>().Any(c => c.HasOutput),
                GetExportPath = () => ExportHelper.GetFilePath(GetInquiryHelper(), GetWaveConditionsFileFilterGenerator())
            });

            yield return(new ExportInfo <WaveImpactAsphaltCoverWaveConditionsCalculationContext>
            {
                Name = context => RiskeerCommonFormsResources.WaveConditionsExporter_DisplayName,
                Extension = RiskeerCommonFormsResources.DataTypeDisplayName_csv_file_filter_Extension,
                CreateFileExporter = (context, filePath) => new WaveImpactAsphaltCoverWaveConditionsExporter(new[]
                {
                    context.WrappedData
                }, filePath,
                                                                                                             input =>
                                                                                                             WaveConditionsInputHelper.GetTargetProbability(input, context.AssessmentSection)
                                                                                                             .ToString(CultureInfo.InvariantCulture)),
                IsEnabled = context => context.WrappedData.HasOutput,
                GetExportPath = () => ExportHelper.GetFilePath(GetInquiryHelper(), GetWaveConditionsFileFilterGenerator())
            });

            yield return(RiskeerExportInfoFactory.CreateCalculationGroupConfigurationExportInfo <WaveImpactAsphaltCoverCalculationGroupContext>(
                             (context, filePath) => new WaveImpactAsphaltCoverWaveConditionsCalculationConfigurationExporter(
                                 context.WrappedData.Children, filePath, context.AssessmentSection),
                             context => context.WrappedData.Children.Any(),
                             GetInquiryHelper()));

            yield return(RiskeerExportInfoFactory.CreateCalculationConfigurationExportInfo <WaveImpactAsphaltCoverWaveConditionsCalculationContext>(
                             (context, filePath) => new WaveImpactAsphaltCoverWaveConditionsCalculationConfigurationExporter(
                                 new[]
            {
                context.WrappedData
            }, filePath, context.AssessmentSection),
                             GetInquiryHelper()));
        }
        public void GetTargetProbability_InputWithInvalidWaterLevelType_ThrowsInvalidEnumArgumentException()
        {
            // Setup
            const WaveConditionsInputWaterLevelType waterLevelType = (WaveConditionsInputWaterLevelType)99;
            var waveConditionsInput = new WaveConditionsInput
            {
                WaterLevelType = waterLevelType
            };

            // Call
            void Call() => WaveConditionsInputHelper.GetTargetProbability(waveConditionsInput, new AssessmentSectionStub());

            // Assert
            var expectedMessage = $"The value of argument 'WaterLevelType' ({waterLevelType}) is invalid for Enum type '{nameof(WaveConditionsInputWaterLevelType)}'.";
            var exception       = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(Call, expectedMessage);

            Assert.AreEqual("WaterLevelType", exception.ParamName);
        }
        public void GetTargetProbability_ValidInput_ReturnsExpectedValue(
            WaveConditionsInputWaterLevelType waterLevelType,
            Func <WaveConditionsInput, IAssessmentSection, double> getExpectedTargetProbability)
        {
            // Setup
            var assessmentSection = new AssessmentSectionStub();

            var input = new WaveConditionsInput
            {
                WaterLevelType = waterLevelType,
                CalculationsTargetProbability = new HydraulicBoundaryLocationCalculationsForTargetProbability(0.01)
            };

            // Call
            double targetProbability = WaveConditionsInputHelper.GetTargetProbability(input, assessmentSection);

            // Assert
            Assert.AreEqual(getExpectedTargetProbability(input, assessmentSection), targetProbability);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Performs a wave conditions calculation for the stability of stone revetment failure mechanism based on the supplied
        /// <see cref="StabilityStoneCoverWaveConditionsCalculation"/>  and sets
        /// <see cref="StabilityStoneCoverWaveConditionsCalculation.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="StabilityStoneCoverWaveConditionsCalculation"/> 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="generalWaveConditionsInput">Calculation input parameters that apply to all <see cref="StabilityStoneCoverWaveConditionsCalculation"/> instances.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="assessmentSection"/>
        /// or <paramref name="generalWaveConditionsInput"/> is <c>null</c>.</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="ArgumentOutOfRangeException">Thrown when the target probability or
        /// calculated probability falls outside the [0.0, 1.0] range and is not <see cref="double.NaN"/>.</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>
        public void Calculate(StabilityStoneCoverWaveConditionsCalculation calculation,
                              IAssessmentSection assessmentSection,
                              GeneralStabilityStoneCoverWaveConditionsInput generalWaveConditionsInput)
        {
            if (calculation == null)
            {
                throw new ArgumentNullException(nameof(calculation));
            }

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

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

            StabilityStoneCoverWaveConditionsInput           calculationInput = calculation.InputParameters;
            StabilityStoneCoverWaveConditionsCalculationType calculationType  = calculationInput.CalculationType;

            if (!Enum.IsDefined(typeof(StabilityStoneCoverWaveConditionsCalculationType), calculationType))
            {
                throw new InvalidEnumArgumentException(nameof(calculationType), (int)calculationType,
                                                       typeof(StabilityStoneCoverWaveConditionsCalculationType));
            }

            CalculationServiceHelper.LogCalculationBegin();

            double targetProbability = WaveConditionsInputHelper.GetTargetProbability(calculationInput, assessmentSection);

            RoundedDouble assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(calculationInput, assessmentSection);

            int waterLevelCount = calculationInput.GetWaterLevels(assessmentLevel).Count();

            TotalWaterLevelCalculations = calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both
                                              ? waterLevelCount * 2
                                              : waterLevelCount;

            try
            {
                IEnumerable <WaveConditionsOutput> blocksOutputs = null;
                if (calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both ||
                    calculationType == StabilityStoneCoverWaveConditionsCalculationType.Blocks)
                {
                    CurrentCalculationType = Resources.StabilityStoneCoverWaveConditions_Blocks_DisplayName;
                    blocksOutputs          = CalculateBlocks(calculation, assessmentSection, assessmentLevel,
                                                             generalWaveConditionsInput.GeneralBlocksWaveConditionsInput, targetProbability);
                }

                if (Canceled)
                {
                    return;
                }

                IEnumerable <WaveConditionsOutput> columnsOutputs = null;
                if (calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both ||
                    calculationType == StabilityStoneCoverWaveConditionsCalculationType.Columns)
                {
                    CurrentCalculationType = Resources.StabilityStoneCoverWaveConditions_Columns_DisplayName;
                    columnsOutputs         = CalculateColumns(calculation, assessmentSection, assessmentLevel,
                                                              generalWaveConditionsInput.GeneralColumnsWaveConditionsInput, targetProbability);
                }

                if (!Canceled)
                {
                    calculation.Output = CreateOutput(calculationType, blocksOutputs, columnsOutputs);
                }
            }
            finally
            {
                CalculationServiceHelper.LogCalculationEnd();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Performs a wave conditions calculation for the grass cover erosion outwards failure mechanism based on the supplied
        /// <see cref="GrassCoverErosionOutwardsWaveConditionsCalculation"/> and sets
        /// <see cref="GrassCoverErosionOutwardsWaveConditionsCalculation.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="GrassCoverErosionOutwardsWaveConditionsCalculation"/> that holds all the information required to perform the calculation.</param>
        /// <param name="failureMechanism">The grass cover erosion outwards failure mechanism, which contains general parameters that apply to all
        /// <see cref="GrassCoverErosionOutwardsWaveConditionsCalculation"/> instances.</param>
        /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that holds information about the target probability used in the calculation.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="failureMechanism"/>
        /// or <paramref name="assessmentSection"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when:
        /// <list type="bullet">
        /// <item>the hydraulic boundary database file path contains invalid characters.</item>
        /// <item><paramref name="failureMechanism"/> has no (0) contribution.</item>
        /// </list></exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when an unexpected
        /// enum value is encountered.</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="ArgumentOutOfRangeException">Thrown when the target probability or
        /// calculated probability falls outside the [0.0, 1.0] range and is not <see cref="double.NaN"/>.</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>
        /// <exception cref="NotSupportedException">Thrown when <see cref="GrassCoverErosionOutwardsWaveConditionsCalculationType"/>
        /// is a valid value, but unsupported.</exception>
        public void Calculate(GrassCoverErosionOutwardsWaveConditionsCalculation calculation,
                              GrassCoverErosionOutwardsFailureMechanism failureMechanism,
                              IAssessmentSection assessmentSection)
        {
            if (calculation == null)
            {
                throw new ArgumentNullException(nameof(calculation));
            }

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

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

            GrassCoverErosionOutwardsWaveConditionsInput           calculationInput = calculation.InputParameters;
            GrassCoverErosionOutwardsWaveConditionsCalculationType calculationType  = calculationInput.CalculationType;

            if (!Enum.IsDefined(typeof(GrassCoverErosionOutwardsWaveConditionsCalculationType), calculationType))
            {
                throw new InvalidEnumArgumentException(nameof(calculationType), (int)calculationType,
                                                       typeof(GrassCoverErosionOutwardsWaveConditionsCalculationType));
            }

            CalculationServiceHelper.LogCalculationBegin();

            RoundedDouble assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(calculationInput, assessmentSection);

            double targetProbability = WaveConditionsInputHelper.GetTargetProbability(calculationInput, assessmentSection);

            HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase;

            DetermineTotalWaterLevelCalculations(calculationInput, assessmentLevel);

            try
            {
                IEnumerable <WaveConditionsOutput> waveRunUpOutput = null;
                if (ShouldCalculateWaveRunUp(calculationType))
                {
                    CurrentCalculationType = Resources.GrassCoverErosionOutwardsWaveConditions_WaveRunUp_DisplayName;
                    waveRunUpOutput        = CalculateWaveRunUp(calculation, failureMechanism, hydraulicBoundaryDatabase, assessmentLevel, targetProbability);
                }

                if (Canceled)
                {
                    return;
                }

                IEnumerable <WaveConditionsOutput> waveImpactOutput = null;
                if (ShouldCalculateWaveImpact(calculationType))
                {
                    CurrentCalculationType = Resources.GrassCoverErosionOutwardsWaveConditions_WaveImpact_DisplayName;
                    waveImpactOutput       = CalculateWaveImpact(calculation, failureMechanism, hydraulicBoundaryDatabase, assessmentLevel, targetProbability);
                }

                IEnumerable <WaveConditionsOutput> waveImpactWithWaveDirectionOutput = null;
                if (ShouldCalculateWaveImpactWithWaveDirection(calculationType))
                {
                    CurrentCalculationType            = Resources.GrassCoverErosionOutwardsWaveConditions_WaveImpactWithWaveDirection_DisplayName;
                    waveImpactWithWaveDirectionOutput = CalculateWaveImpactWithWaveDirection(calculation, failureMechanism, hydraulicBoundaryDatabase, assessmentLevel, targetProbability);
                }

                if (!Canceled)
                {
                    calculation.Output = CreateOutput(calculationType, waveRunUpOutput, waveImpactOutput, waveImpactWithWaveDirectionOutput);
                }
            }
            finally
            {
                CalculationServiceHelper.LogCalculationEnd();
            }
        }