diff --git a/bfps/_base.py b/bfps/_base.py index 1a112baa3775842f013640596768ad0597eaa187..8f7aeaaf1183f27535498565d14eec31b5b58569 100644 --- a/bfps/_base.py +++ b/bfps/_base.py @@ -74,11 +74,16 @@ class _base(object): self, parameters = None, function_suffix = '', + template_class = '', + template_prefix = '', file_group = 'parameters'): if type(parameters) == type(None): parameters = self.parameters key = sorted(list(parameters.keys())) - src_txt = ('int read_parameters' + function_suffix + '()\n{\n' + + src_txt = (template_prefix + + 'int ' + + template_class + + 'read_parameters' + function_suffix + '()\n{\n' + 'hid_t parameter_file;\n' + 'hid_t dset, memtype, space;\n' + 'char fname[256];\n' + diff --git a/bfps/cpp/full_code/NSVE.cpp b/bfps/cpp/full_code/NSVE.cpp index 826bf0e3d3d9875a727048b6432b92dedd23cd4f..d9332589fdcdda8241ae656386cfb3b64d5b8aa2 100644 --- a/bfps/cpp/full_code/NSVE.cpp +++ b/bfps/cpp/full_code/NSVE.cpp @@ -2,6 +2,36 @@ #include <cmath> #include "NSVE.hpp" +int grow_single_dataset(hid_t dset, int tincrement) +{ + int ndims; + hsize_t space; + space = H5Dget_space(dset); + ndims = H5Sget_simple_extent_ndims(space); + hsize_t *dims = new hsize_t[ndims]; + H5Sget_simple_extent_dims(space, dims, NULL); + dims[0] += tincrement; + H5Dset_extent(dset, dims); + H5Sclose(space); + delete[] dims; + return EXIT_SUCCESS; +} + +herr_t grow_dataset_visitor( + hid_t o_id, + const char *name, + const H5O_info_t *info, + void *op_data) +{ + if (info->type == H5O_TYPE_DATASET) + { + hsize_t dset = H5Dopen(o_id, name, H5P_DEFAULT); + grow_single_dataset(dset, *((int*)(op_data))); + H5Dclose(dset); + } + return EXIT_SUCCESS; +} + template <typename rnumber> int NSVE<rnumber>::read_iteration(void) { diff --git a/bfps/cpp/full_code/NSVE.hpp b/bfps/cpp/full_code/NSVE.hpp index 137f6838cf61b5a12b3b28bd5d87329196016e66..4d55cec051db5b0e3e17faedd7a935ce311bb4c5 100644 --- a/bfps/cpp/full_code/NSVE.hpp +++ b/bfps/cpp/full_code/NSVE.hpp @@ -34,35 +34,13 @@ #include "vorticity_equation.hpp" #include "full_code/direct_numerical_simulation.hpp" -int grow_single_dataset(hid_t dset, int tincrement) -{ - int ndims; - hsize_t space; - space = H5Dget_space(dset); - ndims = H5Sget_simple_extent_ndims(space); - hsize_t *dims = new hsize_t[ndims]; - H5Sget_simple_extent_dims(space, dims, NULL); - dims[0] += tincrement; - H5Dset_extent(dset, dims); - H5Sclose(space); - delete[] dims; - return EXIT_SUCCESS; -} +int grow_single_dataset(hid_t dset, int tincrement); herr_t grow_dataset_visitor( hid_t o_id, const char *name, const H5O_info_t *info, - void *op_data) -{ - if (info->type == H5O_TYPE_DATASET) - { - hsize_t dset = H5Dopen(o_id, name, H5P_DEFAULT); - grow_single_dataset(dset, *((int*)(op_data))); - H5Dclose(dset); - } - return EXIT_SUCCESS; -} + void *op_data); template <typename rnumber> class NSVE: public direct_numerical_simulation diff --git a/bfps/cpp/full_code/main_code.hpp b/bfps/cpp/full_code/main_code.hpp index 14029f4a85e7be47f097e4a3136a49d7cf5e8f06..06a684303d63ba3ecff6c2259082630787a1188f 100644 --- a/bfps/cpp/full_code/main_code.hpp +++ b/bfps/cpp/full_code/main_code.hpp @@ -28,26 +28,41 @@ #define MAIN_CODE_HPP + +#include <cfenv> +#include <string> +#include <iostream> #include "base.hpp" #include "field.hpp" #include "scope_timer.hpp" +int myrank, nprocs; + template <class DNS> -main_code( - const std::string &simname, +int main_code( + int argc, + char *argv[], const bool floating_point_exceptions) { /* floating point exception switch */ - if (this->floating_point_exceptions) + if (floating_point_exceptions) feenableexcept(FE_INVALID | FE_OVERFLOW); else // using std::cerr because DEBUG_MSG requires myrank to be defined - std::cerr << ("FPE have been turned OFF" << std::endl; + std::cerr << "FPE have been turned OFF" << std::endl; + if (argc != 2) + { + std::cerr << + "Wrong number of command line arguments. Stopping." << + std::endl; + MPI_Finalize(); + return EXIT_SUCCESS; + } + std::string simname = std::string(argv[1]); /* initialize MPI environment */ - int myrank, nprocs; #ifdef NO_FFTWOMP MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myrank); @@ -83,11 +98,8 @@ main_code( /* import fftw wisdom */ if (myrank == 0) - { - char fname[256]; - sprintf(fname, "%s_fftw_wisdom.txt", simname.c_str()); - fftwf_import_wisdom_from_filename(fname); - } + fftwf_import_wisdom_from_filename( + (simname + std::string("_fftw_wisdom.txt")).c_str()); fftwf_mpi_broadcast_wisdom(MPI_COMM_WORLD); @@ -105,7 +117,7 @@ main_code( * recover from should not be important enough to not clean up fftw and MPI * things. */ - DNS *dns( + DNS *dns = new DNS( MPI_COMM_WORLD, simname); int return_value; @@ -124,17 +136,16 @@ main_code( DEBUG_MSG("problem calling dns->finalize(), return value is %d", return_value); + delete dns; + /* export fftw wisdom */ fftwf_mpi_gather_wisdom(MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); if (myrank == 0) - { - char fname[256]; - sprintf(fname, "%s_fftw_wisdom.txt", simname); - fftwf_export_wisdom_to_filename(fname); - } + fftwf_export_wisdom_to_filename( + (simname + std::string("_fftw_wisdom.txt")).c_str()); @@ -142,7 +153,7 @@ main_code( fftwf_mpi_cleanup(); fftw_mpi_cleanup(); #ifndef NO_FFTWOMP - if (nbThreads > 1){ + if (nThreads > 1){ fftw_cleanup_threads(); fftwf_cleanup_threads(); } diff --git a/tests/test_DNS.py b/tests/test_DNS.py new file mode 100644 index 0000000000000000000000000000000000000000..3ff6596330e2192bb919dd9611baff03f56fd473 --- /dev/null +++ b/tests/test_DNS.py @@ -0,0 +1,12 @@ +from bfps.DNS import DNS + + +def main(): + c = DNS() + c.write_src() + c.compile_code() + return None + +if __name__ == '__main__': + main() +