Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhantomNR #480

Merged
merged 37 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0dbad15
Added NRSPH code and ET interface
spencermagnall Jun 20, 2022
fdf8fd3
Fixed errors in evolve routine
spencermagnall Jun 20, 2022
09e337c
Major update with shell-crossing,exact interp, etc.
spencermagnall Mar 17, 2023
cc7d4c0
Added radiation dominated universe setup
spencermagnall Mar 31, 2023
21de775
Fixed the stress energy tensor calc for 3d case and added options for…
spencermagnall Apr 4, 2023
60fe915
Added parrelisation for simple loops
spencermagnall Apr 7, 2023
e391255
Added code to change perturbation wavelength
spencermagnall Apr 18, 2023
802756a
merge+fix issues
danieljprice Apr 19, 2023
bcd2830
Fixed compilation errors with master branch merge
spencermagnall Apr 21, 2023
b949d7d
Added powerspectrum flrw setup
spencermagnall Apr 24, 2023
c5bf979
Fixed stress energy calc for radiation dominated
spencermagnall Apr 26, 2023
a50b779
Removed extra tmunu calculation
spencermagnall May 2, 2023
21f4d08
Merge branch 'master' of https://github.com/danieljprice/phantom
spencermagnall May 2, 2023
6da3cd7
[tab-bot] tabs removed
spencermagnall May 2, 2023
797203b
[format-bot] F77-style SHOUTING removed
spencermagnall May 2, 2023
0f571ec
[header-bot] updated file headers
spencermagnall May 2, 2023
1403280
[space-bot] whitespace at end of lines removed
spencermagnall May 2, 2023
7f4c06c
[author-bot] updated AUTHORS file
spencermagnall May 2, 2023
615c116
[format-bot] end if -> endif; end do -> enddo; if( -> if (
spencermagnall May 2, 2023
a041762
[indent-bot] standardised indentation
spencermagnall May 2, 2023
995d246
fixed tmunu allocation error
spencermagnall May 2, 2023
71866a7
Fixed sqrtg allocation error
spencermagnall May 2, 2023
bf717dc
Added vectorisation to interpolation
spencermagnall May 29, 2023
80541de
Code optimisation and phantom checkpoint added
spencermagnall Jun 5, 2023
1c669de
Improved vectorised code
spencermagnall Jun 8, 2023
d8c66ad
Removed unused variable warnings
spencermagnall Jun 9, 2023
c96d22e
sync fork with latest phantom version
spencermagnall Aug 28, 2023
ad57a52
Hopefully fixed build errors in testsuite
spencermagnall Aug 29, 2023
e5efd4d
Fixed precision errors in blob test setup and build
spencermagnall Aug 30, 2023
ec658ce
Fixed unused variable warning
spencermagnall Aug 31, 2023
7d22e0e
Added documentation for phantomNR and fixed rad dom setup
spencermagnall Sep 20, 2023
e56b5b9
Merge remote-tracking branch 'upstream/master'
spencermagnall Sep 20, 2023
f177e58
(flrw) fixed complier warnings
spencermagnall Oct 25, 2023
5c1f127
(einsteintk_wrapper) fixed compiler warning
spencermagnall Oct 25, 2023
4cc40b0
(AUTHORS) fixed authors file with bots
spencermagnall Oct 26, 2023
02d1b2b
(flrwpspec) fixed compile/runtime issues
spencermagnall Oct 26, 2023
87c53cc
Implemented requested for pull request
spencermagnall Oct 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Simone Ceppi <simone.ceppi@unimi.it>
MatsEsseldeurs <matsesseldeurs@yahoo.com>
Caitlyn Hardiman <caitlyn.hardiman1@monash.edu>
Enrico Ragusa <enr.ragusa@gmail.com>
Spencer Magnall <spencermagnall@gmail.com>
fhu <fhuu0005@student.monash.edu>
Sergei Biriukov <svbiriukov@gmail.com>
Cristiano Longarini <cristiano.longarini@unimi.it>
Expand All @@ -54,11 +55,11 @@ Kieran Hirsh <kieran.hirsh1@monash.edu>
Nicole Rodrigues <nicole.rodrigues@monash.edu>
Amena Faruqi <Amena.Faruqi@warwick.ac.uk>
David Trevascus <dtre10@student.monash.edu>
Farzana Meru <f.meru@warwick.ac.uk>
Chris Nixon <cjn@leicester.ac.uk>
Megha Sharma <megha@meghas-air.home>
Nicolas Cuello <cuellonicolas@gmail.com>
Benoit Commercon <benoit.commercon@gmail.com>
Farzana Meru <f.meru@warwick.ac.uk>
Giulia Ballabio <giulia.ballabio2@studenti.unimi.it>
Joe Fisher <jwfis1@student.monash.edu>
Maxime Lombart <maxime.lombart@ens-lyon.fr>
Expand All @@ -70,6 +71,7 @@ s-neilson <36410751+s-neilson@users.noreply.github.com>
Alison Young <ayoung@astro.ex.ac.uk>
Cox, Samuel <sc676@leicester.ac.uk>
Jorge Cuadra <jcuadra@astro.puc.cl>
Miguel Gonzalez-Bolivar <miguelgb@astro.unam.mx>
Nicolás Cuello <cuello.nicolas@gmail.com>
Steven Rieder <steven@rieder.nl>
Stéven Toupin <steven.toupin@gmail.com>
Expand Down
6 changes: 5 additions & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ ifdef METRIC
else
SRCMETRIC= metric_minkowski.f90
endif
SRCGR=inverse4x4.f90 $(SRCMETRIC) metric_tools.f90 utils_gr.f90
SRCGR=inverse4x4.f90 einsteintk_utils.f90 $(SRCMETRIC) metric_tools.f90 utils_gr.f90 interpolate3D.f90 tmunu2grid.f90
#
# chemistry and cooling
#
Expand Down Expand Up @@ -547,6 +547,10 @@ SOURCES= physcon.f90 ${CONFIG} ${SRCKERNEL} io.F90 units.f90 \
mf_write.f90 evolve.F90 utils_orbits.f90 utils_linalg.f90 \
checksetup.F90 initial.F90

# Needed as einsteintk_wrapper depends on initial
ifeq ($(GR),yes)
SOURCES+=einsteintk_wrapper.f90
endif
OBJECTS1 = $(SOURCES:.f90=.o)
OBJECTS = $(OBJECTS1:.F90=.o)

Expand Down
16 changes: 16 additions & 0 deletions build/Makefile_setups
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,22 @@ ifeq ($(SETUP), testgr)
SETUPFILE= setup_grdisc.f90
endif

ifeq ($(SETUP), flrw)
GR=yes
KNOWN_SETUP=yes
IND_TIMESTEPS=no
METRIC=et
SETUPFILE= setup_flrw.f90
PERIODIC=yes
endif
ifeq ($(SETUP), flrwpspec)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a comment after the #ifeq giving a description of the setup (this is used in the docs)

GR=yes
KNOWN_SETUP=yes
IND_TIMESTEPS=no
METRIC=et
SETUPFILE= setup_flrwpspec.f90
PERIODIC=yes
endif
ifeq ($(SETUP), default)
# default setup, uniform box
KNOWN_SETUP=yes
Expand Down
79 changes: 79 additions & 0 deletions docs/phantomNR.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
PhantomNR
=========

Using PhantomNR to simulate general relativistic hydrodynamics on dynamical spacetimes
--------------------------------------------------------------------------------------

About phantomNR
~~~~~~~~~~~~~~~

`phantomNR <https://github.com/spencermagnall/phantomNR>`__ is
an extension to the General Relativistic Smoothed Particle Hydrodynamics code Phantom,
that allows for the evolution of relativistic fluids with evolving spacetime metrics.
This is acomplished via coupling with the numerical relativity framework Einstein Toolkit (ET).
phantomNR's current usage is as a fully relativistic N-Body code for the simulation of inhomogenous
cosmologies (see `Magnall et al. 2023 <https://ui.adsabs.harvard.edu/abs/2023arXiv230715194M/abstract>`__).
Einstein Toolkit acts as a "driver" for both the spacetime evolution, and the hydrodynamic evolution.
As a consquence, simulations are started and mointered entirely within ET, and are setup using a .par
parameter file which describes the parameters of the simulation. In addition, phantomNR also requires
particle information, which is provided via the standard phantom dump file.


Compilation and linking
~~~~~~~~~~~~~~~~~~~~~~~
You will first need to compile phantom and phantomsetup
using the flrw setup

::

scripts/writemake.sh flrw > Makefile

make; make setup

which compiles the libphantom.a static library which is
required for linking and the phantom and phantomsetup binaries.

You will also need to set the include directory of phantom in Einstein Toolkit
e.g:

::

PHANTOM_DIR = /Users/smag0001/phantom/phantomET/bin

Generating a phantom dump file from phantom setup
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Particles can be setup using phantomsetup in two ways:

1. **Using a regular .setup file**
e.g ./phantomsetup flrw.setup will produce a dump file and .in file using an interactive setup routine.


3. **Using a .par file** By appending .setup to the end of an Einstein Toolkit parameter file, phantomsetup
will automatically read in (most) relevant quantities about the simulation setup and generate an appropriate
distribution of particles


Troubleshooting
---------------

**Issue**: Large Constraint Violations



**Solution**: Generally, this is indicative of a mismatch between the spacetime setup by Einstein Toolkit
and the particle distribution which is setup by Phantom. A large raw constraint violation, may not always be indicative
of a poorly initialised setup however. It is important to check the relative constraint violations (TODO insert equations)

In many cases, a poor initial constraint is simply a consquence of not setting spacetime and consistently (e.g phi=1e-4 for particles, but phi=1e-6 for spacetime).
We reccomend that the .in and dumpfiles are generated using the .par file of Einstein Toolkit to alleviate this issue.

Constraint violations may also occur due to a low particle and/or grid resolution




Using phantomNR on Ozstar/NT
-------------------------------


9 changes: 9 additions & 0 deletions src/main/config.F90
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@ module dim
logical, parameter :: gr = .false.
#endif

!---------------------
! Numerical relativity
!---------------------
#ifdef NR
logical, parameter :: nr = .true.
#else
logical, parameter :: nr = .false.
#endif

!--------------------
! Supertimestepping
!--------------------
Expand Down
21 changes: 12 additions & 9 deletions src/main/cons2primsolver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ end subroutine get_u
!+
!----------------------------------------------------------------
subroutine primitive2conservative(x,metrici,v,dens,u,P,rho,pmom,en,ien_type)
use utils_gr, only:get_u0
use utils_gr, only:get_u0,get_sqrtg
use metric_tools, only:unpack_metric
use io, only:error
use eos, only:gmw,get_entropy
Expand All @@ -93,9 +93,9 @@ subroutine primitive2conservative(x,metrici,v,dens,u,P,rho,pmom,en,ien_type)

enth = 1. + u + P/dens

! Hard coded sqrtg=1 since phantom is always in cartesian coordinates
sqrtg = 1.
! get determinant of metric
call unpack_metric(metrici,gcov=gcov)
call get_sqrtg(gcov,sqrtg)

call get_u0(gcov,v,U0,ierror)
if (ierror > 0) call error('get_u0 in prim2cons','1/sqrt(-v_mu v^mu) ---> non-negative: v_mu v^mu')
Expand Down Expand Up @@ -134,6 +134,7 @@ end subroutine primitive2conservative
!+
!----------------------------------------------------------------
subroutine conservative2primitive(x,metrici,v,dens,u,P,temp,gamma,rho,pmom,en,ierr,ien_type)
use utils_gr, only:get_sqrtg,get_sqrt_gamma
use metric_tools, only:unpack_metric
use eos, only:ieos,gmw,get_entropy,get_p_from_rho_s,gamma_global=>gamma
use io, only:fatal
Expand All @@ -147,21 +148,21 @@ subroutine conservative2primitive(x,metrici,v,dens,u,P,temp,gamma,rho,pmom,en,ie
integer, intent(in) :: ien_type
real, dimension(1:3,1:3) :: gammaijUP
real :: sqrtg,sqrtg_inv,lorentz_LEO,pmom2,alpha,betadown(1:3),betaUP(1:3),enth_old,v3d(1:3)
real :: f,df,term,lorentz_LEO2,gamfac,pm_dot_b,sqrt_gamma_inv,enth,gamma1
real :: f,df,term,lorentz_LEO2,gamfac,pm_dot_b,sqrt_gamma_inv,enth,gamma1,sqrt_gamma
real(kind=8) :: cgsdens,cgsu
integer :: niter, i
real, parameter :: tol = 1.e-12
integer, parameter :: nitermax = 100
logical :: converged
real :: gcov(0:3,0:3)
ierr = 0

! Hard coding sqrgt=1 since phantom is always in cartesian coordinates
sqrtg = 1.
sqrtg_inv = 1./sqrtg

! Get metric components from metric array
call unpack_metric(metrici,gammaijUP=gammaijUP,alpha=alpha,betadown=betadown,betaUP=betaUP)
call unpack_metric(metrici,gcov=gcov,gammaijUP=gammaijUP,alpha=alpha,betadown=betadown,betaUP=betaUP)

! Retrieve sqrt(g)
call get_sqrtg(gcov,sqrtg)
sqrtg_inv = 1./sqrtg
pmom2 = 0.
do i=1,3
pmom2 = pmom2 + pmom(i)*dot_product(gammaijUP(:,i),pmom(:))
Expand All @@ -172,6 +173,7 @@ subroutine conservative2primitive(x,metrici,v,dens,u,P,temp,gamma,rho,pmom,en,ie

niter = 0
converged = .false.
call get_sqrt_gamma(gcov,sqrt_gamma)
sqrt_gamma_inv = alpha*sqrtg_inv ! get determinant of 3 spatial metric
term = rho*sqrt_gamma_inv
gamfac = gamma/(gamma-1.)
Expand Down Expand Up @@ -238,6 +240,7 @@ subroutine conservative2primitive(x,metrici,v,dens,u,P,temp,gamma,rho,pmom,en,ie

if (.not.converged) ierr = 1


lorentz_LEO = sqrt(1.+pmom2/enth**2)
dens = term/lorentz_LEO

Expand Down
2 changes: 1 addition & 1 deletion src/main/deriv.F90
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ subroutine derivs(icall,npart,nactive,xyzh,vxyzu,fxyzu,fext,divcurlv,divcurlB,&
if (gr) then
! Recalculate the metric after moving particles to their new tasks
call init_metric(npart,xyzh,metrics)
call prim2consall(npart,xyzh,metrics,vxyzu,dens,pxyzu,use_dens=.false.)
!call prim2consall(npart,xyzh,metrics,vxyzu,dens,pxyzu,use_dens=.false.)
endif

if (nptmass > 0 .and. periodic) call ptmass_boundary_crossing(nptmass,xyzmh_ptmass)
Expand Down
2 changes: 1 addition & 1 deletion src/main/eos_shen.f90
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ end subroutine Cint
! Interpolate between values using linear interpolation in 1D
!+
!------------------------------------------------------------------------
subroutine linear_interpolator_one_d(val0,val1,u,val)
pure subroutine linear_interpolator_one_d(val0,val1,u,val)
real, intent(out) :: val
real, intent(in) :: val0,val1,u

Expand Down
Loading
Loading