Skip to content

Commit

Permalink
Merge pull request #595 from becnealon/apr3
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljprice authored Oct 20, 2024
2 parents 92dda46 + 95ac4a9 commit cdb7a8c
Show file tree
Hide file tree
Showing 57 changed files with 2,751 additions and 393 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- ['testkd', '']
- ['testdust', 'dust']
- ['testgr', 'gr']
- ['testgrav', 'gravity ptmass']
- ['testgrav', 'gravity ptmass setstar']
- ['testgrowth', 'dustgrowth']
- ['testnimhd', 'nimhd']
- ['test2', '']
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ forcing.dat
*.tar
.DS_Store
_build
build/wind_profile1D.dat
build/radiation-test01explicit.ev
build/radiation-test01implicit.ev
build/radiation-test02explicit.ev
build/radiation-test02implicit.ev
build/test000
*.cmdx
*.cmod
*.ilm
*.stb

1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Nicolás Cuello <cuello.nicolas@gmail.com>
Chris Nixon <cjn@leicester.ac.uk>
Miguel Gonzalez-Bolivar <miguelgb@astro.unam.mx>
Benoit Commercon <benoit.commercon@gmail.com>
Christopher Russell <cmprussell@gmail.com>
Giulia Ballabio <giulia.ballabio2@studenti.unimi.it>
Joe Fisher <jwfis1@student.monash.edu>
Maxime Lombart <maxime.lombart@ens-lyon.fr>
Expand Down
26 changes: 18 additions & 8 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ LIBTOOL=ar rcs
# -DMHD ! magnetic fields
# -DNONIDEALMHD ! non-ideal magnetic fields including ionisation; uses NICIL
# -DLIGHTCURVE ! lightcurve estimation
# -DAPR ! live adaptive particle refinement

include Makefile_setups

Expand Down Expand Up @@ -295,6 +296,13 @@ endif
ifeq ($(AOCC), yes)
FPPFLAGS += -DAOCC
endif

SRCAPR=relaxem.f90 apr_region.f90 apr.f90
ifeq ($(APR), yes)
FPPFLAGS += -DAPR
KERNEL=WendlandC2
endif

#
# kernel choice
#
Expand Down Expand Up @@ -537,7 +545,7 @@ SOURCES= physcon.f90 ${CONFIG} ${SRCKERNEL} io.F90 units.f90 \
${SRCKROME} memory.f90 ${SRCREADWRITE_DUMPS} ${SRCINJECT} \
H2regions.f90 subgroup.f90 \
quitdump.f90 ptmass.F90\
readwrite_infile.F90 dens.F90 force.F90 deriv.F90 energies.F90 sort_particles.f90 \
dens.F90 force.F90 deriv.F90 ${SRCAPR} readwrite_infile.F90 energies.F90 sort_particles.f90 \
utils_shuffleparticles.F90 evwrite.f90 substepping.F90 step_leapfrog.F90 writeheader.F90 ${SRCAN} step_supertimestep.F90 \
mf_write.f90 evolve.F90 utils_orbits.f90 utils_linalg.f90 \
checksetup.f90 initial.F90
Expand Down Expand Up @@ -650,12 +658,14 @@ libsetup: $(OBJLIBSETUP)
.PHONY: phantomsetup
phantomsetup: setup

SRCSETUP= prompting.f90 utils_omp.F90 setup_params.f90 \
set_dust_options.f90 set_units.f90 \
density_profiles.f90 readwrite_kepler.f90 readwrite_mesa.f90 \
SRCSETSTAR= prompting.f90 density_profiles.f90 readwrite_kepler.f90 readwrite_mesa.f90 \
set_cubic_core.f90 set_fixedentropycore.f90 set_softened_core.f90 \
set_star_utils.f90 relax_star.f90 set_star.f90

SRCSETUP= utils_omp.F90 setup_params.f90 \
${SRCSETSTAR} set_dust_options.f90 set_units.f90 \
set_slab.f90 set_disc.F90 set_orbit.f90 \
set_cubic_core.f90 set_fixedentropycore.f90 set_softened_core.f90 \
set_star_utils.f90 relax_star.f90 set_star.f90 set_hierarchical.f90 \
set_hierarchical.f90 \
set_vfield.f90 set_Bfield.f90 \
${SETUPFILE}

Expand All @@ -682,11 +692,11 @@ endif

# 22/4/24: added setup_params to avoid weird build failure with ifort on Mac OS
SRCTESTS=utils_testsuite.f90 ${TEST_FASTMATH} test_kernel.f90 \
test_dust.f90 test_growth.f90 test_smol.F90 \
${SRCAPR} test_apr.f90 test_dust.f90 test_growth.f90 test_smol.F90 \
test_nonidealmhd.F90 directsum.f90 test_gravity.f90 \
test_derivs.F90 test_cooling.f90 test_eos_stratified.f90 \
test_eos.f90 test_externf.f90 test_rwdump.f90 \
test_step.F90 test_indtstep.F90 set_disc.F90 test_setdisc.F90 \
test_step.F90 test_indtstep.F90 ${SRCSETSTAR} set_disc.F90 test_setdisc.F90 test_setstar.f90 \
test_hierarchical.f90 test_damping.f90 test_wind.f90 test_iorig.f90 \
test_link.F90 test_kdtree.F90 test_part.f90 test_ptmass.f90 test_luminosity.F90\
test_gnewton.f90 test_corotate.f90 test_geometry.f90 \
Expand Down
9 changes: 8 additions & 1 deletion build/Makefile_setups
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ ifeq ($(SETUP), galcen)
endif

