From a5cf2767718d34a459886d0b134b04c119b77fed Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Sat, 31 Mar 2018 12:06:59 +0200 Subject: [PATCH] Add Distance filter --- sample/CMakeLists.txt | 5 +- sample/simpleDistanceFilter.cpp | 86 +++++++++++++++++++++++++++++++++ src/loadRamses.cpp | 2 +- 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 sample/simpleDistanceFilter.cpp diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index 900b59f..02b7a12 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -89,7 +89,10 @@ if (Boost_FOUND) add_executable(simple3DFilter simple3DFilter.cpp) target_link_libraries(simple3DFilter ${tolink}) - install(TARGETS simple3DFilter + add_executable(simpleDistanceFilter simpleDistanceFilter.cpp) + target_link_libraries(simpleDistanceFilter ${tolink}) + + install(TARGETS simple3DFilter simpleDistanceFilter RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) diff --git a/sample/simpleDistanceFilter.cpp b/sample/simpleDistanceFilter.cpp new file mode 100644 index 0000000..44db8b4 --- /dev/null +++ b/sample/simpleDistanceFilter.cpp @@ -0,0 +1,86 @@ +#include "openmp.hpp" +#include "omptl/algorithm" +#include +#include "yorick.hpp" +#include "sphSmooth.hpp" +#include "mykdtree.hpp" +#include "miniargs.hpp" +#include +#include "hdf5_array.hpp" +#include +#include +#include + +using namespace std; +using namespace CosmoTool; + +struct VCoord{ +}; + +using boost::format; +using boost::str; +typedef boost::multi_array array_type_2d; +typedef boost::multi_array array_type_1d; + +typedef KDTree<3,float> MyTree; +typedef MyTree::Cell MyCell; + +int main(int argc, char **argv) +{ + + char *fname1, *fname2; + + MiniArgDesc args[] = { + { "INPUT DATA1", &fname1, MINIARG_STRING }, + { 0, 0, MINIARG_NULL } + }; + + if (!parseMiniArgs(argc, argv, args)) + return 1; + + H5::H5File in_f(fname1, 0); + H5::H5File out_f("distances.h5", H5F_ACC_TRUNC); + array_type_2d v1_data; + array_type_1d dist_data; + uint32_t N1_points; + + hdf5_read_array(in_f, "particles", v1_data); + assert(v1_data.shape()[1] == 7); + + N1_points = v1_data.shape()[0]; + + cout << "Got " << N1_points << " in the first file." << endl; + + MyCell *allCells_1 = new MyCell[N1_points]; + + cout << "Shuffling data in cells..." << endl; +#pragma omp parallel for schedule(static) + for (int i = 0 ; i < N1_points; i++) + { + for (int j = 0; j < 3; j++) + allCells_1[i].coord[j] = v1_data[i][j]; + allCells_1[i].active = true; + } + dist_data.resize(boost::extents[N1_points]); + + cout << "Building trees..." << endl; + MyTree tree1(allCells_1, N1_points); +#pragma omp parallel + { + MyCell **foundCells = new MyCell *[2]; + + #pragma omp for + for (size_t i = 0; i < N1_points; i++) { + double dists[2]; + + tree1.getNearestNeighbours(allCells_1[i].coord, 2, foundCells, dists); + dist_data[i] = dists[1]; + } + + delete[] foundCells; + } + + hdf5_write_array(out_f, "distances", dist_data); + + return 0; +}; diff --git a/src/loadRamses.cpp b/src/loadRamses.cpp index 3e841d5..0c628f8 100644 --- a/src/loadRamses.cpp +++ b/src/loadRamses.cpp @@ -34,7 +34,7 @@ knowledge of the CeCILL license and that you accept its terms. +*/ #include -#include +#include "/usr/include/regex.h" #include #include #include