Mesh Generation

In this tutorial, we will use pyHyp to generate a 3D mesh in CGNS format. The coordinates for the NACA0012 airfoil are in the file n0012.dat. Coordinates for most airfoils can be obtained from the UIUC Data site.

Create the following empty runscript in the current directory.

  • genMesh.py

pyHyp runscript

Import the pyHyp libraries and numpy.

import numpy as np
from pyhyp import pyHyp

Surface Mesh Generation

data = np.loadtxt("n0012.dat")
x = data[:, 0].copy()
newY = data[:, 1].copy()
ndim = x.shape[0]

airfoil3d = np.zeros((ndim, 2, 3))
for j in range(2):
    airfoil3d[:, j, 0] = x[:]
    airfoil3d[:, j, 1] = newY[:]
airfoil3d[:, 0, 2] = 0.0
airfoil3d[:, 1, 2] = 1.0
# write out plot3d
fsam = open("new.xyz", "w")
fsam.write(str(1) + "\n")
fsam.write(str(ndim) + " " + str(2) + " " + str(1) + "\n")
for ell in range(3):
    for k in range(1):
        for j in range(2):
            for i in range(ndim):
                fsam.write("%.15f\n" % (airfoil3d[i, j, ell]))
fsam.close()

pyHyp requires a surface mesh input before it can create a 3D mesh. A 2D surface mesh can be created using the code above, which produces a PLOT3D file with extension .xyz. This meshes only the airfoil surface, and is used as the input file for pyHyp, which marches the existing mesh to the farfield. By performing this intermediate step, the volume mesh generation is faster and higher-quality.

Options

options = {
    # ---------------------------
    #        Input Parameters
    # ---------------------------
    "inputFile": "new.xyz",
    "unattachedEdgesAreSymmetry": False,
    "outerFaceBC": "farfield",
    "autoConnect": True,
    "BC": {1: {"jLow": "zSymm", "jHigh": "zSymm"}},
    "families": "wall",

General Options

inputFile

Name of the surface mesh file.

unattachedEdgesAreSymmetry

Tells pyHyp to automatically apply symmetry boundary conditions to any unattached edges (those that do not interface with another block).

outerFaceBC

Tells pyHyp which boundary condition to apply to the outermost face of the extruded mesh. Note that we do not set the inlet or outlet boundaries seperately because they are automatically handled in ADflow consistently with the free stream flow direction.

BC

Tells pyHyp that, since it is a 2D problem, both sides of the domain jLow and jHigh are set to be symmetry boundary conditions. The input surface is automatically assigned to be a wall boundary.

families

Name given to wall surfaces. If a dictionary is submitted, each wall patch can have a different name. This can help the user to apply certain operations to specific wall patches in ADflow.

    # ---------------------------
    #        Grid Parameters
    # ---------------------------
    "N": 129,
    "s0": 3e-6,
    "marchDist": 100.0,

Grid Parameters

N

Number of nodes in off-wall direction. If multigrid will be used this number should be 2m-1(n+1), where m is the number of multigrid levels and n is the number of layers on the coarsest mesh.

s0

Thickness of first off-wall cell layer.

marchDist

Distance of the far-field.

    # ---------------------------
    #   Pseudo Grid Parameters
    # ---------------------------
    "ps0": -1.0,
    "pGridRatio": -1.0,
    "cMax": 3.0,
    # ---------------------------
    #   Smoothing parameters
    # ---------------------------
    "epsE": 1.0,
    "epsI": 2.0,
    "theta": 3.0,
    "volCoef": 0.25,
    "volBlend": 0.0001,
    "volSmoothIter": 100,
}

Running pyHyp and Writing to File

The following three lines of code extrude the surface mesh and write the resulting volume mesh to a .cgns file.

hyp = pyHyp(options=options)
hyp.run()
hyp.writeCGNS("n0012.cgns")