Commit d0045300 authored by Dion Haefner's avatar Dion Haefner

dorie wrapper is now a python script

parent 9d944a43
# Exclude build folder # Exclude build folder
build-cmake/ build-cmake/
# Exclude the parsed mini file # Exclude generated files
testing/convergence.mini testing/*.mini
python/parfield/wrapper/pf_from_file.py
# Ignore temporary and auto-generated files # # Ignore temporary and auto-generated files #
*~ *~
......
#!/bin/bash #!/usr/bin/env python
###### set by CMake ######## import os
DORIEDIR=@CMAKE_BINARY_DIR@ import shutil
MPIRUN=@MPIEXEC@ import argparse
############################ import warnings
import subprocess
DORIE_EXECUTABLE=$DORIEDIR/dune/dorie/dorie import multiprocessing
PARAMETERDIR=$DORIEDIR/doc/default_files
DORIE_PYTHON=$DORIEDIR/dune-env try:
input = raw_input
run_dorie_sequential() except NameError:
{ pass
echo "###################################################"
echo "EXECUTING DORIE IN SEQUENTIAL MODE (Single Process)" # paths set by cmake
echo "###################################################" DORIEDIR = "@CMAKE_BINARY_DIR@"
$DORIE_EXECUTABLE $1 MPIEXEC = "@MPIEXEC@"
} MPIEXEC_NUMPROC_FLAG = "@MPIEXEC_NUMPROC_FLAG@"
MPIEXEC_PREFLAG = "@MPIEXEC_PREFLAG@"
run_dorie_parallel() MPIEXEC_POSTFLAGS = "@MPIEXEC_POSTFLAGS@"
{ #
echo "################################"
echo "EXECUTING DORIE IN PARALLEL MODE" DORIE_EXECUTABLE = os.path.join(DORIEDIR, "dune/dorie/dorie")
echo "################################" PARAMETERDIR = os.path.join(DORIEDIR, "doc/default_files")
$MPIRUN -n $2 $DORIE_EXECUTABLE $1 DORIE_PYTHON = os.path.join(DORIEDIR, "dune-env")
} MPIRUN = lambda nproc, exe, *args: [k for k in [MPIEXEC,MPIEXEC_NUMPROC_FLAG,str(nproc),MPIEXEC_PREFLAG,str(exe),MPIEXEC_POSTFLAGS] + list(args) if k]
initialize_folder() def run(args):
{ if not os.path.isfile(args["config"]):
echo "###################" raise IOError("Configuration file {} not found".format(args["config"]))
echo "INITIALIZING FOLDER" if args["parallel"] == 1:
echo "###################" subprocess.call([DORIE_EXECUTABLE, args["config"]])
cp -iv $PARAMETERDIR/default.ini $PWD/config.ini else:
cp -iv $PARAMETERDIR/default_pf.ini $PWD/parfield.ini print([MPIRUN(args["parallel"],DORIE_EXECUTABLE) + [args["config"]]])
cp -iv $PARAMETERDIR/2d_infiltr.bcdat $PWD/2d_infiltr.bcdat subprocess.call(MPIRUN(args["parallel"],DORIE_EXECUTABLE,args["config"]))
cp -iv $PARAMETERDIR/3d_infiltr.bcdat $PWD/3d_infiltr.bcdat
echo "Initialization done" def create(args):
} for f in ("config.ini", "parfield.ini", "2d_infiltr.bcdat", "3d_infiltr.bcdat"):
newfile = os.path.join(os.getcwd(),f)
plot_vtk() if os.path.exists(newfile):
{ override = (input("File {} exists. Override? [Y/n] ".format(f)) or "Y") in ["Y","y"]
$DORIE_PYTHON plot_vtk.py -f $1 --var $2 if not override:
} continue
shutil.copyfile(os.path.join(PARAMETERDIR, f), newfile)
pf_from_file() print("Folder initialized")
{
$DORIE_PYTHON pf_from_file.py --param $1 --debug def pfg(args):
} if not os.path.isfile(args["config"]):
raise IOError("Configuration file {} not found".format(args["config"]))
################### if args["parallel"] == 1:
subprocess.call([DORIE_PYTHON, "pf_from_file.py", "--param", args["config"]])
# CHECK IF DORIE WAS INSTALLED else:
if [[ ! -e $DORIE_EXECUTABLE ]]; then raise NotImplementedError
echo -e "Error: DORiE executable not found at $DORIE_EXECUTABLE.\nMake sure you have built and installed DORiE."
exit def plot(args):
fi if not os.path.isfile(args["vtk"]):
raise IOError("File {} not found".format(args["vtk"]))
RUN=0 if args["var"]:
PLOT=0 subprocess.call([DORIE_PYTHON, "plot_vtk.py", "-f", args["vtk"], "--var", args["var"]])
CREATE=0 else:
PFG=0 subprocess.call([DORIE_PYTHON, "plot_vtk.py", "-f", args["vtk"]])
PARALLEL=0
if __name__ == "__main__":
# NO ARGUMENTS SUPPLIED try: # catch all exceptions we we can output an error message
if [[ $# = 0 ]]; then with warnings.catch_warnings(record=True) as warn: # catch all warnings so we can count them
echo "Usage: dorie COMMAND [COMMAND-OPTIONS]. For more information try 'dorie help'" # PARSE COMMAND LINE
exit parser = argparse.ArgumentParser(description="DORiE command line interface",
fi epilog="For more information check our online documentation:\n"
"http://dorie-docs.bitballoon.com (password: 'richards')"
# PARSE EACH ARGUMENT )
subparsers = parser.add_subparsers(title="Commands")
case $1 in
run) # run dorie parser_run = subparsers.add_parser('run',help="start dorie")
RUN=1 parser_run.add_argument('config',help="DORiE configuration file. Can be created with 'dorie create'.")
shift parser_run.add_argument('--parallel', metavar='N', nargs='?', default=1, const=multiprocessing.cpu_count(), type=int, required=False,
if [[ $# > 0 ]]; then help="Run in parallel on N processes. If N is not specified, run on all available CPU threads.")
INIFILE=$1 parser_run.set_defaults(func=run)
else
echo "Error: No parameter file specified" parser_create = subparsers.add_parser('create', help="Copy example configuration to current folder.")
exit parser_create.set_defaults(func=create)
fi
shift parser_pfg = subparsers.add_parser('pfg', help="Start parameter field generator.")
if [[ $# > 0 ]]; then parser_pfg.add_argument('config',
case $1 in help="Configuration file for the parameter field generator. Can be created with 'dorie create'.")
parser_pfg.add_argument('--parallel', metavar='N', nargs='?', default=1, const=multiprocessing.cpu_count(), type=int, required=False,
--parallel|--par) help="Run in parallel on N processes. If N is not specified, run on all available CPU threads.")
shift parser_pfg.set_defaults(func=pfg)
if [[ $# > 0 ]]; then
PARALLEL=$1 parser_plot = subparsers.add_parser('plot', help="Plot a preview of a VTK file created by DORiE.")
else parser_plot.add_argument('vtk', help="Input VTK file")
echo "Error: Specify the number of threads when using --parallel" parser_plot.add_argument('--var', nargs='*', required=False)
exit parser_plot.set_defaults(func=plot)
fi
;; args = parser.parse_args()
args.func(vars(args))
--sequential|--seq) except Exception as e:
PARALLEL=0 print("dorie failed with ({0}) warning(s) and ({1}) error(s)".format(len(warn),1))
;; raise
*)
echo "Error: Unrecognized option $1"
exit
;;
esac
fi
if [[ -e $INIFILE && -f $INIFILE && -s $INIFILE ]]; then
if [[ $PARALLEL > 0 ]]; then
run_dorie_parallel $INIFILE $PARALLEL
else
run_dorie_sequential $INIFILE
fi
else
echo "Error: Invalid parameter file $INIFILE"
fi
exit
;;
plot)
PLOT=1
shift
if [[ $# = 0 ]]; then
echo "Error: Specify a VTK file to plot"
exit
fi
while [[ $# > 0 && ! $1 = "--var" ]]; do
if [[ -e $1 && -f $1 && -s $1 ]]; then
VTKFILE+="$1 "
else
echo "Error: Invalid VTK file $1"
exit
fi
shift
done
if [[ $1 = "--var" ]]; then
shift
VARIABLES=""
while [[ $# > 0 ]]; do
VARIABLES+="$1 "
shift
done
fi
plot_vtk "$VTKFILE" "$VARIABLES"
exit
;;
create)
initialize_folder
exit
;;
pfg)
shift
if [[ $# = 1 ]]; then
pf_from_file $1
exit
else
echo "Usage: dorie pfg INIFILE. For more information run 'dorie help'"
exit
fi
;;
help)
echo -e "Usage: dorie COMMAND [COMMAND-OPTIONS]\n"
echo -e "COMMANDS:"
echo -e " 'run INIFILE [OPTIONS]' starts DORiE with parameter file INIFILE"
echo -e " OPTIONS:"
echo -e " '--parallel NPROC' starts DORiE in parallel with NPROC processes"
echo -e " '--sequential' starts DORiE in sequential mode (default)"
echo -e " 'create' creates dummy parameter files in the current directory"
echo -e " 'pfg INIFILE' runs the parameter field generator"
echo -e " 'plot VTK [--var VAR]' plots the variables VAR (default: all variables) from the VTK file(s) VTK"
echo -e " 'help' displays this message"
exit
;;
*)
echo -e "Error: Command not recognized: $1. For more information run 'dorie help'"
exit
;;
esac
...@@ -17,12 +17,12 @@ endfunction() ...@@ -17,12 +17,12 @@ endfunction()
file(COPY ${CMAKE_CURRENT_LIST_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/..) file(COPY ${CMAKE_CURRENT_LIST_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/..)
scrape_parameters(${PROJECT_SOURCE_DIR}/dune/dorie-rfg ${CMAKE_CURRENT_SOURCE_DIR}/field-parameters.xml ${CMAKE_CURRENT_SOURCE_DIR}/parameters.css "default_pf.ini field-parameters.html field-parameters.rst" FIELDPARSCRAPE_RETURN) scrape_parameters(${PROJECT_SOURCE_DIR}/dune/dorie-rfg ${CMAKE_CURRENT_SOURCE_DIR}/field-parameters.xml ${CMAKE_CURRENT_SOURCE_DIR}/parameters.css "parfield.ini field-parameters.html field-parameters.rst" FIELDPARSCRAPE_RETURN)
if (${FIELDPARSCRAPE_RETURN} GREATER 0) if (${FIELDPARSCRAPE_RETURN} GREATER 0)
message(FATAL_ERROR "Parameter scraper failed. DORiE can not be built.") message(FATAL_ERROR "Parameter scraper failed. DORiE can not be built.")
endif() endif()
scrape_parameters(${PROJECT_SOURCE_DIR}/dune/dorie ${CMAKE_CURRENT_SOURCE_DIR}/parameters.xml ${CMAKE_CURRENT_SOURCE_DIR}/parameters.css "default.ini parameters.html parameters.rst" PARSCRAPE_RETURN) scrape_parameters(${PROJECT_SOURCE_DIR}/dune/dorie ${CMAKE_CURRENT_SOURCE_DIR}/parameters.xml ${CMAKE_CURRENT_SOURCE_DIR}/parameters.css "config.ini parameters.html parameters.rst" PARSCRAPE_RETURN)
if (${PARSCRAPE_RETURN} GREATER 0) if (${PARSCRAPE_RETURN} GREATER 0)
message(FATAL_ERROR "Parameter scraper failed. DORiE can not be built.") message(FATAL_ERROR "Parameter scraper failed. DORiE can not be built.")
endif() endif()
#!/usr/bin/env python
import os
import argparse
import warnings
import subprocess
from dorie.parfield import configparser, pfgerror
from dorie.parfield.converter import ImageConverter, CSVConverter, H5Converter, FFTH5Converter
"""
Script invoking the image to h5 converter on a file given via command line.
"""
# path to random field generator executable, set by CMake
RFG_EXEC = "/home/dion/codes/dune/dorie/build-cmake/dune/dorie-rfg/dorie-rfg"
if __name__ == "__main__":
try: # catch all exceptions we we can output an error message
with warnings.catch_warnings(record=True) as warn: # catch all warnings so we can count them
# PARSE COMMAND LINE
parser = argparse.ArgumentParser()
parser.add_argument('-p','--param',help='The configuration file holding all parameterization information',required=True)
parser.add_argument('--debug',help='Display warnings',action='store_true',required=False)
args = vars(parser.parse_args())
cp = configparser.cp(args["param"])
params = {}
for par in ("generator","inputFile","outputFile"):
try:
params[par] = cp["general"][par]
except KeyError:
raise RuntimeError("Missing option general.generator in parameter file {}".format(args["param"]))
# CALL CONVERTER
if params["generator"] == "image":
ImageConverter(args["param"])
elif params["generator"] == "csv":
CSVConverter(args["param"])
elif params["generator"] == "fft":
try:
subprocess.check_call([RFG_EXEC,args["param"]])
except subprocess.CalledProcessError:
raise RuntimeError("FFT Field generator failed")
out_path = cp.get("generator.fft","outputPath")
FFTH5Converter(args["param"], out_path + "/YField.h5")
elif params["generator"] == "hdf5":
H5Converter(args["param"])
else:
raise RuntimeError("Unrecognized generator {}".format(gen))
# HANDLE WARNINGS
if not "debug" in args:
debug = False
else:
debug = args["debug"]
if debug:
for w in warn:
print(" {0}: {1}".format(w.category.__name__,w.message))
print("Parameter field generator exited successfully with ({0}) warning(s) and ({1}) error(s)".format(len(warn),0))
except Exception as e:
print("Parameter field generator failed with ({0}) warning(s) and ({1}) error(s)".format(len(warn),1))
raise
...@@ -12,8 +12,9 @@ from dorie.parfield.converter import ImageConverter, CSVConverter, H5Converter, ...@@ -12,8 +12,9 @@ from dorie.parfield.converter import ImageConverter, CSVConverter, H5Converter,
Script invoking the image to h5 converter on a file given via command line. Script invoking the image to h5 converter on a file given via command line.
""" """
# path to random field generator executable, set by CMake # paths set by CMake
RFG_EXEC = "@dorie-rfg_EXEC@" RFG_EXEC = "@dorie-rfg_EXEC@"
MPIRUN = "@MPIEXEC@ @MPIEXEC_NUMPROC_FLAG@ {} @MPIEXEC_PREFLAG@ {} @MPIEXEC_POSTFLAGS@"
if __name__ == "__main__": if __name__ == "__main__":
try: # catch all exceptions we we can output an error message try: # catch all exceptions we we can output an error message
...@@ -21,6 +22,7 @@ if __name__ == "__main__": ...@@ -21,6 +22,7 @@ if __name__ == "__main__":
# PARSE COMMAND LINE # PARSE COMMAND LINE
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-p','--param',help='The configuration file holding all parameterization information',required=True) parser.add_argument('-p','--param',help='The configuration file holding all parameterization information',required=True)
parser.add_argument('--parallel',help='Number of processes to run on',required=False)
parser.add_argument('--debug',help='Display warnings',action='store_true',required=False) parser.add_argument('--debug',help='Display warnings',action='store_true',required=False)
args = vars(parser.parse_args()) args = vars(parser.parse_args())
...@@ -40,7 +42,10 @@ if __name__ == "__main__": ...@@ -40,7 +42,10 @@ if __name__ == "__main__":
CSVConverter(args["param"]) CSVConverter(args["param"])
elif params["generator"] == "fft": elif params["generator"] == "fft":
try: try:
subprocess.check_call([RFG_EXEC,args["param"]]) if args["parallel"]:
subprocess.check_call(MPIRUN.format(int(args["parallel"]), RFG_EXEC), args["param"])
else:
subprocess.check_call([RFG_EXEC,args["param"]])
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
raise RuntimeError("FFT Field generator failed") raise RuntimeError("FFT Field generator failed")
out_path = cp.get("generator.fft","outputPath") out_path = cp.get("generator.fft","outputPath")
......
include /home/dion/codes/dune/dorie/build-cmake/doc/default_files/default_pf.ini
__name = correlation
__inifile_optionkey = pfg
_asset_path = "/home/dion/codes/dune/dorie/testing"
_evaluation = correlation
[_correlation]
padding = true
[general]
generator = fft
overwrite = true
[generator]
extensions = 1 1, 1 1 1 | expand dim
[generator.fft]
dimensions = 2, 3 | expand dim
outputPath = fft_fields/
N = 2048 2048, 128 128 128 | expand dim
variance = 0.2
correlationLengths = .0039 .00195, .0313 .0625 .0781 | expand dim
include /home/dion/codes/dune/dorie/build-cmake/doc/default_files/default.ini
__name = muphi
__inifile_optionkey = run
_asset_path = "/home/dion/codes/dune/dorie/testing"
_evaluation = muphi
_reference.path = {_asset_path}/reference/
output.fileName = muphi | unique name
output.outputPath = muphi | unique name
output.verbose = 0
time.end = 1.5E5
time.maxTimestep = 1E5
time.startTimestep = 1E3
adaptivity.useAdaptivity = false
grid.dimensions = 2
grid.initialLevel = 0
grid.gridType = rectangular
grid.cells = 50 200
grid.extensions = 1 1
boundary.file = "{_asset_path}/bcs/muphi2d.dat"
parameters.soilDistribution = twoMedia
# fix some parameters so we make sure they are the same as in the muphi run
[parameters.vanGenuchten.1]
thetaR = 0.03
thetaS = 0.32
alpha = -2.3
tau = -1.1
n = 4.17
K0 = 2.2e-5
fraction = 0.8 #Part of the field that is filled with medium 1 (top)
[parameters.vanGenuchten.2]
thetaR = 0.01
thetaS = 0.41
alpha = -0.7
tau = 0
n = 1.3
K0 = 1e-5
[randomField]
N = 1000 1000
variance = 0.2
correlationLengths = .4 .05
seed = 223141598
beta = 0
embeddingFactor = .01
variogramModel = gaussian
newField = false
newEV = false
showEV = false
include /home/dion/codes/dune/dorie/build-cmake/doc/default_files/default.ini
__name = ode
__inifile_optionkey = run
_asset_path = "/home/dion/codes/dune/dorie/testing"
_evaluation = ode
output.fileName = ode | unique
output.outputPath = ode | unique
output.verbose = 0
time.end = 1E7
time.maxTimestep = 1E7
time.startTimestep = 1E4
adaptivity.threshold = 1E-10
adaptivity.useAdaptivity = false, true, true | expand gridtype
grid.initialLevel = 2, 0, 0 | expand gridtype
grid.gridType = rectangular, rectangular, gmsh | expand gridtype
grid.cells = 1 100
grid.gridFile = "{_asset_path}/meshes/mesh.msh"
boundary.file = "{_asset_path}/bcs/bcFile2d.dat"
parameters.soilDistribution = homogeneous, twoLayers | expand
parameters.fraction = 0.6
[_ode]
flux = -3e-6
l2_abstol = 5E-5
include /home/dion/codes/dune/dorie/build-cmake/doc/default_files/default.ini
__name = reference
__inifile_optionkey = run
_asset_path = "/home/dion/codes/dune/dorie/testing"
_evaluation = reference
_reference.path = {_asset_path}/reference/
output.fileName = reference | unique name
output.outputPath = reference | unique name
output.verbose = 0
time.end = 1E5
time.maxTimestep = 1E5
time.startTimestep = 1E4
adaptivity.threshold = 1E-10
adaptivity.useAdaptivity = false, true, false | expand dim
adaptivity.refinementFraction = .05
grid.dimensions = 2, 2, 3 | expand dim
grid.initialLevel = 0
grid.gridType = gmsh, rectangular, rectangular | expand dim
grid.cells = 20 20, 20 20, 10 10 10 | expand dim
grid.extensions = 1 1, 1 1, 1 1 1 | expand dim
grid.gridFile = "{_asset_path}/meshes/mesh.msh", "{_asset_path}/meshes/mesh.msh", "{_asset_path}/meshes/3dcube.msh" | expand dim
boundary.file = "{_asset_path}/bcs/bcFile2d.dat", "{_asset_path}/bcs/bcFile2d.dat", "{_asset_path}/bcs/bcFile3d.dat" | expand dim
parameters.soilDistribution = twoMedia, millerSimilarity | expand
randomField.N = 1000 1000, 1000 1000, 100 100 100 | expand dim
randomField.correlationLengths = .2 .1, .2 .1, .2 .1 .4 | expand dim
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment