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
0f8920dd
Commit
0f8920dd
authored
Jan 20, 2016
by
Cristian Lalescu
Browse files
improve command line tool
parent
9b81285a
Changes
2
Hide whitespace changes
Inline
Side-by-side
bfps/Launcher.py
View file @
0f8920dd
import
os
import
sys
import
numpy
as
np
import
argparse
import
bfps
class
Launcher
:
def
__init__
(
self
,
data_dir
=
'./'
):
self
.
parser
=
bfps
.
get_parser
(
bfps
.
NavierStokes
,
work_dir
=
os
.
path
.
realpath
(
data_dir
))
def
__init__
(
self
):
self
.
base_class
=
bfps
.
NavierStokes
self
.
parser
=
argparse
.
ArgumentParser
(
prog
=
'bfps'
)
self
.
parser
.
add_argument
(
'-v'
,
'--version'
,
action
=
'version'
,
version
=
'%(prog)s '
+
bfps
.
__version__
)
self
.
parser
.
add_argument
(
'-n'
,
type
=
int
,
dest
=
'n'
,
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'
,
default
=
2
)
self
.
parser
.
add_argument
(
'--precision'
,
type
=
str
,
dest
=
'precision'
,
default
=
'single'
)
self
.
parser
.
add_argument
(
'--simname'
,
type
=
str
,
dest
=
'simname'
,
default
=
'test'
)
self
.
parser
.
add_argument
(
'--wd'
,
type
=
str
,
dest
=
'work_dir'
,
default
=
'./'
)
self
.
parser
.
add_argument
(
'--njobs'
,
type
=
int
,
dest
=
'njobs'
,
default
=
1
)
self
.
parser
.
add_argument
(
'--QR-stats'
,
action
=
'store_true'
,
dest
=
'QR_stats'
)
dest
=
'QR_stats'
,
help
=
'add this option if you want to compute velocity gradient and QR stats'
)
self
.
parser
.
add_argument
(
'--kMeta'
,
type
=
float
,
...
...
@@ -41,8 +73,18 @@ class Launcher:
type
=
int
,
dest
=
'src_iteration'
,
default
=
0
)
self
.
data_dir
=
data_dir
self
.
base_class
=
bfps
.
NavierStokes
self
.
parser
.
add_argument
(
'--particle-rand-seed'
,
type
=
int
,
dest
=
'particle_rand_seed'
,
default
=
None
)
c
=
self
.
base_class
()
for
k
in
sorted
(
c
.
parameters
.
keys
()):
self
.
parser
.
add_argument
(
'--{0}'
.
format
(
k
),
type
=
type
(
c
.
parameters
[
k
]),
dest
=
k
,
default
=
None
)
return
None
def
__call__
(
self
,
...
...
@@ -50,9 +92,6 @@ class Launcher:
opt
=
self
.
parser
.
parse_args
(
args
)
if
opt
.
environment
!=
''
:
bfps
.
host_info
[
'environment'
]
=
opt
.
environment
opt
.
nx
=
opt
.
n
opt
.
ny
=
opt
.
n
opt
.
nz
=
opt
.
n
opt
.
work_dir
=
os
.
path
.
join
(
os
.
path
.
realpath
(
opt
.
work_dir
),
'N{0:0>4}'
.
format
(
opt
.
n
))
...
...
@@ -60,7 +99,6 @@ class Launcher:
fluid_precision
=
opt
.
precision
,
simname
=
opt
.
simname
,
QR_stats_on
=
opt
.
QR_stats
)
c
.
pars_from_namespace
(
opt
)
# with the default Lundgren forcing, I can estimate the dissipation
# with nondefault forcing, figure out the amplitude for this viscosity
# yourself
...
...
@@ -75,6 +113,16 @@ class Launcher:
meantrS2
=
(
opt
.
n
//
2
/
opt
.
kMeta
)
**
4
*
c
.
parameters
[
'nu'
]
**
2
c
.
parameters
[
'max_Q_estimate'
]
=
meantrS2
c
.
parameters
[
'max_R_estimate'
]
=
.
4
*
meantrS2
**
1.5
# command line parameters will overwrite any defaults
cmd_line_pars
=
vars
(
opt
)
for
k
in
[
'nx'
,
'ny'
,
'nz'
]:
if
type
(
cmd_line_pars
[
k
])
==
type
(
None
):
cmd_line_pars
[
k
]
=
opt
.
n
for
k
in
c
.
parameters
.
keys
():
if
k
in
cmd_line_pars
.
keys
():
if
not
type
(
cmd_lines_pars
[
k
])
==
type
(
None
):
c
.
parameters
[
k
]
=
cmd_line_pars
[
k
]
c
.
fill_up_fluid_code
()
c
.
finalize_code
()
c
.
write_src
()
...
...
@@ -83,11 +131,7 @@ class Launcher:
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
c
.
work_dir
,
c
.
simname
+
'.h5'
)):
c
.
write_par
()
if
c
.
parameters
[
'nparticles'
]
>
0
:
if
opt
.
particle_rand_seed
!=
0
:
rseed
=
opt
.
particle_rand_seed
else
:
rseed
=
None
data
=
c
.
generate_tracer_state
(
species
=
0
,
rseed
=
rseed
)
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
(
...
...
bfps/__init__.py
View file @
0f8920dd
...
...
@@ -53,41 +53,3 @@ from .fluid_converter import fluid_converter
from
.fluid_resize
import
fluid_resize
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
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