Skip to content

Commit

Permalink
Fix the tutorial notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenrbrandt committed Mar 23, 2023
1 parent 12e9e1b commit 74ba1ce
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 25 deletions.
62 changes: 46 additions & 16 deletions tutorial-server/notebooks/CreatingANewThorn-HeatEqn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@
"The above thorn files and directories should reside in `Cactus/arrangements/ArrangementName/ThornName/`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# this allows you to use \"cd\" in cells to change directories instead of requiring \"%cd\"\n",
"%automagic on\n",
"# Keeps display scrolled to the bottom\n",
"import scrolldown\n",
"# override IPython's default %%bash to not buffer all output\n",
"from IPython.core.magic import register_cell_magic\n",
"@register_cell_magic\n",
"def bash(line, cell): get_ipython().system(cell)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -261,14 +277,16 @@
"outputs": [],
"source": [
"%%writefile {thorn_dir}/src/init.c\n",
"#include <math.h>\n",
"#include <cctk.h>\n",
"#include <cctk_Arguments.h>\n",
"#include <cctk_Parameters.h>\n",
"#include <stdio.h>\n",
"\n",
"// Initialize grid functions\n",
"void HeatEqn_Initialize(CCTK_ARGUMENTS) \n",
"{\n",
" DECLARE_CCTK_ARGUMENTS; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_ARGUMENTS_HeatEqn_Initialize; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_PARAMETERS; // Declare all parameters from param.ccl\n",
"\n",
" for (int k = 0; k < cctk_lsh[2]; k++) // loop over the z direction\n",
Expand Down Expand Up @@ -302,11 +320,12 @@
"#include <cctk.h>\n",
"#include <cctk_Arguments.h>\n",
"#include <cctk_Parameters.h>\n",
"#include <stdio.h>\n",
"\n",
"// Update grid functions at interior points\n",
"void HeatEqn_Update(CCTK_ARGUMENTS)\n",
"{\n",
" DECLARE_CCTK_ARGUMENTS; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_ARGUMENTS_HeatEqn_Update; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_PARAMETERS; // Declare all parameters from param.ccl\n",
"\n",
" const int gz = cctk_nghostzones[2];\n",
Expand Down Expand Up @@ -361,11 +380,12 @@
"#include <cctk.h>\n",
"#include <cctk_Arguments.h>\n",
"#include <cctk_Parameters.h>\n",
"#include <stdio.h>\n",
"\n",
"// Update grid functions at boundary points\n",
"void HeatEqn_Boundary(CCTK_ARGUMENTS) \n",
"{\n",
" DECLARE_CCTK_ARGUMENTS; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_ARGUMENTS_HeatEqn_Boundary; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_PARAMETERS; // Declare all parameters from param.ccl\n",
"\n",
" const int gz = cctk_nghostzones[2];\n",
Expand Down Expand Up @@ -617,16 +637,22 @@
"SCHEDULE HeatEqn_Initialize AT CCTK_INITIAL\n",
"{\n",
" LANG: C\n",
" Writes: U(Everywhere)\n",
" Reads: Grid::coordinates(Everywhere)\n",
"} \"Initialize evolved variables\"\n",
"\n",
"SCHEDULE HeatEqn_Update AT CCTK_EVOL\n",
"{\n",
" LANG: C\n",
" Writes: U(Interior)\n",
" Reads: U_p(Everywhere)\n",
"} \"Evolve the Heat equation\"\n",
"\n",
"SCHEDULE HeatEqn_Boundary AT CCTK_EVOL AFTER HeatEqn_Update\n",
"{\n",
" LANG: C\n",
" Writes: U(Boundary)\n",
" SYNC: evol_group\n",
"} \"Heat equation BC\""
]
},
Expand Down Expand Up @@ -746,12 +772,14 @@
"outputs": [],
"source": [
"# Make sure the new thorn is in our ThornList\n",
"contents = None\n",
"with open(thorn_list, 'r') as f:\n",
" contents = f.read()\n",
"if new_thorn_path not in contents:\n",
" with open(thorn_list, 'a') as f:\n",
" f.write(new_thorn_path + '\\n')\n",
"def add_thorn(new_thorn_path):\n",
" contents = None\n",
" with open(thorn_list, 'r') as f:\n",
" contents = f.read()\n",
" if new_thorn_path not in contents:\n",
" with open(thorn_list, 'a') as f:\n",
" f.write(new_thorn_path + '\\n')\n",
"add_thorn(new_thorn_path)\n",
"!tail {thorn_list}"
]
},
Expand All @@ -771,7 +799,7 @@
"outputs": [],
"source": [
"%cd {cactus_dir}\n",
"!time ./simfactory/bin/sim build --mdbkey make 'make -j2'"
"!time ./simfactory/bin/sim build -j2"
]
},
{
Expand Down Expand Up @@ -933,11 +961,13 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"%cd {cactus_dir}\n",
"!time ./simfactory/bin/sim create-run heat_eqn --parfile={par_dir}/heat_eqn.par --procs=2"
"!time ./simfactory/bin/sim create-run heat_eqn --parfile={par_dir}/heat_eqn.par --procs=1"
]
},
{
Expand Down Expand Up @@ -1008,7 +1038,7 @@
"outputs": [],
"source": [
"## create file handle\n",
"u_h5 = h5py.File(\"U.xy.h5\")"
"u_h5 = h5py.File(\"U.xy.h5\",\"r\")"
]
},
{
Expand Down Expand Up @@ -1050,8 +1080,8 @@
"outputs": [],
"source": [
"## get xdata, ydata\n",
"x_h5 = h5py.File(\"x.xy.h5\")\n",
"y_h5 = h5py.File(\"y.xy.h5\")\n",
"x_h5 = h5py.File(\"x.xy.h5\", \"r\")\n",
"y_h5 = h5py.File(\"y.xy.h5\", \"r\")\n",
"\n",
"for nm in x_h5:\n",
" if hasattr(x_h5[nm], 'shape'):\n",
Expand Down Expand Up @@ -1275,7 +1305,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
54 changes: 45 additions & 9 deletions tutorial-server/notebooks/CreatingANewThorn-WaveEqn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@
"The above thorn files and directories should reside in `Cactus/arrangements/ArrangementName/ThornName/`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# this allows you to use \"cd\" in cells to change directories instead of requiring \"%cd\"\n",
"%automagic on\n",
"# Keeps display scrolled to the bottom\n",
"import scrolldown\n",
"# override IPython's default %%bash to not buffer all output\n",
"from IPython.core.magic import register_cell_magic\n",
"@register_cell_magic\n",
"def bash(line, cell): get_ipython().system(cell)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -276,7 +292,7 @@
"// Register variables with MoL\n",
"void WaveEqn_MoLRegister(CCTK_ARGUMENTS)\n",
"{\n",
" DECLARE_CCTK_ARGUMENTS; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_ARGUMENTS_WaveEqn_MoLRegister; // Declare all grid functions from interface.ccl\n",
" CCTK_INT ierr = 0, group, rhs;\n",
"\n",
" // Look up the group index of the evol_group\n",
Expand Down Expand Up @@ -325,7 +341,7 @@
"// Initialize grid functions\n",
"void WaveEqn_Initialize(CCTK_ARGUMENTS)\n",
"{\n",
" DECLARE_CCTK_ARGUMENTS; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_ARGUMENTS_WaveEqn_Initialize; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_PARAMETERS; // Declare all parameters from param.ccl\n",
"\n",
" for (int k = 0; k < cctk_lsh[2]; k++) // loop over the z direction\n",
Expand Down Expand Up @@ -364,7 +380,7 @@
"// Update RHS functions\n",
"void WaveEqn_RHS(CCTK_ARGUMENTS)\n",
"{\n",
" DECLARE_CCTK_ARGUMENTS; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_ARGUMENTS_WaveEqn_RHS; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_PARAMETERS; // Declare all parameters from param.ccl\n",
"\n",
" const int gz = cctk_nghostzones[2];\n",
Expand Down Expand Up @@ -424,7 +440,7 @@
"// Update grid functions at boundary points\n",
"void WaveEqn_Boundary(CCTK_ARGUMENTS)\n",
"{\n",
" DECLARE_CCTK_ARGUMENTS; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_ARGUMENTS_WaveEqn_Boundary; // Declare all grid functions from interface.ccl\n",
" DECLARE_CCTK_PARAMETERS; // Declare all parameters from param.ccl\n",
"\n",
" const int gz = cctk_nghostzones[2];\n",
Expand Down Expand Up @@ -713,16 +729,23 @@
"SCHEDULE WaveEqn_Initialize AT CCTK_INITIAL\n",
"{\n",
" LANG: C\n",
" WRITES: evol_group(Everywhere)\n",
" READS: Grid::coordinates(Everywhere)\n",
"} \"Initialize evolved variables\"\n",
"\n",
"SCHEDULE WaveEqn_RHS IN MoL_CalcRHS\n",
"{\n",
" LANG: C\n",
" READS: evol_group(Everywhere)\n",
" WRITES: rhs_group(Interior)\n",
"} \"Evolve the scalar wave equation\"\n",
"\n",
"SCHEDULE WaveEqn_Boundary IN MoL_CalcRHS AFTER WaveEqn_RHS\n",
"{\n",
" LANG: C\n",
" WRITES: rhs_group(Boundary)\n",
" READS: evol_group(Boundary)\n",
" SYNC: rhs_group\n",
"} \"Scalar wave equation BC\""
]
},
Expand Down Expand Up @@ -1109,7 +1132,7 @@
"outputs": [],
"source": [
"## create file handle\n",
"u_h5 = h5py.File(\"U.xy.h5\")"
"u_h5 = h5py.File(\"U.xy.h5\", \"r\")"
]
},
{
Expand Down Expand Up @@ -1151,8 +1174,8 @@
"outputs": [],
"source": [
"## get xdata, ydata\n",
"x_h5 = h5py.File(\"x.xy.h5\")\n",
"y_h5 = h5py.File(\"y.xy.h5\")\n",
"x_h5 = h5py.File(\"x.xy.h5\", \"r\")\n",
"y_h5 = h5py.File(\"y.xy.h5\", \"r\")\n",
"\n",
"for nm in x_h5:\n",
" if hasattr(x_h5[nm], 'shape'):\n",
Expand Down Expand Up @@ -1213,7 +1236,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# set graphics backend\n",
Expand Down Expand Up @@ -1329,6 +1354,17 @@
"anim.save(file + '.gif', writer='imagemagick', fps=fps)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import Image\n",
"with open('wave_eqn.gif','rb') as f:\n",
" display(Image(data=f.read(), format='gif'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1377,7 +1413,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 74ba1ce

Please sign in to comment.