Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F81196520
grid_hermitian.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Sep 4, 17:03
Size
5 KB
Mime Type
text/x-c++
Expires
Fri, Sep 6, 17:03 (2 d)
Engine
blob
Format
Raw Data
Handle
20502776
Attached To
rTAMAAS tamaas
grid_hermitian.hh
View Options
/**
* @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");
UInt 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");
UInt 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
Log In to Comment