Fisheye: Tag 949 refers to a dead (removed) revision in file `DamEngine/trunk/src/Deltares.DamEngine.Calculators/Stability/StabilityCalculationException.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/Stability/StabilityServiceAgent.cs =================================================================== diff -u -r877 -r949 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/Stability/StabilityServiceAgent.cs (.../StabilityServiceAgent.cs) (revision 877) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/Stability/StabilityServiceAgent.cs (.../StabilityServiceAgent.cs) (revision 949) @@ -20,17 +20,8 @@ // All rights reserved. using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; using System.Text; -using System.Threading; -using Deltares.DamEngine.Calculators.General; using Deltares.DamEngine.Calculators.Interfaces; -using Deltares.DamEngine.Data.General; -using Deltares.DamEngine.Data.General.Results; -using Deltares.DamEngine.Data.Geometry; -using Deltares.DamEngine.Data.Standard.Language; namespace Deltares.DamEngine.Calculators.Stability { @@ -40,78 +31,17 @@ /// public class StabilityServiceAgent : IDisposable { - private DGSMStabDAMInterface mstabDamDll; - private DGSDAMSlopeWInterface slopeWDamDll; - + private readonly DGSMStabDAMInterface mstabDamDll; + public StabilityServiceAgent() { - mstabDamDll = new DGSMStabDAMInterface(); - slopeWDamDll = new DGSDAMSlopeWInterface(); - MStabExePath = DamProjectData.MStabExePath; - SlopeWExePath = DamProjectData.SlopeWExePath; + mstabDamDll = new DGSMStabDAMInterface(); } - #region Native Members - - /// - /// Constant to the dll file can only be a constant! - /// - - #endregion - #region Wrapper Methods - - public string MStabExePath { get; set; } - public string SlopeWExePath { get; set; } - public ProgramType ProgramType { get; set; } - + + /// - /// Get DLL version - /// - /// - public string GetDllVersion() - { - if (ProgramType == ProgramType.SlopeW) - { - return slopeWDamDll.GetDllVersion(); - } - else - { - return mstabDamDll.GetDllVersion(); - } - } - - /// - /// Create MStab project file - /// - /// - public void CreateProjectFile(string inputXmlString) - { - lock (typeof (StabilityServiceAgent)) - { - var result = 0; - if (ProgramType == ProgramType.SlopeW) - { - result = slopeWDamDll.CreateProjectFile(inputXmlString); - if (result > 0) - { - string errorMessage = slopeWDamDll.ErrorMessage(); - throw new StabilityServiceAgentException(errorMessage); - } - } - else - { - result = mstabDamDll.CreateProjectFile(inputXmlString); - if (result > 0) - { - string errorMessage = mstabDamDll.ErrorMessage(); - throw new StabilityServiceAgentException(errorMessage); - } - } - } - } - - /// /// Create Soilprofile for location X in geometry-2d /// /// @@ -131,431 +61,9 @@ throw new StabilityServiceAgentException(mstabDamDll.ErrorMessage()); } - /// - /// Create Geometry2DData object from geometry2D file - /// - /// - /// - public void CreateGeometry2DDataFromGeometry2D(string inputXML, ref StringBuilder outputXML) - { - const int defaultBufferSize = 10000; - int bufferSize = defaultBufferSize; - outputXML = new StringBuilder(bufferSize); - int returnCode = mstabDamDll.CreateGeometry2DDataFromGeometry2D(inputXML, outputXML, ref bufferSize); - if (returnCode == DgsStandardDllInterface.DllErrorOutputBufferTooSmall) - { - outputXML = new StringBuilder(bufferSize); - returnCode = mstabDamDll.CreateGeometry2DDataFromGeometry2D(inputXML, outputXML, ref bufferSize); - } - if (returnCode != DgsStandardDllInterface.DllErrorNone) - throw new StabilityServiceAgentException(mstabDamDll.ErrorMessage()); - } - - /// - /// Calculate piping length - /// - /// - /// - public double CalculatePipingLength(PolyLine headLine) - { - int pointCount = headLine.Points.Count; - var headLinePoints = new DGSMStabDAMInterface.LegacyCoordinate[pointCount]; - double[] pointCoordinates = new double[pointCount * 2]; - for (int pointIndex = 0; pointIndex < pointCount; pointIndex++) - { - headLinePoints[pointIndex].x = headLine.Points[pointIndex].X; - headLinePoints[pointIndex].z = headLine.Points[pointIndex].Z; - pointCoordinates[pointIndex * 2] = headLine.Points[pointIndex].X; - pointCoordinates[pointIndex * 2 + 1] = headLine.Points[pointIndex].Z; - } - return mstabDamDll.PipingLengthCalculation(pointCount, ref headLinePoints); - } - - /// - /// Calculate MStab projects in specified directory - /// - /// - public void CalculateMStabDirectory(string directoryPath) - { - ThrowHelper.ThrowIfStringArgumentNullOrEmpty(directoryPath, StringResourceNames.ProjectFileNameNullOrEmpty); - ThrowHelper.ThrowIfDirectoryNotExist(directoryPath, StringResourceNames.ProjectFileNotExist); - ThrowHelper.ThrowIfFileNotExist(MStabExePath, StringResourceNames.MStabExecutableFileNameNotFound); - - try - { - // Compute the project files - ProcessInputfFile(directoryPath); - } - catch (ArgumentNullException argumentNullException) - { - throw new StabilityServiceAgentException(argumentNullException.Message, argumentNullException); - } - catch (FileNotFoundException outputFileNotFoundException) - { - throw new StabilityServiceAgentException(outputFileNotFoundException.Message, outputFileNotFoundException); - } - } - - /// - /// Calculate MStab project - /// - /// - public void CalculateMStabProject(string projectFilePath) - { - ThrowHelper.ThrowIfStringArgumentNullOrEmpty(projectFilePath, StringResourceNames.ProjectFileNameNullOrEmpty); - ThrowHelper.ThrowIfFileNotExist(projectFilePath, StringResourceNames.ProjectFileNotExist); - ThrowHelper.ThrowIfFileNotExist(MStabExePath, StringResourceNames.MStabExecutableFileNameNotFound); - - try - { - // Compute the project files - ProcessInputfFile(projectFilePath); - } - catch (ArgumentNullException argumentNullException) - { - throw new StabilityServiceAgentException(argumentNullException.Message, argumentNullException); - } - catch (FileNotFoundException outputFileNotFoundException) - { - throw new StabilityServiceAgentException(outputFileNotFoundException.Message, outputFileNotFoundException); - } - } - - /// - /// Calculate SlopeW project - /// - /// - public void CalculateSlopeWProject(string projectFilePath) - { - ThrowHelper.ThrowIfStringArgumentNullOrEmpty(projectFilePath, StringResourceNames.ProjectFileNameNullOrEmpty); - ThrowHelper.ThrowIfFileNotExist(projectFilePath, StringResourceNames.ProjectFileNotExist); - ThrowHelper.ThrowIfFileNotExist(SlopeWExePath, StringResourceNames.SlopeWExecutableFileNameNotFound); - - try - { - // Compute the project files - ProcessInputfFile(projectFilePath); - } - catch (ArgumentNullException argumentNullException) - { - throw new StabilityServiceAgentException(argumentNullException.Message, argumentNullException); - } - catch (FileNotFoundException outputFileNotFoundException) - { - throw new StabilityServiceAgentException(outputFileNotFoundException.Message, outputFileNotFoundException); - } - } - - /// - /// Extracts the relevant calculation results from the outputfile of MStab - /// - /// The project file to process - /// The MStab calculation results - public MStabResults ExtractStabilityResults(string projectFileName) - { - ThrowHelper.ThrowIfStringArgumentNullOrEmpty(projectFileName, StringResourceNames.ProjectFileNameNullOrEmpty); - ThrowHelper.ThrowIfFileNotExist(projectFileName, StringResourceNames.ProjectFileNotExist); - - try - { - if (ProgramType == ProgramType.SlopeW) - { - string outputFile = GetSlopeWOutputFileName(projectFileName); - return ParseSlopeWResultsFromOutputFile(outputFile); - } - else - { - string outputFile = Path.Combine(Path.GetDirectoryName(projectFileName), GetOutputFileName(projectFileName)); - return ParseMStabResultsFromOutputFile(outputFile); - } - } - catch (ArgumentNullException argumentNullException) - { - string message = LocalizationManager.GetTranslatedText(this.GetType(), "CouldNotExtractSafetyFactor"); - throw new StabilityServiceAgentException(message, argumentNullException); - } - catch (FileNotFoundException outputFileNotFoundException) - { - string message = LocalizationManager.GetTranslatedText(this.GetType(), "CouldNotExtractSafetyFactor"); - - string outputFile = Path.Combine(Path.GetDirectoryName(projectFileName), GetOutputFileName(projectFileName)); - string[] errorMessages = ParseMStabErrorFile(outputFile); - if (errorMessages.Length > 0) - { - message = errorMessages[0]; - } - - throw new StabilityServiceAgentException(message, outputFileNotFoundException); - } - } - - /// - /// Extract the beta-value from dumpfile of MStab - /// - /// - /// - public double ExtractBeta(string projectFileName) - { - ThrowHelper.ThrowIfStringArgumentNullOrEmpty(projectFileName, StringResourceNames.ProjectFileNameNullOrEmpty); - ThrowHelper.ThrowIfFileNotExist(projectFileName, StringResourceNames.ProjectFileNotExist); - - string outputFile = Path.Combine(Path.GetDirectoryName(projectFileName), GetOutputFileName(projectFileName)); - - try - { - return ParseBetaFromOutputFile(outputFile); - } - catch (ArgumentNullException argumentNullException) - { - throw new StabilityServiceAgentException(argumentNullException.Message, argumentNullException); - } - catch (FileNotFoundException outputFileNotFoundException) - { - throw new StabilityServiceAgentException(outputFileNotFoundException.Message, outputFileNotFoundException); - } - } - #endregion - #region Helper Methods - - private string CreateMStabIniFile(string inputFileName) - { - string filename = Path.GetTempFileName(); - filename = Path.ChangeExtension(filename, "ini"); - string defaultIniFilename = Path.Combine(Path.GetDirectoryName(MStabExePath), "DGeoStability.ini"); - string newIniContent = "[D-Geo Stability batch processing]"; - var isDirectoryBatchCalculation = Directory.Exists(inputFileName); - if (isDirectoryBatchCalculation) - { - newIniContent += System.Environment.NewLine + "Path=" + inputFileName; - newIniContent += System.Environment.NewLine + "Filespec=*.sti"; - } - else - { - newIniContent += System.Environment.NewLine + "InputFileName=" + inputFileName; - } - newIniContent += System.Environment.NewLine + "Plot Critical Circle=1"; - newIniContent += System.Environment.NewLine + "PlotWMF=1"; - newIniContent += System.Environment.NewLine + "PlotJPeg=1"; - if (File.Exists(defaultIniFilename)) - { - string iniContent = File.ReadAllText(defaultIniFilename); - newIniContent += System.Environment.NewLine + System.Environment.NewLine + iniContent; - }; - File.WriteAllText(filename, newIniContent); - return filename; - - } - - /// - /// Processes the input file using the working folder - /// - /// The folder or file name; for MStab: if a filename is specified then the file will be calculated; if a foldername is specified, all the stability files in the folder will be calculated. For SlopeW only filename is allowed - private void ProcessInputfFile(string folderOrFileName) - { - const string quote = "\""; - var argument = ""; - var programpath = ""; - string mStabIniFilename = ""; - if (ProgramType == ProgramType.SlopeW) - { - programpath = SlopeWExePath; - argument = " /s /x " + quote + folderOrFileName + quote + " " + quote + Path.GetFileNameWithoutExtension(folderOrFileName) + quote; - } - else - { - programpath = MStabExePath; - mStabIniFilename = CreateMStabIniFile(folderOrFileName); - argument = string.Format("/b \"{0}\"", mStabIniFilename); - - // For debugging and calling with commandline options i.s.o. inifile - //string filename = Path.GetTempFileName(); - //File.WriteAllText(filename, programpath); - //File.WriteAllText(filename, argument); - //File.AppendAllText(filename, mStabIniFilename); - //argument = string.Format("/B /PlotJPeg /Plot \"{0}\"", folderOrFileName); // note: use the folder name only for running MStab in batch mode - //File.AppendAllText(filename, argument); - } - - var process = new Process - { - StartInfo = - { - FileName = programpath, - Arguments = argument, - UseShellExecute = false - } - - }; - - General.Parallel.KillOnAbort(process); - - process.Start(); - - try - { - process.WaitForExit(); - } - catch (ThreadInterruptedException) - { - // thread was killed by user action to stop calculation - } - finally - { - if (File.Exists(mStabIniFilename)) - { - File.Delete(mStabIniFilename); - } - } - } - - - /// - /// Creates a random working folder by using a GUID - /// - /// The generated folder name - private static string CreateTempDirName() - { - return string.Format("{0}\\{1}", Path.GetTempPath(), Guid.NewGuid().ToString().Replace('-', '0')); - } - - /// - /// Gets the stripped file name with the correct extension extracted from the input file name - /// - /// The file name with path - /// The project file name without path and correct extension - private static string GetOutputFileName(string projectFileName) - { - return GetStrippedFileNameWithoutExtension(projectFileName) + ".std"; - } - - /// - /// Gets the filename with the correct extension and the proper path for the outputfile for SlopeW - /// - /// The file name with path - /// The project file name with extended path and correct extension - private static string GetSlopeWOutputFileName(string projectFileName) - { - string outputFile = Path.GetDirectoryName(projectFileName); - outputFile = Path.Combine(outputFile, Path.GetFileNameWithoutExtension(projectFileName)); - outputFile = Path.Combine(outputFile, "001"); - outputFile = Path.Combine(outputFile, Path.GetFileNameWithoutExtension(projectFileName)); - string outputFileTest = outputFile + ".optfrc"; - if (!File.Exists(outputFileTest)) - { - outputFileTest = outputFile + ".frc01"; - } - if (!File.Exists(outputFileTest)) - { - outputFileTest = ""; - } - return outputFileTest; - } - - /// - /// Gets the stripped file name without a path - /// - /// The file name - /// The project file name without path and correct extension - private static string GetInputFileName(string projectFileName) - { - return GetStrippedFileNameWithoutExtension(projectFileName) + ".sti"; - } - - /// - /// Gets the stripped file name without path and extension - /// - /// The file name to strip - /// The file name - private static string GetStrippedFileNameWithoutExtension(string fileName) - { - return fileName.Substring(fileName.LastIndexOf("\\") + 1).Split('.')[0]; - } - - /// - /// Gets the constructed file name with folder - /// - /// The name of the file - /// The name of the folder - /// The full file path - private static string GetFileName(string fileName, string folderName) - { - return string.Format("{0}\\{1}", folderName, fileName); - } - - /// - /// Parses the safety factor from the output file - /// - /// The file to parse - /// The safety factor - private static MStabResults ParseMStabResultsFromOutputFile(string outputFile) - { - if (!File.Exists(outputFile)) - throw new FileNotFoundException("No valid calculation performed"); - - var fileContent = StabilityServiceFileParser.GetFileContents(outputFile); - return StabilityServiceFileParser.GetMStabResults(fileContent); - } - - /// - /// Parses the error messages from the error file - /// - /// The file to parse - /// The error messages - private string[] ParseMStabErrorFile(string outputFile) - { - string errorFile = outputFile.Replace(".std", ".err"); - - if (File.Exists(errorFile)) - { - List messages = new List(); - bool content = false; - foreach (string line in File.ReadAllLines(outputFile)) - { - if (line.StartsWith("**********")) - { - content = !content; - } - else if (content) - { - messages.Add(line); - } - } - - return messages.ToArray(); - } - else - { - return new string[0]; - } - } - - /// - /// Parses the safety factor from the output file - /// - /// The file to parse - /// The safety factor - private static MStabResults ParseSlopeWResultsFromOutputFile(string outputFile) - { - if (!File.Exists(outputFile)) - throw new FileNotFoundException("No valid calculation performed"); - - var fileContent = StabilityServiceFileParser.GetFileContents(outputFile); - return StabilityServiceFileParser.GetSlopeWResults(fileContent); - } - - private static double ParseBetaFromOutputFile(string outputFile) - { - if (!File.Exists(outputFile)) - throw new FileNotFoundException("No valid calculation performed"); - - var fileContent = StabilityServiceFileParser.GetFileContents(outputFile); - return StabilityServiceFileParser.GetBeta(fileContent); - } - - #endregion - + #region IDispose Members public void Dispose() Fisheye: Tag 949 refers to a dead (removed) revision in file `DamEngine/trunk/src/Deltares.DamEngine.Calculators/General/DamRunner.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 949 refers to a dead (removed) revision in file `DamEngine/trunk/src/Deltares.DamEngine.Calculators/Stability/StabilityCalculation.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 949 refers to a dead (removed) revision in file `DamEngine/trunk/src/Deltares.DamEngine.Calculators/Stability/StabilityCalculator.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/General/Geometry2DTo1DConverter.cs =================================================================== diff -u -r937 -r949 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/General/Geometry2DTo1DConverter.cs (.../Geometry2DTo1DConverter.cs) (revision 937) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/General/Geometry2DTo1DConverter.cs (.../Geometry2DTo1DConverter.cs) (revision 949) @@ -58,7 +58,7 @@ SoilGeometry2DName = soilGeometry2DName; SurfaceLine = surfaceLine; DikeEmbankmentMaterial = dikeEmbankmentMaterial; - this.SoilList = soilList; + SoilList = soilList; XOffsetSoilGeometry2DOrigin = 0; } @@ -75,7 +75,7 @@ SoilGeometry2DName = soilGeometry2DName; SurfaceLine = surfaceLine; DikeEmbankmentMaterial = dikeEmbankmentMaterial; - this.SoilList = soilList; + SoilList = soilList; XOffsetSoilGeometry2DOrigin = xOffsetSoilGeometry2DOrigin; } public string SoilGeometry2DName { get; set; } @@ -95,9 +95,11 @@ //xCoordinate = Math.Min(xCoordinate, this.SurfaceLine[CharacteristicPointType.SurfaceLevelInside].X - 0.1); //xCoordinate = this.SurfaceLine[CharacteristicPointType.SurfaceLevelInside].X-0.25; DAMMStabGeometry2DSectionAssembler assembler = new DAMMStabGeometry2DSectionAssembler(); - var geometry2DSectionParameters = new Geometry2DSectionParameters(); - geometry2DSectionParameters.SoilGeometry2DName = System.IO.Path.GetFullPath(SoilGeometry2DName); - geometry2DSectionParameters.XCoordinateSection = xCoordinate + XOffsetSoilGeometry2DOrigin; + var geometry2DSectionParameters = new Geometry2DSectionParameters + { + SoilGeometry2DName = Path.GetFullPath(SoilGeometry2DName), + XCoordinateSection = xCoordinate + XOffsetSoilGeometry2DOrigin + }; XDocument doc = assembler.CreateDataTransferObject(geometry2DSectionParameters); String LXMLInput = doc.ToString(); @@ -139,15 +141,17 @@ /// The x coordinate. private void AddDikeMaterialIfSurfaceLineAboveGeometrySurface(ref SoilProfile1D soilProfile, double xCoordinate) { - double surfaceLevel = this.SurfaceLine.Geometry.GetZAtUnsortedX(xCoordinate); + double surfaceLevel = SurfaceLine.Geometry.GetZAtUnsortedX(xCoordinate); if (surfaceLevel > soilProfile.Layers[0].TopLevel) { // Add toplayer ThrowIfNoDikeMaterialAssigned(); - var topLayer = new SoilLayer1D(); - topLayer.Name = soilProfile.GetNewUniqueLayerName(); - topLayer.SoilName = DikeEmbankmentMaterial.Name; - topLayer.TopLevel = surfaceLevel; + var topLayer = new SoilLayer1D + { + Name = soilProfile.GetNewUniqueLayerName(), + SoilName = DikeEmbankmentMaterial.Name, + TopLevel = surfaceLevel + }; soilProfile.Layers.Insert(0, topLayer); } } Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/Deltares.DamEngine.Calculators.csproj =================================================================== diff -u -r946 -r949 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/Deltares.DamEngine.Calculators.csproj (.../Deltares.DamEngine.Calculators.csproj) (revision 946) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/Deltares.DamEngine.Calculators.csproj (.../Deltares.DamEngine.Calculators.csproj) (revision 949) @@ -60,15 +60,11 @@ - - + - - - @@ -137,11 +133,7 @@ Resources.resx - - - - Fisheye: Tag 949 refers to a dead (removed) revision in file `DamEngine/trunk/src/Deltares.DamEngine.Calculators/General/DamCalculation.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 949 refers to a dead (removed) revision in file `DamEngine/trunk/src/Deltares.DamEngine.Calculators/Stability/MStabProject.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 949 refers to a dead (removed) revision in file `DamEngine/trunk/src/Deltares.DamEngine.Calculators/General/CalculationHelper.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 949 refers to a dead (removed) revision in file `DamEngine/trunk/src/Deltares.DamEngine.Calculators/General/DamProjectCalculator.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStabilityCommon/CalculationHelper.cs =================================================================== diff -u -r929 -r949 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStabilityCommon/CalculationHelper.cs (.../General/CalculationHelper.cs) (revision 929) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStabilityCommon/CalculationHelper.cs (.../KernelWrappers/DamMacroStabilityCommon/CalculationHelper.cs) (revision 949) @@ -19,199 +19,22 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Text.RegularExpressions; -using System.Xml.Linq; -using Deltares.DamEngine.Calculators.Dikes_Operational; -using Deltares.DamEngine.Calculators.PlLinesCreator; -using Deltares.DamEngine.Calculators.Stability; using Deltares.DamEngine.Calculators.Uplift; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.General.PlLines; -using Deltares.DamEngine.Data.General.Results; using Deltares.DamEngine.Data.Geotechnics; -namespace Deltares.DamEngine.Calculators.General +namespace Deltares.DamEngine.Calculators.KernelWrappers.DamMacroStabilityCommon { - public class StabilityProjectFileCreationArguments - { - public string DikeName { get; set; } - public Location Location { get; set; } - public int EntryCount { get; set; } - public DateTime EntryDateTime { get; set; } - public MStabModelType Model { get; set; } - public string StabilityWorkingPath { get; set; } - public string SoilGeometry2DName { get; set; } - public SoilProfileType SoilProfileType { get; set; } - public PLLines PLLines { get; set; } - public FailureMechanismSystemType FailureMechanismType { get; set; } - public MStabParameters StabilityParameters { get; set; } - public string StabilityExePath { get; set; } - } - + internal class CalculationHelper { - internal static string CreateStabilityProjectFile(StabilityProjectFileCreationArguments arg) - { - var location = arg.Location; - var model = arg.Model; - - var fileName = GetProjectFileName(arg.DikeName, location, null, model, arg.StabilityWorkingPath, arg.EntryDateTime); - - // get all the parameters needed for the calculation - var damCalculation = GetCalculationSpecification(arg, fileName); - - // Create the project file - CreateMStabProjectFile(damCalculation.FailureMechanismParametersMStab, arg.StabilityExePath); - - return fileName; - } - - - internal static IEnumerable GetStabilityModels(bool isCombinedBishopUpliftVan, Location location, PLLines plLines, string soilGeometry2DName, MStabModelType defaultModel) - { - double? upliftFactor = GetLowestUpliftFactor(location.SurfaceLine, - location.GetMostProbableProfile(FailureMechanismSystemType.StabilityInside), soilGeometry2DName, plLines, location); - return !isCombinedBishopUpliftVan ? new List { defaultModel } : GetMStabModelsToCalculate(upliftFactor); - } - - internal static DamFailureMechanismeCalculationSpecification GetCalculationSpecification(StabilityProjectFileCreationArguments arguments, string projectFileName) - { - return GetCalculationSpecification(arguments.FailureMechanismType, arguments.Location, - arguments.SoilGeometry2DName, arguments.SoilProfileType, - arguments.PLLines, arguments.StabilityParameters, arguments.Model, - arguments.Location.StabilityOptions.SoilDatabaseName, projectFileName); - } - - internal static DamFailureMechanismeCalculationSpecification GetCalculationSpecification( - FailureMechanismSystemType failureMechanismType, - Location location, string soilGeometry2DName, - SoilProfileType soilProfileType, - PLLines plLines, - MStabParameters mstabParameters, MStabModelType model, - string soilDatabasePath, string projectFileName) - { - // Note: local use of new calculationSpecification for now ok but might be unwanted in future when you want to use multiple specifications - var calculationSpecification = new DamFailureMechanismeCalculationSpecification(); - BuildDamCalculation(failureMechanismType, location, soilGeometry2DName, soilProfileType, plLines, mstabParameters, model, calculationSpecification, soilDatabasePath, projectFileName); - return calculationSpecification; - } - /// - /// Fill damCalculation with the appropriate values - /// - internal static void BuildDamCalculation(FailureMechanismSystemType failureMechanismType, Location location, string soilGeometry2DName, SoilProfileType soilProfileType, - PLLines plLines, MStabParameters mstabParameters, MStabModelType model, - DamFailureMechanismeCalculationSpecification damCalculation, string soilDatabasePath, string projectFileName) - { - damCalculation.FailureMechanismParametersMStab = - new FailureMechanismParametersMStab - { - Location = location, - SurfaceLine = location.SurfaceLine, - PLLines = plLines, - SoilProfile = location.GetMostProbableProfile(FailureMechanismSystemType.StabilityInside), - MStabParameters = - new MStabParameters - { - SoilDatabaseName = soilDatabasePath, - Model = model, - ProjectFileName = projectFileName, - GeometryCreationOptions = - { - SoilProfileType = soilProfileType, - SoilGeometry2DFilename = soilGeometry2DName, - MaterialForDike = location.DikeEmbankmentMaterial, - MaterialForShoulder = location.ShoulderEmbankmentMaterial, - XOffsetSoilGeometry2DOrigin = -location.XSoilGeometry2DOrigin, - IsUseOriginalPLLineAssignments = location.IsUseOriginalPLLineAssignments - } - } - }; - if (location.StabilityOptions?.TrafficLoad != null) - { - damCalculation.FailureMechanismParametersMStab.TrafficLoad = location.StabilityOptions.TrafficLoad.Value; - } - damCalculation.FailureMechanismParametersMStab.MStabParameters.GridPosition = - failureMechanismType == FailureMechanismSystemType.StabilityOutside ? MStabGridPosition.Left : MStabGridPosition.Right; - - MStabParameters parameters = damCalculation.FailureMechanismParametersMStab.MStabParameters; - parameters.GeometryCreationOptions.PLLineAssignment = PLLineCreationMethod2PLLineAssignment(location.ModelParametersForPLLines.PLLineCreationMethod); - if (location.IsUseOriginalPLLineAssignments) - parameters.GeometryCreationOptions.PLLineAssignment = PLLineAssignment.OrginalPLLines; - parameters.GeometryCreationOptions.IntrusionVerticalWaterPressureType = location.IntrusionVerticalWaterPressure.Value; - parameters.GeometryCreationOptions.PenetrationLength = location.ModelParametersForPLLines.PenetrationLength; - switch (failureMechanismType) - { - case FailureMechanismSystemType.StabilityOutside: - parameters.GridPosition = MStabGridPosition.Left; - break; - default: - parameters.GridPosition = MStabGridPosition.Right; - break; - } - - parameters.ShearStrength = mstabParameters.ShearStrength; - parameters.IsProbabilistic = mstabParameters.IsProbabilistic; - parameters.SearchMethod = mstabParameters.SearchMethod; - parameters.CalculationOptions = mstabParameters.CalculationOptions; - if (location.StabilityOptions?.MinimalCircleDepth != null) - { - parameters.CalculationOptions.MinimalCircleDepth = location.StabilityOptions.MinimalCircleDepth.Value; - } - - parameters.ZoneAreas = new MStabZoneAreas - { - SafetyFactorZone1A = location.ModelFactors.RequiredSafetyFactorStabilityInnerSlope.Value, - SafetyFactorZone1B = location.ModelFactors.RequiredSafetyFactorStabilityInnerSlope.Value, - DikeTableHeight = location.SurfaceLine.GetDefaultDikeTableHeight().Value, - XCoordinateDikeTopAtPolder = location.SurfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtPolder).X, - XCoordinateDikeTopAtRiver = location.SurfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtRiver).X, - XCoordinateStartRestProfile = location.SurfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtRiver).X - }; - if (location.StabilityOptions?.ZoneAreaRestSlopeCrestWidth != null) - { - parameters.ZoneAreas.DikeTableWidth = location.StabilityOptions.ZoneAreaRestSlopeCrestWidth.Value; - } - - // Slip circle definition for Uplift Van; TODO: Combine with code in StabilityCalculation - parameters.SlipCircleDefinition.Assign(mstabParameters.SlipCircleDefinition); - if (parameters.Model == MStabModelType.UpliftVan) - { - // Determine right side of slip plane grid (right grid) - // This is the location with the lowest uplift factor - SurfaceLine2 surfaceLine = location.SurfaceLine; - var upliftLocationAndResult = GetLocationWithLowestUpliftFactor(surfaceLine, location.GetMostProbableProfile(FailureMechanismSystemType.StabilityInside), soilGeometry2DName, plLines, location); - double upliftCriterion = location.UpliftCriterionStability.Value; - bool isUplift = !(upliftLocationAndResult == null) && (upliftLocationAndResult.UpliftFactor < upliftCriterion); - double xCoordinateLastUpliftPoint = isUplift ? upliftLocationAndResult.X : surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtPolder).X; - parameters.SlipCircleDefinition.XCoordinateLastUpliftPoint = xCoordinateLastUpliftPoint; - } - - if (parameters.CalculationOptions.ZonesType.Equals(MStabZonesType.ForbiddenZone)) - { - var surfaceLine = damCalculation.FailureMechanismParametersMStab.SurfaceLine; - double maxZoneX = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtPolder).X + - location.StabilityOptions.ForbiddenZoneFactor.Value * (surfaceLine.GetDikeToeInward().X - surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtPolder).X); - parameters.ForbiddenZone = new MStabForbiddenZone - { - IsXEntryMinUsed = false, - XEntryMin = 0.0, - IsXEntryMaxUsed = true, - XEntryMax = maxZoneX - }; - } - } - - /// /// Converts PLLineCreationMethod (from location) to PLLineAssignment /// /// The pl line creation method. /// the pl line assignment method - public static PLLineAssignment PLLineCreationMethod2PLLineAssignment(PLLineCreationMethod plLineCreationMethod) + public static PLLineAssignment PlLineCreationMethod2PlLineAssignment(PLLineCreationMethod plLineCreationMethod) { PLLineAssignment plLineAssignment = PLLineAssignment.ExpertKnowledge; switch (plLineCreationMethod) @@ -234,7 +57,7 @@ /// The pl lines. /// The location. /// - static public UpliftLocationAndResult GetLocationWithLowestUpliftFactor(SurfaceLine2 surfaceLine, SoilProfile1D soilProfile, string soilGeometry2DName, PLLines plLines, Location location) + public static UpliftLocationAndResult GetLocationWithLowestUpliftFactor(SurfaceLine2 surfaceLine, SoilProfile1D soilProfile, string soilGeometry2DName, PLLines plLines, Location location) { UpliftLocationDeterminator upliftLocationDeterminator = new UpliftLocationDeterminator() { @@ -247,225 +70,6 @@ XSoilGeometry2DOrigin = location.XSoilGeometry2DOrigin }; return upliftLocationDeterminator.GetLocationAtWithLowestUpliftFactor(); - } - - /// - /// Calculate all generated MStab files - /// - /// - /// - internal static void CalculateMStabProjects(string directory, string mstabExePath) - { - var agent = new StabilityServiceAgent { MStabExePath = mstabExePath }; - agent.CalculateMStabDirectory(directory); - } - - /// - /// Calculate all generated MStab files - /// - internal static void CalculateMStabProjects(IEnumerable projectFilenames, string stabilityExePath) - { - var agent = new StabilityServiceAgent { MStabExePath = stabilityExePath }; - foreach (string mstabProjectFilename in projectFilenames) - { - string mstabProjectFullFilename = Path.GetFullPath(mstabProjectFilename); - agent.CalculateMStabProject(mstabProjectFullFilename); - } - } - - /// - /// Determine name of Stability project file - /// - internal static string GetProjectFileName(string dikeName, Location location, int? jobCount, MStabModelType? model, string stabilityWorkingPath, DateTime? dateTime) - { - string calculationName = String.Format("Dik({0})_Loc({1})", dikeName, location.Name); - if (jobCount != null) - { - calculationName = calculationName + String.Format("_Stp({0})", jobCount); - } - if (model != null) - { - calculationName = calculationName + String.Format("_Mdl({0})", model); - } - if (dateTime != null) - { - calculationName = calculationName + "_" + DateToTimeStamp(dateTime.Value); - } - calculationName = Regex.Replace(calculationName, @"[\\\/:\*\?""'<>|.]", "_"); - // assemble the target project file name - return Path.Combine(stabilityWorkingPath, calculationName + ".sti"); - } - - /// - /// Convert Date to time stamp as needed by TNO AnySense. - /// - /// The date time. - /// - public static string DateToTimeStamp(DateTime dateTime) - { - // Following 2 lines is an example how to handle customization of this format. - // TNO at the last moment decided they did not need this change so we change it back to - // the default format - // string customFormat = "yyyy-MM-dd_HH-mm-ss"; - // return dateTime.ToString(customFormat); - return dateTime.ToString("s", DateTimeFormatInfo.InvariantInfo); - } - - /// - /// Select which models to calculate dependent on uplift factor - /// - internal static IList GetMStabModelsToCalculate(double? upliftFactor) - { - const double CBishopMinimum = 1.0; - const double CLiftVanMaximum = 1.2; - - var models = new List(); - - if (!upliftFactor.HasValue || upliftFactor >= CBishopMinimum) - models.Add(MStabModelType.Bishop); - if (!upliftFactor.HasValue || upliftFactor <= CLiftVanMaximum) - models.Add(MStabModelType.UpliftVan); - - return models; - } - - /// - /// Determine where lowest uplift factor occurs and the value of that factor - /// - internal static double? GetLowestUpliftFactor(SurfaceLine2 surfaceLine, SoilProfile1D soilProfile, string soilGeometry2DName, PLLines plLines, Location location) - { - var upliftLocationDeterminator = new UpliftLocationDeterminator() - { - SurfaceLine = surfaceLine, - SoilProfile = soilProfile, - SoilGeometry2DName = soilGeometry2DName, - SoilList = location.SoilList, - DikeEmbankmentMaterial = location.GetDikeEmbankmentSoil(), - PLLines = plLines, - XSoilGeometry2DOrigin = location.XSoilGeometry2DOrigin - }; - - UpliftLocationAndResult upliftLocationAndResult = upliftLocationDeterminator.GetLocationAtWithLowestUpliftFactor(); - if (upliftLocationAndResult != null) - return upliftLocationAndResult.UpliftFactor; - - return null; - } - - /// - /// Creates all PL lines. - /// - /// The water level. - /// The location. - /// Name of the soil geometry2 D. - /// Type of the soil geometry. - /// - internal static PLLines CreateAllPLLines(double waterLevel, Location location, string soilGeometry2DName, SoilProfileType soilProfileType) - { - // When calculating with timeseries, we want PL3 and PL4 to derive the head from the waterlevel. - // We can force that by overruling the location HeadPl3 and HeadPl4 with null, - // because then in PLLinesCreator the waterlevel is used as head for Pl3 and Pl4 - // for stability this must set to true - var plLinesCreator = new PLLinesCreator - { - WaterLevelRiverHigh = waterLevel, - SurfaceLine = location.SurfaceLine, - WaterLevelPolder = location.PolderLevel, - HeadInPLLine2 = location.HeadPl2, - HeadInPLLine3 = null, - HeadInPLLine4 = null, - ModelParametersForPLLines = location.ModelParametersForPLLines, - SoilProfile = location.GetMostProbableProfile(FailureMechanismSystemType.StabilityInside), - SoilGeometry2DName = soilGeometry2DName, - SoilProfileType = soilProfileType, - GaugePLLines = location.GaugePLLines, - Gauges = location.Gauges, - GaugeMissVal = location.GaugeMissVal, - IsAdjustPL3AndPL4SoNoUpliftWillOccurEnabled = true, - PlLineOffsetBelowDikeTopAtRiver = location.PlLineOffsetBelowDikeTopAtRiver, - PlLineOffsetBelowDikeTopAtPolder = location.PlLineOffsetBelowDikeTopAtPolder, - PlLineOffsetBelowDikeCrestMiddle = location.PlLineOffsetBelowDikeCrestMiddle, - PlLineOffsetFactorBelowShoulderCrest = location.PlLineOffsetFactorBelowShoulderCrest, - UsePlLineOffsetBelowDikeCrestMiddle = location.UsePlLineOffsetBelowDikeCrestMiddle, - UsePlLineOffsetFactorBelowShoulderCrest = location.UsePlLineOffsetFactorBelowShoulderCrest, - SoilList = location.SoilList, - DikeEmbankmentMaterial = location.SoilList.GetSoilByName(location.DikeEmbankmentMaterial), - XSoilGeometry2DOrigin = location.XSoilGeometry2DOrigin - }; - - PLLines plLines = plLinesCreator.CreateAllPLLines(location); - return plLines; - } - - /// - /// Create and write the XML definiton file for the MStab project - /// Call the stability agent to create the stability project file - /// - internal static void CreateMStabProjectFile(FailureMechanismParametersMStab failureMechanismParametersMStab, string stabilityExePath) - { -// var assembler = new DamMStabAssembler(); -// XDocument xDocument = assembler.CreateDataTransferObject(failureMechanismParametersMStab); -// var fileName = failureMechanismParametersMStab.MStabParameters.ProjectFileName + ".xml"; -// xDocument.Save(fileName); -// -// // call the stability agent to create a MStab specific (xml) file -// var agent = new StabilityServiceAgent { MStabExePath = stabilityExePath }; -// agent.CreateProjectFile(xDocument.ToString()); ##Bka: to be rplaced by interface call to kernel. - } - - /// - /// Determine the minimal safety factor for a set of MStab projects - /// - internal static double DetermineSafetyFactor(IEnumerable mstabProjectPaths, ref string basisFileName, string stabilityExePath) - { - var agent = new StabilityServiceAgent { MStabExePath = stabilityExePath }; - - double? minimumSafetyFactor = null; - - foreach (string path in mstabProjectPaths) - { - MStabResults mStabResults = agent.ExtractStabilityResults(path); - if (!minimumSafetyFactor.HasValue || mStabResults.zone1.safetyFactor < minimumSafetyFactor) - { - minimumSafetyFactor = mStabResults.zone1.safetyFactor; - basisFileName = path; - } - } - - return minimumSafetyFactor ?? 0; - } - - /// - /// Determines the type of the soil geometry (1D or 2D). - /// - /// The location. - /// Type of the soil geometry. - /// Name of the soil geometry2 D. - internal static void DetermineSoilGeometryType(Location location, out SoilProfileType soilProfileType, out string soilGeometry2DName) - { - SoilProfile1D soilProfile = location.GetMostProbableProfile(FailureMechanismSystemType.StabilityInside); - soilGeometry2DName = location.GetMostProbableGeometry2DName(FailureMechanismSystemType.StabilityInside); - string mapForSoilGeometries2D = ""; - if (location.StabilityOptions != null) - { - mapForSoilGeometries2D = location.StabilityOptions.MapForSoilGeometries2D; - } - if ((soilGeometry2DName != null) && (mapForSoilGeometries2D != null)) - { - soilGeometry2DName = Path.Combine(mapForSoilGeometries2D, soilGeometry2DName); - } - if (soilProfile != null) - { - soilProfileType = SoilProfileType.ProfileType1D; - } - else - { - if (soilGeometry2DName == null) - { - throw new TimeSerieStabilityCalculatorException(String.Format("Location {0} does not have a soilprofile assigned", location.Name)); - } - soilProfileType = SoilProfileType.ProfileTypeStiFile; - } - } + } } } \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStabilityCommon/MStabXmlDoc.cs =================================================================== diff -u -r929 -r949 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStabilityCommon/MStabXmlDoc.cs (.../MStabXmlDoc.cs) (revision 929) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/DamMacroStabilityCommon/MStabXmlDoc.cs (.../MStabXmlDoc.cs) (revision 949) @@ -89,7 +89,7 @@ failureMechanismParametersMStab.MStabParameters.GeometryCreationOptions.XOffsetSoilGeometry2DOrigin = -scenario.Location.XSoilGeometry2DOrigin; failureMechanismParametersMStab.MStabParameters.GeometryCreationOptions.PLLineAssignment = - CalculationHelper.PLLineCreationMethod2PLLineAssignment(scenario.Location.ModelParametersForPLLines.PLLineCreationMethod); + CalculationHelper.PlLineCreationMethod2PlLineAssignment(scenario.Location.ModelParametersForPLLines.PLLineCreationMethod); if (scenario.Location.IntrusionVerticalWaterPressure != null) failureMechanismParametersMStab.MStabParameters.GeometryCreationOptions.IntrusionVerticalWaterPressureType = scenario.Location.IntrusionVerticalWaterPressure.Value; Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesAssessmentRegional/RWScenariosCalculation.cs =================================================================== diff -u -r946 -r949 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesAssessmentRegional/RWScenariosCalculation.cs (.../RWScenariosCalculation.cs) (revision 946) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesAssessmentRegional/RWScenariosCalculation.cs (.../RWScenariosCalculation.cs) (revision 949) @@ -34,7 +34,6 @@ using Deltares.DamEngine.Data.Standard.Calculation; using Deltares.DamEngine.Data.Standard.Language; using Deltares.DamEngine.Data.Standard.Logging; -using Deltares.Stability.Calculation; namespace Deltares.DamEngine.Calculators.Dikes_Assessment_Regional { @@ -421,35 +420,34 @@ /// private void ProcessJobStability(RWScenarioProfileResult job) { - StabilityCalculation calculator = new StabilityCalculation(); +// StabilityCalculation calculator = new StabilityCalculation(); - lock (runningJobs) - { - runningJobs[calculator] = job; - } +// lock (runningJobs) +// { +// runningJobs[calculator] = job; +// } // calculator.MStabExePath = this.MStabExePath; - calculator.RegisterSendMessage(this.SendStabilityMessage); - - string soilDatabaseName = job.Location.StabilityOptions.SoilDatabaseName; -// DamFailureMechanismeCalculationSpecification damCalculation = -// calculator.GetSpecification(this.evaluationJob.DikeName, soilDatabaseName, job.Location, new SoilGeometry(job.SoilGeometryProbability.SoilProfile1D, null), -// (MStabModelType)job.MstabModelOption, job.LoadSituation, job.DikeDrySensitivity, job.HydraulicShortcutType, MStabParameters); +// calculator.RegisterSendMessage(this.SendStabilityMessage); // -// calculator.SaveToFile(damCalculation.FailureMechanismParametersMStab); +// string soilDatabaseName = job.Location.StabilityOptions.SoilDatabaseName; + // DamFailureMechanismeCalculationSpecification damCalculation = + // calculator.GetSpecification(this.evaluationJob.DikeName, soilDatabaseName, job.Location, new SoilGeometry(job.SoilGeometryProbability.SoilProfile1D, null), + // (MStabModelType)job.MstabModelOption, job.LoadSituation, job.DikeDrySensitivity, job.HydraulicShortcutType, MStabParameters); + // + // calculator.SaveToFile(damCalculation.FailureMechanismParametersMStab); + // string inputFile = damCalculation.FailureMechanismParametersMStab.MStabParameters.ProjectFileName; + // + // job.BaseFileName = inputFile.Replace(DamProject.OldProjectWorkingPath, @"").Replace(".sti", ""); -// string inputFile = damCalculation.FailureMechanismParametersMStab.MStabParameters.ProjectFileName; -// -// job.BaseFileName = inputFile.Replace(DamProject.OldProjectWorkingPath, @"").Replace(".sti", ""); - // calculator.Load(inputFile); - job.CalculationResult = calculator.Run(); +// job.CalculationResult = calculator.Run(); if (job.CalculationResult == CalculationResult.Succeeded) { string results = ""; - job.CalculationResult = calculator.GetResults(ref results); +// job.CalculationResult = calculator.GetResults(ref results); //XmlDeserializer deserializer = new XmlDeserializer(); // RWResult result = (RWResult)deserializer.XmlDeserializeFromString(results, typeof(RWResult)); @@ -467,7 +465,7 @@ lock (runningJobs) { - runningJobs.Remove(calculator); +// runningJobs.Remove(calculator); } } Fisheye: Tag 949 refers to a dead (removed) revision in file `DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesOperational/TimeSerieStabilityCalculator.cs'. Fisheye: No comparison available. Pass `N' to diff?