0
votes

OpenFOAM section:

I have meshed a hollow cylinder shape in OpenFOAM. In this model, flow will be flow from outer cylinder wall to the inner cylinder wall; Right-Hand law is used for meshing points as below: enter image description here I have tried to plot face normals by OpenFOAM compiled paraFoam, but I couldn't. It is possible to plot boundary mesh faces (which are on top, bottom, inner and outer cylinder walls) by Glyph normals, but not the internal mesh faces.

Q OpenFOAM: Is there any function code or way to plot them inside paraFoam?

Mesh file have been exported to be plotted inside python, as above right picture. As it is obvious, in this way, mesh faces on Start-End overlapping plane have opposite directions comparing to the other rotational face normals.

Q OpenFOAM: Do these face normal directions result in wrong results? or results are controlled, only, by Right-Hand rule? Is there any code or way to change these directions, if it is needed?

Note: I have imported this mesh file into python FiPy by Gmsh3D and used its faceNormals and cellCenters to plot the face normals by matplotlib.

FiPy section:

I have changed the clockwise Start-End mesh face normals direction to counterclockwise by the following code, due to my needs to use counterclockwise faceNormals direction:

for i in range(self.mesh.numberOfCells):
    for f in self.mesh.cellFaceIDs.data.T[i]:
        if self.mesh.faceCenters().T[f][0] > 0 > self.mesh.faceNormals.T[f][1] and self.mesh.faceCenters().T[f][1] == 0:
            self.mesh.faceNormals.T[f] = np.multiply(np.array([-1, -1, 1]), self.mesh.faceNormals.T[f])

Q FiPy: Do these face normal direction changes have any effect on FiPy solving results? As I understood it from the recent explanation (I couldn't ask this question there duo to not having enough reputation quorum), FiPy considers cell faceNormal direction of a shared face outward to its corresponding neighbor cell, and faceNormal directions (which are shown in the picture using FiPy mesh.FaceNormals) have no effect on the solution, by themselves; This means that it can be considered in opposite directions by the solver depending on the circumstances. Is it right?? Is there any FiPy mesh modules to create such O'grid cylindrical type meshing system, in which x, y, and z coordinates of the nodes could be available? I have tried 'CylindricalGrid2D' for radial meshing, but it gives only r and z coordinates of the nodes.

2

2 Answers

1
votes

Regarding resetting the values of the faceNormals with FiPy. That might not be possible depending on the type of mesh. For example, with a Grid2D style mesh that would result in AttributeError: can't set attribute as the normals are calculated when required rather than stored in the mesh object. If it is possible it most likely breaks FiPy though. For example, the following gives very different results when the faceNormals are randomly flipped.

from fipy import CellVariable, Grid3D, DiffusionTerm
from fipy.meshes.mesh import Mesh
import numpy as np

grid = Grid3D(nx=3, ny=3, nz=1)

mesh = Mesh(grid.vertexCoords, grid.faceVertexIDs, grid.cellFaceIDs)

var = CellVariable(mesh=mesh)

var.constrain(1, where=mesh.facesLeft)
var.constrain(0, where=mesh.facesRight)

DiffusionTerm().solve(var)
print(var)

var[:] = 0.0

flip = 2 * np.random.randint(2, size=mesh.faceNormals.shape[1]) - 1
mesh.faceNormals[:] = mesh.faceNormals * flip[None]

DiffusionTerm().solve(var)
print(var)
1
votes

FiPy considers faceNormal direction of a shared face outward to the neighbor cell,

No, as stated in the link you posted, FiPy considers the faceNormal direction to be into the second of the two cells bounding a face. A neighbor cell is relative to a cell. A face has two bounding cells; if the face is on the exterior, then both bounding cells are the same.

and faceNormal directions (which are shown in the picture using FiPy mesh.FaceNormals) have no effect on the solution, by themselves; This means that it can be considered in opposite directions by the solver depending on the circumstances. Is it right??

No. As demonstrated in the answer posted by @wd15, FiPy uses the faceNormal internally and expects it to obey the conventions we have defined, i.e., that it always points into the second cell.

There's nothing stopping you from initializing a FaceVariable with faceNormals and then overriding some values as you see fit:

my_normals = fp.FaceVariable(mesh=mesh, value=mesh.faceNormals, rank=1)
my_normals.setValue(my_desired_orientation, where=my_backward_faces)

Is there any FiPy mesh modules to create such O'grid cylindrical type meshing system, in which x, y, and z coordinates of the nodes could be available?

No.