HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
PetscCreatePointList.cpp File Reference
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <arrayfunctions.h>
#include <mpivars_cpp.h>
#include <simulation_object.h>
#include <petscinterface_struct.h>

Go to the source code of this file.

Functions

int PetscCreatePointList (void *obj)
 

Function Documentation

◆ PetscCreatePointList()

int PetscCreatePointList ( void *  obj)

Create a list of computational points for each simulation domain: This is a list of all the grid points on which the PDE is solved. Thus, it is the total number of grid points minus the ghost points and blanked out points.

Note: this list is local, not global.

Parameters
objObject of type PETScContext

Definition at line 25 of file PetscCreatePointList.cpp.

26 {
27  PETScContext* ctxt = (PETScContext*) obj;
29 
30  int nsims = ctxt->nsims;
31  int ndims = sim[0].solver.ndims;
32 
33  /* count the number of computational points */
34  ctxt->npoints = 0;
35  ctxt->ndofs = 0;
36  ctxt->offsets = (int*) calloc(nsims, sizeof(int));
37  for (int ns = 0; ns < nsims; ns++) {
38  ctxt->npoints += sim[ns].solver.npoints_local;
39  ctxt->offsets[ns] = ctxt->ndofs;
40  ctxt->ndofs += (sim[ns].solver.npoints_local*sim[ns].solver.nvars);
41  }
42 
43  int nv = ndims+1;
44  ctxt->points.resize(nsims, nullptr);
45 
46  for (int ns = 0; ns < nsims; ns++) {
47 
48  int npoints = sim[ns].solver.npoints_local;
49  ctxt->points[ns] = (int*) calloc (npoints*nv,sizeof(int));
50 
51  const int* const dim( sim[ns].solver.dim_local );
52  const int ghosts( sim[ns].solver.ghosts );
53 
54  int done = 0, i = 0;
55  std::vector<int> index(ndims,0);
56  while (!done) {
57  int p; _ArrayIndex1D_(ndims, dim, index.data(), ghosts, p);
58  _ArrayCopy1D_(index.data(), (ctxt->points[ns]+i*nv), ndims);
59  (ctxt->points[ns]+i*nv)[ndims] = p;
60  _ArrayIncrementIndex_(ndims,dim,index,done);
61  i++;
62  }
63 
64  if (i != npoints) {
65  fprintf(stderr,"Error in PetscCreatePointList() on rank %d:\n", sim[ns].mpi.rank);
66  fprintf(stderr,"Inconsistency in point count - %d, %d.\n",
67  i, npoints);
68  return 1;
69  }
70  }
71 
72  int global_npoints;
73  int global_ndofs;
74  MPISum_integer(&global_npoints,&(ctxt->npoints),1,&sim[0].mpi.world);
75  MPISum_integer(&global_ndofs,&(ctxt->ndofs),1,&sim[0].mpi.world);
76  if (!ctxt->rank) {
77  printf("PETSc: total number of computational points is %d.\n",global_npoints);
78  printf("PETSc: total number of computational DOFs is %d.\n",global_ndofs);
79  }
80 
81  return 0;
82 }
std::vector< int * > points
int nvars
Definition: hypar.h:29
Structure defining a simulation.
int npoints_local
Definition: hypar.h:42
int MPISum_integer(int *, int *, int, void *)
Definition: MPISum.c:16
#define _ArrayIndex1D_(N, imax, i, ghost, index)
Structure containing the variables for time-integration with PETSc.
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _ArrayCopy1D_(x, y, size)