Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresGuiPlugin.cs =================================================================== diff -u -r0cc0f65e5dd8ecc7733776517b5891cb2089adca -rab3c22a03e36c7fcdb96d754b45fb8e4717ec9cc --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresGuiPlugin.cs (.../HeightStructuresGuiPlugin.cs) (revision 0cc0f65e5dd8ecc7733776517b5891cb2089adca) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresGuiPlugin.cs (.../HeightStructuresGuiPlugin.cs) (revision ab3c22a03e36c7fcdb96d754b45fb8e4717ec9cc) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections; using System.Collections.Generic; using System.IO; @@ -30,15 +31,21 @@ using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.TreeNodeInfos; +using Ringtoets.Common.Service; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Forms.PresentationObjects; using Ringtoets.HeightStructures.Forms.PropertyClasses; using Ringtoets.HeightStructures.Forms.Views; -using Ringtoets.HeightStructures.Service; +using Ringtoets.HeightStructures.Plugin.Properties; +using Ringtoets.HydraRing.Calculation.Activities; +using Ringtoets.HydraRing.Calculation.Data; +using Ringtoets.HydraRing.Calculation.Data.Input.Structures; +using Ringtoets.HydraRing.Calculation.Data.Output; using Ringtoets.HydraRing.IO; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; @@ -128,15 +135,58 @@ }; } + private static ExceedanceProbabilityCalculationActivity CreateHydraRingExceedenceProbabilityCalculationActivity( + string hlcdDirectory, + HeightStructuresCalculation calculation, + HeightStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + var hydraulicBoundaryLocationId = (int) calculation.InputParameters.HydraulicBoundaryLocation.Id; + var failureMechanismSection = failureMechanism.Sections.First(); // TODO: Obtain dike section based on cross section of structure with reference line + var sectionLength = failureMechanismSection.GetSectionLength(); + var generalInputParameters = failureMechanism.GeneralInput; + var inputParameters = calculation.InputParameters; + + return HydraRingActivityFactory.Create( + calculation.Name, + hlcdDirectory, + failureMechanismSection.Name, // TODO: Provide name of reference line instead + HydraRingTimeIntegrationSchemeType.FBC, + HydraRingUncertaintiesType.All, + new StructuresOvertoppingCalculationInput( + hydraulicBoundaryLocationId, + new HydraRingSection(1, failureMechanismSection.Name, sectionLength, inputParameters.OrientationOfTheNormalOfTheStructure), + generalInputParameters.GravitationalAcceleration, + generalInputParameters.ModelFactorOvertoppingFlow.Mean, generalInputParameters.ModelFactorOvertoppingFlow.StandardDeviation, + inputParameters.LevelOfCrestOfStructure.Mean, inputParameters.LevelOfCrestOfStructure.StandardDeviation, + inputParameters.OrientationOfTheNormalOfTheStructure, + inputParameters.ModelFactorOvertoppingSuperCriticalFlow.Mean, inputParameters.ModelFactorOvertoppingSuperCriticalFlow.StandardDeviation, + inputParameters.AllowableIncreaseOfLevelForStorage.Mean, inputParameters.AllowableIncreaseOfLevelForStorage.StandardDeviation, + generalInputParameters.ModelFactorForStorageVolume.Mean, generalInputParameters.ModelFactorForStorageVolume.StandardDeviation, + inputParameters.StorageStructureArea.Mean, inputParameters.StorageStructureArea.GetVariationCoefficient(), + generalInputParameters.ModelFactorForIncomingFlowVolume, + inputParameters.FlowWidthAtBottomProtection.Mean, inputParameters.FlowWidthAtBottomProtection.StandardDeviation, + inputParameters.CriticalOvertoppingDischarge.Mean, inputParameters.CriticalOvertoppingDischarge.GetVariationCoefficient(), + inputParameters.FailureProbabilityOfStructureGivenErosion, + inputParameters.WidthOfFlowApertures.Mean, inputParameters.WidthOfFlowApertures.GetVariationCoefficient(), + inputParameters.DeviationOfTheWaveDirection, + inputParameters.StormDuration.Mean, inputParameters.StormDuration.GetVariationCoefficient()), + calculation.ClearOutput, + output => { ParseHydraRingOutput(calculation, failureMechanism, assessmentSection, output); }); + } + private void CalculateAll(HeightStructuresFailureMechanism failureMechanism, IEnumerable calculations, IAssessmentSection assessmentSection) { - ActivityProgressDialogRunner.Run(Gui.MainWindow, - calculations.Select(calc => new HeightStructuresCalculationActivity(calc, - Path.GetDirectoryName(assessmentSection.HydraulicBoundaryDatabase.FilePath), - failureMechanism, - assessmentSection)).ToList()); + // TODO: Remove "Where" filter when validation is implemented + ActivityProgressDialogRunner.Run(Gui.MainWindow, calculations.Where(calc => calc.InputParameters.HydraulicBoundaryLocation != null) + .Select(calc => CreateHydraRingExceedenceProbabilityCalculationActivity( + Path.GetDirectoryName(assessmentSection.HydraulicBoundaryDatabase.FilePath), + calc, + failureMechanism, + assessmentSection + )).ToList()); } private static string AllDataAvailable(IAssessmentSection assessmentSection, HeightStructuresFailureMechanism failureMechanism) @@ -161,6 +211,25 @@ return null; } + private static void ParseHydraRingOutput(HeightStructuresCalculation calculation, + HeightStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection, + ExceedanceProbabilityCalculationOutput output) + { + if (output != null) + { + calculation.Output = ProbabilityAssessmentService.Calculate(assessmentSection.FailureMechanismContribution.Norm, + failureMechanism.Contribution, + failureMechanism.GeneralInput.N, + output.Beta); + calculation.NotifyObservers(); + } + else + { + throw new InvalidOperationException(Resources.HeightStructuresGuiPlugin_Error_during_overtopping_calculation); + } + } + #region EmptyProbabilityAssessmentOutput TreeNodeInfo private ContextMenuStrip EmptyProbabilityAssessmentOutputContextMenuStrip(EmptyProbabilityAssessmentOutput output, object parentData, TreeViewControl treeViewControl) @@ -436,10 +505,18 @@ private void Calculate(HeightStructuresCalculation calculation, HeightStructuresCalculationContext context) { - ActivityProgressDialogRunner.Run(Gui.MainWindow, new HeightStructuresCalculationActivity(calculation, - Path.GetDirectoryName(context.AssessmentSection.HydraulicBoundaryDatabase.FilePath), - context.FailureMechanism, - context.AssessmentSection)); + // TODO: Remove null-check when validation is implemented + if (calculation.InputParameters.HydraulicBoundaryLocation == null) + { + return; + } + var activity = CreateHydraRingExceedenceProbabilityCalculationActivity( + Path.GetDirectoryName(context.AssessmentSection.HydraulicBoundaryDatabase.FilePath), + calculation, + context.FailureMechanism, + context.AssessmentSection); + + ActivityProgressDialogRunner.Run(Gui.MainWindow, activity); } private void CalculationContextOnNodeRemoved(HeightStructuresCalculationContext context, object parentData)