Page MenuHomec4science

surface_complex.hh
No OneTemporary

File Metadata

Created
Fri, Jun 7, 20:02

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
/* -------------------------------------------------------------------------- */
template <typename T>
class SurfaceComplex : public Map2dSquare<std::complex<T> > {
public:
SurfaceComplex(UInt a, Real L):Map2dSquare<std::complex<T> >(a,L){}
SurfaceComplex(Surface<T> & s);
SurfaceComplex<T> & operator=(const Surface<T> & s);
SurfaceComplex<T> & operator=(const SurfaceComplex<T> & s);
//! 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;
// set all the members of the map to a given value
using Map2d<std::complex<T> >::operator=;
virtual const SurfaceComplex<T> & getWrappedNumpy(){return *this;};
};
/* -------------------------------------------------------------------------- */
template <typename T>
SurfaceComplex<T> & SurfaceComplex<T>::operator=(const Surface<T> & s){
this->setGridSize(s.size());
UInt size = s.size()*s.size();
for (UInt i = 0; i < size; i++) {
this->at(i) = s(i);
}
return *this;
}
/* -------------------------------------------------------------------------- */
template <typename T>
SurfaceComplex<T> & SurfaceComplex<T>::operator=(const SurfaceComplex<T> & s){
this->setGridSize(s.size());
UInt size = s.size()*s.size();
for (UInt i = 0; i < size; i++) {
this->at(i) = s(i);
}
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->at(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->at(i,j).imag();
}
return res;
}
/* -------------------------------------------------------------------------- */
template <typename T>
void SurfaceComplex<T>::makeItRealBySquare(){
UInt n = this->size();
for (UInt i = 0 ; i < n ; ++i)
for (UInt j = 0 ; j < n ; ++j){
Real norm = std::norm(this->at(i,j));
this->at(i,j) = norm;
}
}
/* -------------------------------------------------------------------------- */
template <typename T>
void SurfaceComplex<T>::makeItRealByAbs(){
UInt n = this->size();
for (UInt i = 0 ; i < n ; ++i)
for (UInt j = 0 ; j < n ; ++j){
Real abs = std::abs(this->at(i,j));
this->at(i,j) = abs;
}
}
/* -------------------------------------------------------------------------- */
template <typename T>
void SurfaceComplex<T>::makeItRealBySum(){
UInt n = this->size();
for (UInt i = 0 ; i < n*n ; ++i){
this->at(i) = this->at(i).real() + this->at(i).imag();
}
}
/* -------------------------------------------------------------------------- */
template <typename T>
SurfaceComplex<T>::SurfaceComplex(Surface<T> & surface):
Map2dSquare<std::complex<T> >(surface.size(),surface.getL()){
UInt n = this->size();
for (UInt i = 0; i < n*n; i++) {
this->at(i) = surface(i);
}
}
/* -------------------------------------------------------------------------- */
#endif /* SURFACE_COMPLEX_H */

Event Timeline