HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
SparseGridsInitialSolution.cpp
Go to the documentation of this file.
1 
6 #include <arrayfunctions.h>
8 
9 extern "C" int VolumeIntegral (double*,double*,void*,void*);
10 
18 {
19  int ierr;
20 
21  /* first, read in the full grid initial solution */
22  int retval = ::InitialSolution( (void*) m_sim_fg, 1 );
23  if (retval) return retval;
24 
25  /* now, interpolate to all the sparse grids */
26  for (int n = 0; n < m_nsims_sg; n++) {
27 
28  if (!m_rank) {
29  printf("Interpolating grid coordinates to sparse grids domain %d.\n", n);
30  }
32 
33  HyPar* solver = &(m_sims_sg[n].solver);
34  MPIVariables* mpi = &(m_sims_sg[n].mpi);
35 
36  int nvars = solver->nvars;
37  int ghosts = solver->ghosts;
38  int *dim_local = solver->dim_local;
39 
40  /* calculate dxinv */
41  {
42  int offset = 0;
43  for (int d = 0; d < m_ndims; d++) {
44  for (int i = 0; i < dim_local[d]; i++) {
45  solver->dxinv[i+offset+ghosts]
46  = 2.0 / ( solver->x[i+1+offset+ghosts]
47  - solver->x[i-1+offset+ghosts] );
48  }
49  offset += (dim_local[d] + 2*ghosts);
50  }
51  }
52 
53  /* exchange MPI-boundary values of dxinv between processors */
54  {
55  int offset = 0;
56  for (int d = 0; d < m_ndims; d++) {
57  ierr = MPIExchangeBoundaries1D( mpi,
58  &(solver->dxinv[offset]),
59  dim_local[d],
60  ghosts,
61  d,
62  m_ndims );
63  if (ierr) return ierr;
64  offset += (dim_local[d] + 2*ghosts);
65  }
66  }
67 
68  /* fill in ghost values of dxinv at physical boundaries by extrapolation */
69  {
70  int offset = 0;
71  for (int d = 0; d < m_ndims; d++) {
72  double *dxinv = &(solver->dxinv[offset]);
73  int *dim = dim_local;
74  if (mpi->ip[d] == 0) {
75  /* fill left boundary along this dimension */
76  for (int i = 0; i < ghosts; i++) dxinv[i] = dxinv[ghosts];
77  }
78  if (mpi->ip[d] == mpi->iproc[d]-1) {
79  /* fill right boundary along this dimension */
80  for (int i = dim[d]+ghosts; i < dim[d]+2*ghosts; i++) {
81  dxinv[i] = dxinv[dim[d]+ghosts-1];
82  }
83  }
84  offset += (dim[d] + 2*ghosts);
85  }
86  }
87 
88  }
89 
90  return 0;
91 }
int VolumeIntegral(double *, double *, void *, void *)
int nvars
Definition: hypar.h:29
void interpolateGrid(SimulationObject *const, const SimulationObject *const)
double * x
Definition: hypar.h:107
int MPIExchangeBoundaries1D(void *, double *, int, int, int, int)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
std::vector< SimulationObject > m_sims_sg
int * dim_local
Definition: hypar.h:37
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
Contains macros and function definitions for common array operations.
double * dxinv
Definition: hypar.h:110