Index: dam engine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStabilityOutwards/DamMacroStabilityOutwardsKernelWrapper.cs =================================================================== diff -u --- dam engine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStabilityOutwards/DamMacroStabilityOutwardsKernelWrapper.cs (revision 0) +++ dam engine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStabilityOutwards/DamMacroStabilityOutwardsKernelWrapper.cs (revision 781) @@ -0,0 +1,256 @@ +// Copyright (C) Stichting Deltares 2017. 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; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Xml.Linq; +using Deltares.DamEngine.Calculators.KernelWrappers.Common; +using Deltares.DamEngine.Calculators.KernelWrappers.DamMacroStability; +using Deltares.DamEngine.Calculators.KernelWrappers.Interfaces; +using Deltares.DamEngine.Calculators.Properties; +using Deltares.DamEngine.Data.Design; +using Deltares.DamEngine.Data.General; +using Deltares.DamEngine.Data.General.Results; +using Deltares.DamEngine.Data.Geotechnics; +using Deltares.DamEngine.Data.Standard.Calculation; +using Deltares.DamEngine.Data.Standard.Logging; +using Deltares.DamMacroStability.Calculator; + +namespace Deltares.DamEngine.Calculators.KernelWrappers.DamMacroStabilityOutwards +{ + public class DamMacroStabilityOutwardsKernelWrapper : IKernelWrapper + { + private const string DamMacroStabilityFolder = @".\KernelWrappers\DamMacroStability"; + private const string DGeoStabilityExe = "DGeoStability.exe"; + + /// + /// Prepares the specified dam kernel input. + /// + /// The dam kernel input. + /// The kernel data input. + /// The kernel data output + /// + /// Result of the prepare + /// + public PrepareResult Prepare(DamKernelInput damKernelInput, out IKernelDataInput kernelDataInput, out IKernelDataOutput kernelDataOutput) + { + var damMacroStabilityOutput = new DamMacroStabilityOutput() + { + CalculationResult = CalculationResult.NoRun + }; + kernelDataOutput = damMacroStabilityOutput; + if (damKernelInput.SubSoilScenario.SegmentFailureMechanismType == FailureMechanismSystemType.StabilityOutside) + { + //damKernelInput.Location.StabilityOptions. + // ToDo zant set stiFileName + // string stabilityDirectory = GetStabilityCalculationDirectory(); + // string filenameExtension = GetFilenameExtension(); + // string fileName = calculationName + filenameExtension; + // var stabilityProjectFilename = Path.Combine(stabilityDirectory, fileName); + + const string testFolder = @"..\..\Deltares.DamEngine.Calculators.Tests\Files\MacroStability"; + // Relative paths in ini file do not work yet in DGeoStability 16.2. This is fixed in 18.1. + var absoluteFolder = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), testFolder)); + var stiFileName = Path.Combine(absoluteFolder, "test.sti"); + + + var damMacroStabilityInput = new DamMacroStabilityInput() + { + DGeoStabilityExePath = Path.Combine(DamMacroStabilityFolder, DGeoStabilityExe), + DGeoStabilityInputFileName = stiFileName + }; + kernelDataInput = damMacroStabilityInput; + + // Write xml file + XDocument xmlDocument = CreateMstabDamXmlDocument(damKernelInput, damMacroStabilityInput); + + // Use xml file to create sti file + CreateStiFile(xmlDocument); + + return PrepareResult.Successful; + } + kernelDataInput = null; + return PrepareResult.NotRelevant; + } + + /// + /// Validates the specified kernel data input. + /// + /// The kernel data input. + /// The kernel data output. + /// The return messages. + /// + /// Number of errors that prevent a calculation + /// + public int Validate(IKernelDataInput kernelDataInput, IKernelDataOutput kernelDataOutput, out List messages) + { + var calculator = StabilityCalculator(kernelDataInput); + //ToDo zant calculator has no Validate. +// List kernelMessages = calculator.Validate(); + messages = new List(); +// foreach (string stringMessage in kernelMessages) +// { +// messages.Add(new LogMessage() { Message = stringMessage, MessageType = LogMessageType.Error }); +// } + return messages.Count; + } + + /// + /// Executes the kernel. + /// + /// The kernel data input. + /// The kernel data output. + /// The return messages. + public void Execute(IKernelDataInput kernelDataInput, IKernelDataOutput kernelDataOutput, out List messages) + { + DamMacroStabilityOutput damMacroStabilityOutput = (DamMacroStabilityOutput) kernelDataOutput; + messages = new List(); + + // start calculation + var calculator = StabilityCalculator(kernelDataInput); + calculator.Calculate(); + + // get results + var results = calculator.GetResults(); + if (results.Count > 0) + { + var zone1 = new DamMacroStabilityOutput.ResultsSingleZone(); + zone1.SafetyFactor = results[0].Zone1.SafetyFactor; + zone1.CircleSurfacePointLeftXCoordinate = results[0].Zone1.CircleSurfacePointLeftXCoordinate; + zone1.CircleSurfacePointRightXCoordinate = results[0].Zone1.CircleSurfacePointRightXCoordinate; + zone1.EntryPointXCoordinate = results[0].Zone1.EntryPointXCoordinate; + zone1.ExitPointXCoordinate = results[0].Zone1.ExitPointXCoordinate; + damMacroStabilityOutput.Zone1Results = zone1; + if (results[0].Zone2 != null) + { + var zone2 = new DamMacroStabilityOutput.ResultsSingleZone(); + zone2.SafetyFactor = results[0].Zone1.SafetyFactor; + zone2.CircleSurfacePointLeftXCoordinate = results[0].Zone1.CircleSurfacePointLeftXCoordinate; + zone2.CircleSurfacePointRightXCoordinate = results[0].Zone1.CircleSurfacePointRightXCoordinate; + zone2.EntryPointXCoordinate = results[0].Zone1.EntryPointXCoordinate; + zone2.ExitPointXCoordinate = results[0].Zone1.ExitPointXCoordinate; + damMacroStabilityOutput.Zone2Results = zone2; + } + } + } + + internal XDocument CreateMstabDamXmlDocument(DamKernelInput damKernelInput, DamMacroStabilityInput kernelDataInput) + { + const string testFolder = @"..\..\Deltares.DamEngine.Calculators.Tests\Files\MacroStability"; + // var stabilityProjectFilename = Path.Combine(testFolder, "test.sti"); + // var soilDbName = + var geometryFileName = Path.Combine(testFolder, "DWP_1.sti"); + + var stabilityProjectFilename = kernelDataInput.DGeoStabilityInputFileName; + var scenario = damKernelInput.DesignScenario; + var subSoilScenario = damKernelInput.SubSoilScenario; + var riverLevel = scenario.RiverLevel; + var surfaceLine = scenario.Location.SurfaceLine; + var trafficLoad = scenario.Location.StabilityOptions.TrafficLoad; + var requiredSafetyFactor = scenario.RequiredSafetyFactorStabilityInnerSlope; + if (requiredSafetyFactor == null) + { + throw new MacroStabilityException("Required safety factor must be specified"); + } + List errorMessages; + + // ToDo zant + scenario.Location.StabilityOptions.MapForSoilGeometries2D = testFolder; + scenario.Location.SoildatabaseName = Path.Combine(testFolder, "DAM Tutorial Design0.soilmaterials.mdb"); + scenario.Location.DikeEmbankmentMaterial = "dijksmateriaal_klei"; + + XDocument mstabXml = MStabXmlDoc.CreateMStabXmlDoc(stabilityProjectFilename, scenario, subSoilScenario, + riverLevel, null, surfaceLine, trafficLoad, requiredSafetyFactor.Value, out errorMessages); + mstabXml.Save(stabilityProjectFilename + ".xml"); + + return mstabXml; + } + + internal void CreateStiFile(XDocument xmlDocument) + { + DGSMStabDAMInterface mstabDamDll = new DGSMStabDAMInterface(); + var result = mstabDamDll.CreateProjectFile(xmlDocument.ToString()); + if (result > 0) + { + string errorMessage = mstabDamDll.ErrorMessage(); + throw new MacroStabilityException(errorMessage); + } + } + + internal static StabilityCalculator StabilityCalculator(IKernelDataInput kernelDataInput) + { + DamMacroStabilityInput damMacroStabilityInput = kernelDataInput as DamMacroStabilityInput; + if (damMacroStabilityInput == null) + { + throw new NoNullAllowedException(Resources.DamMacroStabilityKernelWrapper_StabilityCalculator_NoInputObjectDefinedForMacroStability); + } + var calculator = new StabilityCalculator + { + ProjectName = damMacroStabilityInput.DGeoStabilityInputFileName, + DGeoStabilityExePath = damMacroStabilityInput.DGeoStabilityExePath + }; + return calculator; + } + + /// + /// Fills the design results with the kernel output. + /// + /// The dam kernel input. + /// The kernel data output. + /// The result message. + /// The design result. + /// + public void PostProcess(DamKernelInput damKernelInput, IKernelDataOutput kernelDataOutput, string resultMessage, out DesignResult designResult) + { + DamMacroStabilityOutput damMacroStabilityOutput = kernelDataOutput as DamMacroStabilityOutput; + if (damMacroStabilityOutput == null) + { + throw new NoNullAllowedException(Resources.DamMacroStabilityKernelWrapper_PostProcess_NoOutputObjectDefinedForSellmeijer4Forces); + } + + // TODO: this is just fake data + string id = "id"; + string soilProfile2DName = "soilProfile2DName"; + var d = new DamFailureMechanismeCalculationSpecification(); + var s = new DesignScenario(); + s.Location = new Location(); + var p = new SoilProfile1D(); + designResult = new DesignResult(d, s, p, soilProfile2DName, AnalysisType.NoAdaption); + designResult.CalculationResult = damMacroStabilityOutput.CalculationResult; + var stabilityDesignResults = new StabilityDesignResults(); + stabilityDesignResults.Zone1SafetyFactor = damMacroStabilityOutput.Zone1Results.SafetyFactor; + stabilityDesignResults.LocalZone1EntryPointX = damMacroStabilityOutput.Zone1Results.EntryPointXCoordinate; + stabilityDesignResults.LocalZone1ExitPointX = damMacroStabilityOutput.Zone1Results.ExitPointXCoordinate; + stabilityDesignResults.SafetyFactor = stabilityDesignResults.Zone1SafetyFactor; + if (damMacroStabilityOutput.Zone2Results != null) + { + var zone2 = (DamMacroStabilityOutput.ResultsSingleZone) damMacroStabilityOutput.Zone2Results; + stabilityDesignResults.Zone2SafetyFactor = zone2.SafetyFactor; + stabilityDesignResults.LocalZone2EntryPointX = zone2.EntryPointXCoordinate; + stabilityDesignResults.LocalZone2ExitPointX = zone2.ExitPointXCoordinate; + stabilityDesignResults.SafetyFactor = Math.Min(damMacroStabilityOutput.Zone1Results.SafetyFactor, zone2.SafetyFactor); + } + designResult.StabilityDesignResults = stabilityDesignResults; + } + } +} Index: dam engine/trunk/src/Deltares.DamEngine.Calculators/Deltares.DamEngine.Calculators.csproj =================================================================== diff -u -r778 -r781 --- dam engine/trunk/src/Deltares.DamEngine.Calculators/Deltares.DamEngine.Calculators.csproj (.../Deltares.DamEngine.Calculators.csproj) (revision 778) +++ dam engine/trunk/src/Deltares.DamEngine.Calculators/Deltares.DamEngine.Calculators.csproj (.../Deltares.DamEngine.Calculators.csproj) (revision 781) @@ -93,6 +93,7 @@ + Index: dam engine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/DamMacroStability/DamMacroStabilityKernelWrapperTests.cs =================================================================== diff -u -r715 -r781 --- dam engine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/DamMacroStability/DamMacroStabilityKernelWrapperTests.cs (.../DamMacroStabilityKernelWrapperTests.cs) (revision 715) +++ dam engine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/DamMacroStability/DamMacroStabilityKernelWrapperTests.cs (.../DamMacroStabilityKernelWrapperTests.cs) (revision 781) @@ -62,8 +62,8 @@ // kernelWrapper.Execute(damStabilityInput, kernelOutput, out messages); // DamMacroStabilityOutput damMacroStabilityOutput = (DamMacroStabilityOutput) kernelOutput; // Assert.AreEqual(0, messages.Count); -// Assert.AreEqual(1.282, damMacroStabilityOutput.Zone1.SafetyFactor, diff); -// Assert.IsNull(damMacroStabilityOutput.Zone2); +// Assert.AreEqual(1.282, damMacroStabilityOutput.Zone1Results.SafetyFactor, diff); +// Assert.IsNull(damMacroStabilityOutput.Zone2Results); // // // Fill the design results // DesignResult result; @@ -173,12 +173,12 @@ zone1.SafetyFactor = 1.1; zone1.EntryPointXCoordinate = 1.2; zone1.ExitPointXCoordinate = 1.3; - output.Zone1 = zone1; + output.Zone1Results = zone1; var zone2 = new DamMacroStabilityOutput.ResultsSingleZone(); zone2.SafetyFactor = 0.9; zone2.EntryPointXCoordinate = 2.2; zone2.ExitPointXCoordinate = 2.3; - output.Zone2 = zone2; + output.Zone2Results = zone2; DesignResult result; kernelWrapper.PostProcess(null, output, "", out result); Index: dam engine/trunk/src/Deltares.DamEngine.Calculators/Dikes Design/DesignCalculator.cs =================================================================== diff -u -r715 -r781 --- dam engine/trunk/src/Deltares.DamEngine.Calculators/Dikes Design/DesignCalculator.cs (.../DesignCalculator.cs) (revision 715) +++ dam engine/trunk/src/Deltares.DamEngine.Calculators/Dikes Design/DesignCalculator.cs (.../DesignCalculator.cs) (revision 781) @@ -3,6 +3,7 @@ using System.Text; using Deltares.DamEngine.Calculators.KernelWrappers.Common; using Deltares.DamEngine.Calculators.KernelWrappers.DamMacroStability; +using Deltares.DamEngine.Calculators.KernelWrappers.DamMacroStabilityOutwards; using Deltares.DamEngine.Calculators.KernelWrappers.DamPipingBligh; using Deltares.DamEngine.Calculators.KernelWrappers.DamPipingSellmeijer4Forces; using Deltares.DamEngine.Calculators.KernelWrappers.Interfaces; @@ -97,9 +98,11 @@ IKernelWrapper kernelWrapper = null; switch (failureMechanismSystemType) { - case FailureMechanismSystemType.HorizontalBalance: - case FailureMechanismSystemType.StabilityOutside: + case FailureMechanismSystemType.HorizontalBalance: throw new NotImplementedException(Resources.DesignCalculatorKernelNotImplemented); + case FailureMechanismSystemType.StabilityOutside: + kernelWrapper = new DamMacroStabilityOutwardsKernelWrapper(); + break; case FailureMechanismSystemType.StabilityInside: kernelWrapper = new DamMacroStabilityKernelWrapper(); break; Index: dam engine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStability/DamMacroStabilityKernelWrapper.cs =================================================================== diff -u -r715 -r781 --- dam engine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStability/DamMacroStabilityKernelWrapper.cs (.../DamMacroStabilityKernelWrapper.cs) (revision 715) +++ dam engine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStability/DamMacroStabilityKernelWrapper.cs (.../DamMacroStabilityKernelWrapper.cs) (revision 781) @@ -110,7 +110,7 @@ zone1.CircleSurfacePointRightXCoordinate = results[0].Zone1.CircleSurfacePointRightXCoordinate; zone1.EntryPointXCoordinate = results[0].Zone1.EntryPointXCoordinate; zone1.ExitPointXCoordinate = results[0].Zone1.ExitPointXCoordinate; - damMacroStabilityOutput.Zone1 = zone1; + damMacroStabilityOutput.Zone1Results = zone1; if (results[0].Zone2 != null) { var zone2 = new DamMacroStabilityOutput.ResultsSingleZone(); @@ -119,7 +119,7 @@ zone2.CircleSurfacePointRightXCoordinate = results[0].Zone1.CircleSurfacePointRightXCoordinate; zone2.EntryPointXCoordinate = results[0].Zone1.EntryPointXCoordinate; zone2.ExitPointXCoordinate = results[0].Zone1.ExitPointXCoordinate; - damMacroStabilityOutput.Zone2 = zone2; + damMacroStabilityOutput.Zone2Results = zone2; } } } @@ -208,17 +208,17 @@ designResult = new DesignResult(d, s, p, soilProfile2DName, AnalysisType.NoAdaption); var stabilityDesignResults = new StabilityDesignResults(); - stabilityDesignResults.Zone1SafetyFactor = damPipingOutput.Zone1.SafetyFactor; - stabilityDesignResults.LocalZone1EntryPointX = damPipingOutput.Zone1.EntryPointXCoordinate; - stabilityDesignResults.LocalZone1ExitPointX = damPipingOutput.Zone1.ExitPointXCoordinate; + stabilityDesignResults.Zone1SafetyFactor = damPipingOutput.Zone1Results.SafetyFactor; + stabilityDesignResults.LocalZone1EntryPointX = damPipingOutput.Zone1Results.EntryPointXCoordinate; + stabilityDesignResults.LocalZone1ExitPointX = damPipingOutput.Zone1Results.ExitPointXCoordinate; stabilityDesignResults.SafetyFactor = stabilityDesignResults.Zone1SafetyFactor; - if (damPipingOutput.Zone2 != null) + if (damPipingOutput.Zone2Results != null) { - var zone2 = (DamMacroStabilityOutput.ResultsSingleZone) damPipingOutput.Zone2; + var zone2 = (DamMacroStabilityOutput.ResultsSingleZone) damPipingOutput.Zone2Results; stabilityDesignResults.Zone2SafetyFactor = zone2.SafetyFactor; stabilityDesignResults.LocalZone2EntryPointX = zone2.EntryPointXCoordinate; stabilityDesignResults.LocalZone2ExitPointX = zone2.ExitPointXCoordinate; - stabilityDesignResults.SafetyFactor = Math.Min(damPipingOutput.Zone1.SafetyFactor, zone2.SafetyFactor); + stabilityDesignResults.SafetyFactor = Math.Min(damPipingOutput.Zone1Results.SafetyFactor, zone2.SafetyFactor); } designResult.StabilityDesignResults = stabilityDesignResults; } Index: dam engine/trunk/src/Deltares.DamEngine.Calculators/General/Geometry2DTo1DConverter.cs =================================================================== diff -u -r769 -r781 --- dam engine/trunk/src/Deltares.DamEngine.Calculators/General/Geometry2DTo1DConverter.cs (.../Geometry2DTo1DConverter.cs) (revision 769) +++ dam engine/trunk/src/Deltares.DamEngine.Calculators/General/Geometry2DTo1DConverter.cs (.../Geometry2DTo1DConverter.cs) (revision 781) @@ -163,7 +163,7 @@ layer.Soil = SoilList.GetSoilByName(layer.SoilName); if (layer.Soil == null) { - throw new Geometry2DTo1DConverterException(String.Format("Soil material '{0}' belonging to layer '{1}' not available in soilmaterials", layer.SoilName, layer.Name)); + throw new Geometry2DTo1DConverterException(String.Format("Soil material '{0}' belonging to layer '{1}' not available in soillist", layer.SoilName, layer.Name)); } if (SoilList.AquiferDictionary.ContainsKey(layer.Soil)) { Index: dam engine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStability/DamMacroStabilityOutput.cs =================================================================== diff -u -r596 -r781 --- dam engine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStability/DamMacroStabilityOutput.cs (.../DamMacroStabilityOutput.cs) (revision 596) +++ dam engine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStability/DamMacroStabilityOutput.cs (.../DamMacroStabilityOutput.cs) (revision 781) @@ -1,9 +1,52 @@ -using Deltares.DamEngine.Calculators.KernelWrappers.Interfaces; +// Copyright (C) Stichting Deltares 2017. 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 Deltares.DamEngine.Calculators.KernelWrappers.Interfaces; +using Deltares.DamEngine.Data.General; +using Deltares.DamEngine.Data.Standard.Calculation; + namespace Deltares.DamEngine.Calculators.KernelWrappers.DamMacroStability { public class DamMacroStabilityOutput : IKernelDataOutput { + + /// + /// Gets or sets the calculation result. + /// + /// + /// The calculation result. + /// + public CalculationResult CalculationResult { get; set; } + + /// + /// Gets or sets the uplift situation. + /// + /// + /// The uplift situation. + /// + public UpliftSituation UpliftSituation { get; set; } + + /// + /// Structure holding the resuls per zone + /// public struct ResultsSingleZone { public double SafetyFactor; @@ -19,8 +62,21 @@ } } - public ResultsSingleZone Zone1 { get; set; } - public ResultsSingleZone? Zone2 { get; set; } + /// + /// Gets or sets the zone1 results. + /// + /// + /// The zone1. + /// + public ResultsSingleZone Zone1Results { get; set; } + + /// + /// Gets or sets the zone2 results. + /// + /// + /// The zone2. + /// + public ResultsSingleZone? Zone2Results { get; set; } } }