aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrhaas <rhaas@df1f8a13-aa1d-4dd4-9681-27ded5b42416>2013-06-19 03:34:21 +0000
committerrhaas <rhaas@df1f8a13-aa1d-4dd4-9681-27ded5b42416>2013-06-19 03:34:21 +0000
commitd213198312bce97abc76d50828ae11d1e1049948 (patch)
tree2d55fabe168f86af361f1f8adca77b222322108d
parent474719cb822661afa915df69051886edd65f3de5 (diff)
add 0th order interpolationHEADmaster
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
-rw-r--r--src/Interpolate.c86
1 files 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