Skip to content

Commit

Permalink
Update tsunami bathy.h5 file
Browse files Browse the repository at this point in the history
- Saved bathy.h5 using CheckpointFile
- Made grammar/spelling updates to both .ipynb demos
  • Loading branch information
cpjordan committed Jan 18, 2024
1 parent 296c884 commit 12c12eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
21 changes: 7 additions & 14 deletions demos/01-2d-channel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"\n",
"The flow is forced by an initial perturbation in the water elevation field centred in the middle of the channel. The model solves the Shallow Water Equations which are not expanded herein for brevity.\n",
" \n",
"To run this example, it is necessary to install [firedrake](https://www.firedrakeproject.org/download.html) and [Thetis](https://thetisproject.org/download.html)\n",
"To run this example, it is necessary to install [Firedrake](https://www.firedrakeproject.org/download.html) and [Thetis](https://thetisproject.org/download.html)\n",
"\n",
"[Link to Tutorials on Thetis Website](https://thetisproject.org/documentation.html)"
]
Expand All @@ -18,7 +18,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We begin with a number of imports. Note that we use `from thetis import *` which means that we do not need to prepend `thetis.` all the time. This also automatically includes a `from firedrake import *` so that we have access to the all the firedrake objects we saw yesterday such as `RectangleMesh`, `Function`, `FunctionSpace` etc. - without having to prepend `fd` as we did then."
"We begin with a number of imports. Note that we use `from thetis import *` which means that we do not need to prepend `thetis.` all the time. This also automatically includes a `from firedrake import *` so that we have access to Firedrake objects such as `RectangleMesh`, `Function`, `FunctionSpace` etc. - without having to prepend `fd` as we did then."
]
},
{
Expand Down Expand Up @@ -60,7 +60,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can use the built in [plot](https://firedrakeproject.org/firedrake.html#firedrake.plot.plot) function of firedrake to visualise the mesh."
"We can use the built in [plot](https://firedrakeproject.org/firedrake.html#firedrake.plot.plot) function of Firedrake to visualise the mesh."
]
},
{
Expand Down Expand Up @@ -158,7 +158,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The standard output of Thetis is in the form of a `.pvd` file with an associated series of `.vtu` files (and `.pvtu` when running in parallel). For visualisation we recommend the program [paraview](https://paraview.org). This program is however not available inside this jupyter environment. Therefore we will here use hdf5 output files instead, which can be used to read back in the solution in Firedrake and Thetis (unlike the `.pvd`+`.vtu` output which cannot be read back in by Firedrake). This output can also be used as checkpoints, from which Thetis can be restarted. Here we will use the hdf5 output to read it back into Firedrake and plot it.\n",
"The standard output of Thetis is in the form of a `.pvd` file with an associated series of `.vtu` files (and `.pvtu` when running in parallel). For visualisation we recommend the program [ParaView](https://paraview.org). This program is however not available inside this jupyter environment. Therefore we will here use hdf5 output files instead, which can be used to read back in the solution in Firedrake and Thetis (unlike the `.pvd`+`.vtu` output which cannot be read back in by Firedrake). This output can also be used as checkpoints, from which Thetis can be restarted. Here we will use the hdf5 output to read it back into Firedrake and plot it.\n",
"\n",
"We select which fields to output (`'elev_2d'` for elevations and `'uv_2d'` for the 2d velocity vector):"
]
Expand Down Expand Up @@ -253,7 +253,7 @@
"source": [
"Above we set the water elevation (using key `'elev'`) on the left bounday. Alternatively, we could also prescribe the normal velocity (with key `'un'`), the full 2D velocity vector (`'uv'`) or the total flux through the boundary (`'flux'`). For all supported boundary conditions, see module [shallowwater_eq](https://thetisproject.org/thetis.html#module-thetis.shallowwater_eq).\n",
"\n",
"In order to set time-dependent boundary conditions we first define a python function that evaluates the time dependent variable:"
"In order to set time-dependent boundary conditions we first define a Python function that evaluates the time dependent variable:"
]
},
{
Expand Down Expand Up @@ -327,7 +327,7 @@
"source": [
"Note that if boundary conditions are not assigned for some boundaries (the lateral boundaries 3 and 4 in this case), Thetis assumes impermeable land conditions.\n",
"\n",
"The only missing piece is to add a mechanism that re-evaluates the boundary condition as the simulation progresses. For this purpose we use the optional update_forcings argument of the [iterate()](https://thetisproject.org/thetis.html#thetis.solver2d.FlowSolver2d.iterate) method. update_forcings is a python function that updates all time dependent [Constants](https://firedrakeproject.org/firedrake.html#firedrake.constant.Constant) or [Functions](https://firedrakeproject.org/firedrake.html#firedrake.function.Function) used to force the model. In this case we only need to update `tide_elev_const`:"
"The only missing piece is to add a mechanism that re-evaluates the boundary condition as the simulation progresses. For this purpose we use the optional update_forcings argument of the [iterate()](https://thetisproject.org/thetis.html#thetis.solver2d.FlowSolver2d.iterate) method. update_forcings is a Python function that updates all time dependent [Constants](https://firedrakeproject.org/firedrake.html#firedrake.constant.Constant) or [Functions](https://firedrakeproject.org/firedrake.html#firedrake.function.Function) used to force the model. In this case we only need to update `tide_elev_const`:"
]
},
{
Expand Down Expand Up @@ -441,7 +441,7 @@
"### Visualising the output\n",
"Information on how to visualise results can be found here [outputs and visualization page](https://thetisproject.org/outputs_and_visu.html).\n",
"\n",
"Here we will use the hdf5 output (also used for checkpointing) to read back in the solution at different timesteps and plot it using Firedrake. The following code opens the 9th output. We use `os.path.join` to combine the different parts (base outputdirectory, hdf5 sub directory, and actual filename) into a filename and then load the velocity results on the function space defined earlier using CheckpointFile."
"Here we will use the hdf5 output (also used for checkpointing) to read back in the solution at different timesteps and plot it using Firedrake. The following code opens the 9th output. We use `os.path.join` to combine the different parts (base output directory, hdf5 subdirectory, and actual filename) into a filename and then load the velocity results on the function space defined earlier using `CheckpointFile`."
]
},
{
Expand Down Expand Up @@ -1058,13 +1058,6 @@
"source": [
"In addition you will need to remove the left boundary condition as it does no longer apply!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
23 changes: 8 additions & 15 deletions demos/02-2d-tsunami.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The 1945 Makran Tsunami was a large tsunami which originated due to the 1945 Balochistan earthquake. The resulting tsunami is beielved to have killed around 4000 people along the coast of modern day Pakistan, India, Iran and Oman. Tidal records indicate that the tsunami was recorded as far as the islands of Seychells and Minicoy. Moden simulations of the tsunami indicate tsunami elevations would have been observed across the islands of the Maldives as well. \n",
"The 1945 Makran Tsunami was a large tsunami which originated due to the 1945 Balochistan earthquake. The resulting tsunami is believed to have killed around 4000 people along the coast of modern day Pakistan, India, Iran and Oman. Tidal records indicate that the tsunami was recorded as far as the islands of Seychelles and Minicoy. Modern simulations of the tsunami indicate tsunami elevations would have been observed across the islands of the Maldives as well. \n",
"\n",
"Here we will model the tsunami using elevations from actual fault estimations."
]
Expand All @@ -27,7 +27,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As usual we begin by importing the required python libraries and modules. "
"As usual we begin by importing the required Python libraries and modules. "
]
},
{
Expand All @@ -52,7 +52,7 @@
"metadata": {},
"source": [
"### Importing the mesh\n",
"Next we will import the mesh (this mesh was actually created using [qmesh](http://qmesh.org) mentioned in yesterday's lecture). Additionally we will visualise the mesh as well using the firedrake plot utility function. The plot function provides an easy way to plot of firedrake functions. "
"Next we will import the mesh and visualise it using the Firedrake plot utility function. The plot function provides an easy way to plot of Firedrake functions. "
]
},
{
Expand Down Expand Up @@ -106,7 +106,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To start of with however, we will simply use a constant depth of 2000m. The bathymetry function will be defined within the function space of piecewise linear functions (\"CG\" for Continous Galerkin and a polynomial degree of 1). We will again visualise the depth to confirm if the value is assigned across the domain."
"To start off with however, we will simply use a constant depth of 2000m. The bathymetry function will be defined within the function space of piecewise linear functions (\"CG\" for Continous Galerkin and a polynomial degree of 1). We will again visualise the depth to confirm if the value is assigned across the domain."
]
},
{
Expand Down Expand Up @@ -470,7 +470,7 @@
"source": [
"a. Instead of the constant bathymetry, load the bathymetry file provided in the runfiles folder, visualize the bathymetry and use this bathymetry to run the model. Notice any difference?\n",
"\n",
"Note that this h5 file was saved previously with the deprecated DumbCheckpoint instead of CheckpointFile, so we have to load the bathymetry a little differently, use:"
"Hint, to load the bathymetry, use:"
]
},
{
Expand All @@ -480,16 +480,9 @@
"outputs": [],
"source": [
"# NBVAL_SKIP\n",
"import h5py\n",
"\n",
"with h5py.File(\"runfiles/bathy.h5\", \"r\") as hf:\n",
" bathy_data = hf[\"fields/bathy\"][:]\n",
"\n",
"P1 = FunctionSpace(mesh, \"CG\", 1)\n",
"\n",
"# Create a Firedrake Function and assign the bathymetry data\n",
"bathymetry_2d = Function(P1)\n",
"bathymetry_2d.dat.data[:] = bathy_data;"
"with CheckpointFile(\"runfiles/bathy.h5\", 'r') as CF:\n",
" mesh = CF.load_mesh()\n",
" bathymetry_2d = CF.load_function(mesh, name=\"bathymetry\")"
]
},
{
Expand Down
Binary file modified demos/runfiles/bathy.h5
Binary file not shown.

0 comments on commit 12c12eb

Please sign in to comment.