Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TurTLE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TurTLE
TurTLE
Commits
a716276a
Commit
a716276a
authored
9 years ago
by
Cristian Lalescu
Browse files
Options
Downloads
Patches
Plain Diff
add more docstrings to tools
parent
56ae48ca
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bfps/tools.py
+46
-11
46 additions, 11 deletions
bfps/tools.py
with
46 additions
and
11 deletions
bfps/tools.py
+
46
−
11
View file @
a716276a
...
...
@@ -35,7 +35,7 @@ def generate_data_3D(
"""
returns the Fourier representation of a Gaussian random field.
The generated field is scalar (single component), in practice a
3D `numpy` complex-valued array.
3D
`
`numpy`
`
complex-valued array.
The field will use the FFTW representation, with the slowest
direction corresponding to :math:`y`, the intermediate to :math:`z`
and the fastest direction to :math:`x`.
...
...
@@ -53,8 +53,8 @@ def generate_data_3D(
:type p: float
:type amplitude: float
:returns: `
a
`, a complex valued 3D `numpy.array` that uses the
FFTW
layout.
:returns: `
`a`
`, a complex valued 3D
`
`numpy.array`
`
that uses the
FFTW
layout.
"""
assert
(
n0
%
2
==
0
and
n1
%
2
==
0
and
n2
%
2
==
0
)
a
=
np
.
zeros
((
n1
,
n0
,
n2
/
2
+
1
),
dtype
=
dtype
)
...
...
@@ -80,7 +80,7 @@ def generate_data_3D(
def
randomize_phases
(
v
):
"""
randomize the phases of an FFTW complex field.
Given some `numpy.array` of dimension at least 3, with values
Given some
`
`numpy.array`
`
of dimension at least 3, with values
corresponding to the FFTW layout for the Fourier representation,
randomize the phases (assuming that the initial field is complex
valued; otherwise I
'
m not sure what will come out).
...
...
@@ -104,19 +104,36 @@ def padd_with_zeros(
a
,
n0
,
n1
,
n2
,
odtype
=
None
):
""""
grows
"
a complex FFTW field by adding modes with 0 amplitude
:param a: ``numpy.array`` of dimension at least 3
:param n0: number of :math:`z` nodes on desired real-space grid
:param n1: number of :math:`y` nodes on desired real-space grid
:param n2: number of :math:`x` nodes on desired real-space grid
:param odtype: data type to use --- in principle conversion between
single and double precision can be performed with this
function as well.
:type n0: int
:type n1: int
:type n2: int
:type odtype: numpy.dtype
:returns: ``b``, a ``numpy.array`` of size
``(n1, n0, n2//2+1) + a.shape[3:]``, with all modes
not present in ``a`` set to 0.
"""
if
(
type
(
odtype
)
==
type
(
None
)):
odtype
=
a
.
dtype
assert
(
a
.
shape
[
0
]
<=
n0
and
a
.
shape
[
1
]
<=
n1
and
a
.
shape
[
2
]
<=
n2
)
a
.
shape
[
2
]
<=
n2
//
2
+
1
)
b
=
np
.
zeros
((
n0
,
n1
,
n2
/
2
+
1
)
+
a
.
shape
[
3
:],
dtype
=
odtype
)
m0
=
a
.
shape
[
0
]
m1
=
a
.
shape
[
1
]
m0
=
a
.
shape
[
1
]
m1
=
a
.
shape
[
0
]
m2
=
a
.
shape
[
2
]
b
[
:
m
0
/
2
,
:
m
1
/
2
,
:
m2
/
2
+
1
]
=
a
[
:
m
0
/
2
,
:
m
1
/
2
,
:
m2
/
2
+
1
]
b
[
:
m
0
/
2
,
n
1
-
m
1
/
2
:
,
:
m2
/
2
+
1
]
=
a
[
:
m
0
/
2
,
m
1
-
m
1
/
2
:
,
:
m2
/
2
+
1
]
b
[
n
0
-
m
0
/
2
:
,
:
m
1
/
2
,
:
m2
/
2
+
1
]
=
a
[
m
0
-
m
0
/
2
:
,
:
m
1
/
2
,
:
m2
/
2
+
1
]
b
[
n
0
-
m
0
/
2
:
,
n
1
-
m
1
/
2
:
,
:
m2
/
2
+
1
]
=
a
[
m
0
-
m
0
/
2
:
,
m
1
-
m
1
/
2
:
,
:
m2
/
2
+
1
]
b
[
:
m
1
/
/
2
,
:
m
0
/
/
2
,
:
m2
/
/
2
+
1
]
=
a
[
:
m
1
/
/
2
,
:
m
0
/
/
2
,
:
m2
/
/
2
+
1
]
b
[
:
m
1
/
/
2
,
n
0
-
m
0
/
/
2
:
,
:
m2
/
/
2
+
1
]
=
a
[
:
m
1
/
/
2
,
m
0
-
m
0
/
/
2
:
,
:
m2
/
/
2
+
1
]
b
[
n
1
-
m
1
/
/
2
:
,
:
m
0
/
/
2
,
:
m2
/
/
2
+
1
]
=
a
[
m
1
-
m
1
/
/
2
:
,
:
m
0
/
/
2
,
:
m2
/
/
2
+
1
]
b
[
n
1
-
m
1
/
/
2
:
,
n
0
-
m
0
/
/
2
:
,
:
m2
/
/
2
+
1
]
=
a
[
m
1
-
m
1
/
/
2
:
,
m
0
-
m
0
/
/
2
:
,
:
m2
/
/
2
+
1
]
return
b
def
get_kindices
(
...
...
@@ -169,6 +186,17 @@ except ImportError:
def
get_fornberg_coeffs
(
x
=
None
,
a
=
None
):
"""
compute finite difference coefficients
Compute finite difference coefficients for a generic grid specified
by ``x``, according to [Fornberg]_.
The function is used by :func:`particle_finite_diff_test`.
.. [Fornberg] B. Fornberg,
*Generation of Finite Difference Formulas on Arbitrarily Spaced Grids*.
Mathematics of Computation,
**51:184**, 699-706, 1988
"""
N
=
len
(
a
)
-
1
d
=
[]
for
m
in
range
(
N
+
1
):
...
...
@@ -201,6 +229,13 @@ def particle_finite_diff_test(
m
=
3
,
species
=
0
,
plot_on
=
False
):
"""
sanity test for particle data.
Compare finite differences of particle positions with sampled
velocities and accelerations.
.. seealso:: :func:`get_fornberg_coeffs`
"""
d
=
c
.
get_data_file
()
group
=
d
[
'
particles/tracers{0}
'
.
format
(
species
)]
acc_on
=
'
acceleration
'
in
group
.
keys
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment