Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityInwards/MacroStabilityKernelInterface.cs
===================================================================
diff -u
--- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityInwards/MacroStabilityKernelInterface.cs (revision 0)
+++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityInwards/MacroStabilityKernelInterface.cs (revision 6465)
@@ -0,0 +1,37 @@
+// Copyright (C) Stichting Deltares 2024. 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.MacroStability.Interface;
+
+namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityInwards;
+
+public class MacroStabilityKernelInterface: IKernelDataInput
+{
+ ///
+ /// Gets or sets the actual input for the Interface
+ ///
+ ///
+ /// The input.
+ ///
+ public MacroStabilityInterface Input { get; set; } // = new (fullInputModelType);
+
+}
\ No newline at end of file
Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/EngineToMacroStabilityKernelInputTests.cs
===================================================================
diff -u -r6420 -r6465
--- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/EngineToMacroStabilityKernelInputTests.cs (.../EngineToMacroStabilityKernelInputTests.cs) (revision 6420)
+++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/EngineToMacroStabilityKernelInputTests.cs (.../EngineToMacroStabilityKernelInputTests.cs) (revision 6465)
@@ -84,11 +84,8 @@
FullInputModelType fullInputModel = FillMacroStabilityKernelInputFromEngine.CreateFullInputModel(
damKernelInput, expectedParametersMStab.MStabParameters, expectedWaternet, xCoordinateLowestUpliftFactorPoint);
Assert.That(fullInputModel, Is.Not.Null);
- // // reverse that input to the engine data
- // var fillEngineFromMacroStabilityWrapperInput = new FillEngineFromMacroStabilityWrapperInput();
- //fillEngineFromMacroStabilityWrapperInput.FillDamProjectDataFromKernelModel(expectedMacrostabilityInput);
- //
- // // Then the data models are equal
+
+ // Then the data models are equal
CompareStabilityModel(expectedParametersMStab, fullInputModel.StabilityModel);
CompareSoilModel(expectedSoilList, fullInputModel.StabilityModel.Soils);
CompareSoilProfile2D(expectedSoilProfile2D, fullInputModel.StabilityModel.ConstructionStages[0].SoilProfile, fullInputModel.StabilityModel.Soils);
@@ -101,57 +98,8 @@
bool areTangentLineSpecified = expectedUpliftVanCalculationGridSettings.UpliftVanTangentLinesDefinition == TangentLinesDefinition.Specified;
CompareUpliftVanCalculationGrid(expectedUpliftVanCalculationGrid, fullInputModel.StabilityModel.UpliftVanCalculationGrid, areTangentLineSpecified);
CompareWaternet(expectedWaternet, fullInputModel.StabilityModel.ConstructionStages[0].Waternet);
- //Todo : add and or implement comparer per item as these are added to the code
}
- [TestCase(1)]
- [TestCase(2)]
- [TestCase(3)]
- public void GivenCSharpWrapperOutputWhenGoingToAndFromEngineTheDataIsEqual(int testNumber)
- {
- //ToDo fill this
- //MacroStabilityOutput expectedKernelOutput = CreateKernelOutputForTest(testNumber);
- var engineOutput = new Calculators.KernelWrappers.MacroStabilityInwards.MacroStabilityOutput();
- Assert.That(engineOutput, Is.Not.Null);
- // FillEngineFromMacroStabilityWrapperOutput.FillEngineDataWithResults(expectedKernelOutput, engineOutput, out List logMessages);
- // MacroStabilityOutput kernelOutput = FillMacroStabilityWrapperOutputFromEngine.FillMacroStabilityWrapperOutput(engineOutput, logMessages);
-
- // var compare = new CompareLogic
- // {
- // Config =
- // {
- // MaxDifferences = 100
- // }
- // };
- // ComparisonResult result = compare.Compare(expectedKernelOutput, kernelOutput);
- // Assert.That(result.Differences, Is.Empty, "Differences found read/write kernel Output");
- }
-
- private static UpliftVanCalculationGrid CreateExampleUpliftVanCalculationGrid()
- {
- var random = new Random(21);
- var upliftVanCalculationGrid = new UpliftVanCalculationGrid
- {
- LeftGridXLeft = random.NextDouble(),
- LeftGridXRight = random.NextDouble(),
- LeftGridZTop = random.NextDouble(),
- LeftGridZBottom = random.NextDouble(),
- LeftGridXCount = random.Next(),
- LeftGridZCount = random.Next(),
- RightGridXLeft = random.NextDouble(),
- RightGridXRight = random.NextDouble(),
- RightGridZTop = random.NextDouble(),
- RightGridZBottom = random.NextDouble(),
- RightGridXCount = random.Next(),
- RightGridZCount = random.Next(),
- TangentLinesCreationMethod = TangentLinesDefinition.OnBoundaryLines,
- TangentLineZBottom = 0,
- TangentLineZTop = 10,
- TangentLineCount = 10
- };
- return upliftVanCalculationGrid;
- }
-
private static Waternet CreateExampleWaternet()
{
var waterNet = new Waternet
@@ -338,7 +286,6 @@
private static void CompareHeadLine(GeometryPointString expectedHeadLine, HeadLineType actualHeadLine)
{
- //CompareWaternetLine(expectedHeadLine, actualHeadLine.WaternetLine);
Assert.That(actualHeadLine.WaternetLine.Name, Is.EqualTo(expectedHeadLine.Name));
List expectedPoints = expectedHeadLine.Points;
List actualPoints = actualHeadLine.WaternetLine.Points.ToList();
@@ -482,209 +429,84 @@
});
}
- // private static MacroStabilityOutput CreateKernelOutputForTest(int choice)
- // {
- // var output = new MacroStabilityOutput();
- // var messagesOutput = new List();
- // if (choice == 1)
- // {
- // // Result 1: succeeded, has a SafetyFactor of ca. 3.856, no messages
- // output.ResultType = CalculationResultType.Succeeded;
- // output.PreprocessingOutputBase = new UpliftVanPreprocessingOutput();
- // output.StabilityOutput = new StabilityOutput
- // {
- // SafetyFactor = 3.856,
- // ModelOptionType = StabilityModelOptionType.UpliftVan
- // };
- // output.StabilityOutput.MinimumSafetyCurve = SetupUpliftDualSlidingCircle();
- // }
- // else if (choice == 2)
- // {
- // // Result 2: succeeded, has a SafetyFactor of ca. 1.857, has info and warning, but no error messages
- // messagesOutput.Clear();
- // var infoMessage = new Message();
- // infoMessage.Content = "Info";
- // infoMessage.MessageType = MessageType.Info;
- // messagesOutput.Add(infoMessage);
- // var warningMessage = new Message();
- // warningMessage.Content = "Warning";
- // warningMessage.MessageType = MessageType.Warning;
- // messagesOutput.Add(warningMessage);
- // output.ResultType = CalculationResultType.Succeeded;
- // output.PreprocessingOutputBase = new UpliftVanPreprocessingOutput();
- // output.StabilityOutput = new StabilityOutput
- // {
- // SafetyFactor = 1.857,
- // Messages = messagesOutput,
- // ModelOptionType = StabilityModelOptionType.UpliftVan
- // };
- // }
- // else
- // {
- // // Result 3 failed - has a SafetyFactor of NaN, has an error message
- // messagesOutput.Clear();
- // var errorMessage = new Message();
- // errorMessage.Content = "Error";
- // errorMessage.MessageType = MessageType.Error;
- // messagesOutput.Add(errorMessage);
- // output.StabilityOutput = new StabilityOutput();
- // output.ResultType = CalculationResultType.RunFailed;
- // output.StabilityOutput.SafetyFactor = double.NaN;
- // output.StabilityOutput.Messages = messagesOutput;
- // }
- //
- // return output;
- // }
- //
- // private static DualSlidingCircleMinimumSafetyCurve SetupUpliftDualSlidingCircle()
- // {
- // var dualSlidingCircleMinimumSafetyCurve = new DualSlidingCircleMinimumSafetyCurve
- // {
- // ActiveCircleCenter = new MacroStability.CSharpWrapper.Point2D(10, 10),
- // ActiveCircleRadius = 8,
- // PassiveCircleCenter = new MacroStability.CSharpWrapper.Point2D(22, 11),
- // PassiveCircleRadius = 7
- // };
- // List slices = CreateSlices();
- // dualSlidingCircleMinimumSafetyCurve.Slices = slices;
- //
- // return dualSlidingCircleMinimumSafetyCurve;
- // }
- //
- // private static List CreateSlices()
- // {
- // var slices = new List();
- // for (var i = 1; i < 6; i++)
- // {
- // var slice = new Slice
- // {
- // BottomLeftPoint = new MacroStability.CSharpWrapper.Point2D(-1 * i, 1 * i),
- // BottomRightPoint = new MacroStability.CSharpWrapper.Point2D(-2 * i, 2 * i),
- // TopLeftPoint = new MacroStability.CSharpWrapper.Point2D(-3 * i, 3 * i),
- // TopRightPoint = new MacroStability.CSharpWrapper.Point2D(-4 * i, 4 * i),
- // Name = "Slice" + i,
- // POP = 1.11 * i,
- // YieldStress = 2.22 * i,
- // OCR = 3.33 * i,
- // ResultantForce = 4.44 * i,
- // ResultantMoment = 5.55 * i,
- // ResultantAngle = 6.66 * i,
- // CohesionInput = 7.77 * i,
- // CohesionOutput = 8.88 * i,
- // FrictionAngleInput = 9.99 * i,
- // FrictionAngleOutput = 10.10 * i,
- // DilatancyInput = 11.11 * i,
- // SuInput = 12.12 * i,
- // SuOutput = 13.13 * i,
- // ShearStrengthModelType = ShearStrengthModelType.MohrCoulomb,
- // ShearStressInput = 14.14 * i,
- // ShearStressOutput = 15.15 * i,
- // Weight = 16.16 * i,
- // TotalPorePressure = 17.17 * i,
- // EffectiveStress = 18.18 * i,
- // HydrostaticPorePressure = 19.19 * i,
- // PiezometricPorePressure = 20.20 * i,
- // ExcessPorePressure = 21.21 * i,
- // DegreeOfConsolidationPorePressure = 22.22 * i,
- // PorePressureDueToDegreeOfConsolidationLoad = 23.23 * i,
- // LoadStress = 24.24 * i,
- // SoilStress = 25.25 * i,
- // TotalStress = 26.26 * i,
- // PorePressure = 27.27 * i,
- // VerticalPorePressure = 28.28 * i,
- // HorizontalPorePressure = 29.29 * i,
- // ExternalLoad = 30.30 * i,
- // NormalStress = 31.31 * i,
- // LeftForce = 32.32 * i,
- // LeftForceY = 33.33 * i,
- // LeftForceAngle = 34.34 * i,
- // RightForce = 35.35 * i,
- // RightForceY = 36.36 * i,
- // RightForceAngle = 37.37 * i,
- // HorizontalSoilQuakeStress = 38.38 * i,
- // VerticalSoilQuakeStress = 39.39 * i,
- // WaterQuakeStress = 40.40 * i,
- // RatioCuPc = 41.41 * i,
- // StrengthIncreaseExponent = 42.42 * i,
- // UpliftFactor = 43.43 * i,
- // UpliftReductionFactor = 44.44 * i,
- // ArcLength = 45.45 * i,
- // BottomAngle = 46.46 * i,
- // TopAngle = 47.47 * i,
- // Width = 48.48 * i
- // };
- // slices.Add(slice);
- // }
- //
- // return slices;
- // }
- //
- // public class GivenDamKernelInput
- // {
- // private readonly DamKernelInput damKernelInput = CreateDamKernelInputWithForbiddenZone();
- //
- // [Test]
- // [TestCase(0.0, 5.0)]
- // [TestCase(0.2, 6.0)]
- // [TestCase(1.0, 10.0)]
- // public void WithForbiddenZone_WhenTransferSlipPlaneConstraints_ThenSlipPlaneConstraintsAreSet(double forbiddenZoneFactor,double xEntryMax)
- // {
- // damKernelInput.Location.StabilityOptions.ForbiddenZoneFactor = forbiddenZoneFactor;
- // var macroStabilityInput = new MacroStabilityInput();
- // // When
- // FillMacroStabilityWrapperInputFromEngine.TransferSlipPlaneConstraints(damKernelInput.Location, macroStabilityInput.StabilityModel.SlipPlaneConstraints);
- // Assert.Multiple(() =>
- // {
- // // Then
- // Assert.That(macroStabilityInput.StabilityModel.SlipPlaneConstraints.SlipPlaneMinDepth, Is.EqualTo(1.5));
- // Assert.That(macroStabilityInput.StabilityModel.SlipPlaneConstraints.XEntryMin, Is.EqualTo(1.0));
- // Assert.That(macroStabilityInput.StabilityModel.SlipPlaneConstraints.XEntryMax, Is.EqualTo(xEntryMax));
- // });
- // }
- //
- // [Test]
- // public void WithNoZones_WhenTransferSlipPlaneConstraints_ThenXEntryIsNotSet()
- // {
- // damKernelInput.Location.StabilityOptions.StabilityZoneType = StabilityZoneType.NoZones;
- // var macroStabilityInput = new MacroStabilityInput();
- // // When
- // FillMacroStabilityWrapperInputFromEngine.TransferSlipPlaneConstraints(damKernelInput.Location, macroStabilityInput.StabilityModel.SlipPlaneConstraints);
- // Assert.Multiple(() =>
- // {
- // // Then
- // Assert.That(macroStabilityInput.StabilityModel.SlipPlaneConstraints.SlipPlaneMinDepth, Is.EqualTo(1.5));
- // Assert.That(macroStabilityInput.StabilityModel.SlipPlaneConstraints.XEntryMin, Is.NaN);
- // Assert.That(macroStabilityInput.StabilityModel.SlipPlaneConstraints.XEntryMax, Is.NaN);
- // });
- // }
- //
- // private static DamKernelInput CreateDamKernelInputWithForbiddenZone()
- // {
- // var surfaceLine = new SurfaceLine2()
- // {
- // CharacteristicPoints =
- // {
- // GeometryMustContainPoint = true
- // },
- // Geometry = new GeometryPointString()
- // };
- // surfaceLine.EnsurePointOfType(1.0, 0, CharacteristicPointType.DikeTopAtRiver);
- // surfaceLine.EnsurePointOfType(5.0, 0, CharacteristicPointType.DikeTopAtPolder);
- // surfaceLine.EnsurePointOfType(10.0, 0, CharacteristicPointType.DikeToeAtPolder);
- // var damKernelInput = new DamKernelInput
- // {
- // Location = new Location()
- // {
- // SurfaceLine = surfaceLine,
- // StabilityOptions = new StabilityOptions
- // {
- // MinimalCircleDepth = 1.5,
- // StabilityZoneType = StabilityZoneType.ForbiddenZone,
- // ForbiddenZoneFactor = 0.2
- // }
- // }
- // };
- // return damKernelInput;
- // }
- // }
+ public class GivenDamKernelInput
+ {
+ private readonly DamKernelInput damKernelInput = CreateDamKernelInputWithForbiddenZone();
+
+ [Test]
+ [TestCase(0.0, 5.0)]
+ [TestCase(0.2, 6.0)]
+ [TestCase(1.0, 10.0)]
+ public void WithForbiddenZone_WhenTransferSlipPlaneConstraints_ThenSlipPlaneConstraintsAreSet(double forbiddenZoneFactor,double xEntryMax)
+ {
+ damKernelInput.Location.StabilityOptions.ForbiddenZoneFactor = forbiddenZoneFactor;
+ var macroStabilityInput = new FullInputModelType
+ {
+ StabilityModel = new StabilityInputType
+ {
+ SlipPlaneConstraints = new SlipPlaneConstraintsType()
+ }
+ };
+ // When
+ FillMacroStabilityKernelInputFromEngine.TransferSlipPlaneConstraints(damKernelInput.Location, macroStabilityInput.StabilityModel.SlipPlaneConstraints);
+ Assert.Multiple(() =>
+ {
+ // Then
+ Assert.That(macroStabilityInput.StabilityModel.SlipPlaneConstraints.SlipPlaneMinDepth, Is.EqualTo(1.5));
+ Assert.That(macroStabilityInput.StabilityModel.SlipPlaneConstraints.XEntryMin, Is.EqualTo(1.0));
+ Assert.That(macroStabilityInput.StabilityModel.SlipPlaneConstraints.XEntryMax, Is.EqualTo(xEntryMax));
+ });
+ }
+
+ [Test]
+ public void WithNoZones_WhenTransferSlipPlaneConstraints_ThenXEntryIsNotSet()
+ {
+ damKernelInput.Location.StabilityOptions.StabilityZoneType = StabilityZoneType.NoZones;
+ var macroStabilityInput = new FullInputModelType
+ {
+ StabilityModel = new StabilityInputType
+ {
+ SlipPlaneConstraints = new SlipPlaneConstraintsType()
+ }
+ };
+ // When
+ FillMacroStabilityKernelInputFromEngine.TransferSlipPlaneConstraints(damKernelInput.Location, macroStabilityInput.StabilityModel.SlipPlaneConstraints);
+ Assert.Multiple(() =>
+ {
+ // Then
+ Assert.That(macroStabilityInput.StabilityModel.SlipPlaneConstraints.SlipPlaneMinDepth, Is.EqualTo(1.5));
+ Assert.That(macroStabilityInput.StabilityModel.SlipPlaneConstraints.XEntryMin, Is.NaN);
+ Assert.That(macroStabilityInput.StabilityModel.SlipPlaneConstraints.XEntryMax, Is.NaN);
+ });
+ }
+
+ private static DamKernelInput CreateDamKernelInputWithForbiddenZone()
+ {
+ var surfaceLine = new SurfaceLine2()
+ {
+ CharacteristicPoints =
+ {
+ GeometryMustContainPoint = true
+ },
+ Geometry = new GeometryPointString()
+ };
+ surfaceLine.EnsurePointOfType(1.0, 0, CharacteristicPointType.DikeTopAtRiver);
+ surfaceLine.EnsurePointOfType(5.0, 0, CharacteristicPointType.DikeTopAtPolder);
+ surfaceLine.EnsurePointOfType(10.0, 0, CharacteristicPointType.DikeToeAtPolder);
+ var damKernelInput = new DamKernelInput
+ {
+ Location = new Location()
+ {
+ SurfaceLine = surfaceLine,
+ StabilityOptions = new StabilityOptions
+ {
+ MinimalCircleDepth = 1.5,
+ StabilityZoneType = StabilityZoneType.ForbiddenZone,
+ ForbiddenZoneFactor = 0.2
+ }
+ }
+ };
+ return damKernelInput;
+ }
+ }
}
\ No newline at end of file
Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillEngineFromMacroStabilityKernelOutput.cs
===================================================================
diff -u -r6425 -r6465
--- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillEngineFromMacroStabilityKernelOutput.cs (.../FillEngineFromMacroStabilityKernelOutput.cs) (revision 6425)
+++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillEngineFromMacroStabilityKernelOutput.cs (.../FillEngineFromMacroStabilityKernelOutput.cs) (revision 6465)
@@ -44,6 +44,7 @@
logMessages = new List();
macroStabilityOutput.StabilityOutputItems.Add(new MacroStabilityOutputItem());
TransferProperties(fullOutputModel.StabilityOutput, macroStabilityOutput.StabilityOutputItems[0]);
+ macroStabilityOutput.CalculationResult = CalculationResult.Succeeded;
}
private static void TransferProperties(StabilityOutputType stabilityOutput, MacroStabilityOutputItem macroStabilityOutputItem)
Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/StixFileWriterConnector.cs
===================================================================
diff -u
--- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/StixFileWriterConnector.cs (revision 0)
+++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/StixFileWriterConnector.cs (revision 6465)
@@ -0,0 +1,192 @@
+// Copyright (C) Stichting Deltares 2025. 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.IO;
+using Deltares.DamEngine.Calculators.KernelWrappers.Common;
+using Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityInwards;
+using Deltares.DamEngine.Data.General;
+using Deltares.DamEngine.Data.Standard.Calculation;
+using Deltares.DamEngine.Data.Standard.Language;
+using Deltares.DamEngine.Data.Standard.Logging;
+using Deltares.MacroStability.CSharpWrapper.Input;
+using Deltares.MacroStability.CSharpWrapper.Output;
+using Deltares.MacroStability.Io.XmlInput;
+using Deltares.StixFileWriter;
+using MacroStabilityOutput = Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityInwards.MacroStabilityOutput;
+using Waternet = Deltares.DamEngine.Data.Geometry.Waternet;
+
+namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo;
+
+public static class StixFileWriterConnector
+{
+ ///
+ /// Writes the stix file based on only the input
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void WriteStixFileWithInput(DamKernelInput damKernelInput, MStabParameters mStabParameters, Waternet waterNet,
+ double xCoordinateLowestUpliftFactorPoint, MacroStabilityOutput macroStabilityOutput,
+ string fileName, List messages)
+ {
+ try
+ {
+ var filler = new FillMacroStabilityWrapperInputFromEngine();
+ MacroStabilityInput macroStabilityInput = filler.CreateMacroStabilityInput(damKernelInput, mStabParameters, waterNet,
+ xCoordinateLowestUpliftFactorPoint);
+ MacroStabilityOutputItem stabilityOutputItem = macroStabilityOutput.StabilityOutputItems[^1];
+ CreateCorrectGridAsInputBasedOnOutputItem(stabilityOutputItem, macroStabilityInput);
+ WriteStixFileBasedOnInputOnly(fileName, macroStabilityInput);
+ }
+ catch (Exception exceptionDuringStixFileWriter)
+ {
+ string message = LocalizationManager.GetTranslatedText(typeof(MacroStabilityCommonHelper),
+ "UnexpectedErrorStixFileCreation") + exceptionDuringStixFileWriter.Message;
+ messages.Add(new LogMessage(LogMessageType.Warning, null, message));
+ }
+ }
+
+ ///
+ /// Writes the stix file based the input and the results.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void WriteStixFileWithInputAndResults(DamKernelInput damKernelInput, MStabParameters mStabParameters,
+ Waternet waterNet, double xCoordinateLowestUpliftFactorPoint,
+ MacroStabilityOutput macroStabilityOutput, string fileName, List messages)
+ {
+ try
+ {
+ var filler = new FillMacroStabilityWrapperInputFromEngine();
+ MacroStabilityInput macroStabilityInput = filler.CreateMacroStabilityInput(damKernelInput, mStabParameters, waterNet,
+ xCoordinateLowestUpliftFactorPoint);
+
+ MacroStabilityOutputItem stabilityOutputItem = macroStabilityOutput.StabilityOutputItems[^1];
+ CreateCorrectGridAsInputBasedOnOutputItem(stabilityOutputItem, macroStabilityInput);
+
+ if (stabilityOutputItem.CalculationResult == CalculationResult.Succeeded)
+ {
+ WriteStixFileBasedOnInputAndResultsSlipPlane(fileName, macroStabilityInput, stabilityOutputItem);
+ }
+ }
+ catch (Exception exceptionDuringStixFileWriter)
+ {
+ string message = LocalizationManager.GetTranslatedText(typeof(MacroStabilityCommonHelper),
+ "UnexpectedErrorStixFileCreation") + exceptionDuringStixFileWriter.Message;
+ messages.Add(new LogMessage(LogMessageType.Warning, null, message));
+ }
+ }
+
+ private static void CreateCorrectGridAsInputBasedOnOutputItem(MacroStabilityOutputItem stabilityOutputItem, MacroStabilityInput macroStabilityInput)
+ {
+ switch (stabilityOutputItem.StabilityModelType)
+ {
+ case StabilityModelType.Bishop:
+ macroStabilityInput.StabilityModel.BishopCalculationCircle = CSharpWrapperConverters.CreateWrapperBishopCalculationCircle(stabilityOutputItem.InputBishopCalculationGrid);
+ break;
+ case StabilityModelType.UpliftVan:
+ macroStabilityInput.StabilityModel.UpliftVanCalculationGrid = CSharpWrapperConverters.CreateWrapperUpliftVanCalculationGrid(stabilityOutputItem.InputUpliftVanCalculationGrid);
+ break;
+ }
+ }
+
+ ///
+ /// Writes the stix file based on input and results search grid.
+ /// For Uplift-Van with Grid, the stix file is not written because this combination is not possible in D-Stability.
+ ///
+ /// Name of the file.
+ /// The input.
+ private static void WriteStixFileBasedOnInputOnly(string fileName, MacroStabilityInput input)
+ {
+ if (input.StabilityModel.ModelOption == StabilityModelOptionType.UpliftVan &&
+ input.StabilityModel.SearchAlgorithm == SearchAlgorithm.Grid)
+ {
+ return;
+ }
+
+ string fileNameForCalculationAsStix = DetermineStixFilename(fileName, "input");
+ var inputStixFile = new StixWriter();
+ inputStixFile.FillInfo("DAM Engine", Path.GetDirectoryName(fileName),
+ Path.GetFileName(fileName), true);
+ StixFileWrite(inputStixFile, fileNameForCalculationAsStix, input);
+ }
+
+ ///
+ /// Writes the stix file based on input and results slip plane.
+ ///
+ /// Name of the file.
+ /// The input.
+ /// The macro stability output.
+ private static void WriteStixFileBasedOnInputAndResultsSlipPlane(string fileName, MacroStabilityInput input,
+ MacroStabilityOutputItem macroStabilityOutputItem)
+ {
+ macroStabilityOutputItem.CalculationPath = Path.GetDirectoryName(fileName);
+ macroStabilityOutputItem.ProjectName = Path.GetFileName(fileName);
+ string fileNameForCalculationAsStix = DetermineStixFilename(fileName, "result");
+ var resultStixWrite = new StixWriter();
+ resultStixWrite.FillInfo("DAM Engine", macroStabilityOutputItem.CalculationPath,
+ macroStabilityOutputItem.ProjectName, true);
+ switch (macroStabilityOutputItem.StabilityModelType)
+ {
+ case StabilityModelType.UpliftVan:
+ resultStixWrite.FillCalculatedDualCircle(macroStabilityOutputItem.ActiveCenterPoint.X,
+ macroStabilityOutputItem.ActiveCenterPoint.Z,
+ macroStabilityOutputItem.ActiveCenterPointRadius,
+ macroStabilityOutputItem.PassiveCenterPoint.X,
+ macroStabilityOutputItem.PassiveCenterPoint.Z);
+ break;
+ case StabilityModelType.Bishop:
+ resultStixWrite.FillCalculatedCircle(macroStabilityOutputItem.ActiveCenterPoint.X,
+ macroStabilityOutputItem.ActiveCenterPoint.Z,
+ macroStabilityOutputItem.ActiveCenterPointRadius);
+ break;
+ }
+
+ StixFileWrite(resultStixWrite, fileNameForCalculationAsStix, input);
+ }
+
+ private static string DetermineStixFilename(string fileNameForCalc, string suffix, string extension = ".stix")
+ {
+ return Path.Combine(Path.GetDirectoryName(fileNameForCalc) ?? string.Empty,
+ $"{Path.GetFileNameWithoutExtension(fileNameForCalc)}_{suffix}{extension}");
+ }
+
+ private static void StixFileWrite(StixWriter stixWriter, string fileName, MacroStabilityInput input)
+ {
+ if (File.Exists(fileName))
+ {
+ File.Delete(fileName);
+ }
+
+ stixWriter.WriteStixFile(fileName, input);
+ }
+
+}
\ No newline at end of file