From ce1a45da0644e77048ae4f8999b8d98a0789a32c Mon Sep 17 00:00:00 2001 From: Cristian C Lalescu <Cristian.Lalescu@ds.mpg.de> Date: Tue, 14 Nov 2017 16:51:02 +0100 Subject: [PATCH] add resize cpp files --- bfps/cpp/full_code/resize.cpp | 74 +++++++++++++++++++++++++++++++++++ bfps/cpp/full_code/resize.hpp | 67 +++++++++++++++++++++++++++++++ setup.py | 1 + 3 files changed, 142 insertions(+) create mode 100644 bfps/cpp/full_code/resize.cpp create mode 100644 bfps/cpp/full_code/resize.hpp diff --git a/bfps/cpp/full_code/resize.cpp b/bfps/cpp/full_code/resize.cpp new file mode 100644 index 00000000..87a45c03 --- /dev/null +++ b/bfps/cpp/full_code/resize.cpp @@ -0,0 +1,74 @@ +#include <string> +#include <cmath> +#include "resize.hpp" +#include "scope_timer.hpp" + + +template <typename rnumber> +int resize<rnumber>::initialize(void) +{ + this->NSVE_field_stats<rnumber>::initialize(); + DEBUG_MSG("after NSVE_field_stats::initialize\n"); + hid_t parameter_file = H5Fopen( + (this->simname + std::string(".h5")).c_str(), + H5F_ACC_RDONLY, + H5P_DEFAULT); + + this->niter_out = hdf5_tools::read_value<int>( + parameter_file, "/parameters/niter_out"); + 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, + "/resize/parameters/iteration_list"); + + this->new_nx = hdf5_tools::read_value<int>( + parameter_file, "/resize/parameters/new_nx"); + this->new_ny = hdf5_tools::read_value<int>( + parameter_file, "/resize/parameters/new_ny"); + this->new_nz = hdf5_tools::read_value<int>( + parameter_file, "/resize/parameters/new_nz"); + this->new_simname = hdf5_tools::read_string( + parameter_file, "/resize/parameters/new_simname"); + H5Fclose(parameter_file); + + this->new_field = new field<rnumber, FFTW, THREE>( + this->new_nx, this->new_ny, this->new_nz, + this->comm, + this->vorticity->fftw_plan_rigor); + return EXIT_SUCCESS; +} + +template <typename rnumber> +int resize<rnumber>::work_on_current_iteration(void) +{ + DEBUG_MSG("entered resize::work_on_current_iteration\n"); + this->read_current_cvorticity(); + + std::string fname = ( + this->new_simname + + std::string("_fields.h5")); + this->new_field = this->vorticity; + this->new_field->io( + fname, + "vorticity", + this->iteration, + false); + return EXIT_SUCCESS; +} + +template <typename rnumber> +int resize<rnumber>::finalize(void) +{ + delete this->new_field; + this->NSVE_field_stats<rnumber>::finalize(); + return EXIT_SUCCESS; +} + +template class resize<float>; +template class resize<double>; + diff --git a/bfps/cpp/full_code/resize.hpp b/bfps/cpp/full_code/resize.hpp new file mode 100644 index 00000000..de227c88 --- /dev/null +++ b/bfps/cpp/full_code/resize.hpp @@ -0,0 +1,67 @@ +/********************************************************************** +* * +* 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 RESIZE_HPP +#define RESIZE_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 resize: public NSVE_field_stats<rnumber> +{ + public: + std::string new_simname; + + int new_nx; + int new_ny; + int new_nz; + + int niter_out; + + field<rnumber, FFTW, THREE> *new_field; + + resize( + const MPI_Comm COMMUNICATOR, + const std::string &simulation_name): + NSVE_field_stats<rnumber>( + COMMUNICATOR, + simulation_name){} + virtual ~resize(){} + + int initialize(void); + int work_on_current_iteration(void); + int finalize(void); +}; + +#endif//RESIZE_HPP + diff --git a/setup.py b/setup.py index b03bd4f4..d837670f 100644 --- a/setup.py +++ b/setup.py @@ -94,6 +94,7 @@ src_file_list = ['full_code/joint_acc_vel_stats', 'full_code/field_test', 'hdf5_tools', 'full_code/get_rfields', + 'full_code/resize', 'full_code/NSVE_field_stats', 'full_code/native_binary_to_hdf5', 'full_code/postprocess', -- GitLab