Page MenuHomec4science

grid_hermitian.hh
No OneTemporary

File Metadata

Created
Thu, May 9, 19:26

grid_hermitian.hh

/**
* @file
*
* @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 __GRID_HERMITIAN_HH__
#define __GRID_HERMITIAN_HH__
/* -------------------------------------------------------------------------- */
#include "grid.hh"
#include "tamaas.hh"
#include <complex>
#include <vector>
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
static complex<Real> dummy;
/**
* @brief Multi-dimensional, multi-component herimitian array
*
* This class represents an array of hermitian data, meaning it has dimensions
* of: n1 * n2 * n3 * ... * (nx / 2 + 1)
*
* However, it acts as a fully dimensioned array, returning a dummy reference
* for data outside its real dimension, allowing one to write full (and
* inefficient) loops without really worrying about the reduced dimension.
*
* It would however be better to just use the true dimensions of the surface
* for all intents and purposes, as it saves computation time.
*/
template <typename T, UInt dim>
class GridHermitian : public Grid<complex<T>, dim> {
public:
typedef complex<T> value_type;
/* ------------------------------------------------------------------------ */
/* Constructors */
/* ------------------------------------------------------------------------ */
public:
GridHermitian() = default;
GridHermitian(const GridHermitian& o) = default;
GridHermitian(GridHermitian&& o) = default;
using Grid<value_type, dim>::Grid;
using Grid<complex<T>, dim>::operator=;
/* ------------------------------------------------------------------------ */
/* Access operators */
/* ------------------------------------------------------------------------ */
template <typename... T1>
inline complex<T>& operator()(T1... args);
template <typename... T1>
inline const complex<T>& operator()(T1... args) const;
static std::array<UInt, dim>
hermitianDimensions(const std::array<UInt, dim>& n) {
std::array<UInt, dim> hn(n);
hn[dim - 1] /= 2;
hn[dim - 1] += 1;
return hn;
}
private:
template <typename... T1>
inline void packTuple(UInt* t, UInt i, T1... args) const;
template <typename... T1>
inline void packTuple(UInt* t, UInt i) const;
};
/* -------------------------------------------------------------------------- */
/* Inline function definitions */
/* -------------------------------------------------------------------------- */
template <typename T, UInt dim>
template <typename... T1>
inline void GridHermitian<T, dim>::packTuple(UInt* t, UInt i,
T1... args) const {
*t = i;
packTuple(t + 1, args...);
}
template <typename T, UInt dim>
template <typename... T1>
inline void GridHermitian<T, dim>::packTuple(UInt* t, UInt i) const {
*t = i;
}
template <typename T, UInt dim>
template <typename... T1>
inline complex<T>& GridHermitian<T, dim>::operator()(T1... args) {
constexpr UInt nargs = sizeof...(T1);
static_assert(nargs <= dim + 1, "Too many arguments");
auto& last_index =
std::get<nargs - 1>(std::forward_as_tuple(args...));
if (nargs != 1 && last_index >= this->n[dim - 1]) {
std::array<UInt, dim + 1> tuple = {{0}};
packTuple(tuple.data(), args...);
for (UInt i = 0; i < dim; i++) {
if (tuple[i] && i != dim - 1)
tuple[i] = this->n[i] - tuple[i];
else if (tuple[i] && i == dim - 1)
tuple[i] = 2 * (this->n[i] - 1) - tuple[i];
}
dummy = conj(this->Grid<complex<T>, dim>::operator()(tuple));
return dummy;
}
else
return Grid<complex<T>, dim>::operator()(args...);
}
template <typename T, UInt dim>
template <typename... T1>
inline const complex<T>& GridHermitian<T, dim>::operator()(T1... args) const {
constexpr UInt nargs = sizeof...(T1);
static_assert(nargs <= dim + 1, "Too many arguments");
auto& last_index =
std::get<nargs - 1>(std::forward_as_tuple(args...));
if (nargs != 1 && last_index >= this->n[dim - 1]) {
std::array<UInt, dim + 1> tuple = {{0}};
packTuple(tuple.data(), args...);
for (UInt i = 0; i < dim; i++) {
if (tuple[i] && i != dim - 1)
tuple[i] = this->n[i] - tuple[i];
else if (tuple[i] && i == dim - 1)
tuple[i] = 2 * (this->n[i] - 1) - tuple[i];
}
dummy = conj(this->Grid<complex<T>, dim>::operator()(tuple));
return dummy;
}
else
return Grid<complex<T>, dim>::operator()(args...);
}
__END_TAMAAS__
#endif // __GRID_HERMITIAN_HH__

Event Timeline