From f8baa7935c615baff133bf3425fd996f907496d8 Mon Sep 17 00:00:00 2001 From: schnetter <> Date: Wed, 30 Apr 2003 10:37:00 +0000 Subject: First cut at the interpolator. Tentatively works on unigrid and for First cut at the interpolator. Tentatively works on unigrid and for singlepatch mode. darcs-hash:20030430103731-07bb3-dad06ae817a997cfd4f1beefc4065ca1ecc12342.gz --- Carpet/CarpetInterp/src/interp.cc | 681 +++------------------------------ Carpet/CarpetInterp/src/interp.h | 2 +- Carpet/CarpetInterp/src/interp.hh | 29 +- Carpet/CarpetInterp/src/make.code.defn | 4 +- 4 files changed, 75 insertions(+), 641 deletions(-) (limited to 'Carpet/CarpetInterp/src') diff --git a/Carpet/CarpetInterp/src/interp.cc b/Carpet/CarpetInterp/src/interp.cc index 8b48e9c54..47d5b9cb8 100644 --- a/Carpet/CarpetInterp/src/interp.cc +++ b/Carpet/CarpetInterp/src/interp.cc @@ -1,30 +1,22 @@ -// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetInterp/src/interp.cc,v 1.36 2004/09/13 14:36:13 schnetter Exp $ +// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetInterp/src/interp.cc,v 1.1 2003/04/30 12:37:31 schnetter Exp $ #include -#include -#include +#include #include #include #include "cctk.h" -#include "util_ErrorCodes.h" -#include "util_Table.h" +#include "Carpet/CarpetLib/src/vect.hh" -#include "bbox.hh" -#include "data.hh" -#include "defs.hh" -#include "ggf.hh" -#include "vect.hh" - -#include "carpet.hh" +#include "Carpet/Carpet/src/carpet.hh" #include "interp.hh" extern "C" { - static char const * const rcsid = "$Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetInterp/src/interp.cc,v 1.36 2004/09/13 14:36:13 schnetter Exp $"; + static char const * const rcsid = "$Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetInterp/src/interp.cc,v 1.1 2003/04/30 12:37:31 schnetter Exp $"; CCTK_FILEVERSION(Carpet_CarpetInterp_interp_cc); } @@ -39,84 +31,6 @@ namespace CarpetInterp { typedef vect ivect; typedef vect rvect; - typedef bbox ibbox; - - - -#define ind_rc(m,rl,c) ind_rc_(m,rl,minrl,maxrl,c,maxncomps,vhh) - static inline int ind_rc_(int const m, - int const rl, int const minrl, int const maxrl, - int const c, int const maxncomps, - vector *> const hh) - { - assert (m>=0 && m=minrl && rl=0 && maxrl<=hh.at(m)->reflevels()); - assert (c>=0 && c=0 && maxncomps<=hh.at(m)->components(rl)); - int const ind = (rl-minrl) * maxncomps + c; - assert (ind>=0 && ind < (maxrl-minrl) * maxncomps); - return ind; - } - -#define ind_prc(p,m,rl,c) \ - ind_prc_(p,nprocs,m,rl,minrl,maxrl,c,maxncomps,cgh,vhh) - static inline int ind_prc_(int const p, int const nprocs, - int const m, - int const rl, int const minrl, int const maxrl, - int const c, int const maxncomps, - cGH const * const cgh, - vector *> const hh) - { - assert (p>=0 && p=0 && m=minrl && rl=0 && maxrl<=hh.at(m)->reflevels()); - assert (c>=0 && c=0 && maxncomps<=hh.at(m)->components(rl)); - int const ind = (p * (maxrl-minrl) + (rl-minrl)) * maxncomps + c; - assert (ind>=0 && ind < nprocs * (maxrl-minrl) * maxncomps); - return ind; - } - - - static int GetInterpNumTimelevels(const cGH * const cgh, - const int group) - { - assert (group>=0 && group= 0) { - // all is well - just check they're not asking too much - if (interp_ntl > CCTK_ActiveTimeLevelsGI(cgh, group)) { - char * const groupname = CCTK_GroupName (group); - CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, - "The tags table entry \"InterpNumTimelevels\" " - "for group \"%s\" says that %d timelevels should " - "be used for time interpolation.\n However, only %d " - "are active.", - groupname, interp_ntl, - CCTK_ActiveTimeLevelsGI(cgh, group)); - } - } else { - assert(0); - } - - return interp_ntl; - - } void CarpetInterpStartup () @@ -126,7 +40,7 @@ namespace CarpetInterp { - int InterpGridArrays (cGH const * const cgh, + int InterpGridArrays (cGH const * const cGH, int const N_dims, int const local_interp_handle, int const param_table_handle, @@ -140,556 +54,77 @@ namespace CarpetInterp { CCTK_INT const output_array_type_codes [], void * const output_arrays []) { - if (CCTK_IsFunctionAliased ("SymmetryInterpolate")) { - return SymmetryInterpolate - (cgh, N_dims, - local_interp_handle, param_table_handle, coord_system_handle, - N_interp_points, interp_coords_type_code, interp_coords, - N_input_arrays, input_array_variable_indices, - N_output_arrays, output_array_type_codes, output_arrays); - } else { - return Carpet_DriverInterpolate - (cgh, N_dims, - local_interp_handle, param_table_handle, coord_system_handle, - N_interp_points, interp_coords_type_code, interp_coords, - N_input_arrays, input_array_variable_indices, - N_output_arrays, output_array_type_codes, output_arrays); - } - } - - - - extern "C" CCTK_INT - Carpet_DriverInterpolate (CCTK_POINTER_TO_CONST const cgh_, - CCTK_INT const N_dims, - CCTK_INT const local_interp_handle, - CCTK_INT const param_table_handle, - CCTK_INT const coord_system_handle, - CCTK_INT const N_interp_points, - CCTK_INT const interp_coords_type_code, - CCTK_POINTER_TO_CONST const interp_coords [], - CCTK_INT const N_input_arrays, - CCTK_INT const input_array_variable_indices [], - CCTK_INT const N_output_arrays, - CCTK_INT const output_array_type_codes [], - CCTK_POINTER const output_arrays []) - { - cGH const * const cgh = static_cast (cgh_); int ierr; - assert (cgh); + assert (cGH); assert (N_dims == dim); - - - if (is_meta_mode()) { - CCTK_WARN (0, "It is not possible to interpolate in meta mode"); - } - - bool const want_global_mode = is_global_mode(); - - - - // Get some information - MPI_Comm const comm = CarpetMPIComm (); - int const myproc = CCTK_MyProc (cgh); - int const nprocs = CCTK_nProcs (cgh); - assert (myproc>=0 && myprocreflevels() : reflevel+1; - - // Multiple convergence levels are not supported - assert (mglevels == 1); - int const ml = 0; - - int maxncomps = 0; - for (int rl=minrl; rlcomponents(rl)); - } - - - - // Find the time interpolation order - int partype; - void const * const parptr - = CCTK_ParameterGet ("prolongation_order_time", "Carpet", &partype); - assert (parptr); - assert (partype == PARAMETER_INTEGER); - int const prolongation_order_time = * (CCTK_INT const *) parptr; - - CCTK_REAL const current_time = cgh->cctk_time / cgh->cctk_delta_time; - - - - // Find out about the coordinates: origin and delta for the Carpet - // grid indices -#if 0 const char * coord_system_name = CCTK_CoordSystemName (coord_system_handle); assert (coord_system_name); - rvect lower, upper, delta; + rvect lower, upper; for (int d=0; dbaseextent; - delta[d] - = (upper[d] - lower[d]) / (baseext.upper()[d] - baseext.lower()[d]); - } -#else - rvect const lower = rvect::ref(cgh->cctk_origin_space); - rvect const delta = rvect::ref(cgh->cctk_delta_space) / maxreflevelfact; - rvect const upper = lower + delta * (vhh.at(m)->baseextent.upper() - vhh.at(m)->baseextent.lower()); -#endif - - assert (N_interp_points >= 0); - assert (interp_coords); - for (int d=0; d= 0); - if (N_interp_points > 0) { - assert (output_arrays); - for (int j=0; jcctk_lbnd); + const ivect lsh (cGH->cctk_lsh ); + const ivect gsh (cGH->cctk_gsh ); - // Assign interpolation points to components - vector rlev (N_interp_points); // refinement level of point n - vector home (N_interp_points); // component of point n - vector homecnts ((maxrl-minrl) * maxncomps); // number of points in component c - - for (int n=0; n(interp_coords[d])[n]; - } - - // Find the component that this grid point belongs to - rlev.at(n) = -1; - home.at(n) = -1; - if (all(pos>=lower && pos<=upper)) { - for (int rl=maxrl-1; rl>=minrl; --rl) { - - const int fact = maxreflevelfact / ipow(reffact, rl) * ipow(mgfact, mglevel); - ivect const ipos = ivect(floor((pos - lower) / (delta * fact) + 0.5)) * fact; - assert (all(ipos % vhh.at(m)->bases.at(rl).at(ml).stride() == 0)); - - // TODO: use something faster than a linear search - for (int c=0; ccomponents(rl); ++c) { - if (vhh.at(m)->extents.at(rl).at(c).at(ml).contains(ipos)) { - rlev.at(n) = rl; - home.at(n) = c; - goto found; - } - } - } - } - CCTK_VWarn (3, __LINE__, __FILE__, CCTK_THORNSTRING, - "Interpolation point #%d at [%g,%g,%g] is not on any grid patch", - n, pos[0], pos[1], pos[2]); - // Map the point (arbitrarily) to the first component of the - // coarsest grid - rlev.at(n) = minrl; - home.at(n) = 0; - found: - assert (rlev.at(n)>=minrl && rlev.at(n)=0 && home.at(n)components(rlev.at(n))); - ++ homecnts.at(ind_rc(m, rlev.at(n), home.at(n))); - - } // for n - - // Communicate counts - vector allhomecnts(nprocs * (maxrl-minrl) * maxncomps); - MPI_Allgather - (&homecnts .at(0), (maxrl-minrl) * maxncomps, MPI_INT, - &allhomecnts.at(0), (maxrl-minrl) * maxncomps, MPI_INT, comm); - - - - // Create coordinate patches - vector > allcoords - (nprocs * (maxrl-minrl) * maxncomps); - for (int p=0; pcomponents(rl); ++c) { - ivect lo (0); - ivect up (1); - up[0] = allhomecnts.at(ind_prc(p,m,rl,c)); - up[1] = dim; - ivect str (1); - ibbox extent (lo, up-str, str); - allcoords.at(ind_prc(p,m,rl,c)).allocate (extent, p); - } - } - } - - // Fill in local coordinate patches - { - vector tmpcnts ((maxrl-minrl) * maxncomps); - for (int n=0; n=minrl && rl=0 && ccomponents(rl)); - assert (tmpcnts.at(ind_rc(m,rl,c)) >= 0); - assert (tmpcnts.at(ind_rc(m,rl,c)) < homecnts.at(ind_rc(m,rl,c))); - assert (dim==3); - for (int d=0; d(interp_coords[d])[n]; - } - ++ tmpcnts.at(c + (rl-minrl)*maxncomps); - } - for (int rl=minrl; rlcomponents(rl); ++c) { - assert (tmpcnts.at(ind_rc(m,rl,c)) == homecnts.at(ind_rc(m,rl,c))); - } - } - } - - // Transfer coordinate patches - for (comm_state state; !state.done(); state.step()) { - for (int p=0; pcomponents(rl); ++c) { - allcoords.at(ind_prc(p,m,rl,c)).change_processor - (state, vhh.at(m)->processors.at(rl).at(c)); - } - } - } - } - - - - // Create output patches - vector > alloutputs - (nprocs * (maxrl-minrl) * maxncomps, -1); - for (int p=0; pcomponents(rl); ++c) { - ivect lo (0); - ivect up (1); - up[0] = allhomecnts.at(ind_prc(p,m,rl,c)); - up[1] = N_output_arrays; - ivect str (1); - ibbox extent (lo, up-str, str); - alloutputs.at(ind_prc(p,m,rl,c)).allocate - (extent, vhh.at(m)->processors.at(rl).at(c)); - } - } - } + const rvect coord_delta + = (upper - lower) / rvect((gsh - 1) * reflevelfact); + const rvect coord_origin = lower + rvect(lbnd) * coord_delta; - - - // - // Do the local interpolation - // - int overall_ierr = 0; - BEGIN_GLOBAL_MODE(cgh) { - for (int rl=minrl; rl(cgh), rl); + vector input_array_type_codes(N_input_arrays); + vector input_arrays(N_input_arrays); + for (int n=0; ncctk_time / cgh->cctk_delta_time; - bool const need_time_interp - = (fabs(current_time - level_time) - > 1e-12 * (fabs(level_time) + fabs(current_time) - + fabs(cgh->cctk_delta_time))); - assert (! (! want_global_mode && need_time_interp)); - int const num_tl = need_time_interp ? prolongation_order_time + 1 : 1; + // Ignore this entry + input_array_type_codes[n] = -1; + input_arrays[n] = 0; + + } else { + + int const vi = input_array_variable_indices[n]; + assert (vi>=0 && vi=0 && gicctk_lsh[d]; - coord_delta[d] = cgh->cctk_delta_space[d] / cgh->cctk_levfac[d]; - coord_origin[d] = cgh->cctk_origin_space[d] + (cgh->cctk_lbnd[d] + 1.0 * cgh->cctk_levoff[d] / cgh->cctk_levoffdenom[d]) * coord_delta[d]; - } - - - - // Find out about the grid functions - vector input_array_type_codes(N_input_arrays); - vector input_arrays(N_input_arrays); - for (int n=0; n=0 && vi=0 && gi group.numtimelevels)&& - (interp_ntls > group.numtimelevels)) { - CCTK_VWarn(0, __LINE__,__FILE__,"CarpetInterp", - "Tried to interpolate variable '%s' " - "in time.\nIt has insufficient timelevels " - "(%d are required).", - CCTK_FullName(vi), - min(num_tl,interp_ntls)); - } - assert (group.numtimelevels >= min(num_tl,interp_ntls)); - - input_array_type_codes.at(n) = group.vartype; - - } - } // for input arrays - - - - // Work on the data from all processors - for (int p=0; p tmp_interp_coords (dim); - for (int d=0; d > tmp_output_arrays (num_tl); - - for (int tl=0; tl=0 && vi=0 && gi interp_ntls-1) { - // Do the interpolation anyway, just from - // an earlier timelevel. - int const vi = input_array_variable_indices[n]; - assert (vi>=0 && vi=0 && vi operand_indices (N_output_arrays); - ierr = Util_TableGetIntArray - (param_table_handle, N_output_arrays, - &operand_indices.front(), "operand_indices"); - if (ierr == UTIL_ERROR_TABLE_NO_SUCH_KEY) { - assert (N_output_arrays == N_input_arrays); - for (int m=0; m=0 && vi=0 && gi times(interp_ntls); - for (int tl=0; tltime (-tl, reflevel, mglevel); - } - - // Calculate interpolation weights - vector tfacs(interp_ntls); - switch (interp_ntls) { - case 1: - // no interpolation - // We have to assume that any GF with one timelevel - // is constant in time!!! - // assert (fabs((time - times.at(0)) / fabs(time + times.at(0) + cgh->cctk_delta_time)) < 1e-12); - tfacs.at(0) = 1.0; - break; - case 2: - // linear (2-point) interpolation - tfacs.at(0) = (time - times.at(1)) / (times.at(0) - times.at(1)); - tfacs.at(1) = (time - times.at(0)) / (times.at(1) - times.at(0)); - break; - case 3: - // quadratic (3-point) interpolation - tfacs.at(0) = (time - times.at(1)) * (time - times.at(2)) / ((times.at(0) - times.at(1)) * (times.at(0) - times.at(2))); - tfacs.at(1) = (time - times.at(0)) * (time - times.at(2)) / ((times.at(1) - times.at(0)) * (times.at(1) - times.at(2))); - tfacs.at(2) = (time - times.at(0)) * (time - times.at(1)) / ((times.at(2) - times.at(0)) * (times.at(2) - times.at(1))); - break; - default: - assert (0); - } - - // Interpolate - assert (output_array_type_codes[j] == CCTK_VARIABLE_REAL); - for (int k=0; k(cgh)); - } // for rl - - } END_GLOBAL_MODE; - - - - // Transfer output patches back - for (comm_state state; !state.done(); state.step()) { - for (int p=0; pcomponents(rl); ++c) { - alloutputs.at(ind_prc(p,m,rl,c)).change_processor (state, p); - } - } - } - } - - - - // Read out local output patches - { - vector tmpcnts ((maxrl-minrl) * maxncomps); - for (int n=0; n(output_arrays[j])[n] = alloutputs.at(ind_prc(myproc,m,rl,c))[ivect(tmpcnts.at(ind_rc(m,rl,c)),j,0)]; - } - ++ tmpcnts.at(ind_rc(m,rl,c)); - } - for (int rl=minrl; rlcomponents(rl); ++c) { - assert (tmpcnts.at(ind_rc(m,rl,c)) == homecnts.at(ind_rc(m,rl,c))); - } } } - - - int global_overall_ierr; - MPI_Allreduce - (&overall_ierr, &global_overall_ierr, 1, MPI_INT, MPI_MIN, comm); - - - - // Done. - return global_overall_ierr; + ierr = CCTK_InterpLocalUniform (N_dims, + local_interp_handle, + param_table_handle, + &coord_origin[0], + &coord_delta[0], + N_interp_points, + interp_coords_type_code, + interp_coords, + N_input_arrays, + &lsh[0], + &input_array_type_codes[0], + &input_arrays[0], + N_output_arrays, + output_array_type_codes, + output_arrays); + + return ierr; } } // namespace CarpetInterp diff --git a/Carpet/CarpetInterp/src/interp.h b/Carpet/CarpetInterp/src/interp.h index 4600c6922..8b349b0da 100644 --- a/Carpet/CarpetInterp/src/interp.h +++ b/Carpet/CarpetInterp/src/interp.h @@ -1,4 +1,4 @@ -/* $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetInterp/src/interp.h,v 1.2 2003/11/05 16:18:38 schnetter Exp $ */ +/* $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetInterp/src/interp.h,v 1.1 2003/04/30 12:37:31 schnetter Exp $ */ #ifndef CARPETINTERP_H #define CARPETINTERP_H diff --git a/Carpet/CarpetInterp/src/interp.hh b/Carpet/CarpetInterp/src/interp.hh index db0d1360a..ff81643f6 100644 --- a/Carpet/CarpetInterp/src/interp.hh +++ b/Carpet/CarpetInterp/src/interp.hh @@ -1,4 +1,4 @@ -// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetInterp/src/interp.hh,v 1.2 2004/05/21 18:12:23 schnetter Exp $ +// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetInterp/src/interp.hh,v 1.1 2003/04/30 12:37:31 schnetter Exp $ #ifndef CARPETINTERP_HH #define CARPETINTERP_HH @@ -9,20 +9,19 @@ namespace CarpetInterp { - int - InterpGridArrays (cGH const * const cGH, - int const N_dims, - int const local_interp_handle, - int const param_table_handle, - int const coord_system_handle, - int const N_interp_points, - int const interp_coords_type_code, - void const * const interp_coords [], - int const N_input_arrays, - CCTK_INT const input_array_variable_indices [], - int const N_output_arrays, - CCTK_INT const output_array_type_codes [], - void * const output_arrays []); + int InterpGridArrays (cGH const * const cGH, + int const N_dims, + int const local_interp_handle, + int const param_table_handle, + int const coord_system_handle, + int const N_interp_points, + int const interp_coords_type_code, + void const * const interp_coords [], + int const N_input_arrays, + CCTK_INT const input_array_variable_indices [], + int const N_output_arrays, + CCTK_INT const output_array_type_codes [], + void * const output_arrays []); } // namespace CarpetInterp diff --git a/Carpet/CarpetInterp/src/make.code.defn b/Carpet/CarpetInterp/src/make.code.defn index d5f82ae59..8511e0de3 100644 --- a/Carpet/CarpetInterp/src/make.code.defn +++ b/Carpet/CarpetInterp/src/make.code.defn @@ -1,8 +1,8 @@ # Main make.code.defn file for thorn CarpetInterp -# $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetInterp/src/make.code.defn,v 1.1 2003/04/29 14:02:25 schnetter Exp $ +# $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetInterp/src/make.code.defn,v 1.2 2003/04/30 12:37:31 schnetter Exp $ # Source files in this directory -SRCS = +SRCS = interp.cc # Subdirectories containing source files SUBDIRS = -- cgit v1.2.3