Skip to content

Commit

Permalink
ScalarField/ScalarField_Tmunu.py & Tutorial-ScalarField_Tmunu.ipynb: …
Browse files Browse the repository at this point in the history
…minor comment fixes and updates
  • Loading branch information
leowerneck committed Oct 4, 2022
1 parent 08e36cc commit 23679fb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 47 deletions.
48 changes: 26 additions & 22 deletions ScalarField/ScalarField_Tmunu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,71 @@
# wernecklr **at** gmail **dot* com
# Zachariah B. Etienne

# First we import needed core NRPy+ modules
import sympy as sp # SymPy: The Python computer algebra package upon which NRPy+ depends
import indexedexp as ixp # NRPy+: Symbolic indexed expression (e.g., tensors, vectors, etc.) support
import reference_metric as rfm # NRPy+: Reference metric support
import BSSN.BSSN_quantities as Bq # NRPy+: BSSN quantities
import BSSN.ADM_in_terms_of_BSSN as BtoA # NRPy+: ADM quantities in terms of BSSN quantities
import BSSN.ADMBSSN_tofrom_4metric as ADMg # NRPy+: ADM 4-metric to/from ADM or BSSN quantities
# Step 1: Import core Python/NRPy+ modules
from sympy import Rational # SymPy: The Python computer algebra package upon which NRPy+ depends
from NRPy_param_funcs import set_parval_from_str # NRPy+: Parameter interface
from indexedexp import zerorank1, zerorank2 # NRPy+: Symbolic indexed expression (e.g., tensors, vectors, etc.) support
from reference_metric import reference_metric # NRPy+: Reference metric support
import BSSN.BSSN_quantities as Bq # NRPy+: BSSN quantities
import BSSN.ADM_in_terms_of_BSSN as BtoA # NRPy+: ADM quantities in terms of BSSN quantities
import BSSN.ADMBSSN_tofrom_4metric as ADMg # NRPy+: ADM 4-metric to/from ADM or BSSN quantities
import ScalarField.ScalarField_quantities as SFq # NRPyCritCol: Scalar Field gridfunctions and derivatives

def ScalarField_Tmunu():

# Step 2: Scalar field energy-momentum tensor
global T4UU

# Step 1.c: Set spatial dimension (must be 3 for BSSN, as BSSN is
# Step 2.a: Set spatial dimension (must be 3 for BSSN, as BSSN is
# a 3+1-dimensional decomposition of the general
# relativistic field equations)
DIM = 3

# Step 1.d: Given the chosen coordinate system, set up
# Step 2.b: Given the chosen coordinate system, set up
# corresponding reference metric and needed
# reference metric quantities
# The following function call sets up the reference metric
# and related quantities, including rescaling matrices ReDD,
# ReU, and hatted quantities.
rfm.reference_metric()
reference_metric()

# Step 1.e: Import all basic (unrescaled) BSSN scalars & tensors
# Step 2.c: Import all basic (unrescaled) BSSN scalars & tensors
Bq.BSSN_basic_tensors()
alpha = Bq.alpha
betaU = Bq.betaU

# Step 1.g: Define ADM quantities in terms of BSSN quantities
# Step 2.d: Define ADM quantities in terms of BSSN quantities
BtoA.ADM_in_terms_of_BSSN()
gammaDD = BtoA.gammaDD
gammaUU = BtoA.gammaUU

# Step 1.h: Define scalar field quantitites
sf_dD = ixp.declarerank1("sf_dD")
Pi = sp.Symbol("sfM",real=True)
# Step 2.e: Define scalar field quantitites
SFq.ScalarField_quantities()
Pi = SFq.sfM
sf_dD = SFq.sf_dD

# Step 2a: Set up \partial^{t}\varphi = Pi/alpha
sf4dU = ixp.zerorank1(DIM=4)
# Step 2.f: Set up \partial^{t}\varphi = Pi/alpha
sf4dU = zerorank1(DIM=4)
sf4dU[0] = Pi/alpha

