Remove generated binaries and python files

parent a77cc3e8
import os
import sys
import shutil
import subprocess
try: # Python 2.x compatibility
input = raw_input
except NameError:
pass
# paths set by cmake
DORIEDIR = "/home/saospina/Codes/DUNE_INSTALL/Debug/dorie"
MPIEXEC = "/usr/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", "param.yml"):
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)
#!/usr/bin/env python3
from __future__ import absolute_import
import os
import sys
import argparse
import warnings
import subprocess
import multiprocessing
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.
"""
# paths set by CMake
DORIEDIR = "/Users/soilros/Codes/DORIE_INSTALL/Debug/dorie"
MPIEXEC = "/usr/local/bin/mpiexec"
MPIEXEC_NUMPROC_FLAG = "-n"
MPIEXEC_PREFLAG = ""
MPIEXEC_POSTFLAGS = ""
#
RFG_EXEC = os.path.join(DORIEDIR, "dune/dorie-rfg/dorie-rfg")
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]
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('param',help='The configuration file holding all parameterization information')
parser.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.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.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:
if args["parallel"] == 1:
subprocess.check_call([RFG_EXEC,args["param"]])
else:
subprocess.check_call(MPIRUN(args["parallel"], RFG_EXEC, args["param"], mpi_flags=args["mpi_flags"]))
except subprocess.CalledProcessError:
print("FFT Field generator failed")
sys.exit(1)
out_path = cp.get("generator.fft","outputPath")
FFTH5Converter(args["param"], out_path + "/yfield.stoch.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
#!/usr/bin/env python3
from __future__ import absolute_import
import sys
import os
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 = "/Users/soilros/Codes/DORIE_INSTALL/Debug/dorie"
#
DORIE_WRAPPER = os.path.join(DORIEDIR, "bin/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))
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