Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78853539
fractal_surface.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
Fri, Aug 23, 08:36
Size
4 KB
Mime Type
text/x-python
Expires
Sun, Aug 25, 08:36 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
19842639
Attached To
rTAMAAS tamaas
fractal_surface.py
View Options
#!/usr/bin/python
# -*- coding: utf-8 -*-
##*
#
# @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/>.
#
#
################################################################
from
tamaas
import
*
import
argparse
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"--rescale"
,
help
=
"Rescale surface for RMS(slopes) = 1"
,
action
=
'store_true'
)
parser
.
add_argument
(
"--N"
,
help
=
"Number of points"
,
type
=
int
,
default
=
512
)
parser
.
add_argument
(
"--k0"
,
help
=
"Roll-off wave number"
,
type
=
int
,
default
=
4
)
parser
.
add_argument
(
"--k1"
,
help
=
"Low cutoff wave number"
,
type
=
int
,
default
=
4
)
parser
.
add_argument
(
"--k2"
,
help
=
"High cutoff wave number"
,
type
=
int
,
default
=
32
)
parser
.
add_argument
(
"--rms"
,
help
=
"RMS(heights)"
,
default
=
1.
)
parser
.
add_argument
(
"--H"
,
help
=
"Hurst exponent"
,
default
=
0.8
)
args
=
parser
.
parse_args
()
#generate surface
SG
=
SurfaceGeneratorFilterFFT
()
SG
.
getGridSize
()
.
assign
(
args
.
N
)
SG
.
getHurst
()
.
assign
(
args
.
H
)
SG
.
getRMS
()
.
assign
(
args
.
rms
);
SG
.
getQ0
()
.
assign
(
args
.
k0
);
SG
.
getQ1
()
.
assign
(
args
.
k1
);
SG
.
getQ2
()
.
assign
(
args
.
k2
);
SG
.
getRandomSeed
()
.
assign
(
156
);
SG
.
Init
()
a
=
SG
.
buildSurface
()
if
args
.
rescale
:
rms_slopes
=
SurfaceStatistics
.
computeSpectralRMSSlope
(
a
)
a
/=
rms_slopes
#compute and print surface statistics
class
Stats
:
def
__getitem__
(
self
,
key
):
return
self
.
__dict__
[
key
]
stats
=
Stats
()
stats
.
size
=
SG
.
getGridSize
()
stats
.
hurst
=
SG
.
getHurst
()
.
value
()
stats
.
rms
=
SG
.
getRMS
()
stats
.
k0
=
SG
.
getQ0
()
stats
.
k1
=
SG
.
getQ1
()
.
value
()
stats
.
k2
=
SG
.
getQ2
()
.
value
()
stats
.
seed
=
SG
.
getRandomSeed
()
stats
.
rms_spectral
=
SurfaceStatistics
.
computeSpectralStdev
(
a
);
stats
.
rms_slopes_spectral
=
SurfaceStatistics
.
computeSpectralRMSSlope
(
a
);
stats
.
rms_geometric
=
a
.
std
(
ddof
=
1
)
stats
.
rms_slopes_geometric
=
SurfaceStatistics
.
computeRMSSlope
(
a
);
stats
.
moments
=
SurfaceStatistics
.
computeMoments
(
a
);
stats
.
m0
=
stats
[
'rms_spectral'
]
**
2
stats
.
m2
=
stats
.
moments
[
0
]
stats
.
m4
=
stats
.
moments
[
1
]
stats
.
alpha
=
stats
[
'm0'
]
*
stats
[
'm4'
]
/
(
stats
[
'm2'
]
**
2
)
stats
.
L
=
1.
stats
.
m0prime
=
SurfaceStatistics
.
computeAnalyticFractalMoment
(
0
,
stats
.
k1
,
stats
.
k2
,
stats
.
hurst
,
1.
,
stats
.
L
)
stats
.
moment_A
=
stats
.
m0
/
stats
.
m0prime
stats
.
analytic_m0
=
SurfaceStatistics
.
computeAnalyticFractalMoment
(
0
,
stats
.
k1
,
stats
.
k2
,
stats
.
hurst
,
stats
.
moment_A
,
stats
.
L
);
stats
.
analytic_m2
=
SurfaceStatistics
.
computeAnalyticFractalMoment
(
2
,
stats
.
k1
,
stats
.
k2
,
stats
.
hurst
,
stats
.
moment_A
,
stats
.
L
);
stats
.
analytic_m4
=
SurfaceStatistics
.
computeAnalyticFractalMoment
(
4
,
stats
.
k1
,
stats
.
k2
,
stats
.
hurst
,
stats
.
moment_A
,
stats
.
L
);
stats
.
analytic_alpha
=
stats
.
analytic_m0
*
stats
.
analytic_m4
/
(
stats
.
analytic_m2
*
stats
.
analytic_m2
);
print
"""
[N] {size}
[rms] {rms}
[rmsSpectral] {rms_spectral}
[rmsSlopeSpectral] {rms_slopes_spectral}
[rmsSlopeGeometric] {rms_slopes_geometric}
[Hurst] {hurst}
[k1] {k1}
[k2] {k2}
[moment A] {moment_A}
[m0] {m0}
[analytic m0] {analytic_m0}
[m2] {m2}
[analytic m2] {analytic_m2}
[m4] {m4}
[analytic m4] {analytic_m4}
[alpha] {alpha}
[analytic_alpha] {analytic_alpha}
[seed] {seed}
"""
.
format
(
**
stats
.
__dict__
)
#plot the surface
b
=
a
.
real
import
matplotlib.pyplot
as
plt
plt
.
imshow
(
b
)
plt
.
show
()
Event Timeline
Log In to Comment