From 19c5e446aa480a213d547e717b86185466f9c417 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Tue, 30 Oct 2012 13:58:46 -0400 Subject: [PATCH] Allow to disable simplices if they are strange --- src/dinterpolate.hpp | 3 +++ src/dinterpolate.tcc | 49 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/dinterpolate.hpp b/src/dinterpolate.hpp index 9ce6281..acbe3f7 100644 --- a/src/dinterpolate.hpp +++ b/src/dinterpolate.hpp @@ -29,6 +29,7 @@ namespace CosmoTool { uint32_t numSimplex; uint32_t *simplex_list; gsl_eigen_symmv_workspace *eigen_work; + bool *disable_simplex; /** * This construct the interpolator. The construction is time consuming so @@ -53,6 +54,7 @@ namespace CosmoTool { this->simplex_list = simplex_list; this->numPoints = numPoints; this->numSimplex = numSimplex; + this->disable_simplex = new bool[numSimplex]; buildPreweight(); buildQuickAccess(); @@ -67,6 +69,7 @@ namespace CosmoTool { delete quickAccess; delete[] point_to_simplex_list_base; delete[] all_preweight; + delete[] disable_simplex; gsl_eigen_symmv_free(eigen_work); } diff --git a/src/dinterpolate.tcc b/src/dinterpolate.tcc index e18a7e6..e0cf763 100644 --- a/src/dinterpolate.tcc +++ b/src/dinterpolate.tcc @@ -1,3 +1,6 @@ +#include +#include +#include #include #include #include @@ -21,7 +24,8 @@ namespace CosmoTool { for (uint32_t i = 0; i < (N+1)*numSimplex; i++) { assert(simplex_list[i] < numPoints); - numSimplex_by_point[simplex_list[i]]++; + if (!disable_simplex[i/(N+1)]) + numSimplex_by_point[simplex_list[i]]++; } // Compute the total number and the index for accessing lists. @@ -37,7 +41,11 @@ namespace CosmoTool { { for (int j = 0; j <= N; j++) { - uint32_t p = simplex_list[(N+1)*i+j]; + uint32_t s = (N+1)*i+j; + if (disable_simplex[i]) + continue; + + uint32_t p = simplex_list[s]; assert(index_by_point[p] < point_to_simplex_size); point_to_simplex_list_base[index_by_point[p]] = i; ++index_by_point[p]; @@ -48,7 +56,9 @@ namespace CosmoTool { for (uint32_t i = 0; i < numPoints; i++) { // check assertion - assert((i==0 && index_by_point[0]==numSimplex_by_point[0]) || ((index_by_point[i]-index_by_point[i-1]) == (numSimplex_by_point[i]+1))); + assert((i==0 && index_by_point[0]==numSimplex_by_point[0]) + || + ((index_by_point[i]-index_by_point[i-1]) == (numSimplex_by_point[i]+1))); assert(index_by_point[i] < point_to_simplex_size); point_to_simplex_list_base[index_by_point[i]] = -1; } @@ -80,6 +90,7 @@ namespace CosmoTool { double preweight[N*N]; double preweight_inverse[N*N]; gsl_permutation *p = gsl_permutation_alloc(N); + uint32_t numDisabled = 0; all_preweight = new PType[N*N*numSimplex]; @@ -105,13 +116,38 @@ namespace CosmoTool { gsl_linalg_LU_decomp(&M.matrix, p, &signum); double a = fabs(gsl_linalg_LU_det(&M.matrix, signum)); if (a < 1e-10) - throw InvalidArgumentException("Invalid tesselation. One simplex is coplanar."); - gsl_linalg_LU_invert(&M.matrix, p, &iM.matrix); + { +#ifdef DEBUG + for (int j = 0; j < N; j++) + { + PType xref = positions[pref][j]; + for (int k = 0; k < N; k++) + { + preweight[j*N + k] = positions[simplex_list[k+base+1]][j] - xref; + } + } + std::ofstream f("matrix.txt"); + for (int j = 0; j < N*N; j++) + f << std::setprecision(12) << preweight[j] << std::endl; + throw InvalidArgumentException("Invalid tesselation. One simplex is coplanar."); +#else + gsl_matrix_set_zero(&iM.matrix); + disable_simplex[i] = true; + numDisabled++; +#endif + } + else { + gsl_linalg_LU_invert(&M.matrix, p, &iM.matrix); + disable_simplex[i] = false; + } + for (int j = 0; j < N*N; j++) all_preweight[N*N*i + j] = preweight_inverse[j]; } + std::cout << "Number of disabled simplices: " << numDisabled << std::endl; + gsl_permutation_free(p); } @@ -166,6 +202,9 @@ namespace CosmoTool { template bool DelaunayInterpolate::checkPointInSimplex(const CoordType& pos, uint32_t simplex) { + if (disable_simplex[simplex]) + return false; + uint32_t *desc_simplex = &simplex_list[simplex*(N+1)]; CoordType *p[N+1], v[N], hyper;