Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F69989784
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
Thu, Jul 4, 16:46
Size
4 KB
Mime Type
text/x-c
Expires
Sat, Jul 6, 16:46 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
18775588
Attached To
rTAMAAS tamaas
surface_generator_filter.cpp
View Options
/**
*
* @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 "fft_plan_manager.hh"
#include "fftransform.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
=
*
white_noise_FFT
;
*
surface_spectral
*=
*
h_coeff_power
;
std
::
cerr
<<
"fourier transform filter spectrum"
<<
std
::
endl
;
FFTransform
<
Real
,
2
>
&
plan
=
FFTPlanManager
::
get
().
createPlan
(
*
surface
,
*
surface_spectral
);
plan
.
backwardTransform
();
FFTPlanManager
::
get
().
destroyPlan
(
*
surface
,
*
surface_spectral
);
}
/* -------------------------------------------------------------------------- */
void
SurfaceGeneratorFilter
::
generateWhiteNoiseFFT
(){
white_noise_FFT
=
new
SurfaceComplex
<
Real
>
(
sources
->
size
(),
sources
->
getL
());
FFTransform
<
Real
,
2
>
&
plan
=
FFTPlanManager
::
get
().
createPlan
(
*
sources
,
*
white_noise_FFT
);
plan
.
forwardTransform
();
FFTPlanManager
::
get
().
destroyPlan
(
*
sources
,
*
white_noise_FFT
);
// white_noise_FFT->dumpToParaview("white noise FFT",NO_REPLICATION);
}
/* -------------------------------------------------------------------------- */
void
SurfaceGeneratorFilter
::
generateHFFT
(){
FFTransform
<
Real
,
2
>
&
plan
=
FFTPlanManager
::
get
().
createPlan
(
*
h_coeff
,
*
h_coeff_power
);
// fourier transform it
plan
.
forwardTransform
();
// make it real so that applicable filter is constructed
h_coeff_power
->
makeItRealByAbs
();
FFTPlanManager
::
get
().
destroyPlan
(
*
h_coeff
,
*
h_coeff_power
);
}
/* -------------------------------------------------------------------------- */
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
)
{
h_coeff_power
=
new
SurfaceComplex
<
Real
>
(
h_coeff
->
size
(),
h_coeff
->
getL
());
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
Log In to Comment