diff --git a/doc/examples/fluidsimfoam-multi-region-snappy/src/fluidsimfoam_multi_region_snappy/output.py b/doc/examples/fluidsimfoam-multi-region-snappy/src/fluidsimfoam_multi_region_snappy/output.py index d36593169ba4f2a225668b21752e4f963b5067fc_ZG9jL2V4YW1wbGVzL2ZsdWlkc2ltZm9hbS1tdWx0aS1yZWdpb24tc25hcHB5L3NyYy9mbHVpZHNpbWZvYW1fbXVsdGlfcmVnaW9uX3NuYXBweS9vdXRwdXQucHk=..6de176599a7969cfa8a87f850633506a94729697_ZG9jL2V4YW1wbGVzL2ZsdWlkc2ltZm9hbS1tdWx0aS1yZWdpb24tc25hcHB5L3NyYy9mbHVpZHNpbWZvYW1fbXVsdGlfcmVnaW9uX3NuYXBweS9vdXRwdXQucHk= 100644 --- a/doc/examples/fluidsimfoam-multi-region-snappy/src/fluidsimfoam_multi_region_snappy/output.py +++ b/doc/examples/fluidsimfoam-multi-region-snappy/src/fluidsimfoam_multi_region_snappy/output.py @@ -10,7 +10,7 @@ "bottomAir/fvSolution", "controlDict", "decomposeParDict", - "decomposeParDict.6", + "decomposeParDict.mesh", "fvSchemes", "fvSolution", "heater/changeDictionaryDict", @@ -77,7 +77,6 @@ ) # remove these lines to get fluidsimfoam default helpers - _helper_decompose_par_dict = None _helper_turbulence_properties = None _complete_params_block_mesh_dict = None @@ -88,3 +87,17 @@ "package-data(fluidsimfoam_multi_region_snappy.templates)/geom.stl.gz" " -> constant/triSurface/geom.stl.gz" ) + + _helper_decompose_par_dict = Output._helper_decompose_par_dict.new() + _helper_decompose_par_dict.add_region( + "heater", + { + "numberOfSubdomains": 1, + "method": "simple", + "coeffs": {"n": [1, 1, 1]}, + }, + ) + + _helper_decompose_par_dict_mesh = Output._helper_decompose_par_dict.new( + nsubdoms=6, method="scotch", key_in_params="parallel_mesh" + ) diff --git a/doc/examples/fluidsimfoam-multi-region-snappy/src/fluidsimfoam_multi_region_snappy/templates/system/decomposeParDict.6.jinja b/doc/examples/fluidsimfoam-multi-region-snappy/src/fluidsimfoam_multi_region_snappy/templates/system/decomposeParDict.6.jinja deleted file mode 100644 index d36593169ba4f2a225668b21752e4f963b5067fc_ZG9jL2V4YW1wbGVzL2ZsdWlkc2ltZm9hbS1tdWx0aS1yZWdpb24tc25hcHB5L3NyYy9mbHVpZHNpbWZvYW1fbXVsdGlfcmVnaW9uX3NuYXBweS90ZW1wbGF0ZXMvc3lzdGVtL2RlY29tcG9zZVBhckRpY3QuNi5qaW5qYQ==..0000000000000000000000000000000000000000 --- a/doc/examples/fluidsimfoam-multi-region-snappy/src/fluidsimfoam_multi_region_snappy/templates/system/decomposeParDict.6.jinja +++ /dev/null @@ -1,11 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - object decomposeParDict; -} - -numberOfSubdomains 6; - -method scotch; diff --git a/doc/examples/fluidsimfoam-multi-region-snappy/src/fluidsimfoam_multi_region_snappy/templates/system/decomposeParDict.jinja b/doc/examples/fluidsimfoam-multi-region-snappy/src/fluidsimfoam_multi_region_snappy/templates/system/decomposeParDict.jinja deleted file mode 100644 index d36593169ba4f2a225668b21752e4f963b5067fc_ZG9jL2V4YW1wbGVzL2ZsdWlkc2ltZm9hbS1tdWx0aS1yZWdpb24tc25hcHB5L3NyYy9mbHVpZHNpbWZvYW1fbXVsdGlfcmVnaW9uX3NuYXBweS90ZW1wbGF0ZXMvc3lzdGVtL2RlY29tcG9zZVBhckRpY3QuamluamE=..0000000000000000000000000000000000000000 --- a/doc/examples/fluidsimfoam-multi-region-snappy/src/fluidsimfoam_multi_region_snappy/templates/system/decomposeParDict.jinja +++ /dev/null @@ -1,29 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - object decomposeParDict; -} - -numberOfSubdomains 4; - -method scotch; - -regions -{ - heater - { - numberOfSubdomains 1; - method simple; - coeffs - { - n - ( - 1 - 1 - 1 - ); - } - } -} diff --git a/doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/Allrun-parallel b/doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/Allrun-parallel index d36593169ba4f2a225668b21752e4f963b5067fc_ZG9jL2V4YW1wbGVzL2ZsdWlkc2ltZm9hbS1tdWx0aS1yZWdpb24tc25hcHB5L3Rlc3RzL3NhdmVkX2Nhc2VzL2Nhc2UwL0FsbHJ1bi1wYXJhbGxlbA==..6de176599a7969cfa8a87f850633506a94729697_ZG9jL2V4YW1wbGVzL2ZsdWlkc2ltZm9hbS1tdWx0aS1yZWdpb24tc25hcHB5L3Rlc3RzL3NhdmVkX2Nhc2VzL2Nhc2UwL0FsbHJ1bi1wYXJhbGxlbA== 100755 --- a/doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/Allrun-parallel +++ b/doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/Allrun-parallel @@ -10,7 +10,7 @@ rm -rf constant/polyMesh/sets # For meshing only -decompDict="-decomposeParDict system/decomposeParDict.6" +decompDict="-decomposeParDict system/decomposeParDict.mesh" runApplication blockMesh diff --git a/doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/system/decomposeParDict b/doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/system/decomposeParDict index d36593169ba4f2a225668b21752e4f963b5067fc_ZG9jL2V4YW1wbGVzL2ZsdWlkc2ltZm9hbS1tdWx0aS1yZWdpb24tc25hcHB5L3Rlc3RzL3NhdmVkX2Nhc2VzL2Nhc2UwL3N5c3RlbS9kZWNvbXBvc2VQYXJEaWN0..6de176599a7969cfa8a87f850633506a94729697_ZG9jL2V4YW1wbGVzL2ZsdWlkc2ltZm9hbS1tdWx0aS1yZWdpb24tc25hcHB5L3Rlc3RzL3NhdmVkX2Nhc2VzL2Nhc2UwL3N5c3RlbS9kZWNvbXBvc2VQYXJEaWN0 100644 --- a/doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/system/decomposeParDict +++ b/doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/system/decomposeParDict @@ -3,6 +3,7 @@ version 2.0; format ascii; class dictionary; + location "system"; object decomposeParDict; } diff --git a/doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/system/decomposeParDict.6 b/doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/system/decomposeParDict.mesh similarity index 92% rename from doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/system/decomposeParDict.6 rename to doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/system/decomposeParDict.mesh index d36593169ba4f2a225668b21752e4f963b5067fc_ZG9jL2V4YW1wbGVzL2ZsdWlkc2ltZm9hbS1tdWx0aS1yZWdpb24tc25hcHB5L3Rlc3RzL3NhdmVkX2Nhc2VzL2Nhc2UwL3N5c3RlbS9kZWNvbXBvc2VQYXJEaWN0LjY=..6de176599a7969cfa8a87f850633506a94729697_ZG9jL2V4YW1wbGVzL2ZsdWlkc2ltZm9hbS1tdWx0aS1yZWdpb24tc25hcHB5L3Rlc3RzL3NhdmVkX2Nhc2VzL2Nhc2UwL3N5c3RlbS9kZWNvbXBvc2VQYXJEaWN0Lm1lc2g= 100644 --- a/doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/system/decomposeParDict.6 +++ b/doc/examples/fluidsimfoam-multi-region-snappy/tests/saved_cases/case0/system/decomposeParDict.mesh @@ -3,6 +3,7 @@ version 2.0; format ascii; class dictionary; + location "system"; object decomposeParDict; } diff --git a/doc/examples/fluidsimfoam-multi-region-snappy/tests/test_multi_region_snappy.py b/doc/examples/fluidsimfoam-multi-region-snappy/tests/test_multi_region_snappy.py index d36593169ba4f2a225668b21752e4f963b5067fc_ZG9jL2V4YW1wbGVzL2ZsdWlkc2ltZm9hbS1tdWx0aS1yZWdpb24tc25hcHB5L3Rlc3RzL3Rlc3RfbXVsdGlfcmVnaW9uX3NuYXBweS5weQ==..6de176599a7969cfa8a87f850633506a94729697_ZG9jL2V4YW1wbGVzL2ZsdWlkc2ltZm9hbS1tdWx0aS1yZWdpb24tc25hcHB5L3Rlc3RzL3Rlc3RfbXVsdGlfcmVnaW9uX3NuYXBweS5weQ== 100644 --- a/doc/examples/fluidsimfoam-multi-region-snappy/tests/test_multi_region_snappy.py +++ b/doc/examples/fluidsimfoam-multi-region-snappy/tests/test_multi_region_snappy.py @@ -10,6 +10,8 @@ def test_generate_base_case(): params = Simul.create_default_params() params.output.sub_directory = "tests_fluidsimfoam/multi-region-snappy" + params.parallel.nsubdoms = 4 + params.parallel.method = "scotch" sim = Simul(params) check_saved_case(here / "saved_cases/case0", sim.path_run) @@ -21,7 +23,5 @@ # change parameters to get a very short and small simulation params.control_dict.end_time = 0.002 sim = Simul(params) - # for now we remove decomposeParDict to run in sequential - (sim.path_run / "system/decomposeParDict").unlink() sim.make.exec("run") sim.make.exec("clean") diff --git a/src/fluidsimfoam/foam_input_files/decompose_par.py b/src/fluidsimfoam/foam_input_files/decompose_par.py index d36593169ba4f2a225668b21752e4f963b5067fc_c3JjL2ZsdWlkc2ltZm9hbS9mb2FtX2lucHV0X2ZpbGVzL2RlY29tcG9zZV9wYXIucHk=..6de176599a7969cfa8a87f850633506a94729697_c3JjL2ZsdWlkc2ltZm9hbS9mb2FtX2lucHV0X2ZpbGVzL2RlY29tcG9zZV9wYXIucHk= 100644 --- a/src/fluidsimfoam/foam_input_files/decompose_par.py +++ b/src/fluidsimfoam/foam_input_files/decompose_par.py @@ -1,4 +1,5 @@ """Helper to create decomposeParDict files""" +from copy import deepcopy from math import prod @@ -3,6 +4,11 @@ from math import prod -from fluidsimfoam.foam_input_files import FileHelper, FoamInputFile +from fluidsimfoam.foam_input_files import ( + FileHelper, + FoamInputFile, + _complete_params_dict, + _update_dict_with_params, +) supported_methods = set( [ @@ -39,7 +45,8 @@ self, nsubdoms=1, method="scotch", + key_in_params="parallel", ): self.nsubdoms = nsubdoms check_method(method) self.method = method @@ -42,7 +49,12 @@ ): self.nsubdoms = nsubdoms check_method(method) self.method = method + self.key_in_params = key_in_params + self.regions = {} + + def add_region(self, name, data): + self.regions[name] = data def complete_params(self, params): par_params = params._set_child( @@ -46,5 +58,5 @@ def complete_params(self, params): par_params = params._set_child( - "parallel", + self.key_in_params, attribs={ @@ -50,5 +62,5 @@ attribs={ - "nsubdoms": 1, + "nsubdoms": self.nsubdoms, "method": self.method, "nsubdoms_xyz": None, "order": "xyz", @@ -59,4 +71,7 @@ par_params._set_child("scotch", attribs={"strategy": None}) + if self.regions: + _complete_params_dict(par_params, "regions", self.regions) + def make_tree(self, params): @@ -62,5 +77,5 @@ def make_tree(self, params): - par_params = params.parallel + par_params = params[self.key_in_params] nsubdoms = par_params.nsubdoms if nsubdoms == 1: @@ -122,4 +137,10 @@ tree.init_from_py_objects(data) + if self.regions: + regions = deepcopy(self.regions) + _update_dict_with_params(regions, par_params.regions) + tree.set_child("regions", {}) + tree["regions"].init_from_py_objects(regions) + return tree @@ -125,1 +146,10 @@ return tree + + def new(self, nsubdoms=None, method=None, key_in_params=None): + if nsubdoms is None: + nsubdoms = self.nsubdoms + if method is None: + method = self.method + if key_in_params is None: + key_in_params = self.key_in_params + return type(self)(nsubdoms, method, key_in_params)