30 double* xg_src = NULL;
33 int offset_global, offset_local;
34 offset_global = offset_local = 0;
37 (a_src->
mpi.
rank ? NULL : &xg_src[offset_global]),
49 double *xg_dst = NULL;
62 for (
int dir = 0; dir <
m_ndims; dir++) {
65 dim_to[dir] = dim_dst[dir];
67 if (dim_from[dir] == dim_to[dir])
continue;
69 double fac = (dim_to[dir] > dim_from[dir] ?
70 (double)dim_to[dir]/(
double)dim_from[dir]
71 : (double)dim_from[dir]/(
double)dim_to[dir] );
73 fprintf(stderr,
"Error in SparseGridsSimulation::interpolate() - \n");
74 fprintf(stderr,
" refinement/coarsening factor not a power of 2!\n");
78 if (x_from != NULL) free(x_from);
82 if (dim_to[dir] < dim_from[dir]) {
91 for (
int d = 0; d <
m_ndims; d++) {
92 if (dim_to[d] != dim_dst[d]) {
93 fprintf(stderr,
"Error in SparseGridsSimulation::interpolate() - \n");
94 fprintf(stderr,
" dim_to[%d] != dim_dst[%d]!\n", d, d);
99 if (x_from != NULL) free(x_from);
105 int offset_global = 0, offset_local = 0;
106 for (
int d=0; d<
m_ndims; d++) {
108 (a_dst->
mpi.
rank ? NULL : &xg_dst[offset_global]),
125 for (
int d = 0; d <
m_ndims; d++) {
138 for (
int d = 0; d <
m_ndims; d++) {
139 double* X = &(a_dst->
solver.
x[offset]);
142 if (a_dst->
mpi.
ip[d] == 0) {
144 for (
int i = 0; i < ghosts; i++) {
145 int delta = ghosts - i;
146 X[i] = X[ghosts] + ((double) delta) * (X[ghosts]-X[ghosts+1]);
151 for (
int i = dim[d]+ghosts; i < dim[d]+2*ghosts; i++) {
152 int delta = i - (dim[d]+ghosts-1);
153 X[i] = X[dim[d]+ghosts-1]
154 + ((double) delta) * (X[dim[d]+ghosts-1]-X[dim[d]+ghosts-2]);
157 offset += (dim[d] + 2*ghosts);
170 const double*
const a_x_src,
171 double*
const a_x_dst,
175 for (
int d = 0; d <
m_ndims; d++) {
176 if ((d != a_dir) && (a_dim_src[d] != a_dim_dst[d])) {
177 fprintf(stderr,
"Error in SparseGridsSimulation::coarsenGrid1D() -\n");
178 fprintf(stderr,
" a_dim_src[%d] != a_dim_dst[%d]\n", d, d);
183 int n_src = a_dim_src[a_dir];
184 int n_dst = a_dim_dst[a_dir];
186 fprintf(stderr,
"Error in SparseGridsSimulation::coarsenGrid1D() -\n");
187 fprintf(stderr,
" destination grid is finer than source grid along a_dir!\n");
191 double fac = ((double) n_src) / ((double) n_dst);
192 int stride = (int) fac;
194 fprintf(stderr,
"Error in SparseGridsSimulation::coarsenGrid1D() -\n");
195 fprintf(stderr,
" non-integer coarsening factor!\n");
199 const double* x_src = a_x_src;
200 double* x_dst = a_x_dst;
202 for (
int d = 0; d <
m_ndims; d++) {
206 for (
int i = 0; i < a_dim_dst[d]; i++) {
208 for (
int j=stride*i; j<stride*(i+1); j++) {
210 fprintf(stderr,
"Error in SparseGridsSimulation::coarsenGrid1D() -\n");
211 fprintf(stderr,
" j >= n_src!\n");
216 avg /= (double) stride;
226 x_src += a_dim_src[d];
227 x_dst += a_dim_dst[d];
240 const double*
const a_x_src,
241 double*
const a_x_dst,
245 for (
int d = 0; d <
m_ndims; d++) {
246 if ((d != a_dir) && (a_dim_src[d] != a_dim_dst[d])) {
247 fprintf(stderr,
"Error in SparseGridsSimulation::coarsenGrid1D() -\n");
248 fprintf(stderr,
" a_dim_src[%d] != a_dim_dst[%d]\n", d, d);
253 int n_src = a_dim_src[a_dir];
254 int n_dst = a_dim_dst[a_dir];
256 fprintf(stderr,
"Error in SparseGridsSimulation::refineGrid1D() -\n");
257 fprintf(stderr,
" destination grid is coarser than source grid along a_dir!\n");
261 double fac = ((double) n_dst) / ((double) n_src);
262 int stride = (int) fac;
264 fprintf(stderr,
"Error in SparseGridsSimulation::refineGrid1D() -\n");
265 fprintf(stderr,
" non-integer refinement factor!\n");
270 for (
int d = 0; d < a_dir; d++) offset += a_dim_src[d];
271 const double* x_src = a_x_src + offset;
272 double* x_dst = a_x_dst + offset;
274 fprintf(stderr,
"Error in SparseGridsSimulation::refineGrid1D() -\n");
275 fprintf(stderr,
" NOT YET IMPLEMENTED! Why do you need this?\n");
void refineGrid1D(const GridDimensions &, const GridDimensions &, const double *const, double *const, int)
Structure defining a simulation.
int MPIPartitionArray1D(void *, double *, double *, int, int, int, int)
std::vector< int > GridDimensions
Some basic definitions and macros.
void interpolateGrid(SimulationObject *const, const SimulationObject *const)
int MPIExchangeBoundaries1D(void *, double *, int, int, int, int)
int MPIGatherArray1D(void *, double *, double *, int, int, int, int)
void allocateGridArrays(const GridDimensions &a_dim, double **const a_x, const int a_ngpt=0)
Contains some vector ops.
void coarsenGrid1D(const GridDimensions &, const GridDimensions &, const double *const, double *const, int)
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
void copyFrom(std::vector< int > &a_iv, const int *const a_iv_carr, int a_n)