Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
TurTLE
TurTLE
Commits
2212daf8
Commit
2212daf8
authored
Jan 23, 2016
by
Cristian Lalescu
Browse files
broken --- rename files and classes
only test_io passes right now.
parent
5f87cc6a
Changes
11
Hide whitespace changes
Inline
Side-by-side
bfps/
f
luid
_c
onvert
er
.py
→
bfps/
F
luid
C
onvert.py
View file @
2212daf8
...
...
@@ -24,22 +24,21 @@
import
bfps
import
bfps.fluid_base
import
bfps.tools
import
numpy
as
np
import
pickle
import
os
from
._fluid_base
import
_fluid_particle_base
class
f
luid
_c
onvert
er
(
bfps
.
fluid_base
.
fluid_particle_base
):
class
F
luid
C
onvert
(
_
fluid_particle_base
):
def
__init__
(
self
,
name
=
'
f
luid
_c
onvert
er
'
,
name
=
'
F
luid
C
onvert'
,
work_dir
=
'./'
,
simname
=
'test'
,
fluid_precision
=
'single'
,
use_fftw_wisdom
=
True
):
super
(
fluid_converter
,
self
).
__init__
(
_fluid_particle_base
.
__init__
(
self
,
name
=
name
,
work_dir
=
work_dir
,
simname
=
simname
,
...
...
bfps/
f
luid
_r
esize.py
→
bfps/
F
luid
R
esize.py
View file @
2212daf8
...
...
@@ -24,20 +24,20 @@
import
bfps
import
bfps.fluid_base
from
._fluid_base
import
_fluid_particle_base
import
numpy
as
np
class
f
luid
_r
esize
(
bfps
.
fluid_base
.
fluid_particle_base
):
class
F
luid
R
esize
(
_
fluid_particle_base
):
def
__init__
(
self
,
name
=
'
f
luid
_r
esize'
,
name
=
'
F
luid
R
esize'
,
work_dir
=
'./'
,
simname
=
'test'
,
dtype
=
np
.
float32
,
use_fftw_wisdom
=
False
):
super
(
fluid_resize
,
self
).
__init__
(
_fluid_particle_base
.
__init__
(
self
,
name
=
name
,
work_dir
=
work_dir
,
simname
=
simname
,
...
...
bfps/Launcher.py
View file @
2212daf8
import
os
import
argparse
import
bfps
import
.__init__
as
bfps
from
.NavierStokes
import
NavierStokes
from
.FluidResize
import
FluidResize
from
.FluidConvert
import
FluidConvert
class
Launcher
:
def
__init__
(
self
):
self
.
base_class
=
bfps
.
NavierStokes
def
__init__
(
self
,
base_class
=
NavierStokes
):
self
.
base_class
=
base_class
self
.
parser
=
argparse
.
ArgumentParser
(
prog
=
'bfps'
)
self
.
parser
.
add_argument
(
'-v'
,
'--version'
,
...
...
@@ -18,10 +24,6 @@ class Launcher:
default
=
32
,
metavar
=
'N'
,
help
=
'code is run by default in a grid of NxNxN'
)
self
.
parser
.
add_argument
(
'--run'
,
dest
=
'run'
,
action
=
'store_true'
)
self
.
parser
.
add_argument
(
'--ncpu'
,
type
=
int
,
dest
=
'ncpu'
,
...
...
@@ -128,29 +130,28 @@ class Launcher:
c
.
finalize_code
()
c
.
write_src
()
c
.
set_host_info
(
bfps
.
host_info
)
if
opt
.
run
:
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
c
.
work_dir
,
c
.
simname
+
'.h5'
)):
c
.
write_par
()
if
c
.
parameters
[
'nparticles'
]
>
0
:
data
=
c
.
generate_tracer_state
(
species
=
0
,
rseed
=
opt
.
particle_rand_seed
)
for
s
in
range
(
1
,
c
.
particle_species
):
c
.
generate_tracer_state
(
species
=
s
,
data
=
data
)
init_condition_file
=
os
.
path
.
join
(
c
.
work_dir
,
c
.
simname
+
'_cvorticity_i{0:0>5x}'
.
format
(
0
))
if
not
os
.
path
.
exists
(
init_condition_file
):
if
len
(
opt
.
src_simname
)
>
0
:
src_file
=
os
.
path
.
join
(
c
.
work_dir
,
opt
.
src_simname
+
'_cvorticity_i{0:0>5x}'
.
format
(
opt
.
src_iteration
))
os
.
symlink
(
src_file
,
init_condition_file
)
else
:
c
.
generate_vector_field
(
write_to_file
=
True
,
spectra_slope
=
2.0
,
amplitude
=
0.25
)
c
.
run
(
ncpu
=
opt
.
ncpu
,
njobs
=
opt
.
njobs
)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
c
.
work_dir
,
c
.
simname
+
'.h5'
)):
c
.
write_par
()
if
c
.
parameters
[
'nparticles'
]
>
0
:
data
=
c
.
generate_tracer_state
(
species
=
0
,
rseed
=
opt
.
particle_rand_seed
)
for
s
in
range
(
1
,
c
.
particle_species
):
c
.
generate_tracer_state
(
species
=
s
,
data
=
data
)
init_condition_file
=
os
.
path
.
join
(
c
.
work_dir
,
c
.
simname
+
'_cvorticity_i{0:0>5x}'
.
format
(
0
))
if
not
os
.
path
.
exists
(
init_condition_file
):
if
len
(
opt
.
src_simname
)
>
0
:
src_file
=
os
.
path
.
join
(
c
.
work_dir
,
opt
.
src_simname
+
'_cvorticity_i{0:0>5x}'
.
format
(
opt
.
src_iteration
))
os
.
symlink
(
src_file
,
init_condition_file
)
else
:
c
.
generate_vector_field
(
write_to_file
=
True
,
spectra_slope
=
2.0
,
amplitude
=
0.25
)
c
.
run
(
ncpu
=
opt
.
ncpu
,
njobs
=
opt
.
njobs
)
return
c
bfps/NavierStokes.py
View file @
2212daf8
...
...
@@ -28,11 +28,9 @@ import os
import
numpy
as
np
import
h5py
import
bfps
import
bfps.fluid_base
import
bfps.tools
from
._fluid_base
import
_fluid_particle_base
class
NavierStokes
(
bfps
.
fluid_base
.
fluid_particle_base
):
class
NavierStokes
(
_
fluid_particle_base
):
def
__init__
(
self
,
name
=
'NavierStokes'
,
...
...
@@ -46,7 +44,8 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base):
self
.
QR_stats_on
=
QR_stats_on
self
.
frozen_fields
=
frozen_fields
self
.
fftw_plan_rigor
=
fftw_plan_rigor
super
(
NavierStokes
,
self
).
__init__
(
_fluid_particle_base
.
__init__
(
self
,
name
=
name
,
work_dir
=
work_dir
,
simname
=
simname
,
...
...
@@ -715,7 +714,7 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base):
self
.
parameters
[
'nx'
]
//
2
+
1
,
3
))
def
write_par
(
self
,
iter0
=
0
):
super
(
NavierStokes
,
self
)
.
write_par
(
iter0
=
iter0
)
_fluid_particle_base
.
write_par
(
self
,
iter0
=
iter0
)
with
h5py
.
File
(
os
.
path
.
join
(
self
.
work_dir
,
self
.
simname
+
'.h5'
),
'r+'
)
as
ofile
:
kspace
=
self
.
get_kspace
()
nshells
=
kspace
[
'nshell'
].
shape
[
0
]
...
...
bfps/__init__.py
View file @
2212daf8
...
...
@@ -48,8 +48,45 @@ bfpsfolder = os.path.join(homefolder, '.config/', 'bfps')
sys
.
path
.
append
(
bfpsfolder
)
from
host_information
import
host_info
from
.code
import
code
from
.fluid_converter
import
fluid_converter
from
.fluid_resize
import
fluid_resize
from
.FluidConvert
import
FluidConvert
from
.FluidResize
import
FluidResize
from
.NavierStokes
import
NavierStokes
import
argparse
def
get_parser
(
base_class
=
NavierStokes
,
n
=
32
,
ncpu
=
2
,
precision
=
'single'
,
simname
=
'test'
,
work_dir
=
'./'
,
njobs
=
1
):
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--run'
,
dest
=
'run'
,
action
=
'store_true'
)
parser
.
add_argument
(
'-n'
,
type
=
int
,
dest
=
'n'
,
default
=
n
)
parser
.
add_argument
(
'--ncpu'
,
type
=
int
,
dest
=
'ncpu'
,
default
=
ncpu
)
parser
.
add_argument
(
'--precision'
,
type
=
str
,
dest
=
'precision'
,
default
=
precision
)
parser
.
add_argument
(
'--simname'
,
type
=
str
,
dest
=
'simname'
,
default
=
simname
)
parser
.
add_argument
(
'--wd'
,
type
=
str
,
dest
=
'work_dir'
,
default
=
work_dir
)
parser
.
add_argument
(
'--njobs'
,
type
=
int
,
dest
=
'njobs'
,
default
=
njobs
)
c
=
base_class
(
simname
=
simname
)
for
k
in
sorted
(
c
.
parameters
.
keys
()):
parser
.
add_argument
(
'--{0}'
.
format
(
k
),
type
=
type
(
c
.
parameters
[
k
]),
dest
=
k
,
default
=
c
.
parameters
[
k
])
return
parser
bfps/__main__.py
View file @
2212daf8
...
...
@@ -3,7 +3,7 @@ from .Launcher import Launcher
def
main
():
l
=
Launcher
()
l
(
sys
.
argv
[
1
:]
+
[
'--run'
]
)
l
(
sys
.
argv
[
1
:])
return
None
if
__name__
==
'__main__'
:
...
...
bfps/base.py
→
bfps/
_
base.py
View file @
2212daf8
...
...
@@ -28,9 +28,9 @@ import os
import
sys
import
numpy
as
np
import
h5py
import
bfps
from
bfps
import
install_info
class
base
(
object
):
class
_
base
(
object
):
"""
This class contains simulation parameters, and handles parameter related
functionalities of both python objects and C++ codes.
...
...
@@ -109,8 +109,8 @@ class base(object):
else
:
ofile
[
'parameters/'
+
k
]
=
self
.
parameters
[
k
]
ofile
[
'iteration'
]
=
int
(
iter0
)
for
k
in
bfps
.
install_info
.
keys
():
ofile
[
'install_info/'
+
k
]
=
str
(
bfps
.
install_info
[
k
])
for
k
in
install_info
.
keys
():
ofile
[
'install_info/'
+
k
]
=
str
(
install_info
[
k
])
ofile
.
close
()
return
None
def
read_parameters
(
self
):
...
...
bfps/code.py
→
bfps/
_
code.py
View file @
2212daf8
...
...
@@ -31,10 +31,11 @@ import subprocess
import
h5py
from
datetime
import
datetime
import
math
import
bfps
from
bfps
.base
import
base
from
.
_
base
import
_
base
class
code
(
base
):
class
_
code
(
_
base
):
"""
This class is meant to stitch together the C++ code into a final source file,
compile it, and handle all job launching.
...
...
@@ -43,7 +44,7 @@ class code(base):
self
,
work_dir
=
'./'
,
simname
=
'test'
):
super
(
code
,
self
)
.
__init__
(
work_dir
=
work_dir
,
simname
=
simname
)
_base
.
__init__
(
self
,
work_dir
=
work_dir
,
simname
=
simname
)
self
.
version_message
=
(
'/***********************************************************************
\n
'
+
'* this code automatically generated by bfps
\n
'
+
'* version {0}
\n
'
.
format
(
bfps
.
__version__
)
+
...
...
bfps/fluid_base.py
→
bfps/
_
fluid_base.py
View file @
2212daf8
...
...
@@ -24,15 +24,14 @@
import
bfps
import
bfps.code
import
bfps.tools
from
._code
import
_code
from
bfps
import
tools
import
os
import
numpy
as
np
import
h5py
class
fluid_particle_base
(
bfps
.
code
):
class
_
fluid_particle_base
(
_
code
):
def
__init__
(
self
,
name
=
'solver'
,
...
...
@@ -40,7 +39,8 @@ class fluid_particle_base(bfps.code):
simname
=
'test'
,
dtype
=
np
.
float32
,
use_fftw_wisdom
=
True
):
super
(
fluid_particle_base
,
self
).
__init__
(
_code
.
__init__
(
self
,
work_dir
=
work_dir
,
simname
=
simname
)
self
.
use_fftw_wisdom
=
use_fftw_wisdom
...
...
@@ -284,19 +284,19 @@ class fluid_particle_base(bfps.code):
field_name
=
'vorticity'
,
write_to_file
=
False
):
np
.
random
.
seed
(
rseed
)
Kdata00
=
bfps
.
tools
.
generate_data_3D
(
Kdata00
=
tools
.
generate_data_3D
(
self
.
parameters
[
'nz'
]
//
2
,
self
.
parameters
[
'ny'
]
//
2
,
self
.
parameters
[
'nx'
]
//
2
,
p
=
spectra_slope
,
amplitude
=
amplitude
).
astype
(
self
.
ctype
)
Kdata01
=
bfps
.
tools
.
generate_data_3D
(
Kdata01
=
tools
.
generate_data_3D
(
self
.
parameters
[
'nz'
]
//
2
,
self
.
parameters
[
'ny'
]
//
2
,
self
.
parameters
[
'nx'
]
//
2
,
p
=
spectra_slope
,
amplitude
=
amplitude
).
astype
(
self
.
ctype
)
Kdata02
=
bfps
.
tools
.
generate_data_3D
(
Kdata02
=
tools
.
generate_data_3D
(
self
.
parameters
[
'nz'
]
//
2
,
self
.
parameters
[
'ny'
]
//
2
,
self
.
parameters
[
'nx'
]
//
2
,
...
...
@@ -308,7 +308,7 @@ class fluid_particle_base(bfps.code):
Kdata0
[...,
0
]
=
Kdata00
Kdata0
[...,
1
]
=
Kdata01
Kdata0
[...,
2
]
=
Kdata02
Kdata1
=
bfps
.
tools
.
padd_with_zeros
(
Kdata1
=
tools
.
padd_with_zeros
(
Kdata0
,
self
.
parameters
[
'nz'
],
self
.
parameters
[
'ny'
],
...
...
@@ -396,7 +396,7 @@ class fluid_particle_base(bfps.code):
assert
(
self
.
parameters
[
'niter_todo'
]
%
self
.
parameters
[
'niter_part'
]
==
0
)
assert
(
self
.
parameters
[
'niter_out'
]
%
self
.
parameters
[
'niter_stat'
]
==
0
)
assert
(
self
.
parameters
[
'niter_out'
]
%
self
.
parameters
[
'niter_part'
]
==
0
)
super
(
fluid_particle_base
,
self
)
.
write_par
(
iter0
=
iter0
)
_code
.
write_par
(
self
,
iter0
=
iter0
)
with
h5py
.
File
(
os
.
path
.
join
(
self
.
work_dir
,
self
.
simname
+
'.h5'
),
'r+'
)
as
ofile
:
ofile
[
'field_dtype'
]
=
np
.
dtype
(
self
.
dtype
).
str
kspace
=
self
.
get_kspace
()
...
...
tests/base.py
View file @
2212daf8
...
...
@@ -33,7 +33,7 @@ import numpy as np
import
matplotlib.pyplot
as
plt
import
bfps
from
bfps
import
f
luid
_r
esize
from
bfps
import
F
luid
R
esize
from
bfps.tools
import
particle_finite_diff_test
as
acceleration_test
parser
=
bfps
.
get_parser
()
...
...
@@ -54,7 +54,7 @@ parser.add_argument(
def
double
(
opt
):
old_simname
=
'N{0:0>3x}'
.
format
(
opt
.
n
)
new_simname
=
'N{0:0>3x}'
.
format
(
opt
.
n
*
2
)
c
=
f
luid
_r
esize
(
c
=
F
luid
R
esize
(
work_dir
=
opt
.
work_dir
,
simname
=
old_simname
+
'_double'
,
dtype
=
opt
.
precision
)
...
...
tests/test_io.py
View file @
2212daf8
...
...
@@ -26,7 +26,10 @@
from
base
import
*
class
test_io
(
bfps
.
code
):
import
bfps
from
bfps._code
import
_code
class
test_io
(
_code
):
def
__init__
(
self
,
name
=
'test_io'
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment