HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
SparseGridsInterpolate.cpp
Go to the documentation of this file.
1 
6 #include <arrayfunctions.h>
7 #include <mathfunctions_cpp.h>
8 #include <std_vec_ops.h>
10 
16  const SimulationObject* const a_src
17  )
18 {
19  /* get the destination grid dimensions */
20  GridDimensions dim_dst;
21  StdVecOps::copyFrom(dim_dst, a_dst->solver.dim_global, m_ndims);
22 
23  /* get number of vector components */
24  int nvars = a_src->solver.nvars;
25  if (nvars != a_dst->solver.nvars) {
26  fprintf(stderr, "Error in SparseGridsSimulation::interpolate(): unequal nvars\n");
27  exit(1);
28  }
29 
30  double *ug_dst = NULL;
31  interpolate(dim_dst, &ug_dst, a_src);
32 
33  /* partition the destination */
35  (void*) &(a_dst->mpi),
36  (a_dst->mpi.rank ? NULL : ug_dst),
37  a_dst->solver.u,
38  a_dst->solver.dim_global,
39  a_dst->solver.dim_local,
40  a_dst->solver.ghosts,
41  nvars);
42 
43  if (!m_rank) {
44  free(ug_dst);
45  }
46 
47  return;
48 }
49 
64  double** const a_u_dst,
65  const SimulationObject* const a_src
66  )
67 {
68  if ((*a_u_dst) != NULL) {
69  fprintf(stderr, "Error in SparseGridsSimulation::interpolate() - \n");
70  fprintf(stderr, " a_u_dst is not NULL!\n");
71  exit(1);
72  }
73 
74  /* get the source grid dimensions */
75  GridDimensions dim_src;
76  StdVecOps::copyFrom(dim_src, a_src->solver.dim_global, m_ndims);
77 
78  /* get number of vector components and number of ghost points*/
79  int nvars = a_src->solver.nvars;
80  int ghosts = a_src->solver.ghosts;
81 
82  /* gather the source on rank 0 */
83  double *ug_src = NULL;
84  if (!m_rank) allocateDataArrays(dim_src, nvars, &ug_src, ghosts);
86  (void*) &(a_src->mpi),
87  ug_src,
88  a_src->solver.u,
89  a_src->solver.dim_global,
90  a_src->solver.dim_local,
91  ghosts,
92  nvars );
93 
94  std::vector<int> periodic_arr(m_ndims);
95  for (int i=0; i<m_ndims; i++) {
96  periodic_arr[i] = (m_is_periodic[i] ? 1 : 0);
97  }
98 
99  if (!m_rank) {
100  int ierr = ::InterpolateGlobalnDVar( a_dim_dst.data(),
101  a_u_dst,
102  dim_src.data(),
103  ug_src,
104  nvars,
105  ghosts,
106  m_ndims,
107  periodic_arr.data());
108  if (ierr) {
109  fprintf(stderr,"InterpolateGlobalnDVar() returned with error!\n");
110  exit(1);
111  }
112  }
113 
114  return;
115 }
int MPIPartitionArraynDwGhosts(int, void *, double *, double *, int *, int *, int, int)
int nvars
Definition: hypar.h:29
Structure defining a simulation.
Contains function definitions for common mathematical functions for C++ code.
std::vector< int > GridDimensions
double * u
Definition: hypar.h:116
void allocateDataArrays(const GridDimensions &a_dim, const int a_nvars, double **const a_u, const int a_ngpt=0)
int MPIGatherArraynDwGhosts(int, void *, double *, double *, int *, int *, int, int)
int InterpolateGlobalnDVar(const int *const, double **const, const int *const, double *const, const int, const int, const int, const int *const)
std::vector< bool > m_is_periodic
Contains some vector ops.
int * dim_local
Definition: hypar.h:37
void interpolate(SimulationObject *const, const SimulationObject *const)
int ghosts
Definition: hypar.h:52
Contains macros and function definitions for common array operations.
int * dim_global
Definition: hypar.h:33
void copyFrom(std::vector< int > &a_iv, const int *const a_iv_carr, int a_n)
Definition: std_vec_ops.h:36