Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77985791
surface_generator_filter.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 17, 16:31
Size
3 KB
Mime Type
text/x-c
Expires
Mon, Aug 19, 16:31 (2 d)
Engine
blob
Format
Raw Data
Handle
19961484
Attached To
rTAMAAS tamaas
surface_generator_filter.cpp
View Options
/* -------------------------------------------------------------------------- */
#include "surface_generator_filter.hh"
#include <cmath>
#include <iostream>
/* -------------------------------------------------------------------------- */
SurfaceGeneratorFilter::SurfaceGeneratorFilter(const std::string & inputfile):
SurfaceGenerator(inputfile){
h_coeff = NULL;
sources = NULL;
surface_spectral = NULL;
white_noise_FFT = NULL;
h_coeff_power = NULL;
}
/* -------------------------------------------------------------------------- */
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");
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;
}
}
Event Timeline
Log In to Comment