{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "\n", "# Tutorial-IllinoisGRMHD: symmetry__set_gzs_staggered_gfs.C\n", "\n", "## Authors: Leo Werneck & Zach Etienne\n", "\n", "**This module is currently under development**\n", "\n", "## In this tutorial module we explain how `IllinoisGRMHD` handles symmetry options and the ghostzones of staggered gridfunctions. This module will likely be absorbed by another one once we finish documenting the code.\n", "\n", "### Required and recommended citations:\n", "\n", "* **(Required)** Etienne, Z. B., Paschalidis, V., Haas R., Mösta P., and Shapiro, S. L. IllinoisGRMHD: an open-source, user-friendly GRMHD code for dynamical spacetimes. Class. Quantum Grav. 32 (2015) 175009. ([arxiv:1501.07276](http://arxiv.org/abs/1501.07276)).\n", "* **(Required)** Noble, S. C., Gammie, C. F., McKinney, J. C., Del Zanna, L. Primitive Variable Solvers for Conservative General Relativistic Magnetohydrodynamics. Astrophysical Journal, 641, 626 (2006) ([astro-ph/0512420](https://arxiv.org/abs/astro-ph/0512420)).\n", "* **(Recommended)** Del Zanna, L., Bucciantini N., Londrillo, P. An efficient shock-capturing central-type scheme for multidimensional relativistic flows - II. Magnetohydrodynamics. A&A 400 (2) 397-413 (2003). DOI: 10.1051/0004-6361:20021641 ([astro-ph/0210618](https://arxiv.org/abs/astro-ph/0210618))." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "# Table of Contents\n", "$$\\label{toc}$$\n", "\n", "This module is organized as follows\n", "\n", "0. [Step 0](#src_dir): **Source directory creation**\n", "1. [Step 1](#introduction): **Introduction**\n", "1. [Step 2](#symmetry__set_gzs_staggered_gfs__c): **`symmetry__set_gzs_staggered_gfs.C`**\n", "1. [Step n-1](#code_validation): **Code validation**\n", "1. [Step n](#latex_pdf_output): **Output this notebook to $\\LaTeX$-formatted PDF file**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "# Step 0: Source directory creation \\[Back to [top](#toc)\\]\n", "$$\\label{src_dir}$$\n", "\n", "We will now use the [cmdline_helper.py NRPy+ module](Tutorial-Tutorial-cmdline_helper.ipynb) to create the source directory within the `IllinoisGRMHD` NRPy+ directory, if it does not exist yet." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Step 0: Creation of the IllinoisGRMHD source directory\n", "# Step 0a: Add NRPy's directory to the path\n", "# https://stackoverflow.com/questions/16780014/import-file-from-parent-directory\n", "import os,sys\n", "nrpy_dir_path = os.path.join(\"..\",\"..\")\n", "if nrpy_dir_path not in sys.path:\n", " sys.path.append(nrpy_dir_path)\n", "\n", "# Step 0b: Load up cmdline_helper and create the directory\n", "import cmdline_helper as cmd\n", "IGM_src_dir_path = os.path.join(\"..\",\"src\")\n", "cmd.mkdir(IGM_src_dir_path)\n", "\n", "# Step 0c: Create the output file path\n", "outfile_path__symmetry__set_gzs_staggered_gfs__C = os.path.join(IGM_src_dir_path,\"symmetry__set_gzs_staggered_gfs.C\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "# Step 1: Introduction \\[Back to [top](#toc)\\]\n", "$$\\label{introduction}$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "# Step 2: `symmetry__set_gzs_staggered_gfs.C` \\[Back to [top](#toc)\\]\n", "$$\\label{symmetry__set_gzs_staggered_gfs__c}$$" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ../src/symmetry__set_gzs_staggered_gfs.C\n" ] } ], "source": [ "%%writefile $outfile_path__symmetry__set_gzs_staggered_gfs__C\n", "#include \"cctk.h\"\n", "#include \"cctk_Parameters.h\"\n", "#include \n", "#include \n", "#include \"IllinoisGRMHD_headers.h\"\n", "\n", "void IllinoisGRMHD_set_symmetry_gzs_staggered(const cGH *cctkGH, const int *cctk_lsh,CCTK_REAL *X,CCTK_REAL *Y,CCTK_REAL *Z, CCTK_REAL *gridfunc,\n", " CCTK_REAL *gridfunc_syms,int stagger_x,int stagger_y,int stagger_z) {\n", "\n", " DECLARE_CCTK_PARAMETERS;\n", "\n", " if(CCTK_EQUALS(Symmetry, \"equatorial\"))\n", " CCTK_VError(VERR_DEF_PARAMS,\"Warning: Symmetry==equatorial not supported! USE AT YOUR OWN RISK. You will need to comment this error message out.\");\n", "\n", " // No symmetries -> return.\n", " if(CCTK_EQUALS(Symmetry, \"none\")) return;\n", "\n", " CCTK_REAL dz = Z[CCTK_GFINDEX3D(cctkGH,0,0,1)] - Z[CCTK_GFINDEX3D(cctkGH,0,0,0)];\n", "\n", " CCTK_REAL z_offset = dz*0.5*stagger_z;\n", "\n", " int num_gzs=0;\n", " //FIXME: Might want to use cctk_nghostzones instead...\n", " while( (Z[CCTK_GFINDEX3D(cctkGH,0,0,num_gzs)]+z_offset) < -dz*0.1 && num_gzs=cctk_lsh[2]) CCTK_VError(VERR_DEF_PARAMS,\"ERROR in symmetry__set_gzs_staggered_gfs.C\");\n", "\n", "#pragma omp parallel for\n", " for(int k=0;k gridfunc[index 0] = gridfunc_syms[2]*gridfunc[index 1]\n", " *\n", " * if num_gzs==2 && stagger_z==1:\n", " * z[] = {-3dz/2,-dz/2,dz/2,3dz/2 etc}\n", " * -> gridfunc[index 0] = gridfunc_syms[2]*gridfunc[index 3]\n", " * -> gridfunc[index 1] = gridfunc_syms[2]*gridfunc[index 2]\n", " * .\n", " * .\n", " * .\n", " * -> gridfunc[i] = gridfunc_syms[2]*gridfunc[(num_gz*2-1)-i]\n", " *\n", " * UNSTAGGERED PATTERN:\n", " * if num_gzs==1 && stagger_z==0:\n", " * z[] = {-dz,0,dz, etc} -> gridfunc[index 0] = gridfunc_syms[2]*gridfunc[index 2]\n", " *\n", " * if num_gzs==2 && stagger_z==0:\n", " * z[] = {-2dz,-dz,0,dz,2dz, etc} -> gridfunc[index 0] = gridfunc_syms[2]*gridfunc[index 4]\n", " * z[] = {-2dz,-dz,0,dz,2dz, etc} -> gridfunc[index 1] = gridfunc_syms[2]*gridfunc[index 3]\n", " * .\n", " * .\n", " * .\n", " * -> gridfunc[i] = gridfunc_syms[2]*gridfunc[(num_gz*2)-i]\n", " *\n", " * OVERALL PATTERN: gridfunc[i] = gridfunc_syms[2]*gridfunc[(num_gz*2-stagger_z)-i] */\n", "\n", " int matching_index_outside_sym_gz = CCTK_GFINDEX3D(cctkGH,i,j,(num_gzs*2-stagger_z)-k);\n", "\n", " gridfunc[index_inside__sym_gz] = gridfunc_syms[2]*gridfunc[matching_index_outside_sym_gz];\n", " }\n", "}\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "# Step n-1: Code validation \\[Back to [top](#toc)\\]\n", "$$\\label{code_validation}$$\n", "\n", "First we download the original `IllinoisGRMHD` source code and then compare it to the source code generated by this tutorial notebook." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Validation test for symmetry__set_gzs_staggered_gfs.C: FAILED!\n", "Diff:\n", "12c12\n", "< if(CCTK_EQUALS(Symmetry, \"equatorial\")) \n", "---\n", "> if(CCTK_EQUALS(Symmetry, \"equatorial\"))\n", "34c34\n", "< * if num_gzs==1 && stagger_z==1: \n", "---\n", "> * if num_gzs==1 && stagger_z==1:\n", "37,38c37,38\n", "< * if num_gzs==2 && stagger_z==1: \n", "< * z[] = {-3dz/2,-dz/2,dz/2,3dz/2 etc} \n", "---\n", "> * if num_gzs==2 && stagger_z==1:\n", "> * z[] = {-3dz/2,-dz/2,dz/2,3dz/2 etc}\n", "64a65\n", "> \n" ] } ], "source": [ "# Verify if the code generated by this tutorial module\n", "# matches the original IllinoisGRMHD source code\n", "\n", "# First download the original IllinoisGRMHD source code\n", "import urllib\n", "from os import path\n", "\n", "original_IGM_file_url = \"https://bitbucket.org/zach_etienne/wvuthorns/raw/5611b2f0b17135538c9d9d17c7da062abe0401b6/IllinoisGRMHD/src/symmetry__set_gzs_staggered_gfs.C\"\n", "original_IGM_file_name = \"symmetry__set_gzs_staggered_gfs-original.C\"\n", "original_IGM_file_path = os.path.join(IGM_src_dir_path,original_IGM_file_name)\n", "\n", "# Then download the original IllinoisGRMHD source code\n", "# We try it here in a couple of ways in an attempt to keep\n", "# the code more portable\n", "try:\n", " original_IGM_file_code = urllib.request.urlopen(original_IGM_file_url).read().decode(\"utf-8\")\n", " # Write down the file the original IllinoisGRMHD source code\n", " with open(original_IGM_file_path,\"w\") as file:\n", " file.write(original_IGM_file_code)\n", "except:\n", " try:\n", " original_IGM_file_code = urllib.urlopen(original_IGM_file_url).read().decode(\"utf-8\")\n", " # Write down the file the original IllinoisGRMHD source code\n", " with open(original_IGM_file_path,\"w\") as file:\n", " file.write(original_IGM_file_code)\n", " except:\n", " # If all else fails, hope wget does the job\n", " !wget -O $original_IGM_file_path $original_IGM_file_url\n", "\n", "# Perform validation\n", "Validation__symmetry__set_gzs_staggered_gfs__C = !diff $original_IGM_file_path $outfile_path__symmetry__set_gzs_staggered_gfs__C\n", "\n", "if Validation__symmetry__set_gzs_staggered_gfs__C == []:\n", " # If the validation passes, we do not need to store the original IGM source code file\n", " !rm $original_IGM_file_path\n", " print(\"Validation test for symmetry__set_gzs_staggered_gfs.C: PASSED!\")\n", "else:\n", " # If the validation fails, we keep the original IGM source code file\n", " print(\"Validation test for symmetry__set_gzs_staggered_gfs.C: FAILED!\")\n", " # We also print out the difference between the code generated\n", " # in this tutorial module and the original IGM source code\n", " print(\"Diff:\")\n", " for diff_line in Validation__symmetry__set_gzs_staggered_gfs__C:\n", " print(diff_line)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "# Step n: 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-IllinoisGRMHD__symmetry__set_gzs_staggered_gfs.pdf](Tutorial-IllinoisGRMHD__symmetry__set_gzs_staggered_gfs.pdf) (Note that clicking on this link may not work; you may need to open the PDF file through another means)." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "latex_nrpy_style_path = os.path.join(nrpy_dir_path,\"latex_nrpy_style.tplx\")\n", "#!jupyter nbconvert --to latex --template $latex_nrpy_style_path --log-level='WARN' Tutorial-IllinoisGRMHD__symmetry__set_gzs_staggered_gfs.ipynb\n", "#!pdflatex -interaction=batchmode Tutorial-IllinoisGRMHD__symmetry__set_gzs_staggered_gfs.tex\n", "#!pdflatex -interaction=batchmode Tutorial-IllinoisGRMHD__symmetry__set_gzs_staggered_gfs.tex\n", "#!pdflatex -interaction=batchmode Tutorial-IllinoisGRMHD__symmetry__set_gzs_staggered_gfs.tex\n", "!rm -f Tut*.out Tut*.aux Tut*.log" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.3" } }, "nbformat": 4, "nbformat_minor": 2 }