Index: DamEngine/trunk/src/Deltares.DamEngine.Data/General/Dike.cs =================================================================== diff -u -r5406 -r5426 --- DamEngine/trunk/src/Deltares.DamEngine.Data/General/Dike.cs (.../Dike.cs) (revision 5406) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/General/Dike.cs (.../Dike.cs) (revision 5426) @@ -203,7 +203,7 @@ locations = Locations.OrderBy(o => o.Name).ToList(); } - public void Validate(bool isOperational) + public void Validate(bool isOperational, bool isPiping) { if (Locations == null || Locations.Count < 1) { @@ -212,6 +212,24 @@ foreach (Location location in Locations) { + if (isPiping) + { + if (location.Segment == null) + { + throw new DikeException("Location " + location.Name + " has no segment defined"); + } + + if (location.Segment.SoilProfileProbabilities.Count < 1) + { + throw new DikeException("Location " + location.Name + " has no soil profiles defined"); + } + + if (location.Segment.SoilProfileProbabilities[0].SoilProfile2D != null) + { + throw new DikeException("A piping calculation with a 2D-geometry is not supported."); + } + } + if (location.SurfaceLine != null) { var validator = new SurfaceLine2Validator(); Index: DamEngine/trunk/src/Deltares.DamEngine.Interface/EngineInterface.cs =================================================================== diff -u -r4540 -r5426 --- DamEngine/trunk/src/Deltares.DamEngine.Interface/EngineInterface.cs (.../EngineInterface.cs) (revision 4540) +++ DamEngine/trunk/src/Deltares.DamEngine.Interface/EngineInterface.cs (.../EngineInterface.cs) (revision 5426) @@ -105,7 +105,9 @@ try { - DamProjectData.Dike.Validate(DamProjectData.DamProjectType == DamProjectType.Operational); + bool isOperational = DamProjectData.DamProjectType == DamProjectType.Operational; + bool isPiping = DamProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType == FailureMechanismSystemType.Piping; + DamProjectData.Dike.Validate(isOperational, isPiping); } catch (Exception e) { Index: DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/PipingBlighTests.cs =================================================================== diff -u -r5248 -r5426 --- DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/PipingBlighTests.cs (.../PipingBlighTests.cs) (revision 5248) +++ DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/PipingBlighTests.cs (.../PipingBlighTests.cs) (revision 5426) @@ -26,6 +26,7 @@ using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.Data.Standard.Calculation; using Deltares.DamEngine.Interface; +using Deltares.DamEngine.Io.XmlInput; using Deltares.DamEngine.Io.XmlOutput; using Deltares.DamEngine.TestHelpers; using NUnit.Framework; @@ -280,4 +281,41 @@ Assert.That(output.Results.CalculationMessages[4].Message1, Does.Contain("no uplift")); }); } + + [Test] + public void TestRunPipingBlighWithGeometry2DIsNotPossible() + { + // Based on DAM Tutorial Design.damx + // Except for the following changes: + // - Calculation type is Piping in segments.csv (instead of Stability) + // - Select model Piping Bligh + // - Select 1st location (DWP_1) + const string calcDir = "TestRunPipingBlighWithGeometry2DIsNotPossible"; + if (Directory.Exists(calcDir)) + { + Directory.Delete(calcDir, true); // delete previous results + } + + const string tutorialStability2D = @"InputTutorialStability2D.xml"; + string inputString = File.ReadAllText(tutorialStability2D); + string[] locations = ["DWP_1"]; + inputString = XmlAdapter.SelectLocations(inputString, locations); + + inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used + inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used + inputString = XmlAdapter.ChangeValueInXml(inputString, "FailureMechanismSystemType", "2"); // Piping + inputString = XmlAdapter.ChangeValueInXml(inputString, "SegmentFailureMechanismType", "2"); // Piping + inputString = XmlAdapter.ChangeStabilityToPiping(inputString); + inputString = XmlAdapter.ChangePipingInputModel(inputString, InputPipingModelType.Bligh); + + var engineInterface = new EngineInterface(inputString); + string validationMessages = engineInterface.Validate(); + Assert.Multiple(() => + { + Assert.That(validationMessages, Does.Contain("A piping calculation with a 2D-geometry is not supported.")); + Assert.That(engineInterface.DamProjectData.CalculationMessages, Has.Count.EqualTo(1)); + }); + Assert.That(engineInterface.DamProjectData.CalculationMessages[0].Message, Does.Contain("A piping calculation with a 2D-geometry is not supported.")); + } + } \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/XmlAdapter.cs =================================================================== diff -u -r5397 -r5426 --- DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/XmlAdapter.cs (.../XmlAdapter.cs) (revision 5397) +++ DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/XmlAdapter.cs (.../XmlAdapter.cs) (revision 5426) @@ -21,30 +21,36 @@ using System.Linq; using System.Text.RegularExpressions; +using Deltares.DamEngine.Io.XmlInput; namespace Deltares.DamEngine.TestHelpers; /// /// Helper class for adapting xml in tests /// -public class XmlAdapter +public static class XmlAdapter { /// /// Changes in an XML the value of all elements with the specified key to the specified value. /// /// The input. /// The key. /// The value. - /// + /// The modified input public static string ChangeValueInXml(string input, string key, string value) { - string result = input; string searchString = key + "=" + "\"([^\"]*)\""; // This means match any pattern which matches ="" string replacement = key + "=\"" + value + "\""; // Replace with ="" - result = Regex.Replace(input, searchString, replacement, RegexOptions.IgnorePatternWhitespace); + string result = Regex.Replace(input, searchString, replacement, RegexOptions.IgnorePatternWhitespace); return result; } - + + /// + /// Selects locations from an XML based on the location names by removing the other locations. + /// + /// The input. + /// The names of the locations that need to be selected. + /// The modified input public static string SelectLocations(string input, string[] locationNames) { string result = input; @@ -61,4 +67,58 @@ return result; } + /// + /// Changes the stability input model. + /// + /// The input. + /// The stability input model + /// The modified input + public static string ChangeStabilityInputModel(string input, InputStabilityModelType stabilityModelType) + { + const string pattern = "StabilityModelType=\"[a-zA-Z]+\""; + string replacement = stabilityModelType switch + { + InputStabilityModelType.Bishop => "StabilityModelType=\"Bishop\"", + InputStabilityModelType.UpliftVan => "StabilityModelType=\"UpliftVan\"", + InputStabilityModelType.BishopUpliftVan => "StabilityModelType=\"BishopUpliftVan\"", + _ => pattern + }; + string result = Regex.Replace(input, pattern, replacement); + return result; + } + + /// + /// Changes the piping input model. + /// + /// The input. + /// The piping input model + /// The modified input + public static string ChangePipingInputModel(string input, InputPipingModelType pipingModelType) + { + const string pattern = "PipingModelType=\"[a-zA-Z]+\""; + string replacement = pipingModelType switch + { + InputPipingModelType.Bligh => "PipingModelType=\"Bligh\"", + InputPipingModelType.WtiSellmeijerRevised => "PipingModelType=\"WtiSellmeijerRevised\"", + InputPipingModelType.Sellmeijer4Forces => "PipingModelType=\"Sellmeijer4Forces\"", + InputPipingModelType.SellmeijerVnk => "PipingModelType=\"SellmeijerVnk\"", + _ => pattern + }; + string result = Regex.Replace(input, pattern, replacement); + return result; + } + + /// + /// Changes the stability model type to piping model type. + /// + /// The input. + /// The modified input + public static string ChangeStabilityToPiping(string input) + { + const string pattern = "StabilityModelType="; + const string replacement = "PipingModelType="; + string result = Regex.Replace(input, pattern, replacement); + return result; + } + } \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/MacroStabilityInwardsTests.cs =================================================================== diff -u -r5411 -r5426 --- DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/MacroStabilityInwardsTests.cs (.../MacroStabilityInwardsTests.cs) (revision 5411) +++ DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/MacroStabilityInwardsTests.cs (.../MacroStabilityInwardsTests.cs) (revision 5426) @@ -23,7 +23,6 @@ using System.Globalization; using System.IO; using System.Linq; -using System.Text.RegularExpressions; using System.Threading; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.Geometry; @@ -128,7 +127,7 @@ string[] locations = ["DWP_1"]; inputString = XmlAdapter.SelectLocations(inputString, locations); - inputString = ChangeInputModel(inputString, InputStabilityModelType.UpliftVan); + inputString = XmlAdapter.ChangeStabilityInputModel(inputString, InputStabilityModelType.UpliftVan); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used @@ -185,7 +184,7 @@ string[] locations = ["DWP_1"]; inputString = XmlAdapter.SelectLocations(inputString, locations); - inputString = ChangeInputModel(inputString, InputStabilityModelType.BishopUpliftVan); + inputString = XmlAdapter.ChangeStabilityInputModel(inputString, InputStabilityModelType.BishopUpliftVan); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used @@ -246,7 +245,7 @@ string[] locations = ["DWP_22"]; inputString = XmlAdapter.SelectLocations(inputString, locations); - inputString = ChangeInputModel(inputString, InputStabilityModelType.BishopUpliftVan); + inputString = XmlAdapter.ChangeStabilityInputModel(inputString, InputStabilityModelType.BishopUpliftVan); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "SearchMethod", "2"); @@ -307,7 +306,7 @@ string[] locations = ["DWP_18"]; inputString = XmlAdapter.SelectLocations(inputString, locations); - inputString = ChangeInputModel(inputString, InputStabilityModelType.BishopUpliftVan); + inputString = XmlAdapter.ChangeStabilityInputModel(inputString, InputStabilityModelType.BishopUpliftVan); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used @@ -593,7 +592,7 @@ // Test to see if calculation does NOT work in this case as it must fail with water level above dike top. Output output = GetOutputStringForProject(analysisType, false); - Assert.That(output.Results.CalculationMessages.Length, Is.EqualTo(2)); + Assert.That(output.Results.CalculationMessages, Has.Length.EqualTo(2)); Assert.Multiple(() => { Assert.That(output.Results.CalculationMessages[0].Message1, Does.Contain("Location 'DWP_1', subsoil scenario 'DWP_1.stix', design scenario '1': The preparation for this calculation failed.")); @@ -619,7 +618,7 @@ const string fileName = @"TestFiles\DeltaDijkBishopInwards.xml"; string inputString = File.ReadAllText(fileName); - inputString = ChangeInputModel(inputString, InputStabilityModelType.Bishop); + inputString = XmlAdapter.ChangeStabilityInputModel(inputString, InputStabilityModelType.Bishop); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used @@ -688,7 +687,7 @@ // Read as Bishop, then change to UpliftVan const string fileName = @"TestFiles\DeltaDijkBishopInwards.xml"; string inputString = File.ReadAllText(fileName); - inputString = ChangeInputModel(inputString, InputStabilityModelType.UpliftVan); + inputString = XmlAdapter.ChangeStabilityInputModel(inputString, InputStabilityModelType.UpliftVan); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used @@ -766,7 +765,7 @@ const string fileName = @"TestFiles\DeltaDijkBishopInwards.xml"; string inputString = File.ReadAllText(fileName); - inputString = ChangeInputModel(inputString, InputStabilityModelType.BishopUpliftVan); + inputString = XmlAdapter.ChangeStabilityInputModel(inputString, InputStabilityModelType.BishopUpliftVan); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used @@ -853,7 +852,7 @@ const string fileName = @"TestFiles\DeltaDijkBishopInwards.xml"; string inputString = File.ReadAllText(fileName); - inputString = ChangeInputModel(inputString, InputStabilityModelType.BishopUpliftVan); + inputString = XmlAdapter.ChangeStabilityInputModel(inputString, InputStabilityModelType.BishopUpliftVan); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "UpliftCriterionStability", @"1.0"); @@ -951,27 +950,6 @@ return GeneralHelper.RunAfterInputValidation(inputString, isSuccessful); } - private string ChangeInputModel(string input, InputStabilityModelType modelType) - { - var pattern = "StabilityModelType=\"[a-zA-Z]+\""; - string replacement = pattern; - switch (modelType) - { - case InputStabilityModelType.Bishop: - replacement = "StabilityModelType=\"Bishop\""; - break; - case InputStabilityModelType.UpliftVan: - replacement = "StabilityModelType=\"UpliftVan\""; - break; - case InputStabilityModelType.BishopUpliftVan: - replacement = "StabilityModelType=\"BishopUpliftVan\""; - break; - } - - string result = Regex.Replace(input, pattern, replacement); - return result; - } - private static void CheckCalculationResults(DesignResult output, string locationName, string profileName, DesignResultStabilityDesignResultsStabilityModelType model, double safetyFactor, bool isUplift, CalculationResult result) {