# Step 2b: Set up \partial^{i}\varphi = -Pi*beta^{i}/alpha + gamma^{ij}\partial_{j}\varphi
# Step 2.g: Set up \partial^{i}\varphi = -Pi*beta^{i}/alpha + gamma^{ij}\partial_{j}\varphi
for i in range(DIM):
sf4dU[i+1] = -Pi*betaU[i]/alpha
for j in range(DIM):
sf4dU[i+1] += gammaUU[i][j]*sf_dD[j]

# Step 2c: Set up \partial^{i}\varphi\partial_{i}\varphi = -Pi**2 + gamma^{ij}\partial_{i}\varphi\partial_{j}\varphi
# Step 2.h: Set up \partial^{i}\varphi\partial_{i}\varphi = -Pi**2 + gamma^{ij}\partial_{i}\varphi\partial_{j}\varphi
sf4d2 = -Pi**2
for i in range(DIM):
for j in range(DIM):
sf4d2 += gammaUU[i][j]*sf_dD[i]*sf_dD[j]

# Step 3a: Setting up g^{\mu\nu}
# Step 2.i: Setting up g^{\mu\nu}
ADMg.g4UU_ito_BSSN_or_ADM("ADM",gammaDD=gammaDD,betaU=betaU,alpha=alpha, gammaUU=gammaUU)
g4UU = ADMg.g4UU

