diff --git a/bfps/PP.py b/bfps/PP.py index 4d19095a088d4fa1347eff5f35a32a5fc8ef1870..27a359287dca65f01f2a66eaaef1fe56c13862fc 100644 --- a/bfps/PP.py +++ b/bfps/PP.py @@ -434,6 +434,12 @@ class PP(_code): self.simulation_parser_arguments(parser_native_binary_to_hdf5) self.job_parser_arguments(parser_native_binary_to_hdf5) self.parameters_to_parser_arguments(parser_native_binary_to_hdf5) + parser_field_single_to_double = subparsers.add_parser( + 'field_single_to_double', + help = 'convert complex vorticity from single to double') + self.simulation_parser_arguments(parser_field_single_to_double) + self.job_parser_arguments(parser_field_single_to_double) + self.parameters_to_parser_arguments(parser_field_single_to_double) parser_get_rfields = subparsers.add_parser( 'get_rfields', help = 'get real space velocity field') diff --git a/bfps/cpp/full_code/field_single_to_double.cpp b/bfps/cpp/full_code/field_single_to_double.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bbc7e292081c893cd9ce958026eac12dec3d9c11 --- /dev/null +++ b/bfps/cpp/full_code/field_single_to_double.cpp @@ -0,0 +1,85 @@ +#include <string> +#include <cmath> +#include "field_single_to_double.hpp" +#include "scope_timer.hpp" + + +template <typename rnumber> +int field_single_to_double<rnumber>::initialize(void) +{ + this->NSVE_field_stats<rnumber>::initialize(); + DEBUG_MSG("after NSVE_field_stats::initialize\n"); + this->vec_field_double = new field<double, FFTW, THREE>( + this->nx, this->ny, this->nz, + this->comm, + this->vorticity->fftw_plan_rigor); + hid_t parameter_file = H5Fopen( + (this->simname + std::string(".h5")).c_str(), + H5F_ACC_RDONLY, + H5P_DEFAULT); + hid_t dset = H5Dopen(parameter_file, "/parameters/niter_out", H5P_DEFAULT); + H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &this->niter_out); + H5Dclose(dset); + if (H5Lexists(parameter_file, "/parameters/checkpoints_per_file", H5P_DEFAULT)) + { + dset = H5Dopen(parameter_file, "/parameters/checkpoints_per_file", H5P_DEFAULT); + H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &this->checkpoints_per_file); + H5Dclose(dset); + } + else + this->checkpoints_per_file = 1; + H5Fclose(parameter_file); + parameter_file = H5Fopen( + (this->simname + std::string("_post.h5")).c_str(), + H5F_ACC_RDONLY, + H5P_DEFAULT); + DEBUG_MSG("before read_vector\n"); + this->iteration_list = hdf5_tools::read_vector<int>( + parameter_file, + "/get_rfields/parameters/iteration_list"); + H5Fclose(parameter_file); + return EXIT_SUCCESS; +} + +template <typename rnumber> +int field_single_to_double<rnumber>::work_on_current_iteration(void) +{ + DEBUG_MSG("entered field_single_to_double::work_on_current_iteration\n"); + this->read_current_cvorticity(); + + this->vorticity->RLOOP( + [&](ptrdiff_t rindex, + ptrdiff_t xindex, + ptrdiff_t yindex, + ptrdiff_t zindex){ + { + this->vec_field_double->rval(rindex, 0) = this->vorticity->rval(rindex, 0); + this->vec_field_double->rval(rindex, 1) = this->vorticity->rval(rindex, 1); + this->vec_field_double->rval(rindex, 2) = this->vorticity->rval(rindex, 2); + } + } + ); + + std::string fname = ( + this->simname + + std::string("_checkpoint_double_") + + std::to_string(this->iteration / (this->niter_out*this->checkpoints_per_file)) + + std::string(".h5")); + this->vec_field_double->io( + fname, + "vorticity", + this->iteration, + false); + + return EXIT_SUCCESS; +} + +template <typename rnumber> +int field_single_to_double<rnumber>::finalize(void) +{ + delete this->vec_field_double; + return EXIT_SUCCESS; +} + +template class field_single_to_double<float>; + diff --git a/bfps/cpp/full_code/field_single_to_double.hpp b/bfps/cpp/full_code/field_single_to_double.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c4afc439ca091343088a507555924eab6e16a5b9 --- /dev/null +++ b/bfps/cpp/full_code/field_single_to_double.hpp @@ -0,0 +1,62 @@ +/********************************************************************** +* * +* 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 FIELD_SINGLE_TO_DOUBLE_HPP +#define FIELD_SINGLE_TO_DOUBLE_HPP + +#include <cstdlib> +#include <sys/types.h> +#include <sys/stat.h> +#include <vector> +#include "base.hpp" +#include "field.hpp" +#include "field_binary_IO.hpp" +#include "full_code/NSVE_field_stats.hpp" + +template <typename rnumber> +class field_single_to_double: public NSVE_field_stats<rnumber> +{ + public: + int checkpoints_per_file; + int niter_out; + + field<double, FFTW, THREE> *vec_field_double; + + field_single_to_double( + const MPI_Comm COMMUNICATOR, + const std::string &simulation_name): + NSVE_field_stats<rnumber>( + COMMUNICATOR, + simulation_name){} + virtual ~field_single_to_double(){} + + int initialize(void); + int work_on_current_iteration(void); + int finalize(void); +}; + +#endif//FIELD_SINGLE_TO_DOUBLE_HPP + diff --git a/setup.py b/setup.py index 8152e5fe0c0600e3a7b423ae80c0f1291812d29a..7889c927cb10d0eb66d14bc422d4ba4d8436d5e8 100644 --- a/setup.py +++ b/setup.py @@ -98,6 +98,7 @@ src_file_list = ['full_code/NSVEcomplex_particles', 'full_code/test_interpolation', 'hdf5_tools', 'full_code/get_rfields', + 'full_code/field_single_to_double', 'full_code/resize', 'full_code/NSVE_field_stats', 'full_code/native_binary_to_hdf5',