Sampling Functions

prefoil.sampling.bigeometric(start, end, n, a1=0.001, b1=0.001, ra=1.1, rb=1.1)[source]

This spacing function will create a distribution with a geometric sequence from both sides. It will try to find the optimal number of nodes to allocate to each sequence such that the middle region of constant spacings matches with the final spacing from each sequence. The default settings work well for \(n\sim\mathcal{O}(100)\) (200 on entire airfoil).

 a1                           deltac                               b1
|                             <----->                               |
|  |   |    |     |     |     |     |     |     |     |    |   |  | |
|                                                                   |
<-- na=3 --><--------------- nc=n-2-na-nb -----------><--- nb=4  --->
Parameters:
startfloat

Parametric location of start of distribution (between 0 and 1).

endfloat

Parametric location of end of distribution (between 0 and 1).

nint

Number of nodes needed in distribution (including start and end).

a1float

Initial spacing from the start.

b1float

Initial spacing from the end.

rafloat

Geometric ratio from the start.

rbfloat

Geometric ratio from the end.

Returns:
sNdarray [N]

The parametric spline locations that define the sampling

prefoil.sampling.conical(start, end, n, m=numpy.pi, coeff=1, bad_edge=False)[source]

Generalized sampling function that extends from linear to more-than-cosine point distribution. The user selects the chord intervals over which this function is defined, the number of sampling points, and the “frequency” of the distribution. At a high level, this function translates a linear distribution of angles into a non-linear distribution of sampling points using a composite trigonometric function. The periodicity of the sampling refinement is defined by the angle sampling range m. The cosine function turns a set of equally-spaced angles into a set of x coordinates denser at \(n\pi\) (with n : int). The default \(m=\pi\) thus means that sampled points will accumulate at the leading and trailing edge. If you double this frequency with \(m=2\pi\), then there will be an additional sampling concentration at mid chord, with \(m=3\pi`\) there will be 2 additional concentrations, and so on. The user can also use a non-integer multiplier to have non-equally spaced refined areas - e.g. with \(m = \pi/2\) the sampling will be coarse at the LE and refined at the TE.

A more-than-cosine distribution exacerbates the non-linearity introduced by the cosine. The coeff parameter, b for conciseness in the code, defines the “strength” of the distortion:

  • \(b = 0\): linear distribution

  • \(b = 1\): cosine distribution

  • \(b > 1\): more-than-cosine distribution, meaning that the points are

The overall function is composed of two sub-functions, continuous at \(b = 1 \rightarrow s = \cos(x)\). For \(b < 1\), the following function is used:

\[s = \left(\frac{\cos(x) + 1}{2} - \frac{x}{\pi}\right)b + \frac{x}{\pi}\]

While for coeff >=1:

\[s = \frac{1}{2}\left(1 + \frac{\cos(x)}{\sqrt{\cos(x) ^ 2 + \sin(x) ^ 2 / b ^ 2}}\right)\]

For more clarity, the user can plot these functions and see how the first one goes from linear to cosine as b approaches 1, and the second goes from cosine to a discontinuous (flipped) Heaviside function for \(b \rightarrow \infty\). Note that the cosine/conical functions are normalized and shifted to fit into the user-prescribed sampling interval.

Parameters:
startfloat

the airfoil chord location to start sampling at

endfloat

the airfoil chord location to stop sampling at

nint

the number of points to sample

mfloat

the maximum angle used for sampling the point distribution, starting from zero. This implicitly defines the “frequency” of the refinement, e.g. m=pi refinement at LE and TE, \(m=2\pi\) refinement at LE, TE, and mid-chord, etc

bad_edgebool

This is some kind of sneaky hack used to avoid bad meshes. If true, the second and second to last points of the ndarray are removed from the sampling vector. This is necessary to avoid bad mesh elements at small leading and trailing edges. Such problem often occurs for high N and high b. As a rule of thumb, the size of the smallest element (considering a normalized airfoil of size 1m) should always be > 1e-4 for pyHyp to extrude the mesh correctly.

Returns:
sNdarray [N]

The parametric spline locations that define the sampling

prefoil.sampling.cosine(start, end, n, m=numpy.pi)[source]

Sampling function based on cosine spacing. Check prefoil.sampling.conical() for more implementation information.

Parameters:
startfloat

the airfoil chord location to start sampling at

endfloat

the airfoil chord location to stop sampling at

nint

the number of points to sample

mfloat

the maximum angle used for sampling the point distribution, starting from zero. This implicitly defines the “frequency” of the refinement, e.g. \(m=\pi\) refinement at LE and TE, \(m=2\pi\) refinement at LE, TE, and mid-chord, etc

Returns:
sNdarray [N]

The parametric spline locations that define the sampling

prefoil.sampling.joinedSpacing(n, spacingFunc=<function polynomial>, func_args=None, s_LE=0.5)[source]

Function that returns two point distributions joined at s_LE. If it is desired to specify different spacing functions for the top and the bottom, the user can provide a list for the spacingFunc and func_args.

Note that one point is added when sampling due to the removal of “double” elements when returning the point array

Parameters:
nint

the number of points to sample

spacingFuncfunction

a function that returns the sampling spacing

func_argsdict

options to pass into the spacingFunc

s_LEfloat

parametric location of the leading edge

Returns:
sNdarray [N]

The parametric spline locations that define the sampling

prefoil.sampling.polynomial(start, end, n, m=numpy.pi, order=5)[source]

similar to cosine spacing but instead of a unit circle, a function of the form \(1 - x^{\mathrm{order}}\) is used. This does a better job on not overly clustering points at the edges.

        ---------------|---------------
      -/            -/ | \-            \-    order 4
    -/            -/   |   \-            \-
  -/            -/     |     \-            \-
-/            -/       |       \-            \-
|           -/         |         \-           |
|         -/           | order 1   \-         |
|       -/             |             \-       |
|     -/               |               \-     |
|   -/                 |                 \-   |
| -/                   |                   \- |
|/                     |                     \|
------------------------------------------------
Parameters:
startfloat

parametric location of the sampling start point

endfloat

parametric location of the sampling end point

nint

number of points to sample

mfloat

the maximum angle for the sampling process

orderfloat

the order of polynomial from which to sample

Returns:
sNdarray [N]

The parametric spline locations that define the sampling

prefoil.sampling.tanh_distribution(start, end, n, s0=None, s1=None)[source]

Hyperbolic tangent distribution based on: https://www.cfd-online.com/Wiki/Structured_mesh_generation (Retrieved May 9, 2024)

The original paper is: Marcel Vinokur. “On One-Dimensional Stretching Functions for Finite-Difference Calculations.” Journal of Computational and Physics (1983) https://doi.org/10.1016/0021-9991(83)90065-7

Parameters:
startfloat

The location to start sampling at

endfloat

The location to stop sampling at

nint

The number of points to sample

s0float

The desired spacing at the start location

s1float

The desired spacing at the end location

Returns:
distNdarray [N]

The parametric coordinates that define the distribution