Skip to content
Snippets Groups Projects
Commit 134dd810 authored by Chichi Lalescu's avatar Chichi Lalescu
Browse files

add preliminary field test

parent 0ce7d47f
No related branches found
No related tags found
1 merge request!23WIP: Feature/use cmake
Pipeline #
...@@ -257,6 +257,12 @@ class TEST(_code): ...@@ -257,6 +257,12 @@ class TEST(_code):
self.simulation_parser_arguments(parser_filter_test) self.simulation_parser_arguments(parser_filter_test)
self.job_parser_arguments(parser_filter_test) self.job_parser_arguments(parser_filter_test)
self.parameters_to_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 return None
def prepare_launch( def prepare_launch(
self, self,
......
#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>;
/**********************************************************************
* *
* 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
...@@ -14,7 +14,7 @@ int test::main_loop(void) ...@@ -14,7 +14,7 @@ int test::main_loop(void)
this->start_simple_timer(); this->start_simple_timer();
this->do_work(); this->do_work();
this->print_simple_timer( this->print_simple_timer(
"do_work required " + std::to_string(this->iteration)); "do_work required ");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
......
...@@ -91,6 +91,7 @@ print('This is bfps version ' + VERSION) ...@@ -91,6 +91,7 @@ print('This is bfps version ' + VERSION)
src_file_list = ['full_code/joint_acc_vel_stats', src_file_list = ['full_code/joint_acc_vel_stats',
'full_code/test', 'full_code/test',
'full_code/filter_test', 'full_code/filter_test',
'full_code/field_test',
'hdf5_tools', 'hdf5_tools',
'full_code/get_rfields', 'full_code/get_rfields',
'full_code/NSVE_field_stats', 'full_code/NSVE_field_stats',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment