From f708467da5c2f6c9b61b98704333de1f2425495e Mon Sep 17 00:00:00 2001 From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de> Date: Mon, 29 Aug 2016 17:40:38 +0200 Subject: [PATCH] Read options from an ini file --- python/dune/perftool/options.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/python/dune/perftool/options.py b/python/dune/perftool/options.py index 7041c587..375d3ab9 100644 --- a/python/dune/perftool/options.py +++ b/python/dune/perftool/options.py @@ -33,12 +33,7 @@ def get_form_compiler_arguments(): parser.add_argument("--print-transformations", action="store_true", help="print out dot files after ufl tree transformations") parser.add_argument("--print-transformations-dir", type=str, help="place where to put dot files (can be omitted)") parser.add_argument("--diagonal-transformation-matrix", action="store_true", help="set option if the jacoby of the transformation is diagonal (axiparallel grids)") - - # These are the options that I deemed necessary in uflpdelab -# parser.add_argument("--param-class-file", type=str, help="The filename for the generated parameter class header") -# parser.add_argument("--export-trafo-graphs", action="store_true", help="export expression graphs after the application of each single transformation") -# parser.add_argument("--parameter-tree", action="store_true", help="have the generated local operate take a Dune::ParameterTree as constructor argument") -# parser.add_argument("--inifile", type=str, help="The inifile that this program's driver should be hardcoded to. Omit to use a commandline argument ini file") + parser.add_argument("--ini-file", type=str, help="An inifile to use. A generated driver will be hard-coded to it, a [formcompiler] section will be used as default values to form compiler arguments (use snake case)") # Modify the positional argument to not be a list args = vars(parser.parse_args()) @@ -52,6 +47,8 @@ def get_form_compiler_arguments(): args["driver_file"] = os.path.abspath(args["driver_file"]) if args["operator_file"]: args["operator_file"] = os.path.abspath(args["operator_file"]) + if args["ini_file"]: + args["ini_file"] = os.path.abspath(args["ini_file"]) # Return the argument dict. This result is memoized to turn all get_option calls into simple dict lookups. return args @@ -68,6 +65,14 @@ def init_option_dict(): _option_dict.update(get_form_compiler_arguments()) _arguments_read = True + # Read arguments from the given inifile + if args["ini_file"]: + from dune.common.parametertree.parser import parse_ini_file + inifile = parse_ini_file(args["ini_file"]) + for key, value in inifile["formcompiler"]: + if key not in _option_dict: + _option_dict[key] = value + def set_option(key, value): """Add the key value pair to the options. -- GitLab