Page MenuHomec4science

map_2d.cpp
No OneTemporary

File Metadata

Created
Fri, Jun 7, 09:38

map_2d.cpp

/**
*
* @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/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "map_2d.hh"
#include "fft_plan_manager.hh"
#include <fstream>
#include <sstream>
#include <fftw3.h>
#include <omp.h>
/* -------------------------------------------------------------------------- */
#define TIMER
#include "surface_timer.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
template <typename T>
void Map2d<T>::rescaleHeights(Real C){
/* compute actual RMS */
for (UInt i = 0 ; i < this->n[0] ; ++i)
for (UInt j = 0 ; j < this->n[1] ; ++j){
this->at(i,j) *= C;
}
}
/* -------------------------------------------------------------------------- */
template <typename T>
void Map2d<T>::setGridSize(UInt n0, UInt n1){
const UInt n[] = {n0, n1};
this->resize(n);
}
/* -------------------------------------------------------------------------- */
template <typename T>
void Map2d<T>::setGridSize(const UInt n[2]){
this->resize(n);
}
/* -------------------------------------------------------------------------- */
template <typename T>
void Map2d<T>::operator=(const T & e){
this->Grid<T, 2>::operator=(e);
}
/* -------------------------------------------------------------------------- */
template <typename T>
Map2d<T>::Map2d(UInt n0, UInt n1, Real L0, Real L1) {
setGridSize(n0,n1);
this->L[0] = L0;
this->L[1] = L1;
}
/* -------------------------------------------------------------------------- */
template <typename T>
Map2d<T>::Map2d(const UInt * n, const Real *L) {
setGridSize(n);
this->L[0] = L[0];
this->L[1] = L[1];
}
/* -------------------------------------------------------------------------- */
template <typename T>
Map2d<T>::~Map2d()
{}
/* -------------------------------------------------------------------------- */
template <typename T>
void Map2d<T>::dumpToTextFile(std::string filename) {
UInt n1 = this->size(0);
UInt n2 = this->size(1);
std::cout << "Writing surface file " << filename << std::endl;
std::ofstream file(filename.c_str());
if (!file.is_open()) SURFACE_FATAL("cannot open file " << filename);
file.precision(15);
for (UInt i = 0; i < n1; i++) {
for (UInt j=0; j< n2; j++) {
file << i << " " << j << " ";
this->writeValue(file,this->at(i,j));
file << std::endl;
}
file << std::endl;
}
file.close();
}
/* -------------------------------------------------------------------------- */
template <typename T>
void Map2d<T>::writeValue(std::ostream & os, const T & val) {
os << val;
}
/* -------------------------------------------------------------------------- */
template <>
void Map2d<complex>::writeValue(std::ostream & os, const complex & val) {
os << std::scientific << val.real();
os << " " << val.imag();
}
/* -------------------------------------------------------------------------- */
template class Map2d<complex>;
template class Map2d<Real>;
template class Map2d<int>;
template class Map2d<unsigned int>;
template class Map2d<bool>;
template class Map2d<unsigned long>;
__END_TAMAAS__

Event Timeline