From 89a5e91521b38b64cb51ea8acf7b8fb41da74137 Mon Sep 17 00:00:00 2001 From: Chichi Lalescu <chichilalescu@gmail.com> Date: Sat, 8 Sep 2018 21:52:03 +0200 Subject: [PATCH] partial move read_parameters to cpp files NSVEparticles test works. --- bfps/DNS.py | 20 ------------- bfps/cpp/full_code/NSVE.cpp | 22 ++++++++++++++ bfps/cpp/full_code/NSVEparticles.cpp | 14 +++++++++ bfps/cpp/full_code/code_base.cpp | 14 +++++++++ bfps/cpp/full_code/code_base.hpp | 1 + .../full_code/direct_numerical_simulation.cpp | 11 +++++++ .../full_code/direct_numerical_simulation.hpp | 1 + setup.py | 29 +++++++------------ 8 files changed, 74 insertions(+), 38 deletions(-) diff --git a/bfps/DNS.py b/bfps/DNS.py index c7d77956..e6ef006a 100644 --- a/bfps/DNS.py +++ b/bfps/DNS.py @@ -116,26 +116,6 @@ class DNS(_code): with open(self.name + '.cpp', 'w') as outfile: outfile.write(self.version_message + '\n\n') outfile.write(self.includes + '\n\n') - outfile.write( - self.cread_pars( - template_class = '{0}<rnumber>::'.format(self.dns_type), - template_prefix = 'template <typename rnumber> ', - simname_variable = 'this->simname.c_str()', - prepend_this = True) + - '\n\n') - for rnumber in ['float', 'double']: - outfile.write(self.cread_pars( - template_class = '{0}<{1}>::'.format(self.dns_type, rnumber), - template_prefix = 'template '.format(rnumber), - just_declaration = True) + '\n\n') - if self.dns_type in ['NSVEparticles', 'NSVE_no_output', 'NSVEparticles_no_output', 'NSVEcomplex_particles', 'NSVEp_extra_sampling']: - outfile.write('template <typename rnumber> int NSVE<rnumber>::read_parameters(){return EXIT_SUCCESS;}\n') - outfile.write('template int NSVE<float>::read_parameters();\n') - outfile.write('template int NSVE<double>::read_parameters();\n\n') - if self.dns_type in ['NSVEparticles_no_output', 'NSVEp_extra_sampling']: - outfile.write('template <typename rnumber> int NSVEparticles<rnumber>::read_parameters(){return EXIT_SUCCESS;}\n') - outfile.write('template int NSVEparticles<float>::read_parameters();\n') - outfile.write('template int NSVEparticles<double>::read_parameters();\n\n') outfile.write(self.main + '\n') return None def generate_default_parameters(self): diff --git a/bfps/cpp/full_code/NSVE.cpp b/bfps/cpp/full_code/NSVE.cpp index e8bf9fd2..ce0a9544 100644 --- a/bfps/cpp/full_code/NSVE.cpp +++ b/bfps/cpp/full_code/NSVE.cpp @@ -137,6 +137,28 @@ int NSVE<rnumber>::do_stats() return EXIT_SUCCESS; } +template <typename rnumber> +int NSVE<rnumber>::read_parameters(void) +{ + this->direct_numerical_simulation::read_parameters(); + hid_t parameter_file = H5Fopen((this->simname + ".h5").c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); + this->nu = hdf5_tools::read_value<double>(parameter_file, "parameters/nu"); + this->dt = hdf5_tools::read_value<double>(parameter_file, "parameters/dt"); + this->fmode = hdf5_tools::read_value<int>(parameter_file, "parameters/fmode"); + this->famplitude = hdf5_tools::read_value<double>(parameter_file, "parameters/famplitude"); + this->friction_coefficient = hdf5_tools::read_value<double>(parameter_file, "parameters/friction_coefficient"); + this->fk0 = hdf5_tools::read_value<double>(parameter_file, "parameters/fk0"); + this->fk1 = hdf5_tools::read_value<double>(parameter_file, "parameters/fk1"); + this->energy = hdf5_tools::read_value<double>(parameter_file, "parameters/energy"); + this->histogram_bins = hdf5_tools::read_value<int>(parameter_file, "parameters/histogram_bins"); + this->max_velocity_estimate = hdf5_tools::read_value<double>(parameter_file, "parameters/max_velocity_estimate"); + this->max_vorticity_estimate = hdf5_tools::read_value<double>(parameter_file, "parameters/max_vorticity_estimate"); + std::string tmp = hdf5_tools::read_string(parameter_file, "parameters/forcing_type"); + snprintf(this->forcing_type, 511, "%s", tmp.c_str()); + H5Fclose(parameter_file); + return EXIT_SUCCESS; +} + template class NSVE<float>; template class NSVE<double>; diff --git a/bfps/cpp/full_code/NSVEparticles.cpp b/bfps/cpp/full_code/NSVEparticles.cpp index bbdd96c3..78f3d6a0 100644 --- a/bfps/cpp/full_code/NSVEparticles.cpp +++ b/bfps/cpp/full_code/NSVEparticles.cpp @@ -142,6 +142,20 @@ int NSVEparticles<rnumber>::do_stats() return EXIT_SUCCESS; } +template <typename rnumber> +int NSVEparticles<rnumber>::read_parameters(void) +{ + this->NSVE<rnumber>::read_parameters(); + hid_t parameter_file = H5Fopen((this->simname + ".h5").c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); + this->niter_part = hdf5_tools::read_value<int>(parameter_file, "parameters/niter_part"); + this->nparticles = hdf5_tools::read_value<int>(parameter_file, "parameters/nparticles"); + this->tracers0_integration_steps = hdf5_tools::read_value<int>(parameter_file, "parameters/tracers0_integration_steps"); + this->tracers0_neighbours = hdf5_tools::read_value<int>(parameter_file, "parameters/tracers0_neighbours"); + this->tracers0_smoothness = hdf5_tools::read_value<int>(parameter_file, "parameters/tracers0_smoothness"); + H5Fclose(parameter_file); + return EXIT_SUCCESS; +} + template class NSVEparticles<float>; template class NSVEparticles<double>; diff --git a/bfps/cpp/full_code/code_base.cpp b/bfps/cpp/full_code/code_base.cpp index 1b06fe8e..32fe9c1c 100644 --- a/bfps/cpp/full_code/code_base.cpp +++ b/bfps/cpp/full_code/code_base.cpp @@ -34,3 +34,17 @@ int code_base::check_stopping_condition(void) return EXIT_SUCCESS; } +int code_base::read_parameters(void) +{ + hid_t parameter_file = H5Fopen((this->simname + ".h5").c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); + this->dkx = hdf5_tools::read_value<double>(parameter_file, "parameters/dkx"); + this->dky = hdf5_tools::read_value<double>(parameter_file, "parameters/dky"); + this->dkz = hdf5_tools::read_value<double>(parameter_file, "parameters/dkz"); + this->nx = hdf5_tools::read_value<int>(parameter_file, "parameters/nx"); + this->ny = hdf5_tools::read_value<int>(parameter_file, "parameters/ny"); + this->nz = hdf5_tools::read_value<int>(parameter_file, "parameters/nz"); + this->dealias_type = hdf5_tools::read_value<int>(parameter_file, "parameters/dealias_type"); + H5Fclose(parameter_file); + return EXIT_SUCCESS; +} + diff --git a/bfps/cpp/full_code/code_base.hpp b/bfps/cpp/full_code/code_base.hpp index cf0521e2..5ec4260d 100644 --- a/bfps/cpp/full_code/code_base.hpp +++ b/bfps/cpp/full_code/code_base.hpp @@ -108,6 +108,7 @@ class code_base return EXIT_SUCCESS; } + virtual int read_parameters(void); virtual int initialize(void) = 0; virtual int main_loop(void) = 0; virtual int finalize(void) = 0; diff --git a/bfps/cpp/full_code/direct_numerical_simulation.cpp b/bfps/cpp/full_code/direct_numerical_simulation.cpp index edc2f994..f763cde9 100644 --- a/bfps/cpp/full_code/direct_numerical_simulation.cpp +++ b/bfps/cpp/full_code/direct_numerical_simulation.cpp @@ -117,3 +117,14 @@ int direct_numerical_simulation::main_loop(void) return EXIT_SUCCESS; } +int direct_numerical_simulation::read_parameters(void) +{ + this->code_base::read_parameters(); + hid_t parameter_file = H5Fopen((this->simname + ".h5").c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); + this->checkpoints_per_file = hdf5_tools::read_value<int>(parameter_file, "parameters/checkpoints_per_file"); + this->niter_out = hdf5_tools::read_value<int>(parameter_file, "parameters/niter_out"); + this->niter_stat = hdf5_tools::read_value<int>(parameter_file, "parameters/niter_stat"); + this->niter_todo = hdf5_tools::read_value<int>(parameter_file, "parameters/niter_todo"); + H5Fclose(parameter_file); + return EXIT_SUCCESS; +} diff --git a/bfps/cpp/full_code/direct_numerical_simulation.hpp b/bfps/cpp/full_code/direct_numerical_simulation.hpp index 8050bb04..15ab698a 100644 --- a/bfps/cpp/full_code/direct_numerical_simulation.hpp +++ b/bfps/cpp/full_code/direct_numerical_simulation.hpp @@ -51,6 +51,7 @@ class direct_numerical_simulation: public code_base simulation_name){} virtual ~direct_numerical_simulation(){} + virtual int read_parameters(void); virtual int write_checkpoint(void) = 0; virtual int initialize(void) = 0; virtual int step(void) = 0; diff --git a/setup.py b/setup.py index 7889c927..b427ebe7 100644 --- a/setup.py +++ b/setup.py @@ -88,40 +88,29 @@ print('This is bfps version ' + VERSION) ### lists of files and MANIFEST.in -src_file_list = ['full_code/NSVEcomplex_particles', +src_file_list = [ + 'full_code/code_base', + 'full_code/direct_numerical_simulation', + 'full_code/NSVE', 'full_code/joint_acc_vel_stats', 'full_code/test', 'full_code/filter_test', 'full_code/field_test', 'full_code/symmetrize_test', 'full_code/field_output_test', - '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', 'full_code/postprocess', - 'full_code/code_base', - 'full_code/direct_numerical_simulation', - 'full_code/NSVE', - 'field_binary_IO', - 'vorticity_equation', 'field', 'kspace', 'field_layout', - 'field_descriptor', - 'rFFTW_distributed_particles', - 'distributed_particles', - 'particles', - 'particles_base', - 'rFFTW_interpolator', - 'interpolator', - 'interpolator_base', - 'fluid_solver', - 'fluid_solver_base', + 'hdf5_tools', 'fftw_tools', + 'vorticity_equation', + 'field_binary_IO', 'spline_n1', 'spline_n2', 'spline_n3', @@ -134,7 +123,11 @@ src_file_list = ['full_code/NSVEcomplex_particles', 'spline_n10', 'Lagrange_polys', 'scope_timer', + 'interpolator', + 'interpolator_base', + 'full_code/test_interpolation', 'full_code/NSVEparticles', + 'full_code/NSVEcomplex_particles', 'full_code/NSVEp_extra_sampling'] particle_headers = [ -- GitLab