# Step 3b: Setting up T^{\mu\nu} for a massless scalar field
T4UU = ixp.zerorank2(DIM=4)
# Step 2.j: Setting up T^{\mu\nu} for a massless scalar field
T4UU = zerorank2(DIM=4)
for mu in range(4):
for nu in range(4):
T4UU[mu][nu] = sf4dU[mu]*sf4dU[nu] - g4UU[mu][nu]*sf4d2/2
47 changes: 22 additions & 25 deletions Tutorial-ScalarField_Tmunu.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,50 +84,47 @@
"outputs": [],
"source": [
"# Step 1.a: import all needed modules from NRPy+:\n",
"import sympy as sp # SymPy: The Python computer algebra package upon which NRPy+ depends\n",
"import NRPy_param_funcs as par # NRPy+: Parameter interface\n",
"import indexedexp as ixp # NRPy+: Symbolic indexed expression (e.g., tensors, vectors, etc.) support\n",
"import reference_metric as rfm # NRPy+: Reference metric support\n",
"import BSSN.BSSN_quantities as Bq # NRPy+: BSSN quantities\n",
"import BSSN.ADM_in_terms_of_BSSN as BtoA # NRPy+: ADM quantities in terms of BSSN quantities\n",
"import BSSN.ADMBSSN_tofrom_4metric as ADMg # NRPy+: ADM 4-metric to/from ADM or BSSN quantities\n",
"from sympy import Rational # SymPy: The Python computer algebra package upon which NRPy+ depends\n",
"from NRPy_param_funcs import set_parval_from_str # NRPy+: Parameter interface\n",
"from indexedexp import zerorank1, zerorank2 # NRPy+: Symbolic indexed expression (e.g., tensors, vectors, etc.) support\n",
"from reference_metric import reference_metric # NRPy+: Reference metric support\n",
"import BSSN.BSSN_quantities as Bq # NRPy+: BSSN quantities\n",
"import BSSN.ADM_in_terms_of_BSSN as BtoA # NRPy+: ADM quantities in terms of BSSN quantities\n",
"import BSSN.ADMBSSN_tofrom_4metric as ADMg # NRPy+: ADM 4-metric to/from ADM or BSSN quantities\n",
"import ScalarField.ScalarField_quantities as SFq # NRPyCritCol: Scalar Field gridfunctions and derivatives\n",
"\n",
"# Step 1.b: Set the coordinate system for the numerical grid\n",
"coord_system = \"Spherical\"\n",
"par.set_parval_from_str(\"reference_metric::CoordSystem\",coord_system)\n",
"CoordSystem = \"Spherical\"\n",
"set_parval_from_str(\"reference_metric::CoordSystem\", CoordSystem)\n",
"\n",
"# Step 1.c: Set spatial dimension (must be 3 for BSSN, as BSSN is\n",
"# a 3+1-dimensional decomposition of the general\n",
"# relativistic field equations)\n",
"DIM = 3\n",
"par.set_parval_from_str(\"grid::DIM\",DIM)\n",
"set_parval_from_str(\"grid::DIM\",DIM)\n",
"\n",
"# Step 1.d: Given the chosen coordinate system, set up\n",
"# corresponding reference metric and needed\n",
"# reference metric quantities\n",
"# The following function call sets up the reference metric\n",
"# and related quantities, including rescaling matrices ReDD,\n",
"# ReU, and hatted quantities.\n",
"rfm.reference_metric()\n",
"\n",
"# Step 1.e: Set the theta and phi axes to be the symmetry axes; i.e., axis \"1\" and \"2\",\n",
"# corresponding to the i1 and i2 directions. This sets all spatial derivatives\n",
"# in the theta and phi directions to zero (analytically).\n",
"par.set_parval_from_str(\"indexedexp::symmetry_axes\",\"12\")\n",
"reference_metric()\n",
"\n",
"# Step 1.e: Import all basic (unrescaled) BSSN scalars & tensors\n",
"Bq.BSSN_basic_tensors()\n",
"alpha = Bq.alpha\n",
"betaU = Bq.betaU\n",
"\n",
"# Step 1.g: Define ADM quantities in terms of BSSN quantities\n",
"# Step 1.f: Define ADM quantities in terms of BSSN quantities\n",
"BtoA.ADM_in_terms_of_BSSN()\n",
"gammaDD = BtoA.gammaDD\n",
"gammaUU = BtoA.gammaUU\n",
"\n",
"# Step 1.h: Define scalar field quantitites\n",
"sf_dD = ixp.declarerank1(\"sf_dD\")\n",
"Pi = sp.Symbol(\"sfM\",real=True)"
"SFq.ScalarField_quantities()\n",
"Pi = SFq.sfM\n",
"sf_dD = SFq.sf_dD"
]
},
{
Expand Down Expand Up @@ -178,7 +175,7 @@
"outputs": [],
"source": [
"# Step 2a: Set up \\partial^{t}\\varphi = Pi/alpha\n",
"sf4dU = ixp.zerorank1(DIM=4)\n",
"sf4dU = zerorank1(DIM=4)\n",
"sf4dU[0] = Pi / alpha"
]
},
Expand Down Expand Up @@ -314,10 +311,10 @@
"outputs": [],
"source": [
"# Step 3b: Setting up T^{\\mu\\nu} for a massless scalar field\n",
"T4UU = ixp.zerorank2(DIM=4)\n",
"T4UU = zerorank2(DIM=4)\n",
"for mu in range(4):\n",
" for nu in range(4):\n",
" T4UU[mu][nu] = sf4dU[mu] * sf4dU[nu] - sp.Rational(1,2) * g4UU[mu][nu] * sf4d2"
" T4UU[mu][nu] = sf4dU[mu] * sf4dU[nu] - Rational(1,2) * g4UU[mu][nu] * sf4d2"
]
},
{
Expand Down Expand Up @@ -381,7 +378,7 @@
"\n",
"for mu in range(4):\n",
" for nu in range(4):\n",
" print(\"T4UU[\"+str(mu)+\"][\"+str(nu)+\"] - sfTmunu.T4UU[\"+str(mu)+\"][\"+str(nu)+\"] = \"+str(sp.simplify(T4UU[mu][nu] - sfTmunu.T4UU[mu][nu])))"
" print(\"T4UU[\"+str(mu)+\"][\"+str(nu)+\"] - sfTmunu.T4UU[\"+str(mu)+\"][\"+str(nu)+\"] = \"+str((T4UU[mu][nu] - sfTmunu.T4UU[mu][nu]).simplify()))"
]
},
{
Expand Down Expand Up @@ -426,7 +423,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -440,7 +437,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.5"
"version": "3.10.6"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 23679fb

Please sign in to comment.