diff --git a/bfps/cpp/field.cpp b/bfps/cpp/field.cpp new file mode 100644 index 0000000000000000000000000000000000000000..52940de915ce91298c81a0fb2a33e605fb7ad77d --- /dev/null +++ b/bfps/cpp/field.cpp @@ -0,0 +1,110 @@ +/********************************************************************** +* * +* Copyright 2015 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 * +* * +**********************************************************************/ + + +#include "field.hpp" + +template <class number, + field_backend be, + field_components fc> +field_container<number, be, fc>::field_container( + int nx, int ny, int nz, + MPI_Comm COMM_TO_USE) +{ + this->comm = COMM_TO_USE; + MPI_Comm_rank(this->comm, &this->myrank); + MPI_Comm_size(this->comm, &this->nprocs); + + if (be == FFTW) + { + ptrdiff_t nfftw[3]; + nfftw[0] = nz; + nfftw[1] = ny; + nfftw[2] = nx; + this->local_size = fftw_mpi_local_size_many( + 3, + nfftw, + ncomp(fc), + FFTW_MPI_DEFAULT_BLOCK, + this->comm, + this->subsizes, + this->starts); + } + this->sizes[0] = nz; + this->sizes[1] = ny; + this->sizes[2] = nx; + if (fc == THREE || fc == THREExTHREE) + this->sizes[3] = 3; + if (fc == THREExTHREE) + this->sizes[4] = 3; + if (be == FFTW) + { + for (int i=1; i<ndim(fc); i++) + { + this->subsizes[i] = this->sizes[i]; + this->starts[i] = 0; + } + } +} + +template <class number, + field_backend be, + field_components fc> +field_container<number, be, fc>::~field_container() +{} + +template <class number, + field_backend be, + field_components fc> +int field_container<number, be, fc>::read( + const char *fname, + const char *dset_name, + int iteration) +{ + return EXIT_SUCCESS; +} + +template <class number, + field_backend be, + field_components fc> +int field_container<number, be, fc>::write( + const char *fname, + const char *dset_name, + int iteration) +{ + return EXIT_SUCCESS; +} + +//template <class rnum, +// field_representation repr, +// field_backend be, +// field_components fc> +//field::field( +// int *n, +// MPI_Comm COMM_TO_USE) +//{} +// +//field::~field() +//{} + diff --git a/bfps/cpp/field.hpp b/bfps/cpp/field.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1988a39e0a3575671bf06b55b0b8b0529274f08f --- /dev/null +++ b/bfps/cpp/field.hpp @@ -0,0 +1,112 @@ +/********************************************************************** +* * +* Copyright 2015 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 * +* * +**********************************************************************/ + + + +#include <mpi.h> +#include <hdf5.h> +#include <fftw3-mpi.h> +#include <vector> + +#ifndef FIELD + +#define FIELD + +enum field_representation {REAL, COMPLEX, BOTH}; +enum field_backend {FFTW}; +enum field_components {ONE, THREE, THREExTHREE}; + +constexpr unsigned int ncomp( + field_components fc) + /* return actual number of field components for each enum value */ +{ + return ((fc == THREE) ? 3 : ( + (fc == THREExTHREE) ? 9 : 1)); +} + +constexpr unsigned int ndim( + field_components fc) + /* return actual number of field dimensions for each enum value */ +{ + return ((fc == THREE) ? 4 : ( + (fc == THREExTHREE) ? 5 : 3)); +} + +template <class number, + field_backend be, + field_components fc> +class field_container +{ + public: + /* description */ + hsize_t sizes[ndim(fc)]; + hsize_t subsizes[ndim(fc)]; + hsize_t starts[ndim(fc)]; + ptrdiff_t slice_size, local_size, full_size; + + int myrank, nprocs; + MPI_Comm comm; + + std::vector<int> rank; + std::vector<std::vector<int>> all_start; + std::vector<std::vector<int>> all_size; + + number *data; + + /* methods */ + field_container( + int nx, int ny, int nz, + MPI_Comm COMM_TO_USE); + ~field_container(); + + int read( + const char *fname, + const char *dset_name, + int iteration); + + int write( + const char *fname, + const char *dset_name, + int iteration); +}; + +//template <class rnum, +// field_representation repr, +// field_backend be, +// field_components fc> +//class field +//{ +// public: +// +// field_container< *kdata, *rdata; +// +// /* methods */ +// field( +// int *n, +// MPI_Comm COMM_TO_USE); +// ~field(); +//}; + +#endif//FIELD + diff --git a/setup.py b/setup.py index 2075b690e7676e097e6e9b17e7352a652e7415f9..b324575816befe78e7892a6961f84cbe62bf62b8 100644 --- a/setup.py +++ b/setup.py @@ -88,7 +88,8 @@ print('This is bfps version ' + VERSION) ### lists of files and MANIFEST.in -src_file_list = ['field_descriptor', +src_file_list = ['field', + 'field_descriptor', 'rFFTW_distributed_particles', 'distributed_particles', 'particles',