// Copyright (C) Stichting Deltares 2025. 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.Data.Properties;
namespace Deltares.DamEngine.Data.Geotechnics;
public static class SoilProfile1DAquiferLayerCombiner
{
///
/// Combines the aquifer layers.
///
/// The 1D soil profile.
/// Name of the top layer.
/// Properties of the combined aquifer layers
/// InconsistentWaterpressureInterpolationModel
public static AquiferLayerProperties CombineLayers(SoilProfile1D soilProfile1D, string topLayerName)
{
SoilLayer1D layerWithName = soilProfile1D.GetLayerWithName(topLayerName);
var num1 = 0.0;
double diameterD70 = layerWithName.Soil.DiameterD70;
var num2 = 0.0;
int startLayerIndex = soilProfile1D.GetLayerIndexAt(layerWithName);
WaterpressureInterpolationModel interpolationModel = layerWithName.WaterpressureInterpolationModel;
for (int layerIndexAt = startLayerIndex; layerIndexAt < soilProfile1D.LayerCount && soilProfile1D.Layers[layerIndexAt].IsAquifer; ++layerIndexAt)
{
if (interpolationModel != soilProfile1D.Layers[layerIndexAt].WaterpressureInterpolationModel)
{
throw new SoilProfile1DAquiferLayerCombinerException(
string.Format(Resources.SoilProfile1DAquiferLayerCombiner_CombineLayers_InconsistentWaterpressureInterpolationModel,
soilProfile1D.Name));
}
double layerHeight = soilProfile1D.GetLayerHeight(soilProfile1D.Layers[layerIndexAt]);
num1 += layerHeight;
num2 += layerHeight * soilProfile1D.Layers[layerIndexAt].Soil.PermeabKx;
}
var aquiferLayer = new AquiferLayerProperties();
aquiferLayer.D70 = diameterD70;
aquiferLayer.Height = num1;
aquiferLayer.PermeabilityKx = num2 / num1;
return aquiferLayer;
}
public struct AquiferLayerProperties
{
public double D70 { get; set; }
public double Height { get; set; }
public double PermeabilityKx { get; set; }
}
}