GiRaFFE_NRPy
1D tests¶This notebook is organized as follows
GiRaFFEfood_NRPy
initial data modulesfree_parameters.h
GiRaFFE_NRPy_standalone.c
: The Main C Codeimport os, sys # Standard Python modules for multiplatform OS-level functions
# First, we'll add the parent directory to the list of directories Python will check for modules.
nrpy_dir_path = os.path.join("..")
if nrpy_dir_path not in sys.path:
sys.path.append(nrpy_dir_path)
# Import needed Python modules
import NRPy_param_funcs as par # NRPy+: Parameter interface
import indexedexp as ixp # NRPy+: Symbolic indexed expression (e.g., tensors, vectors, etc.) support
import reference_metric as rfm # NRPy+: Reference metric support
import sympy as sp # SymPy: The Python computer algebra package upon which NRPy+ depends
#Step 0: Set the spatial dimension parameter to 3.
par.set_parval_from_str("grid::DIM", 3)
DIM = par.parval_from_str("grid::DIM")
# TINYDOUBLE = par.Cparameters("REAL", "TINYDOUBLE", 1e-100)
# Choices are: Spherical, SinhSpherical, SinhSphericalv2, Cylindrical, SinhCylindrical,
# SymTP, SinhSymTP
dst_basis = "Cartesian"
# Set coordinate system to dst_basis
par.set_parval_from_str("reference_metric::CoordSystem",dst_basis)
rfm.reference_metric()
GiRaFFEfood_NRPy
initial data modules [Back to top]¶With the preliminaries out of the way, we will write the C functions to set up initial data. There are two categories of initial data that must be set: the spacetime metric variables, and the GRFFE plasma variables. We will set up the spacetime first, namely the Minkowski spacetime.
Now, we will write out the initials data function for the GRFFE variables.
ID_opts = ["AlfvenWave", "ThreeAlfvenWaves", "DegenAlfvenWave", "FastWave", "FFEBD"]
# for initial_data in ID_opts:
initial_data = "FFEBD"
if initial_data=="AlfvenWave":
import GiRaFFEfood_NRPy.GiRaFFEfood_NRPy_1D_tests as gid
gid.GiRaFFEfood_NRPy_1D_tests(stagger = True)
desc = "Generate Alfven wave 1D initial data for GiRaFFEfood_NRPy."
elif initial_data=="ThreeAlfvenWaves":
import GiRaFFEfood_NRPy.GiRaFFEfood_NRPy_1D_tests_three_waves as gid
gid.GiRaFFEfood_NRPy_1D_tests_three_waves(stagger = True)
desc = "Generate three Alfven wave 1D initial data for GiRaFFEfood_NRPy."
elif initial_data=="DegenAlfvenWave":
import GiRaFFEfood_NRPy.GiRaFFEfood_NRPy_1D_tests_degen_Alfven_wave as gid
gid.GiRaFFEfood_NRPy_1D_tests_degen_Alfven_wave(stagger = True)
desc = "Generate degenerate Alfven wave 1D initial data for GiRaFFEfood_NRPy."
elif initial_data=="FastWave":
import GiRaFFEfood_NRPy.GiRaFFEfood_NRPy_1D_tests_fast_wave as gid
gid.GiRaFFEfood_NRPy_1D_tests_fast_wave(stagger = True)
desc = "Generate fast wave 1D initial data for GiRaFFEfood_NRPy."
elif initial_data=="FFEBD":
import GiRaFFEfood_NRPy.GiRaFFEfood_NRPy_1D_tests_FFE_breakdown as gid
gid.GiRaFFEfood_NRPy_1D_tests_FFE_breakdown(stagger = True)
desc = "Generate FFE breakdown 1D initial data for GiRaFFEfood_NRPy."
We define Jacobians relative to the center of the destination grid, at a point xjdst=(xx0,xx1,xx2
)dst on the destination grid:
Jac_dUCart_dDdstUD[i][j]=∂xiCart∂xjdst,
via exact differentiation (courtesy SymPy), and the inverse Jacobian Jac_dUdst_dDCartUD[i][j]=∂xidst∂xjCart,
using NRPy+'s generic_matrix_inverter3x3()
function. In terms of these, the transformation of BSSN tensors from Cartesian to the destination grid's "reference_metric::CoordSystem"
coordinates may be written:
while for lowered indices we have
Adsti=∂xℓCart∂xidstACartℓ# Step 3: Transform BSSN tensors in Cartesian basis to destination grid basis, using center of dest. grid as origin
# Step 3.a: Next construct Jacobian and inverse Jacobian matrices:
Jac_dUCart_dDrfmUD,Jac_dUrfm_dDCartUD = rfm.compute_Jacobian_and_inverseJacobian_tofrom_Cartesian()
# Step 3.b: Convert basis of all BSSN *vectors* from Cartesian to destination basis
BU_dst = rfm.basis_transform_vectorU_from_Cartesian_to_rfmbasis(Jac_dUrfm_dDCartUD, gid.BU)
ValenciavU_dst = rfm.basis_transform_vectorU_from_Cartesian_to_rfmbasis(Jac_dUrfm_dDCartUD, gid.ValenciavU)
# Note that the below the function should really be "...basis_transform_vectorUDfrom_Cartesian_to_rfmbasis.."
AD_dst = rfm.basis_transform_vectorU_from_Cartesian_to_rfmbasis(Jac_dUCart_dDrfmUD, gid.AD)
print("Initial data type = "+ initial_data)
for i in range(DIM):
print(gid.ValenciavU[i] - ValenciavU_dst[i])
print(gid.BU[i] - BU_dst[i])
print(gid.AD[i] - AD_dst[i])
Initial data type = FFEBD 0 0 0 0 0 0 0 0 0
# Choices are: Spherical, SinhSpherical, SinhSphericalv2, Cylindrical, SinhCylindrical,
# SymTP, SinhSymTP
dst_basis = "SymTP"
# Set coordinate system to dst_basis
par.set_parval_from_str("reference_metric::CoordSystem",dst_basis)
rfm.reference_metric()
# Step 3: Transform BSSN tensors in Cartesian basis to destination grid basis, using center of dest. grid as origin
# Step 3.a: Next construct Jacobian and inverse Jacobian matrices:
Jac_dUCart_dDrfmUD,Jac_dUrfm_dDCartUD = rfm.compute_Jacobian_and_inverseJacobian_tofrom_Cartesian()
# Step 3.b: Convert basis of all BSSN *vectors* from Cartesian to destination basis
BU_dst = rfm.basis_transform_vectorU_from_Cartesian_to_rfmbasis(Jac_dUrfm_dDCartUD, gid.BU)
ValenciavU_dst = rfm.basis_transform_vectorU_from_Cartesian_to_rfmbasis(Jac_dUrfm_dDCartUD, gid.ValenciavU)
# Note that the below the function should really be "...basis_transform_vectorUDfrom_Cartesian_to_rfmbasis.."
AD_dst = rfm.basis_transform_vectorU_from_Cartesian_to_rfmbasis(Jac_dUCart_dDrfmUD, gid.AD)
import GiRaFFEfood_NRPy.BasisTransform as BT
BT.basis_transform(dst_basis, gid.AD, gid.ValenciavU, gid.BU)
def consistency_check(quantity1,quantity2,string):
if quantity1-quantity2==0:
print(string+" is in agreement!")
else:
print(string+" does not agree!")
sys.exit(1)
print("Consistency check between GiRaFFEfood_NRPy tutorial and NRPy+ module:")
for i in range(3):
consistency_check(ValenciavU_dst[i],BT.ValenciavU_dst[i],"ValenciavU"+str(i))
consistency_check(AD_dst[i],BT.AD_dst[i],"AD"+str(i))
consistency_check(BU_dst[i],BT.BU_dst[i],"BU"+str(i))
Consistency check between GiRaFFEfood_NRPy tutorial and NRPy+ module: ValenciavU0 is in agreement! AD0 is in agreement! BU0 is in agreement! ValenciavU1 is in agreement! AD1 is in agreement! BU1 is in agreement! ValenciavU2 is in agreement! AD2 is in agreement! BU2 is in agreement!
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-Start_to_Finish-GiRaFFE_NRPy-1D_tests-staggered.pdf (Note that clicking on this link may not work; you may need to open the PDF file through another means.)
import cmdline_helper as cmd # NRPy+: Multi-platform Python command-line interface
cmd.output_Jupyter_notebook_to_LaTeXed_PDF("Tutorial-Start_to_Finish-GiRaFFE_NRPy-1D_tests-staggered",location_of_template_file=os.path.join(".."))
Created Tutorial-Start_to_Finish-GiRaFFE_NRPy-1D_tests-staggered.tex, and compiled LaTeX file to PDF file Tutorial-Start_to_Finish- GiRaFFE_NRPy-1D_tests-staggered.pdf