Skip to content
Snippets Groups Projects
Commit c2cd02c0 authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

add methods to sample to file

parent accc61f6
Branches
Tags
No related merge requests found
......@@ -472,7 +472,7 @@ if (BUILD_TESTING)
### basic particle functionality
add_test(
NAME test_tracer_set
COMMAND turtle TEST test_tracer_set -n 32 --np 2 --ntpp 2
COMMAND turtle TEST test_tracer_set -n 32 --np 2 --ntpp 2 --simname tracer_set_testsim
WORKING_DIRECTORY ${TEST_OUTPUT_DIRECTORY})
### compare DNS output to stored results
add_test(
......
......@@ -32,6 +32,7 @@
#include <memory>
#include "field.hpp"
#include "particles/p2p/p2p_distr_mpi.hpp"
#include "particles/particles_sampling.hpp"
......@@ -154,6 +155,70 @@ class abstract_particle_set
this->getParticleIndex());
return EXIT_SUCCESS;
}
template <typename field_rnumber,
field_backend be,
field_components fc>
int sample(
field<field_rnumber, be, fc> *field_to_sample,
particles_output_sampling_hdf5<partsize_t, particle_rnumber, 3> *particle_sample_writer,
const std::string species_name,
const std::string field_name,
const int iteration)
{
// set file layout
particle_sample_writer->setParticleFileLayout(this->getParticleFileLayout());
// allocate position array
std::unique_ptr<particle_rnumber[]> xx = this->extractFromParticleState(0, 3);
// allocate temporary array
std::unique_ptr<particle_rnumber[]> pdata(new particle_rnumber[ncomp(fc)*this->getLocalNumberOfParticles()]);
// clean up temporary array
std::fill_n(pdata.get(), ncomp(fc)*this->getLocalNumberOfParticles(), 0);
this->sample(*field_to_sample, pdata.get());
particle_sample_writer->template save_dataset<ncomp(fc)>(
species_name,
field_name,
xx.get(),
&pdata,
this->getParticleIndex(),
this->getLocalNumberOfParticles(),
iteration);
// deallocate temporary array
delete[] pdata.release();
// deallocate position array
delete[] xx.release();
return EXIT_SUCCESS;
}
int sample_state_triple(
const int i0,
particles_output_sampling_hdf5<partsize_t, particle_rnumber, 3> *particle_sample_writer,
const std::string species_name,
const std::string field_name,
const int iteration)
{
assert(i0 >= 0);
assert(i0 <= this->getStateSize()-3);
// set file layout
particle_sample_writer->setParticleFileLayout(this->getParticleFileLayout());
// allocate position array
std::unique_ptr<particle_rnumber[]> xx = this->extractFromParticleState(0, 3);
// allocate temporary array
std::unique_ptr<particle_rnumber[]> yy = this->extractFromParticleState(i0, i0+3);
particle_sample_writer->template save_dataset<3>(
species_name,
field_name,
xx.get(),
&yy,
this->getParticleIndex(),
this->getLocalNumberOfParticles(),
iteration);
// deallocate temporary array
delete[] yy.release();
// deallocate position array
delete[] xx.release();
return EXIT_SUCCESS;
}
};
#endif//ABSTRACT_PARTICLE_SET_HPP
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment