18 if (x%2 != 0)
return 0;
33 const int*
const a_dim_dst,
34 const double*
const a_u_src,
35 double*
const a_u_dst,
42 for (
int d = 0; d < a_ndims; d++) {
43 if ((d != a_dir) && (a_dim_src[d] != a_dim_dst[d])) {
44 fprintf(stderr,
"Error in coarsen1D() -\n");
45 fprintf(stderr,
" a_dim_src[%d] != a_dim_dst[%d]\n", d, d);
50 int n_src = a_dim_src[a_dir];
51 int n_dst = a_dim_dst[a_dir];
53 fprintf(stderr,
"Error in coarsen1D() -\n");
54 fprintf(stderr,
" destination grid is finer than source grid along a_dir!\n");
58 double fac = ((double) n_src) / ((double) n_dst);
59 int stride = (int) fac;
61 fprintf(stderr,
"Error in coarsen1D() -\n");
62 fprintf(stderr,
" non-integer coarsening factor!\n");
67 double c0, c1, c2, c3, c4, c5;
78 c1 = c4 = -25.0/256.0;
79 c2 = c3 = 150.0/256.0;
87 int bounds_transverse[a_ndims];
89 bounds_transverse[a_dir] = 1;
91 int index_transverse[a_ndims], done = 0;
95 int index_dst[a_ndims], index_src[a_ndims];
99 for (
int i_dst = 0; i_dst < n_dst; i_dst++) {
101 int i_m1 = i_dst*stride + (stride/2-1);
109 index_dst[a_dir] = i_dst;
113 index_src[a_dir] = i_m3;
117 index_src[a_dir] = i_m2;
121 index_src[a_dir] = i_m1;
125 index_src[a_dir] = i_p1;
129 index_src[a_dir] = i_p2;
133 index_src[a_dir] = i_p3;
136 for (
int v = 0; v < a_nvars; v++) {
137 double val = c0 * a_u_src[p_m3*a_nvars+v]
138 + c1 * a_u_src[p_m2*a_nvars+v]
139 + c2 * a_u_src[p_m1*a_nvars+v]
140 + c3 * a_u_src[p_p1*a_nvars+v]
141 + c4 * a_u_src[p_p2*a_nvars+v]
142 + c5 * a_u_src[p_p3*a_nvars+v];
143 a_u_dst[p*a_nvars+v] = val;
164 const int*
const a_dim_dst,
165 const double*
const a_u_src,
166 double*
const a_u_dst,
173 for (
int d = 0; d < a_ndims; d++) {
174 if ((d != a_dir) && (a_dim_src[d] != a_dim_dst[d])) {
175 fprintf(stderr,
"Error in refine1D() -\n");
176 fprintf(stderr,
" a_dim_src[%d] != a_dim_dst[%d]\n", d, d);
181 int n_src = a_dim_src[a_dir];
182 int n_dst = a_dim_dst[a_dir];
184 fprintf(stderr,
"Error in refine1D() -\n");
185 fprintf(stderr,
" destination grid is coarser than source grid along a_dir!\n");
189 double fac = ((double) n_dst) / ((double) n_src);
190 int stride = (int) fac;
192 fprintf(stderr,
"Error in refine1D() -\n");
193 fprintf(stderr,
" non-integer refinement factor!\n");
199 int bounds_transverse[a_ndims];
201 bounds_transverse[a_dir] = 1;
203 int index_transverse[a_ndims], done = 0;
207 int index_dst [a_ndims],
222 for (
int i_dst = 0; i_dst < n_dst; i_dst++) {
224 double xi_dst = ((double) i_dst + 0.5) / ((double) stride) - 0.5;
226 int i_src_2 = floor(xi_dst);
227 int i_src_3 = ceil(xi_dst);
228 int i_src_0 = i_src_2 - 2;
229 int i_src_1 = i_src_2 - 1;
230 int i_src_4 = i_src_3 + 1;
231 int i_src_5 = i_src_3 + 2;
233 double alpha = (xi_dst - (double)i_src_2) / ((double)i_src_3 - (
double)i_src_2);
235 index_dst[a_dir] = i_dst;
238 index_src0[a_dir] = i_src_0;
239 int q0;
_ArrayIndex1D_(a_ndims, a_dim_src, index_src0, a_ngpt, q0);
241 index_src1[a_dir] = i_src_1;
242 int q1;
_ArrayIndex1D_(a_ndims, a_dim_src, index_src1, a_ngpt, q1);
244 index_src2[a_dir] = i_src_2;
245 int q2;
_ArrayIndex1D_(a_ndims, a_dim_src, index_src2, a_ngpt, q2);
247 index_src3[a_dir] = i_src_3;
248 int q3;
_ArrayIndex1D_(a_ndims, a_dim_src, index_src3, a_ngpt, q3);
250 index_src4[a_dir] = i_src_4;
251 int q4;
_ArrayIndex1D_(a_ndims, a_dim_src, index_src4, a_ngpt, q4);
253 index_src5[a_dir] = i_src_5;
254 int q5;
_ArrayIndex1D_(a_ndims, a_dim_src, index_src5, a_ngpt, q5);
257 double c0, c1, c2, c3, c4, c5;
273 c0 = -((-3.0 + alpha)*(-2.0 + alpha)*(-1.0 + alpha)*alpha*(1.0 + alpha))/120.0;
274 c1 = ((-3.0 + alpha)*(-2.0 + alpha)*(-1.0 + alpha)*alpha*(2.0 + alpha))/24.0;
275 c2 = -((-3.0 + alpha)*(-2.0 + alpha)*(-1.0 + alpha)*(1.0 + alpha)*(2.0 + alpha))/12.0;
276 c3 = ((-3.0 + alpha)*(-2.0 + alpha)*alpha*(1.0 + alpha)*(2.0 + alpha))/12.0;
277 c4 = -((-3.0 + alpha)*(-1.0 + alpha)*alpha*(1.0 + alpha)*(2.0 + alpha))/24.0;
278 c5 = (alpha*(4.0 - 5.0*alpha*alpha + alpha*alpha*alpha*alpha))/120.0;
284 for (
int v = 0; v < a_nvars; v++) {
286 a_u_dst[p*a_nvars+v] = c0 * a_u_src[q0*a_nvars+v]
287 + c1 * a_u_src[q1*a_nvars+v]
288 + c2 * a_u_src[q2*a_nvars+v]
289 + c3 * a_u_src[q3*a_nvars+v]
290 + c4 * a_u_src[q4*a_nvars+v]
291 + c5 * a_u_src[q5*a_nvars+v];
318 double**
const a_u_dst,
319 const int*
const a_dim_src,
320 double*
const a_u_src,
324 const int*
const a_periodic
327 if ((*a_u_dst) != NULL) {
328 fprintf(stderr,
"Error in InterpolateGlobalnDVar() - \n");
329 fprintf(stderr,
" a_u_dst is not NULL!\n");
333 if (a_u_src == NULL) {
334 fprintf(stderr,
"Error in InterpolateGlobalnDVar() - \n");
335 fprintf(stderr,
" a_u_src is NULL!\n");
339 int dim_to[a_ndims], dim_from[a_ndims];
348 for (
int dir = 0; dir < a_ndims; dir++) {
351 dim_to[dir] = a_dim_dst[dir];
353 if (dim_from[dir] == dim_to[dir])
continue;
355 double fac = (dim_to[dir] > dim_from[dir] ?
356 (double)dim_to[dir]/(
double)dim_from[dir]
357 : (double)dim_from[dir]/(
double)dim_to[dir] );
360 fprintf(stderr,
"Error in interpolate() - \n");
361 fprintf(stderr,
" refinement/coarsening factor not a power of 2!\n");
365 if (u_from != NULL) free(u_from);
370 long size = (long) a_nvars;
371 for (
int d = 0; d < a_ndims; d++) {
372 size *= (long) (dim_to[d] + 2*a_ghosts);
374 u_to = (
double*) calloc (size,
sizeof(
double));
384 if (dim_to[dir] < dim_from[dir]) {
393 if (retval)
return retval;
403 if (retval)
return retval;
409 for (
int d = 0; d < a_ndims; d++) {
410 if (dim_to[d] != a_dim_dst[d]) {
411 fprintf(stderr,
"Error in InterpolateGlobalnDVar() - \n");
412 fprintf(stderr,
" dim_to[%d] (%d) != a_dim_dst[%d] (%d)!\n",
413 d, dim_to[d], d, a_dim_dst[d]);
418 if (u_from != NULL) free(u_from);
void fillGhostCells(const int *const, const int, double *const, const int, const int, const int *const)
Contains function definitions for common mathematical functions.
static int refine1D(const int *const a_dim_src, const int *const a_dim_dst, const double *const a_u_src, double *const a_u_dst, const int a_dir, const int a_nvars, const int a_ngpt, const int a_ndims)
static int coarsen1D(const int *const a_dim_src, const int *const a_dim_dst, const double *const a_u_src, double *const a_u_dst, const int a_dir, const int a_nvars, const int a_ngpt, const int a_ndims)
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
static int isPowerOfTwo(int x)
int InterpolateGlobalnDVar(const int *const a_dim_dst, double **const a_u_dst, const int *const a_dim_src, double *const a_u_src, const int a_nvars, const int a_ghosts, const int a_ndims, const int *const a_periodic)