mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-06 00:01:11 +00:00
Update cosmotool 2nd part
This commit is contained in:
parent
64e05fc180
commit
003bc39d4a
70 changed files with 8708 additions and 0 deletions
104
external/cosmotool/sample/gadgetToArray.cpp
vendored
Normal file
104
external/cosmotool/sample/gadgetToArray.cpp
vendored
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*+
|
||||
This is CosmoTool (./sample/gadgetToArray.cpp) -- Copyright (C) Guilhem Lavaux (2007-2014)
|
||||
|
||||
guilhem.lavaux@gmail.com
|
||||
|
||||
This software is a computer program whose purpose is to provide a toolbox for cosmological
|
||||
data analysis (e.g. filters, generalized Fourier transforms, power spectra, ...)
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited
|
||||
liability.
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
+*/
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include "cic.hpp"
|
||||
#include "loadGadget.hpp"
|
||||
#include "miniargs.hpp"
|
||||
#include <H5Cpp.h>
|
||||
#include "hdf5_array.hpp"
|
||||
|
||||
using namespace CosmoTool;
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
typedef boost::multi_array<float, 2> array_type;
|
||||
uint32_t res;
|
||||
char *fname;
|
||||
int id;
|
||||
double MPC;
|
||||
|
||||
MiniArgDesc desc[] = {
|
||||
{ "SNAPSHOT", &fname, MINIARG_STRING },
|
||||
{ "MPC", &MPC, MINIARG_DOUBLE },
|
||||
{ 0, 0, MINIARG_NULL }
|
||||
};
|
||||
|
||||
if (!parseMiniArgs(argc, argv, desc))
|
||||
return 1;
|
||||
|
||||
H5::H5File f("density.h5", H5F_ACC_TRUNC);
|
||||
|
||||
|
||||
SimuData *p = loadGadgetMulti(fname, 0, 0);
|
||||
double L0 = p->BoxSize/MPC;
|
||||
cout << "Will read " << p->TotalNumPart << " particles" << endl;
|
||||
array_type parts(boost::extents[p->TotalNumPart][7]);
|
||||
uint64_t q = 0;
|
||||
|
||||
try {
|
||||
for (int cpuid=0;;cpuid++) {
|
||||
cout << " = CPU " << cpuid << " = " << endl;
|
||||
p = loadGadgetMulti(fname, cpuid, NEED_POSITION|NEED_VELOCITY|NEED_MASS);
|
||||
cout << " = DONE LOAD, COPYING IN PLACE" << endl;
|
||||
for (uint32_t i = 0; i < p->NumPart; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
parts[q][j] = p->Pos[j][i]/MPC;
|
||||
while (parts[q][j] < 0) parts[q][j] += L0;
|
||||
while (parts[q][j] >= L0) parts[q][j] -= L0;
|
||||
parts[q][j] -= L0/2;
|
||||
}
|
||||
parts[q][3] = p->Vel[0][i];
|
||||
parts[q][4] = p->Vel[1][i];
|
||||
parts[q][5] = p->Vel[2][i];
|
||||
parts[q][6] = p->Mass[i];
|
||||
q++;
|
||||
}
|
||||
cout << " = DONE (q=" << q << ")" << endl;
|
||||
|
||||
delete p;
|
||||
}
|
||||
} catch (const NoSuchFileException& e) {}
|
||||
|
||||
cout << " ++ WRITING ++" << endl;
|
||||
hdf5_write_array(f, "particles", parts);
|
||||
|
||||
return 0;
|
||||
}
|
96
external/cosmotool/sample/gadgetToDensity.cpp
vendored
Normal file
96
external/cosmotool/sample/gadgetToDensity.cpp
vendored
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*+
|
||||
This is CosmoTool (./sample/gadgetToDensity.cpp) -- Copyright (C) Guilhem Lavaux (2007-2014)
|
||||
|
||||
guilhem.lavaux@gmail.com
|
||||
|
||||
This software is a computer program whose purpose is to provide a toolbox for cosmological
|
||||
data analysis (e.g. filters, generalized Fourier transforms, power spectra, ...)
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited
|
||||
liability.
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
+*/
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include "cic.hpp"
|
||||
#include "loadGadget.hpp"
|
||||
#include "miniargs.hpp"
|
||||
#include "yorick.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace CosmoTool;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
uint32_t res;
|
||||
char *fname;
|
||||
int id;
|
||||
|
||||
MiniArgDesc desc[] = {
|
||||
{ "SNAPSHOT", &fname, MINIARG_STRING },
|
||||
{ "ID", &id, MINIARG_INT },
|
||||
{ "RESOLUTION", &res, MINIARG_INT },
|
||||
{ 0, 0, MINIARG_NULL }
|
||||
};
|
||||
|
||||
if (!parseMiniArgs(argc, argv, desc))
|
||||
return 1;
|
||||
|
||||
SimuData *p = loadGadgetMulti(fname, 0, 0);
|
||||
double L0 = p->BoxSize;
|
||||
CICFilter filter(res, L0);
|
||||
|
||||
delete p;
|
||||
|
||||
try {
|
||||
for (int cpuid=0;;cpuid++) {
|
||||
p = loadGadgetMulti(fname, cpuid, NEED_POSITION);
|
||||
for (uint32_t i = 0; i < p->NumPart; i++)
|
||||
{
|
||||
CICParticles a;
|
||||
|
||||
a.mass = 1.0;
|
||||
a.coords[0] = p->Pos[0][i]/1000;
|
||||
a.coords[1] = p->Pos[1][i]/1000;
|
||||
a.coords[2] = p->Pos[2][i]/1000;
|
||||
filter.putParticles(&a, 1);
|
||||
}
|
||||
|
||||
delete p;
|
||||
}
|
||||
} catch (const NoSuchFileException& e) {}
|
||||
|
||||
CICType *denField;
|
||||
uint32_t Ntot;
|
||||
filter.getDensityField(denField, Ntot);
|
||||
|
||||
cout << "L0=" << L0 << endl;
|
||||
cout << "Saving density field" << endl;
|
||||
uint32_t dimList[] = { res, res, res};
|
||||
saveArray("densityField.nc", denField, dimList, 3);
|
||||
|
||||
return 0;
|
||||
}
|
72
external/cosmotool/sample/graficToDensity.cpp
vendored
Normal file
72
external/cosmotool/sample/graficToDensity.cpp
vendored
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <boost/multi_array.hpp>
|
||||
#include <H5Cpp.h>
|
||||
#include "hdf5_array.hpp"
|
||||
#include "miniargs.hpp"
|
||||
#include "fortran.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace CosmoTool;
|
||||
|
||||
//#define GRAFIC_GUILHEM
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
uint32_t res;
|
||||
char *fname;
|
||||
int id;
|
||||
|
||||
MiniArgDesc desc[] = {
|
||||
{ "GRAFIC", &fname, MINIARG_STRING },
|
||||
{ 0, 0, MINIARG_NULL }
|
||||
};
|
||||
|
||||
if (!parseMiniArgs(argc, argv, desc))
|
||||
return 1;
|
||||
|
||||
UnformattedRead ur(fname);
|
||||
|
||||
ur.beginCheckpoint();
|
||||
int32_t nx = ur.readInt32();
|
||||
int32_t ny = ur.readInt32();
|
||||
int32_t nz = ur.readInt32();
|
||||
float dx = ur.readReal32();
|
||||
float xo = ur.readReal32();
|
||||
float yo = ur.readReal32();
|
||||
float zo = ur.readReal32();
|
||||
float astart = ur.readReal32();
|
||||
float omega_m = ur.readReal32();
|
||||
float omega_nu = ur.readReal32();
|
||||
float h0 = ur.readReal32();
|
||||
#ifdef GRAFIC_GUILHEM
|
||||
float w0 = ur.readReal32();
|
||||
#endif
|
||||
ur.endCheckpoint();
|
||||
|
||||
cout << "Grafic file: Nx=" << nx << " Ny=" << ny << " Nz=" << nz << endl;
|
||||
cout << "a_start = " << astart << endl;
|
||||
cout << "z_start = " << 1/astart - 1 << endl;
|
||||
cout << "L = " << nx*dx << endl;
|
||||
|
||||
boost::multi_array<float, 3> density(boost::extents[nx][ny][nz]);
|
||||
|
||||
for (int32_t iz = 0; iz < nz; iz++)
|
||||
{
|
||||
ur.beginCheckpoint();
|
||||
for (int32_t iy = 0; iy < ny; iy++)
|
||||
{
|
||||
for (int32_t ix = 0; ix < nx; ix++)
|
||||
{
|
||||
density[ix][iy][iz] = ur.readReal32();
|
||||
}
|
||||
}
|
||||
ur.endCheckpoint();
|
||||
}
|
||||
|
||||
H5::H5File f("density.h5", H5F_ACC_TRUNC);
|
||||
hdf5_write_array(f, "density", density);
|
||||
|
||||
return 0;
|
||||
}
|
218
external/cosmotool/sample/simple3DFilter.cpp
vendored
Normal file
218
external/cosmotool/sample/simple3DFilter.cpp
vendored
Normal file
|
@ -0,0 +1,218 @@
|
|||
#include "openmp.hpp"
|
||||
#include "omptl/algorithm"
|
||||
#include <cassert>
|
||||
#include "yorick.hpp"
|
||||
#include "sphSmooth.hpp"
|
||||
#include "mykdtree.hpp"
|
||||
#include "miniargs.hpp"
|
||||
#include <H5Cpp.h>
|
||||
#include "hdf5_array.hpp"
|
||||
#include <iostream>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace CosmoTool;
|
||||
|
||||
#define N_SPH 32
|
||||
|
||||
struct VCoord{
|
||||
float v[3];
|
||||
float mass;
|
||||
};
|
||||
|
||||
using boost::format;
|
||||
using boost::str;
|
||||
typedef boost::multi_array<float, 2> array_type;
|
||||
typedef boost::multi_array<float, 3> array3_type;
|
||||
typedef boost::multi_array<float, 4> array4_type;
|
||||
|
||||
ComputePrecision getVelocity(const VCoord& v, int i)
|
||||
{
|
||||
return v.mass * v.v[i];
|
||||
}
|
||||
|
||||
ComputePrecision getMass(const VCoord& v)
|
||||
{
|
||||
return v.mass;
|
||||
}
|
||||
|
||||
typedef SPHSmooth<VCoord> MySmooth;
|
||||
typedef MySmooth::SPHTree MyTree;
|
||||
typedef MyTree::Cell MyCell;
|
||||
|
||||
template<typename FuncT>
|
||||
void computeInterpolatedField(MyTree *tree1, double boxsize, int Nres, double cx, double cy, double cz,
|
||||
array3_type& bins, array3_type& arr, FuncT func, double rLimit2)
|
||||
{
|
||||
#pragma omp parallel
|
||||
{
|
||||
MySmooth smooth1(tree1, N_SPH);
|
||||
|
||||
#pragma omp for schedule(dynamic)
|
||||
for (int rz = 0; rz < Nres; rz++)
|
||||
{
|
||||
double pz = (rz)*boxsize/Nres-cz;
|
||||
|
||||
cout << format("[%d] %d / %d") % smp_get_thread_id() % rz % Nres << endl;
|
||||
for (int ry = 0; ry < Nres; ry++)
|
||||
{
|
||||
double py = (ry)*boxsize/Nres-cy;
|
||||
for (int rx = 0; rx < Nres; rx++)
|
||||
{
|
||||
double px = (rx)*boxsize/Nres-cx;
|
||||
|
||||
MyTree::coords c = { float(px), float(py), float(pz) };
|
||||
|
||||
double r2 = c[0]*c[0]+c[1]*c[1]+c[2]*c[2];
|
||||
if (r2 > rLimit2)
|
||||
{
|
||||
arr[rx][ry][rz] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t numInCell = bins[rx][ry][rz];
|
||||
if (numInCell > N_SPH)
|
||||
smooth1.fetchNeighbours(c, numInCell);
|
||||
else
|
||||
smooth1.fetchNeighbours(c);
|
||||
|
||||
arr[rx][ry][rz] = smooth1.computeSmoothedValue(c, func);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
char *fname1, *fname2;
|
||||
double rLimit, boxsize, rLimit2, cx, cy, cz;
|
||||
int Nres;
|
||||
|
||||
MiniArgDesc args[] = {
|
||||
{ "INPUT DATA1", &fname1, MINIARG_STRING },
|
||||
{ "RADIUS LIMIT", &rLimit, MINIARG_DOUBLE },
|
||||
{ "BOXSIZE", &boxsize, MINIARG_DOUBLE },
|
||||
{ "RESOLUTION", &Nres, MINIARG_INT },
|
||||
{ "CX", &cx, MINIARG_DOUBLE },
|
||||
{ "CY", &cy, MINIARG_DOUBLE },
|
||||
{ "CZ", &cz, MINIARG_DOUBLE },
|
||||
{ 0, 0, MINIARG_NULL }
|
||||
};
|
||||
|
||||
if (!parseMiniArgs(argc, argv, args))
|
||||
return 1;
|
||||
|
||||
H5::H5File in_f(fname1, 0);
|
||||
H5::H5File out_f("fields.h5", H5F_ACC_TRUNC);
|
||||
array_type v1_data;
|
||||
uint32_t N1_points, N2_points;
|
||||
|
||||
array3_type bins(boost::extents[Nres][Nres][Nres]);
|
||||
|
||||
rLimit2 = rLimit*rLimit;
|
||||
|
||||
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];
|
||||
|
||||
#pragma omp parallel for schedule(static)
|
||||
for (long i = 0; i < Nres*Nres*Nres; i++)
|
||||
bins.data()[i] = 0;
|
||||
|
||||
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];
|
||||
for (int k = 0; k < 3; k++)
|
||||
allCells_1[i].val.pValue.v[k] = v1_data[i][3+k];
|
||||
allCells_1[i].val.pValue.mass = v1_data[i][6];
|
||||
allCells_1[i].active = true;
|
||||
allCells_1[i].val.weight = 0.0;
|
||||
|
||||
long rx = floor((allCells_1[i].coord[0]+cx)*Nres/boxsize+0.5);
|
||||
long ry = floor((allCells_1[i].coord[1]+cy)*Nres/boxsize+0.5);
|
||||
long rz = floor((allCells_1[i].coord[2]+cz)*Nres/boxsize+0.5);
|
||||
|
||||
if (rx < 0 || rx >= Nres || ry < 0 || ry >= Nres || rz < 0 || rz >= Nres)
|
||||
continue;
|
||||
|
||||
#pragma omp atomic update
|
||||
bins[rx][ry][rz]++;
|
||||
}
|
||||
v1_data.resize(boost::extents[1][1]);
|
||||
|
||||
hdf5_write_array(out_f, "num_in_cell", bins);
|
||||
|
||||
cout << "Building trees..." << endl;
|
||||
MyTree tree1(allCells_1, N1_points);
|
||||
|
||||
cout << "Creating smoothing filter..." << endl;
|
||||
|
||||
// array3_type out_rad_1(boost::extents[Nres][Nres][Nres]);
|
||||
|
||||
cout << "Weighing..." << endl;
|
||||
|
||||
#pragma omp parallel
|
||||
{
|
||||
MySmooth smooth1(&tree1, N_SPH);
|
||||
|
||||
#pragma omp for schedule(dynamic)
|
||||
for (int rz = 0; rz < Nres; rz++)
|
||||
{
|
||||
double pz = (rz)*boxsize/Nres-cz;
|
||||
|
||||
(cout << rz << " / " << Nres << endl).flush();
|
||||
for (int ry = 0; ry < Nres; ry++)
|
||||
{
|
||||
double py = (ry)*boxsize/Nres-cy;
|
||||
for (int rx = 0; rx < Nres; rx++)
|
||||
{
|
||||
double px = (rx)*boxsize/Nres-cx;
|
||||
|
||||
MyTree::coords c = { float(px), float(py), float(pz) };
|
||||
|
||||
double r2 = c[0]*c[0]+c[1]*c[1]+c[2]*c[2];
|
||||
if (r2 > rLimit2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t numInCell = bins[rx][ry][rz];
|
||||
if (numInCell > N_SPH)
|
||||
smooth1.fetchNeighbours(c, numInCell);
|
||||
else
|
||||
smooth1.fetchNeighbours(c);
|
||||
#pragma omp critical
|
||||
smooth1.addGridSite(c);
|
||||
}
|
||||
}
|
||||
(cout << " Done " << rz << endl).flush();
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Interpolating..." << endl;
|
||||
|
||||
array3_type interpolated(boost::extents[Nres][Nres][Nres]);
|
||||
|
||||
computeInterpolatedField(&tree1, boxsize, Nres, cx, cy, cz,
|
||||
bins, interpolated, getMass, rLimit2);
|
||||
hdf5_write_array(out_f, "density", interpolated);
|
||||
//out_f.flush();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
computeInterpolatedField(&tree1, boxsize, Nres, cx, cy, cz,
|
||||
bins, interpolated, boost::bind(getVelocity, _1, i), rLimit2);
|
||||
hdf5_write_array(out_f, str(format("p%d") % i), interpolated);
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
86
external/cosmotool/sample/simpleDistanceFilter.cpp
vendored
Normal file
86
external/cosmotool/sample/simpleDistanceFilter.cpp
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "openmp.hpp"
|
||||
#include "omptl/algorithm"
|
||||
#include <cassert>
|
||||
#include "yorick.hpp"
|
||||
#include "sphSmooth.hpp"
|
||||
#include "mykdtree.hpp"
|
||||
#include "miniargs.hpp"
|
||||
#include <H5Cpp.h>
|
||||
#include "hdf5_array.hpp"
|
||||
#include <iostream>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace CosmoTool;
|
||||
|
||||
struct VCoord{
|
||||
};
|
||||
|
||||
using boost::format;
|
||||
using boost::str;
|
||||
typedef boost::multi_array<float, 2> array_type_2d;
|
||||
typedef boost::multi_array<float, 1> 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;
|
||||
};
|
183
external/cosmotool/sample/testHDF5.cpp
vendored
Normal file
183
external/cosmotool/sample/testHDF5.cpp
vendored
Normal file
|
@ -0,0 +1,183 @@
|
|||
/*+
|
||||
This is CosmoTool (./sample/testHDF5.cpp) -- Copyright (C) Guilhem Lavaux (2007-2014)
|
||||
|
||||
guilhem.lavaux@gmail.com
|
||||
|
||||
This software is a computer program whose purpose is to provide a toolbox for cosmological
|
||||
data analysis (e.g. filters, generalized Fourier transforms, power spectra, ...)
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited
|
||||
liability.
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
+*/
|
||||
#include <iostream>
|
||||
#include "hdf5_array.hpp"
|
||||
#include <H5Cpp.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct MyStruct
|
||||
{
|
||||
int a;
|
||||
double b;
|
||||
char c;
|
||||
};
|
||||
|
||||
struct MyStruct2
|
||||
{
|
||||
MyStruct base;
|
||||
int d;
|
||||
};
|
||||
|
||||
enum MyColors
|
||||
{
|
||||
RED, GREEN, BLUE
|
||||
};
|
||||
|
||||
CTOOL_STRUCT_TYPE(MyStruct, hdf5t_MyStruct,
|
||||
((int, a))
|
||||
((double, b))
|
||||
((char, c))
|
||||
)
|
||||
|
||||
CTOOL_STRUCT_TYPE(MyStruct2, hdf5t_MyStruct2,
|
||||
((MyStruct, base))
|
||||
((int, d))
|
||||
)
|
||||
|
||||
CTOOL_ENUM_TYPE(MyColors, hdf5t_MyColors,
|
||||
(RED) (GREEN) (BLUE)
|
||||
)
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::multi_array<float, 2> array_type;
|
||||
typedef boost::multi_array<float, 3> array3_type;
|
||||
typedef boost::multi_array<MyStruct, 1> array_mys_type;
|
||||
typedef boost::multi_array<MyColors, 1> array_mys_color;
|
||||
typedef boost::multi_array<bool, 1> array_mys_bool;
|
||||
typedef boost::multi_array<MyStruct2, 1> array_mys2_type;
|
||||
typedef boost::multi_array<std::complex<double>, 2> arrayc_type;
|
||||
typedef array_type::index index;
|
||||
|
||||
H5::H5File f("test.h5", H5F_ACC_TRUNC);
|
||||
|
||||
H5::Group g = f.createGroup("test_group");
|
||||
|
||||
array_type A(boost::extents[2][3]);
|
||||
array_type B, Bprime(boost::extents[1][2]);
|
||||
array3_type C(boost::extents[2][3][4]);
|
||||
arrayc_type D, E;
|
||||
array_mys_type F(boost::extents[10]), G;
|
||||
array_mys2_type H(boost::extents[10]);
|
||||
array_mys_color I(boost::extents[2]);
|
||||
array_mys_bool J(boost::extents[2]);
|
||||
|
||||
I[0] = RED;
|
||||
I[1] = BLUE;
|
||||
J[0] = false;
|
||||
J[1] = true;
|
||||
|
||||
int values = 0;
|
||||
for (index i = 0; i != 2; i++)
|
||||
for (index j = 0; j != 3; j++)
|
||||
A[i][j] = values++;
|
||||
|
||||
for (index i = 0; i != 10; i++)
|
||||
{
|
||||
F[i].a = i;
|
||||
F[i].b = double(i)/4.;
|
||||
F[i].c = 'r'+i;
|
||||
H[i].base = F[i];
|
||||
H[i].d = 2*i;
|
||||
}
|
||||
std::cout << " c = " << ((char *)&F[1])[offsetof(MyStruct, c)] << endl;
|
||||
|
||||
CosmoTool::hdf5_write_array(g, "test_data", A);
|
||||
CosmoTool::hdf5_write_array(g, "test_struct", F);
|
||||
CosmoTool::hdf5_write_array(g, "test_struct2", H);
|
||||
CosmoTool::hdf5_write_array(g, "colors", I);
|
||||
CosmoTool::hdf5_write_array(g, "bools", J);
|
||||
CosmoTool::hdf5_read_array(g, "test_data", B);
|
||||
|
||||
int verify = 0;
|
||||
for (index i = 0; i != 2; i++)
|
||||
for (index j = 0; j != 3; j++)
|
||||
if (B[i][j] != verify++) {
|
||||
std::cout << "Invalid array content" << endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
std::cout << "Testing C " << std::endl;
|
||||
try
|
||||
{
|
||||
CosmoTool::hdf5_read_array(g, "test_data", C);
|
||||
std::cout << "Did not throw InvalidDimensions" << endl;
|
||||
abort();
|
||||
}
|
||||
catch (const CosmoTool::InvalidDimensions&)
|
||||
{}
|
||||
|
||||
std::cout << "Testing Bprime " << std::endl;
|
||||
try
|
||||
{
|
||||
CosmoTool::hdf5_read_array(g, "test_data", Bprime, false, true);
|
||||
for (index i = 0; i != 1; i++)
|
||||
for (index j = 0; j != 2; j++)
|
||||
if (B[i][j] != Bprime[i][j]) {
|
||||
std::cout << "Invalid array content in Bprime" << endl;
|
||||
abort();
|
||||
}
|
||||
}
|
||||
catch (const CosmoTool::InvalidDimensions&)
|
||||
{
|
||||
std::cout << "Bad! Dimensions should be accepted" << std::endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
D.resize(boost::extents[2][3]);
|
||||
D = A;
|
||||
|
||||
CosmoTool::hdf5_write_array(g, "test_data_c", D);
|
||||
|
||||
CosmoTool::hdf5_read_array(g, "test_data_c", E);
|
||||
|
||||
verify = 0;
|
||||
for (index i = 0; i != 2; i++)
|
||||
for (index j = 0; j != 3; j++)
|
||||
if (E[i][j].real() != verify++) {
|
||||
std::cout << "Invalid array content" << endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
CosmoTool::hdf5_read_array(g, "test_struct", G);
|
||||
for (index i = 0; i != 10; i++)
|
||||
if (G[i].a != F[i].a || G[i].b != F[i].b || G[i].c != F[i].c) {
|
||||
std::cout << "Invalid struct content" << endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue