Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 13 additions & 21 deletions wolf-sheep-soil-creep/precice-config.xml
Original file line number Diff line number Diff line change
@@ -1,69 +1,61 @@
<?xml version="1.0" encoding="UTF-8" ?>
<precice-configuration>

<log>
<sink
filter="%Severity% > debug"
format="---[precice] %ColorizedSeverity% %Message%"
enabled="true" />
</log>


<data:scalar name="Grass" />
<data:scalar name="Soil" />

<mesh name="Wolf-Sheep-Grass-Mesh" dimensions="2">
<use-data name="Grass" />
<use-data name="Soil" />
</mesh>

<mesh name="Soil-Creep-Mesh" dimensions="2">
<use-data name="Grass" />
</mesh>

<mesh name="Soil-Grass-Mesh" dimensions="2">
<use-data name="Soil" />
</mesh>

<mesh name="Soil-Depth-Mesh" dimensions="2">
<use-data name="Soil" />
</mesh>

<participant name="Wolf-Sheep-Grass">
<receive-mesh name="Soil-Depth-Mesh" from="Soil-Creep" />
<receive-mesh name="Soil-Creep-Mesh" from="Soil-Creep" />
<provide-mesh name="Wolf-Sheep-Grass-Mesh" />
<provide-mesh name="Soil-Grass-Mesh" />
<write-data name="Grass" mesh="Wolf-Sheep-Grass-Mesh" />
<read-data name="Soil" mesh="Soil-Grass-Mesh" />
<read-data name="Soil" mesh="Wolf-Sheep-Grass-Mesh" />
<mapping:nearest-neighbor
direction="read"
from="Soil-Depth-Mesh"
to="Soil-Grass-Mesh"
from="Soil-Creep-Mesh"
to="Wolf-Sheep-Grass-Mesh"
constraint="consistent" />
</participant>

<participant name="Soil-Creep">
<receive-mesh name="Wolf-Sheep-Grass-Mesh" from="Wolf-Sheep-Grass" />
<provide-mesh name="Soil-Creep-Mesh" />
<provide-mesh name="Soil-Depth-Mesh" />
<read-data name="Grass" mesh="Soil-Creep-Mesh" />
<write-data name="Soil" mesh="Soil-Depth-Mesh" />
<write-data name="Soil" mesh="Soil-Creep-Mesh" />
<mapping:nearest-neighbor
direction="read"
from="Wolf-Sheep-Grass-Mesh"
to="Soil-Creep-Mesh"
constraint="consistent" />
</participant>


<m2n:sockets acceptor="Wolf-Sheep-Grass" connector="Soil-Creep" exchange-directory=".." />


<coupling-scheme:serial-explicit>
<participants first="Soil-Creep" second="Wolf-Sheep-Grass" />
<time-window-size value="2" />
<max-time value="100" />
<exchange
data="Grass"
mesh="Wolf-Sheep-Grass-Mesh"
from="Wolf-Sheep-Grass"
to="Soil-Creep"
initialize="true" />
<exchange data="Soil" mesh="Soil-Depth-Mesh" from="Soil-Creep" to="Wolf-Sheep-Grass" />
<exchange data="Grass" mesh="Wolf-Sheep-Grass-Mesh" from="Wolf-Sheep-Grass" to="Soil-Creep" initialize="true"/>
<exchange data="Soil" mesh="Soil-Creep-Mesh" from="Soil-Creep" to="Wolf-Sheep-Grass" />
</coupling-scheme:serial-explicit>

</precice-configuration>
11 changes: 11 additions & 0 deletions wolf-sheep-soil-creep/soil-creep-fenicsx/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh
set -e -u

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"

rm -rfv ./output/

. ../../tools/cleaning-tools.sh

