HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
PetscCreatePointList.cpp
Go to the documentation of this file.
1 
6 #ifdef with_petsc
7 
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <vector>
11 #include <arrayfunctions.h>
12 #include <mpivars_cpp.h>
13 #include <simulation_object.h>
14 #include <petscinterface_struct.h>
15 
25 int PetscCreatePointList(void *obj )
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 }
83 
84 #endif
std::vector< int * > points
int nvars
Definition: hypar.h:29
Structure defining a simulation.
C++ declarations for MPI-related functions.
int npoints_local
Definition: hypar.h:42
Simulation object.
int ndims
Definition: hypar.h:26
int MPISum_integer(int *, int *, int, void *)
Definition: MPISum.c:16
MPI_Comm world
#define _ArrayIndex1D_(N, imax, i, ghost, index)
Structure containing the variables for time-integration with PETSc.
#define _ArrayIncrementIndex_(N, imax, i, done)
int PetscCreatePointList(void *obj)
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
Contains structure that defines the interface for time integration with PETSc (https://petsc.org/release/)