// 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.Drawing; using System.Linq; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Probability; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.HeightStructures.Data; using Ringtoets.HydraRing.Data; using Ringtoets.Integration.Data; using Ringtoets.Integration.Data.StandAlone.SectionResults; using Ringtoets.Piping.Data; using Ringtoets.Piping.KernelWrapper.TestUtil; using Ringtoets.Piping.Primitives; namespace Application.Ringtoets.Storage.TestUtil { /// /// This class can be used to create instances which have their properties set and can be used in tests. /// public static class RingtoetsProjectTestHelper { /// /// Returns a new complete instance of . /// /// A new complete instance of . public static RingtoetsProject GetFullTestProject() { var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { Name = "assessmentSection", HydraulicBoundaryDatabase = GetHydraulicBoundaryDatabase(), ReferenceLine = GetReferenceLine() }; PipingFailureMechanism pipingFailureMechanism = assessmentSection.PipingFailureMechanism; ConfigurePipingFailureMechanism(pipingFailureMechanism, assessmentSection); AddSections(pipingFailureMechanism); SetSectionResults(pipingFailureMechanism.SectionResults); GrassCoverErosionInwardsFailureMechanism grassCoverErosionInwardsFailureMechanism = assessmentSection.GrassCoverErosionInwards; ConfigureGrassCoverErosionInwardsFailureMechanism(grassCoverErosionInwardsFailureMechanism, assessmentSection); AddSections(grassCoverErosionInwardsFailureMechanism); SetSectionResults(grassCoverErosionInwardsFailureMechanism.SectionResults, grassCoverErosionInwardsFailureMechanism.Calculations.OfType()); AddSections(assessmentSection.MacrostabilityInwards); SetSectionResults(assessmentSection.MacrostabilityInwards.SectionResults); AddSections(assessmentSection.MacrostabilityOutwards); SetSectionResults(assessmentSection.MacrostabilityOutwards.SectionResults); AddSections(assessmentSection.Microstability); SetSectionResults(assessmentSection.Microstability.SectionResults); AddSections(assessmentSection.StabilityStoneCover); SetSectionResults(assessmentSection.StabilityStoneCover.SectionResults); AddSections(assessmentSection.WaveImpactAsphaltCover); SetSectionResults(assessmentSection.WaveImpactAsphaltCover.SectionResults); AddSections(assessmentSection.WaterPressureAsphaltCover); SetSectionResults(assessmentSection.WaterPressureAsphaltCover.SectionResults); AddSections(assessmentSection.GrassCoverErosionOutwards); SetSectionResults(assessmentSection.GrassCoverErosionOutwards.SectionResults); AddSections(assessmentSection.GrassCoverSlipOffInwards); SetSectionResults(assessmentSection.GrassCoverSlipOffInwards.SectionResults); AddSections(assessmentSection.GrassCoverSlipOffOutwards); SetSectionResults(assessmentSection.GrassCoverSlipOffOutwards.SectionResults); AddSections(assessmentSection.HeightStructures); SetSectionResults(assessmentSection.HeightStructures.SectionResults); AddSections(assessmentSection.ClosingStructure); SetSectionResults(assessmentSection.ClosingStructure.SectionResults); AddSections(assessmentSection.StrengthStabilityPointConstruction); SetSectionResults(assessmentSection.StrengthStabilityPointConstruction.SectionResults); AddSections(assessmentSection.StrengthStabilityLengthwiseConstruction); SetSectionResults(assessmentSection.StrengthStabilityLengthwiseConstruction.SectionResults); AddSections(assessmentSection.PipingStructure); SetSectionResults(assessmentSection.PipingStructure.SectionResults); AddSections(assessmentSection.DuneErosion); SetSectionResults(assessmentSection.DuneErosion.SectionResults); AddSections(assessmentSection.TechnicalInnovation); SetSectionResults(assessmentSection.TechnicalInnovation.SectionResults); var fullTestProject = new RingtoetsProject { Name = "tempProjectFile", Description = "description", AssessmentSections = { assessmentSection } }; return fullTestProject; } private static void ConfigurePipingFailureMechanism(PipingFailureMechanism pipingFailureMechanism, AssessmentSection assessmentSection) { pipingFailureMechanism.PipingProbabilityAssessmentInput.A = 0.9; pipingFailureMechanism.PipingProbabilityAssessmentInput.UpliftCriticalSafetyFactor = (RoundedDouble) 1.9; var referenceLineGeometryPoints = assessmentSection.ReferenceLine.Points.ToArray(); PipingSoilProfile pipingSoilProfile = new TestPipingSoilProfile(); PipingSoilLayer pipingSoilLayer = pipingSoilProfile.Layers.First(); pipingSoilLayer.BelowPhreaticLevelMean = 2.2; pipingSoilLayer.BelowPhreaticLevelDeviation = 1.2; pipingSoilLayer.BelowPhreaticLevelShift = 3.2; pipingSoilLayer.DiameterD70Mean = 2.42; pipingSoilLayer.DiameterD70Deviation = 21.002; pipingSoilLayer.PermeabilityMean = 0.9982; pipingSoilLayer.PermeabilityDeviation = 0.220; pipingSoilLayer.Color = Color.HotPink; pipingSoilLayer.MaterialName = "HotPinkLayer"; pipingFailureMechanism.StochasticSoilModels.Add(new StochasticSoilModel(-1, "modelName", "modelSegmentName") { Geometry = { referenceLineGeometryPoints[1], referenceLineGeometryPoints[2], referenceLineGeometryPoints[3] }, StochasticSoilProfiles = { new StochasticSoilProfile(0.2, SoilProfileType.SoilProfile1D, -1) { SoilProfile = pipingSoilProfile }, new StochasticSoilProfile(0.8, SoilProfileType.SoilProfile1D, -1) { SoilProfile = new TestPipingSoilProfile() } } }); pipingFailureMechanism.SurfaceLines.Add(GetSurfaceLine()); CalculationGroup pipingCalculationGroup = pipingFailureMechanism.CalculationsGroup; pipingCalculationGroup.Children.Add(new CalculationGroup { Name = "A", Children = { new PipingCalculationScenario(pipingFailureMechanism.GeneralInput) { Name = "AA", IsRelevant = true, Contribution = (RoundedDouble) 1.0, Comments = "Nice comment about this calculation!", InputParameters = { SurfaceLine = pipingFailureMechanism.SurfaceLines.First(), HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(), StochasticSoilModel = pipingFailureMechanism.StochasticSoilModels.First(), StochasticSoilProfile = pipingFailureMechanism.StochasticSoilModels.First() .StochasticSoilProfiles.First(), EntryPointL = (RoundedDouble) 1.0, ExitPointL = (RoundedDouble) 2.0, PhreaticLevelExit = { Mean = (RoundedDouble) 1.1, StandardDeviation = (RoundedDouble) 2.2 }, DampingFactorExit = { Mean = (RoundedDouble) 3.3, StandardDeviation = (RoundedDouble) 4.4 }, SaturatedVolumicWeightOfCoverageLayer = { Mean = (RoundedDouble) 7.7, StandardDeviation = (RoundedDouble) 6.6, Shift = (RoundedDouble) 5.5 }, Diameter70 = { Mean = (RoundedDouble) 8.8, StandardDeviation = (RoundedDouble) 9.9 }, DarcyPermeability = { Mean = (RoundedDouble) 10.10, StandardDeviation = (RoundedDouble) 11.11 } }, Output = new PipingOutput(1.1, 2.2, 3.3, 4.4, 5.5, 6.6), SemiProbabilisticOutput = new PipingSemiProbabilisticOutput(7.7, 0.9, 10.10, 11.11, 0.12, 13.13, 14.14, 0.15, 0.16, 17.17, 0.18, 19.19, 20.20) } } }); pipingCalculationGroup.Children.Add(new CalculationGroup { Name = "B" }); pipingCalculationGroup.Children.Add(new PipingCalculationScenario(pipingFailureMechanism.GeneralInput) { Name = "C", IsRelevant = false, Contribution = (RoundedDouble) 0.5, Comments = "Another great comment", InputParameters = { SurfaceLine = pipingFailureMechanism.SurfaceLines.First(), HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(), StochasticSoilModel = pipingFailureMechanism.StochasticSoilModels.First(), StochasticSoilProfile = pipingFailureMechanism.StochasticSoilModels.First() .StochasticSoilProfiles.Skip(1).First(), EntryPointL = (RoundedDouble) 0.3, ExitPointL = (RoundedDouble) 2.3, PhreaticLevelExit = { Mean = (RoundedDouble) 12.12, StandardDeviation = (RoundedDouble) 13.13 }, DampingFactorExit = { Mean = (RoundedDouble) 14.14, StandardDeviation = (RoundedDouble) 15.15 }, SaturatedVolumicWeightOfCoverageLayer = { Mean = (RoundedDouble) 18.18, StandardDeviation = (RoundedDouble) 17.17, Shift = (RoundedDouble) 16.16 }, Diameter70 = { Mean = (RoundedDouble) 19.19, StandardDeviation = (RoundedDouble) 20.20 }, DarcyPermeability = { Mean = (RoundedDouble) 21.21, StandardDeviation = (RoundedDouble) 22.22 } }, Output = null, SemiProbabilisticOutput = null }); } private static void ConfigureGrassCoverErosionInwardsFailureMechanism(GrassCoverErosionInwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { failureMechanism.GeneralInput.N = 15; var dikeProfile = new DikeProfile(new Point2D(1, 2), new[] { new RoughnessPoint(new Point2D(1, 2), 1), new RoughnessPoint(new Point2D(3, 4), 0.5) }, new[] { new Point2D(5, 6), new Point2D(7, 8) }, new BreakWater(BreakWaterType.Caisson, 15), new DikeProfile.ConstructionProperties { DikeHeight = 1.1, Name = "2.2", Orientation = 3.3, X0 = 4.4 }); failureMechanism.DikeProfiles.Add(dikeProfile); failureMechanism.DikeProfiles.Add(new DikeProfile(new Point2D(9, 10), new[] { new RoughnessPoint(new Point2D(11, 12), 1), new RoughnessPoint(new Point2D(13, 14), 0.5), }, new Point2D[0], null, new DikeProfile.ConstructionProperties { DikeHeight = 5.5, Name = "6.6", Orientation = 7.7, X0 = 8.8 })); failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup { Name = "GEKB A", Children = { new GrassCoverErosionInwardsCalculation { Name = "Calculation 1", Comments = "Comments for Calculation 1", InputParameters = { DikeProfile = dikeProfile, HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations[0], BreakWater = { Height = (RoundedDouble) (dikeProfile.BreakWater.Height + 0.3), Type = BreakWaterType.Wall }, DikeHeight = (RoundedDouble) (dikeProfile.DikeHeight + 0.2), Orientation = dikeProfile.Orientation, CriticalFlowRate = { Mean = (RoundedDouble) 1.1, StandardDeviation = (RoundedDouble) 2.2 }, CalculateDikeHeight = true, UseForeshore = true, UseBreakWater = true }, Output = new GrassCoverErosionInwardsOutput(0.45, true, new ProbabilityAssessmentOutput(0.004, 0.95, 0.00003, 1.1, 4.5), 0.56) } } }); failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup { Name = "GEKB B" }); failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup { Name = "GEKB C", Children = { new GrassCoverErosionInwardsCalculation { Name = "Calculation 2", Comments = "Comments about Calculation 2" } } }); } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults, IEnumerable calculations) { var random = new Random(21); bool firstSectionResultHasCalculation = false; var grassCoverErosionInwardsCalculation = calculations.First(); foreach (var sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); if (!firstSectionResultHasCalculation) { sectionResult.Calculation = grassCoverErosionInwardsCalculation; firstSectionResultHasCalculation = true; } } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerTwoA = (RoundedDouble) random.NextDouble(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerTwoA = (RoundedDouble) random.NextDouble(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerTwoA = (RoundedDouble) random.NextDouble(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerTwoA = (RoundedDouble) random.NextDouble(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { var randomLayer2AResult = (AssessmentLayerTwoAResult) random.Next(0, Enum.GetValues(typeof(AssessmentLayerTwoAResult)).Length); sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerTwoA = randomLayer2AResult; sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { var randomLayer2AResult = (AssessmentLayerTwoAResult) random.Next(0, Enum.GetValues(typeof(AssessmentLayerTwoAResult)).Length); sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerTwoA = randomLayer2AResult; sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { var randomLayer2AResult = (AssessmentLayerTwoAResult) random.Next(0, Enum.GetValues(typeof(AssessmentLayerTwoAResult)).Length); sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerTwoA = randomLayer2AResult; sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { var randomLayer2AResult = (AssessmentLayerTwoAResult) random.Next(0, Enum.GetValues(typeof(AssessmentLayerTwoAResult)).Length); sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerTwoA = randomLayer2AResult; sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { var randomLayer2AResult = (AssessmentLayerTwoAResult) random.Next(0, Enum.GetValues(typeof(AssessmentLayerTwoAResult)).Length); sectionResult.AssessmentLayerOne = Convert.ToBoolean(random.Next(0, 2)); sectionResult.AssessmentLayerTwoA = randomLayer2AResult; sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { var randomLayer2AResult = (AssessmentLayerTwoAResult) random.Next(0, Enum.GetValues(typeof(AssessmentLayerTwoAResult)).Length); sectionResult.AssessmentLayerTwoA = randomLayer2AResult; sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { var randomLayer2AResult = (AssessmentLayerTwoAResult) random.Next(0, Enum.GetValues(typeof(AssessmentLayerTwoAResult)).Length); sectionResult.AssessmentLayerTwoA = randomLayer2AResult; sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void SetSectionResults(IEnumerable sectionResults) { var random = new Random(21); foreach (var sectionResult in sectionResults) { sectionResult.AssessmentLayerTwoA = (RoundedDouble) random.NextDouble(); sectionResult.AssessmentLayerThree = (RoundedDouble) random.NextDouble(); } } private static void AddSections(IFailureMechanism failureMechanism) { failureMechanism.AddSection(new FailureMechanismSection("section 1", new[] { new Point2D(0, 2), new Point2D(2, 3) })); failureMechanism.AddSection(new FailureMechanismSection("section 2", new[] { new Point2D(2, 3), new Point2D(4, 5) })); failureMechanism.AddSection(new FailureMechanismSection("section 3", new[] { new Point2D(4, 5), new Point2D(2, 3) })); } private static RingtoetsPipingSurfaceLine GetSurfaceLine() { var surfaceLine = new RingtoetsPipingSurfaceLine { Name = "Surfaceline", ReferenceLineIntersectionWorldPoint = new Point2D(4.0, 6.0) }; var geometryPoints = new[] { new Point3D(6.0, 6.0, -2.3), new Point3D(5.8, 6.0, -2.3), // Dike toe at river new Point3D(5.6, 6.0, 3.4), new Point3D(4.2, 6.0, 3.5), new Point3D(4.0, 6.0, 0.5), // Dike toe at polder new Point3D(3.8, 6.0, 0.5), // Ditch dike side new Point3D(3.6, 6.0, 0.2), // Bottom ditch dike side new Point3D(3.4, 6.0, 0.25), // Bottom ditch polder side new Point3D(3.2, 6.0, 0.5), // Ditch polder side new Point3D(3.0, 6.0, 0.5), }; surfaceLine.SetGeometry(geometryPoints); surfaceLine.SetDikeToeAtRiverAt(geometryPoints[1]); surfaceLine.SetDikeToeAtPolderAt(geometryPoints[4]); surfaceLine.SetDitchDikeSideAt(geometryPoints[5]); surfaceLine.SetBottomDitchDikeSideAt(geometryPoints[6]); surfaceLine.SetBottomDitchPolderSideAt(geometryPoints[7]); surfaceLine.SetDitchPolderSideAt(geometryPoints[8]); return surfaceLine; } private static ReferenceLine GetReferenceLine() { IEnumerable points = new[] { new Point2D(2, 3), new Point2D(5, 4), new Point2D(5, 8), new Point2D(-3, 2) }; var referenceLine = new ReferenceLine(); referenceLine.SetGeometry(points); return referenceLine; } private static HydraulicBoundaryDatabase GetHydraulicBoundaryDatabase() { var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { FilePath = "/temp/test", Version = "1.0" }; hydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(13001, "test", 152.3, 2938.5) { DesignWaterLevel = (RoundedDouble) 12.4, WaveHeight = (RoundedDouble) 2.4, DesignWaterLevelCalculationConvergence = CalculationConvergence.NotCalculated, WaveHeightCalculationConvergence = CalculationConvergence.NotCalculated }); return hydraulicBoundaryDatabase; } } }