Page MenuHomec4science

surface_generator_filter.cpp
No OneTemporary

File Metadata

Created
Mon, Jul 8, 08:22

surface_generator_filter.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 "surface_generator_filter.hh"
#include <cmath>
#include <iostream>
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
SurfaceGeneratorFilter::SurfaceGeneratorFilter(){
h_coeff = NULL;
sources = NULL;
surface_spectral = NULL;
white_noise_FFT = NULL;
h_coeff_power = NULL;
}
/* -------------------------------------------------------------------------- */
SurfaceGeneratorFilter::~SurfaceGeneratorFilter(){
delete white_noise_FFT;
delete surface_spectral;
}
/* -------------------------------------------------------------------------- */
void SurfaceGeneratorFilter::Init(){
SurfaceGenerator::Init();
}
/* -------------------------------------------------------------------------- */
void SurfaceGeneratorFilter::applyFilterOnSource(){
std::cerr << "resize surface" << std::endl;
if (surface_spectral == NULL)
surface_spectral = new SurfaceComplex<Real>(surface->size(),surface->getL());
else surface_spectral->setGridSize(surface->size());
std::cerr << "do full product in fourier space" << std::endl;
surface_spectral->fullProduct(*white_noise_FFT,*h_coeff_power);
std::cerr << "fourier transform filter spectrum" << std::endl;
surface_spectral->FFTITransform(*surface);
}
/* -------------------------------------------------------------------------- */
void SurfaceGeneratorFilter::generateWhiteNoiseFFT(){
white_noise_FFT = new SurfaceComplex<Real>(*sources);
white_noise_FFT->FFTTransform();
// white_noise_FFT->dumpToParaview("white noise FFT",NO_REPLICATION);
}
/* -------------------------------------------------------------------------- */
void SurfaceGeneratorFilter::generateHFFT(){
SurfaceComplex<Real> h_coeff_FFT(*h_coeff);
// fourier transform it
h_coeff_FFT.FFTTransform();
// copy it to power spectrum
*h_coeff_power = h_coeff_FFT;
// make it real so that applicable filter is constructed
h_coeff_power->makeItRealByAbs();
}
/* -------------------------------------------------------------------------- */
Surface<Real> & SurfaceGeneratorFilter::buildSurface(){
if (surface == NULL) SURFACE_FATAL("Init function was not called");
int n = surface->size();
if (white_noise_FFT == NULL){
// create the random source
sources = new Surface<Real>(n,1.);
Surface<Real>::generateWhiteNoiseSurface(*sources,random_seed);
fprintf(stderr,"build FFT of white noise\n");
generateWhiteNoiseFFT();
delete (sources);
}
fprintf(stderr,"build filter coefficients\n");
computeFilterCoefficients();
if (h_coeff_power == NULL) {
generateHFFT();
}
// s->setHeights(h_coeff_power);
// h_coeff_power->dumpToParaview("h_coeff_power",NO_REPLICATION);
fprintf(stderr,"apply filter on white noise\n");
applyFilterOnSource();
delete h_coeff_power;
fprintf(stderr,"recenter arround mean the surface\n");
surface->recenterHeights();
constrainRMS();
// s->setHeights(heights);
//s->SetHeights(sources);
//s->SetHeights(h);
return *surface;
}
/* -------------------------------------------------------------------------- */
void SurfaceGeneratorFilter::clearSource(){
if (white_noise_FFT != NULL){
delete white_noise_FFT;
white_noise_FFT = NULL;
}
}
__END_TAMAAS__

Event Timeline