diff --git a/bfps/TEST.py b/bfps/TEST.py index 5f5734030344f15c7b23d7849fede80105e11fc6..f7e8e24e0cbcff53ec586173ae80f5507210eceb 100644 --- a/bfps/TEST.py +++ b/bfps/TEST.py @@ -257,6 +257,12 @@ class TEST(_code): self.simulation_parser_arguments(parser_filter_test) self.job_parser_arguments(parser_filter_test) self.parameters_to_parser_arguments(parser_filter_test) + parser_field_test = subparsers.add_parser( + 'field_test', + help = 'plain field test') + self.simulation_parser_arguments(parser_field_test) + self.job_parser_arguments(parser_field_test) + self.parameters_to_parser_arguments(parser_field_test) return None def prepare_launch( self, diff --git a/bfps/cpp/full_code/field_test.cpp b/bfps/cpp/full_code/field_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..acee36172a41e6e9e540f981ff979988183acff7 --- /dev/null +++ b/bfps/cpp/full_code/field_test.cpp @@ -0,0 +1,105 @@ +#include <string> +#include <cmath> +#include <random> +#include "field_test.hpp" +#include "scope_timer.hpp" + + +template <typename rnumber> +int field_test<rnumber>::initialize(void) +{ + this->read_parameters(); + return EXIT_SUCCESS; +} + +template <typename rnumber> +int field_test<rnumber>::finalize(void) +{ + return EXIT_SUCCESS; +} + +template <typename rnumber> +int field_test<rnumber>::read_parameters() +{ + this->test::read_parameters(); + // in case any parameters are needed, this is where they should be read + hid_t parameter_file; + hid_t dset, memtype, space; + parameter_file = H5Fopen( + (this->simname + std::string(".h5")).c_str(), + H5F_ACC_RDONLY, + H5P_DEFAULT); + dset = H5Dopen(parameter_file, "/parameters/filter_length", H5P_DEFAULT); + H5Dread(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &this->filter_length); + H5Dclose(dset); + H5Fclose(parameter_file); + return EXIT_SUCCESS; +} + +template <typename rnumber> +int field_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); + field<rnumber, FFTW, ONE> *scal_field_alt = 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); + //auto gaussian = std::bind(rgen, rdist); + kspace<FFTW,SMOOTH> *kk = new kspace<FFTW, SMOOTH>( + scal_field->clayout, this->dkx, this->dky, this->dkz); + + if (this->myrank == 0) + { + hid_t stat_file = H5Fopen( + (this->simname + std::string(".h5")).c_str(), + H5F_ACC_RDWR, + H5P_DEFAULT); + kk->store(stat_file); + H5Fclose(stat_file); + } + + // 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_alt = scal_field->get_rdata(); + scal_field->dft(); + scal_field->ift(); + scal_field->normalize(); + + double max_error = 0; + scal_field->RLOOP( + [&](ptrdiff_t rindex, + ptrdiff_t xindex, + ptrdiff_t yindex, + ptrdiff_t zindex){ + double tval = fabs(scal_field->rval(rindex) - scal_field_alt->rval(rindex)); + if (max_error < tval) + max_error = tval; + }); + + DEBUG_MSG("maximum error is %g\n", max_error); + + // deallocate + delete kk; + delete scal_field; + delete scal_field_alt; + return EXIT_SUCCESS; +} + +template class field_test<float>; +template class field_test<double>; + diff --git a/bfps/cpp/full_code/field_test.hpp b/bfps/cpp/full_code/field_test.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5339feb80ae690170f52935e97cd700e958a48a4 --- /dev/null +++ b/bfps/cpp/full_code/field_test.hpp @@ -0,0 +1,63 @@ +/********************************************************************** +* * +* 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_TEST_HPP +#define FILTER_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_test: public test +{ + public: + double filter_length; + // kspace, in case we want to compute spectra or smth + + field_test( + const MPI_Comm COMMUNICATOR, + const std::string &simulation_name): + test( + COMMUNICATOR, + simulation_name){} + ~field_test(){} + + int initialize(void); + int do_work(void); + int finalize(void); + int read_parameters(void); +}; + +#endif//FILTER_TEST_HPP + diff --git a/bfps/cpp/full_code/test.cpp b/bfps/cpp/full_code/test.cpp index 4f7a402c44c2a2999975881929c2582107897c5c..fd2192a0817bc0351a3103a838189a46a61cb080 100644 --- a/bfps/cpp/full_code/test.cpp +++ b/bfps/cpp/full_code/test.cpp @@ -14,7 +14,7 @@ int test::main_loop(void) this->start_simple_timer(); this->do_work(); this->print_simple_timer( - "do_work required " + std::to_string(this->iteration)); + "do_work required "); return EXIT_SUCCESS; } diff --git a/setup.py b/setup.py index 9bba17014aabf36c685395843b806f650604face..b03bd4f4268cdaac9e16bdb3fe68384aae7958a3 100644 --- a/setup.py +++ b/setup.py @@ -91,6 +91,7 @@ print('This is bfps version ' + VERSION) src_file_list = ['full_code/joint_acc_vel_stats', 'full_code/test', 'full_code/filter_test', + 'full_code/field_test', 'hdf5_tools', 'full_code/get_rfields', 'full_code/NSVE_field_stats',