Page MenuHomec4science

surface_generator_random_phase.cpp
No OneTemporary

File Metadata

Created
Fri, May 10, 00:24

surface_generator_random_phase.cpp

/**
* @file
* LICENSE
*
* Copyright (©) 2016-2021 EPFL (École Polytechnique Fédérale de Lausanne),
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#include "surface_generator_random_phase.hh"
#include <iostream>
/* -------------------------------------------------------------------------- */
namespace tamaas {
/* -------------------------------------------------------------------------- */
template <UInt dim>
Grid<Real, dim>& SurfaceGeneratorRandomPhase<dim>::buildSurface() {
if (this->grid.dataSize() == 0)
TAMAAS_EXCEPTION("the size of the grid is zero, did you call setSizes() ?");
if (this->filter == nullptr)
TAMAAS_EXCEPTION("spectrum is null, did you call setSpectrum() ?");
// Resizing arrays
auto hermitian_dim =
GridHermitian<Real, dim>::hermitianDimensions(this->grid.sizes());
this->white_noise.resize(hermitian_dim);
this->filter_coefficients.resize(hermitian_dim);
/// Generating white noise with uniform distribution for phase
this->template generateWhiteNoise<uniform_real_distribution<Real>>();
/// Applying filters
this->filter->computeFilter(this->filter_coefficients);
Loop::loop([](Complex& coeff,
Real& phase) { coeff *= thrust::polar(1., 2 * M_PI * phase); },
this->filter_coefficients, this->white_noise);
this->engine->backward(this->grid, this->filter_coefficients);
/// Normalizing surface for hrms independent of number of points
this->grid *= this->grid.globalDataSize();
return this->grid;
}
/* -------------------------------------------------------------------------- */
template class SurfaceGeneratorRandomPhase<1>;
template class SurfaceGeneratorRandomPhase<2>;
/* -------------------------------------------------------------------------- */
} // namespace tamaas

Event Timeline