This module is currently under development
IllinoisGRMHD
codes.¶We will now use the cmdline_helper.py NRPy+ module to create the source directory within the IllinoisGRMHD
NRPy+ directory if it does not exist yet.
# Step 0: Creation of the IllinoisGRMHD source directory
# Step 0a: Add NRPy's directory to the path
# https://stackoverflow.com/questions/16780014/import-file-from-parent-directory
import os,sys
nrpy_dir_path = os.path.join("..","..")
if nrpy_dir_path not in sys.path:
sys.path.append(nrpy_dir_path)
# Step 0b: Load up cmdline_helper and create the directory
import cmdline_helper as cmd
IGM_src_dir_path = os.path.join("..","src")
cmd.mkdir(IGM_src_dir_path)
# Step 0c: Create the output file path
outfile_path__MoL_registration__C = os.path.join(IGM_src_dir_path,"MoL_registration.C")
%%writefile $outfile_path__MoL_registration__C
//--------------------------------------------------------------------------
// Register with the time stepper
// (MoL thorn, found in arrangements/CactusBase/MoL)
// To understand this, read documentation in arrangements/CactusBase/MoL/doc
//--------------------------------------------------------------------------
#include "cctk.h"
#include <cstdio>
#include <cmath>
#include <cstddef>
#include "cctk_Parameters.h"
#include "cctk_Arguments.h"
#include "Symmetry.h"
extern "C" void IllinoisGRMHD_RegisterVars(CCTK_ARGUMENTS)
{
DECLARE_CCTK_ARGUMENTS;
DECLARE_CCTK_PARAMETERS;
CCTK_INT ierr = 0, group, rhs;
// Register evolution & RHS gridfunction groups
/* Ax and Ax_rhs */
group = CCTK_GroupIndex("IllinoisGRMHD::em_Ax");
rhs = CCTK_GroupIndex("IllinoisGRMHD::em_Ax_rhs");
ierr += MoLRegisterEvolvedGroup(group, rhs);
/* Ay and Ay_rhs */
group = CCTK_GroupIndex("IllinoisGRMHD::em_Ay");
rhs = CCTK_GroupIndex("IllinoisGRMHD::em_Ay_rhs");
ierr += MoLRegisterEvolvedGroup(group, rhs);
/* Az and Az_rhs */
group = CCTK_GroupIndex("IllinoisGRMHD::em_Az");
rhs = CCTK_GroupIndex("IllinoisGRMHD::em_Az_rhs");
ierr += MoLRegisterEvolvedGroup(group, rhs);
/* psi6phi and psi6phi_rhs */
group = CCTK_GroupIndex("IllinoisGRMHD::em_psi6phi");
rhs = CCTK_GroupIndex("IllinoisGRMHD::em_psi6phi_rhs");
ierr += MoLRegisterEvolvedGroup(group, rhs);
/* ALL OTHER EVOLVED VARIABLES (rho_star,tau,mhd_st_x,mhd_st_y,mhd_st_z) */
group = CCTK_GroupIndex("IllinoisGRMHD::grmhd_conservatives");
rhs = CCTK_GroupIndex("IllinoisGRMHD::grmhd_conservatives_rhs");
ierr += MoLRegisterEvolvedGroup(group, rhs);
if (ierr) CCTK_ERROR("Problems registering with MoL");
//***********************************************
//***********************************************
// Next register ADMBase variables needed by
// IllinoisGRMHD as SaveAndRestore, so that
// they are not set to NaN at the start of
// each timestep (requiring that they be
// e.g., recomputed from BSSN variables
// in the BSSN solver, like Baikal or
// ML_BSSN)
ierr += MoLRegisterSaveAndRestoreGroup(CCTK_GroupIndex("admbase::lapse"));
ierr += MoLRegisterSaveAndRestoreGroup(CCTK_GroupIndex("admbase::shift"));
ierr += MoLRegisterSaveAndRestoreGroup(CCTK_GroupIndex("admbase::metric"));
ierr += MoLRegisterSaveAndRestoreGroup(CCTK_GroupIndex("admbase::curv"));
if (ierr) CCTK_ERROR("Problems registering with MoLRegisterSaveAndRestoreGroup");
}
Writing ../src/MoL_registration.C
# Verify if the code generated by this tutorial module
# matches the original IllinoisGRMHD source code
# First download the original IllinoisGRMHD source code
import urllib
from os import path
original_IGM_file_url = "https://bitbucket.org/zach_etienne/wvuthorns/raw/5611b2f0b17135538c9d9d17c7da062abe0401b6/IllinoisGRMHD/src/MoL_registration.C"
original_IGM_file_name = "MoL_registration-original.C"
original_IGM_file_path = os.path.join(IGM_src_dir_path,original_IGM_file_name)
# Then download the original IllinoisGRMHD source code
# We try it here in a couple of ways in an attempt to keep
# the code more portable
try:
original_IGM_file_code = urllib.request.urlopen(original_IGM_file_url).read().decode("utf-8")
# Write down the file the original IllinoisGRMHD source code
with open(original_IGM_file_path,"w") as file:
file.write(original_IGM_file_code)
except:
try:
original_IGM_file_code = urllib.urlopen(original_IGM_file_url).read().decode("utf-8")
# Write down the file the original IllinoisGRMHD source code
with open(original_IGM_file_path,"w") as file:
file.write(original_IGM_file_code)
except:
# If all else fails, hope wget does the job
!wget -O $original_IGM_file_path $original_IGM_file_url
# Perform validation
Validation__MoL_registration__C = !diff $original_IGM_file_path $outfile_path__MoL_registration__C
if Validation__MoL_registration__C == []:
# If the validation passes, we do not need to store the original IGM source code file
!rm $original_IGM_file_path
print("Validation test for MoL_registration.C: PASSED!")
else:
# If the validation fails, we keep the original IGM source code file
print("Validation test for MoL_registration.C: FAILED!")
# We also print out the difference between the code generated
# in this tutorial module and the original IGM source code
print("Diff:")
for diff_line in Validation__MoL_registration__C:
print(diff_line)
Validation test for MoL_registration.C: FAILED! Diff: 2c2 < // Register with the time stepper --- > // Register with the time stepper 20c20 < --- > 52a53 >
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 Tutorial-IllinoisGRMHD__MoL_registration.pdf (Note that clicking on this link may not work; you may need to open the PDF file through another means).
latex_nrpy_style_path = os.path.join(nrpy_dir_path,"latex_nrpy_style.tplx")
#!jupyter nbconvert --to latex --template $latex_nrpy_style_path --log-level='WARN' Tutorial-IllinoisGRMHD__MoL_registration.ipynb
#!pdflatex -interaction=batchmode Tutorial-IllinoisGRMHD__MoL_registration.tex
#!pdflatex -interaction=batchmode Tutorial-IllinoisGRMHD__MoL_registration.tex
#!pdflatex -interaction=batchmode Tutorial-IllinoisGRMHD__MoL_registration.tex
!rm -f Tut*.out Tut*.aux Tut*.log