// Copyright (C) Stichting Deltares 2019. 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 Deltares.DamEngine.Calculators.Uplift;
using Deltares.DamEngine.Data.General;
using Deltares.DamEngine.Data.General.PlLines;
using Deltares.DamEngine.Data.General.Sensors;
using Deltares.DamEngine.Data.Geotechnics;
namespace Deltares.DamEngine.Calculators.KernelWrappers.Common
{
///
/// Helper for Uplift
///
public class UpliftHelper
{
///
/// Determines the stability uplift situation.
///
/// The dam kernel input.
/// if set to true [use rivel level low].
/// The uplift situation
public static UpliftSituation DetermineStabilityUplift(DamKernelInput damKernelInput, bool useRivelLevelLow)
{
UpliftSituation upliftSituation;
var plLines = DeterminePlLinesForStability(damKernelInput, useRivelLevelLow, out upliftSituation);
upliftSituation.IsUplift = DetermineIsUplift(plLines, damKernelInput.Location, damKernelInput.SubSoilScenario);
return upliftSituation;
}
///
/// Determines the pl lines for stability.
///
/// The dam kernel input.
/// if set to true [use rivel level low].
/// The uplift situation.
/// pl lines
public static PlLines DeterminePlLinesForStability(DamKernelInput damKernelInput, bool useRivelLevelLow,
out UpliftSituation upliftSituation)
{
var riverLevel = damKernelInput.RiverLevelHigh;
double? riverLevelLow = null;
if (useRivelLevelLow)
{
riverLevelLow = damKernelInput.RiverLevelLow;
}
SensorPlLineCreatorSettings sensorPlLineCreatorSettings = new SensorPlLineCreatorSettings();
sensorPlLineCreatorSettings.SensorLocation = damKernelInput.Location.SensorLocation;
sensorPlLineCreatorSettings.DateTime = damKernelInput.TimeStepDateTime;
var plLines = PlLinesHelper.CreatePlLinesForStability(damKernelInput.Location, damKernelInput.SubSoilScenario, riverLevel,
riverLevelLow, sensorPlLineCreatorSettings, out upliftSituation);
return plLines;
}
///
/// Determines if there is uplift.
///
/// The pl lines.
/// The location.
/// The sub soil scenario.
/// true if there is uplift
public static bool DetermineIsUplift(PlLines plLines, Location location, SoilGeometryProbability subSoilScenario)
{
var isUplift = false;
var upliftCriterion = location.ModelFactors.UpliftCriterionStability;
if (plLines != null)
{
var surfaceLineWithNewHeight = location.SurfaceLine;
double? upliftFactor = GetLowestUpliftFactor(surfaceLineWithNewHeight,
subSoilScenario.SoilProfile1D, subSoilScenario.FullStiFileName,
subSoilScenario.SoilProfile2D, plLines, location);
isUplift = (upliftFactor < upliftCriterion);
}
return isUplift;
}
private static double? GetLowestUpliftFactor(SurfaceLine2 surfaceLine, SoilProfile1D soilProfile1D, string soilGeometry2DName,
SoilProfile2D soilProfile2D, PlLines plLines, Location location)
{
var upliftLocationDeterminator = new UpliftLocationDeterminator()
{
SurfaceLine = surfaceLine,
SoilProfile = soilProfile1D,
SoilProfile2D = soilProfile2D,
SoilGeometry2DName = soilGeometry2DName,
SoilList = location.SoilList,
DikeEmbankmentMaterial = location.GetDikeEmbankmentSoil(),
PlLines = plLines,
XSoilGeometry2DOrigin = location.XSoilGeometry2DOrigin
};
UpliftLocationAndResult upliftLocationAndResult = upliftLocationDeterminator.GetLocationAtWithLowestUpliftFactor();
return upliftLocationAndResult?.UpliftFactor;
}
}
}