From d213198312bce97abc76d50828ae11d1e1049948 Mon Sep 17 00:00:00 2001 From: rhaas Date: Wed, 19 Jun 2013 03:34:21 +0000 Subject: add 0th order interpolation minor extra changes: * correct typo * turn if-else cascade into switch git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/LocalInterp/trunk@221 df1f8a13-aa1d-4dd4-9681-27ded5b42416 --- src/Interpolate.c | 86 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/src/Interpolate.c b/src/Interpolate.c index 56df7d0..06503ba 100644 --- a/src/Interpolate.c +++ b/src/Interpolate.c @@ -305,9 +305,9 @@ int LocalInterp_Interpolate (int order, return UTIL_ERROR_BAD_INPUT; } - if (order < 1) + if (order < 0) { - CCTK_WARN (1, "Inperpolation order must be positive"); + CCTK_WARN (1, "Interpolation order must be non-negative"); return UTIL_ERROR_BAD_INPUT; } @@ -511,44 +511,54 @@ if (n == LocalInterp_verbose_debug_n) * NOTE-MAXORDER: support higher interpolation orders by adding the * appropriate coefficients in another else branch */ - if (order == 1) - { - /* first order (linear) 1D interpolation */ - for (int i = 0; i < num_dims; i++) - { - coeff[i][0] = 1 - offset[i]; - coeff[i][1] = offset[i]; - } - } - else if (order == 2) - { - /* second order (quadratic) 1D interpolation */ - for (int i = 0; i < num_dims; i++) - { - coeff[i][0] = (1-offset[i]) * (2-offset[i]) / ( 2 * 1 ); - coeff[i][1] = ( -offset[i]) * (2-offset[i]) / ( 1 * (-1)); - coeff[i][2] = ( -offset[i]) * (1-offset[i]) / ((-1) * (-2)); - } - } - else if (order == 3) - { - /* third order (cubic) 1D interpolation */ - for (int i = 0; i < num_dims; i++) - { - coeff[i][0] = (1-offset[i]) * (2-offset[i]) * (3-offset[i]) / - ( 3 * 2 * 1 ); - coeff[i][1] = ( -offset[i]) * (2-offset[i]) * (3-offset[i]) / - ( 2 * 1 * (-1)); - coeff[i][2] = ( -offset[i]) * (1-offset[i]) * (3-offset[i]) / - ( 1 * (-1) * (-2)); - coeff[i][3] = ( -offset[i]) * (1-offset[i]) * (2-offset[i]) / - ((-1) * (-2) * (-3)); - } - } - else + switch(order) { + case 0: + /* zeroeth order (copy) 1D interpolation */ + for (int i = 0; i < num_dims; i++) + { + coeff[i][0] = 1; + } + break; + case 1: + /* first order (linear) 1D interpolation */ + for (int i = 0; i < num_dims; i++) + { + coeff[i][0] = 1 - offset[i]; + coeff[i][1] = offset[i]; + } + break; + case 2: + /* second order (quadratic) 1D interpolation */ + for (int i = 0; i < num_dims; i++) + { + coeff[i][0] = (1-offset[i]) * (2-offset[i]) / ( 2 * 1 ); + coeff[i][1] = ( -offset[i]) * (2-offset[i]) / ( 1 * (-1)); + coeff[i][2] = ( -offset[i]) * (1-offset[i]) / ((-1) * (-2)); + } + break; + case 3: + /* third order (cubic) 1D interpolation */ + for (int i = 0; i < num_dims; i++) + { + coeff[i][0] = (1-offset[i]) * (2-offset[i]) * (3-offset[i]) / + ( 3 * 2 * 1 ); + coeff[i][1] = ( -offset[i]) * (2-offset[i]) * (3-offset[i]) / + ( 2 * 1 * (-1)); + coeff[i][2] = ( -offset[i]) * (1-offset[i]) * (3-offset[i]) / + ( 1 * (-1) * (-2)); + coeff[i][3] = ( -offset[i]) * (1-offset[i]) * (2-offset[i]) / + ((-1) * (-2) * (-3)); + } + break; + default: #pragma omp critical - CCTK_WARN (0, "Implementation error"); + { + CCTK_VError (__LINE__,__FILE__,CCTK_THORNSTRING, + "Implementation error. Unexpected interpolation order %d", + order); + } + break; } #ifdef LOCALINTERP_VERBOSE_DEBUG -- cgit v1.2.3