From c22aa7f3f2e8fa82b4b2e0090bdb8127aab04564 Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Sun, 21 Nov 2021 15:00:04 +0500 Subject: [PATCH] Mod: trying to fix issue --- anisotropy/shaping/bodyCentered.py | 12 +++++++++--- anisotropy/shaping/faceCentered.py | 13 +++++++++---- anisotropy/shaping/occExtended.py | 22 ++++++++++++++++++++++ anisotropy/shaping/simple.py | 26 ++++---------------------- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/anisotropy/shaping/bodyCentered.py b/anisotropy/shaping/bodyCentered.py index a2ad47f..3dea258 100644 --- a/anisotropy/shaping/bodyCentered.py +++ b/anisotropy/shaping/bodyCentered.py @@ -6,6 +6,7 @@ from netgen.occ import * import numpy from numpy import pi, sqrt, arccos +from .occExtended import * from . import Periodic class BodyCentered(Periodic): @@ -136,16 +137,21 @@ class BodyCentered(Periodic): vecFlow = self.normal(inletface) self.cell = inletface.Extrude(extr) - + self.cell = reconstruct(self.cell) + # Boundaries symetryId = 0 for face in self.cell.faces: fNorm = self.normal(face) fAngle = self.angle(vecFlow, fNorm) + + if fAngle == 0: + if (face.center.pos() == inletface.center.pos()).prod(): + face.name = "inlet" - if fAngle == 0 and not face.center == inletface.center: - face.name = "outlet" + else: + face.name = "outlet" else: face.name = f"symetry{ symetryId }" diff --git a/anisotropy/shaping/faceCentered.py b/anisotropy/shaping/faceCentered.py index dc2f34e..8aef95b 100644 --- a/anisotropy/shaping/faceCentered.py +++ b/anisotropy/shaping/faceCentered.py @@ -6,6 +6,7 @@ from netgen.occ import * import numpy from numpy import pi, sqrt +from .occExtended import * from . import Periodic class FaceCentered(Periodic): @@ -143,17 +144,21 @@ class FaceCentered(Periodic): vecFlow = self.normal(inletface) self.cell = inletface.Extrude(extr) - + self.cell = reconstruct(self.cell) + # Boundaries symetryId = 0 - # ISSUE: inlet and outlet faces have the same name and normal vector after extrusion for face in self.cell.faces: fNorm = self.normal(face) fAngle = self.angle(vecFlow, fNorm) + + if fAngle == 0: + if (face.center.pos() == inletface.center.pos()).prod(): + face.name = "inlet" - if fAngle == 0 and not face.center == inletface.center: - face.name = "outlet" + else: + face.name = "outlet" else: face.name = f"symetry{ symetryId }" diff --git a/anisotropy/shaping/occExtended.py b/anisotropy/shaping/occExtended.py index c522c2e..2a5212c 100644 --- a/anisotropy/shaping/occExtended.py +++ b/anisotropy/shaping/occExtended.py @@ -25,3 +25,25 @@ def add_method(cls): def pos(self) -> numpy.array: return numpy.array([self.x, self.y, self.z]) + +# 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. + + Warning: not works with curved edges. + """ + facesNew = [] + + for face in shape.faces: + edgesNew = [] + for edge in face.edges: + v = edge.vertices + edgesNew.append(occ.Segment(v[0].p, v[1].p)) + + faceNew = occ.Face(occ.Wire(edgesNew)) + faceNew.name = face.name + facesNew.append(faceNew) + + return numpy.array(facesNew).sum() + + diff --git a/anisotropy/shaping/simple.py b/anisotropy/shaping/simple.py index 965c11e..d1b5130 100644 --- a/anisotropy/shaping/simple.py +++ b/anisotropy/shaping/simple.py @@ -9,22 +9,6 @@ from numpy import pi, sqrt from .occExtended import * from . import Periodic -def reconstruct(solid): - solidNew = [] - - for face in solid.faces: - vertices = numpy.array([ v.p.pos() for v in face.vertices ]) - # TODO: correct following vertices - vertices = numpy.unique(vertices, axis = 0) - - circuit = Wire([ Segment(Pnt(*v1), Pnt(*v2)) for v1, v2 in zip(vertices, numpy.roll(vertices, -1, axis = 0)) ]) - faceNew = Face(circuit) - faceNew.name = face.name - - solidNew.append(faceNew) - - return numpy.array(solidNew).sum() - class Simple(Periodic): def __init__( @@ -147,18 +131,16 @@ class Simple(Periodic): inletface.name = "inlet" vecFlow = self.normal(inletface) - # ISSUE: netgen.occ.Face.Extrude: the opposite face has the same name and normal vector as an initial face. - self.cell = inletface.Extrude(extr) - self.cell = reconstruct(self.cell) - print([ f.name for f in self.cell.faces ]) + self.cell = inletface.Extrude(extr * Vec(*vecFlow)) + #self.cell = reconstruct(self.cell) + # Boundaries symetryId = 0 for face in self.cell.faces: fNorm = self.normal(face) fAngle = self.angle(vecFlow, fNorm) - print((face.center.pos() == inletface.center.pos())) - print(fAngle) + if fAngle == 0: if (face.center.pos() == inletface.center.pos()).prod(): face.name = "inlet"