Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F65747366
test_fftransform.py
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
Wed, Jun 5, 23:00
Size
2 KB
Mime Type
text/x-python
Expires
Fri, Jun 7, 23:00 (2 d)
Engine
blob
Format
Raw Data
Handle
18121042
Attached To
rTAMAAS tamaas
test_fftransform.py
View Options
#!/usr/bin/env python
# coding: utf-8
# -----------------------------------------------------------------------------
# @author Lucas Frérot <lucas.frerot@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/>.
# -----------------------------------------------------------------------------
import
sys
import
tamaas
as
tm
import
numpy
as
np
def
main
():
size
=
8
# Generate random rough surface
SG
=
tm
.
SurfaceGeneratorFilterFFT
()
SG
.
getGridSize
()
.
assign
(
size
)
SG
.
getHurst
()
.
assign
(
0.8
)
SG
.
getRMS
()
.
assign
(
1.
);
SG
.
getQ0
()
.
assign
(
4
);
SG
.
getQ1
()
.
assign
(
4
);
SG
.
getQ2
()
.
assign
(
32
);
SG
.
getRandomSeed
()
.
assign
(
156
);
SG
.
Init
()
surface
=
SG
.
buildSurface
()
# Compute fourier transform through numpy
numpy_spectral
=
np
.
fft
.
rfft2
(
surface
)
# Compute fourier tranform through tamaas
tamaas_spectral
=
tm
.
SurfaceRealComplex
(
size
,
1.
)
transform
=
tm
.
FFTransformFFTWReal
(
surface
,
tamaas_spectral
)
transform
.
forwardTransform
()
spectral
=
tm
.
convertGrid
(
tamaas_spectral
)
error_npy
=
np
.
abs
(
np
.
sum
((
spectral
-
numpy_spectral
)
**
2
))
surface_copy
=
surface
.
copy
()
surface
[:,:]
=
0
transform
.
backwardTransform
()
error_back
=
np
.
abs
(
np
.
sum
((
surface_copy
-
surface
)
**
2
))
print
error_back
print
error_npy
if
error_back
>
1e-16
or
error_npy
>
1e-16
:
return
1
return
0
if
__name__
==
'__main__'
:
sys
.
exit
(
main
())
Event Timeline
Log In to Comment