B:BD[
3.85350] → [
3.85350:86291]
B:BD[
3.86291] → [
2.734:762]
∅:D[
2.762] → [
3.86317:86361]
B:BD[
3.86317] → [
3.86317:86361]
B:BD[
3.86361] → [
2.763:781]
∅:D[
2.781] → [
3.87271:88201]
B:BD[
3.87271] → [
3.87271:88201]
B:BD[
3.88201] → [
2.782:810]
∅:D[
2.810] → [
3.88227:88246]
B:BD[
3.88227] → [
3.88227:88246]
B:BD[
3.88246] → [
2.811:829]
∅:D[
2.829] → [
3.89201:92194]
B:BD[
3.89201] → [
3.89201:92194]
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a id='code_validation'></a>\n",
"\n",
"# Step 5: Code validation \\[Back to [top](#toc)\\]\n",
"$$\\label{code_validation}$$\n",
"\n",
"Here we will show plots demonstrating good agreement between `BaikalETK` and, e.g., `McLachlan` (another, trusted ETK thorn)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a id='self_validation'></a>\n",
"\n",
"## Step 5.a: Validation against [BaikalETK.BaikalETK_Pymodule](../edit/BaikalETK/BaikalETK_Pymodule.py) module \\[Back to [top](#toc)\\]\n",
"$$\\label{self_validation}$$\n",
"\n",
"As a self-validation check, we verify agreement in all codes generated by\n",
"1. this tutorial notebook, and \n",
"2. the NRPy+ [Baikal.BaikalETK_Pymodule](../edit/BaikalETK/BaikalETK_Pymodule.py) module."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# First generate all codes using BaikalETK.BaikalETK_Pymodule.BaikalETK_codegen():\n",
"gri.glb_gridfcs_list = []\n",
"\n",
"import BaikalETK.BaikalETK_Pymodule as BE\n",
"outvalrootdir = \"BaikalETK-validate\"\n",
"BE.BaikalETK_codegen(outrootdir=outvalrootdir,\n",
" FD_order=FD_order, # Finite difference order: even numbers only, starting with 2. 12 is generally unstable\n",
" LapseCondition = LapseCondition,\n",
" ShiftCondition = ShiftCondition, # Set the standard, second-order advecting-shift,\n",
" # Gamma-driving shift condition\n",
" add_stress_energy_source_terms = add_stress_energy_source_terms, # Enable stress-energy terms?\n",
" default_KO_strength = default_KO_strength)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Then compare all files generated by this notebook & the separate Python module.\n",
"import difflib\n",
"rootfiles = [f for f in os.listdir(outrootdir) if os.path.isfile(os.path.join(outrootdir, f)) and \"ccl\" in os.path.join(outrootdir, f)]\n",
"srcfiles = [f for f in os.listdir(outdir) if os.path.isfile(os.path.join(outdir, f))]\n",
"\n",
"def compare_two_files(outdir1,outdir2,filebase):\n",
" with open(os.path.join(outdir1,file)) as file1, open(os.path.join(outdir2,file)) as file2:\n",
" # Read the lines of each file\n",
" file1_lines = file1.readlines()\n",
" file2_lines = file2.readlines()\n",
" num_diffs = 0\n",
" file1_lines_noleadingwhitespace = []\n",
" for line in file1_lines:\n",
" if line.strip() == \"\": # If the line contains only whitespace, remove all leading whitespace\n",
" file1_lines_noleadingwhitespace.append(line.lstrip())\n",
" else:\n",
" file1_lines_noleadingwhitespace.append(line)\n",
" file2_lines_noleadingwhitespace = []\n",
" for line in file2_lines:\n",
" if line.strip() == \"\": # If the line contains only whitespace, remove all leading whitespace\n",
" file2_lines_noleadingwhitespace.append(line.lstrip())\n",
" else:\n",
" file2_lines_noleadingwhitespace.append(line)\n",
" for line in difflib.unified_diff(file1_lines_noleadingwhitespace, file2_lines_noleadingwhitespace, \n",
" fromfile=os.path.join(outdir1,file), \n",
" tofile =os.path.join(outdir2,file)):\n",
" sys.stdout.writelines(line)\n",
" num_diffs = num_diffs + 1\n",
" if num_diffs == 0:\n",
" print(\"PASSED: \"+file)\n",
" else:\n",
" print(\"FAILED (see diff above): \"+file)\n",
"\n",
"print(\"Ignoring lines with only whitespace:\")\n",
"for file in rootfiles:\n",
" compare_two_files(outrootdir,outvalrootdir,file)\n",
"for file in srcfiles:\n",
" compare_two_files(outdir,os.path.join(outvalrootdir,\"src\"),file)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a id='latex_pdf_output'></a>\n",
"\n",
"# Step 6: Output this notebook to $\\LaTeX$-formatted PDF file \\[Back to [top](#toc)\\]\n",
"$$\\label{latex_pdf_output}$$\n",
"\n",
"The following code cell converts this Jupyter notebook into a proper, clickable $\\LaTeX$-formatted PDF file. After the cell is successfully run, the generated PDF may be found in the root NRPy+ tutorial directory, with filename\n",
"[Tutorial-BaikalETK.pdf](Tutorial-BaikalETK.pdf) (Note that clicking on this link may not work; you may need to open the PDF file through another means.)"