From 3291590d1a1cf8a47a48d2343a0839d6d0554a8a Mon Sep 17 00:00:00 2001 From: Chichi Lalescu <chichilalescu@gmail.com> Date: Tue, 27 Mar 2018 22:24:41 +0200 Subject: [PATCH] add field output test --- bfps/TEST.py | 6 +++ bfps/cpp/full_code/field_output_test.cpp | 63 ++++++++++++++++++++++++ bfps/cpp/full_code/field_output_test.hpp | 60 ++++++++++++++++++++++ setup.py | 1 + 4 files changed, 130 insertions(+) create mode 100644 bfps/cpp/full_code/field_output_test.cpp create mode 100644 bfps/cpp/full_code/field_output_test.hpp diff --git a/bfps/TEST.py b/bfps/TEST.py index f7e8e24e..43b2d813 100644 --- a/bfps/TEST.py +++ b/bfps/TEST.py @@ -263,6 +263,12 @@ class TEST(_code): self.simulation_parser_arguments(parser_field_test) self.job_parser_arguments(parser_field_test) self.parameters_to_parser_arguments(parser_field_test) + parser_field_output_test = subparsers.add_parser( + 'field_output_test', + help = 'plain field output test') + self.simulation_parser_arguments(parser_field_output_test) + self.job_parser_arguments(parser_field_output_test) + self.parameters_to_parser_arguments(parser_field_output_test) return None def prepare_launch( self, diff --git a/bfps/cpp/full_code/field_output_test.cpp b/bfps/cpp/full_code/field_output_test.cpp new file mode 100644 index 00000000..f5440064 --- /dev/null +++ b/bfps/cpp/full_code/field_output_test.cpp @@ -0,0 +1,63 @@ +#include <string> +#include <cmath> +#include <random> +#include "field_output_test.hpp" +#include "scope_timer.hpp" + + +template <typename rnumber> +int field_output_test<rnumber>::initialize(void) +{ + this->read_parameters(); + return EXIT_SUCCESS; +} + +template <typename rnumber> +int field_output_test<rnumber>::finalize(void) +{ + return EXIT_SUCCESS; +} + +template <typename rnumber> +int field_output_test<rnumber>::read_parameters() +{ + this->test::read_parameters(); + return EXIT_SUCCESS; +} + +template <typename rnumber> +int field_output_test<rnumber>::do_work(void) +{ + // allocate + field<rnumber, FFTW, ONE> *scal_field = new field<rnumber, FFTW, ONE>( + this->nx, this->ny, this->nz, + this->comm, + DEFAULT_FFTW_FLAG); + std::default_random_engine rgen; + std::normal_distribution<rnumber> rdist; + rgen.seed(1); + + // fill up scal_field + scal_field->real_space_representation = true; + scal_field->RLOOP( + [&](ptrdiff_t rindex, + ptrdiff_t xindex, + ptrdiff_t yindex, + ptrdiff_t zindex){ + scal_field->rval(rindex) = rdist(rgen); + }); + + scal_field->io( + this->simname + std::string("_fields.h5"), + "scal_field", + 0, + false); + + // deallocate + delete scal_field; + return EXIT_SUCCESS; +} + +template class field_output_test<float>; +template class field_output_test<double>; + diff --git a/bfps/cpp/full_code/field_output_test.hpp b/bfps/cpp/full_code/field_output_test.hpp new file mode 100644 index 00000000..3662e4b1 --- /dev/null +++ b/bfps/cpp/full_code/field_output_test.hpp @@ -0,0 +1,60 @@ +/********************************************************************** +* * +* 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 FILTER_OUTPUT_TEST_HPP +#define FILTER_OUTPUT_TEST_HPP + + + +#include <cstdlib> +#include "base.hpp" +#include "kspace.hpp" +#include "field.hpp" +#include "full_code/test.hpp" + +/** \brief A class for testing basic field class functionality. + */ + +template <typename rnumber> +class field_output_test: public test +{ + public: + field_output_test( + const MPI_Comm COMMUNICATOR, + const std::string &simulation_name): + test( + COMMUNICATOR, + simulation_name){} + ~field_output_test(){} + + int initialize(void); + int do_work(void); + int finalize(void); + int read_parameters(void); +}; + +#endif//FILTER_OUTPUT_TEST_HPP + diff --git a/setup.py b/setup.py index ff73b945..9511a92d 100644 --- a/setup.py +++ b/setup.py @@ -93,6 +93,7 @@ src_file_list = ['full_code/NSVEcomplex_particles', 'full_code/test', 'full_code/filter_test', 'full_code/field_test', + 'full_code/field_output_test', 'hdf5_tools', 'full_code/get_rfields', 'full_code/resize', -- GitLab