// 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.IO; using System.Text.RegularExpressions; using Deltares.DamEngine.Calculators.KernelWrappers.Common; using Deltares.DamEngine.Data.General; namespace Deltares.DamEngine.Calculators.KernelWrappers.DamMacroStabilityCommon { /// /// Utility methods for DamMacroStability /// public class DamMacroStabilityUtils { /// /// Gets the name of the stability input file. /// /// The dam kernel input. /// Index of the iteration. /// The model. /// Working directory /// public static string GetStabilityInputFileName(DamKernelInput damKernelInput, int iterationIndex, MStabModelType model, string projectWorkingPath) { // Assume 2D sti-file, then check on type being 1D string soilGeometryName = Path.GetFileNameWithoutExtension(damKernelInput.SubSoilScenario.StiFileName); if (damKernelInput.SubSoilScenario.SoilProfileType == SoilProfileType.ProfileType1D) { soilGeometryName = damKernelInput.SubSoilScenario.SoilProfile1DName; } string calculationName = DetermineCalculationFilename(damKernelInput.DesignScenario.Location.Name, damKernelInput.DesignScenario.LocationScenarioID, soilGeometryName, iterationIndex); const string filenameExtension = ".sti"; string fileName = calculationName + filenameExtension; string stabilityDirectory = GetStabilityCalculationDirectory(model, projectWorkingPath); return Path.Combine(stabilityDirectory, fileName); } private static string DetermineCalculationFilename(string locationName, string scenarioName, string soilGeometryName, int iterationIndex) { string calculationName; if (iterationIndex <= 0) { calculationName = String.Format("Loc({0})_Sce({1})_Pro({2})", locationName, scenarioName, soilGeometryName); } else { calculationName = String.Format("Loc({0})_Sce({1})_Pro({2})_Ite({3})", locationName, scenarioName, soilGeometryName, iterationIndex); } return Regex.Replace(calculationName, @"[\\\/:\*\?""'<>|.]", "_"); } private static string GetStabilityCalculationDirectory(MStabModelType model, string projectWorkingPath) { string calculationBaseDirectory = projectWorkingPath; const string stabilitySubDir = @"Stability\"; string stabilityDirectory = Path.Combine(calculationBaseDirectory, stabilitySubDir); var modelSubDirectory = model.ToString(); if (modelSubDirectory != "") stabilityDirectory = Path.Combine(stabilityDirectory, modelSubDirectory); if (!Directory.Exists(stabilityDirectory)) Directory.CreateDirectory(stabilityDirectory); return stabilityDirectory; } } }