clean_fenicsx .
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"participant_name": "Soil-Creep",
"precice_config_file_path": "../precice-config.xml",
"interfaces": [
{
"mesh_name": "Soil-Creep-Mesh",
"write_data": [
{
"name": "Soil"
}
],
"read_data": [
{
"name": "Grass"
}
]
}
]
}
23 changes: 23 additions & 0 deletions wolf-sheep-soil-creep/soil-creep-fenicsx/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -e -u

. ../../tools/log.sh

exec > >(tee --append "$LOGFILE") 2>&1

if [ ! -v PRECICE_TUTORIALS_NO_VENV ]; then

if [ ! -d ".venv" ]; then
python3 -m venv --system-site-packages .venv
source .venv/bin/activate
pip install -r ../solver-fenicsx/requirements.txt && pip freeze > pip-installed-packages.log
else
source .venv/bin/activate
fi

fi

mkdir -p output
python3 ../solver-fenicsx/soil_creep.py

close_log
16 changes: 8 additions & 8 deletions wolf-sheep-soil-creep/soil-creep-landlab/soil_creep.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

rmg = RasterModelGrid((width, height))

solver_dt = 0.2 * rmg.dx * rmg.dx / fast_creep

# Create elevation field and have it slope down to the south at 10% gradient
elev = rmg.add_zeros("topographic__elevation", at="node")
elev[:] = 0.1 * rmg.y_of_node
Expand Down Expand Up @@ -54,24 +56,22 @@
solver_process_size = 1
participant = precice.Participant(participant_name, config_file_name, solver_process_index, solver_process_size)

positions = [[x, y] for x in range(width) for y in range(height)]
vertex_gm_ids = participant.set_mesh_vertices("Soil-Creep-Mesh", positions)
vertex_soil_ids = participant.set_mesh_vertices("Soil-Depth-Mesh", positions)
positions = [[x, y] for y in range(height) for x in range(width)]
vertex_ids = participant.set_mesh_vertices("Soil-Creep-Mesh", positions)

participant.initialize()

while participant.is_coupling_ongoing():
solver_dt = 0.2 * rmg.dx * rmg.dx / fast_creep
precice_dt = participant.get_max_time_step_size()
dt = np.minimum(solver_dt, precice_dt)

gm = participant.read_data("Soil-Creep-Mesh", "Grass", vertex_gm_ids, dt)
gm = participant.read_data("Soil-Creep-Mesh", "Grass", vertex_ids, dt)

# Assign the higher creep coefficient to cells where the grass has
# been eaten and not yet recovered; the slower value is assigned to
# "fully grown" grass patches.
creep_coef[gm.flatten() == 1] = fast_creep
creep_coef[gm.flatten() == 2] = slow_creep
creep_coef[gm == 1] = fast_creep
creep_coef[gm == 2] = slow_creep

# Limit the creep coefficient according to the soil-thickness field, so absent soil cannot move.
creep_coef *= 1.0 - np.exp(-soil / hstar)
Expand All @@ -86,7 +86,7 @@
# Update the soil cover
soil += elev - prior_elev

participant.write_data("Soil-Depth-Mesh", "Soil", vertex_soil_ids, soil)
participant.write_data("Soil-Creep-Mesh", "Soil", vertex_ids, soil)

participant.advance(dt)

Expand Down
9 changes: 9 additions & 0 deletions wolf-sheep-soil-creep/soil-creep-simplified-landlab/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env sh
set -e -u

rm -rfv ./output/

. ../../tools/cleaning-tools.sh

clean_precice_logs .
clean_case_logs .
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
numpy >1, <2
matplotlib>=3,<4
pyprecice~=3.0
21 changes: 21 additions & 0 deletions wolf-sheep-soil-creep/soil-creep-simplified-landlab/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -e -u

. ../../tools/log.sh

exec > >(tee --append "$LOGFILE") 2>&1

if [ ! -v PRECICE_TUTORIALS_NO_VENV ]; then
if [ ! -d ".venv" ]; then
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt && pip freeze > pip-installed-packages.log
else
source .venv/bin/activate
fi
fi

mkdir -p output
python3 soil_creep.py

close_log
Loading