Page MenuHomec4science

surface_complex.hh
No OneTemporary

File Metadata

Created
Fri, May 24, 07:27

surface_complex.hh

/**
*
* @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/>.
*
*/
/* -------------------------------------------------------------------------- */
#ifndef SURFACE_COMPLEX_H
#define SURFACE_COMPLEX_H
/* -------------------------------------------------------------------------- */
#include "grid_hermitian.hh"
#include "surface.hh"
__BEGIN_TAMAAS__
template <typename T>
class SurfaceComplex : public GridHermitian<T, 2> {
public:
SurfaceComplex(UInt a, Real L);
SurfaceComplex(Surface<T> & s);
SurfaceComplex<T> & operator=(const Surface<T> & s);
SurfaceComplex<T> & operator=(const SurfaceComplex<T> & s);
using GridHermitian<T, 2>::operator=;
//! make a surface real by taking norm as real part and imaginary 0
void makeItRealBySquare();
//! make it real by summing the imaginary and real parts
void makeItRealBySum();
//! make a surface real by taking norm as real part and imaginary 0
void makeItRealByAbs();
//! get real part
Surface<T> real() const;
//! get imaginary part
Surface<T> imag() const;
UInt size() const { return this->n[0]; }
UInt getL() const { return this->L[0]; }
void setGridSize(UInt s);
std::complex<T> & operator()(UInt i, UInt j);
const std::complex<T> & operator()(UInt i, UInt j) const;
std::complex<T> & operator()(UInt i);
const std::complex<T> & operator()(UInt i) const;
virtual const SurfaceComplex<T> & getWrappedNumpy(){return *this;};
#define SURF_OPERATOR(op) \
inline void operator op(const Surface<T> & other); \
inline void operator op(const SurfaceComplex<T> & other) \
SURF_OPERATOR(+=);
SURF_OPERATOR(*=);
SURF_OPERATOR(-=);
SURF_OPERATOR(/=);
#undef SURF_OPERATOR
};
/* -------------------------------------------------------------------------- */
template <typename T>
void SurfaceComplex<T>::setGridSize(UInt s) {
this->n[0] = s;
this->n[1] = s/2+1;
this->resize(this->n);
}
/* -------------------------------------------------------------------------- */
template <typename T>
SurfaceComplex<T> & SurfaceComplex<T>::operator=(const Surface<T> & s){
this->setGridSize(s.size());
for (UInt i = 0; i < this->n[0]; i++) {
for (UInt j = 0; j < this->n[1]; j++) {
(*this)(i,j) = s(i,j);
}
}
return *this;
}
/* -------------------------------------------------------------------------- */
template <typename T>
SurfaceComplex<T> & SurfaceComplex<T>::operator=(const SurfaceComplex<T> & s){
this->GridHermitian<T, 2>::operator=(s);
return *this;
}
/* -------------------------------------------------------------------------- */
template <typename T>
Surface<T> SurfaceComplex<T>::real()const{
Surface<T> res(this->size(),this->getL());
UInt n = this->size();
for (UInt i = 0 ; i < n ; ++i)
for (UInt j = 0 ; j < n ; ++j){
res(i,j) = (*this)(i,j).real();
}
return res;
}
/* -------------------------------------------------------------------------- */
template <typename T>
Surface<T> SurfaceComplex<T>::imag()const{
Surface<T> res(this->size(),this->getL());
UInt n = this->size();
for (UInt i = 0 ; i < n ; ++i)
for (UInt j = 0 ; j < n ; ++j){
res(i,j) = (*this)(i,j).imag();
}
return res;
}
/* -------------------------------------------------------------------------- */
template <typename T>
void SurfaceComplex<T>::makeItRealBySquare(){
for (UInt i = 0 ; i < this->n[0] ; ++i)
for (UInt j = 0 ; j < this->n[1] ; ++j){
(*this)(i,j) = std::norm((*this)(i,j));
}
}
/* -------------------------------------------------------------------------- */
template <typename T>
void SurfaceComplex<T>::makeItRealByAbs(){
for (UInt i = 0 ; i < this->n[0] ; ++i)
for (UInt j = 0 ; j < this->n[1] ; ++j){
(*this)(i,j) = std::abs((*this)(i,j));
}
}
/* -------------------------------------------------------------------------- */
template <typename T>
void SurfaceComplex<T>::makeItRealBySum(){
for (UInt i = 0 ; i < this->data.size() ; ++i){
this->data[i] = this->data[i].real() + this->data[i].imag();
}
}
/* -------------------------------------------------------------------------- */
template <typename T>
SurfaceComplex<T>::SurfaceComplex(UInt a, Real L):
GridHermitian<T, 2>() {
this->n[0] = a;
this->n[1] = a/2+1;
this->L[0] = L;
this->L[1] = L;
this->resize(this->n);
}
/* -------------------------------------------------------------------------- */
template <typename T>
SurfaceComplex<T>::SurfaceComplex(Surface<T> & surface):
GridHermitian<T, 2>() {
UInt a = surface.size();
Real L = surface.getL();
this->n[0] = a;
this->n[1] = a/2+1;
this->L[0] = L;
this->L[1] = L;
this->resize(this->n);
for (UInt i = 0; i < this->n[0] ; i++)
for (UInt j = 0 ; j < this->n[1] ; j++)
(*this)(i, j) = surface(i, j);
}
/* -------------------------------------------------------------------------- */
template <typename T>
std::complex<T> & SurfaceComplex<T>::operator()(UInt i, UInt j) {
return GridHermitian<T, 2>::operator()(i, j, 0);
}
template <typename T>
const std::complex<T> & SurfaceComplex<T>::operator()(UInt i, UInt j) const {
return GridHermitian<T, 2>::operator()(i, j, 0);
}
template <typename T>
const std::complex<T> & SurfaceComplex<T>::operator()(UInt i) const {
return GridHermitian<T, 2>::operator()(i);
}
template <typename T>
std::complex<T> & SurfaceComplex<T>::operator()(UInt i) {
return GridHermitian<T, 2>::operator()(i);
}
/* -------------------------------------------------------------------------- */
#define SURF_OP_IMPL(op) \
template <typename T> \
inline void SurfaceComplex<T>::operator op(const Surface<T> & other) { \
TAMAAS_ASSERT(this->n[0] == other.sizes()[0] && this->n[1] == other.sizes()[1]/2+1, \
"surface size does not match"); \
_Pragma("omp parallel for") \
for (UInt i = 0 ; i < this->n[0] ; i++) \
for (UInt j = 0 ; j < this->n[1] ; j++) \
(*this)(i, j) op other(i, j); \
} \
template <typename T> \
inline void SurfaceComplex<T>::operator op(const SurfaceComplex<T> & other) { \
Grid<std::complex<T>, 2>::operator op(other); \
}
SURF_OP_IMPL(+=);
SURF_OP_IMPL(*=);
SURF_OP_IMPL(-=);
SURF_OP_IMPL(/=);
#undef SURF_OP_IMPL
__END_TAMAAS__
#endif /* SURFACE_COMPLEX_H */

Event Timeline