Commit d0045300 authored by Dion Haefner's avatar Dion Haefner

dorie wrapper is now a python script

parent 9d944a43
# Exclude build folder
build-cmake/
# Exclude the parsed mini file
testing/convergence.mini
# Exclude generated files
testing/*.mini
python/parfield/wrapper/pf_from_file.py
# Ignore temporary and auto-generated files #
*~
......
#!/bin/bash
###### set by CMake ########
DORIEDIR=@CMAKE_BINARY_DIR@
MPIRUN=@MPIEXEC@
############################
DORIE_EXECUTABLE=$DORIEDIR/dune/dorie/dorie
PARAMETERDIR=$DORIEDIR/doc/default_files
DORIE_PYTHON=$DORIEDIR/dune-env
run_dorie_sequential()
{
echo "###################################################"
echo "EXECUTING DORIE IN SEQUENTIAL MODE (Single Process)"
echo "###################################################"
$DORIE_EXECUTABLE $1
}
run_dorie_parallel()
{
echo "################################"
echo "EXECUTING DORIE IN PARALLEL MODE"
echo "################################"
$MPIRUN -n $2 $DORIE_EXECUTABLE $1
}
initialize_folder()
{
echo "###################"
echo "INITIALIZING FOLDER"
echo "###################"
cp -iv $PARAMETERDIR/default.ini $PWD/config.ini
cp -iv $PARAMETERDIR/default_pf.ini $PWD/parfield.ini
cp -iv $PARAMETERDIR/2d_infiltr.bcdat $PWD/2d_infiltr.bcdat
cp -iv $PARAMETERDIR/3d_infiltr.bcdat $PWD/3d_infiltr.bcdat
echo "Initialization done"
}
plot_vtk()
{
$DORIE_PYTHON plot_vtk.py -f $1 --var $2
}
pf_from_file()
{
$DORIE_PYTHON pf_from_file.py --param $1 --debug
}
###################
# CHECK IF DORIE WAS INSTALLED
if [[ ! -e $DORIE_EXECUTABLE ]]; then
echo -e "Error: DORiE executable not found at $DORIE_EXECUTABLE.\nMake sure you have built and installed DORiE."
exit
fi
RUN=0
PLOT=0
CREATE=0
PFG=0
PARALLEL=0
# NO ARGUMENTS SUPPLIED
if [[ $# = 0 ]]; then
echo "Usage: dorie COMMAND [COMMAND-OPTIONS]. For more information try 'dorie help'"
exit
fi
# PARSE EACH ARGUMENT
case $1 in
run) # run dorie
RUN=1
shift
if [[ $# > 0 ]]; then
INIFILE=$1
else
echo "Error: No parameter file specified"
exit
fi
shift
if [[ $# > 0 ]]; then
case $1 in
--parallel|--par)
shift
if [[ $# > 0 ]]; then
PARALLEL=$1
else
echo "Error: Specify the number of threads when using --parallel"
exit
fi
;;
--sequential|--seq)
PARALLEL=0
;;
*)
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
#!/usr/bin/env python
import os
import shutil
import argparse
import warnings
import subprocess
import multiprocessing
try:
input = raw_input
except NameError:
pass
# paths set by cmake
DORIEDIR = "@CMAKE_BINARY_DIR@"
MPIEXEC = "@MPIEXEC@"
MPIEXEC_NUMPROC_FLAG = "@MPIEXEC_NUMPROC_FLAG@"
MPIEXEC_PREFLAG = "@MPIEXEC_PREFLAG@"
MPIEXEC_POSTFLAGS = "@MPIEXEC_POSTFLAGS@"
#
DORIE_EXECUTABLE = os.path.join(DORIEDIR, "dune/dorie/dorie")
PARAMETERDIR = os.path.join(DORIEDIR, "doc/default_files")
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]
def run(args):
if not os.path.isfile(args["config"]):
raise IOError("Configuration file {} not found".format(args["config"]))
if args["parallel"] == 1:
subprocess.call([DORIE_EXECUTABLE, args["config"]])
else:
print([MPIRUN(args["parallel"],DORIE_EXECUTABLE) + [args["config"]]])
subprocess.call(MPIRUN(args["parallel"],DORIE_EXECUTABLE,args["config"]))
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):
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"]))
if args["parallel"] == 1:
subprocess.call([DORIE_PYTHON, "pf_from_file.py", "--param", args["config"]])
else:
raise NotImplementedError
def plot(args):
if not os.path.isfile(args["vtk"]):
raise IOError("File {} not found".format(args["vtk"]))
if args["var"]:
subprocess.call([DORIE_PYTHON, "plot_vtk.py", "-f", args["vtk"], "--var", args["var"]])
else:
subprocess.call([DORIE_PYTHON, "plot_vtk.py", "-f", args["vtk"]])
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(description="DORiE command line interface",
epilog="For more information check our online documentation:\n"
"http://dorie-docs.bitballoon.com (password: 'richards')"
)
subparsers = parser.add_subparsers(title="Commands")
parser_run = subparsers.add_parser('run',help="start dorie")
parser_run.add_argument('config',help="DORiE configuration file. Can be created with 'dorie create'.")
parser_run.add_argument('--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.set_defaults(func=run)
parser_create = subparsers.add_parser('create', help="Copy example configuration to current folder.")
parser_create.set_defaults(func=create)
parser_pfg = subparsers.add_parser('pfg', help="Start parameter field generator.")
parser_pfg.add_argument('config',
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,
help="Run in parallel on N processes. If N is not specified, run on all available CPU threads.")
parser_pfg.set_defaults(func=pfg)
parser_plot = subparsers.add_parser('plot', help="Plot a preview of a VTK file created by DORiE.")
parser_plot.add_argument('vtk', help="Input VTK file")
parser_plot.add_argument('--var', nargs='*', required=False)
parser_plot.set_defaults(func=plot)
args = parser.parse_args()
args.func(vars(args))
except Exception as e:
print("dorie failed with ({0}) warning(s) and ({1}) error(s)".format(len(warn),1))
raise
......@@ -17,12 +17,12 @@ endfunction()
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)
message(FATAL_ERROR "Parameter scraper failed. DORiE can not be built.")
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)
message(FATAL_ERROR "Parameter scraper failed. DORiE can not be built.")
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,
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@"
MPIRUN = "@MPIEXEC@ @MPIEXEC_NUMPROC_FLAG@ {} @MPIEXEC_PREFLAG@ {} @MPIEXEC_POSTFLAGS@"
if __name__ == "__main__":
try: # catch all exceptions we we can output an error message
......@@ -21,6 +22,7 @@ if __name__ == "__main__":
# PARSE COMMAND LINE
parser = argparse.ArgumentParser()
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)
args = vars(parser.parse_args())
......@@ -40,7 +42,10 @@ if __name__ == "__main__":
CSVConverter(args["param"])
elif params["generator"] == "fft":
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:
raise RuntimeError("FFT Field generator failed")
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