diff --git a/bfps/cpp/full_code/NSVEparticles.cpp b/bfps/cpp/full_code/NSVEparticles.cpp new file mode 100644 index 0000000000000000000000000000000000000000..08b50226b47f19a3f9b723c5482e1f34f3648e24 --- /dev/null +++ b/bfps/cpp/full_code/NSVEparticles.cpp @@ -0,0 +1,80 @@ +#include <string> +#include <cmath> +#include "NSVEparticles.hpp" +#include "scope_timer.hpp" + + +template <typename rnumber> +int NSVEparticles<rnumber>::initialize(void) +{ + this->NSVE<rnumber>::initialize(); + + this->ps = particles_system_builder( + fs->cvelocity, // (field object) + fs->kk, // (kspace object, contains dkx, dky, dkz) + tracers0_integration_steps, // to check coherency between parameters and hdf input file (nb rhs) + (long long int)nparticles, // to check coherency between parameters and hdf input file + fs->get_current_fname(), // particles input filename + std::string("/tracers0/state/") + std::to_string(fs->iteration), // dataset name for initial input + std::string("/tracers0/rhs/") + std::to_string(fs->iteration), // dataset name for initial input + tracers0_neighbours, // parameter (interpolation no neighbours) + tracers0_smoothness, // parameter + this->comm, + fs->iteration+1); + this->particles_output_writer_mpi = new particles_output_hdf5<long long int,double,3,3>( + MPI_COMM_WORLD, + "tracers0", + nparticles, + tracers0_integration_steps); + return EXIT_SUCCESS; +} + +template <typename rnumber> +int NSVEparticles<rnumber>::step(void) +{ + this->fs->compute_velocity(fs->cvorticity); + this->fs->cvelocity->ift(); + this->ps->completeLoop(this->dt); + this->NSVE<rnumber>::step(); + return EXIT_SUCCESS; +} + +template <typename rnumber> +int NSVEparticles<rnumber>::write_checkpoint(void) +{ + this->NSVE<rnumber>::write_checkpoint(); + this->particles_output_writer_mpi->open_file(fs->get_current_fname()); + this->particles_output_writer_mpi->save( + this->ps->getParticlesPositions(), + this->ps->getParticlesRhs(), + this->ps->getParticlesIndexes(), + this->ps->getLocalNbParticles(), + this->fs->iteration); + this->particles_output_writer_mpi->close_file(); + return EXIT_SUCCESS; +} + +template <typename rnumber> +int NSVEparticles<rnumber>::finalize(void) +{ + this->NSVE<rnumber>::finalize(); + this->ps.release(); + delete this->particles_output_writer_mpi; + return EXIT_SUCCESS; +} + +template <typename rnumber> +int NSVEparticles<rnumber>::do_stats() +{ + // fluid stats go here + this->NSVE<rnumber>::do_stats(); + // particle sampling should go here + //if (this->iteration % this->niter_part == 0) + //{ + //} + return EXIT_SUCCESS; +} + +template class NSVEparticles<float>; +template class NSVEparticles<double>; + diff --git a/bfps/cpp/full_code/NSVEparticles.hpp b/bfps/cpp/full_code/NSVEparticles.hpp new file mode 100644 index 0000000000000000000000000000000000000000..298d9950b878cf1e6e257ed021fd2b14d37f705e --- /dev/null +++ b/bfps/cpp/full_code/NSVEparticles.hpp @@ -0,0 +1,74 @@ +/********************************************************************** +* * +* Copyright 2017 Max Planck Institute * +* for Dynamics and Self-Organization * +* * +* This file is part of bfps. * +* * +* bfps is free software: you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published * +* by the Free Software Foundation, either version 3 of the License, * +* or (at your option) any later version. * +* * +* bfps is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with bfps. If not, see <http://www.gnu.org/licenses/> * +* * +* Contact: Cristian.Lalescu@ds.mpg.de * +* * +**********************************************************************/ + + + +#ifndef NSVEPARTICLES_HPP +#define NSVEPARTICLES_HPP + + + +#include <cstdlib> +#include "base.hpp" +#include "vorticity_equation.hpp" +#include "full_code/NSVE.hpp" +#include "particles/particles_system_builder.hpp" +#include "particles/particles_output_hdf5.hpp" + +template <typename rnumber> +class NSVEparticles: public NSVE +{ + public: + + /* parameters that are read in read_parameters */ + int niter_part; + int nparticles; + int tracers0_integration_steps; + int tracers0_neighbours; + int tracers0_smoothness; + + /* other stuff */ + std::unique_ptr<abstract_particles_system<long long int, double>> ps; + particles_output_hdf5<long long int, double,3,3> *particles_output_writer_mpi; + + + NSVEparticles( + const MPI_Comm COMMUNICATOR, + const std::string &simulation_name): + NSVE( + COMMUNICATOR, + simulation_name){} + ~NSVEparticles(){} + + int initialize(void); + int step(void); + int finalize(void); + + int read_parameters(void); + int write_checkpoint(void); + int do_stats(void); +}; + +#endif//NSVEPARTICLES_HPP +