Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresCalculationConfigurationExporter.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresCalculationConfigurationExporter.cs (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresCalculationConfigurationExporter.cs (revision 9d677016ec66d0ec3cfce9e9b47ac89998f9f620) @@ -0,0 +1,108 @@ +// 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 Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.IO.Configurations; +using Ringtoets.Common.IO.Configurations.Helpers; +using Ringtoets.Common.IO.Exporters; +using Ringtoets.ClosingStructures.Data; + +namespace Ringtoets.ClosingStructures.IO +{ + /// + /// Exports a closing structures calculation configuration and stores it as an XML file. + /// + public class ClosingStructuresCalculationConfigurationExporter : SchemaCalculationConfigurationExporter< + ClosingStructuresCalculationConfigurationWriter, + StructuresCalculation, + ClosingStructuresCalculationConfiguration> + { + /// + /// Creates a new instance of . + /// + /// The calculation configuration to export. + /// The path of the XML file to export to. + /// Thrown when is null. + /// Thrown when is invalid. + public ClosingStructuresCalculationConfigurationExporter(IEnumerable calculations, string filePath) : base(calculations, filePath) {} + + protected override ClosingStructuresCalculationConfiguration ToConfiguration(StructuresCalculation calculation) + { + ClosingStructuresInput input = calculation.InputParameters; + var calculationConfiguration = new ClosingStructuresCalculationConfiguration(calculation.Name); + + calculationConfiguration.HydraulicBoundaryLocationName = input.HydraulicBoundaryLocation?.Name; + + if (input.Structure != null) + { + calculationConfiguration.StructureName = input.Structure.Name; + calculationConfiguration.StructureNormalOrientation = input.StructureNormalOrientation; + + calculationConfiguration.InflowModelType = (ConfigurationClosingStructureInflowModelType?) new ConfigurationClosingStructureInflowModelTypeConverter().ConvertFrom(input.InflowModelType); + calculationConfiguration.IdenticalApertures = input.IdenticalApertures; + calculationConfiguration.FailureProbabilityOpenStructure = input.FailureProbabilityOpenStructure; + calculationConfiguration.FailureProbabilityReparation = input.FailureProbabilityReparation; + calculationConfiguration.ProbabilityOrFrequencyOpenStructureBeforeFlooding = input.ProbabilityOrFrequencyOpenStructureBeforeFlooding; + + calculationConfiguration.FlowWidthAtBottomProtection = input.FlowWidthAtBottomProtection.ToStochastConfiguration(); + calculationConfiguration.WidthFlowApertures = input.WidthFlowApertures.ToStochastConfiguration(); + calculationConfiguration.StorageStructureArea = input.StorageStructureArea.ToStochastConfiguration(); + calculationConfiguration.AllowedLevelIncreaseStorage = input.AllowedLevelIncreaseStorage.ToStochastConfiguration(); + calculationConfiguration.CriticalOvertoppingDischarge = input.CriticalOvertoppingDischarge.ToStochastConfiguration(); + + calculationConfiguration.AreaFlowApertures = input.AreaFlowApertures.ToStochastConfiguration(); + calculationConfiguration.DrainCoefficient = input.DrainCoefficient.ToStochastConfiguration(); + calculationConfiguration.InsideWaterLevel = input.InsideWaterLevel.ToStochastConfiguration(); + calculationConfiguration.LevelCrestStructureNotClosing = input.LevelCrestStructureNotClosing.ToStochastConfiguration(); + calculationConfiguration.ThresholdHeightOpenWeir = input.ThresholdHeightOpenWeir.ToStochastConfiguration(); + } + + if (input.ForeshoreProfile != null) + { + calculationConfiguration.ForeshoreProfileName = input.ForeshoreProfile?.Name; + calculationConfiguration.WaveReduction = new WaveReductionConfiguration + { + UseForeshoreProfile = input.UseForeshore, + UseBreakWater = input.UseBreakWater, + BreakWaterType = (ConfigurationBreakWaterType?) new ConfigurationBreakWaterTypeConverter().ConvertFrom(input.BreakWater.Type), + BreakWaterHeight = input.BreakWater.Height + }; + } + + calculationConfiguration.FailureProbabilityStructureWithErosion = input.FailureProbabilityStructureWithErosion; + calculationConfiguration.FactorStormDurationOpenStructure = input.FactorStormDurationOpenStructure; + + calculationConfiguration.StormDuration = input.StormDuration.ToStochastConfigurationWithMean(); + calculationConfiguration.DrainCoefficient = input.DrainCoefficient.ToStochastConfigurationWithMean(); + calculationConfiguration.ModelFactorSuperCriticalFlow = input.ModelFactorSuperCriticalFlow.ToStochastConfigurationWithMean(); + + return calculationConfiguration; + } + + protected override ClosingStructuresCalculationConfigurationWriter CreateWriter(string filePath) + { + return new ClosingStructuresCalculationConfigurationWriter(filePath); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Ringtoets.ClosingStructures.IO.csproj =================================================================== diff -u -rc0c4d914f97d3471b73898030db0066dced39331 -r9d677016ec66d0ec3cfce9e9b47ac89998f9f620 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Ringtoets.ClosingStructures.IO.csproj (.../Ringtoets.ClosingStructures.IO.csproj) (revision c0c4d914f97d3471b73898030db0066dced39331) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Ringtoets.ClosingStructures.IO.csproj (.../Ringtoets.ClosingStructures.IO.csproj) (revision 9d677016ec66d0ec3cfce9e9b47ac89998f9f620) @@ -50,6 +50,7 @@ + True Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/ClosingStructuresCalculationConfigurationExporterTest.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/ClosingStructuresCalculationConfigurationExporterTest.cs (revision 0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/ClosingStructuresCalculationConfigurationExporterTest.cs (revision 9d677016ec66d0ec3cfce9e9b47ac89998f9f620) @@ -0,0 +1,263 @@ +// 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.Collections.Generic; +using System.IO; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.TestUtil; + +namespace Ringtoets.ClosingStructures.IO.Test +{ + [TestFixture] + public class ClosingStructuresCalculationConfigurationExporterTest + : CustomSchemaCalculationConfigurationExporterDesignGuidelinesTestFixture< + ClosingStructuresCalculationConfigurationExporter, + ClosingStructuresCalculationConfigurationWriter, + StructuresCalculation, + ClosingStructuresCalculationConfiguration> + { + + private static IEnumerable Calculations + { + get + { + yield return new TestCaseData("completeConfiguration", new[] + { + CreateFullCalculation() + }) + .SetName("Calculation configuration with all parameters set"); + yield return new TestCaseData("sparseConfiguration", new[] + { + CreateSparseCalculation() + }) + .SetName("Calculation configuration with none of its parameters set"); + yield return new TestCaseData("configurationWithStructure", new[] + { + CreateCalculationWithStructure() + }) + .SetName("Calculation configuration with a structure set"); + yield return new TestCaseData("configurationWithForeshoreProfile", new[] + { + CreateCalculationWithForeshoreProfile() + }) + .SetName("Calculation configuration with foreshore profile"); + yield return new TestCaseData("configurationWithUseBreakWater", new[] + { + CreateCalculationWithUseBreakWater() + }) + .SetName("Calculation configuration with use breakwater true"); + yield return new TestCaseData("folderWithSubfolderAndCalculation", new[] + { + new CalculationGroup("Testmap", false) + { + Children = + { + CreateFullCalculation(), + new CalculationGroup("Nested", false) + { + Children = + { + CreateSparseCalculation() + } + } + } + } + }) + .SetName("Calculation configuration with hierarchy"); + } + } + + [Test] + [TestCaseSource(nameof(Calculations))] + public void Export_ValidData_ReturnTrueAndWritesFile(string fileName, ICalculationBase[] calculations) + { + // Setup + string testDirectory = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.ClosingStructures.IO, + nameof(ClosingStructuresCalculationConfigurationExporter)); + + string expectedXmlFilePath = Path.Combine(testDirectory, $"{fileName}.xml"); + + // Call and Assert + WriteAndValidate(calculations, expectedXmlFilePath); + } + + private static ICalculation CreateSparseCalculation() + { + return new StructuresCalculation + { + Name = "sparse config" + }; + } + + private static StructuresCalculation CreateFullCalculation() + { + return new TestClosingStructuresCalculation + { + Name = "full config", + InputParameters = + { + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("Locatie1"), + Structure = new TestClosingStructure("kunstwerk1"), + ForeshoreProfile = new TestForeshoreProfile("profiel1"), + FailureProbabilityStructureWithErosion = 1e-4, + StructureNormalOrientation = (RoundedDouble) 67.1, + FactorStormDurationOpenStructure = (RoundedDouble) 1.0, + IdenticalApertures = 1, + ProbabilityOrFrequencyOpenStructureBeforeFlooding = 1e-2, + FailureProbabilityOpenStructure = 1e-3, + FailureProbabilityReparation = 1e-2, + InflowModelType = ClosingStructureInflowModelType.LowSill, + UseBreakWater = true, + UseForeshore = true, + BreakWater = + { + Type = BreakWaterType.Dam, + Height = (RoundedDouble) 1.234 + }, + StormDuration = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 6.0, + CoefficientOfVariation = (RoundedDouble) 0.22 + }, + ModelFactorSuperCriticalFlow = new NormalDistribution + { + Mean = (RoundedDouble) 1.10, + StandardDeviation = (RoundedDouble) 0.14 + }, + FlowWidthAtBottomProtection = new LogNormalDistribution + { + Mean = (RoundedDouble) 15.2, + StandardDeviation = (RoundedDouble) 0.1 + }, + WidthFlowApertures = new NormalDistribution + { + Mean = (RoundedDouble) 13.2, + StandardDeviation = (RoundedDouble) 0.3 + }, + StorageStructureArea = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 15000, + CoefficientOfVariation = (RoundedDouble) 0.01 + }, + AllowedLevelIncreaseStorage = new LogNormalDistribution + { + Mean = (RoundedDouble) 0.2, + StandardDeviation = (RoundedDouble) 0.01 + }, + CriticalOvertoppingDischarge = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 2, + CoefficientOfVariation = (RoundedDouble) 0.1 + }, + DrainCoefficient = new NormalDistribution + { + Mean = (RoundedDouble) 1.1, + StandardDeviation = (RoundedDouble) 0.02 + }, + InsideWaterLevel = new NormalDistribution + { + Mean = (RoundedDouble) 0.5, + StandardDeviation = (RoundedDouble) 0.1 + }, + AreaFlowApertures = new LogNormalDistribution + { + Mean = (RoundedDouble) 80.5, + StandardDeviation = (RoundedDouble) 1 + }, + ThresholdHeightOpenWeir = new NormalDistribution + { + Mean = (RoundedDouble) 1.2, + StandardDeviation = (RoundedDouble) 0.1 + }, + LevelCrestStructureNotClosing = new NormalDistribution + { + Mean = (RoundedDouble) 4.3, + StandardDeviation = (RoundedDouble) 0.2 + } + } + }; + } + + private static StructuresCalculation CreateCalculationWithForeshoreProfile() + { + return new StructuresCalculation + { + Name = "with foreshore profile", + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile("profiel1"), + UseForeshore = true + } + }; + } + + private static StructuresCalculation CreateCalculationWithUseBreakWater() + { + return new StructuresCalculation + { + Name = "with use breakwater", + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile("profiel1"), + BreakWater = + { + Type = BreakWaterType.Caisson, + Height = (RoundedDouble) 1.23 + }, + UseBreakWater = true, + UseForeshore = false + } + }; + } + + private static StructuresCalculation CreateCalculationWithStructure() + { + return new StructuresCalculation + { + Name = "with structure", + InputParameters = + { + Structure = new TestClosingStructure("kunstwerk1"), + } + }; + } + + protected override StructuresCalculation CreateCalculation() + { + return new TestClosingStructuresCalculation(); + } + + protected override ClosingStructuresCalculationConfigurationExporter CallConfigurationFilePathConstructor(IEnumerable calculations, string filePath) + { + return new ClosingStructuresCalculationConfigurationExporter(calculations, filePath); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Ringtoets.ClosingStructures.IO.Test.csproj =================================================================== diff -u -rc0c4d914f97d3471b73898030db0066dced39331 -r9d677016ec66d0ec3cfce9e9b47ac89998f9f620 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Ringtoets.ClosingStructures.IO.Test.csproj (.../Ringtoets.ClosingStructures.IO.Test.csproj) (revision c0c4d914f97d3471b73898030db0066dced39331) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Ringtoets.ClosingStructures.IO.Test.csproj (.../Ringtoets.ClosingStructures.IO.Test.csproj) (revision 9d677016ec66d0ec3cfce9e9b47ac89998f9f620) @@ -49,6 +49,7 @@ Properties\GlobalAssembly.cs + @@ -78,6 +79,10 @@ {52BA7627-CBAB-4209-BE77-3B5F31378277} Ringtoets.Common.IO + + {4843D6E5-066F-4795-94F5-1D53932DD03C} + Ringtoets.Common.Data.TestUtil + {33508D7C-1602-4C0D-8503-73AAE98C19E5} Ringtoets.Common.IO.TestUtil @@ -90,6 +95,10 @@ {24043F46-406D-4719-B94B-033D63D61153} Ringtoets.ClosingStructures.IO + + {F5B43C29-6169-4E9A-859E-09090330B94E} + Ringtoets.ClosingStructures.Data.TestUtil +