Skip to content

Commit

Permalink
Fixed a potential issue in encoded solverName and many other minor th…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
friedenhe authored Nov 22, 2023
1 parent 71a6d41 commit 8252cf6
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions pyofm/pyOFM.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@
import gzip
from .pyOFMesh import pyOFMesh

try:
from collections import OrderedDict
except ImportError:
try:
from ordereddict import OrderedDict
except ImportError:
print(
"Could not find any OrderedDict class. For 2.6 and earlier, \
use:\n pip install ordereddict"
)


class Error(Exception):
"""
Expand Down Expand Up @@ -64,19 +53,20 @@ class PYOFM(object):

def __init__(self, comm=None):

if comm == None:
if comm is None:
self.comm = MPI.COMM_WORLD
else:
self.comm = comm

self.parRun = False
parArg = ""
if self.comm.size > 1:
parArg = " -parallel"

solverName = "pyOFMesh -python" + parArg

self.ofMesh = pyOFMesh(solverName.encode())
solverNameEncoded = solverName.encode()

self.ofMesh = pyOFMesh(solverNameEncoded)

self.ofMesh.readMesh()

Expand Down Expand Up @@ -274,12 +264,12 @@ def writeVolumeMeshPoints(self, points):
fileOrigDir = self.fileNames["pointsFile0Dir"]
try:
shutil.move(fileOrig, fileNew)
except:
except Exception:
raise Error("Can not move %s to %s" % (fileOrig, fileNew))

try:
shutil.rmtree(fileOrigDir)
except:
except Exception:
raise Error("Can not remove %s" % (fileOrigDir))

self.comm.Barrier()
Expand All @@ -294,7 +284,7 @@ def checkMeshCompression(self):
print("Checking if we need to compress the mesh files")
meshFileDir = "constant/polyMesh"
for file1 in os.listdir(meshFileDir):
if (not ".gz" in file1) and (not file1 == "boundary"):
if (".gz" not in file1) and (file1 != "boundary"):
compFileName = os.path.join(meshFileDir, file1)
if os.path.isfile(compFileName):
with open(compFileName, "rb") as f_in, gzip.open(compFileName + ".gz", "wb") as f_out:
Expand Down

0 comments on commit 8252cf6

Please sign in to comment.