ifeq ($(SETUP), starcluster)
# Cluster of stars (ptmass)
# Cluster of stars (ptmass)
SETUPFILE= setup_starcluster.f90
KNOWN_SETUP=yes
endif
Expand Down Expand Up @@ -1048,6 +1048,13 @@ ifeq ($(SETUP), testgr)
SETUPFILE= setup_grdisc.f90
endif

ifeq ($(SETUP), testapr)
# unit tests for apr
APR=yes
KNOWN_SETUP=yes
PERIODIC=yes
endif

ifeq ($(SETUP), flrw)
# constant density FLRW cosmology with perturbations
GR=yes
Expand Down
120 changes: 120 additions & 0 deletions docs/user-guide/apr_guide.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
Running phantom with APR
========================

APR allows you to arbitrarily set regions of your simulation to have different local resolutions.
A description of the method and our implementation can be found in Nealon & Price 2024 (under review) and
you should cite this work if you are using APR.

The rules of this method are:
1. A mass factor of 2 is allowed between adjacent refinement levels (e.g. one parent 0> two children)
2. Regions are spherical but can be nested together like a layered onion
3. You cannot have both refinement and derefinement in the same simulation, e.g. the base refinement level has to be either the maximum or minimum
4. Try to ensure that particles have several sound crossing times between subsequent split/merge procedures to reduce noise


Compiling Phantom with APR
--------------------------
Use your usual setup routine but with APR=yes. For example:

::

mkdir mycalc
cd mycalc
~/phantom/scripts/writemake.sh disc > Makefile
export APR=yes
make setup
make

Initial conditions with APR
-------------------------
APR does not affect any setups except SETUP=star (but for the relax procedure only). When you check your .in file it will have apr options at the bottom:

::

apr_max = 3 ! number of additional refinement levels (3 -> 2x resolution)

This option sets how many *extra* levels of refinement you want. Each level corresponds to a factor of 2 in mass.
To increase the spatial resolution by a factor of 2 you will need to use 3 levels here.

::

ref_dir = 1 ! increase (1) or decrease (-1) resolution

This chooses whether you are refining or derefining the simulation. If you are refining then the base resolution level will be 0.
If you are derefining the base level will be apr_max.

::

apr_type = 2 ! 1: static, 2: moving sink, 3: create clumps

Here you choose what kind of region you want. Current options include:
1. A position fixed in space
2. Tracking a particular sink particle
3. Tracking a gravitationally bound clump (under development).
Depending on what you choose here you will get additional options to describe the properties of the region you selected.
You may need to re-run to get the right options if you alter apr_type. To add your own new region you can edit the apr_region.f90 file.
Note for now that we only allow spherical regions.

::

apr_rad = 5. ! radius of innermost region

This chooses the radius of the core of the refinement zone, where the highest/lowest refinement will be. If you think about
your refinement zone as an onion, this is the core of the onion.

::

apr_drad = 10. ! size of step to next region

This chooses the step width of the nested regions – the width of the shells as you step up your resolution.

Running with APR
--------------------
When APR is implemented and being used Phantom prints out the following statement in the log file:

::

Adapative particle refinement is ON

Additionally, because the particle numbers are changing each step you should see the number of
particles being updated during the steps e.g.:

::

> step 2 / 16 t = 20.92159 dt = 0.072 moved 502 in 0.058 cpu-s < | np = 37902 |
> step 4 / 16 t = 21.06588 dt = 0.072 moved 1792 in 0.070 cpu-s <
> step 6 / 16 t = 21.21017 dt = 0.072 moved 319 in 0.058 cpu-s <
> step 8 / 16 t = 21.35445 dt = 0.072 moved 6175 in 0.097 cpu-s <
> step 10 / 16 t = 21.49874 dt = 0.072 moved 442 in 0.057 cpu-s < | np = 37901 |
> step 12 / 16 t = 21.64303 dt = 0.072 moved 1283 in 0.064 cpu-s <
> step 14 / 16 t = 21.78732 dt = 0.072 moved 476 in 0.058 cpu-s < | np = 37900 |
> step 16 / 16 t = 21.93160 dt = 0.072 moved 37860 in 0.31 cpu-s <

Plotting with APR
--------------------
APR is natively read by both splash and sarracen. The easiest way to check the method is working exactly
as you expect is to scatter plot (not render!) the mass of the particles in your simulation. This will
show you where the refinement zone is and you can confirm the geometry, it’s evolution as well as the
refinement direction.

Analysis with APR
--------------------
No analysis files that ship with Phantom have been updated to accommodate APR. To do this yourself, any
time you define a particle mass from the massoftype array you will need to edit it to read

::

if (use_apr) then
pmassi = aprmassoftype(iamtypei,apr_level(i))
else
pmassi = massoftype(iamtypei)
endif

This relies on the apr_level, aprmassoftype and use_apr which can be included with

::

use dim, only::use_apr
use part, only::apr_level,aprmassoftype

Note that apr_level is integer(kind=1).
1 change: 1 addition & 0 deletions docs/user-guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ This section contains the basic user guide for Phantom.
hdf5
mpi
data-curation
apr_guide
Loading

0 comments on commit cdb7a8c

Please sign in to comment.