Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
dorie
dorie
Commits
b2185fcc
Commit
b2185fcc
authored
Sep 06, 2018
by
Lukas Riedel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Revert "Move 'dorie' wrapper into Python package.""
This reverts commit
79a3cb0d
.
parent
79a3cb0d
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
258 additions
and
15 deletions
+258
-15
.gitignore
.gitignore
+2
-0
CMakeLists.txt
CMakeLists.txt
+0
-1
bin/CMakeLists.txt
bin/CMakeLists.txt
+0
-8
python/CMakeLists.txt
python/CMakeLists.txt
+1
-0
python/dorie/dorie/cli/CMakeLists.txt
python/dorie/dorie/cli/CMakeLists.txt
+1
-0
python/dorie/dorie/cli/__init__.py
python/dorie/dorie/cli/__init__.py
+0
-0
python/dorie/dorie/cli/cmds.py
python/dorie/dorie/cli/cmds.py
+77
-0
python/dorie/dorie/cli/cmds.py.in
python/dorie/dorie/cli/cmds.py.in
+77
-0
python/dorie/dorie/cli/parser.py
python/dorie/dorie/cli/parser.py
+77
-0
python/dorie/setup.py
python/dorie/setup.py
+1
-0
python/dorie/wrapper/CMakeLists.txt
python/dorie/wrapper/CMakeLists.txt
+1
-0
python/dorie/wrapper/dorie.in
python/dorie/wrapper/dorie.in
+19
-0
python/dorie/wrapper/test_dorie.py.in
python/dorie/wrapper/test_dorie.py.in
+2
-6
No files found.
.gitignore
View file @
b2185fcc
...
...
@@ -2,8 +2,10 @@
build-cmake/
# Exclude generated files
python/dorie/wrapper/dorie
python/dorie/wrapper/pf_from_file.py
python/dorie/wrapper/test_dorie.py
python/dorie/cli/cmds.py
# Ignore temporary and auto-generated files #
*~
...
...
CMakeLists.txt
View file @
b2185fcc
...
...
@@ -41,7 +41,6 @@ dune_enable_all_packages()
dune_require_cxx_standard
(
MODULE
"dorie"
VERSION 14
)
# add subdirectories
add_subdirectory
(
"bin"
)
add_subdirectory
(
"m4"
)
add_subdirectory
(
"cmake/modules"
)
add_subdirectory
(
"python"
)
...
...
bin/CMakeLists.txt
deleted
100644 → 0
View file @
79a3cb0d
configure_file
(
dorie.in
${
CMAKE_BINARY_DIR
}${
CMAKE_FILES_DIRECTORY
}
/dorie @ONLY
)
# copy the temporary file into the final destination, setting the permissions
file
(
COPY
${
CMAKE_BINARY_DIR
}${
CMAKE_FILES_DIRECTORY
}
/dorie
DESTINATION
${
CMAKE_CURRENT_BINARY_DIR
}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
install
(
PROGRAMS
${
CMAKE_CURRENT_BINARY_DIR
}
/dorie DESTINATION
${
CMAKE_INSTALL_BINDIR
}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
python/CMakeLists.txt
View file @
b2185fcc
...
...
@@ -3,6 +3,7 @@ set(DUNE_PYTHON_INSTALL_EDITABLE TRUE)
# install Python package
add_subdirectory
(
dorie/wrapper
)
add_subdirectory
(
dorie/dorie/cli
)
dune_python_install_package
(
PATH dorie
)
# set cache variable
...
...
python/dorie/dorie/cli/CMakeLists.txt
0 → 100644
View file @
b2185fcc
configure_file
(
cmds.py.in
${
CMAKE_CURRENT_SOURCE_DIR
}
/cmds.py
)
\ No newline at end of file
python/dorie/dorie/cli/__init__.py
0 → 100644
View file @
b2185fcc
python/dorie/dorie/cli/cmds.py
0 → 100644
View file @
b2185fcc
import
os
import
sys
import
shutil
import
subprocess
try
:
# Python 2.x compatibility
input
=
raw_input
except
NameError
:
pass
# paths set by cmake
DORIEDIR
=
"/Users/lriedel/dune/dorie/build-cmake"
MPIEXEC
=
"/usr/local/bin/mpiexec"
MPIEXEC_NUMPROC_FLAG
=
"-n"
MPIEXEC_PREFLAG
=
""
MPIEXEC_POSTFLAGS
=
""
# set some paths
DORIE_EXECUTABLE
=
os
.
path
.
join
(
DORIEDIR
,
"dune/dorie/dorie"
)
PARAMETERDIR
=
os
.
path
.
join
(
DORIEDIR
,
"doc/default_files"
)
def
MPIRUN
(
nproc
,
exe
,
*
args
,
**
kwargs
):
mpi_flags
=
kwargs
.
get
(
"mpi_flags"
)
or
[]
return
[
k
for
k
in
[
MPIEXEC
,
MPIEXEC_NUMPROC_FLAG
,
str
(
nproc
)]
\
+
mpi_flags
+
[
MPIEXEC_PREFLAG
,
str
(
exe
),
MPIEXEC_POSTFLAGS
]
+
list
(
args
)
if
k
]
def
run
(
args
):
if
not
os
.
path
.
isfile
(
args
[
"config"
]):
raise
IOError
(
"Configuration file {} not found"
.
format
(
args
[
"config"
]))
try
:
if
args
[
"parallel"
]
==
1
:
subprocess
.
check_call
([
DORIE_EXECUTABLE
,
args
[
"config"
]])
else
:
subprocess
.
check_call
(
MPIRUN
(
args
[
"parallel"
],
DORIE_EXECUTABLE
,
args
[
"config"
],
mpi_flags
=
args
[
"mpi_flags"
]))
except
subprocess
.
CalledProcessError
:
print
(
"Error while running DORiE"
)
sys
.
exit
(
1
)
def
create
(
args
):
for
f
in
(
"config.ini"
,
"parfield.ini"
,
"2d_infiltr.bcdat"
,
"3d_infiltr.bcdat"
):
newfile
=
os
.
path
.
join
(
os
.
getcwd
(),
f
)
if
os
.
path
.
exists
(
newfile
)
and
not
args
[
"force"
]:
override
=
(
input
(
"File {} exists. Override? [Y/n] "
.
format
(
f
))
or
"Y"
)
in
[
"Y"
,
"y"
]
if
not
override
:
continue
shutil
.
copyfile
(
os
.
path
.
join
(
PARAMETERDIR
,
f
),
newfile
)
print
(
"Folder initialized"
)
def
pfg
(
args
):
if
not
os
.
path
.
isfile
(
args
[
"config"
]):
raise
IOError
(
"Configuration file {} not found"
.
format
(
args
[
"config"
]))
try
:
if
args
[
"parallel"
]
==
1
:
subprocess
.
check_call
([
"pf_from_file.py"
,
args
[
"config"
]])
else
:
if
args
[
"mpi_flags"
]:
mpi_flags
=
[
"--mpi-flags="
+
f
for
f
in
args
[
"mpi_flags"
]]
else
:
mpi_flags
=
[]
subprocess
.
check_call
([
"pf_from_file.py"
,
args
[
"config"
],
"--parallel"
,
str
(
args
[
"parallel"
])]
+
mpi_flags
)
except
subprocess
.
CalledProcessError
:
print
(
"Error while running DORiE"
)
sys
.
exit
(
1
)
def
plot
(
args
):
if
not
os
.
path
.
isfile
(
args
[
"vtk"
]):
raise
IOError
(
"File {} not found"
.
format
(
args
[
"vtk"
]))
try
:
if
args
[
"var"
]:
subprocess
.
check_call
([
"plot_vtk.py"
,
"-f"
,
args
[
"vtk"
],
"--var"
,
args
[
"var"
]])
else
:
subprocess
.
check_call
([
"plot_vtk.py"
,
"-f"
,
args
[
"vtk"
]])
except
subprocess
.
CalledProcessError
:
print
(
"Error while running DORiE"
)
sys
.
exit
(
1
)
bin/dorie
.in
→
python/dorie/dorie/cli/cmds.py
.in
View file @
b2185fcc
#!/usr/bin/env python3
import os
import sys
import shutil
import
argparse
import
warnings
import subprocess
import
multiprocessing
try: # Python 2.x compatibility
input = raw_input
...
...
@@ -19,12 +14,10 @@ MPIEXEC = "@MPIEXEC@"
MPIEXEC_NUMPROC_FLAG = "@MPIEXEC_NUMPROC_FLAG@"
MPIEXEC_PREFLAG = "@MPIEXEC_PREFLAG@"
MPIEXEC_POSTFLAGS = "@MPIEXEC_POSTFLAGS@"
#
# set some paths
DORIE_EXECUTABLE = os.path.join(DORIEDIR, "dune/dorie/dorie")
PARAMETERDIR = os.path.join(DORIEDIR, "doc/default_files")
DORIE_PYTHON
=
os
.
path
.
join
(
DORIEDIR
,
"run-in-dune-env"
)
def MPIRUN(nproc,exe,*args,**kwargs):
mpi_flags = kwargs.get("mpi_flags") or []
return [k for k in [MPIEXEC,MPIEXEC_NUMPROC_FLAG,str(nproc)] \
...
...
@@ -59,13 +52,13 @@ def pfg(args):
raise IOError("Configuration file {} not found".format(args["config"]))
try:
if args["parallel"] == 1:
subprocess
.
check_call
([
DORIE_PYTHON
,
"pf_from_file.py"
,
args
[
"config"
]])
subprocess.check_call(["pf_from_file.py", args["config"]])
else:
if args["mpi_flags"]:
mpi_flags = ["--mpi-flags=" + f for f in args["mpi_flags"]]
else:
mpi_flags = []
subprocess
.
check_call
([
DORIE_PYTHON
,
"pf_from_file.py"
,
args
[
"config"
],
subprocess.check_call(["pf_from_file.py", args["config"],
"--parallel", str(args["parallel"])] + mpi_flags)
except subprocess.CalledProcessError:
print("Error while running DORiE")
...
...
@@ -76,69 +69,9 @@ def plot(args):
raise IOError("File {} not found".format(args["vtk"]))
try:
if args["var"]:
subprocess
.
check_call
([
DORIE_PYTHON
,
"plot_vtk.py"
,
"-f"
,
args
[
"vtk"
],
"--var"
,
args
[
"var"
]])
subprocess.check_call(["plot_vtk.py", "-f", args["vtk"], "--var", args["var"]])
else:
subprocess
.
check_call
([
DORIE_PYTHON
,
"plot_vtk.py"
,
"-f"
,
args
[
"vtk"
]])
subprocess.check_call(["plot_vtk.py", "-f", args["vtk"]])
except subprocess.CalledProcessError:
print("Error while running DORiE")
sys
.
exit
(
1
)
if
__name__
==
"__main__"
:
# parse command line and call command handler
try
:
with
warnings
.
catch_warnings
(
record
=
True
)
as
warn
:
parser
=
argparse
.
ArgumentParser
(
description
=
"DORiE command line interface"
,
epilog
=
"For more information check our online documentation: "
"http://dorie-docs.bitballoon.com (password: 'richards')."
)
subparsers
=
parser
.
add_subparsers
(
title
=
"Commands"
,
dest
=
"command"
)
subparsers
.
required
=
True
parser_create
=
subparsers
.
add_parser
(
'create'
,
description
=
"Copy example configuration to current folder."
,
help
=
"Copy example configuration to current folder."
)
parser_create
.
add_argument
(
'-f'
,
'--force'
,
help
=
"Override existing files."
,
action
=
"store_true"
)
parser_create
.
set_defaults
(
func
=
create
)
parser_pfg
=
subparsers
.
add_parser
(
'pfg'
,
help
=
"Start parameter field generator."
,
description
=
"Start parameter field generator."
,
usage
=
"%(prog)s <config> [-h] [-p [N]] [-m=MPI_FLAGS]"
)
parser_pfg
.
add_argument
(
'config'
,
help
=
"Configuration file for the parameter field generator. "
"Can be created with 'dorie create'."
)
parser_pfg
.
add_argument
(
'-p'
,
'--parallel'
,
metavar
=
'N'
,
nargs
=
'?'
,
default
=
1
,
const
=
multiprocessing
.
cpu_count
(),
type
=
int
,
required
=
False
,
help
=
"Run in parallel on N processes. "
"If N is not specified, run on all available CPU threads."
)
parser_pfg
.
add_argument
(
'-m'
,
'--mpi-flags'
,
action
=
"append"
,
required
=
False
,
help
=
"Additional flags that are passed to mpirun when run in parallel. "
"May be specified multiple times."
)
parser_pfg
.
set_defaults
(
func
=
pfg
)
parser_run
=
subparsers
.
add_parser
(
'run'
,
help
=
"Run DORiE."
,
description
=
"Run DORiE."
,
usage
=
"%(prog)s <config> [-h] [-p [N]] [-m=MPI_FLAGS]"
)
parser_run
.
add_argument
(
'config'
,
help
=
"DORiE configuration file. Can be created with 'dorie create'."
)
parser_run
.
add_argument
(
'-p'
,
'--parallel'
,
metavar
=
'N'
,
nargs
=
'?'
,
default
=
1
,
const
=
multiprocessing
.
cpu_count
(),
type
=
int
,
required
=
False
,
help
=
"Run in parallel on N processes. "
"If N is not specified, run on all available CPU threads."
)
parser_run
.
add_argument
(
'-m'
,
'--mpi-flags'
,
action
=
"append"
,
required
=
False
,
help
=
"Additional flags that are passed to mpirun when run in parallel. "
"May be specified multiple times."
)
parser_run
.
set_defaults
(
func
=
run
)
parser_plot
=
subparsers
.
add_parser
(
'plot'
,
help
=
"Plot a preview of a VTK file created by DORiE."
,
description
=
"Plot a preview of a VTK file created by DORiE."
,
usage
=
"%(prog)s <vtk> [-h] [--v [VAR [VAR ...]]]"
)
parser_plot
.
add_argument
(
'vtk'
,
help
=
"Input VTK file."
)
parser_plot
.
add_argument
(
'-v'
,
'--var'
,
nargs
=
'*'
,
required
=
False
,
help
=
"Plot only given variables. If not specified, all variables are plotted."
)
parser_plot
.
set_defaults
(
func
=
plot
)
try
:
args
=
parser
.
parse_args
()
except
SystemExit
:
sys
.
exit
(
1
)
args
.
func
(
vars
(
args
))
except
Exception
as
e
:
print
(
"dorie failed with ({0}) warning(s) and ({1}) error(s)"
.
format
(
len
(
warn
),
1
))
raise
sys.exit(1)
\ No newline at end of file
python/dorie/dorie/cli/parser.py
0 → 100644
View file @
b2185fcc
import
argparse
import
multiprocessing
# import all commands
from
.cmds
import
*
def
create_cl_parser
():
"""Create the command line parser for the DORiE CLI.
Returns:
ArgumentParser object for parsing the command line.
"""
parser
=
argparse
.
ArgumentParser
(
description
=
"DORiE Command Line Interface"
,
epilog
=
"For more information check our online documentation: "
"http://dorie-doc.netlify.com."
)
subparsers
=
parser
.
add_subparsers
(
title
=
"Commands"
,
dest
=
"command"
)
subparsers
.
required
=
True
parser_create
=
subparsers
.
add_parser
(
'create'
,
description
=
"Copy example configuration to current folder."
,
help
=
"Copy example configuration to current folder."
)
parser_create
.
add_argument
(
'-f'
,
'--force'
,
action
=
"store_true"
,
help
=
"Override existing files."
)
parser_create
.
set_defaults
(
func
=
create
)
parser_pfg
=
subparsers
.
add_parser
(
'pfg'
,
help
=
"Start parameter field generator."
,
description
=
"Start parameter field generator."
)
parser_pfg
.
add_argument
(
'config'
,
help
=
"Configuration file for the parameter field generator. "
"A default version can be created with 'dorie create'."
)
parser_pfg
.
add_argument
(
'-p'
,
'--parallel'
,
metavar
=
'N'
,
nargs
=
'?'
,
default
=
1
,
const
=
multiprocessing
.
cpu_count
(),
type
=
int
,
required
=
False
,
help
=
"Run in parallel on N processes. "
"If N is not specified, run on all available CPU threads."
)
parser_pfg
.
add_argument
(
'-m'
,
'--mpi-flags'
,
action
=
"append"
,
required
=
False
,
help
=
"Additional flags that are passed to mpirun when run in parallel. "
"May be specified multiple times."
)
parser_pfg
.
set_defaults
(
func
=
pfg
)
parser_run
=
subparsers
.
add_parser
(
'run'
,
help
=
"Run DORiE."
,
description
=
"Run DORiE."
)
parser_run
.
add_argument
(
'config'
,
help
=
"DORiE configuration file. "
"A default version can be created with 'dorie create'."
)
parser_run
.
add_argument
(
'-p'
,
'--parallel'
,
metavar
=
'N'
,
nargs
=
'?'
,
default
=
1
,
const
=
multiprocessing
.
cpu_count
(),
type
=
int
,
required
=
False
,
help
=
"Run in parallel on N processes. "
"If N is not specified, run on all available CPU threads."
)
parser_run
.
add_argument
(
'-m'
,
'--mpi-flags'
,
action
=
"append"
,
required
=
False
,
help
=
"Additional flags that are passed to mpirun when run in parallel. "
"May be specified multiple times."
)
parser_run
.
set_defaults
(
func
=
run
)
parser_plot
=
subparsers
.
add_parser
(
'plot'
,
help
=
"Plot a preview of a VTK file created by DORiE."
,
description
=
"Plot a preview of a VTK file created by DORiE."
)
parser_plot
.
add_argument
(
'vtk'
,
help
=
"Input VTK file."
)
parser_plot
.
add_argument
(
'-v'
,
'--var'
,
nargs
=
'*'
,
help
=
"Plot only given variables. If not specified, all variables are plotted."
)
parser_plot
.
set_defaults
(
func
=
plot
)
return
parser
\ No newline at end of file
python/dorie/setup.py
View file @
b2185fcc
...
...
@@ -24,6 +24,7 @@ setup(name='dorie',
'wheel'
],
scripts
=
[
'wrapper/dorie'
,
'wrapper/pf_from_file.py'
,
'wrapper/plot_vtk.py'
,
'wrapper/scrape_folder.py'
,
...
...
python/dorie/wrapper/CMakeLists.txt
View file @
b2185fcc
configure_file
(
dorie.in
${
CMAKE_CURRENT_SOURCE_DIR
}
/dorie
)
configure_file
(
pf_from_file.py.in
${
CMAKE_CURRENT_SOURCE_DIR
}
/pf_from_file.py
)
configure_file
(
test_dorie.py.in
${
CMAKE_CURRENT_SOURCE_DIR
}
/test_dorie.py
)
\ No newline at end of file
python/dorie/wrapper/dorie.in
0 → 100644
View file @
b2185fcc
#!/usr/bin/env python3
import
sys
import
warnings
from
dorie.cli.parser
import
create_cl_parser
if
__name__
==
"__main__"
:
# parse command line and call command handler
try
:
with
warnings
.
catch_warnings
(
record
=
True
)
as
warn
:
try
:
parser
=
create_cl_parser
()
args
=
parser
.
parse_args
()
except
SystemExit
:
sys
.
exit
(
1
)
args
.
func
(
vars
(
args
))
except
Exception
as
e
:
print
(
"dorie failed with ({0}) warning(s) and ({1}) error(s)"
.
format
(
len
(
warn
),
1
))
raise
python/dorie/wrapper/test_dorie.py.in
View file @
b2185fcc
...
...
@@ -9,14 +9,10 @@ from dune.testtools.wrapper.argumentparser import get_args
from
dune.testtools.parser
import
parse_ini_file
from
dorie.testtools.wrapper
import
test_dorie
# paths set by cmake
DORIEDIR
=
"@CMAKE_BINARY_DIR@"
#
DORIE_WRAPPER
=
os
.
path
.
join
(
DORIEDIR
,
"bin/dorie"
)
DORIE_WRAPPER
=
"dorie"
if
__name__
==
"__main__"
:
args
=
get_args
()
iniargument
=
args
[
"ini"
]
iniinfo
=
parse_ini_file
(
args
[
"ini"
])
sys
.
exit
(
test_dorie
.
test_dorie
(
iniinfo
,
iniargument
,
DORIE_WRAPPER
))
sys
.
exit
(
test_dorie
.
test_dorie
(
iniinfo
,
iniargument
,
DORIE_WRAPPER
))
Write
Preview
Markdown
is supported
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