From 7d0fe5a4a9727fc5b3bb5f580d7f2b1cbfa922f7 Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Tue, 7 Dec 2021 15:57:27 +0500 Subject: [PATCH] Mod: minor changes --- anisotropy/core/runner.py | 72 ++++++++++++------------- anisotropy/openfoam/foamfile.py | 2 +- anisotropy/openfoam/meshManipulation.py | 2 +- anisotropy/shaping/bodyCentered.py | 4 +- anisotropy/shaping/faceCentered.py | 4 +- anisotropy/shaping/occExtended.py | 22 ++++---- anisotropy/shaping/simple.py | 9 ++-- anisotropy/solving/onephase.py | 51 +++++++++--------- environment.yml | 3 ++ 9 files changed, 83 insertions(+), 86 deletions(-) diff --git a/anisotropy/core/runner.py b/anisotropy/core/runner.py index fe5a5b0..46ea0d5 100644 --- a/anisotropy/core/runner.py +++ b/anisotropy/core/runner.py @@ -42,15 +42,11 @@ class UltimateRunner(object): params = self.config.cases[0] filename = "shape.step" - match params["label"]: - case "simple": - self.shape = Simple(params["direction"]) - - case "bodyCentered": - self.shape = BodyCentered(params["direction"]) - - case "faceCentered": - self.shape = FaceCentered(params["direction"]) + self.shape = { + "simple": Simple, + "bodyCentered": BodyCentered, + "faceCentered": FaceCentered + }[params["label"]](params["direction"]) self.shape.build() @@ -90,22 +86,21 @@ class UltimateRunner(object): patches[name] = [ f"patch{ n }" ] for name in patches.keys(): - match name: - case "inlet": - patchGroup = "inlet" - patchType = "patch" + if name == "inlet": + patchGroup = "inlet" + patchType = "patch" - case "outlet": - patchGroup = "outlet" - patchType = "patch" + elif name == "outlet": + patchGroup = "outlet" + patchType = "patch" - case "wall": - patchGroup = "wall" - patchType = "wall" + elif name == "wall": + patchGroup = "wall" + patchType = "wall" - case _: - patchGroup = "symetry" - patchType = "symetryPlane" + else: + patchGroup = "symetry" + patchType = "symetryPlane" createPatchDict["patches"].append({ "name": name, @@ -118,35 +113,34 @@ class UltimateRunner(object): }) flow.append(createPatchDict) - + flow.write() # Build a flow - flow.build() + #flow.build() def pipeline(self, stage: str = None): stage = stage or self.config["stage"] - match stage: - case "shape" | "all": - with self.database.atomic(): - Shape.create(self._exec_id, **self.config.cases[0]) + if stage in ["shape", "all"]: + with self.database.atomic(): + Shape.create(self._exec_id, **self.config.cases[0]) - self.computeShape() + self.computeShape() - case "mesh" | "all": - with self.database.atomic(): - Mesh.create(self._exec_id) + elif stage in ["mesh", "all"]: + with self.database.atomic(): + Mesh.create(self._exec_id) - self.computeMesh() + self.computeMesh() - case "flow" | "all": - with self.database.atomic(): - Flow.create(self._exec_id) + elif stage in ["flow", "all"]: + with self.database.atomic(): + Flow.create(self._exec_id) - self.computeFlow() + self.computeFlow() - case "postProcess" | "all": - self.postProcess() + elif stage in ["postProcess", "all"]: + self.postProcess() diff --git a/anisotropy/openfoam/foamfile.py b/anisotropy/openfoam/foamfile.py index 143ee4f..7825a84 100644 --- a/anisotropy/openfoam/foamfile.py +++ b/anisotropy/openfoam/foamfile.py @@ -63,7 +63,7 @@ class FoamFile(object): "| \\\\ / O peration |", "| \\\\ / A nd | |", "| \\\\/ M anipulation | |", - "\*---------------------------------------------------------------------------*/" + "\\*---------------------------------------------------------------------------*/" ] desc[3] += " Version: {}".format(version() or "missed") desc[3] += " " * (limit - len(desc[3])) + "|" diff --git a/anisotropy/openfoam/meshManipulation.py b/anisotropy/openfoam/meshManipulation.py index 7c0fc96..2dc4934 100644 --- a/anisotropy/openfoam/meshManipulation.py +++ b/anisotropy/openfoam/meshManipulation.py @@ -28,7 +28,7 @@ def checkMesh(case: str = None) -> str: with open("checkMesh.log", "r") as io: warnings = [] for line in io: - if re.search("\*\*\*", line): + if re.search(r"***", line): warnings.append(line.replace("***", "").strip()) if warnings: diff --git a/anisotropy/shaping/bodyCentered.py b/anisotropy/shaping/bodyCentered.py index 5a32a21..88c3a9d 100644 --- a/anisotropy/shaping/bodyCentered.py +++ b/anisotropy/shaping/bodyCentered.py @@ -136,8 +136,8 @@ class BodyCentered(Periodic): inletface.name = "inlet" vecFlow = self.normal(inletface) - self.cell = inletface.Extrude(extr) - self.cell = reconstruct(self.cell) + # ISSUE: don't use face.Extrude(length), only face.Extrude(length, vector) + self.cell = inletface.Extrude(extr, Vec(*vecFlow)) # Boundaries symetryId = 0 diff --git a/anisotropy/shaping/faceCentered.py b/anisotropy/shaping/faceCentered.py index e7b7de6..1fa59f4 100644 --- a/anisotropy/shaping/faceCentered.py +++ b/anisotropy/shaping/faceCentered.py @@ -143,8 +143,8 @@ class FaceCentered(Periodic): inletface.name = "inlet" vecFlow = self.normal(inletface) - self.cell = inletface.Extrude(extr) - self.cell = reconstruct(self.cell) + # ISSUE: don't use face.Extrude(length), only face.Extrude(length, vector) + self.cell = inletface.Extrude(extr, Vec(*vecFlow)) # Boundaries symetryId = 0 diff --git a/anisotropy/shaping/occExtended.py b/anisotropy/shaping/occExtended.py index 45c5163..d2cccb6 100644 --- a/anisotropy/shaping/occExtended.py +++ b/anisotropy/shaping/occExtended.py @@ -27,15 +27,15 @@ def pos(self) -> numpy.array: # ISSUE: netgen.occ.Face.Extrude: the opposite face has the same name and normal vector as an initial face. -def reconstruct(shape): - """Reconstruct shape with new objects. - """ - faces = [] - - for face in shape.faces: - faceNew = occ.Face(face.wires[0]) - faceNew.name = face.name - faces.append(faceNew) - - return occ.Solid(faces) +#def reconstruct(shape): +# """Reconstruct shape with new objects. +# """ +# faces = [] +# +# for face in shape.faces: +# faceNew = occ.Face(face.wires[0]) +# faceNew.name = face.name +# faces.append(faceNew) +# +# return occ.Solid(faces) diff --git a/anisotropy/shaping/simple.py b/anisotropy/shaping/simple.py index 7acc3e2..2635b07 100644 --- a/anisotropy/shaping/simple.py +++ b/anisotropy/shaping/simple.py @@ -131,8 +131,8 @@ class Simple(Periodic): inletface.name = "inlet" vecFlow = self.normal(inletface) - self.cell = inletface.Extrude(extr * Vec(*vecFlow)) - self.cell = reconstruct(self.cell) + # ISSUE: don't use face.Extrude(length), only face.Extrude(length, vector) + self.cell = inletface.Extrude(extr, Vec(*vecFlow)) # Boundaries symetryId = 0 @@ -140,11 +140,11 @@ class Simple(Periodic): for face in self.cell.faces: fNorm = self.normal(face) fAngle = self.angle(vecFlow, fNorm) - + if fAngle == 0 or fAngle == numpy.pi: if (face.center.pos() == inletface.center.pos()).prod(): face.name = "inlet" - + else: face.name = "outlet" @@ -152,6 +152,7 @@ class Simple(Periodic): face.name = f"symetry{ symetryId }" symetryId += 1 + # Main shape self.shape = self.cell - self.lattice diff --git a/anisotropy/solving/onephase.py b/anisotropy/solving/onephase.py index 1bd5ab4..660997e 100644 --- a/anisotropy/solving/onephase.py +++ b/anisotropy/solving/onephase.py @@ -74,34 +74,33 @@ class OnePhaseFlow(FoamCase): # ISSUE: add proxy from geometry direction to outlet boundaryField. for boundary in boundaries: - match boundary: - case "inlet": - p["boundaryField"][boundary] = dict( - type = "fixedValue", - value = "uniform 1e-3" - ) - u["boundaryField"][boundary] = dict( - type = "fixedValue", - value = "uniform (0 0 -6e-5)" # * direction - ) + if boundary == "inlet": + p["boundaryField"][boundary] = dict( + type = "fixedValue", + value = "uniform 1e-3" + ) + u["boundaryField"][boundary] = dict( + type = "fixedValue", + value = "uniform (0 0 -6e-5)" # * direction + ) - case "outlet": - p["boundaryField"][boundary] = dict( - type = "fixedValue", - value = "uniform 0" - ) - u["boundaryField"][boundary] = dict( - type = "zeroGradient", - ) + elif boundary == "outlet": + p["boundaryField"][boundary] = dict( + type = "fixedValue", + value = "uniform 0" + ) + u["boundaryField"][boundary] = dict( + type = "zeroGradient", + ) - case _: - p["boundaryField"][boundary] = dict( - type = "zeroGradient" - ) - u["boundaryField"][boundary] = dict( - type = "fixedValue", - value = "uniform (0 0 0)" - ) + else: + p["boundaryField"][boundary] = dict( + type = "zeroGradient" + ) + u["boundaryField"][boundary] = dict( + type = "fixedValue", + value = "uniform (0 0 0)" + ) self.extend([ controlDict, diff --git a/environment.yml b/environment.yml index 51dd97e..ca943e6 100644 --- a/environment.yml +++ b/environment.yml @@ -1,7 +1,10 @@ name: anisotropy channels: + - local - conda-forge dependencies: - python>=3.9 - poetry - sqlite + - occt + - netgen