ammarhakim / gkylzero

Lowest, compiled layer of Gkeyll infrastructure.
MIT License
22 stars 5 forks source link

[DR] Non-uniform grids in the gyrokinetic app #546

Open Maxwell-Rosen opened 4 days ago

Maxwell-Rosen commented 4 days ago

Associated PR #547 This DR encompasses the need for non-uniform geometries in the numerical and analytic geometries that we deal with in Gkeyll. This work stems from a desire to pack cells near the mirror throat for magnetic mirror / WHAM simulations. @akashukla implemented the general geometry, but it assigned the grid a uniform spacing along a field line.

Two methods to deform the grid are implemented. A user can specify a mapping from the input file to deform the grid, or there can be a non-uniform mapping that is dependent on the global magnetic field. The magnetic field dependent mapping involves first initializing a uniform geometry magnetic field, then reading it to determine the appropriate deformation. This mapping may also have parameters set by the user. Since geometry is defined in 3x and then deflated for lower cdim simulations, this non-uniform mapping must be defined in 3x.

I introduced a new structure to the zero folder called position_map. This contains information about the non-uniform mapping and information from within the geometry.

The position map must be defined after the geometry is set because the simulation only knows about the configuration space basis after the deflation and geometry creation.

A separate position_map_set function is created to mirror the velocity_map interface, where the initialization function does not take in an array input. Instead, we need to read information from the geometry because this map is set in the geometry.

A new array is added to GK geometry called c2fa. This object mirrors mapc2p, except instead of populating it with cylindrical coordinates, c2fa is populated with the field-aligned coordinates of every point. This is necessary for the position_map object.

The geometry is deformed in a non-uniform way inside the gkyl_mirror_geo_calc, where the theta coordinate is mapped to a different one based on the specific mapping.

The initial conditions must be mapped to the non-uniform geometry. A method proj_on_basis_c2p_position_func is introduced to the gk_species_projection.c files to deform a grid using the position map. This initial condition mapping is why it's so important to store the c2fa mapping.

Initial conditions are appropriately mapped with the non-uniform deformation.

image

This is the non-uniform geometry applied to this situation. It contains both an analytic and magnetic field mapping, verifying that both are implemented correctly.

image

The magnetic field-dependent mapping has only been implemented in the mirror geometry modules but has a suggested structure to apply to other geometries.

Maxwell-Rosen commented 1 day ago

Here is the mapping for the step 1x non-uniform regression tests. Furthermore, the mapping was verified to work in the correct dimension by putting print statements in the code for the initial conditions for higher dimensionality simulations.

These are all 2 GPU tests.

image image

Here is the mapping for the sheath regression tests.

image image