// Copyright (C) Stichting Deltares 2018. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Xml.Linq; using Deltares.DamEngine.Calculators.KernelWrappers.DamMacroStabilityCommon.Assemblers; using Deltares.DamEngine.Calculators.Stability; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.General.PlLines; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; namespace Deltares.DamEngine.Calculators.General { /// /// Exception class for Geometry2DTo1DConverter /// public class Geometry2DDataCreatorException : ApplicationException { public Geometry2DDataCreatorException(string message) : base(message) { } } /// /// Create Geometry2DData object from geometry2D file /// public class Geometry2DDataCreator { /// /// Creates the geometry2 d data from geometry 2d. /// /// The filename. /// public static Geometry2DData CreateGeometry2DDataFromGeometry2D(string filename) { var geometry2DSectionAssembler = new DAMMStabGeometry2DSectionAssembler(); var geometry2DSectionParameters = new Geometry2DSectionParameters { SoilGeometry2DName = Path.GetFullPath(filename), XCoordinateSection = 0.0 }; // this parameter is not used XDocument doc = geometry2DSectionAssembler.CreateDataTransferObject(geometry2DSectionParameters); String lxmlInput = doc.ToString(); doc.Save("Geometry2DDataInput.xml"); StringBuilder lxmlOutput = null; var stabilityServiceAgent = new StabilityServiceAgent(); stabilityServiceAgent.CreateGeometry2DDataFromGeometry2D(lxmlInput, ref lxmlOutput); XDocument docOut = XDocument.Parse(lxmlOutput.ToString()); docOut.Save("Geometry2DDataOutput.xml"); var geometry2DDataAssembler = new DAMMStabGeometry2DDataAssembler(); Geometry2DData geometry2DData = geometry2DDataAssembler.CreateOutputObject(docOut); return geometry2DData; } /// /// Creates the geometry2 d data. /// /// The location. /// The soil profile probability. /// The surface line. /// The geometry directory. /// public static Geometry2DData CreateGeometry2DData(Location location, SoilGeometryProbability soilProfileProbability, SurfaceLine2 surfaceLine, String geometryDirectory) { string geometryFilename; CreateGeometryFile(location, soilProfileProbability, geometryDirectory, out geometryFilename); return CreateGeometry2DDataFromGeometry2D(geometryFilename); } /// /// Creates the geometry file. /// /// The location. /// The soil profile probability. /// The geometry directory. /// The geometry filename. /// Geometry file (sti) is not created. private static void CreateGeometryFile(Location location, SoilGeometryProbability soilProfileProbability, String geometryDirectory, out String geometryFilename) { const int iterationIndex = -1; geometryFilename = StabilityCalculator.DetermineCalculationFilename(location.Name, "PL", soilProfileProbability.StiFileName, iterationIndex); geometryFilename = geometryFilename + ".sti"; geometryFilename = Path.Combine(geometryDirectory, geometryFilename); string soilgeometry2DFilename = null; if (soilProfileProbability.StiFileName != null) { soilgeometry2DFilename = Path.GetFullPath(Path.Combine(DamProjectData.ProjectMap, Path.Combine(location.StabilityOptions.MapForSoilGeometries2D, soilProfileProbability.StiFileName))); } var soilGeometry = new SoilGeometry(soilProfileProbability.SoilProfile1D, soilProfileProbability.StiFileName); var failureMechanismeParamatersMStab = new FailureMechanismParametersMStab(); PLLines plLines = new PLLines(); var plLine = new PLLine(); IList geometryPoints = location.SurfaceLine.Geometry.Points; plLine.Points.Add(new PLLinePoint(geometryPoints.First().X, geometryPoints.First().Z)); plLine.Points.Add(new PLLinePoint(geometryPoints.Last().X, geometryPoints.Last().Z)); plLines.Lines[PLLineType.PL1] = plLine; plLines.Lines[PLLineType.PL2] = plLine; plLines.Lines[PLLineType.PL3] = plLine; plLines.Lines[PLLineType.PL4] = plLine; failureMechanismeParamatersMStab.Location = location; failureMechanismeParamatersMStab.PLLines = plLines; failureMechanismeParamatersMStab.SoilProfile = soilGeometry.SoilProfile; failureMechanismeParamatersMStab.MStabParameters.GeometryCreationOptions.SoilProfileType = soilGeometry.SoilProfileType; failureMechanismeParamatersMStab.MStabParameters.GeometryCreationOptions.SoilGeometry2DFilename = soilgeometry2DFilename; failureMechanismeParamatersMStab.MStabParameters.GeometryCreationOptions.MaterialForDike =location.DikeEmbankmentMaterial; failureMechanismeParamatersMStab.MStabParameters.GeometryCreationOptions.MaterialForShoulder = location.ShoulderEmbankmentMaterial; failureMechanismeParamatersMStab.MStabParameters.GeometryCreationOptions.XOffsetSoilGeometry2DOrigin = -location.XSoilGeometry2DOrigin; failureMechanismeParamatersMStab.MStabParameters.SoilDatabaseName = location.StabilityOptions.SoilDatabase; failureMechanismeParamatersMStab.MStabParameters.Model = MStabModelType.Bishop; failureMechanismeParamatersMStab.MStabParameters.ProjectFileName = geometryFilename; failureMechanismeParamatersMStab.SurfaceLine = location.SurfaceLine; DamMStabAssembler assembler = new DamMStabAssembler(); XDocument mstabXml = assembler.CreateDataTransferObject(failureMechanismeParamatersMStab); mstabXml.Save(geometryFilename + ".xml"); StabilityServiceAgent stabilityServiceAgent = new StabilityServiceAgent(); stabilityServiceAgent.CreateProjectFile(mstabXml.ToString()); if (!File.Exists(geometryFilename)) { throw new DamFailureMechanismeCalculatorException("Geometry file (sti) is not created."); } } } }