Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom GrowthRatios and more Schedule variables #94

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e9654d4
minor change on cart grid
anilyil Jul 11, 2023
e0b06c1
added scheduled smoothing and splay
anilyil Jul 15, 2023
4274130
added variable growth ratios as well
anilyil Jul 27, 2023
4325440
Add tests to 'Schedule' parameters
DavidAnderegg Sep 3, 2024
d5b5cde
Update library import checks (#67)
eirikurj Oct 7, 2022
45baf98
Update setup.py + black formatting (#70)
A-CGray Feb 20, 2023
19492ff
update setup.py (#73)
eirikurj Apr 24, 2023
eda5ea7
Updated testing docs (#75)
eytanadler Aug 7, 2023
1d5fbd3
Add config file for building docs on RTD (#74)
eirikurj Aug 22, 2023
f24c42c
Updated Intel config file to work with HPE MPI (#76)
sseraj Aug 30, 2023
4df92b4
Add missing test "n0012 schedule"
DavidAnderegg Sep 3, 2024
0e4237a
Print min and max growth ratio if it is user specified
DavidAnderegg Sep 3, 2024
3411f3c
Add test for 'growth_ratios'
DavidAnderegg Sep 3, 2024
14a2cfd
Add description to new options
DavidAnderegg Sep 3, 2024
ae788a3
Merge branch 'main' of https://github.com/mdolab/pyhyp into mdolab-main
DavidAnderegg Sep 4, 2024
fd282c4
Merge branch 'mdolab-main' into vol_blend_schedule
DavidAnderegg Sep 4, 2024
b34e742
Replace duplicated code with pointer based subroutine
DavidAnderegg Sep 4, 2024
6eb50e7
pick the smallest grid ratio for pGridRatio
DavidAnderegg Sep 4, 2024
145b44e
run 'black' and 'fprettify'
DavidAnderegg Sep 4, 2024
13c9818
Remove trailing white space
DavidAnderegg Sep 4, 2024
57746df
Compute marchdistance when using custom growth ratios
DavidAnderegg Sep 5, 2024
357b05f
remove code duplication by merging the rans-tests
DavidAnderegg Sep 5, 2024
ce7e0e0
Run black, fprettify and flake8
DavidAnderegg Sep 5, 2024
2a8b405
Make normal parameters take a list and a float instead of having
DavidAnderegg Sep 18, 2024
e468a95
Adjust naca example to showcase schedule vars and growth ratios
DavidAnderegg Sep 24, 2024
017c3ee
Get rid of not needed pointers
DavidAnderegg Sep 25, 2024
90c1ebc
make some options per layer instead of global
DavidAnderegg Sep 25, 2024
1e36ad8
Move grid ration computation to python layer
DavidAnderegg Sep 26, 2024
b8006a4
Run black, fprettify and flake8
DavidAnderegg Sep 26, 2024
d437ae7
Add testcase for simpleOCart when no grid is provided
DavidAnderegg Sep 26, 2024
e55d6e9
Adjust tests to account for scalar, schedule or explicit definition of
DavidAnderegg Sep 26, 2024
13cf4fa
Also test splay-options
DavidAnderegg Sep 26, 2024
b226f06
Extend tests to also include 'cornerAngle'
DavidAnderegg Sep 26, 2024
4f29dd7
Add test for constant layers at the beginning and end of extrusion
DavidAnderegg Sep 26, 2024
6a23b58
Update documentation
DavidAnderegg Sep 26, 2024
f49268a
Merge pull request #2 from mdolab/main
DavidAnderegg Sep 26, 2024
5ff70bd
Print marchDist and add deprecation warning to 'volSmoothSchedule'
DavidAnderegg Oct 8, 2024
ae92c75
print the correct gridRatio for pyHypMulti
DavidAnderegg Oct 16, 2024
84e0216
extend warning about precedence of explicit 'growthratios'
DavidAnderegg Oct 16, 2024
adc533a
fix typos
DavidAnderegg Nov 13, 2024
f5f4247
Use member variable instead of passing it into the function
DavidAnderegg Nov 13, 2024
667d140
move mach parameters printing into own function
DavidAnderegg Nov 13, 2024
e4ee691
simplify function
DavidAnderegg Nov 13, 2024
6c5156c
rename default case as such
DavidAnderegg Nov 13, 2024
e87d1b3
Refactor to camelCase
DavidAnderegg Nov 13, 2024
186e813
also move tests and missed cases to camelCase
DavidAnderegg Nov 13, 2024
6201c11
fix typos
DavidAnderegg Nov 13, 2024
f9f0824
Rephrase error message
DavidAnderegg Nov 13, 2024
25ca99f
Add argument descriptions
DavidAnderegg Nov 13, 2024
6706961
run black and flake8
DavidAnderegg Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions doc/options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,28 @@ splay:
desc: >
Splay BC spreading factor.
This controls how far the floating edges splay outwards and can be useful for increasing the volume overlap in overset meshes.
This variable may come in different formats:
(1) If it is a ``scalar``, the same value is used throughout all of the grid.
(2) If it is a ``1D list``, it must have a length of :py:data:`N` - 1. Each entry is used for the corresponding extrusion layer. E.g. ``splay: [0.2, 0.3, 0.4]`` would result in a grid with 3 extrusions where the first layer uses ``0.2``, the second layer uses ``0.3`` and the last one uses ``0.4``.
(3) If it is a ``2D list``, the values are interpolated linearly. E.g. ``splay: [[0.0, 0.2], [0.5, 0.4], [1.0, 0.0]]`` would result in a linear increase from ``0.2`` to ``0.4`` at half of the total :py:data:`N`. Then it would linearly decrease until it reaches ``0.0`` in the last extrusion.


splayEdgeOrthogonality:
desc: >
How hard to try to force orthogonality at splay edges.
Should be between 0 and 0.5.
Please look at :py:data:`splay` for explanations and examples on the format.
anilyil marked this conversation as resolved.
Show resolved Hide resolved

splayCornerOrthogonality:
desc: >
How hard to try to force orthogonality at splay corners.
Please look at :py:data:`splay` for explanations and examples on the format.

cornerAngle:
desc: >
Maximum convex corner angle in degrees necessary to trigger the implicit node averaging scheme.
See Section 8 of :ref:`Chan and Steger<pyhyp_theory>` for more information.
Please look at :py:data:`splay` for explanations and examples on the format.

coarsen:
desc: >
Expand Down Expand Up @@ -190,6 +198,7 @@ epsE:
If the geometry has very sharp corners, too much explicit smoothing will cause the solver to rapidly "soften" the corner and the grid will fold back on itself.
In concave corners, additional smoothing will prevent lines from crossing (avoiding negative cells).
See Section 3 of :ref:`Chan and Steger<pyhyp_theory>` for more information.
Please look at :py:data:`splay` for explanations and examples on the format.

epsI:
desc: >
Expand All @@ -198,6 +207,7 @@ epsI:
Generally increasing the implicit coefficient results in a more stable solution procedure.
Usually this value should be twice the explicit smoothing parameter.
See Section 3 of :ref:`Chan and Steger<pyhyp_theory>` for more information.
Please look at :py:data:`splay` for explanations and examples on the format.

theta:
desc: >
Expand All @@ -206,6 +216,7 @@ theta:
A single theta value is used for both in-plane directions.
Typical values are ~2.0 to ~4.0.
See Section 3 of :ref:`Chan and Steger<pyhyp_theory>` for more information.
Please look at :py:data:`splay` for explanations and examples on the format.

volCoef:
desc: >
Expand All @@ -214,26 +225,25 @@ volCoef:
Larger values will result in a more uniform cell volume distribution.
Alternatively, use more :py:data:`volSmoothIter` for stronger local smoothing.
See Section 5 of :ref:`Chan and Steger<pyhyp_theory>` for more information.
Please look at :py:data:`splay` for explanations and examples on the format.

volBlend:
desc: >
The global volume blending coefficient.
This value will typically be very small, especially if you have widely varying cell sizes.
Typical values are from ~0 to 0.001.
Please look at :py:data:`splay` for explanations and examples on the format.

volSmoothIter:
desc: >
The number of point-Jacobi local volume smoothing iterations to perform at each level.
More iterations will result in a more uniform cell volume distribution.
Please look at :py:data:`splay` for explanations and examples on the format.

volSmoothSchedule:
DavidAnderegg marked this conversation as resolved.
Show resolved Hide resolved
growthRatios:
desc: >
Define a piecewise linear schedule for volume smoothing iterations.
If provided, this supersedes :py:data:`volSmoothIter`.
This option is usually used to limit the number of smoothing iterations early in the extrusion to maintain orthogonality near the wall and ramp up the number of smoothing iterations later in the extrusion to achieve a more uniform cell volume distribution in the farfield.
An example of a smoothing schedule is ``"volSmoothSchedule": [[0, 10], [0.4, 50], [1.0, 100]]``.
In this example, the number of smoothing iterations increases linearly from 10 to 50 over the first 40% of grid levels.
For the remaining levels, the number of smoothing iterations increases linearly from 50 to 100.
Manually specify the growth ratio(s). If not ``None``, this superseeds :py:data:`marchDist`.
DavidAnderegg marked this conversation as resolved.
Show resolved Hide resolved
Please look at :py:data:`splay` for explanations and examples on the format.

KSPRelTol:
desc: >
Expand Down
23 changes: 22 additions & 1 deletion examples/corner/runCorner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
This example shows how to set up dictionaries to run multiple extrusions with pyHypMulti.
We use pyHypMulti to extrude a 90 deg corner twice with different smoothing settings.
"""

import os
import numpy as np
from pyhyp import pyHypMulti

baseDir = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -44,12 +46,31 @@
"volSmoothIter": 100,
}


# helper function to interpolate values for each grid-level
def ls(start, stop, dtype=np.float64):
return np.linspace(start, stop, commonOptions["N"] - 1, dtype=dtype).tolist()


# Now set up specific options
options1 = {"outputFile": "corner1_hyp.cgns"}
options2 = {"epsE": 4.0, "epsI": 8.0, "outputFile": "corner2_hyp.cgns"}
options3 = {
"splay": [[0.0, 0.5], [0.5, 0.0], [1.0, 0.5]],
"splayEdgeOrthogonality": [[0.0, 0.1], [0.5, 0.2], [1.0, 0.3]],
"splayCornerOrthogonality": [[0.0, 0.2], [0.5, 0.3], [1.0, 0.5]],
"outputFile": "corner3_hyp.cgns",
}
options4 = {
"splay": ls(0.5, 0.0),
"splayEdgeOrthogonality": ls(0.1, 0.3),
"splayCornerOrthogonality": ls(0.2, 0.5),
"outputFile": "corner4_hyp.cgns",
}


# Gather options in a list
options = [options1, options2]
options = [options1, options2, options3, options4]

hyp = pyHypMulti(options=options, commonOptions=commonOptions)
hyp.combineCGNS(combinedFile=volumeFile)
1 change: 1 addition & 0 deletions examples/naca0012/naca0012_euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This script uses the NACA 0012 airfoil equation to generate 2D Euler mesh.
This mesh has a sharp trailing edge.
"""

import os
import numpy
from pyhyp import pyHyp
Expand Down
192 changes: 152 additions & 40 deletions examples/naca0012/naca0012_rans.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,15 @@
This script uses the NACA 0012 airfoil equation to generate a 2D RANS mesh.
This mesh has a blunt trailing edge.
"""

import os
import numpy
from pyhyp import pyHyp
import numpy as np
import argparse

baseDir = os.path.dirname(os.path.abspath(__file__))
surfaceFile = os.path.join(baseDir, "naca0012_rans.fmt")
volumeFile = os.path.join(baseDir, "naca0012_rans.cgns")

alpha = numpy.linspace(0, 2 * numpy.pi, 273)
x = numpy.cos(alpha) * 0.5 + 0.5
y = numpy.zeros_like(x)

for i in range(len(x)):
if i < len(x) / 2:
y[i] = 0.6 * (
0.2969 * numpy.sqrt(x[i]) - 0.1260 * x[i] - 0.3516 * x[i] ** 2 + 0.2843 * x[i] ** 3 - 0.1015 * x[i] ** 4
)
else:
y[i] = -0.6 * (
0.2969 * numpy.sqrt(x[i]) - 0.1260 * x[i] - 0.3516 * x[i] ** 2 + 0.2843 * x[i] ** 3 - 0.1015 * x[i] ** 4
)

# Since the TE is open we need to close it. Close it multiple linear segments.
delta_y = numpy.linspace(y[-1], y[0], 32, endpoint=True)
delta_y = delta_y[1:]

x = numpy.append(x, numpy.ones_like(delta_y))
y = numpy.append(y, delta_y)

# Write the plot3d input file:
f = open(surfaceFile, "w")
f.write("1\n")
f.write("%d %d %d\n" % (len(x), 2, 1))
for iDim in range(3):
for j in range(2):
for i in range(len(x)):
if iDim == 0:
f.write("%g\n" % x[i])
elif iDim == 1:
f.write("%g\n" % y[i])
else:
f.write("%g\n" % (float(j)))
f.close()

options = {
# ---------------------------
Expand Down Expand Up @@ -80,6 +46,152 @@
}


hyp = pyHyp(options=options)
hyp.run()
hyp.writeCGNS(volumeFile)
def extrudeDefaultCase():
"""
This is the default where most values are scalars
"""

volumeFile = os.path.join(baseDir, "naca0012_rans.cgns")

generateSurfaceFile(surfaceFile)
hyp = extrudeVolumeMesh(options, volumeFile)

return hyp, volumeFile


def extrudeConstantLayersCase():
"""
Here, the first and last layers are kept constant (growth-ratio == 1.0)
"""

volumeFile = os.path.join(baseDir, "naca0012_rans_constant_layers.cgns")

options.update(
{
"nConstantStart": 5,
"nConstantEnd": 5,
}
)

generateSurfaceFile(surfaceFile)
hyp = extrudeVolumeMesh(options, volumeFile)

return hyp, volumeFile


def extrudeScheduleCase():
"""
Some variables are 'scheduled' which means their value changes depending on
the extrusion layer. The values are specified on intervals which are
linearly interpolated by pyHyp.
"""
volumeFile = os.path.join(baseDir, "naca0012_rans_schedule.cgns")

options.update(
{
"epsE": [[0.0, 1.0], [0.2, 2.0], [1.0, 5.0]],
"epsI": [[0.0, 2.0], [0.2, 2.0], [1.0, 10.0]],
"theta": [[0.0, 3.0], [0.2, 2.5], [1.0, 0.0]],
"volBlend": [[0.0, 0.0001], [1.0, 0.1]],
"volSmoothIter": [[0.0, 100], [1.0, 500]],
"volCoef": [[0.0, 0.25], [1.0, 0.5]],
"growthRatios": [[0.0, 1.05], [1.0, 1.1]],
"cornerAngle": [[0.0, 110.0], [1.0, 120.0]],
}
)

generateSurfaceFile(surfaceFile)
hyp = extrudeVolumeMesh(options, volumeFile)

return hyp, volumeFile


def extrudeExplicitCase():
"""
Some variables are set 'explicitly'. This means, a list of values that
correspond to each layer is provided.
"""

def ls(start, stop, dtype=np.float64):
return np.linspace(start, stop, options["N"] - 1, dtype=dtype).tolist()

options.update(
{
"epsE": ls(1.0, 5.0),
"epsI": ls(2.0, 10.0),
"theta": ls(3.0, 0.0),
"volBlend": ls(0.0001, 0.1),
"volSmoothIter": ls(100, 500, dtype=np.int32),
"volCoef": ls(0.25, 0.5),
"growthRatios": ls(1.05, 1.3),
"cornerAngle": ls(110.0, 120.0),
}
)

volumeFile = os.path.join(baseDir, "naca0012_rans_explicit.cgns")

generateSurfaceFile(surfaceFile)
hyp = extrudeVolumeMesh(options, volumeFile)
return hyp, volumeFile


def generateSurfaceFile(surface_file):
alpha = numpy.linspace(0, 2 * numpy.pi, 273)
x = numpy.cos(alpha) * 0.5 + 0.5
y = numpy.zeros_like(x)

for i in range(len(x)):
if i < len(x) / 2:
y[i] = 0.6 * (
0.2969 * numpy.sqrt(x[i]) - 0.1260 * x[i] - 0.3516 * x[i] ** 2 + 0.2843 * x[i] ** 3 - 0.1015 * x[i] ** 4
)
else:
y[i] = -0.6 * (
0.2969 * numpy.sqrt(x[i]) - 0.1260 * x[i] - 0.3516 * x[i] ** 2 + 0.2843 * x[i] ** 3 - 0.1015 * x[i] ** 4
)

# Since the TE is open we need to close it. Close it multiple linear segments.
deltaY = numpy.linspace(y[-1], y[0], 32, endpoint=True)
deltaY = deltaY[1:]

x = numpy.append(x, numpy.ones_like(deltaY))
y = numpy.append(y, deltaY)

# Write the plot3d input file:
f = open(surface_file, "w")
f.write("1\n")
f.write("%d %d %d\n" % (len(x), 2, 1))
for iDim in range(3):
for j in range(2):
for i in range(len(x)):
if iDim == 0:
f.write("%g\n" % x[i])
elif iDim == 1:
f.write("%g\n" % y[i])
else:
f.write("%g\n" % (float(j)))
f.close()


def extrudeVolumeMesh(options, volumeFile):
hyp = pyHyp(options=options)
hyp.run()
hyp.writeCGNS(volumeFile)

return hyp


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Process some integers.")
choices = ["default", "constant", "schedule", "explicit"]
parser.add_argument("--case", choices=choices, default=choices[0])
args = parser.parse_args()

if args.case == "constant":
extrudeConstantLayersCase()
elif args.case == "schedule":
extrudeScheduleCase()
elif args.case == "explicit":
extrudeExplicitCase()
else:
extrudeDefaultCase()
Loading
Loading