# Copyright (C) Stichting Deltares 2021. All rights reserved. # # This file is part of the Dam Python Interface. # # The Dam Python Interface 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. from typing import List import pytest from pathlib import Path from dampythoninterface.input import DamInput, FailureMechanismSystem, StabilityType from dampythoninterface.surface_line import SurfaceLine, PointTypeEnum, Point from dampythoninterface.soil import Soil, ShearStrengthModelType, DilatancyTypeModel from dampythoninterface.stability_parameters import ( SearchMethodType, StabilityParameters, BishopTangentLinesDefinitionType, GridDeterminationType, ) from dampythoninterface.segment import ( Segment, SoilProfileTypeClass, SoilGeometryProbabilityElement, SegmentFailureMechanismTypeClass, ) from dampythoninterface.soilprofile1D import ( SoilProfile1D, Layer1D, WaterpressureInterpolationModelType, ) from dampythoninterface.location import ( DesignScenario, Location, DesignOptions, StabilityDesignMethodType, WaternetOptions, PhreaticLineCreationMethodType, StabilityOptions, IntrusionVerticalWaterPressureType, DikeSoilScenarioType, ZoneTypeClass, ) from .utils import TestUtils class TestDamInput: def define_locations(self) -> List[Location]: designoptions = DesignOptions( RedesignDikeHeight=True, RedesignDikeShoulder=True, ShoulderEmbankmentMaterial="Ophoogmateriaal_berm", StabilityShoulderGrowSlope="0.33", StabilityShoulderGrowDeltaX="1", StabilitySlopeAdaptionDeltaX="1", SlopeAdaptionStartCotangent="3", SlopeAdaptionEndCotangent="6", SlopeAdaptionStepCotangent="0.5", UseNewDitchDefinition=False, StabilityDesignMethod=StabilityDesignMethodType.OptimizedSlopeAndShoulderAdaption, ) waternet_options = WaternetOptions( PhreaticLineCreationMethod=PhreaticLineCreationMethodType.ExpertKnowledgeRRD, DampingFactorPl3=0, DampingFactorPl4=0, PenetrationLength=0, SlopeDampingFactor=0, IntrusionVerticalWaterPressure=IntrusionVerticalWaterPressureType.Standard, DikeSoilScenario=DikeSoilScenarioType.ClayDikeOnClay, ) design_scenario = DesignScenario( Id="1", RiverLevel=3.8, RiverLevelLow=2.5, DikeTableHeight=4, PlLineOffsetBelowDikeTopAtRiver=0.5, PlLineOffsetBelowDikeTopAtPolder=1, PlLineOffsetBelowShoulderBaseInside=0, PlLineOffsetBelowDikeToeAtPolder=0, HeadPl3=3.6, UpliftCriterionStability=1.2, UpliftCriterionPiping=1.2, RequiredSafetyFactorStabilityInnerSlope=1.22, RequiredSafetyFactorStabilityOuterSlope=1.16, RequiredSafetyFactorPiping=1.2, PolderLevel=0, HeadPl2=0, ) stabilility_options = StabilityOptions( MapForSoilgeometries2D="", SoilDatabaseName="NewPipingVoorbeeld10.soilmaterials.mdb", ZoneType=ZoneTypeClass.NoZones, ForbiddenZoneFactor=1, TrafficLoad=13.3, MinimumCircleDepth=1.5, ) # define location return [ Location( SurfaceLineName="Profiel 1", SegmentName="1", Name="Profiel 1", DikeEmbankmentMaterial="Ophoogmateriaal_dijk", XSoilGeometry2DOrigin=0, DistanceToEntryPoint=0, StabilityOptions=stabilility_options, DesignScenarios=[design_scenario], WaternetOptions=waternet_options, DesignOptions=designoptions, ) ] def define_segment(self, soil_profile_names: List[str]) -> List[Segment]: # first define the soil layers profile_1 = SoilGeometryProbabilityElement( SoilProfileName=soil_profile_names[0], SoilProfileType=SoilProfileTypeClass.ProfileType1D, Probability=1, SegmentFailureMechanismType=SegmentFailureMechanismTypeClass.Stability, ) profile_2 = SoilGeometryProbabilityElement( SoilProfileName=soil_profile_names[1], SoilProfileType=SoilProfileTypeClass.ProfileType1D, Probability=1, SegmentFailureMechanismType=SegmentFailureMechanismTypeClass.Piping, ) return [Segment(Name="1", SoilGeometryProbability=[profile_1, profile_2])] def create_surface_lines(self) -> List[SurfaceLine]: # Create surface lines X = [0, 10, 19, 20.5, 23, 23, 35, 100] Z = [1, 1, 4, 4, 4, 4, 0, 0] PointTypeList = [1, 5, 8, 10, 11, 12, 15, 25] list_of_points = [ Point( X=X[counter], Z=Z[counter], PointType=PointTypeEnum(PointTypeList[counter]), ) for counter, point_type in enumerate(X) ] surfaceline_1 = SurfaceLine(Points=list_of_points, Name="Profiel 1") # check initial expectations assert surfaceline_1.Name == "Profiel 1" return [surfaceline_1] def create_soils(self) -> List[Soil]: soil_1 = Soil( Name="Dijkmateriaal", BeddingAngle=37, DiameterD70=0.00019999999999999998, PermeabKx=0.0004, WhitesConstant=0.25, AbovePhreaticLevel=17, BelowPhreaticLevel=17, DryUnitWeight=0.01, ShearStrengthModel=ShearStrengthModelType.CPhi, UseDefaultShearStrengthModel=False, Cohesion=0.5, FrictionAngle=22, DilatancyType=DilatancyTypeModel.Phi, RRatio=1, StrengthIncreaseExponent=0.7, RatioCuPc=0.22, ) soil_2 = Soil( Name="Deklaag_klei", BeddingAngle=38, DiameterD70=0.00019999999999999998, PermeabKx=0.001, WhitesConstant=0.25, AbovePhreaticLevel=16, BelowPhreaticLevel=16, DryUnitWeight=0.01, ShearStrengthModel=ShearStrengthModelType.CPhi, UseDefaultShearStrengthModel=False, Cohesion=0.5, FrictionAngle=22, DilatancyType=DilatancyTypeModel.Phi, RRatio=1, StrengthIncreaseExponent=0.7, RatioCuPc=0.22, ) soil_3 = Soil( Name="wl_zand1", BeddingAngle=39, DiameterD70=0.00020999999999999998, PermeabKx=0.0009, WhitesConstant=0.25, AbovePhreaticLevel=18, BelowPhreaticLevel=19, DryUnitWeight=0.01, ShearStrengthModel=ShearStrengthModelType.CPhi, UseDefaultShearStrengthModel=False, Cohesion=0, FrictionAngle=32, DilatancyType=DilatancyTypeModel.Phi, RRatio=1, StrengthIncreaseExponent=0.7, RatioCuPc=0.22, ) soil_4 = Soil( Name="Ophoogmateriaal_dijk", BeddingAngle=40, DiameterD70=0.00019999999999999998, PermeabKx=0.0004, WhitesConstant=0.25, AbovePhreaticLevel=17, BelowPhreaticLevel=17, DryUnitWeight=0.01, ShearStrengthModel=ShearStrengthModelType.CPhi, UseDefaultShearStrengthModel=False, Cohesion=0.5, FrictionAngle=22, DilatancyType=DilatancyTypeModel.Phi, RRatio=1, StrengthIncreaseExponent=0.7, RatioCuPc=0.22, ) soil_5 = Soil( Name="Ophoogmateriaal_berm", BeddingAngle=41, DiameterD70=0.00019999999999999998, PermeabKx=0.0004, WhitesConstant=0.25, AbovePhreaticLevel=18, BelowPhreaticLevel=19, DryUnitWeight=0.01, ShearStrengthModel=ShearStrengthModelType.CPhi, UseDefaultShearStrengthModel=False, Cohesion=0.5, FrictionAngle=22, DilatancyType=DilatancyTypeModel.Phi, RRatio=1, StrengthIncreaseExponent=0.7, RatioCuPc=0.22, ) soil_6 = Soil( Name="wl_zand2", BeddingAngle=42, DiameterD70=0.000215, PermeabKx=0.0008, WhitesConstant=0.25, AbovePhreaticLevel=18, BelowPhreaticLevel=19, DryUnitWeight=0.01, ShearStrengthModel=ShearStrengthModelType.CPhi, UseDefaultShearStrengthModel=False, Cohesion=0, FrictionAngle=32, DilatancyType=DilatancyTypeModel.Phi, RRatio=1, StrengthIncreaseExponent=0.7, RatioCuPc=0.22, ) soil_7 = Soil( Name="wl_zand3", BeddingAngle=43, DiameterD70=0.00021999999999999998, PermeabKx=0.0007, WhitesConstant=0.25, AbovePhreaticLevel=18, BelowPhreaticLevel=19, DryUnitWeight=0.01, ShearStrengthModel=ShearStrengthModelType.CPhi, UseDefaultShearStrengthModel=False, Cohesion=0, FrictionAngle=32, DilatancyType=DilatancyTypeModel.Phi, RRatio=1, StrengthIncreaseExponent=0.7, RatioCuPc=0.22, ) soil_8 = Soil( Name="wl_zand4", BeddingAngle=44, DiameterD70=0.000225, PermeabKx=0.0006, WhitesConstant=0.25, AbovePhreaticLevel=18, BelowPhreaticLevel=19, DryUnitWeight=0.01, ShearStrengthModel=ShearStrengthModelType.CPhi, UseDefaultShearStrengthModel=False, Cohesion=0, FrictionAngle=32, DilatancyType=DilatancyTypeModel.Phi, RRatio=1, StrengthIncreaseExponent=0.7, RatioCuPc=0.22, ) soil_9 = Soil( Name="wl_zand5", BeddingAngle=45, DiameterD70=0.00022999999999999998, PermeabKx=0.0005, WhitesConstant=0.25, AbovePhreaticLevel=18, BelowPhreaticLevel=19, DryUnitWeight=0.01, ShearStrengthModel=ShearStrengthModelType.CPhi, UseDefaultShearStrengthModel=False, Cohesion=0, FrictionAngle=32, DilatancyType=DilatancyTypeModel.Phi, RRatio=1, StrengthIncreaseExponent=0.7, RatioCuPc=0.22, ) return [soil_1, soil_2, soil_3, soil_4, soil_5, soil_6, soil_7, soil_8, soil_9] def create_stability_parameters(self) -> StabilityParameters: return StabilityParameters( SearchMethod=SearchMethodType.Calculationgrid, GridDetermination=GridDeterminationType.Automatic, BishopTangentLinesDefinition=BishopTangentLinesDefinitionType.OnBoundaryLines, BishopTangentLinesDistance=0.25, BishopGridVerticalPointsCount=10, BishopGridVerticalPointsDistance=2.5, BishopGridHorizontalPointsCount=10, BishopGridHorizontalPointsDistance=2.5, ) def create_profiles(self, soil_names: List[str]) -> List[SoilProfile1D]: soil_layer_1 = Layer1D( Name="L0", SoilName=soil_names[0], TopLevel=10, IsAquifer=False, WaterpressureInterpolationModel=WaterpressureInterpolationModelType.Automatic, ) soil_layer_2 = Layer1D( Name="L1", SoilName=soil_names[1], TopLevel=0, IsAquifer=False, WaterpressureInterpolationModel=WaterpressureInterpolationModelType.Automatic, ) soil_layer_3 = Layer1D( Name="L2", SoilName=soil_names[2], TopLevel=-2, IsAquifer=True, WaterpressureInterpolationModel=WaterpressureInterpolationModelType.Automatic, ) return [ SoilProfile1D( Name="soilprofile_01", BottomLevel=-10, Layers1D=[soil_layer_1, soil_layer_2, soil_layer_3], ) ] @pytest.mark.integrationtest def test_soil_profiles_contain_soils(self): list_of_surface_lines = self.create_surface_lines() # create soil class soils = self.create_soils() test_stabilty_parameters = self.create_stability_parameters() soil_profiles = self.create_profiles( [soils[0].Name, "wrong soil name", "wrong soil name"] ) segments = self.define_segment([soil_profiles[0].Name, soil_profiles[0].Name]) # run test error_message = "Soil with name wrong soil name" with pytest.raises(ValueError) as e_info: DamInput( SurfaceLines=list_of_surface_lines, Soils=soils, StabilityParameters=test_stabilty_parameters, Segments=segments, SoilProfiles1D=soil_profiles, ) generated_error_message = str(e_info.value) assert error_message in generated_error_message @pytest.mark.integrationtest def test_soil_profiles_contain_segments(self): # Create surface lines list_of_surface_lines = self.create_surface_lines() # create soil class soils = self.create_soils() # Create stability parameters test_stabilty_parameters = self.create_stability_parameters() soil_profiles = self.create_profiles( [soils[0].Name, soils[1].Name, soils[1].Name] ) segments = self.define_segment([soil_profiles[0].Name, "Wrong profile"]) # run test error_message = "Wrong profile" with pytest.raises(ValueError) as e_info: DamInput( SurfaceLines=list_of_surface_lines, Soils=soils, StabilityParameters=test_stabilty_parameters, SoilProfiles1D=soil_profiles, Segments=segments, ) generated_error_message = str(e_info.value) assert error_message in generated_error_message @pytest.mark.integrationtest def test_ExportToXml(self): # Create surface lines list_of_surface_lines = self.create_surface_lines() # create soil class soils = self.create_soils() # Create stability parameters test_stabilty_parameters = self.create_stability_parameters() soil_profiles = self.create_profiles( ["Dijkmateriaal", "Deklaag_klei", "wl_zand1"] ) segments = self.define_segment([soil_profiles[0].Name, soil_profiles[0].Name]) locations = self.define_locations() # Make input class model = DamInput( SurfaceLines=list_of_surface_lines, Soils=soils, StabilityParameters=test_stabilty_parameters, SoilProfiles1D=soil_profiles, Segments=segments, Locations=locations, StabilityModelType=StabilityType.UpliftVan, FailureMechanismSystemType=FailureMechanismSystem.StabilityInside, ProjectPath=Path(""), ) assert model # run test xml_output = Path( TestUtils.get_output_test_data_dir(""), "test_full_output.xml" ) model.ExportToXml(xml_file=xml_output) # test if file was created assert xml_output.is_file()