Skip to content

Coordinate Systems and Meshes

Kyle Gerard Felker edited this page Mar 22, 2018 · 18 revisions

Select a Coordinate System

Currently the following coordinate systems are available:

  • Cartesian (default; x, y, z)
  • Cylindrical coordinates (r, ϕ, z)
  • Spherical-polar coordinates (r, θ, ϕ)
  • Various general-relativistic coordinates

To select a coordinate system, configure the code with the --coord [coord] option.

> python ./configure.py --prob sphtorus --coord spherical_polar

The names of coordinate systems are corresponding to the file names in src/coordinates, and are listed in the help message (use the -h option).

Mesh Spacing

By default, the cell size is simply set evenly: dx = L / Nx. It is sometimes convenient to use logarithmic spacing, i.e. the cell size increases (or decreases) by a constant factor r. This is especially useful in spherical-polar coordinates so that it can maintain the cell aspect ratio. To enable this, set x1rat, x2rat, or x3rat in the <mesh> block in the input file.

    <mesh>
    ...
    x1rat = 1.01

While Athena++ uses formulae consistent with nonuniform mesh spacing, too large a mesh ratio should not be used; a non-fatal warning is raised if the value is not between 0.9 and 1.1 everywhere. The reconstruction algorithm reduces to first-order if the grid spacing changes too much from cell-to-cell, and moreover, the nonuniform truncation error can produce anomalous reflections of waves.

Note that this ratio should be adjusted when resolution is manually changed. For example, when the number of cells in the direction is doubled, the ratio should be adjusted to square root of the original one to maintain consistency. This adjustment is done automatically whenever mesh refinement is invoked.

User-Defined Mesh Generator

More generally, any kind of mesh spacing can be used through the user-defined mesh generator feature. Similar to the user-defined boundary conditions, define the MeshGenerator function first:

    Real MyMeshSpacingX2(Real x, RegionSize rs);

And then enroll it in Mesh::InitUserMeshData:

    EnrollUserMeshGenerator(X2DIR, MyMeshSpacingX2);

Finally, the input variable mesh/x2rat=-1.0 in The Input File or on the command line in order to run a simulation with a MeshGenerator function in that direction.

The MeshGenerator function in x1, for example, must be a monotonic, 1:1 mapping from [0:1] to [rs.x1min:rs.x1max], which returns a coordinate location between rs.x1min:rs.x1max for given x = i/Nx (the logical location of the cell).

For example, let us consider a mesh generator which produces high resolution near the midplane in the θ (x2) direction in spherical-polar coordinates.

    Real CompressedX2(Real x, RegionSize rs)
    {
      Real t=2.0*x-1.0;
      Real w=0.25*(t*(t*t+1.0))+0.5;
      return w*rs.x2max+(1.0-w)*rs.x2min;
    }

This function gives mesh spacing proportional to (3ψ2 + 1) where ψ is the angle from the midplane, and the mesh spacing near the pole is about 4 times larger than that near the midplane. The code will give a warning if the resulting mesh contains a steep change in the mesh size.

Clone this wiki locally