diff --git a/python/bem.i b/python/bem.i index 7b6e0dae..d8601a62 100644 --- a/python/bem.i +++ b/python/bem.i @@ -1,59 +1,62 @@ /** * * @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> * * @section LICENSE * * Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de * Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des * Solides) * * Tamaas is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Tamaas 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Tamaas. If not, see <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* Wrapping bem capabilities /* -------------------------------------------------------------------------- */ %include "bem_interface.hh" %include "bem_fft_base.hh" %include "bem_kato.hh" %include "bem_polonski.hh" %include "bem_gigi.hh" %include "bem_penalty.hh" %include "bem_uzawa.hh" %include "bem_gigipol.hh" %include "bem_grid.hh" %include "bem_grid_kato.hh" %include "bem_grid_polonski.hh" %include "bem_grid_teboulle.hh" %include "bem_grid_condat.hh" %include "functional.hh" %include "meta_functional.hh" %include "elastic_energy_functional.hh" %include "complimentary_term_functional.hh" %include "exponential_adhesion_functional.hh" %include "squared_exponential_adhesion_functional.hh" %include "maugis_adhesion_functional.hh" %include "fftransform.hh" %include "fftransform_fftw.hh" +%ignore tamaas::FFTransform::computeFrequencies; + namespace tamaas { %template(FFTransformReal) FFTransform<Real,2>; %template(FFTransformFFTWReal) FFTransformFFTW<Real,2>; } + diff --git a/src/fftransform.cpp b/src/fftransform.cpp index 7ceed6fc..ca4ed2eb 100644 --- a/src/fftransform.cpp +++ b/src/fftransform.cpp @@ -1,55 +1,57 @@ /** * * @author Lucas Frérot <lucas.frerot@epfl.ch> * * @section LICENSE * * Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de * Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des * Solides) * * Tamaas is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Tamaas 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Tamaas. If not, see <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "fftransform.hh" __BEGIN_TAMAAS__ template<typename T, UInt dim> FFTransform<T, dim>::FFTransform(Grid<T, dim> & real, GridHermitian<T, dim> & spectral): real(real), spectral(spectral) {} /* -------------------------------------------------------------------------- */ template<typename T, UInt dim> FFTransform<T, dim>::~FFTransform() {} /* -------------------------------------------------------------------------- */ template<typename T, UInt dim> void FFTransform<T, dim>::normalize() { real /= (Real) real.getNbPoints(); } /* -------------------------------------------------------------------------- */ +template class FFTransform<Real, 1>; template class FFTransform<Real, 2>; +template class FFTransform<Real, 3>; __END_TAMAAS__ diff --git a/src/fftransform.hh b/src/fftransform.hh index ac5164ed..dee8eac0 100644 --- a/src/fftransform.hh +++ b/src/fftransform.hh @@ -1,66 +1,114 @@ /** * * @author Lucas Frérot <lucas.frerot@epfl.ch> * * @section LICENSE * * Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de * Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des * Solides) * * Tamaas is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Tamaas 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Tamaas. If not, see <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #ifndef FFTRANSFORM_HH #define FFTRANSFORM_HH /* -------------------------------------------------------------------------- */ #include "tamaas.hh" #include "grid.hh" #include "grid_hermitian.hh" +#include "types.hh" +#include <vector> /* -------------------------------------------------------------------------- */ __BEGIN_TAMAAS__ /* -------------------------------------------------------------------------- */ template <typename T, UInt dim> class FFTransform { public: /// Constructor FFTransform(Grid<T, dim> & real, GridHermitian<T, dim> & spectral); /// Destructor virtual ~FFTransform(); public: /// Perform FFT virtual void forwardTransform() = 0; /// Perform IFFT virtual void backwardTransform() = 0; /// Normalize the real surface after backward transform virtual void normalize(); +public: + template <bool hermitian> + static void computeFrequencies(Grid<T, dim> & freq); + protected: Grid<T, dim> & real; GridHermitian<T, dim> & spectral; }; +/* -------------------------------------------------------------------------- */ + +template<typename T, UInt dim> +template<bool hermitian> +void FFTransform<T, dim>::computeFrequencies(Grid<T, dim> & freq) { + // If hermitian is true, we suppose the dimensions of freq are + // reduced based on hermitian symetry and that it has dim components + + const UInt * n = freq.sizes(); + + //#pragma omp parallel for + for (auto it = freq.begin(dim) ; it < freq.end(dim) ; ++it) { + VectorProxy<T> wavevector(*it, dim); + UInt index = freq.getNbPoints() - (freq.end(dim) - it); + UInt tuple[dim] = {0}; + + /// Computing tuple from index + for (UInt d = dim-1 ; d > 0 ; d--) { + tuple[d] = index % n[d]; + index -= tuple[d]; + index /= n[d]; + } + + tuple[0] = index; + + UInt dmax = dim; + + if (hermitian) { + dmax = dim - 1; + wavevector(dim-1) = tuple[dim-1]; + } + + for (UInt d = 0 ; d < dmax ; d++) { + T td = tuple[d]; + T nd = n[d]; + T q = (tuple[d] <= n[d]/2) ? td : td-nd; + wavevector(d) = q; + } + + } +} + /* -------------------------------------------------------------------------- */ __END_TAMAAS__ /* -------------------------------------------------------------------------- */ #endif // FFTRANSFORM_HH