Gravity - hyschive/gamer-fork GitHub Wiki
Related options: --gravity, --pot_scheme, --store_pot_ghost, --unsplit_gravity, --comoving
Parameters described on this page: OPT__BC_POT, GFUNC_COEFF0, NEWTON_G, SOR_OMEGA, SOR_MAX_ITER, SOR_MIN_ITER, MG_MAX_ITER, MG_NPRE_SMOOTH, MG_NPOST_SMOOTH, MG_TOLERATED_ERROR, OPT__GRA_P5_GRADIENT, OPT__SELF_GRAVITY, OPT__EXT_ACC, OPT__EXT_POT, EXT_POT_TABLE_NAME, EXT_POT_TABLE_NPOINT_X, EXT_POT_TABLE_NPOINT_Y, EXT_POT_TABLE_NPOINT_Z, EXT_POT_TABLE_DH, EXT_POT_TABLE_EDGEL_X, EXT_POT_TABLE_EDGEL_Y, EXT_POT_TABLE_EDGEL_Z
Other related parameters: DT__GRAVITY, POT_GPU_NPGROUP
Parameters below are shown in the format: Name
(Valid Values) [Default Value]
-
- Description: Gravity boundary condition. See also Potential Outside the Isolated Boundaries.
- Restriction:
-
-
Description:
Green's function coefficient for calculating the "self"
gravitational potential of each cell (i.e., the gravitational
potential contribution from the mass within the same cell).
The default value depends on the particle interpolation scheme
(
PAR_INTERP
). Set GFUNC_COEFF0=0.0 to exclude the self-potential. - Restriction: Only applicable to the isolated boundary condition.
-
Description:
Green's function coefficient for calculating the "self"
gravitational potential of each cell (i.e., the gravitational
potential contribution from the mass within the same cell).
The default value depends on the particle interpolation scheme
(
-
NEWTON_G
(>0.0) [conform to the unit system set by OPT__UNIT]
-
- Description: Parameter of the SOR Poisson solver for optimizing the convergence rate.
- Restriction: Only applicable when adopting the compilation option --pot_scheme=SOR.
-
-
Description:
Maximum number of iterations in the SOR Poisson solver.
The default value depends on the adopted floating-point accuracy (
FLOAT8
). - Restriction: Only applicable when adopting the compilation option --pot_scheme=SOR.
-
Description:
Maximum number of iterations in the SOR Poisson solver.
The default value depends on the adopted floating-point accuracy (
-
- Description: Minimum number of iterations in the SOR Poisson solver.
- Restriction: Only applicable when adopting the compilation option --pot_scheme=SOR.
-
- Description: Maximum number of iterations in the multigrid Poisson solver. The default value depends on the adopted floating-point accuracy (--double).
- Restriction: Only applicable when adopting the compilation option --pot_scheme=MG.
-
- Description: Number of pre-smoothing steps in the multigrid Poisson solver.
- Restriction: Only applicable when adopting the compilation option --pot_scheme=MG.
-
- Description: Number of post-smoothing steps in the multigrid Poisson solver.
- Restriction: Only applicable when adopting the compilation option --pot_scheme=MG.
-
- Description: Maximum tolerable error in the multigrid Poisson solver.
- Restriction: Only applicable when adopting the compilation option --pot_scheme=MG.
-
- Description: Use 5-point instead of 3-point gradient for calculating the gravitational acceleration from potential. This functionality is only experimental.
-
Restriction:
Must manually set
#define GRA_GHOST_SIZE 2
(and#define USG_GHOST_SIZE 2
as well when adopting the compilation option --unsplit_gravity) in the header fileMacro.h
. Unsupported for particle update.
-
- Description: Enable self-gravity.
- Restriction:
-
- Description: Add external acceleration. See External Acceleration/Potential for how to specify external acceleration.
- Restriction: Not applicable to the wave dark matter simulations (--model=ELBDM).
-
- Description: Add external potential. See External Acceleration/Potential for how to specify external potential.
- Restriction:
-
-
Description:
For OPT__EXT_POT
=2
: table name. - Restriction:
-
Description:
For OPT__EXT_POT
-
-
Description:
For OPT__EXT_POT
=2
: table size (i.e., number of data points) along the x direction. - Restriction:
-
Description:
For OPT__EXT_POT
-
- Description: See EXT_POT_TABLE_NPOINT_X.
- Restriction:
-
- Description: See EXT_POT_TABLE_NPOINT_X.
- Restriction:
-
-
Description:
For OPT__EXT_POT
=2
: spatial interval between adjacent tabular data. - Restriction:
-
Description:
For OPT__EXT_POT
-
-
Description:
For OPT__EXT_POT
=2
: starting x coordinate of the tabular data. -
Restriction:
Must cover the simulation domain plus gravity ghost zones. Specifically,
EXT_POT_TABLE_EDGEL_X
must be smaller or equal toDomainLeftEdge - 1*RootLevelCell
andEXT_POT_TABLE_EDGEL_X + (EXT_POT_TABLE_NPOINT_X-1)*EXT_POT_TABLE_DH
must be larger or equal toDomainRightEdge + 1*RootLevelCell
.
-
Description:
For OPT__EXT_POT
-
- Description: See EXT_POT_TABLE_EDGEL_X.
- Restriction:
-
- Description: See EXT_POT_TABLE_EDGEL_X.
- Restriction:
Follow the steps below to add external acceleration with an analytical function. Get familiar with the general procedure of Adding Problem-specific Functionalities first and be aware that adding external acceleration/potential takes a few extra steps in order to utilize GPUs.
- Enable OPT__EXT_ACC.
- Go to your new test problem folder and copy the built-in point-mass acceleration
routine as a template:
cp ../../../SelfGravity/CPU_Gravity/CPU_ExtAcc_PointMass.cpp ExtAcc_NewProblem.cpp
- Edit
ExtAcc_NewProblem.cpp
to- Replace the keyword
PointMass
byNewProblem
(or whatever appropriate). - Edit the routine
SetExtAccAuxArray_NewProblem()
to set the auxiliary arrayAuxArray[]
, which will be automatically passed toExtAcc_NewProblem()
as the input arrayUserArray[]
. The array size is set byEXT_ACC_NAUX_MAX
ininclude/Macro.h
(default 20). - Edit the routine
ExtAcc_NewProblem()
, which should return the external accelerationAcc[]
at(x, y, z, Time)
.
- Replace the keyword
- Link
ExtAcc_NewProblem.cpp
to a corresponding CUDA source file:This avoids writing redundant codes for CPU and GPU runs separately.ln -s ExtAcc_NewProblem.cpp ExtAcc_NewProblem.cu
- Edit your problem source file (e.g.,
Init_TestProb_Hydro_NewProblem.cpp
) to- Declare a function prototype on top of the file:
void Init_ExtAcc_NewProblem();
- Set up a function pointer in your problem initialization
function (e.g.,
Init_TestProb_Hydro_NewProblem()
):# ifdef GRAVITY Init_ExtAcc_Ptr = Init_ExtAcc_NewProblem # endif
- Declare a function prototype on top of the file:
Adding external potential can be done in a very similar way.
Enable OPT__EXT_POT=1
and then follow the procedure
above and replace Acc
by Pot
. A point-mass example can be found
at src/SelfGravity/CPU_Poisson/CPU_ExtPot_PointMass.cpp
.
Caution: wave dark matter simulations (i.e., --model=ELBDM) does not support external acceleration. Just use external potential.
External potential can also be set via interpolating a table loaded from disk.
Set OPT__EXT_POT=2
and all EXT_POT_TABLE_*
parameters.
The following C++ example creates such a table with a point-mass potential.
#include <cstdio>
#include <cmath>
typedef double real; // this must be consistent with the compilation option FLOAT8
int main()
{
// parameters
const char *Filename = "ExtPotTable"; // EXT_POT_TABLE_NAME
const int NX = 131; // EXT_POT_TABLE_NPOINT_X
const int NY = 131; // EXT_POT_TABLE_NPOINT_Y
const int NZ = 131; // EXT_POT_TABLE_NPOINT_Z
const double dh = 0.0078125; // EXT_POT_TABLE_NPOINT_DH
const double EdgeL[3] = { -dh, -dh, -dh }; // EXT_POT_TABLE_EDGEL_X/Y/Z
// set the external potential array
const double G = 1.0; // gravitational constant
const double M = 1.0; // particle mass
const double cx = EdgeL[0] + 0.5*(NX-1)*dh; // centre
const double cy = EdgeL[1] + 0.5*(NY-1)*dh;
const double cz = EdgeL[2] + 0.5*(NZ-1)*dh;
double dx, dy, dz, r;
real (*ExtPot)[NY][NX] = new real [NZ][NY][NX];
for (int k=0; k<NZ; k++) { dz = EdgeL[2] + k*dh - cz;
for (int j=0; j<NY; j++) { dy = EdgeL[1] + j*dh - cy;
for (int i=0; i<NX; i++) { dx = EdgeL[0] + i*dh - cx;
r = sqrt( dx*dx + dy*dy + dz*dz );
ExtPot[k][j][i] = -G*M/r;
}}}
// output
FILE *File = fopen( Filename, "wb" );
fwrite( ExtPot, sizeof(real), (long)NX*NY*NZ, File );
fclose( File );
delete [] ExtPot;
}
[Optional] To implement a user-specified interpolation routine, use
src/SelfGravity/CPU_Poisson/CPU_ExtPot_Tabular.cpp
as a template and
follow the steps [2-5] in Using Analytical Function.
Caution: external acceleration does not support this functionality yet.