// Copyright (C) Stichting Deltares 2018. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero 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 Affero General Public License for more details. // // You should have received a copy of the GNU Affero 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.IO; using System.Text.RegularExpressions; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.Data.Standard.Calculation; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlInput; using Deltares.DamEngine.Io.XmlOutput; using Deltares.DamEngine.TestHelpers; using NUnit.Framework; namespace Deltares.DamEngine.Interface.Tests { [TestFixture] public class MacroStabilityInwardsTests { private const double tolerance = 0.0005; [Test, Category("Slow")] public void TestRunMacroStabilityTutorialDesignBishop() { // Based on ".data\DamEngineTestProjects\DAM Tutorial Design\DAM Tutorial Design.damx" // with Dam Classic rev.1059 // Set Analysis type to "No adaption" // Select 1st location (DWP_1) // Set Calculation Options: Stability Inside - Bishop // Expected results are determined by running dam\dam clients\DamUI\trunk\data\DamEngineTestProjects\DAM Tutorial Design // with Dam Classic rev.833 const string calcDir = "TestStabInwardsBishop"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } Directory.CreateDirectory(calcDir); const string fileName = @"TestFiles\MacroStabilityTutorialDesignInputFile.xml"; string inputString = File.ReadAllText(fileName); 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, "MapForSoilgeometries2D", @"TestFiles\DAM Tutorial Design.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DAM Tutorial Design0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); Assert.AreEqual(1.282, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.SafetyFactor, tolerance); // Zone1SafetyFactor=1.282 Assert.AreEqual(1.282, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.Zone1SafetyFactor, tolerance); // Zone1EntryPointX Local =38.818 Global=47.238 Assert.AreEqual(38.818, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.Zone1EntryPointX, tolerance); // Zone1ExitPointX Local=64.262 Global=72.682 Assert.AreEqual(64.262, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.Zone1ExitPointX, tolerance); // Zone2SafetyFactor null, is set to default reading from output.xml Assert.AreEqual(0, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.Zone2SafetyFactor, tolerance); // Zone2EntryPointX null, is set to default reading from output.xml Assert.AreEqual(0, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.Zone2EntryPointX, tolerance); // Zone2ExitPointX null, is set to default reading from output.xml Assert.AreEqual(0, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.Zone2ExitPointX, tolerance); // NumberOfIterations=0 Assert.AreEqual(0, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.NumberOfIterations); // ResultMessage "" Assert.AreEqual("", output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.ResultMessage); // Check that a line is specified Assert.IsNotNull(output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.RedesignedSurfaceLine); // Profile name = DWP_1.sti Assert.AreEqual("DWP_1.sti", output.Results.CalculationResults.DesignResults[0].ProfileName); // Uplift var upliftSituation = output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.UpliftSituation; Assert.IsNotNull(upliftSituation); Assert.AreEqual(true, upliftSituation.IsUplift); Assert.AreEqual(1.141, upliftSituation.Pl3MinUplift, tolerance); Assert.AreEqual(4.4, upliftSituation.Pl3HeadAdjusted, tolerance); Assert.AreEqual(60.64, upliftSituation.Pl3LocationXMinUplift, tolerance); Assert.AreEqual(0.0, upliftSituation.Pl4MinUplift, tolerance); Assert.AreEqual(0.0, upliftSituation.Pl4HeadAdjusted, tolerance); Assert.AreEqual(0.0, upliftSituation.Pl4LocationXMinUplift, tolerance); // Calculation Result Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults.DesignResults[0].CalculationResult)); } [Test, Category("Slow")] public void TestRunMacroStabilityTutorialDesignUpliftVan() { // Based on ".data\DamEngineTestProjects\DAM Tutorial Design\DAM Tutorial Design.damx" // with Dam Classic rev.1059 // Select 1st location (DWP_1) // with Dam Classic rev.833 const string calcDir = "TestStabInwardsUpliftVan"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } const string fileName = @"TestFiles\MacroStabilityTutorialDesignInputFile.xml"; string inputString = File.ReadAllText(fileName); inputString = ChangeInputModel(inputString, InputStabilityModelType.UpliftVan); 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, "MapForSoilgeometries2D", @"TestFiles\DAM Tutorial Design.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DAM Tutorial Design0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); Assert.AreEqual(1.062, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.SafetyFactor, tolerance); // Zone1SafetyFactor=1.062 Assert.AreEqual(1.062, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.Zone1SafetyFactor, tolerance); // Zone1EntryPointX Local =39.3 Global=47.72 Assert.AreEqual(39.3, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.Zone1EntryPointX, tolerance); // Zone1ExitPointX Local=64.442 Global=72.682 Assert.AreEqual(64.442, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.Zone1ExitPointX, tolerance); // Zone2SafetyFactor null, is set to default reading from output.xml Assert.AreEqual(0, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.Zone2SafetyFactor, tolerance); // Zone2EntryPointX null, is set to default reading from output.xml Assert.AreEqual(0, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.Zone2EntryPointX, tolerance); // Zone2ExitPointX null, is set to default reading from output.xml Assert.AreEqual(0, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.Zone2ExitPointX, tolerance); // NumberOfIterations=0 Assert.AreEqual(0, output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.NumberOfIterations); // ResultMessage "" Assert.AreEqual("", output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.ResultMessage); // Check that a line is specified Assert.IsNotNull(output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.RedesignedSurfaceLine); // Profile name = DWP_1.sti Assert.AreEqual("DWP_1.sti", output.Results.CalculationResults.DesignResults[0].ProfileName); // Uplift var upliftSituation = output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.UpliftSituation; Assert.IsNotNull(upliftSituation); Assert.AreEqual(true, upliftSituation.IsUplift); Assert.AreEqual(1.141, upliftSituation.Pl3MinUplift, tolerance); Assert.AreEqual(4.4, upliftSituation.Pl3HeadAdjusted, tolerance); Assert.AreEqual(60.64, upliftSituation.Pl3LocationXMinUplift, tolerance); Assert.AreEqual(0.0, upliftSituation.Pl4MinUplift, tolerance); Assert.AreEqual(0.0, upliftSituation.Pl4HeadAdjusted, tolerance); Assert.AreEqual(0.0, upliftSituation.Pl4LocationXMinUplift, tolerance); // Calculation Result Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults.DesignResults[0].CalculationResult)); } [Test, Category("Slow")] public void TestRunMacroStabilityTutorialDesignBishopUpliftVan_UpliftVanLowest() { // Based on ".data\DamEngineTestProjects\DAM Tutorial Design\DAM Tutorial Design.damx" // with Dam Classic rev.1059 // Select 1st location (DWP_1) // with Dam Classic rev.833 const string calcDir = "TestStabInwardsBishopUpliftVan_UpliftVanLowest"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } const string fileName = @"TestFiles\MacroStabilityTutorialDesignInputFile.xml"; string inputString = File.ReadAllText(fileName); inputString = ChangeInputModel(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, "MapForSoilgeometries2D", @"TestFiles\DAM Tutorial Design.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DAM Tutorial Design0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); // Bishop var result = output.Results.CalculationResults.DesignResults[0]; Assert.AreEqual(1.282, result.StabilityDesignResults.SafetyFactor, tolerance); Assert.IsNotNull(result.StabilityDesignResults.UpliftSituation); Assert.IsTrue(result.StabilityDesignResults.UpliftSituation.IsUplift); Assert.AreEqual(DesignResultStabilityDesignResultsStabilityModelType.Bishop, result.StabilityDesignResults.StabilityModelType); Assert.AreEqual("Loc(DWP_1)_Sce(1)_Pro(DWP_1)", result.BaseFileName); // Uplift Van result = output.Results.CalculationResults.DesignResults[1]; Assert.AreEqual(1.062, result.StabilityDesignResults.SafetyFactor, tolerance); Assert.IsNotNull(result.StabilityDesignResults.UpliftSituation); Assert.AreEqual(DesignResultStabilityDesignResultsStabilityModelType.UpliftVan, result.StabilityDesignResults.StabilityModelType); Assert.AreEqual("Loc(DWP_1)_Sce(1)_Pro(DWP_1)", result.BaseFileName); // Worst of Bishop and Uplift Van result = output.Results.CalculationResults.DesignResults[2]; Assert.AreEqual(1.062, result.StabilityDesignResults.SafetyFactor, tolerance); Assert.IsNotNull(result.StabilityDesignResults.UpliftSituation); Assert.AreEqual(DesignResultStabilityDesignResultsStabilityModelType.BishopUpliftVan, result.StabilityDesignResults.StabilityModelType); Assert.AreEqual("Loc(DWP_1)_Sce(1)_Pro(DWP_1)", result.BaseFileName); // Calculation Result Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults.DesignResults[0].CalculationResult)); Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults.DesignResults[1].CalculationResult)); Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults.DesignResults[2].CalculationResult)); } [Test, Category("Slow")] public void TestRunMacroStabilityTutorialDesignBishopUpliftVan_BishopLowest() { // Based on ".data\DamEngineTestProjects\DAM Tutorial Design\DAM Tutorial Design.damx" // with Dam Classic rev.1059 // Select 5th location (DWP_13) // with Dam Classic rev.833 const string calcDir = "TestStabInwardsBishopUpliftVan_BishopLowest"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } const string fileName = @"TestFiles\MacroStabilityTutorialDesignInputFile13.xml"; string inputString = File.ReadAllText(fileName); inputString = ChangeInputModel(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, "MapForSoilgeometries2D", @"TestFiles\DAM Tutorial Design.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DAM Tutorial Design0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); // Bishop var result = output.Results.CalculationResults.DesignResults[0].StabilityDesignResults; Assert.AreEqual(0.452, result.SafetyFactor, tolerance); Assert.IsNotNull(result.UpliftSituation); Assert.IsTrue(result.UpliftSituation.IsUplift); Assert.AreEqual(DesignResultStabilityDesignResultsStabilityModelType.Bishop, result.StabilityModelType); // Uplift Van result = output.Results.CalculationResults.DesignResults[1].StabilityDesignResults; Assert.AreEqual(0.547, result.SafetyFactor, tolerance); Assert.IsNotNull(result.UpliftSituation); Assert.AreEqual(DesignResultStabilityDesignResultsStabilityModelType.UpliftVan, result.StabilityModelType); // Worst of Bishop and Uplift Van result = output.Results.CalculationResults.DesignResults[2].StabilityDesignResults; Assert.AreEqual(0.452, result.SafetyFactor, tolerance); Assert.IsNotNull(result.UpliftSituation); Assert.AreEqual(DesignResultStabilityDesignResultsStabilityModelType.BishopUpliftVan, result.StabilityModelType); // Calculation Result Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults.DesignResults[0].CalculationResult)); Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults.DesignResults[1].CalculationResult)); Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults.DesignResults[2].CalculationResult)); } [Test, Category("Slow")] public void TestRunMacroStabilityTutorialDesignBishopUpliftVan_NoUplift() { // Based on ".data\DamEngineTestProjects\DAM Tutorial Design\DAM Tutorial Design.damx" // with Dam Classic rev.1059 // Select 10th location (DWP_18) // with Dam Classic rev.833 const string calcDir = "TestStabInwardsBishopUpliftVan_NoUplift"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } const string fileName = @"TestFiles\MacroStabilityTutorialDesignInputFile18.xml"; string inputString = File.ReadAllText(fileName); inputString = ChangeInputModel(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, "MapForSoilgeometries2D", @"TestFiles\DAM Tutorial Design.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DAM Tutorial Design0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); // Bishop var result = output.Results.CalculationResults.DesignResults[0].StabilityDesignResults; Assert.IsTrue(result.SafetyFactorSpecified); Assert.AreEqual(1.458, result.SafetyFactor, tolerance); Assert.IsNotNull(result.UpliftSituation); Assert.IsFalse(result.UpliftSituation.IsUplift); Assert.AreEqual(DesignResultStabilityDesignResultsStabilityModelType.Bishop, result.StabilityModelType); // Uplift Van result = output.Results.CalculationResults.DesignResults[1].StabilityDesignResults; Assert.IsFalse(result.SafetyFactorSpecified); Assert.IsNotNull(result.UpliftSituation); Assert.AreEqual(DesignResultStabilityDesignResultsStabilityModelType.UpliftVan, result.StabilityModelType); // Worst of Bishop and Uplift Van result = output.Results.CalculationResults.DesignResults[2].StabilityDesignResults; Assert.IsTrue(result.SafetyFactorSpecified); Assert.AreEqual(1.458, result.SafetyFactor, tolerance); Assert.IsNotNull(result.UpliftSituation); Assert.AreEqual(DesignResultStabilityDesignResultsStabilityModelType.BishopUpliftVan, result.StabilityModelType); // Calculation Result Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults.DesignResults[0].CalculationResult)); Assert.AreEqual(CalculationResult.NoRun, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults.DesignResults[1].CalculationResult)); Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults.DesignResults[2].CalculationResult)); } [Test, Category("Slow")] public void TestRunMacroStabilityDeltaDijkZoneAreasBishopWith1D() { // Expected results are determined by running dam\dam clients\DamUI\trunk\data\DamEngineTestProjects\DeltaDijk_zonering_BI\DeltaDijk normal.damx // with Dam Classic rev.1059 // This tests both zone areas and use of 1D profiles // Select first location (6-4-1-A-1-F) // Analysis type "No adaption" // Calculation options: Stability Inside - Bishop const string calcDir = "TestStabInwardsZoneBishop"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } Directory.CreateDirectory(calcDir); const string fileName = @"TestFiles\DeltaDijkZoneringInwards.xml"; string inputString = File.ReadAllText(fileName); 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, "MapForSoilgeometries2D", @"TestFiles\DeltaDijk normal.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DeltaDijk normal0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); // one location is calculated with 3 1D profiles Assert.AreEqual(3, output.Results.CalculationResults.DesignResults.Length); Assert.AreEqual("6-4-1-A-1-F", output.Results.CalculationResults.DesignResults[0].LocationName); Assert.AreEqual("6-4-1-A-1-F_1_s", output.Results.CalculationResults.DesignResults[0].ProfileName); Assert.AreEqual("6-4-1-A-1-F", output.Results.CalculationResults.DesignResults[1].LocationName); Assert.AreEqual("6-4-1-A-1-F_2_s", output.Results.CalculationResults.DesignResults[1].ProfileName); Assert.AreEqual("6-4-1-A-1-F", output.Results.CalculationResults.DesignResults[2].LocationName); Assert.AreEqual("6-4-1-A-1-F_3_s", output.Results.CalculationResults.DesignResults[2].ProfileName); var result = output.Results.CalculationResults.DesignResults[0]; // SafetyFactor=1.621 (lowest of zone 1 and 2) Assert.AreEqual(1.621, result.StabilityDesignResults.SafetyFactor, tolerance); // Zone1SafetyFactor=1.621 Assert.AreEqual(1.621, result.StabilityDesignResults.Zone1SafetyFactor, tolerance); // Zone1EntryPointX=26.653 Assert.AreEqual(26.653, result.StabilityDesignResults.Zone1EntryPointX, tolerance); // Zone1ExitPointX=32.807 Assert.AreEqual(32.807, result.StabilityDesignResults.Zone1ExitPointX, tolerance); // Zone2SafetyFactor=1.644 Assert.AreEqual(1.644, result.StabilityDesignResults.Zone2SafetyFactor, tolerance); // Zone2EntryPointX=27.196 Assert.AreEqual(27.196, result.StabilityDesignResults.Zone2EntryPointX, tolerance); // Zone2ExitPointX=32.783 Assert.AreEqual(32.783, result.StabilityDesignResults.Zone2ExitPointX, tolerance); // skip testing some of the results like uplift etc. // Calculation Result Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); // test safety factor for other profiles result = output.Results.CalculationResults.DesignResults[1]; // SafetyFactor=1.620 Assert.AreEqual(1.620, result.StabilityDesignResults.SafetyFactor, tolerance); result = output.Results.CalculationResults.DesignResults[2]; // SafetyFactor=1.621 Assert.AreEqual(1.621, result.StabilityDesignResults.SafetyFactor, tolerance); } [Test, Category("Slow")] public void TestRunMacroStabilityDeltaDijkZoneAreasBishopWith1DZone2() { // Expected results are determined by running dam\dam clients\DamUI\trunk\data\DamEngineTestProjects\DeltaDijk_zonering_BI\DeltaDijk normal.damx // with Dam Classic rev.1059 // Select last location (6-4-5-A-1-B) // Analysis type "No adaption" // Calculation options: Stability Inside - Bishop // // In this test the location is calculated with 2 profiles. // For one case safety factor of zone 1 is lower than for zone 2 // For the other one safety factor of zone 1 is higher than for zone 2 // But the overall safety factor should always be the one of zone 1 const string calcDir = "TestStabInwardsZone2Bishop"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } Directory.CreateDirectory(calcDir); const string fileName = @"TestFiles\DeltaDijkZoneringInwardsZone2.xml"; string inputString = File.ReadAllText(fileName); 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, "MapForSoilgeometries2D", @"TestFiles\DeltaDijk normal.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DeltaDijk normal0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); Assert.AreEqual(2, output.Results.CalculationResults.DesignResults.Length); Assert.AreEqual("6-4-5-A-1-B", output.Results.CalculationResults.DesignResults[0].LocationName); Assert.AreEqual("6-4-5-A-1-B_1_s", output.Results.CalculationResults.DesignResults[0].ProfileName); Assert.AreEqual("6-4-5-A-1-B", output.Results.CalculationResults.DesignResults[1].LocationName); Assert.AreEqual("6-4-5-A-1-B_2_s", output.Results.CalculationResults.DesignResults[1].ProfileName); var result = output.Results.CalculationResults.DesignResults[0]; // Zone1SafetyFactor=2.138 Assert.AreEqual(2.138, result.StabilityDesignResults.Zone1SafetyFactor, tolerance); // Zone2SafetyFactor=2.155 Assert.AreEqual(2.155, result.StabilityDesignResults.Zone2SafetyFactor, tolerance); // SafetyFactor=2.138 (same as zone 1) Assert.AreEqual(2.138, result.StabilityDesignResults.SafetyFactor, tolerance); result = output.Results.CalculationResults.DesignResults[1]; // Zone1SafetyFactor=2.009 Assert.AreEqual(2.009, result.StabilityDesignResults.Zone1SafetyFactor, tolerance); // Zone2SafetyFactor=1.974 Assert.AreEqual(1.974, result.StabilityDesignResults.Zone2SafetyFactor, tolerance); // SafetyFactor=2.009 (same as zone 1) Assert.AreEqual(2.009, result.StabilityDesignResults.SafetyFactor, tolerance); // Calculation Result Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); } [Test, Category("Slow")] public void TestRunMacroStabilityDeltaDijkZoneAreasUpliftVanWith1D() { // Expected results are determined by running dam\dam clients\DamUI\trunk\data\DamEngineTestProjects\DeltaDijk_zonering_BI // with Dam Classic rev.1059 // Select first location (6-4-1-A-1-F) // Analysis type "No adaption" // Calculation options: Stability Inside - Bishop // This tests both zone areas and use of 1D profiles const string calcDir = "TestStabInwardsZoneUpliftVan"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } Directory.CreateDirectory(calcDir); const string fileName = @"TestFiles\DeltaDijkZoneringInwards.xml"; string inputString = File.ReadAllText(fileName); inputString = ChangeInputModel(inputString, InputStabilityModelType.UpliftVan); 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, "MapForSoilgeometries2D", @"TestFiles\DeltaDijk normal.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DeltaDijk normal0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); // one location is calculated with 3 1D profiles Assert.AreEqual(3, output.Results.CalculationResults.DesignResults.Length); Assert.AreEqual("6-4-1-A-1-F", output.Results.CalculationResults.DesignResults[0].LocationName); Assert.AreEqual("6-4-1-A-1-F_1_s", output.Results.CalculationResults.DesignResults[0].ProfileName); Assert.AreEqual("6-4-1-A-1-F", output.Results.CalculationResults.DesignResults[1].LocationName); Assert.AreEqual("6-4-1-A-1-F_2_s", output.Results.CalculationResults.DesignResults[1].ProfileName); Assert.AreEqual("6-4-1-A-1-F", output.Results.CalculationResults.DesignResults[2].LocationName); Assert.AreEqual("6-4-1-A-1-F_3_s", output.Results.CalculationResults.DesignResults[2].ProfileName); var result = output.Results.CalculationResults.DesignResults[0]; // SafetyFactor=0.983 (lowest of zone 1 and 2) Assert.AreEqual(0.983, result.StabilityDesignResults.SafetyFactor, tolerance); // Zone1SafetyFactor=0.983 Assert.AreEqual(0.983, result.StabilityDesignResults.Zone1SafetyFactor, tolerance); // Zone1EntryPointX=29.779 Assert.AreEqual(29.779, result.StabilityDesignResults.Zone1EntryPointX, tolerance); // Zone1ExitPointX72.599= Assert.AreEqual(72.599, result.StabilityDesignResults.Zone1ExitPointX, tolerance); // Zone2SafetyFactor=2.221 Assert.AreEqual(2.221, result.StabilityDesignResults.Zone2SafetyFactor, tolerance); // Zone2EntryPointX=27.1 Assert.AreEqual(27.1, result.StabilityDesignResults.Zone2EntryPointX, tolerance); // Zone2ExitPointX=72.524 Assert.AreEqual(72.524, result.StabilityDesignResults.Zone2ExitPointX, tolerance); // skip testing some of the results like uplift etc. // Calculation Result Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); // test safety factor for other profiles result = output.Results.CalculationResults.DesignResults[1]; // SafetyFactor=1.811 Assert.AreEqual(1.811, result.StabilityDesignResults.SafetyFactor, tolerance); result = output.Results.CalculationResults.DesignResults[2]; // SafetyFactor=1.591 Assert.AreEqual(1.591, result.StabilityDesignResults.SafetyFactor, tolerance); } [Test, Category("Slow")] public void TestRunMacroStabilityInvoer10ForbiddenZoneBishop() { // Expected results are determined by running dam\dam clients\DamUI\trunk\data\DamEngineTestProjects\Invoer10\ZoneType.damx // with Dam Classic rev.1059 // Select locations DWP_10_2 and DWP_10_6 // Analysis type "No adaption" // Calculation options: Stability Inside - Bishop // This tests two locations with same profile // But first location with Zone Areas and second location with Forbidden Zone const string calcDir = "TestStabInwardsForbiddenZoneBishop"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } Directory.CreateDirectory(calcDir); const string fileName = @"TestFiles\Invoer10.xml"; string inputString = File.ReadAllText(fileName); 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, "MapForSoilgeometries2D", @"TestFiles\ZoneType.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\ZoneType0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); Assert.AreEqual(2, output.Results.CalculationResults.DesignResults.Length); var result = output.Results.CalculationResults.DesignResults[0]; // SafetyFactor=1.972 (Zone Areas) Assert.AreEqual(1.972, result.StabilityDesignResults.SafetyFactor, tolerance); Assert.AreEqual("DWP_10_2", result.LocationName); Assert.AreEqual("DWP_10.sti", result.ProfileName); Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); result = output.Results.CalculationResults.DesignResults[1]; // SafetyFactor=2.034 (Forbidden Zone) Assert.AreEqual(2.034, result.StabilityDesignResults.SafetyFactor, tolerance); Assert.AreEqual("DWP_10_6", result.LocationName); Assert.AreEqual("DWP_10.sti", result.ProfileName); Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); } [Test, Category("Slow")] public void TestRunMacroStabilityWithErrorUpliftVan() { // Expected results are determined by running .\data\DamEngineTestProjects\DeltaDijk_zonering_BI\DeltaDijk normal.damx // with Dam Classic rev.1059 // Select 5th and 6th location (6-4-3-A-1-C and 6-4-3-A-1-D) // This project has 2 locations with each 2 profiles // In one the combinations location-profile (1st location, 2nd profile) DGeoStability stops during the calculation. // Then the kernel tries to read the safety factor, but fails because the dumpfile is not complete. // In Release+Classic this returned a result Unexpected Error but the calculation continued with the next combination. const string calcDir = "TestStabInwardsWithErrorUpliftVan"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } Directory.CreateDirectory(calcDir); const string fileName = @"TestFiles\ErrorInDGeoStabilityCalculation.xml"; string inputString = File.ReadAllText(fileName); inputString = ChangeInputModel(inputString, InputStabilityModelType.UpliftVan); 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, "MapForSoilgeometries2D", @"TestFiles\DeltaDijk normal.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DeltaDijk normal0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); Assert.AreEqual(4, output.Results.CalculationResults.DesignResults.Length); var result = output.Results.CalculationResults.DesignResults[0]; Assert.AreEqual("6-4-3-A-1-C", result.LocationName); Assert.AreEqual("6-4-3-A-1-C_1_s", result.ProfileName); // Calculation Result Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); // SafetyFactor=2.413 Assert.AreEqual(2.413, result.StabilityDesignResults.SafetyFactor, tolerance); result = output.Results.CalculationResults.DesignResults[1]; Assert.AreEqual("6-4-3-A-1-C", result.LocationName); Assert.AreEqual("6-4-3-A-1-C_2_s", result.ProfileName); // Calculation Result Assert.AreEqual(CalculationResult.UnexpectedError, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); // SafetyFactor not specified Assert.IsFalse(result.StabilityDesignResults.SafetyFactorSpecified); result = output.Results.CalculationResults.DesignResults[2]; Assert.AreEqual("6-4-3-B-1-D", result.LocationName); Assert.AreEqual("6-4-3-B-1-D_1_s", result.ProfileName); // Calculation Result Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); // SafetyFactor=2.471 Assert.AreEqual(2.471, result.StabilityDesignResults.SafetyFactor, tolerance); result = output.Results.CalculationResults.DesignResults[3]; Assert.AreEqual("6-4-3-B-1-D", result.LocationName); Assert.AreEqual("6-4-3-B-1-D_2_s", result.ProfileName); // Calculation Result Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); // SafetyFactor=3.157 Assert.AreEqual(3.157, result.StabilityDesignResults.SafetyFactor, tolerance); } [Test, Category("Slow")] public void TestRunMacroStabilityWithErrorBishopUpliftVan() { // Expected results are determined by running .\data\DamEngineTestProjects\DeltaDijk_zonering_BI\DeltaDijk normal.damx // with Dam Classic rev.1059 // Select 5th and 6th location (6-4-3-A-1-C and 6-4-3-A-1-D) // This project has 2 locations with each 2 profiles // In one the combinations location-profile (1st location, 2nd profile) DGeoStability stops during the calculation. // Then the kernel tries to read the safety factor, but fails because the dumpfile is not complete. // In Release+Classic this returned a result Unexpected Error but the calculation continued with the next combination. const string calcDir = "TestStabInwardsWithErrorBishopUpliftVan"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } Directory.CreateDirectory(calcDir); const string fileName = @"TestFiles\ErrorInDGeoStabilityCalculation.xml"; string inputString = File.ReadAllText(fileName); inputString = ChangeInputModel(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, "MapForSoilgeometries2D", @"TestFiles\DeltaDijk normal.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DeltaDijk normal0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); Assert.AreEqual(12, output.Results.CalculationResults.DesignResults.Length); var result = output.Results.CalculationResults.DesignResults[3]; Assert.AreEqual("6-4-3-A-1-C", result.LocationName); Assert.AreEqual("6-4-3-A-1-C_2_s", result.ProfileName); // Bishop Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); // SafetyFactor=2.219 Assert.AreEqual(2.219, result.StabilityDesignResults.SafetyFactor, tolerance); Assert.AreEqual(DesignResultStabilityDesignResultsStabilityModelType.Bishop, result.StabilityDesignResults.StabilityModelType); result = output.Results.CalculationResults.DesignResults[4]; Assert.AreEqual("6-4-3-A-1-C", result.LocationName); Assert.AreEqual("6-4-3-A-1-C_2_s", result.ProfileName); // Uplift Van Assert.AreEqual(CalculationResult.UnexpectedError, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); // SafetyFactor not specified Assert.IsFalse(result.StabilityDesignResults.SafetyFactorSpecified); Assert.AreEqual(DesignResultStabilityDesignResultsStabilityModelType.UpliftVan, result.StabilityDesignResults.StabilityModelType); result = output.Results.CalculationResults.DesignResults[5]; Assert.AreEqual("6-4-3-A-1-C", result.LocationName); Assert.AreEqual("6-4-3-A-1-C_2_s", result.ProfileName); // Bishop/Uplift Van Assert.AreEqual(CalculationResult.UnexpectedError, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); // SafetyFactor not specified Assert.IsFalse(result.StabilityDesignResults.SafetyFactorSpecified); Assert.AreEqual(DesignResultStabilityDesignResultsStabilityModelType.BishopUpliftVan, result.StabilityDesignResults.StabilityModelType); } [Test, Category("Slow")] public void TestRunFailedExpectCalculationMessage() { // Inputfile was created with .\data\DamEngineTestProjects\Invoer2\DAM Tutorial Design\DAM Tutorial Design.damx // Select dwp 13 // Expected: RunFailed const string calcDir = "TestRunFailedExpectCalculationMessage"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } Directory.CreateDirectory(calcDir); const string fileName = @"TestFiles\MacroStabilityRunFailedExpectCalculationMessage.xml"; string inputString = File.ReadAllText(fileName); 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, "MapForSoilgeometries2D", @"TestFiles\DAM Tutorial Design.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DAM Tutorial Design0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); Assert.AreEqual(1, output.Results.CalculationResults.DesignResults.Length); var result = output.Results.CalculationResults.DesignResults[0]; Assert.AreEqual(CalculationResult.RunFailed, ConversionHelper.ConvertToCalculationResult(result.CalculationResult)); Assert.AreEqual("The new shoulder height with topslope exceeds the allowed maximum height.", output.Results.CalculationResults.DesignResults[0].StabilityDesignResults.ResultMessage); Assert.AreEqual("Location 'DWP_13', subsoil scenario 'DWP_13.sti', design scenario '1': " + "The calculation failed with error message " + "'The design was not successful. " + "The new shoulder height with topslope exceeds the allowed maximum height.'", output.Results.CalculationMessages[0].Message1); } [Test, Category("Slow")] // Expected results are determined by running .\DamUI\trunk\data\DamEngineTestProjects\DAM Tutorial Design\DAM Tutorial Design.damx // with Dam Classic rev.1059 // Select 1st location (DWP_1) // Set designscenario Safetyfactor Inwards to 1.4 // Design strategy: OptimizedSlopeAndShoulderAdaption // Set NewMinDistanceDikeToeStartDitch = 3.0, UseNewMinDistanceDikeToeStartDitch = true (to force value to be written to XML) // // Parameters: CalcDir - StabilityModel - DesignStrategy - CalculationResult - FoS - EntryPointX - ExitPointX - DikeLength - ShoulderHeight - Iterations - ResultMessage [TestCase("TestStabInwardsBishopDesignSequential", "Bishop", "SlopeAdaptionBeforeShoulderAdaption", CalculationResult.Succeeded, 1.444, 39.081, 67.577, 45.387, 2.799, 5, "")] [TestCase("TestStabInwardsBishopDesignOptimized", "Bishop", "OptimizedSlopeAndShoulderAdaption", CalculationResult.Succeeded, 1.412, 50.236, 67.077, 43.760, 3.889, 4, "")] [TestCase("TestStabInwardsUpliftVanDesignSequential", "UpliftVan", "SlopeAdaptionBeforeShoulderAdaption", CalculationResult.Succeeded, 1.414, 39.243, 73.587, 50.285, 3.465, 7, "")] [TestCase("TestStabInwardsUpliftVanDesignOptimized", "UpliftVan", "OptimizedSlopeAndShoulderAdaption", CalculationResult.RunFailed, 1.156, 39.514, 66.926, 36.150, 0.0, 4, "The new shoulder height with topslope exceeds the allowed maximum height.")] public void CanPerformStabilityInwardsDesignTutorialDesignOptimizedSlopeAndShoulderAdaption_OneLocation( string calcDir, string stabilityModel, string designStrategy, CalculationResult calculationResult, double expectedSafetyFactor, double expectedZone1EntryPointX, double expectedZone1ExitPointX, double expectedDikeLength, double expectedShoulderHeight, int expectedNumberOfIterations, string expectedResultMessage) { const string fileName = @"TestFiles\MacroStabilityTutorialDesignInputFile1LocationWithAdaption.xml"; string inputString = File.ReadAllText(fileName); 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, "MapForSoilgeometries2D", @"TestFiles\DAM Tutorial Design.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DAM Tutorial Design0.soilmaterials.mdb"); inputString = XmlAdapter.ChangeValueInXml(inputString, "StabilityModelType", stabilityModel); inputString = XmlAdapter.ChangeValueInXml(inputString, "StabilityDesignMethod", designStrategy); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); DamProjectData actualDamProjectData = FillDamFromXmlOutput.CreateDamProjectData(null, output); Assert.AreEqual(calculationResult, ConversionHelper.ConvertToCalculationResult( output.Results.CalculationResults.DesignResults[0].CalculationResult)); var stabilityDesignResults = output.Results.CalculationResults.DesignResults[0].StabilityDesignResults; Assert.AreEqual(expectedSafetyFactor, stabilityDesignResults.SafetyFactor, tolerance); Assert.AreEqual(expectedSafetyFactor, stabilityDesignResults.Zone1SafetyFactor, tolerance); Assert.AreEqual(expectedZone1EntryPointX, stabilityDesignResults.Zone1EntryPointX, tolerance); Assert.AreEqual(expectedZone1ExitPointX, stabilityDesignResults.Zone1ExitPointX, tolerance); Assert.AreEqual(expectedNumberOfIterations, stabilityDesignResults.NumberOfIterations); Assert.AreEqual(expectedResultMessage, stabilityDesignResults.ResultMessage); SurfaceLine2 redesignedSurfaceLine = actualDamProjectData.DesignCalculations[0].StabilityDesignResults.RedesignedSurfaceLine; if (redesignedSurfaceLine != null) { Assert.AreEqual(expectedDikeLength, redesignedSurfaceLine.GetDikeLength(), tolerance); GeometryPoint pointShoulderBaseInside = redesignedSurfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.ShoulderTopInside); if (pointShoulderBaseInside != null) { Assert.AreEqual(expectedShoulderHeight, pointShoulderBaseInside.Z, tolerance); } } } private string ChangeInputModel(string input, InputStabilityModelType modelType) { string pattern = "StabilityModelType=\"Bishop\""; string replacement = pattern; switch (modelType) { case InputStabilityModelType.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; } } }