@@ -133,8 +133,19 @@ runCommand splitMeshRegions -cellZones -overwrite
133133env -u PYTHONPATH -u PYTHONHOME python3 << 'PYEOF '
134134import re, os, glob
135135
136- FLUID_REGION = '%(multiRegionFluidNames/0%)'
137- SOLID_REGION = '%(multiRegionSolidNames/0%)'
136+ FLUID_REGIONS = []
137+ SOLID_REGIONS = []
138+ try:
139+ with open('constant/regionProperties') as f:
140+ txt = f.read()
141+ fm = re.search(r'fluid\s*\(\s*([^)]*?)\s*\)', txt)
142+ sm = re.search(r'solid\s*\(\s*([^)]*?)\s*\)', txt)
143+ if fm:
144+ FLUID_REGIONS = fm.group(1).split()
145+ if sm:
146+ SOLID_REGIONS = sm.group(1).split()
147+ except FileNotFoundError:
148+ pass
138149
139150def fix_samplemode_to_ami(bfile):
140151 """Upgrade sampleMode nearestPatchFace → nearestPatchFaceAMI for parallel CHT."""
@@ -151,6 +162,14 @@ def get_mapped_patches(bfile):
151162 txt = f.read()
152163 return re.findall(r'\n\s+(\w+)\s*\n\s*\{[^}]*type\s+mappedWall', txt)
153164
165+ def get_nonmapped_patches(bfile):
166+ """Return names of all non-mappedWall patches in boundary file."""
167+ with open(bfile) as f:
168+ txt = f.read()
169+ all_patches = re.findall(r'\n (\w+)\n \{', txt)
170+ mapped = set(re.findall(r'\n\s+(\w+)\s*\n\s*\{[^}]*type\s+mappedWall', txt))
171+ return [p for p in all_patches if p not in mapped]
172+
154173def patch_present(field_txt, patch_name):
155174 return bool(re.search(r'\n\s+' + re.escape(patch_name) + r'\s*\n\s*\{', field_txt))
156175
@@ -206,16 +225,36 @@ def add_missing_patches_to_fields(region, patches, is_fluid):
206225 elif fname in ('k', 'epsilon', 'omega', 'nuTilda', 'alphat') and is_fluid:
207226 add_patch_entry(field_file, patch, ['type zeroGradient;'])
208227
209- fix_samplemode_to_ami('constant/' + FLUID_REGION + '/polyMesh/boundary')
210- fix_samplemode_to_ami('constant/' + SOLID_REGION + '/polyMesh/boundary')
228+ for r in FLUID_REGIONS:
229+ fix_samplemode_to_ami('constant/' + r + '/polyMesh/boundary')
230+ for r in SOLID_REGIONS:
231+ fix_samplemode_to_ami('constant/' + r + '/polyMesh/boundary')
211232
212233# Add 0/ field entries for all mappedWall interface patches splitMeshRegions created
213- fluid_mapped = [p for p in get_mapped_patches('constant/' + FLUID_REGION + '/polyMesh/boundary')
214- if p != 'defaultFaces']
215- solid_mapped = [p for p in get_mapped_patches('constant/' + SOLID_REGION + '/polyMesh/boundary')
216- if p != 'defaultFaces']
217- add_missing_patches_to_fields(FLUID_REGION, fluid_mapped, is_fluid=True)
218- add_missing_patches_to_fields(SOLID_REGION, solid_mapped, is_fluid=False)
234+ for r in FLUID_REGIONS:
235+ mapped = [p for p in get_mapped_patches('constant/' + r + '/polyMesh/boundary')
236+ if p != 'defaultFaces']
237+ add_missing_patches_to_fields(r, mapped, is_fluid=True)
238+ for r in SOLID_REGIONS:
239+ mapped = [p for p in get_mapped_patches('constant/' + r + '/polyMesh/boundary')
240+ if p != 'defaultFaces']
241+ add_missing_patches_to_fields(r, mapped, is_fluid=False)
242+
243+ # Add default BC entries for non-mapped patches in solid regions that aren't yet in
244+ # the field files (e.g. inlet/outlet/wall faces that fall inside a solid volume after
245+ # splitMeshRegions). OpenFOAM requires an explicit entry for every patch in boundaryField.
246+ for r in SOLID_REGIONS:
247+ nonmapped = get_nonmapped_patches('constant/' + r + '/polyMesh/boundary')
248+ for patch in nonmapped:
249+ for field_file in glob.glob(os.path.join('0', r, '*')):
250+ fname = os.path.basename(field_file)
251+ if fname == 'T':
252+ add_patch_entry(field_file, patch, ['type zeroGradient;'])
253+ elif fname == 'p':
254+ add_patch_entry(field_file, patch, [
255+ 'type calculated;',
256+ 'value $internalField;',
257+ ])
219258PYEOF
220259
221260%}
261300%{%(solver/SolverName%)
262301%:chtMultiRegionSimpleFoam chtMultiRegionFoam
263302 # Copy decomposeParDict to each region's system directory
264- for region in %(multiRegionFluidNames/0%) %(multiRegionSolidNames/0% ); do
303+ for region in $( ls -d constant/ * /polyMesh 2> /dev/null | cut -d/ -f2 ) ; do
265304 mkdir -p system/$region
266305 cp system/decomposeParDict system/$region /decomposeParDict
267306 done
0 commit comments