diff --git a/examples/gwk_compressor_casegeneration/Snakefile b/examples/gwk_compressor_casegeneration/Snakefile index b019c22eb8610fc106ca3bd5073cd773665f2b82..03809d98709579875815ca44afff092702725d89 100644 --- a/examples/gwk_compressor_casegeneration/Snakefile +++ b/examples/gwk_compressor_casegeneration/Snakefile @@ -11,8 +11,10 @@ validate(config,"config.schema.yaml") basedir = workflow.current_basedir # declare a dataframe to be a paramspace -paramspace = Paramspace(pd.read_csv("params.tsv", sep="\t")) -paramspace.param_sep="-" +PARAMS=pd.read_csv("caseparams.tsv", sep="\t") +validate(PARAMS, "case.schema.yaml") +paramspace = Paramspace(PARAMS) +#paramspace.param_sep="-" #paramspace.pattern="{}~{}~{}" def create_filelist_from_template(template): @@ -38,30 +40,29 @@ rule all: # Aggregate over entire parameter space (or a subset thereof if needed) # of course, something like this can happen anywhere in the workflow (not # only at the end). - #create_filelist_from_template(TEMPLATE) - "99_Report/parametrization.txt" - #expand("results/plots/{params}.pdf", params=paramspace.instance_patterns) - + *[f"{instance_pattern}/{file}" for instance_pattern in paramspace.instance_patterns for file in DATASETS] rule copy_template: output: - #todo: is there a readable dataformat alternative (csv) instead of pickle? - #dynamic("01_case/{case_type}/{case_files}"), - create_filelist_from_template(TEMPLATE) - #dynamic("01_case/{level_1}/{level_2}"), -# "01_case/check.txt" + # format a wildcard pattern like "alpha~{alpha}/beta~{beta}/gamma~{gamma}" + # into a file path, with alpha, beta, gamma being the columns of the data frame + *[f"{paramspace.wildcard_pattern}/{file}" for file in DATASETS] params: case_type = config["case_params"]["case_type"], - case_parameters = config["case_params"]["parameters"] + # automatically translate the wildcard values into an instance of the param space + # in the form of a dict (here: {"alpha": ..., "beta": ..., "gamma": ...}) + simulation=paramspace.instance run: from case_creation import copy_template - copy_template(output,params["case_type"],params["case_parameters"]) + copy_template(output,params["case_type"],params["simulation"]) +""" rule set_paras: input: - create_filelist_from_template(TEMPLATE) + [os.path.join("01_case",i) for i in create_filelist_from_template(TEMPLATE)] output: "99_Report/parametrization.txt" run: with open(output[0],"w") as fhandle: fhandle.write(" ") +""" diff --git a/examples/gwk_compressor_casegeneration/case.schema.yaml b/examples/gwk_compressor_casegeneration/case.schema.yaml new file mode 100644 index 0000000000000000000000000000000000000000..db7b14e0e8061aab85c689964af2bf258663c727 --- /dev/null +++ b/examples/gwk_compressor_casegeneration/case.schema.yaml @@ -0,0 +1,103 @@ +$schema: "http://json-schema.org/draft-06/schema#" + +description: case configuration file + +type: object +properties: + OUTFLOW_PRESSURE: + type: number + default: 101350 + GLOBAL_TOLERANCE: + type: number + default: 0.00000012 + LENGTH_YPER: + type: number + default: 0.0765 + STAGPOINT_ANNOMALLYFIX: + type: string + default: "yes_placeholder" + QUASIUNSTEADYMODEL: + type: string + default: "no_placeholder" + STAGPOINT_ANNOMALLYFIX: + type: string + default: "yes_placeholder" + QUASIUNSTEADYMODEL: + type: string + default: "yes_placeholder" + WAVINESSMODEL: + type: string + default: "no_placeholder" + VERSION_TWONULLNULLNINE: + type: string + default: "no_placeholder" + HEATFLUXMODEL: + type: string + default: "no_placeholder" + PRANDTLTURBULENT: + type: string + default: "no_placeholder" + ROTATIONAL_EFF: + type: string + default: "no_placeholder" + TRANSITIONMODEL: + type: string + default: "no_placeholder" + VGJMODEL: + type: string + default: "no_placeholder" + ACCURACY_ORDER: + type: number + default: 2 + OUTLET_MFLOW: + type: number + default: 0.00035 + min: 0 + OUTLET_RADIAL_EQUI: + type: string + default: "no_placeholder" + INLET_TOTAL_PRESSURE: + type: number + default: 283.15 + min: 0 + VEL_YANGLE: + type: number + default: 0 + ABS_STAGN_TEMP: + type: number + default: 300 + min: 0 + TURBULENTINTENSITY: + type: number + default: 0.04 + min: 0 + TURBULENTLENGTHSCALE: + type: number + default: 0.002 + min: 0 + INLET_TEMP: + type: number + default: 300 + INLET_VELX: + type: number + default: 30 + INLET_VELY: + type: number + default: 40 + INLET_VELZ: + type: number + default: 0 + OUTFLOW_TEMP: + type: number + default: 290 + OUTFLOW_VELX: + type: number + default: 40 + OUTFLOW_VELY: + type: number + default: 30 + OUTFLOW_VELZ: + type: number + default: 0 +required: [] +additionalProperties: false diff --git a/examples/gwk_compressor_casegeneration/case_creation.py b/examples/gwk_compressor_casegeneration/case_creation.py index b21927a6323da13401579bccdca5e69454719cf1..821996e5122395fd7bce6f3ef5c6cdace2ec8767 100644 --- a/examples/gwk_compressor_casegeneration/case_creation.py +++ b/examples/gwk_compressor_casegeneration/case_creation.py @@ -9,10 +9,16 @@ import warnings from ntrfc.utils.dictionaries.dict_utils import setInDict from ntrfc.utils.dictionaries.dict_utils import nested_dict_pairs_iterator +def TEMPLATEDIR(): + import ntrfc.database.case_templates as templates + + templatepath = os.path.join(os.path.dirname(templates.__file__)) + return templatepath + #todo: at least the next two lines have to be fixed -TEMPLATEDIR = r"D:\CodingProjects\NTRfC\ntrfc\database\case_templates" -path_to_sim=r"D:\CodingProjects\NTRfC\examples\gwk_compressor_casegeneration\01_case" -TEMPLATES = [i for i in os.listdir(TEMPLATEDIR) if os.path.isdir(os.path.join(TEMPLATEDIR, i))] +path_to_sim=r"D:\CodingProjects\NTRfC\examples\gwk_compressor_casegeneration" + +TEMPLATES = [i for i in os.listdir(TEMPLATEDIR()) if os.path.isdir(os.path.join(TEMPLATEDIR(), i))] def get_directory_structure(rootdir): """ @@ -121,12 +127,12 @@ def inplace_change(filename, old_string, new_string): with open(filename) as f: s = f.read() if old_string not in s: - print('"{old_string}" not found in {filename}.'.format(**locals())) + #print('"{old_string}" not found in {filename}.'.format(**locals())) return # Safely write the changed content, if found in the file with open(filename, 'w') as f: - print('Changing "{old_string}" to "{new_string}" in {filename}'.format(**locals())) + print('Inserting "{old_string}" to "{new_string}" in {filename}'.format(**locals())) s = s.replace(old_string, new_string) f.write(s) @@ -142,8 +148,8 @@ def copy_template(output, template, paras): found = template in TEMPLATES assert found, "template unknown. check ntrfc.database.casetemplates directory" - case_structure = get_directory_structure(os.path.join(TEMPLATEDIR, template)) - variables = find_vars_opts(case_structure, "var", list(nested_dict_pairs_iterator(case_structure)),os.path.join(TEMPLATEDIR)) + case_structure = get_directory_structure(os.path.join(TEMPLATEDIR(), template)) + variables = find_vars_opts(case_structure, "var", list(nested_dict_pairs_iterator(case_structure)),os.path.join(TEMPLATEDIR())) defined, undefined, used, unused = check_settings_necessarities(variables, paras) print("found ", str(len(defined)), " defined parameters") @@ -153,15 +159,13 @@ def copy_template(output, template, paras): if len(undefined)>0: warnings.warn("undefined variables") - warnings.warn(str(undefined)) return -1 if len(unused)>0: warnings.warn("unused "+str(len(unused))) - warnings.warn(str(unused)) for fpath in output: - template_fpath = os.path.join(TEMPLATEDIR,fpath) + template_fpath = os.path.join(TEMPLATEDIR(),fpath) shutil.copyfile(template_fpath, fpath) for para in used: - inplace_change(fpath,para,paras[para]) + inplace_change(fpath,para,str(paras[para])) diff --git a/examples/gwk_compressor_casegeneration/caseparams.tsv b/examples/gwk_compressor_casegeneration/caseparams.tsv new file mode 100644 index 0000000000000000000000000000000000000000..7dc27ca070e21d58442d5bbe42b075f93d2fa078 --- /dev/null +++ b/examples/gwk_compressor_casegeneration/caseparams.tsv @@ -0,0 +1,2 @@ +OUTFLOW_PRESSURE +120000 diff --git a/examples/gwk_compressor_casegeneration/casesettings.yaml b/examples/gwk_compressor_casegeneration/casesettings.yaml index eb872a6a0bee7a8a5866cf82fc749c5eeca35568..ce1ddf9d0a010a40fc4d74ab68d83c48257ce034 100644 --- a/examples/gwk_compressor_casegeneration/casesettings.yaml +++ b/examples/gwk_compressor_casegeneration/casesettings.yaml @@ -1,5 +1,2 @@ case_params: case_type: "trace-compressor-cascade-ras" - parameters: - LENGTH_YPER: 0.0765 - diff --git a/examples/gwk_compressor_casegeneration/config.schema.yaml b/examples/gwk_compressor_casegeneration/config.schema.yaml index c222b379ff16f2f656ea7159190dcdadaff2341c..81a722dc72ef71aab5918e16ad63461fb794025f 100644 --- a/examples/gwk_compressor_casegeneration/config.schema.yaml +++ b/examples/gwk_compressor_casegeneration/config.schema.yaml @@ -10,112 +10,10 @@ properties: properties: case_type: type: string - parameters: - type: object - properties: - TRACE_CONTROLINPUT: - type: string - default: "" - OUTFLOW_PRESSURE: - type: number - default: 101350 - GLOBAL_TOLERANCE: - type: number - default: 0.00000012 - LENGTH_YPER: - type: number - STAGPOINT_ANNOMALLYFIX: - type: string - default: "yes_placeholder" - QUASIUNSTEADYMODEL: - type: string - default: "no_placeholder" - STAGPOINT_ANNOMALLYFIX: - type: string - default: "yes_placeholder" - QUASIUNSTEADYMODEL: - type: string - default: "yes_placeholder" - WAVINESSMODEL: - type: string - default: "no_placeholder" - VERSION_TWONULLNULLNINE: - type: string - default: "no_placeholder" - HEATFLUXMODEL: - type: string - default: "no_placeholder" - PRANDTLTURBULENT: - type: string - default: "no_placeholder" - ROTATIONAL_EFF: - type: string - default: "no_placeholder" - TRANSITIONMODEL: - type: string - default: "no_placeholder" - VGJMODEL: - type: string - default: "no_placeholder" - ACCURACY_ORDER: - type: number - default: 2 - OUTLET_MFLOW: - type: number - default: 0.00035 - min: 0 - OUTLET_RADIAL_EQUI: - type: string - default: "no_placeholder" - INLET_TOTAL_PRESSURE: - type: number - default: 283.15 - min: 0 - VEL_YANGLE: - type: number - default: 0 - ABS_STAGN_TEMP: - type: number - default: 300 - min: 0 - TURBULENTINTENSITY: - type: number - default: 0.04 - min: 0 - TURBULENTLENGTHSCALE: - type: number - default: 0.002 - min: 0 - INLET_TEMP: - type: number - default: 300 - INLET_VELX: - type: number - default: 30 - INLET_VELY: - type: number - default: 40 - INLET_VELZ: - type: number - default: 0 - OUTFLOW_TEMP: - type: number - default: 290 - OUTFLOW_VELX: - type: number - default: 40 - OUTFLOW_VELY: - type: number - default: 30 - OUTFLOW_VELZ: - type: number - default: 0 - required: - - LENGTH_YPER + pattern : trace-compressor-cascade-ras required: - case_type - - parameters required: - case_params diff --git a/examples/gwk_compressor_casegeneration/params.tsv b/examples/gwk_compressor_casegeneration/params.tsv deleted file mode 100644 index 14dee8cd44c6a6c1085c3a3a4ed6cee58e862193..0000000000000000000000000000000000000000 --- a/examples/gwk_compressor_casegeneration/params.tsv +++ /dev/null @@ -1,3 +0,0 @@ -param_1 param_2 param_3 -1 2 3 -4 3 2 diff --git a/examples/gwk_compressor_casegeneration/snakedev.py b/examples/gwk_compressor_casegeneration/snakedev.py index cc8520c3af144a37d1471b0fb096dfd979431a0b..39bcfd514b6d98644e4c0a3a98c48fde39d1625f 100644 --- a/examples/gwk_compressor_casegeneration/snakedev.py +++ b/examples/gwk_compressor_casegeneration/snakedev.py @@ -1,6 +1,3 @@ import snakemake -c = snakemake.load_configfile("casesettings.yaml") -snakemake.utils.validate(c,'config.schema.yaml') - snakemake.snakemake(snakefile="Snakefile",) diff --git a/ntrfc/database/case_templates/trace-compressor-cascade-ras/input/TRACE_control.input b/ntrfc/database/case_templates/trace-compressor-cascade-ras/input/TRACE_control.input index 0b52979f2a6802b337369ec64e94c68795a630fc..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/ntrfc/database/case_templates/trace-compressor-cascade-ras/input/TRACE_control.input +++ b/ntrfc/database/case_templates/trace-compressor-cascade-ras/input/TRACE_control.input @@ -1 +0,0 @@ -<var TRACE_CONTROLINPUT var> \ No newline at end of file diff --git a/ntrfc/database/case_templates/trace-compressor-cascade-ras/input/verdichter.jou b/ntrfc/database/case_templates/trace-compressor-cascade-ras/input/verdichter.jou index b2cd0c8434c13efded177057676f8379adbe9d3d..93f4ff0ba2132ced393ffa4c1c43c6daab77ab13 100644 --- a/ntrfc/database/case_templates/trace-compressor-cascade-ras/input/verdichter.jou +++ b/ntrfc/database/case_templates/trace-compressor-cascade-ras/input/verdichter.jou @@ -1,6 +1,6 @@ # journal recorded by gmc_v9.1.8 at 2021/06/11 14:58:57 -gmc -> open '<var MESHNAME var>' +gmc -> open mesh.cgns gmc -> repair