// Copyright (C) Stichting Deltares and State of the Netherlands 2025. All rights reserved. // // This file is part of Riskeer. // // Riskeer is free software: you can redistribute it and/or modify // it under the terms of the GNU 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 General Public License for more details. // // You should have received a copy of the GNU 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.Linq; using Deltares.MacroStability.CSharpWrapper; using Deltares.MacroStability.CSharpWrapper.Input; using Deltares.MacroStability.CSharpWrapper.Output; using Riskeer.MacroStabilityInwards.KernelWrapper.Calculators.Input; using Riskeer.MacroStabilityInwards.KernelWrapper.Calculators.UpliftVan.Input; using Riskeer.MacroStabilityInwards.KernelWrapper.Calculators.Waternet.Input; using Riskeer.MacroStabilityInwards.KernelWrapper.Kernels.UpliftVan; using Riskeer.MacroStabilityInwards.KernelWrapper.Kernels.Waternet; using KernelPreconsolidationStress = Deltares.MacroStability.CSharpWrapper.Input.PreconsolidationStress; using SoilProfile = Deltares.MacroStability.CSharpWrapper.Input.SoilProfile; namespace Riskeer.MacroStabilityInwards.KernelWrapper.Creators.Input { /// /// Creates instances which are required /// by and . /// internal static class MacroStabilityInputCreator { /// /// Creates objects based on the given input for the Uplift Van calculation. /// /// The containing all the values required /// for performing the Uplift Van calculation. /// The collection of . /// The lookup between and . /// The . /// The . /// The calculated for daily circumstances. /// The calculated for extreme circumstances. /// The created . /// Thrown when any parameter is null. public static MacroStabilityInput CreateUpliftVan(UpliftVanCalculatorInput upliftVanInput, ICollection soils, IDictionary layerLookup, SurfaceLine surfaceLine, SoilProfile soilProfile, Waternet dailyWaternet, Waternet extremeWaternet) { if (upliftVanInput == null) { throw new ArgumentNullException(nameof(upliftVanInput)); } if (soils == null) { throw new ArgumentNullException(nameof(soils)); } if (layerLookup == null) { throw new ArgumentNullException(nameof(layerLookup)); } if (surfaceLine == null) { throw new ArgumentNullException(nameof(surfaceLine)); } if (soilProfile == null) { throw new ArgumentNullException(nameof(soilProfile)); } if (dailyWaternet == null) { throw new ArgumentNullException(nameof(dailyWaternet)); } if (extremeWaternet == null) { throw new ArgumentNullException(nameof(extremeWaternet)); } var macroStabilityInput = new MacroStabilityInput { StabilityModel = { Orientation = Orientation.Inwards, SearchAlgorithm = SearchAlgorithm.Grid, ModelOption = StabilityModelOptionType.UpliftVan, ConstructionStages = { AddConstructionStage(soilProfile, dailyWaternet, FixedSoilStressCreator.Create(layerLookup).ToList(), PreconsolidationStressCreator.Create(upliftVanInput.SoilProfile.PreconsolidationStresses).ToList()), AddConstructionStage(soilProfile, extremeWaternet) }, Soils = soils, MoveGrid = upliftVanInput.MoveGrid, MaximumSliceWidth = upliftVanInput.MaximumSliceWidth, UpliftVanCalculationGrid = UpliftVanCalculationGridCreator.Create(upliftVanInput.SlipPlane), SlipPlaneConstraints = SlipPlaneConstraintsCreator.Create(upliftVanInput.SlipPlaneConstraints), NumberOfRefinementsGrid = upliftVanInput.SlipPlane.GridNumberOfRefinements, NumberOfRefinementsTangentLines = upliftVanInput.SlipPlane.TangentLineNumberOfRefinements }, PreprocessingInput = { SearchAreaConditions = { MaxSpacingBetweenBoundaries = 0.8, OnlyAbovePleistoceen = true, AutoSearchArea = upliftVanInput.SlipPlane.GridAutomaticDetermined, AutoTangentLines = upliftVanInput.SlipPlane.TangentLinesAutomaticAtBoundaries, AutomaticForbiddenZones = upliftVanInput.SlipPlaneConstraints.AutomaticForbiddenZones }, PreConstructionStages = { AddPreConstructionStage(surfaceLine), AddPreConstructionStage(surfaceLine) } } }; SetTangentLineProperties(upliftVanInput, macroStabilityInput); return macroStabilityInput; } /// /// Creates objects based on the given input for the daily Waternet calculation. /// /// The containing all the values required /// for performing the Waternet calculation. /// The collection of . /// The . /// The . /// The created . /// Thrown when any parameter is null. public static MacroStabilityInput CreateDailyWaternetForUpliftVan(UpliftVanCalculatorInput upliftVanInput, ICollection soils, SurfaceLine surfaceLine, SoilProfile soilProfile) { if (upliftVanInput == null) { throw new ArgumentNullException(nameof(upliftVanInput)); } if (soils == null) { throw new ArgumentNullException(nameof(soils)); } if (surfaceLine == null) { throw new ArgumentNullException(nameof(surfaceLine)); } if (soilProfile == null) { throw new ArgumentNullException(nameof(soilProfile)); } return CreateWaternet(soils, surfaceLine, soilProfile, UpliftVanWaternetCreatorInputCreator.CreateDaily(upliftVanInput)); } /// /// Creates objects based on the given input for the extreme Waternet calculation. /// /// The containing all the values required /// for performing the Waternet calculation. /// The collection of . /// The . /// The . /// The created . /// Thrown when any parameter is null. public static MacroStabilityInput CreateExtremeWaternetForUpliftVan(UpliftVanCalculatorInput upliftVanInput, ICollection soils, SurfaceLine surfaceLine, SoilProfile soilProfile) { if (upliftVanInput == null) { throw new ArgumentNullException(nameof(upliftVanInput)); } if (soils == null) { throw new ArgumentNullException(nameof(soils)); } if (surfaceLine == null) { throw new ArgumentNullException(nameof(surfaceLine)); } if (soilProfile == null) { throw new ArgumentNullException(nameof(soilProfile)); } return CreateWaternet(soils, surfaceLine, soilProfile, UpliftVanWaternetCreatorInputCreator.CreateExtreme(upliftVanInput)); } /// /// Creates objects based on the given input for the Waternet calculation. /// /// The containing all the values required /// for performing the Waternet calculation. /// The created . /// Thrown when any parameter is null. public static MacroStabilityInput CreateWaternet(WaternetCalculatorInput waternetInput) { if (waternetInput == null) { throw new ArgumentNullException(nameof(waternetInput)); } LayerWithSoil[] layersWithSoil = LayerWithSoilCreator.Create(waternetInput.SoilProfile, out IDictionary _); return CreateWaternet( layersWithSoil.Select(lws => lws.Soil).ToList(), SurfaceLineCreator.Create(waternetInput.SurfaceLine), SoilProfileCreator.Create(layersWithSoil), WaternetCreatorInputCreator.Create(waternetInput)); } private static void SetTangentLineProperties(UpliftVanCalculatorInput upliftVanInput, MacroStabilityInput macroStabilityInput) { if (!upliftVanInput.SlipPlane.TangentLinesAutomaticAtBoundaries) { macroStabilityInput.PreprocessingInput.SearchAreaConditions.TangentLineNumber = upliftVanInput.SlipPlane.TangentLineNumber; macroStabilityInput.PreprocessingInput.SearchAreaConditions.TangentLineZTop = upliftVanInput.SlipPlane.TangentZTop; macroStabilityInput.PreprocessingInput.SearchAreaConditions.TangentLineZBottom = upliftVanInput.SlipPlane.TangentZBottom; } } private static MacroStabilityInput CreateWaternet(ICollection soils, SurfaceLine surfaceLine, SoilProfile soilProfile, WaternetCreatorInput waternetCreatorInput) { return new MacroStabilityInput { StabilityModel = { ConstructionStages = { new ConstructionStage { SoilProfile = soilProfile } }, Soils = soils }, PreprocessingInput = { PreConstructionStages = { new PreConstructionStage { SurfaceLine = surfaceLine, CreateWaternet = true, WaternetCreatorInput = waternetCreatorInput } } } }; } private static ConstructionStage AddConstructionStage( SoilProfile soilProfile, Waternet waternet, List fixedSoilStresses = null, List preconsolidationStresses = null) { return new ConstructionStage { SoilProfile = soilProfile, Waternet = waternet, FixedSoilStresses = fixedSoilStresses ?? new List(), PreconsolidationStresses = preconsolidationStresses ?? new List(), MultiplicationFactorsCPhiForUplift = { new MultiplicationFactorsCPhiForUplift { MultiplicationFactor = 0.0, UpliftFactor = 1.2 } } }; } private static PreConstructionStage AddPreConstructionStage(SurfaceLine surfaceLine) { return new PreConstructionStage { CreateWaternet = false, SurfaceLine = surfaceLine }; } } }