Version 2 (modified by jmstone, 5 years ago) (diff) |
---|

# Grid Structure

**Wiki/Documentation/ProgrammerGuide/Grid Structure**

We organize the information about each Grid in the Domain,
as well as the dependent
variables on that Gird, into a C structure called `GridS`. The dependent
variables *at cell cente* are organized into another C structure we
call `ConsS`. Thus, a GridS contains a 3D array of the ConsS structure, a 3D array of each component of the face centered
magnetic field, plus information about coordinates.
The GridS structure is reproduced below.

typedef struct Grid_s{ ConsS ***U; /* conserved variables */ #ifdef MHD Real ***B1i,***B2i,***B3i; /* interface magnetic fields */ #endif /* MHD */ #ifdef SELF_GRAVITY Real ***Phi, ***Phi_old; /* gravitational potential */ Real ***x1MassFlux; /* x1 mass flux for source term correction */ Real ***x2MassFlux; /* x2 mass flux for source term correction */ Real ***x3MassFlux; /* x3 mass flux for source term correction */ #endif /* GRAVITY */ Real MinX[3]; /* min(x) in each dir on this Grid [0,1,2]=[x1,x2,x3] */ Real MaxX[3]; /* max(x) in each dir on this Grid [0,1,2]=[x1,x2,x3] */ Real dx1,dx2,dx3; /* cell size on this Grid */ Real time, dt; /* current time and timestep */ int is,ie; /* start/end cell index in x1 direction */ int js,je; /* start/end cell index in x2 direction */ int ks,ke; /* start/end cell index in x3 direction */ int Nx[3]; /* # of zones in each dir on Grid [0,1,2]=[x1,x2,x3] */ int Disp[3]; /* i,j,k displacements of Grid from origin [0,1,2]=[i,j,k] */ int rx1_id, lx1_id; /* ID of Grid to R/L in x1-dir (default=-1; no Grid) */ int rx2_id, lx2_id; /* ID of Grid to R/L in x2-dir (default=-1; no Grid) */ int rx3_id, lx3_id; /* ID of Grid to R/L in x3-dir (default=-1; no Grid) */ #ifdef STATIC_MESH_REFINEMENT int NCGrid; /* # of child Grids that overlap this Grid */ int NPGrid; /* # of parent Grids that this Grid overlaps */ int NmyCGrid; /* # of child Grids on same processor as this Grid */ int NmyPGrid; /* # of parent Grids on same processor (either 0 or 1) */ GridOvrlpS *CGrid; /* 1D array of data for NCGrid child overlap regions */ GridOvrlpS *PGrid; /* 1D array of data for NPGrid parent overlap regions */ /* NB: The first NmyCGrid[NmyPGrid] elements of these arrays contain overlap * regions being updated by the same processor as this Grid */ #endif /* STATIC_MESH_REFINEMENT */ #ifdef CYLINDRICAL Real *r,*ri; /* cylindrical scaling factors */ #endif /* CYLINDRICAL */ }GridS;

Some variables relating to SMR and particles have been deleted in the code reproduced above for clarity.

The advantage of making the cell centered variables a 3D
array of type `ConsS`, rather than making the Gas structure itself contain
3D arrays, is that we guarantee that different variables at the same
grid cell will be stored contiguously in memory, which can improve cache
performance.