// 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.Data; using System.IO; using System.Text.RegularExpressions; using Deltares.DamEngine.Calculators.KernelWrappers.Common; using Deltares.DamEngine.Calculators.Properties; 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.FullStiFileName); if (damKernelInput.SubSoilScenario.SoilProfileType == SoilProfileType.ProfileType1D) { soilGeometryName = damKernelInput.SubSoilScenario.SoilProfile1DName; } string calculationName = DetermineCalculationFilename(damKernelInput.FilenamePrefix, 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 filenamePrefix, string soilGeometryName, int iterationIndex) { string calculationName; if (iterationIndex <= 0) { calculationName = String.Format("{0}_Pro({1})", filenamePrefix, soilGeometryName); } else { calculationName = String.Format("{0}_Pro({1})_Ite({2})", filenamePrefix, soilGeometryName, iterationIndex); } return Regex.Replace(calculationName, @"[\\\/:\*\?""'<>|.]", "_"); } /// /// Gets the calculation sub dir as relative path. /// /// The model. /// public static string GetCalculationSubDir(MStabModelType model) { const string stabilitySubDir = @"Stability\"; var modelSubDirectory = model.ToString(); var dir = Path.Combine(stabilitySubDir, modelSubDirectory); return dir; } private static string GetStabilityCalculationDirectory(MStabModelType model, string projectWorkingPath) { string calculationBaseDirectory = projectWorkingPath; var stabilitySubDir = GetCalculationSubDir(model); string stabilityDirectory = Path.Combine(calculationBaseDirectory, stabilitySubDir); if (!Directory.Exists(stabilityDirectory)) Directory.CreateDirectory(stabilityDirectory); return stabilityDirectory; } /// /// Throws the when macro stability kernel input is not assigned. /// /// The dam macro stability input. /// public static void ThrowWhenMacroStabilityKernelInputNull(DamMacroStabilityInput damMacroStabilityInput) { if (damMacroStabilityInput == null) { throw new NoNullAllowedException(Resources.DamMacroStabilityKernelWrapper_StabilityCalculator_NoInputObjectDefinedForMacroStability); } } /// /// Throws the when macro stability kernel output is not assigned. /// /// The dam macro stability output. /// public static void ThrowWhenMacroStabilityKernelOutputNull(DamMacroStabilityOutput damMacroStabilityOutput) { if (damMacroStabilityOutput == null) { throw new NoNullAllowedException(Resources.DamMacroStabilityKernelWrapper_PostProcess_NoOutputObjectDefinedForMacroStability); } } /// /// Throws the when macro stability dam kernel input is not assigned. /// /// The dam kernel input. /// public static void ThrowWhenMacroStabilityDamKernelInputNull(DamKernelInput damKernelInput) { if (damKernelInput == null) { throw new NoNullAllowedException(Resources.DamMacroStabilityKernelWrapper_StabilityCalculator_NoDamInputObjectDefinedForMacroStability); } } } }