Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/IWaternetKernel.cs =================================================================== diff -u -rddcfe77680566b25a6eac697323787a03ae25e46 -re35222f637844b64df2d6fef45bc365a7d805439 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/IWaternetKernel.cs (.../IWaternetKernel.cs) (revision ddcfe77680566b25a6eac697323787a03ae25e46) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/IWaternetKernel.cs (.../IWaternetKernel.cs) (revision e35222f637844b64df2d6fef45bc365a7d805439) @@ -20,10 +20,11 @@ // All rights reserved. using System.Collections.Generic; -using Deltares.MacroStability.Geometry; +using Deltares.MacroStability.CSharpWrapper.Input; +using Deltares.MacroStability.CSharpWrapper.Output; using Deltares.MacroStability.Standard; using Riskeer.MacroStabilityInwards.KernelWrapper.Calculators.Waternet; -using WtiStabilityWaternet = Deltares.MacroStability.Geometry.Waternet; +using WtiStabilityWaternet = Deltares.MacroStability.CSharpWrapper.Waternet; namespace Riskeer.MacroStabilityInwards.KernelWrapper.Kernels.Waternet { @@ -47,12 +48,12 @@ /// /// Sets the soil profile. /// - void SetSoilProfile(SoilProfile2D soilProfile); + void SetSoilProfile(SoilProfile soilProfile); /// /// Sets the surface line. /// - void SetSurfaceLine(SurfaceLine2 surfaceLine); + void SetSurfaceLine(SurfaceLine surfaceLine); /// /// Performs the Waternet calculation. @@ -67,6 +68,8 @@ /// An of objects. /// Thrown when /// an error occurs when performing the validation. - IEnumerable Validate(); + IEnumerable Validate(); + + void SetSoils(ICollection soils); } } \ No newline at end of file Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/WaternetKernelWrapper.cs =================================================================== diff -u -rddcfe77680566b25a6eac697323787a03ae25e46 -re35222f637844b64df2d6fef45bc365a7d805439 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/WaternetKernelWrapper.cs (.../WaternetKernelWrapper.cs) (revision ddcfe77680566b25a6eac697323787a03ae25e46) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/WaternetKernelWrapper.cs (.../WaternetKernelWrapper.cs) (revision e35222f637844b64df2d6fef45bc365a7d805439) @@ -22,11 +22,13 @@ using System; using System.Collections.Generic; using System.Linq; -using Deltares.MacroStability.Geometry; +using Deltares.MacroStability.CSharpWrapper; +using Deltares.MacroStability.CSharpWrapper.Input; +using Deltares.MacroStability.CSharpWrapper.Output; +using Deltares.MacroStability.CSharpWrapper.Output.WaternetCreator; using Deltares.MacroStability.Standard; using Deltares.MacroStability.WaternetCreator; -using Deltares.WTIStability.Calculation.Wrapper; -using WtiStabilityWaternet = Deltares.MacroStability.Geometry.Waternet; +using WtiStabilityWaternet = Deltares.MacroStability.CSharpWrapper.Waternet; namespace Riskeer.MacroStabilityInwards.KernelWrapper.Kernels.Waternet { @@ -35,65 +37,88 @@ /// internal class WaternetKernelWrapper : IWaternetKernel { - private const double unitWeightWater = 9.81; - private readonly Location location; - private readonly WaternetCreator waternetCreator; + private readonly string waternetName; + private readonly MacroStabilityInput input; /// /// Creates a new instance of . /// /// The to use. /// The name of the . - public WaternetKernelWrapper(Location location, string waternetName) + /// + public WaternetKernelWrapper(WaternetCreatorInput waternetCreatorInput, string waternetName) { - if (location == null) - { - throw new ArgumentNullException(nameof(location)); - } + this.waternetName = waternetName; - this.location = location; - Waternet = new WtiStabilityWaternet + input = new MacroStabilityInput { - Name = waternetName + StabilityModel = + { + ConstructionStages = + { + new ConstructionStage() + } + }, + PreprocessingInput = + { + PreConstructionStages = + { + new PreConstructionStage + { + WaternetCreationMode = WaternetCreationMode.CreateWaternet, + WaternetCreatorInput = waternetCreatorInput + } + } + } }; - waternetCreator = new WaternetCreator(unitWeightWater); + } - public WtiStabilityWaternet Waternet { get; } + public WtiStabilityWaternet Waternet { get; private set; } - public void SetSoilProfile(SoilProfile2D soilProfile) + public void SetSoils(ICollection soils) { - location.SoilProfile2D = soilProfile; + input.StabilityModel.Soils = soils; } - public void SetSurfaceLine(SurfaceLine2 surfaceLine) + public void SetSoilProfile(SoilProfile soilProfile) { - location.Surfaceline = surfaceLine; + input.StabilityModel.ConstructionStages.First().SoilProfile = soilProfile; } - public void Calculate() + public void SetSurfaceLine(SurfaceLine surfaceLine) { - CheckIfWaternetCanBeGenerated(); + input.PreprocessingInput.PreConstructionStages.First().SurfaceLine = surfaceLine; + } + public void Calculate() + { try { - waternetCreator.UpdateWaternet(Waternet, location); + var calculator = new Calculator(input); - ReadLogMessages(waternetCreator.LogMessages); + CheckIfWaternetCanBeGenerated(); - SynchronizeWaternetLinePoints(); + WaternetCreatorOutput output = calculator.CalculateWaternet(0); + + Waternet = output.Waternet; + Waternet.Name = waternetName; + + ReadLogMessages(output.Messages); } catch (Exception e) when (!(e is WaternetKernelWrapperException)) { throw new WaternetKernelWrapperException(e.Message, e); } } - public IEnumerable Validate() + public IEnumerable Validate() { try { - return location.Validate(); + var validator = new Validator(input); + ValidationOutput output = validator.ValidateWaternetCreator(); + return output.Messages; } catch (Exception e) { @@ -107,34 +132,29 @@ /// Thrown when the Waternet can not be generated. private void CheckIfWaternetCanBeGenerated() { - if (!waternetCreator.CanGenerateWaternet(location)) + var validator = new Validator(input); + ValidationOutput output = validator.ValidateWaternetCreator(); + + if(!output.IsValid) { throw new WaternetKernelWrapperException(); } } - private void SynchronizeWaternetLinePoints() - { - Waternet.HeadLineList.ForEach(l => l.SyncPoints()); - Waternet.WaternetLineList.ForEach(l => l.SyncPoints()); - Waternet.PhreaticLine.SyncPoints(); - } - /// /// Reads the log messages of the calculation. /// /// The messages to read. /// Thrown when there /// are log messages of the type or . - private static void ReadLogMessages(IEnumerable receivedLogMessages) + private static void ReadLogMessages(IEnumerable receivedLogMessages) { - LogMessage[] errorMessages = receivedLogMessages.Where(lm => lm.MessageType == LogMessageType.FatalError - || lm.MessageType == LogMessageType.Error).ToArray(); + Message[] errorMessages = receivedLogMessages.Where(lm => lm.MessageType == MessageType.Error).ToArray(); if (errorMessages.Any()) { string message = errorMessages.Aggregate(string.Empty, - (current, logMessage) => current + $"{logMessage.Message}{Environment.NewLine}") + (current, logMessage) => current + $"{logMessage.Content}{Environment.NewLine}") .Trim(); throw new WaternetKernelWrapperException(message);