Skip to content

Commit

Permalink
feat(dstab): Added option to add excavation to dstability model (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
breinbaas authored and ElhMah committed Jan 26, 2024
1 parent 51cf354 commit f0c1a46
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
22 changes: 22 additions & 0 deletions geolib/models/dstability/dstability_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
PersistablePoint,
PersistableSoil,
PersistableStateCorrelation,
PersistableExcavation,
Scenario,
SoilCollection,
SoilCorrelation,
Expand Down Expand Up @@ -327,6 +328,9 @@ def _get_state_correlations(self, scenario_index: int, stage_index: int):
f"No state correlations found for stage {stage_index} in scenario {scenario_index}."
)

def _get_excavations(self, scenario_index: int, stage_index: int):
return self.datastructure._get_excavations(scenario_index, stage_index)

def _get_loads(self, scenario_index: int, stage_index: int):
return self.datastructure._get_loads(scenario_index, stage_index)

Expand Down Expand Up @@ -816,6 +820,24 @@ def add_state_correlation(

state_correlations.add_state_correlation(persistable_state_correlation)

def add_excavation(
self,
points: List[Point],
label: str,
notes: str = "",
scenario_index: Optional[int] = None,
stage_index: Optional[int] = None,
):
scenario_index = self.get_scenario_index(scenario_index)
stage_index = self.get_stage_index(stage_index)

persistable_excavation = PersistableExcavation(
Label=label,
Notes=notes,
Points=[PersistablePoint(X=p.x, Z=p.z) for p in points],
)
self._get_excavations(scenario_index, stage_index).append(persistable_excavation)

def add_load(
self,
load: DStabilityLoad,
Expand Down
14 changes: 14 additions & 0 deletions geolib/models/dstability/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,9 @@ class Decorations(DStabilitySubStructure):
Excavations: Optional[List[Optional[PersistableExcavation]]] = []
Id: Optional[str]

def add_excavation(self, excavation: PersistableExcavation):
self.Excavations.append(excavation)


# Calculation Settings

Expand Down Expand Up @@ -2341,6 +2344,17 @@ def _get_soil_layers(self, scenario_index: int, stage_index: int):
f"No soil layers found for stage {stage_index} in scenario {scenario_index}."
)

def _get_excavations(self, scenario_index: int, stage_index: int):
decorations_id = self.scenarios[scenario_index].Stages[stage_index].DecorationsId

for decoration in self.decorations:
if decoration.Id == decorations_id:
return decoration.Excavations

raise ValueError(
f"No excavations found for stage {stage_index} in scenario {scenario_index}."
)

def _get_loads(self, scenario_index: int, stage_index: int):
loads_id = self.scenarios[scenario_index].Stages[stage_index].LoadsId

Expand Down
27 changes: 27 additions & 0 deletions tests/models/dstability/test_dstability_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,33 @@ def test_add_calculation(self):
== AnalysisTypeEnum.BISHOP_BRUTE_FORCE
)

@pytest.mark.unittest
def test_add_excavation(self):
dm = DStabilityModel()
dm.add_layer(
[
Point(x=-50, z=-10),
Point(x=50, z=-10),
Point(x=50, z=-20),
Point(x=-50, z=-20),
],
"Sand",
)

dm.add_excavation(
points=[
Point(x=-20, z=-10),
Point(x=-10, z=-15),
Point(x=10, z=-15),
Point(x=20, z=-10),
],
label="sample excavation",
)

ex = dm._get_excavations(0, 0)
assert len(ex) == 1
assert len(ex[0].Points) == 4

@pytest.mark.unittest
def test_add_scenario(self):
# Setup
Expand Down

0 comments on commit f0c1a46

Please sign in to comment.