Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (revision 7a1b6072eb543968bd2d9b1a21c53572cd98b89a) @@ -0,0 +1,122 @@ +// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic; +using System.Linq; +using log4net; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.HydraRing.Calculation.Calculator; +using Ringtoets.HydraRing.Calculation.Calculator.Factory; +using Ringtoets.HydraRing.Calculation.Data; +using Ringtoets.HydraRing.Calculation.Data.Input.Structures; + +namespace Ringtoets.ClosingStructures.Service +{ + /// + /// Service that provides methods for perfoming Hydra-ring calculations for closing structures calculations. + /// + public class ClosingStructuresCalculationService + { + private static ILog log = LogManager.GetLogger(typeof(ClosingStructuresCalculationService)); + + private IStructuresClosureCalculator calculator; + private bool canceled; + + /// + /// Performs a height structures calculation based on the supplied and sets + /// if the calculation was successful. Error and status information is + /// logged during the execution of the operation. + /// + /// The that holds all the information required to perform the calculation. + /// The that holds information about the norm used in the calculation. + /// The to create input with. + /// The to create the input with for the calculation. + /// The amount of contribution for this failure mechanism in the assessment section. + /// The directory of the HLCD file that should be used for performing the calculation. + /// + public void Calculate(ClosingStructuresCalculation calculation, + IAssessmentSection assessmentSection, + FailureMechanismSection failureMechanismSection, + GeneralClosingStructuresInput generalInput, + double failureMechanismContribution, string hlcdDirectory) + { + StructuresClosureCalculationInput input; + + switch (calculation.InputParameters.InflowModelType) + { + case ClosingStructureInflowModelType.VerticalWall: + input = CreateClosureVerticalWallCalculationInput(calculation, failureMechanismSection, generalInput); + break; + + default: + throw new NotSupportedException("ClosingStructureInflowModelType"); + } + + calculator = HydraRingCalculatorFactory.Instance.CreateStructuresClosureCalculator(hlcdDirectory, assessmentSection.Id); + + calculator.Calculate(input); + } + + private static StructuresClosureVerticalWallCalculationInput CreateClosureVerticalWallCalculationInput(ClosingStructuresCalculation calculation, + FailureMechanismSection failureMechanismSection, + GeneralClosingStructuresInput generalInput) + { + return new StructuresClosureVerticalWallCalculationInput( + calculation.InputParameters.HydraulicBoundaryLocation.Id, + new HydraRingSection(1, failureMechanismSection.GetSectionLength(), calculation.InputParameters.StructureNormalOrientation), + ParseForeshore(calculation.InputParameters), + ParseBreakWater(calculation.InputParameters), + generalInput.GravitationalAcceleration, + calculation.InputParameters.FactorStormDurationOpenStructure, + calculation.InputParameters.FailureProbabilityOpenStructure, + calculation.InputParameters.FailureProbabilityReparation, + calculation.InputParameters.IdenticalApertures, + calculation.InputParameters.AllowedLevelIncreaseStorage.Mean, calculation.InputParameters.AllowedLevelIncreaseStorage.StandardDeviation, + generalInput.ModelFactorStorageVolume.Mean, generalInput.ModelFactorStorageVolume.StandardDeviation, + calculation.InputParameters.StorageStructureArea.Mean, calculation.InputParameters.StorageStructureArea.CoefficientOfVariation, + generalInput.ModelFactorInflowVolume, + calculation.InputParameters.FlowWidthAtBottomProtection.Mean, calculation.InputParameters.FlowWidthAtBottomProtection.StandardDeviation, + calculation.InputParameters.CriticalOvertoppingDischarge.Mean, calculation.InputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation, + calculation.InputParameters.FailureProbabilityStructureWithErosion, + calculation.InputParameters.StormDuration.Mean, calculation.InputParameters.StormDuration.CoefficientOfVariation, + calculation.InputParameters.ProbabilityOpenStructureBeforeFlooding, + generalInput.ModelFactorOvertoppingFlow.Mean, generalInput.ModelFactorOvertoppingFlow.StandardDeviation, + calculation.InputParameters.StructureNormalOrientation, + calculation.InputParameters.ModelFactorSuperCriticalFlow.Mean, calculation.InputParameters.ModelFactorSuperCriticalFlow.StandardDeviation, + calculation.InputParameters.LevelCrestStructureNotClosing.Mean, calculation.InputParameters.LevelCrestStructureNotClosing.StandardDeviation, + calculation.InputParameters.WidthFlowApertures.Mean, calculation.InputParameters.WidthFlowApertures.CoefficientOfVariation, + calculation.InputParameters.DeviationWaveDirection); + } + + private static IEnumerable ParseForeshore(ClosingStructuresInput input) + { + return input.UseForeshore ? input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)) : new HydraRingForelandPoint[0]; + } + + private static HydraRingBreakWater ParseBreakWater(ClosingStructuresInput input) + { + return input.UseBreakWater ? new HydraRingBreakWater((int)input.BreakWater.Type, input.BreakWater.Height) : null; + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/Ringtoets.ClosingStructures.Service.csproj =================================================================== diff -u -r8c7c25ff896b8967361c5c8f4e6ef261ff6f5164 -r7a1b6072eb543968bd2d9b1a21c53572cd98b89a --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/Ringtoets.ClosingStructures.Service.csproj (.../Ringtoets.ClosingStructures.Service.csproj) (revision 8c7c25ff896b8967361c5c8f4e6ef261ff6f5164) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/Ringtoets.ClosingStructures.Service.csproj (.../Ringtoets.ClosingStructures.Service.csproj) (revision 7a1b6072eb543968bd2d9b1a21c53572cd98b89a) @@ -32,6 +32,10 @@ AllRules.ruleset + + ..\..\..\..\packages\log4net.2.0.4\lib\net40-full\log4net.dll + True + @@ -40,12 +44,14 @@ Properties\GlobalAssembly.cs + Copying.licenseheader + @@ -63,6 +69,11 @@ Ringtoets.HydraRing.Calculation False + + {70f8cc9c-5bc8-4fb2-b201-eae7fa8088c2} + Ringtoets.HydraRing.Data + False + {C6309704-D67B-434C-BC98-9F8910BC1D10} Ringtoets.ClosingStructures.Data Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/packages.config =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/packages.config (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/packages.config (revision 7a1b6072eb543968bd2d9b1a21c53572cd98b89a) @@ -0,0 +1,26 @@ + + + + + \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.TestUtil.Test/TestClosingStructureCalculationTest.cs =================================================================== diff -u -rc9130fbb8186c9b1c3d4c4b8496fd4035b80f825 -r7a1b6072eb543968bd2d9b1a21c53572cd98b89a --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.TestUtil.Test/TestClosingStructureCalculationTest.cs (.../TestClosingStructureCalculationTest.cs) (revision c9130fbb8186c9b1c3d4c4b8496fd4035b80f825) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.TestUtil.Test/TestClosingStructureCalculationTest.cs (.../TestClosingStructureCalculationTest.cs) (revision 7a1b6072eb543968bd2d9b1a21c53572cd98b89a) @@ -34,7 +34,7 @@ var referenceStructure = new TestClosingStructure(); // Call - var calculation = new TestClosingStructureCalculation(); + var calculation = new TestClosingStructuresCalculation(); // Assert Assert.IsInstanceOf(calculation); Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.TestUtil/Ringtoets.ClosingStructures.Data.TestUtil.csproj =================================================================== diff -u -rc9130fbb8186c9b1c3d4c4b8496fd4035b80f825 -r7a1b6072eb543968bd2d9b1a21c53572cd98b89a --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.TestUtil/Ringtoets.ClosingStructures.Data.TestUtil.csproj (.../Ringtoets.ClosingStructures.Data.TestUtil.csproj) (revision c9130fbb8186c9b1c3d4c4b8496fd4035b80f825) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.TestUtil/Ringtoets.ClosingStructures.Data.TestUtil.csproj (.../Ringtoets.ClosingStructures.Data.TestUtil.csproj) (revision 7a1b6072eb543968bd2d9b1a21c53572cd98b89a) @@ -46,7 +46,7 @@ - + Fisheye: Tag 7a1b6072eb543968bd2d9b1a21c53572cd98b89a refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.TestUtil/TestClosingStructureCalculation.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.TestUtil/TestClosingStructuresCalculation.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.TestUtil/TestClosingStructuresCalculation.cs (revision 0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.TestUtil/TestClosingStructuresCalculation.cs (revision 7a1b6072eb543968bd2d9b1a21c53572cd98b89a) @@ -0,0 +1,34 @@ +// Copyright (C) Stichting Deltares 2016. 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 Ringtoets.HydraRing.Data; + +namespace Ringtoets.ClosingStructures.Data.TestUtil +{ + public class TestClosingStructuresCalculation : ClosingStructuresCalculation + { + public TestClosingStructuresCalculation() + { + InputParameters.Structure = new TestClosingStructure(); + InputParameters.HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "location", 1, 1); + } + } +} Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs (revision 0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs (revision 7a1b6072eb543968bd2d9b1a21c53572cd98b89a) @@ -0,0 +1,160 @@ +// Copyright (C) Stichting Deltares 2016. 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.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Contribution; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.HydraRing.Calculation.Calculator.Factory; +using Ringtoets.HydraRing.Calculation.Data; +using Ringtoets.HydraRing.Calculation.Data.Input.Structures; +using Ringtoets.HydraRing.Calculation.TestUtil; +using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; +using Ringtoets.HydraRing.Data; + +namespace Ringtoets.ClosingStructures.Service.Test +{ + [TestFixture] + public class ClosingStructuresCalculationServiceTest + { + private static readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Service, "HydraRingCalculation"); + + [Test] + [TestCase(true, false)] + [TestCase(true, true)] + [TestCase(false, false)] + public void Calculate_VariousVerticalWallCalculations_InputPropertiesCorrectlySentToCalculator(bool useForeshore, bool useBreakWater) + { + // Setup + var closingStructuresFailureMechanism = new ClosingStructuresFailureMechanism(); + + var mockRepository = new MockRepository(); + var assessmentSectionStub = CreateAssessmentSectionStub(closingStructuresFailureMechanism, mockRepository); + mockRepository.ReplayAll(); + + closingStructuresFailureMechanism.AddSection(new FailureMechanismSection("test section", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + })); + + ClosingStructuresCalculation calculation = new TestClosingStructuresCalculation() + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSectionStub.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001) + } + }; + + if (useForeshore) + { + calculation.InputParameters.ForeshoreProfile = new ForeshoreProfile(new Point2D(0, 0), + new[] + { + new Point2D(1, 1), + new Point2D(2, 2) + }, + useBreakWater ? new BreakWater(BreakWaterType.Wall, 3.0) : null, + new ForeshoreProfile.ConstructionProperties()); + } + + FailureMechanismSection failureMechanismSection = closingStructuresFailureMechanism.Sections.First(); + + using (new HydraRingCalculatorFactoryConfig()) + { + var calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresClosureCalculator; + + // Call + new ClosingStructuresCalculationService().Calculate(calculation, + assessmentSectionStub, + failureMechanismSection, + closingStructuresFailureMechanism.GeneralInput, + closingStructuresFailureMechanism.Contribution, + testDataPath); + + // Assert + StructuresClosureCalculationInput[] calculationInputs = calculator.ReceivedInputs.ToArray(); + Assert.AreEqual(1, calculationInputs.Length); + Assert.AreEqual(testDataPath, calculator.HydraulicBoundaryDatabaseDirectory); + Assert.AreEqual(assessmentSectionStub.Id, calculator.RingId); + + GeneralClosingStructuresInput generalInput = closingStructuresFailureMechanism.GeneralInput; + ClosingStructuresInput input = calculation.InputParameters; + var expectedInput = new StructuresClosureVerticalWallCalculationInput( + 1300001, + new HydraRingSection(1, failureMechanismSection.GetSectionLength(), input.StructureNormalOrientation), + useForeshore ? input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)) : new HydraRingForelandPoint[0], + useBreakWater ? new HydraRingBreakWater((int) input.BreakWater.Type, input.BreakWater.Height) : null, + generalInput.GravitationalAcceleration, + input.FactorStormDurationOpenStructure, + input.FailureProbabilityOpenStructure, + input.FailureProbabilityReparation, + input.IdenticalApertures, + input.AllowedLevelIncreaseStorage.Mean, input.AllowedLevelIncreaseStorage.StandardDeviation, + generalInput.ModelFactorStorageVolume.Mean, generalInput.ModelFactorStorageVolume.StandardDeviation, + input.StorageStructureArea.Mean, input.StorageStructureArea.CoefficientOfVariation, + generalInput.ModelFactorInflowVolume, + input.FlowWidthAtBottomProtection.Mean, input.FlowWidthAtBottomProtection.StandardDeviation, + input.CriticalOvertoppingDischarge.Mean, input.CriticalOvertoppingDischarge.CoefficientOfVariation, + input.FailureProbabilityStructureWithErosion, + input.StormDuration.Mean, input.StormDuration.CoefficientOfVariation, + input.ProbabilityOpenStructureBeforeFlooding, + generalInput.ModelFactorOvertoppingFlow.Mean, generalInput.ModelFactorOvertoppingFlow.StandardDeviation, + input.StructureNormalOrientation, + input.ModelFactorSuperCriticalFlow.Mean, input.ModelFactorSuperCriticalFlow.StandardDeviation, + input.LevelCrestStructureNotClosing.Mean, input.LevelCrestStructureNotClosing.StandardDeviation, + input.WidthFlowApertures.Mean, input.WidthFlowApertures.CoefficientOfVariation, + input.DeviationWaveDirection); + + StructuresClosureVerticalWallCalculationInput actualInput = (StructuresClosureVerticalWallCalculationInput)calculationInputs[0]; + HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); + Assert.IsFalse(calculator.IsCanceled); + } + mockRepository.VerifyAll(); + } + + private static IAssessmentSection CreateAssessmentSectionStub(IFailureMechanism failureMechanism, MockRepository mockRepository) + { + var assessmentSectionStub = mockRepository.Stub(); + assessmentSectionStub.Stub(a => a.Id).Return("21"); + assessmentSectionStub.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution(new[] + { + failureMechanism + }, 1, 2)); + assessmentSectionStub.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + Locations = + { + new HydraulicBoundaryLocation(1300001, string.Empty, 0, 0) + } + }; + return assessmentSectionStub; + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/Ringtoets.ClosingStructures.Service.Test.csproj =================================================================== diff -u -r8c7c25ff896b8967361c5c8f4e6ef261ff6f5164 -r7a1b6072eb543968bd2d9b1a21c53572cd98b89a --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/Ringtoets.ClosingStructures.Service.Test.csproj (.../Ringtoets.ClosingStructures.Service.Test.csproj) (revision 8c7c25ff896b8967361c5c8f4e6ef261ff6f5164) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/Ringtoets.ClosingStructures.Service.Test.csproj (.../Ringtoets.ClosingStructures.Service.Test.csproj) (revision 7a1b6072eb543968bd2d9b1a21c53572cd98b89a) @@ -52,6 +52,7 @@ Properties\GlobalAssembly.cs + @@ -65,6 +66,10 @@ {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base + + {D749EE4C-CE50-4C17-BF01-9A953028C126} + Core.Common.TestUtil + {D4200F43-3F72-4F42-AF0A-8CED416A38EC} Ringtoets.Common.Data @@ -73,6 +78,14 @@ {888d4097-8bc2-4703-9fb1-8744c94d525e} Ringtoets.HydraRing.Calculation + + {70F8CC9C-5BC8-4FB2-B201-EAE7FA8088C2} + Ringtoets.HydraRing.Data + + + {74CBA865-9338-447F-BAD9-28312446AE84} + Ringtoets.HydraRing.Calculation.TestUtil + {C6309704-D67B-434C-BC98-9F8910BC1D10} Ringtoets.ClosingStructures.Data @@ -81,6 +94,10 @@ {2BDF07D4-0E81-4B9E-9618-E7EBD9399912} Ringtoets.ClosingStructures.Service + + {F5B43C29-6169-4E9A-859E-09090330B94E} + Ringtoets.ClosingStructures.Data.TestUtil +