From 7d39b98db5a37f970831f94d2f9ea608a458c565 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Tue, 2 Mar 2010 10:59:41 -0600 Subject: [PATCH] Fixed test. Compilation fixes --- sample/testkd2.cpp | 33 +++++++++++++++++++++++++++++++-- src/fortran.cpp | 2 +- src/loadRamses.cpp | 6 ++++-- src/yorick.cpp | 1 + src/yorick.hpp | 4 +++- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/sample/testkd2.cpp b/sample/testkd2.cpp index 375f276..0226ba0 100644 --- a/sample/testkd2.cpp +++ b/sample/testkd2.cpp @@ -6,7 +6,7 @@ #define __KD_TREE_NUMNODES #include "mykdtree.hpp" -#define NTRY 3 +#define NTRY 100 #define ND 3 using namespace std; @@ -62,11 +62,12 @@ int main() // Check consistency cout << "Check consistency..." << endl; MyCell **ngb = new MyCell *[12]; + double *distances = new double[12]; ofstream fngb("nearest.txt"); for (int k = 0; k < NTRY; k++) { cout << "Seed = " << xc[k][0] << " " << xc[k][1] << " " << xc[k][2] << endl; - tree.getNearestNeighbours(xc[k], 12, ngb); + tree.getNearestNeighbours(xc[k], 12, ngb, distances); for (uint32_t i = 0; i < 12; i++) { @@ -75,6 +76,34 @@ int main() d2 += ({double delta = xc[k][l] - ngb[i]->coord[l]; delta*delta;}); fngb << ngb[i]->coord[0] << " " << ngb[i]->coord[1] << " " << ngb[i]->coord[2] << " " << sqrt(d2) << endl; } + fngb << endl << endl; + double farther_dist = distances[11]; + for (uint32_t i = 0; i < Ncells; i++) + { + bool found = false; + // If the points is not in the list, it means it is farther than the farther point + for (int j =0; j < 12; j++) + { + if (&cells[i] == ngb[j]) { + found = true; + break; + } + } + double dist_to_seed = 0; + for (int l = 0; l < 3; l++) + { double delta = xc[k][l]-cells[i].coord[l]; + dist_to_seed += delta*delta; } + if (!found) + { + if (dist_to_seed <= farther_dist) + abort(); + } + else + { + if (dist_to_seed > farther_dist) + abort(); + } + } } return 0; diff --git a/src/fortran.cpp b/src/fortran.cpp index 4ca7254..e0f9a75 100644 --- a/src/fortran.cpp +++ b/src/fortran.cpp @@ -224,7 +224,7 @@ void UnformattedWrite::endCheckpoint() if (checkPointAccum == 0) throw InvalidUnformattedAccess(); - ostream::streampos curPos = f->tellp(); + streampos curPos = f->tellp(); int64_t deltaPos = curPos-checkPointRef; diff --git a/src/loadRamses.cpp b/src/loadRamses.cpp index 250bb3d..01cd4c3 100644 --- a/src/loadRamses.cpp +++ b/src/loadRamses.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -436,12 +437,13 @@ CosmoTool::PhaseSpaceData *CosmoTool::loadRamsesPhase(const char *basename, int if (!readInfoFile(basename, outputId, info)) return 0; - double unit_vel = info.unitLength/info.unit_t/1e5; double hubble = info.aexp*info.aexp/info.unit_t / (1e5/CM_IN_MPC); - double L0 = info.boxSize*info.unitLength/CM_IN_MPC/info.aexp; + double L0 = info.boxSize*info.unitLength*hubble/(100*CM_IN_MPC)/info.aexp; + double unit_vel = 100*L0/info.aexp; if (!quiet) { cout << "L0=" << L0 << " Mpc" << endl; cout << "H=" << hubble << " km/s/Mpc" << endl; + cout << "unit_vel=" << unit_vel << " km/s" << endl; } if (!quiet) diff --git a/src/yorick.cpp b/src/yorick.cpp index 3453390..b6ebeed 100644 --- a/src/yorick.cpp +++ b/src/yorick.cpp @@ -212,6 +212,7 @@ namespace CosmoTool { template void loadArray(const char *fname, T*&array, uint32_t *&dimList, uint32_t& rank) + throw (NoSuchFileException) { NcFile f(fname, NcFile::ReadOnly); diff --git a/src/yorick.hpp b/src/yorick.hpp index 6a2cf94..f124ae8 100644 --- a/src/yorick.hpp +++ b/src/yorick.hpp @@ -183,9 +183,11 @@ namespace CosmoTool template void saveArray(const char *fname, T *array, uint32_t *dimList, uint32_t rank); + template void loadArray(const char *fname, - T*& array, uint32_t *& dimList, uint32_t& rank); + T*& array, uint32_t *& dimList, uint32_t& rank) + throw (NoSuchFileException); ProgressiveDoubleOutput saveDoubleArrayProgressive(const char *fname, uint32_t *dimList, uint32_t rank); };