Commit 2d251931 authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

adds simple ghost collision test

parent 45610234
......@@ -187,6 +187,7 @@ set(cpp_for_lib
${PROJECT_SOURCE_DIR}/cpp/full_code/direct_numerical_simulation.cpp
${PROJECT_SOURCE_DIR}/cpp/full_code/NSVE.cpp
${PROJECT_SOURCE_DIR}/cpp/full_code/static_field.cpp
${PROJECT_SOURCE_DIR}/cpp/full_code/static_field_with_ghost_collisions.cpp
${PROJECT_SOURCE_DIR}/cpp/full_code/joint_acc_vel_stats.cpp
${PROJECT_SOURCE_DIR}/cpp/full_code/test.cpp
${PROJECT_SOURCE_DIR}/cpp/full_code/filter_test.cpp
......@@ -229,6 +230,7 @@ set(hpp_for_lib
${PROJECT_SOURCE_DIR}/cpp/full_code/direct_numerical_simulation.hpp
${PROJECT_SOURCE_DIR}/cpp/full_code/NSVE.hpp
${PROJECT_SOURCE_DIR}/cpp/full_code/static_field.hpp
${PROJECT_SOURCE_DIR}/cpp/full_code/static_field_with_ghost_collisions.hpp
${PROJECT_SOURCE_DIR}/cpp/full_code/joint_acc_vel_stats.hpp
${PROJECT_SOURCE_DIR}/cpp/full_code/test.hpp
${PROJECT_SOURCE_DIR}/cpp/full_code/filter_test.hpp
......
......@@ -440,7 +440,7 @@ class DNS(_code):
assert (self.parameters['niter_todo'] % self.parameters['niter_stat'] == 0)
assert (self.parameters['niter_todo'] % self.parameters['niter_out'] == 0)
assert (self.parameters['niter_out'] % self.parameters['niter_stat'] == 0)
if self.dns_type in ['NSVEparticles_no_output', 'NSVEcomplex_particles', 'NSVEparticles', 'static_field']:
if self.dns_type in ['NSVEparticles_no_output', 'NSVEcomplex_particles', 'NSVEparticles', 'static_field', 'static_field_with_ghost_collisions']:
assert (self.parameters['niter_todo'] % self.parameters['niter_part'] == 0)
assert (self.parameters['niter_out'] % self.parameters['niter_part'] == 0)
_code.write_par(self, iter0 = iter0)
......@@ -483,6 +483,8 @@ class DNS(_code):
4),
dtype = np.int64)
ofile['checkpoint'] = int(0)
if self.dns_type in ['static_field_with_ghost_collisions']:
ofile.create_group('statistics/collisions')
if (self.dns_type in ['NSVE', 'NSVE_no_output']):
return None
return None
......@@ -647,6 +649,10 @@ class DNS(_code):
'static_field',
help = 'static field with basic fluid tracers')
parser_static_field_with_ghost_collisions = subparsers.add_parser(
'static_field_with_ghost_collisions',
help = 'static field with basic fluid tracers and ghost collisions')
parser_NSVEp2 = subparsers.add_parser(
'NSVEparticles',
help = 'plain Navier-Stokes vorticity formulation, with basic fluid tracers')
......@@ -659,7 +665,7 @@ class DNS(_code):
'NSVEp_extra_sampling',
help = 'plain Navier-Stokes vorticity formulation, with basic fluid tracers, that sample velocity gradient, as well as pressure and its derivatives.')
for parser in ['NSVEparticles_no_output', 'NSVEp2', 'NSVEp2p', 'NSVEp_extra', 'static_field']:
for parser in ['NSVEparticles_no_output', 'NSVEp2', 'NSVEp2p', 'NSVEp_extra', 'static_field', 'static_field_with_ghost_collisions']:
eval('self.simulation_parser_arguments({0})'.format('parser_' + parser))
eval('self.job_parser_arguments({0})'.format('parser_' + parser))
eval('self.particle_parser_arguments({0})'.format('parser_' + parser))
......@@ -702,7 +708,7 @@ class DNS(_code):
self.dns_type = opt.DNS_class
self.name = self.dns_type + '-' + self.fluid_precision + '-v' + TurTLE.__version__
# merge parameters if needed
if self.dns_type in ['NSVEparticles', 'NSVEcomplex_particles', 'NSVEparticles_no_output', 'NSVEp_extra_sampling', 'static_field']:
if self.dns_type in ['NSVEparticles', 'NSVEcomplex_particles', 'NSVEparticles_no_output', 'NSVEp_extra_sampling', 'static_field', 'static_field_with_ghost_collisions']:
for k in self.NSVEp_extra_parameters.keys():
self.parameters[k] = self.NSVEp_extra_parameters[k]
if type(extra_parameters) != type(None):
......@@ -767,7 +773,7 @@ class DNS(_code):
# hardcoded FFTW complex representation size
field_size = 3*(opt.nx+2)*opt.ny*opt.nz*self.fluid_dtype.itemsize
checkpoint_size = field_size
if self.dns_type in ['static_field', 'NSVEparticles', 'NSVEcomplex_particles', 'NSVEparticles_no_output', 'NSVEp_extra_sampling']:
if self.dns_type in ['static_field', 'NSVEparticles', 'NSVEcomplex_particles', 'NSVEparticles_no_output', 'NSVEp_extra_sampling', 'static_field_with_ghost_collisions']:
rhs_size = self.parameters['tracers0_integration_steps']
if type(opt.tracers0_integration_steps) != type(None):
rhs_size = opt.tracers0_integration_steps
......@@ -1043,7 +1049,7 @@ class DNS(_code):
f['vorticity/complex/{0}'.format(0)] = data
f.close()
# now take care of particles' initial condition
if self.dns_type in ['static_field', 'NSVEparticles', 'NSVEcomplex_particles', 'NSVEparticles_no_output', 'NSVEp_extra_sampling']:
if self.dns_type in ['static_field', 'NSVEparticles', 'NSVEcomplex_particles', 'NSVEparticles_no_output', 'NSVEp_extra_sampling', 'static_field_with_ghost_collisions']:
self.generate_particle_data(opt = opt)
return None
def launch_jobs(
......
......@@ -30,9 +30,10 @@
template <typename rnumber>
int static_field<rnumber>::initialize(void)
int static_field_with_ghost_collisions<rnumber>::initialize(void)
{
TIMEZONE("static_file::initialize");
DEBUG_MSG("hello from initialize\n");
this->read_iteration();
this->read_parameters();
if (this->myrank == 0)
......@@ -89,14 +90,17 @@ int static_field<rnumber>::initialize(void)
this->velocity->ift();
this->vorticity->ift();
p2p_ghost_collisions<double, long long int> p2p_ghost_collisions;
p2p_ghost_collisions.setEnable(this->enable_p2p);
// initialize particles
p2p_ghost_collisions<double, long long int> p2p_gc;
this->ps = Template_double_for_if::evaluate<std::unique_ptr<abstract_particles_system<long long int, double>>,
particles_inner_computer<double, long long int> current_particles_inner_computer(this->tracers0_inner_v0, this->tracers0_lambda);
current_particles_inner_computer.setEnable(enable_inner);
this->ps = Template_double_for_if::evaluate<std::unique_ptr<abstract_particles_system_with_p2p<long long int, double, p2p_ghost_collisions<double, long long int>>>,
int, 1, 11, 1, // interpolation_size
int, 0, 3, 1, // spline_mode
particles_system_build_container<long long int, rnumber,FFTW,THREE,double,
collision_detector<double, long long int>,
p2p_ghost_collisions<double, long long int>,
particles_inner_computer_empty<double,long long int>,
3,3>>(
this->tracers0_neighbours, // template iterator 1
......@@ -110,8 +114,8 @@ int static_field<rnumber>::initialize(void)
std::string("/tracers0/rhs/") + std::to_string(this->iteration),
this->comm,
this->iteration+1,
std::move(cd),
std::move(p2p_ghost_collisions),
std::move(p2p_gc),
std::move(particles_inner_computer_empty<double, long long int>()),
this->tracers0_cutoff);
// initialize output objects
......@@ -135,18 +139,20 @@ int static_field<rnumber>::initialize(void)
}
template <typename rnumber>
int static_field<rnumber>::step(void)
int static_field_with_ghost_collisions<rnumber>::step(void)
{
TIMEZONE("static_file::step");
this->ps->getP2PComputer().reset_collision_counter(); // TODO should it be here ?
// reset collision counter before completeLoop.
// since this is a fake p2p interaction, the counter is always incremented
// during the call to completeLoop
this->ps->getP2PComputer().reset_collision_counter();
this->ps->completeLoop(this->dt);
const long int nbCollision = this->ps->getP2PComputer().get_collision_counter(); // TODO should it be here ?
this->iteration++;
return EXIT_SUCCESS;
}
template <typename rnumber>
int static_field<rnumber>::write_checkpoint(void)
int static_field_with_ghost_collisions<rnumber>::write_checkpoint(void)
{
TIMEZONE("static_file::write_checkpoint");
this->particles_output_writer_mpi->open_file(this->get_current_fname());
......@@ -161,9 +167,9 @@ int static_field<rnumber>::write_checkpoint(void)
}
template <typename rnumber>
int static_field<rnumber>::finalize(void)
int static_field_with_ghost_collisions<rnumber>::finalize(void)
{
TIMEZONE("static_field::finalize");
TIMEZONE("static_field_with_ghost_collisions::finalize");
if (this->myrank == 0)
H5Fclose(this->stat_file);
// good practice rule number n+1: always delete in inverse order of allocation
......@@ -181,9 +187,9 @@ int static_field<rnumber>::finalize(void)
*/
template <typename rnumber>
int static_field<rnumber>::do_stats()
int static_field_with_ghost_collisions<rnumber>::do_stats()
{
TIMEZONE("static_field::do_stats");
TIMEZONE("static_field_with_ghost_collisions::do_stats");
/// either one of two conditions suffices to compute statistics:
/// 1) current iteration is a multiple of niter_part
/// 2) we are within niter_part_fine_duration/2 of a multiple of niter_part_fine_period
......@@ -225,13 +231,22 @@ int static_field<rnumber>::do_stats()
// deallocate temporary data array
delete[] pdata.release();
///count collisions
const long int nbCollision_local = this->ps->getP2PComputer().get_collision_counter();
DEBUG_MSG("there are %ld collisions\n", nbCollision_local);
long int nbCollision_global;
MPI_Allreduce(&nbCollision_local,
&nbCollision_global, 1,
MPI_LONG, MPI_SUM, this->comm);
if (this->myrank == 0)
DEBUG_MSG("globally, there are %ld collisions\n", nbCollision_global);
return EXIT_SUCCESS;
}
template <typename rnumber>
int static_field<rnumber>::read_parameters(void)
int static_field_with_ghost_collisions<rnumber>::read_parameters(void)
{
TIMEZONE("static_field::read_parameters");
TIMEZONE("static_field_with_ghost_collisions::read_parameters");
this->direct_numerical_simulation::read_parameters();
hid_t parameter_file = H5Fopen((this->simname + ".h5").c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
this->fftw_plan_rigor = hdf5_tools::read_string(parameter_file, "parameters/fftw_plan_rigor");
......@@ -243,11 +258,11 @@ int static_field<rnumber>::read_parameters(void)
this->tracers0_integration_steps = hdf5_tools::read_value<int>(parameter_file, "parameters/tracers0_integration_steps");
this->tracers0_neighbours = hdf5_tools::read_value<int>(parameter_file, "parameters/tracers0_neighbours");
this->tracers0_smoothness = hdf5_tools::read_value<int>(parameter_file, "parameters/tracers0_smoothness");
this->tracers0_cutoff = hdf5_tools::read_value<double>(parameter_file, "parameters/tracers0_cutoff");
H5Fclose(parameter_file);
return EXIT_SUCCESS;
}
template class static_field<float>;
template class static_field<double>;
template class static_field_with_ghost_collisions<float>;
template class static_field_with_ghost_collisions<double>;
......@@ -34,10 +34,13 @@
#include "particles/particles_system_builder.hpp"
#include "particles/particles_output_hdf5.hpp"
#include "particles/particles_sampling.hpp"
#include "particles/p2p_computer.hpp"
#include "particles/p2p_ghost_collisions.hpp"
#include "particles/particles_inner_computer.hpp"
template <typename rnumber>
class static_field: public direct_numerical_simulation
class static_field_with_ghost_collisions: public direct_numerical_simulation
{
public:
......@@ -54,25 +57,39 @@ class static_field: public direct_numerical_simulation
int tracers0_neighbours;
int tracers0_smoothness;
double tracers0_cutoff;
double tracers0_inner_v0;
double tracers0_lambda;
bool enable_p2p;
bool enable_inner;
bool enable_vorticity_omega;
/* other stuff */
kspace<FFTW, SMOOTH> *kk;
field<rnumber, FFTW, THREE> *vorticity;
field<rnumber, FFTW, THREE> *velocity;
/* other stuff */
std::unique_ptr<abstract_particles_system_with_p2p<long long int, double, p2p_ghost_collisions>> ps;
std::unique_ptr<abstract_particles_system_with_p2p<long long int, double, p2p_ghost_collisions<double, long long int>>> ps;
particles_output_hdf5<long long int, double,3> *particles_output_writer_mpi;
particles_output_sampling_hdf5<long long int, double, 3> *particles_sample_writer_mpi;
static_field(
static_field_with_ghost_collisions(
const MPI_Comm COMMUNICATOR,
const std::string &simulation_name):
direct_numerical_simulation(
COMMUNICATOR,
simulation_name){}
~static_field(){}
simulation_name),
tracers0_cutoff(1),
tracers0_inner_v0(0),
tracers0_lambda(1.0),
enable_p2p(true),
enable_inner(false),
enable_vorticity_omega(false){}
~static_field_with_ghost_collisions(){}
int initialize(void);
int step(void);
......
......@@ -24,6 +24,7 @@
#define P2P_GHOST_COLLISIONS_HPP
#include <cstring>
#include <set>
template <class real_number, class partsize_t>
class p2p_ghost_collisions{
......@@ -56,11 +57,11 @@ public:
void merge(const p2p_ghost_collisions& other){
collision_counter += other.collision_counter;
std::set <std::pair <partsize_t, partsize_t>> new_collision_pairs;
std::set_union(collision_pairs.begin(), collision_pairs.end(),
other.collision_pairs.begin(), other.collision_pairs.end(),
std::back_inserter(new_collision_pairs));
collision_pairs = new_collision_pairs;
//std::set <std::pair <partsize_t, partsize_t>> new_collision_pairs;
//std::set_union(collision_pairs.begin(), collision_pairs.end(),
// other.collision_pairs.begin(), other.collision_pairs.end(),
// std::back_inserter(new_collision_pairs));
//collision_pairs = new_collision_pairs;
}
constexpr static bool isEnable() {
......
......@@ -6,6 +6,8 @@ turtle.test_fftw
turtle.test_Parseval
turtle.test_NSVEparticles
turtle DNS static_field_with_ghost_collisions --simname dumb_test_of_ghost_collisions
# test postprocessing
turtle PP field_single_to_double --simname dns_nsveparticles --iter0 32 --iter1 32
turtle PP get_rfields --simname dns_nsveparticles --iter0 0 --iter1 64
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment