{ "thorn_name": "CactusNumerical/LocalInterp2", "url": "https://bitbucket.org/cactuscode/cactusnumerical.git", "configuration": "", "interface": "# Interface definition for thorn LocalInterp2\n# $Header$\n\nimplements: LocalInterp\n\nINCLUDE HEADER: LagrangeInterp.hh IN LagrangeInterp.hh\n\n# this thorn doesn't define or use any Cactus grid variables\n", "param": "# Parameter definitions for thorn LocalInterp2\n# $Header$\n\n# there are no parameters for this thorn\n", "schedule": "# Schedule definitions for thorn LocalInterp2\n# $Header$\n\nSchedule LocalInterp2_Startup at STARTUP after Driver_Startup\n{\nLANG:C\n} \"register LocalInterp2's interpolation operators\"\n", "src": { "make.code.defn": "# Main make.code.defn file for thorn LocalInterp\n# $Header$\n\n# Source files in this directory\nSRCS = Startup.c Operator.c Interpolate.cc\n", "Operator.c": "/*@@\n @file Operator.c\n @date Tue Apr 15 18:22:45 1997\n @author Paul Walker\n @desc\n Definition of interpolation operators for regular uniform grids.\n @enddesc\n\n @history\n @date Sun Jul 04 1999\n @author Thomas Radke\n @hdesc conversion to Cactus 4.0 (copied from pughGetPoints.c)\n @date Wed 31 Jan 2001\n @author Thomas Radke\n @hdesc translation of fortran interpolators into C\n @date 22 Jan 2002\n @author Jonathan Thornburg\n @hdesc Move all local-interpolation code from LocalInterp to here\n @endhistory\n\n @version $Id$\n @@*/\n\n#include \n#include \n#include \n\n#include \"cctk.h\"\n#include \"cctk_Parameters.h\"\n#include \"util_ErrorCodes.h\"\n#include \"util_Table.h\"\n#include \"Interpolate.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusBase_LocalInterp2_Operator_c)\n\n\n/********************************************************************\n ******************** External Routines ************************\n ********************************************************************/\nint LocalInterp2_InterpLocalUniform (int num_dims,\n int table,\n /***** coordinate system *****/\n const CCTK_REAL coord_origin[],\n const CCTK_REAL coord_delta[],\n /***** interpolation points *****/\n int num_interp_points,\n int interp_coords_type_code,\n const void *const interp_coords[],\n /***** input arrays *****/\n int num_input_arrays,\n const CCTK_INT input_array_dims[],\n const CCTK_INT input_array_type_codes[],\n const void *const input_arrays[],\n /***** output arrays *****/\n int num_output_arrays,\n const CCTK_INT output_array_type_codes[],\n void *const output_arrays[])\n{\n int iterator, retval;\n char key[128];\n CCTK_INT order, type, nelems;\n\n\n /* check for invalid arguments */\n if (num_dims < 0 || num_interp_points < 0 ||\n num_input_arrays < 0 || num_output_arrays < 0)\n {\n return (UTIL_ERROR_BAD_INPUT);\n }\n\n /* this interpolation operator computes one output array per input array */\n if (num_input_arrays != num_output_arrays)\n {\n CCTK_WARN (1, \"Number of input arrays must match number of output arrays\");\n return (UTIL_ERROR_BAD_INPUT);\n }\n\n if (interp_coords_type_code != CCTK_VARIABLE_REAL)\n {\n CCTK_WARN (1, \"Interpolation coordinates must be of type CCTK_REAL\");\n return (UTIL_ERROR_BAD_INPUT);\n }\n\n /* check if there's anything to do at all */\n if (num_dims == 0 || num_input_arrays == 0)\n {\n return (0);\n }\n\n\n /* get the interpolation order from the user-supplied parameter table */\n order = 1;\n if (table >= 0)\n {\n /* loop through all table options */\n for (iterator = Util_TableItCreate (table);\n Util_TableItQueryIsNonNull (iterator) > 0 &&\n Util_TableItQueryKeyValueInfo (iterator, sizeof (key), key, &type,\n &nelems) > 0;\n Util_TableItAdvance (iterator))\n {\n if (CCTK_Equals (key, \"order\"))\n {\n if (type == CCTK_VARIABLE_INT && nelems == 1)\n {\n Util_TableGetInt (table, &order, \"order\");\n }\n else\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid value for option 'order' in interpolation \"\n \"parameter options table \"\n \"(must be CCTK_INT scalar value)\");\n }\n }\n else if (CCTK_Equals (key, \"N_boundary_points_to_omit\") ||\n CCTK_Equals (key, \"boundary_off_centering_tolerance\") ||\n CCTK_Equals (key, \"boundary_extrapolation_tolerance\") ||\n CCTK_Equals (key, \"per_point_status\") ||\n CCTK_Equals (key, \"local_interpolator_status\"))\n {\n /* warn about unsupported options */\n CCTK_VWarn (4, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Option with key '%s' in interpolation parameter options \"\n \"table is not not supported (will be ignored)\", key);\n }\n else if (CCTK_Equals (key, \"input_array_time_levels\"))\n {\n /* silently ignore options which are meant for the global\n interpolator only */\n }\n else\n {\n /* warn about other options */\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Found option with unrecognized key '%s' in interpolation \"\n \"parameter options table (will be ignored)\", key);\n }\n }\n Util_TableItDestroy (iterator);\n }\n\n /* call the interpolator function */\n retval = LocalInterp2_Interpolate (order, num_interp_points, num_dims,\n num_output_arrays, input_array_dims,\n (const CCTK_REAL *const *) interp_coords,\n coord_origin, coord_delta,\n input_array_type_codes, input_arrays,\n output_array_type_codes, output_arrays);\n\n return (retval);\n}\n", "LagrangeInterp.hh": "#ifndef LOCALINTERP_LAGRANGEINTERP_HH\n#define LOCALINTERP_LAGRANGEINTERP_HH\n\n#include \n#include \n#include \n\n#include \"cctk.h\"\n\n// If this is uncommented always use symmetric operators\n#ifndef LOCALINTERP_SYMMETRIC\n#define LOCALINTERP_SYMMETRIC\n#endif\n\ntemplate\nclass LagrangeInterp1D {\n public:\n LagrangeInterp1D(\n //! [in] Grid origin\n CCTK_REAL const origin,\n //! [in] Grid spacing\n CCTK_REAL const delta,\n //! [in] Number of grid points\n CCTK_INT siz,\n //! [in] Interpolation point\n CCTK_REAL const coord):\n m_origin(origin),\n m_delta(delta),\n m_delta_inv(1.0/m_delta),\n m_siz(siz),\n m_coord(coord),\n m_mid_flag(false),\n m_npoint(order + 1),\n m_out_of_bounds(false),\n point(m_point),\n npoint(m_npoint),\n out_of_bounds(m_out_of_bounds) {\n // Check if we are in the middle between two grid points\n#ifdef LOCALINTERP_SYMMETRIC\n if(0 == order % 2) {\n int idx = std::lrint(std::floor((m_coord - m_origin)*m_delta_inv));\n if(m_coord - (idx*m_delta + m_origin) == 0.5 * m_delta) {\n m_mid_flag = true;\n ++m_npoint;\n }\n else {\n m_mid_flag = false;\n }\n }\n#endif\n // First point (from the left) of the interpolation stencil\n m_point = std::lrint(std::floor((m_coord - m_origin)*m_delta_inv\n - 0.5*(order - 1)));\n#ifdef LOCALINTERP_SYMMETRIC\n if(m_mid_flag) {\n m_point -= 1;\n }\n#endif\n\n // Shift the interpolation stencil if out of the grid\n CCTK_INT shift = m_point;\n if(shift < 0) {\n m_point -= shift;\n m_out_of_bounds = true;\n }\n shift = m_point + order - (m_siz - 1) + m_mid_flag;\n if(shift > 0) {\n m_point -= shift;\n m_out_of_bounds = true;\n }\n\n CCTK_REAL xp[order+2];\n for(int i = 0; i <= order; ++i) {\n xp[i] = (m_point + i) * m_delta + m_origin;\n }\n#ifdef LOCALINTERP_SYMMETRIC\n if(0 == order % 2 && m_mid_flag) {\n xp[order+1] = (m_point + order + 1) * m_delta + m_origin;\n }\n#endif\n m_calc_coeff_lr(xp, &m_coeff_lr[0]);\n#ifdef LOCALINTERP_SYMMETRIC\n if(0 == order % 2 && m_mid_flag) {\n m_calc_coeff_rl(&xp[1], &m_coeff_rl[0]);\n }\n else {\n std::memcpy(m_coeff_rl, m_coeff_lr, sizeof(m_coeff_lr));\n }\n#endif\n }\n\n //! Evaluates the interpolator\n template\n T eval(\n //! [in] must be offset so that vals[0] = vals[\"point\"]\n T const * const vals,\n //! [in] stride used to access vals\n CCTK_INT const stride\n ) const {\n T out_lr = 0;\n for(int i = 0; i <= order; ++i) {\n out_lr += static_cast(m_coeff_lr[i]) * vals[i*stride];\n }\n#ifdef LOCALINTERP_SYMMETRIC\n T out_rl = 0;\n int shift = static_cast(0 == order % 2 && m_mid_flag);\n for(int i = order; i >= 0; --i) {\n out_rl += static_cast(m_coeff_rl[i]) * vals[(i + shift)*stride];\n }\n return T(0.5)*(out_lr + out_rl);\n#else\n return out_lr;\n#endif\n }\n private:\n // Compute the Lagrange interpolation coefficients on a given stencil\n void m_calc_coeff_lr(\n CCTK_REAL const * const xp,\n CCTK_REAL * const coeff\n ) const {\n#define TYPECASE(I0, TEST, I1, OP) \\\n for(int j = 0; j <= order; ++j) { \\\n CCTK_REAL num = 1.0; \\\n CCTK_REAL den = 1.0; \\\n for(int i = I0; i TEST I1; OP i) { \\\n if(i == j) { \\\n continue; \\\n } \\\n num = num * (m_coord - xp[i]); \\\n den = den * (xp[j] - xp[i]); \\\n } \\\n coeff[j] = num/den; \\\n }\n TYPECASE(0, <=, order, ++)\n }\n void m_calc_coeff_rl(\n CCTK_REAL const * const xp,\n CCTK_REAL * const coeff\n ) const {\n TYPECASE(order, >=, 0, --)\n#undef TYPECASE\n }\n private:\n CCTK_REAL m_origin;\n CCTK_REAL m_delta;\n CCTK_REAL m_delta_inv;\n CCTK_INT m_siz;\n\n CCTK_REAL m_coord;\n\n // If true we have an asymmetric stencil, but the interpolation point is\n // exactly in the middle between two grid points. In this case we need to\n // average the results obtained from the interpolation on two separate\n // stencils.\n bool m_mid_flag;\n // First point (going from left to right) of the stencil\n CCTK_INT m_point;\n // Number of points needed for the interpolation\n int m_npoint;\n // The stencil was shifted to avoid going out of bounds\n bool m_out_of_bounds;\n\n // Interpolation coefficients for interpolation from left to right\n CCTK_REAL m_coeff_lr[order+1];\n#ifdef LOCALINTERP_SYMMETRIC\n // Interpolation coefficients for interpolation from right to left\n CCTK_REAL m_coeff_rl[order+1];\n#endif\n public:\n //! Index of the first point of the interpolation stencil\n CCTK_INT const & point;\n //! Number of points needed for the interpolation\n int const & npoint;\n //! The stencil\n bool const & out_of_bounds;\n};\n\ntemplate\nclass NextStencil {\n public:\n enum { value = D - 1 };\n};\n\ntemplate\nclass NextStencil {\n public:\n enum { value = 0 };\n};\n\ntemplate\nclass LagrangeInterpND {\n public:\n LagrangeInterpND(\n //! [in] Grid origin\n CCTK_REAL const origin[ndim],\n //! [in] Grid spacing\n CCTK_REAL const delta[ndim],\n //! [in] Number of grid points\n CCTK_INT const siz[ndim],\n //! [in] Interpolation point\n CCTK_REAL const coord[ndim]):\n m_out_of_bounds(false),\n out_of_bounds(m_out_of_bounds) {\n for(int d = 0; d < ndim; ++d) {\n m_origin[d] = origin[d];\n m_delta[d] = delta[d];\n m_siz[d] = siz[d];\n m_coord[d] = coord[d];\n mp_interp[d] = new (&m_interp_scratch[d][0])\n LagrangeInterp1D(m_origin[d], m_delta[d],\n m_siz[d], m_coord[d]);\n m_out_of_bounds = m_out_of_bounds || mp_interp[d]->out_of_bounds;\n }\n }\n\n template\n T eval(\n //! [in] Grid function to interpolate\n T const * const gf\n ) const {\n T vals[ndim][order+2];\n int pos[ndim];\n m_fill_stencil(gf, pos, vals);\n return mp_interp[ndim-1]->eval(vals[ndim-1], 1);\n }\n private:\n // Recursively fill the stencil used for the interpolation\n template\n void m_fill_stencil(\n T const * const gf,\n int pos[ndim],\n T vals[ndim][order+2]\n ) const {\n assert(D >= 0 && D < ndim);\n if(D == 0) {\n CCTK_INT gidx = mp_interp[0]->point;\n CCTK_INT stride = 1;\n for(int d = 1; d < ndim; ++d) {\n stride *= m_siz[d-1];\n gidx += stride * (mp_interp[d]->point + pos[d]);\n }\n std::memcpy(&vals[0][0], &gf[gidx], mp_interp[0]->npoint*sizeof(T));\n }\n else {\n for(pos[D] = 0; pos[D] < mp_interp[D]->npoint; ++pos[D]) {\n m_fill_stencil::value>(gf, pos, vals);\n vals[D][pos[D]] = mp_interp[D-1]->eval(vals[D-1], 1);\n }\n }\n }\n private:\n CCTK_REAL m_origin[ndim];\n CCTK_REAL m_delta[ndim];\n CCTK_INT m_siz[ndim];\n\n CCTK_REAL m_coord[ndim];\n bool m_out_of_bounds;\n\n // 1D interpolators (will be placed on the stack)\n LagrangeInterp1D * mp_interp[ndim];\n // Scratch space used for placement new\n char m_interp_scratch[ndim][sizeof(LagrangeInterp1D)];\n public:\n bool const & out_of_bounds;\n};\n\n#endif\n", "Interpolate.h": "/*@@\n @file Interpolate.h\n @date 22 Jan 2002\n @author Jonathan Thornburg\n @desc function prototypes\n @enddesc\n @version $Header$\n @history\n @date 22 Jan 2002\n @author Jonathan Thornburg\n @hdesc created by editing down LocalInterp::pughInterpGH.h\n (originally dated 4 July 1999, by Thomas Radke)\n @endhistory\n @@*/\n\n#ifndef _LOCALINTERP_INTERPOLATE_H_\n#define _LOCALINTERP_INTERPOLATE_H_ 1\n\n#ifdef __cplusplus\nextern \"C\"\n{\n#endif\n\n/* prototypes of interpolation operator to be registered */\nint LocalInterp2_InterpLocalUniform (int num_dims,\n int param_table_handle,\n /***** coordinate system *****/\n const CCTK_REAL coord_origin[],\n const CCTK_REAL coord_delta[],\n /***** interpolation points *****/\n int num_interp_points,\n int interp_coords_type_code,\n const void *const interp_coords[],\n /***** input arrays *****/\n int num_input_arrays,\n const CCTK_INT input_array_dims[],\n const CCTK_INT input_array_type_codes[],\n const void *const input_arrays[],\n /***** output arrays *****/\n int num_output_arrays,\n const CCTK_INT output_array_type_codes[],\n void *const output_arrays[]);\n\n/* prototypes of routines used internally */\nint LocalInterp2_Interpolate (int order,\n int num_points,\n int num_dims,\n int num_arrays,\n const CCTK_INT dims[ /* num_dims */ ],\n const CCTK_REAL *const coords[],\n const CCTK_REAL origin[ /* num_dims */ ],\n const CCTK_REAL delta[ /* num_dims */ ],\n const CCTK_INT in_types[ /* num_arrays */ ],\n const void *const in_arrays[ /* num_arrays */ ],\n const CCTK_INT out_types[ /* num_arrays */ ],\n void *const out_arrays[ /* num_arrays */ ]);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* _LOCALINTERP_INTERPOLATE_H_ */\n", "Startup.c": "/*@@\n @file Startup.c\n @date Sun Jul 04 1999\n @author Thomas Radke\n @desc\n Startup routines for LocalInterp/UniformCartesian\n @enddesc\n\n @history\n @date 22 Jan 2002\n @author Jonathan Thornburg\n @hdesc Move all local-interpolation code from LocalInterp to here\n @endhistory\n\n @version $Header$\n @@*/\n\n#include \"cctk.h\"\n#include \"Interpolate.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusBase_LocalInterp2_Startup_c)\n\n\n/********************************************************************\n *************** External Routine Prototypes *******************\n ********************************************************************/\nint LocalInterp2_Startup(void);\n\n\n/*@@\n @routine LocalInterp2_Startup\n @date Sun Jul 04 1999\n @author Thomas Radke\n @desc\n The startup registration routine for LocalInterp.\n Registers the \"uniform cartesian\" interpolation operator\n with the flesh.\n @enddesc\n @calls CCTK_InterpRegisterOpLocalUniform\n @@*/\nint LocalInterp2_Startup (void)\n{\n CCTK_InterpRegisterOpLocalUniform (LocalInterp2_InterpLocalUniform,\n \"uniform cartesian\", CCTK_THORNSTRING);\n return 0;\n}\n", "README": "This directory contains the interpolation functions registered for\n CCTK_InterpLocal()\nunder the names\n \"first-order uniform cartesian\"\n \"second-order uniform cartesian\"\n \"third-order uniform cartesian\"\nand for\n CCTK_InterpLocalUniform()\nunder the name\n \"uniform cartesian\"\n\n\nImplementation Notes\n====================\nThe interpolation operators registered for different orders are mapped\nvia wrappers (in \"Startup.c\") onto a single routine (in \"Operator.c\"),\njust passing the order as an additional argument.\n\nThe actual core interpolation routine is located in \"Interpolate.cc\".\n", "Interpolate.cc": "#include \"cctk.h\"\n#include \"cctk_Interp.h\"\t\t/* defines error codes */\n#include \"util_ErrorCodes.h\"\t\t/* defines error codes */\n#include \"cctk_Parameters.h\"\n#include \"Interpolate.h\"\n\n#include \"LagrangeInterp.hh\"\n\n/* the highest order of interpolation we support so far */\n#define MAXORDER 3\n/* the highest dimension for variables we can deal with (so far) */\n#define MAXDIM 3\n\n/* we return this if we are successful */\n#define RETURN_SUCCESS\t0\n\nnamespace {\n\n#define INTERP_ID(order, num_dims) \\\n ((order)*MAXDIM + (num_dims) - 1)\n\ntemplate\nclass interp_t {\n public:\n // interp_id = order * MAXDIM + num_dims\n enum { order = interp_id / MAXDIM };\n enum { num_dims = interp_id % MAXDIM + 1 };\n};\n\ntemplate\nint __do_interpolate(\n int num_points,\n int num_arrays,\n const CCTK_INT dims[],\n const CCTK_REAL *const coord[],\n const CCTK_REAL origin[],\n const CCTK_REAL delta[],\n const CCTK_INT in_types[],\n const void *const in_arrays[],\n const CCTK_INT out_types[],\n void *const out_arrays[])\n{\n bool error_point_outside = false;\n bool error_bad_input = false;\n#pragma omp parallel for reduction(||: error_point_outside, error_bad_input)\n for(int n = 0; n < num_points; ++n) {\n CCTK_REAL point[num_dims];\n for(int d = 0; d < num_dims; ++d) {\n point[d] = coord[d][n];\n }\n\n LagrangeInterpND interp(origin, delta, dims, point);\n\n if(interp.out_of_bounds) {\n#pragma omp critical\n {\n if (num_dims == 1)\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Interpolation stencil/molecule out of bounds\\n\"\n \" (the interpolation point is either outside the grid, \"\n \"or inside but too close to a grid boundary)\\n\"\n \" for interpolation order %d\\n\"\n \" at interpolation point %d with x = (%f)\\n\"\n \" and grid min/max = (%f/%f)\\n\"\n \"(this may be caused by a global interpolation with\\n\"\n \" driver::ghost_size too small)\\n\"\n ,\n order, n,\n (double) coord[0][n],\n (double) origin[0], (double) (origin[0] + (dims[0]-1)*delta[0]));\n }\n else if (num_dims == 2)\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Interpolation stencil/molecule out of bounds\\n\"\n \" (the interpolation point is either outside the grid, \"\n \"or inside but too close to a grid boundary)\\n\"\n \" for interpolation order %d\\n\"\n \" at interpolation point %d with xy = (%f, %f)\\n\"\n \" and grid min/max = (%f/%f, %f/%f)\\n\"\n \"(this may be caused by a global interpolation with\\n\"\n \" driver::ghost_size too small)\\n\"\n ,\n order, n,\n (double) coord[0][n], (double) coord[1][n],\n (double) origin[0], (double) (origin[0] + (dims[0]-1)*delta[0]),\n (double) origin[1], (double) (origin[1] + (dims[1]-1)*delta[1]));\n }\n else if (num_dims == 3)\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Interpolation stencil/molecule out of bounds\\n\"\n \" (the interpolation point is either outside the grid, \"\n \"or inside but too close to a grid boundary)\\n\"\n \" for interpolation order %d\\n\"\n \" at interpolation point %d with xyz = (%f, %f, %f)\\n\"\n \" and grid min/max = (%f/%f, %f/%f, %f/%f)\\n\"\n \"(this may be caused by a global interpolation with\\n\"\n \" driver::ghost_size too small)\\n\"\n ,\n order, n,\n (double) coord[0][n], (double) coord[1][n], (double) coord[2][n],\n (double) origin[0], (double) (origin[0] + (dims[0]-1)*delta[0]),\n (double) origin[1], (double) (origin[1] + (dims[1]-1)*delta[1]),\n (double) origin[2], (double) (origin[2] + (dims[2]-1)*delta[2]));\n }\n } // end of critical section\n error_point_outside = true;\n continue;\n } // end of if(interp.out_of_bounds)\n\n for(int a = 0; a < num_arrays; ++a) {\n /* check for valid input and output array type */\n if (in_types[a] < 0 || out_types[a] < 0)\n {\n#pragma omp critical\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Datatype for input and/or output array with index %d \"\n \"is invalid\", a);\n error_bad_input = true;\n continue;\n }\n\n /* sorry, for now input and output arrays must be of same type */\n if (in_types[a] != out_types[a])\n {\n#pragma omp critical\n CCTK_WARN (1, \"Type casting of interpolation results not implemented\");\n error_bad_input = true;\n continue;\n }\n\n /* skip this array if it's a query call only */\n if (! out_arrays[a])\n {\n continue;\n }\n\n switch(in_types[a]) {\n#define TYPECASE(CCTK_TYPE_NAME, CCTK_TYPE) \\\n case CCTK_TYPE_NAME: \\\n reinterpret_cast(out_arrays[a])[n] = interp. \\\n LagrangeInterpND::template eval( \\\n reinterpret_cast(in_arrays[a])); \\\n break\n TYPECASE(CCTK_VARIABLE_REAL, CCTK_REAL);\n TYPECASE(CCTK_VARIABLE_COMPLEX, CCTK_COMPLEX);\n#ifdef HAVE_CCTK_REAL4\n TYPECASE(CCTK_VARIABLE_REAL4, CCTK_REAL4);\n TYPECASE(CCTK_VARIABLE_COMPLEX8, CCTK_COMPLEX8);\n#endif\n#ifdef HAVE_CCTK_REAL8\n TYPECASE(CCTK_VARIABLE_REAL8, CCTK_REAL8);\n TYPECASE(CCTK_VARIABLE_COMPLEX16, CCTK_COMPLEX16);\n#endif\n#ifdef HAVE_CCTK_REAL16\n TYPECASE(CCTK_VARIABLE_REAL16, CCTK_REAL16);\n TYPECASE(CCTK_VARIABLE_COMPLEX32, CCTK_COMPLEX32);\n#endif\n#undef TYPECASE\n default:\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Unsupported variable type %d\", (int) in_types[a]);\n }\n }\n } // end of parallel for loop\n if(error_bad_input) {\n return UTIL_ERROR_BAD_INPUT;\n }\n else if(error_point_outside) {\n return CCTK_ERROR_INTERP_POINT_OUTSIDE;\n }\n return RETURN_SUCCESS;\n}\n\nint interpolate(\n int order,\n int num_points,\n int num_dims,\n int num_arrays,\n const CCTK_INT dims[],\n const CCTK_REAL *const coord[],\n const CCTK_REAL origin[],\n const CCTK_REAL delta[],\n const CCTK_INT in_types[],\n const void *const in_arrays[],\n const CCTK_INT out_types[],\n void *const out_arrays[])\n{\n /*\n * verify parameters and check against our restrictions\n */\n if (num_dims < 1)\n {\n CCTK_WARN (1, \"Number of dimensions must be positive\");\n return UTIL_ERROR_BAD_INPUT;\n }\n\n if (num_dims > MAXDIM)\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Interpolation of %d-dimensional arrays not implemented\",\n num_dims);\n return UTIL_ERROR_BAD_INPUT;\n }\n\n if (order < 0)\n {\n CCTK_WARN (1, \"Interpolation order must be non-negative\");\n return UTIL_ERROR_BAD_INPUT;\n }\n\n if (order > MAXORDER)\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Interpolation order %d not implemented\", order);\n return UTIL_ERROR_BAD_INPUT;\n }\n\n /* check that the stencil/molecule isn't bigger than the grid */\n for (int i = 0; i < num_dims; i++)\n {\n if (order+1 > dims[i]) /* stencil/molecule size = order+1 */\n {\n return CCTK_ERROR_INTERP_GRID_TOO_SMALL;\n }\n }\n\n if (num_points < 0)\n {\n CCTK_WARN (1, \"Negative number of points given\");\n return UTIL_ERROR_BAD_INPUT;\n }\n\n\n /* also immediately return if there's nothing to do */\n if (num_points == 0)\n {\n return RETURN_SUCCESS;\n }\n\n int id = INTERP_ID(order, num_dims);\n switch(id)\n {\n#define TYPECASE(ID) \\\n case ID: \\\n return \\\n __do_interpolate::order, interp_t::num_dims>( \\\n num_points, num_arrays, dims, coord, origin, delta, in_types, \\\n in_arrays, out_types, out_arrays); \\\n break\n TYPECASE(0);\n TYPECASE(1);\n TYPECASE(2);\n TYPECASE(3);\n TYPECASE(4);\n TYPECASE(5);\n TYPECASE(6);\n TYPECASE(7);\n TYPECASE(8);\n TYPECASE(9);\n TYPECASE(10);\n TYPECASE(11); // MAXDIM * (MAXORDER + 1) - 1\n#undef TYPECASE\n default:\n CCTK_ERROR(\"This is a bug in Interpolate.cc\");\n }\n\n // If we ever get here, this is a bug in the code\n return -1;\n}\n\n} // anonymous namespace\n\n/*@@\n @routine LocalInterp2_Interpolate\n @date Wed 17 Jan 2001\n @author Thomas Radke\n @desc\n This routine interpolates a set of input arrays\n to a set of output arrays (one-to-one) at arbitrary points\n which are given by their coordinates and the underlying\n regular, uniform grid.\n\n Current limitations of this implementation are:\n - arrays up to three (MAXDIM) dimensions only can be handled\n - interpolation orders up to three (MAXORDER) only are supported\n - coordinates must be given as CCTK_REAL types\n - input and output array types must be the same\n (no type casting of interpolation results supported)\n\n Despite of these limitations, the code was programmed almost\n generically in that it can easily be extended to support\n higher-dimensional arrays or more interpolation orders.\n Places where the code would need to be changed to do this,\n are marked with NOTE-MAXDIM and/or NOTE-MAXORDER comments\n as appropriate.\n @enddesc\n\n @var num_points\n @vdesc number of points to interpolate at\n @vtype int\n @vio in\n @endvar\n @var num_dims\n @vdesc dimensionality of the input arrays\n @vtype int\n @vio in\n @endvar\n @var num_arrays\n @vdesc number of input/output arrays\n @vtype int\n @vio in\n @endvar\n @var dims\n @vdesc dimensions of the input arrays\n @vtype CCTK_INT[ num_dims ]\n @vio in\n @endvar\n @var coord\n @vdesc list of coordinates to interpolate at\n @vtype CCTK_REAL coord[ num_dims ][ num_points ]\n @vio in\n @endvar\n @var origin\n @vdesc origin of the underlying grid\n @vtype CCTK_REAL origin[ num_dims ]\n @vio in\n @endvar\n @var delta\n @vdesc deltas of the underlying grid\n @vtype CCTK_REAL delta[ num_dims ]\n @vio in\n @endvar\n @var in_types\n @vdesc CCTK variable types of input arrays\n @vtype CCTK_INT in_types[ num_arrays ]\n @vio in\n @endvar\n @var in_arrays\n @vdesc list of input arrays\n @vtype void *in_arrays[ num_arrays ]\n @vio in\n @endvar\n @var out_types\n @vdesc CCTK variable types of output arrays\n @vtype CCTK_INT out_types[ num_arrays ]\n @vio in\n @endvar\n @var out_arrays\n @vdesc list of output arrays\n @vtype void *out_arrays[ num_arrays ]\n @vio out\n @endvar\n\n @returntype int\n @returndesc\n 0 - successful interpolation\n negative in case of any errors (eg. the negative total number\n of out-of-bounds interpolation points)\n @endreturndesc\n @@*/\nextern \"C\"\nint LocalInterp2_Interpolate (int order,\n int num_points,\n int num_dims,\n int num_arrays,\n const CCTK_INT dims[],\n const CCTK_REAL *const coord[],\n const CCTK_REAL origin[],\n const CCTK_REAL delta[],\n const CCTK_INT in_types[],\n const void *const in_arrays[],\n const CCTK_INT out_types[],\n void *const out_arrays[]) {\n return interpolate(order, num_points, num_dims, num_arrays, dims, coord,\n origin, delta, in_types, in_arrays, out_types, out_arrays);\n}\n" }, "test": {}, "doc": { "documentation.tex": "% *======================================================================*\n% Cactus Thorn template for ThornGuide documentation\n% Author: Ian Kelley\n% Date: Sun Jun 02, 2002\n% $Header$\n%\n% Thorn documentation in the latex file doc/documentation.tex\n% will be included in ThornGuides built with the Cactus make system.\n% The scripts employed by the make system automatically include\n% pages about variables, parameters and scheduling parsed from the\n% relevent thorn CCL files.\n%\n% This template contains guidelines which help to assure that your\n% documentation will be correctly added to ThornGuides. More\n% information is available in the Cactus UsersGuide.\n%\n% Guidelines:\n% - Do not change anything before the line\n% % BEGIN CACTUS THORNGUIDE\",\n% except for filling in the title, author, date etc. fields.\n% - You can define your own macros are OK, but they must appear after\n% the BEGIN CACTUS THORNGUIDE line, and do not redefine standard\n% latex commands.\n% - To avoid name clashes with other thorns, 'labels', 'citations',\n% 'references', and 'image' names should conform to the following\n% convention:\n% ARRANGEMENT_THORN_LABEL\n% For example, an image wave.eps in the arrangement CactusWave and\n% thorn WaveToyC should be renamed to CactusWave_WaveToyC_wave.eps\n% - Graphics should only be included using the graphix package.\n% More specifically, with the \"includegraphics\" command. Do\n% not specify any graphic file extensions in your .tex file. This\n% will allow us (later) to create a PDF version of the ThornGuide\n% via pdflatex. |\n% - References should be included with the latex \"bibitem\" command.\n% - For the benefit of our Perl scripts, and for future extensions,\n% please use simple latex.\n%\n% *======================================================================*\n%\n% Example of including a graphic image:\n% \\begin{figure}[ht]\n% \t\\begin{center}\n% \t \\includegraphics[width=6cm]{MyArrangement_MyThorn_MyFigure}\n% \t\\end{center}\n% \t\\caption{Illustration of this and that}\n% \t\\label{MyArrangement_MyThorn_MyLabel}\n% \\end{figure}\n%\n% Example of using a label:\n% \\label{MyArrangement_MyThorn_MyLabel}\n%\n% Example of a citation:\n% \\cite{MyArrangement_MyThorn_Author99}\n%\n% Example of including a reference\n% \\bibitem{MyArrangement_MyThorn_Author99}\n% {J. Author, {\\em The Title of the Book, Journal, or periodical}, 1 (1999),\n% 1--16. {\\tt http://www.nowhere.com/}}\n%\n% *======================================================================*\n\n% If you are using CVS use this line to give version information\n% $Header$\n\n\\documentclass{article}\n\n% Use the Cactus ThornGuide style file\n% (Automatically used from Cactus distribution, if you have a\n% thorn without the Cactus Flesh download this from the Cactus\n% homepage at www.cactuscode.org)\n\\usepackage{../../../../doc/latex/cactus}\n\n\\begin{document}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% The author of the documentation\n\\author{Thomas Radke}\n\n% The title of the document (not necessarily the name of the Thorn)\n\\title{Thorn Guide for the {\\bf LocalInterp} Thorn}\n\n% the date your document was last changed, if your document is in CVS,\n% please us:\n% \\date{$ $Date$ $}\n\\date{$ $Date$ $}\n\n\\maketitle\n\n% Do not delete next line\n% START CACTUS THORNGUIDE\n\n% Add all definitions used in this documentation here\n% \\def\\mydef etc\n\n% Add an abstract for this thorn's documentation\n\\begin{abstract}\nThis thorn does processor-local interpolation of N-dimensional data\narrays. In general there may be many input arrays (all defined on the\nsame uniform Cartesian grid) all being interpolated to the same set\nof interpolation points.\n\\end{abstract}\n\n% The following sections are suggestive only.\n% Remove them or add your own.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Introduction}\n\nThis thorn provides processor-local interpolation, using the interpolation\noperator\n\\begin{verbatim}\n \"uniform cartesian\"\n\\end{verbatim}\nfor the Cactus local interpolation API \\verb|CCTK_InterpLocalUniform()|.\n(Note that the word ``{\\tt cartesian}'' is in lower case here!)\nIt supports 1, 2, and 3-dimensional interpolation.\n\nSee the Cactus Reference Manual\nfor a full description of the \\verb|CCTK_InterpLocalUniform()| API,\nand some examples of how to use it.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{History}\n\nThis interpolator was written by Thomas Radke in early 2001 (drawing\non older code by Paul Walker). It originally lived in the PUGHInterp\nthorn, but it turned to have very little to do with PUGH, so was moved\nhere in winter 2001-2002.\n\nFrom winter 2001-2002 to July 2003 this thorn also contained another\ninterpolator written by Jonathan Thornburg, but in July 2003 that\ninterpolator was moved to {\\bf AEIThorns/AEILocalInterp/} because it was\n(is) GPL and Cactus policies are that this arrangement ({\\bf CactusBase})\nis reserved for code under the Cactus-flesh license (= GPL except\nthat it's like LGPL for linking with other thorns).\n\nAt the beginning of 2015 the low-level interpolation kernels of this\nthorn were rewritten in C++ by David Radice.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Implementation}\n\nInternally, this interpolator always does 3-D interpolation, inserting\nzero coordinates as appropriate for lower dimensionalities. The\ninterpolation is done by successive 1-D interpolations along each\naxis.%%%\n\\footnote{%%%\n\t Note that this means that different axes are treated\n\t slightly differently by the interpolator. In other\n\t words, at the level of finite differencing errors,\n\t interpolation does {\\em not\\/} commute with permuting\n\t the axes. However, in practice the differences are\n\t likely to be small, at least for smooth input data.\n\t }%%%\n{} See the \\verb|README| file in the \\verb|src/| directory\nfor further details.\n\n\\subsection{Additional information passed in as table options}\n\nThe \\verb|CCTK_InterpLocalUniform()| API accepts a table handle as one of its\narguments which can be used to pass additional information to the local\ninterpolator via table options.\n\nThe only table option supported so far by {\\bf LocalInterp}'s {\\tt \"uniform\ncartesian\"} operator is the interpolation order which must be\npassed as a CCTK\\_INT value with key {\\tt \"order\"}. Options with keys\n{\\tt \"N\\_boundary\\_points\\_to\\_omit\", \"boundary\\_off\\_centering\\_tolerance\"}, or\n{\\tt \"boundary\\_extrapolation\\_tolerance\"} (which are usually passed by a\nglobal interpolator) are also recognized but silently ignored (a level-4 warning\nmessage will be issued in this case).\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% Do not delete next line\n% END CACTUS THORNGUIDE\n\n\\end{document}\n" } }