diff --git a/src/cell/cell_factory.hh b/src/cell/cell_factory.hh index 9d6d450..3ee48cd 100644 --- a/src/cell/cell_factory.hh +++ b/src/cell/cell_factory.hh @@ -1,96 +1,159 @@ /** * @file cell_factory.hh * * @author Till Junge * * @date 15 Dec 2017 * * @brief Cell factories to help create cells with ease * * Copyright © 2017 Till Junge * * µSpectre 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, or (at * your option) any later version. * * µSpectre 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 GNU Emacs; see the file COPYING. If not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #ifndef CELL_FACTORY_H #define CELL_FACTORY_H #include "common/common.hh" #include "common/ccoord_operations.hh" #include "cell/cell_base.hh" #include "fft/projection_finite_strain_fast.hh" #include "fft/projection_small_strain.hh" #include "fft/fftw_engine.hh" +#ifdef HAVE_MPI +#include "common/communicator.h" +#include "fft/fftwmpi_engine.hh" +#endif + #include namespace muSpectre { /** * Create a unique ptr to a Projection operator (with appropriate * FFT_engine) to be used in a cell constructor */ template > inline std::unique_ptr> cell_input(Ccoord_t resolutions, Rcoord_t lengths, Formulation form) { auto fft_ptr{std::make_unique(resolutions, lengths)}; switch (form) { case Formulation::finite_strain: { using Projection = ProjectionFiniteStrainFast; return std::make_unique(std::move(fft_ptr)); break; } case Formulation::small_strain: { using Projection = ProjectionSmallStrain; return std::make_unique(std::move(fft_ptr)); break; } default: { throw std::runtime_error("unknow formulation"); break; } } } /** * convenience function to create a cell (avoids having to build * and move the chain of unique_ptrs */ template , typename FFTEngine=FFTWEngine> inline Cell make_cell(Ccoord_t resolutions, - Rcoord_t lengths, - Formulation form) { + Rcoord_t lengths, + Formulation form) { - auto && input = cell_input(resolutions, lengths, form); + auto && input = cell_input(resolutions, lengths, + form); auto cell{Cell{std::move(input)}}; return cell; } + +#ifdef WITH_MPI + + /** + * Create a unique ptr to a parallel Projection operator (with appropriate + * FFT_engine) to be used in a cell constructor + */ + template > + inline + std::unique_ptr> + parallel_cell_input(Ccoord_t resolutions, + Rcoord_t lengths, + Formulation form, + const Communicator & comm) { + auto fft_ptr{std::make_unique(resolutions, lengths, comm)}; + switch (form) + { + case Formulation::finite_strain: { + using Projection = ProjectionFiniteStrainFast; + return std::make_unique(std::move(fft_ptr)); + break; + } + case Formulation::small_strain: { + using Projection = ProjectionSmallStrain; + return std::make_unique(std::move(fft_ptr)); + break; + } + default: { + throw std::runtime_error("unknow formulation"); + break; + } + } + } + + + /** + * convenience function to create a parallel cell (avoids having to build + * and move the chain of unique_ptrs + */ + template , + typename FFTEngine=FFTWMPIEngine> + inline + Cell make_parallel_cell(Ccoord_t resolutions, + Rcoord_t lengths, + Formulation form, + const Communicator & comm) { + + auto && input = parallel_cell_input(resolutions, + lengths, + form, comm); + auto cell{Cell{std::move(input)}}; + return cell; + } + +#endif /* WITH_MPI */ } // muSpectre #endif /* CELL_FACTORY_H */