public void GetAssessmentLevel_ValidInputWithHydraulicBoundaryLocation_ReturnsExpectedValue( WaveConditionsInputWaterLevelType waterLevelType, Func <WaveConditionsInput, IAssessmentSection, double> getExpectedAssessmentLevel) { // Setup var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }, true); var input = new WaveConditionsInput { HydraulicBoundaryLocation = hydraulicBoundaryLocation, WaterLevelType = waterLevelType, CalculationsTargetProbability = assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities.First() }; // Call double assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(input, assessmentSection); // Assert Assert.AreEqual(getExpectedAssessmentLevel(input, assessmentSection), assessmentLevel); }
public override IEnumerable <PropertyInfo> GetPropertyInfos() { yield return(new PropertyInfo <HydraulicLoadsStateFailureMechanismContext, HydraulicLoadsStateFailureMechanismProperties> { CreateInstance = context => new HydraulicLoadsStateFailureMechanismProperties(context.WrappedData) }); yield return(new PropertyInfo <RegistrationStateFailureMechanismContext, RegistrationStateFailureMechanismProperties> { CreateInstance = context => new RegistrationStateFailureMechanismProperties(context.WrappedData) }); yield return(new PropertyInfo <StabilityStoneCoverWaveConditionsOutputContext, StabilityStoneCoverWaveConditionsOutputProperties> { CreateInstance = context => new StabilityStoneCoverWaveConditionsOutputProperties(context.WrappedData, context.Input) }); yield return(new PropertyInfo <StabilityStoneCoverWaveConditionsInputContext, StabilityStoneCoverWaveConditionsInputContextProperties> { CreateInstance = context => new StabilityStoneCoverWaveConditionsInputContextProperties( context, () => WaveConditionsInputHelper.GetAssessmentLevel(context.WrappedData, context.AssessmentSection), new ObservablePropertyChangeHandler(context.Calculation, context.WrappedData)) }); }
private static void Validate(WaveImpactAsphaltCoverWaveConditionsCalculationContext context) { IAssessmentSection assessmentSection = context.AssessmentSection; WaveImpactAsphaltCoverWaveConditionsCalculation calculation = context.WrappedData; WaveConditionsCalculationServiceBase.Validate(calculation.InputParameters, WaveConditionsInputHelper.GetAssessmentLevel(calculation.InputParameters, context.AssessmentSection), assessmentSection.HydraulicBoundaryDatabase); }
private static void ValidateAllInCalculationGroup(WaveImpactAsphaltCoverCalculationGroupContext context) { foreach (WaveImpactAsphaltCoverWaveConditionsCalculation calculation in context.WrappedData.GetCalculations().OfType <WaveImpactAsphaltCoverWaveConditionsCalculation>()) { WaveConditionsCalculationServiceBase.Validate(calculation.InputParameters, WaveConditionsInputHelper.GetAssessmentLevel(calculation.InputParameters, context.AssessmentSection), context.AssessmentSection.HydraulicBoundaryDatabase); } }
public void GetAssessmentLevel_AssessmentSectionNull_ThrowsArgumentNullException() { // Call void Call() => WaveConditionsInputHelper.GetAssessmentLevel(new WaveConditionsInput(), null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("assessmentSection", exception.ParamName); }
private static void ValidateAllInCalculationGroup(GrassCoverErosionOutwardsCalculationGroupContext context) { CalculationGroup calculationGroup = context.WrappedData; foreach (GrassCoverErosionOutwardsWaveConditionsCalculation calculation in calculationGroup.GetCalculations().OfType <GrassCoverErosionOutwardsWaveConditionsCalculation>()) { WaveConditionsCalculationServiceBase.Validate( calculation.InputParameters, WaveConditionsInputHelper.GetAssessmentLevel(calculation.InputParameters, context.AssessmentSection), context.AssessmentSection.HydraulicBoundaryDatabase); } }
/// <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(); } }
public void GetAssessmentLevel_InputWithInvalidWaterLevelType_ThrowsInvalidEnumArgumentException() { // Setup const WaveConditionsInputWaterLevelType waterLevelType = (WaveConditionsInputWaterLevelType)99; var waveConditionsInput = new WaveConditionsInput { WaterLevelType = waterLevelType }; // Call void Call() => WaveConditionsInputHelper.GetAssessmentLevel(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 GetAssessmentLevel_ValidInputWithoutHydraulicBoundaryLocation_ReturnsNaN(WaveConditionsInputWaterLevelType waterLevelType) { // Setup var assessmentSection = new AssessmentSectionStub(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new TestHydraulicBoundaryLocation() }, true); var input = new WaveConditionsInput { WaterLevelType = waterLevelType, CalculationsTargetProbability = assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities.First() }; // Call double assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(input, assessmentSection); // Assert Assert.IsNaN(assessmentLevel); }
/// <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(); } }
protected override bool Validate() { return(WaveConditionsCalculationServiceBase.Validate(calculation.InputParameters, WaveConditionsInputHelper.GetAssessmentLevel(calculation.InputParameters, assessmentSection), assessmentSection.HydraulicBoundaryDatabase)); }
private static IEnumerable <RoundedDouble> GetWaterLevels(GrassCoverErosionOutwardsWaveConditionsCalculation calculation, IAssessmentSection assessmentSection) { return(calculation.InputParameters.GetWaterLevels(WaveConditionsInputHelper.GetAssessmentLevel(calculation.InputParameters, assessmentSection))); }
private static IEnumerable <RoundedDouble> GetWaterLevels(StabilityStoneCoverWaveConditionsCalculation calculation, IAssessmentSection assessmentSection) { return(calculation.InputParameters.GetWaterLevels(WaveConditionsInputHelper.GetAssessmentLevel(calculation.InputParameters, assessmentSection))); }
/// <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(); } }