Skip to content

Commit

Permalink
Added handling for parallel openfoam case to be default
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed committed Apr 25, 2024
1 parent c442969 commit e26e273
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
9 changes: 5 additions & 4 deletions postproclib/cplfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ def __init__(self,fdir,cpldir='cpl/',
self.cfddir = cfddir
self.header = HeaderData(open(fdir+cpldir+'coupler_header'))
self.md_field = self.MDFieldType(fdir+mddir, **kwargs)
try:
self.cfd_field = self.CFDFieldType(fdir+cfddir, parallel_run=True)
except (TypeError, FileNotFoundError):
self.cfd_field = self.CFDFieldType(fdir+cfddir)
self.cfd_field = self.CFDFieldType(fdir+cfddir)
#try:
# self.cfd_field = self.CFDFieldType(fdir+cfddir, parallel_run=True)
#except (TypeError, FileNotFoundError):
# self.cfd_field = self.CFDFieldType(fdir+cfddir)
self.cfd_halos = self.cfd_field.nhalos
self.olap_cells = np.array(
[int(self.header.icmax_olap) - int(self.header.icmin_olap) + 1,
Expand Down
36 changes: 33 additions & 3 deletions postproclib/openfoampostproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from .pplexceptions import NoResultsInDir
import glob

def walklevel(some_dir, level=1):
some_dir = some_dir.rstrip(os.path.sep)
assert os.path.isdir(some_dir)
num_sep = some_dir.count(os.path.sep)
for root, dirs, files in os.walk(some_dir):
yield root, dirs, files
num_sep_this = root.count(os.path.sep)
if num_sep + level <= num_sep_this:
del dirs[:]

class OpenFOAM_PostProc(PostProc):

"""
Expand Down Expand Up @@ -43,7 +53,9 @@ def __init__(self, resultsdir, **kwargs):
controlDictfound = False
#possibles = []
writecontrol =''
for root, dirs, files in os.walk(self.resultsdir):
#Use walklevel to prevent finding other openfoam results
#which might be in the same directory
for root, dirs, files in walklevel(self.resultsdir, 2):
if ("controlDict" in files):
controlDictfound = True
with open(root+"/controlDict") as f:
Expand All @@ -69,8 +81,26 @@ def __init__(self, resultsdir, **kwargs):
print(("Convert failed in OpenFOAM_reader", line))

if "processor" in root and not parallel_run:
parallel_run = True
print(("Assuming parallel run as processor folder found in " + self.resultsdir))
#Check if at least two processor folders
if (os.path.isdir(root+'/../processor0') and os.path.isdir(root+'/../processor1')):
print("Assuming parallel run as processor0, processor1, etc found in "
+ self.resultsdir + ".\n")
parallel_run = True
else:
# Check number of folders in processor0 folder as on older versions of OpenFOAM
# this is filled in a one processor parallel run but not on later ones
rmlist = ["constant", "system", "processor0"]
try:
rc = next(os.walk(root+'/../'))[1]
pc = next(os.walk(root))[1]
rootcontents = [i for i in rc if i not in rmlist]
proccontents = [i for i in pc if i not in rmlist]
if len(proccontents) > len(rootcontents):
parallel_run = True
print("Assuming parallel run as processor folder found in "
+ self.resultsdir + " with " + str(len(proccontents)) + " in.\n")
except StopIteration:
pass

#Check if data files exist
if not controlDictfound:
Expand Down

0 comments on commit e26e273

Please sign in to comment.