HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PetscGlobalDOF.cpp File Reference

Compute the global DOF index for all the grid points. More...

#include <stdlib.h>
#include <vector>
#include <basic.h>
#include <arrayfunctions.h>
#include <mpivars_cpp.h>
#include <simulation_object.h>
#include <petscinterface.h>

Go to the source code of this file.

Functions

static int ApplyPeriodicity (int dir, int ndims, int *size, int ghosts, double *phi)
 
int PetscGlobalDOF (void *c)
 

Detailed Description

Compute the global DOF index for all the grid points.

Author
Debojyoti Ghosh

Definition in file PetscGlobalDOF.cpp.

Function Documentation

static int ApplyPeriodicity ( int  dir,
int  ndims,
int *  size,
int  ghosts,
double *  phi 
)
static
Parameters
dirSpatial dimension along which to apply periodicity
ndimsNumber of spatial dimensions
sizeInteger array with the number of grid points in each spatial dimension
ghostsNumber of ghost points
phiThe array on which to apply the boundary condition

Definition at line 16 of file PetscGlobalDOF.cpp.

22 {
23  int bounds[ndims], index1[ndims], index2[ndims], offset[ndims],
24  done, p1 = 0, p2 = 0;
25  _ArrayCopy1D_(size,bounds,ndims); bounds[dir] = ghosts;
26 
27  done = 0; _ArraySetValue_(index1,ndims,0);
28  while (!done) {
29  _ArraySetValue_(offset,ndims,0); offset[dir] = -ghosts;
30  _ArrayIndex1DWO_(ndims,size,index1,offset,ghosts,p1);
31  _ArrayCopy1D_(index1,index2,ndims);
32  index2[dir] = index1[dir] + size[dir]-ghosts;
33  _ArrayIndex1D_(ndims,size,index2,ghosts,p2);
34 
35  phi[p1] = phi[p2];
36  _ArrayIncrementIndex_(ndims,bounds,index1,done);
37  }
38 
39  done = 0; _ArraySetValue_(index1,ndims,0);
40  while (!done) {
41  _ArraySetValue_(offset,ndims,0); offset[dir] = size[dir];
42  _ArrayIndex1DWO_(ndims,size,index1,offset,ghosts,p1);
43  _ArrayIndex1D_(ndims,size,index1,ghosts,p2);
44 
45  phi[p1] = phi[p2];
46  _ArrayIncrementIndex_(ndims,bounds,index1,done);
47  }
48  return(0);
49 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
#define _ArrayCopy1D_(x, y, size)
int PetscGlobalDOF ( void *  c)

Compute the global DOF index for all the grid points: The "global DOF index" is the component number (or block component number for HyPar::nvars > 1) of a grid point in the global solution vector. It is also the row number (or block row number) of the grid point in the global matrix representing, for example, the Jacobian of the right-hand-side.

PETScContext::globalDOF is an integer array with the same layout as the solution array HyPar::u (but with one component) containing the global DOF index for the corresponding grid points. It has the same number of ghost points as HyPar::u.

  • This array is initialized to -1.
  • The global DOF indices are computed for all non-ghost grid points.
  • If any boundaries are periodic, periodic boundary conditions are applied to fill the appropriate ghost points.
  • Ghost points corresponding to internal (MPI) boundaries are filled using MPIExchangeBoundariesnD().
  • Thus, ghost points corresponding to physical, non-periodic boundaries retain the initial value of -1.
Parameters
cObject of type PETScContext

Definition at line 69 of file PetscGlobalDOF.cpp.

70 {
71  PETScContext* ctxt = (PETScContext*) c;
73  int nsims = ctxt->nsims;
74 
75  ctxt->globalDOF.resize(nsims, nullptr);
76 
77  /* compute MPI offset */
78  std::vector<int> local_sizes(ctxt->nproc ,0);
79  local_sizes[ctxt->rank] = ctxt->npoints;
80  MPIMax_integer(local_sizes.data(),local_sizes.data(),ctxt->nproc,&sim[0].mpi.world);
81 
82  int MPIOffset = 0;
83  for (int i=0; i<ctxt->rank; i++) MPIOffset += local_sizes[i];
84 
85  int simOffset = 0;
86  for (int ns = 0; ns < nsims; ns++) {
87 
88  HyPar* solver = &(sim[ns].solver);
89  MPIVariables* mpi = &(sim[ns].mpi);
90 
91  int *dim = solver->dim_local,
92  ndims = solver->ndims,
93  ghosts = solver->ghosts,
94  npoints = solver->npoints_local,
95  npoints_wg = solver->npoints_local_wghosts,
96  nv = ndims + 1, i;
97 
98  ctxt->globalDOF[ns] = (double*) calloc( npoints_wg, sizeof(double) );
99  _ArraySetValue_(ctxt->globalDOF[ns], npoints_wg, -1.0);
100 
101  for (int i = 0; i < npoints; i++) {
102  int p = (ctxt->points[ns]+i*nv)[ndims];
103  ctxt->globalDOF[ns][p] = (double) (i + simOffset + MPIOffset);
104  }
105 
106  for (int i=0; i<ndims; i++) {
107  if (solver->isPeriodic[i]) {
108  ApplyPeriodicity(i,ndims,dim,ghosts,ctxt->globalDOF[ns]);
109  }
110  }
111  MPIExchangeBoundariesnD(ndims,1,dim,ghosts,mpi,ctxt->globalDOF[ns]);
112 
113  simOffset += npoints;
114  }
115 
116  return 0;
117 }
int npoints_local_wghosts
Definition: hypar.h:42
#define _ArraySetValue_(x, size, value)
int npoints_local
Definition: hypar.h:42
int MPIMax_integer(int *, int *, int, void *)
Definition: MPIMax.c:15
int * dim_local
Definition: hypar.h:37
std::vector< int * > points
static int ApplyPeriodicity(int dir, int ndims, int *size, int ghosts, double *phi)
int ghosts
Definition: hypar.h:52
MPI_Comm world
int * isPeriodic
Definition: hypar.h:162
std::vector< double * > globalDOF
Structure containing the variables for time-integration with PETSc.
Structure defining a simulation.
int ndims
Definition: hypar.h:26
int MPIExchangeBoundariesnD(int, int, int *, int, void *, double *)
Structure of MPI-related variables.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23