From c7b0a0a1b8c8bcda97d4ec4f3bc1013dbe97251c Mon Sep 17 00:00:00 2001 From: Ping He Date: Wed, 20 Sep 2023 14:31:46 -0500 Subject: [PATCH 1/2] Auto-checked objFunc and primalBC dict. --- dafoam/pyDAFoam.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/dafoam/pyDAFoam.py b/dafoam/pyDAFoam.py index 63c20215..2ff050e6 100755 --- a/dafoam/pyDAFoam.py +++ b/dafoam/pyDAFoam.py @@ -724,9 +724,6 @@ def __init__(self, comm=None, options=None): # initialize comm for parallel communication self._initializeComm(comm) - # check if the combination of options is valid. - self._checkOptions() - # Initialize families self.families = OrderedDict() @@ -773,6 +770,9 @@ def __init__(self, comm=None, options=None): # initialize mesh information and read grids self._readMeshInfo() + # check if the combination of options is valid. + self._checkOptions() + # initialize the mesh point vector xvVec self._initializeMeshPointVec() @@ -1124,6 +1124,7 @@ def _checkOptions(self): if self.getOption("discipline") not in ["aero", "thermal"]: raise Error("discipline: %s not supported. Options are: aero or thermal" % self.getOption("discipline")) + # check coupling Info nActivated = 0 for coupling in self.getOption("couplingInfo"): if self.getOption("couplingInfo")[coupling]["active"]: @@ -1143,6 +1144,32 @@ def _checkOptions(self): "Only one couplingSurfaceGroups is supported for aerostructural, while %i found" % nAeroStructSurfaces ) + # check the patchNames from primalBC dict + primalBCDict = self.getOption("primalBC") + for bcKey in primalBCDict: + if type(primalBCDict[bcKey]) is dict: + for patchName in primalBCDict[bcKey]["patches"]: + if patchName not in self.boundaries.keys(): + raise Error( + "primalBC-%s-patches-%s is not valid. Please use a patchName from the boundaries list: %s" + % (bcKey, patchName, self.boundaries.keys()) + ) + + # check the patch names from objFunc dict + objFuncDict = self.getOption("objFunc") + for objKey in objFuncDict: + for part in objFuncDict[objKey]: + try: + patches = objFuncDict[objKey][part]["patches"] + except Exception: + break + for patchName in patches: + if patchName not in self.boundaries.keys(): + raise Error( + "objFunc-%s-%s-patches-%s is not valid. Please use a patchName from the boundaries list: %s" + % (objKey, part, patchName, self.boundaries.keys()) + ) + # check other combinations... def saveMultiPointField(self, indexMP): From 9c4b4da765e21c9038d89498e61560a866ae3f6a Mon Sep 17 00:00:00 2001 From: Ping He Date: Wed, 20 Sep 2023 15:12:22 -0500 Subject: [PATCH 2/2] Fixed an issue. --- dafoam/pyDAFoam.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/dafoam/pyDAFoam.py b/dafoam/pyDAFoam.py index 2ff050e6..fa322b47 100755 --- a/dafoam/pyDAFoam.py +++ b/dafoam/pyDAFoam.py @@ -1147,13 +1147,16 @@ def _checkOptions(self): # check the patchNames from primalBC dict primalBCDict = self.getOption("primalBC") for bcKey in primalBCDict: - if type(primalBCDict[bcKey]) is dict: - for patchName in primalBCDict[bcKey]["patches"]: - if patchName not in self.boundaries.keys(): - raise Error( - "primalBC-%s-patches-%s is not valid. Please use a patchName from the boundaries list: %s" - % (bcKey, patchName, self.boundaries.keys()) - ) + try: + patches = primalBCDict[bcKey]["patches"] + except Exception: + continue + for patchName in patches: + if patchName not in self.boundaries.keys(): + raise Error( + "primalBC-%s-patches-%s is not valid. Please use a patchName from the boundaries list: %s" + % (bcKey, patchName, self.boundaries.keys()) + ) # check the patch names from objFunc dict objFuncDict = self.getOption("objFunc") @@ -1162,7 +1165,7 @@ def _checkOptions(self): try: patches = objFuncDict[objKey][part]["patches"] except Exception: - break + continue for patchName in patches: if patchName not in self.boundaries.keys(): raise Error(