Page MenuHomec4science

grid_hermitian.hh
No OneTemporary

File Metadata

Created
Fri, May 24, 15:41

grid_hermitian.hh

/**
*
* @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 "tamaas.hh"
#include "grid.hh"
#include <complex>
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
static std::complex<Real> dummy;
/**
* @brief Multi-dimensional, multi-component herimitian array
*/
template <typename T, UInt dim>
class GridHermitian : public Grid<std::complex<T>, dim> {
/* -------------------------------------------------------------------------- */
/* Constructors */
/* -------------------------------------------------------------------------- */
public:
/// Constructor by default (empty array)
GridHermitian();
/// Constructor
GridHermitian(const UInt n[dim], const Real L[dim], UInt nb_components);
/// Destructor
virtual ~GridHermitian();
/// Use = operator
using Grid<std::complex<T>, dim>::operator=;
/* -------------------------------------------------------------------------- */
/* Access operators */
/* -------------------------------------------------------------------------- */
template <typename... T1>
inline std::complex<T> & operator()(T1... args);
template <typename... T1>
inline const std::complex<T> & operator()(T1... args) const;
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 std::complex<T> & GridHermitian<T, dim>::operator()(T1... args) {
TAMAAS_ASSERT(sizeof...(T1) == dim + 1 || sizeof...(T1) == 1,
"operator() does not match dimension");
if (sizeof...(T1) == 1 && dim != 1) {
UInt tuple[1] = {0};
packTuple(tuple, args...);
if (tuple[0] >= this->data.size()) {
TAMAAS_DEBUG_EXCEPTION("out of bonds access on hermitian surface");
dummy = std::complex<T>(0,0);
return dummy;
}
else return this->Grid<std::complex<T>, dim>::operator()(args...);
}
UInt tuple[dim+1] = {0};
packTuple(tuple, args...);
// reverse tuple if necessary
if (tuple[dim-1] >= this->n[dim-1]) {
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 = std::conj(this->Grid<std::complex<T>, dim>::operator()(tuple));
return dummy;
} else {
return this->Grid<std::complex<T>, dim>::operator()(tuple);
}
}
template <typename T, UInt dim>
template <typename... T1>
inline const std::complex<T> & GridHermitian<T, dim>::operator()(T1... args) const {
TAMAAS_ASSERT(sizeof...(T1) == dim + 1 || sizeof...(T1) == 1,
"operator() does not match dimension");
if (sizeof...(T1) == 1 && dim != 1) {
UInt tuple[1] = {0};
packTuple(tuple, args...);
if (tuple[0] >= this->data.size()) {
TAMAAS_DEBUG_EXCEPTION("out of bonds access on hermitian surface");
dummy = std::complex<T>(0,0);
return dummy;
}
else return this->Grid<std::complex<T>, dim>::operator()(args...);
}
UInt tuple[dim+1] = {0};
packTuple(tuple, args...);
// reverse tuple if necessary
if (tuple[dim-1] >= this->n[dim-1]) {
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 = std::conj(this->Grid<std::complex<T>, dim>::operator()(tuple));
return dummy;
} else {
return this->Grid<std::complex<T>, dim>::operator()(tuple);
}
}
__END_TAMAAS__
#endif // __GRID_HERMITIAN_HH__

Event Timeline