Skip to content

Commit

Permalink
Fix changed names in NACA example (fixes #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Nov 24, 2014
1 parent b785c15 commit fa8ef2d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 50 deletions.
23 changes: 10 additions & 13 deletions examples/airfoil3d.py
@@ -1,11 +1,11 @@
def main():
import numpy
from math import pi, cos, sin
#from math import pi, cos, sin
from meshpy.tet import MeshInfo, build
from meshpy.geometry import GeometryBuilder, Marker, \
generate_extrusion, make_box

from meshpy.naca import generate_naca
from meshpy.naca import get_naca_points

geob = GeometryBuilder()

Expand All @@ -21,7 +21,7 @@ def main():
(r, x) for x, r in zip(
numpy.linspace(-wing_length, 0, wing_subdiv, endpoint=False),
numpy.linspace(0.8, 1, wing_subdiv, endpoint=False))
] + [(1,0)] + [
] + [(1, 0)] + [
(r, x) for x, r in zip(
numpy.linspace(wing_length, 0, wing_subdiv, endpoint=False),
numpy.linspace(0.8, 1, wing_subdiv, endpoint=False))
Expand All @@ -32,7 +32,7 @@ def main():

geob.add_geometry(*generate_extrusion(
rz_points=rz_points,
base_shape=generate_naca("0012", verbose=False, number_of_points=20),
base_shape=get_naca_points("0012", verbose=False, number_of_points=20),
ring_markers=(wing_subdiv*2+4)*[box_marker]))

from meshpy.tools import make_swizzle_matrix
Expand All @@ -42,29 +42,26 @@ def main():
def deform_wing(p):
x, y, z = p
return numpy.array([
x,
y + 0.1*abs(x/wing_length)**2,
z + 0.8*abs(x/wing_length)** 1.2])
x,
y + 0.1*abs(x/wing_length)**2,
z + 0.8*abs(x/wing_length) ** 1.2])

geob.apply_transform(deform_wing)

points, facets, _, facet_markers = make_box(
numpy.array([-wing_length-1,-1,-1.5]),
numpy.array([wing_length+1,1,3]))
numpy.array([-wing_length-1, -1, -1.5]),
numpy.array([wing_length+1, 1, 3]))

geob.add_geometry(points, facets, facet_markers=facet_markers)

mesh_info = MeshInfo()
geob.set(mesh_info)
mesh_info.set_holes([(0,0,0.5)])
mesh_info.set_holes([(0, 0, 0.5)])

mesh = build(mesh_info)
print "%d elements" % len(mesh.elements)
mesh.write_vtk("airfoil3d.vtk")




if __name__ == "__main__":
main()

55 changes: 19 additions & 36 deletions meshpy/naca.py
Expand Up @@ -3,12 +3,11 @@
import numpy



class FourDigitsSymmetric:
def __init__(self, thickness, edge_coeff):
self.thickness = thickness
self.edge_coeff = edge_coeff

def __call__(self, x, side):
t = self.thickness

Expand All @@ -24,7 +23,7 @@ def x_upper(x):
def x_lower(x):
return x

y = t * 5 * (0.2969 * numpy.sqrt(x) + ((((-self.edge_coeff * x +
y = t * 5 * (0.2969 * numpy.sqrt(x) + ((((-self.edge_coeff * x +
0.2843) * x - 0.3516) * x) - 0.126) * x)

if side == "upper":
Expand All @@ -35,9 +34,6 @@ def x_lower(x):
raise ValueError("Neither upper nor lower side selected in the call.")





class FourDigitsCambered:
def __init__(self, thickness, max_camber, max_camber_pos, edge_coeff):
self.thickness = thickness
Expand All @@ -62,8 +58,8 @@ def x_upper(x, y, theta):
def x_lower(x, y, theta):
return x + y * numpy.sin(theta)

y = t * 5 * (0.2969 * numpy.sqrt(x) + ((((-self.edge_coeff * x +
0.2843) * x - 0.3516) * x) -0.126) * x)
y = t * 5 * (0.2969 * numpy.sqrt(x) + ((((-self.edge_coeff * x +
0.2843) * x - 0.3516) * x) - 0.126) * x)

if x <= p:
y_c = m * x / p ** 2 * (2 * p - x)
Expand All @@ -80,9 +76,6 @@ def x_lower(x, y, theta):
raise ValueError("Neither upper nor lower side selected in the call.")





class FiveDigits:
def __init__(self, thickness, m, k1, edge_coeff):
self.thickness = thickness
Expand All @@ -107,12 +100,12 @@ def x_upper(x, y, theta):
def x_lower(x, y, theta):
return x + y * numpy.sin(theta)

y = t * 5 * (0.2969 * numpy.sqrt(x) + ((((-self.edge_coeff * x +
0.2843) * x - 0.3516) * x) -0.126) * x)
y = t * 5 * (0.2969 * numpy.sqrt(x) + ((((-self.edge_coeff * x +
0.2843) * x - 0.3516) * x) - 0.126) * x)

if x <= m:
y_c = k1 / 6 * x *((x - 3 * m) * x + m ** 2 * (3 - m))
theta = numpy.arctan(k1 / 6 * ((3 * x - 6 * m) * x +
y_c = k1 / 6 * x * ((x - 3 * m) * x + m ** 2 * (3 - m))
theta = numpy.arctan(k1 / 6 * ((3 * x - 6 * m) * x +
m ** 2 * (3 - m)))
else:
y_c = k1 * m ** 3 / 6 * (1 - x)
Expand All @@ -126,12 +119,9 @@ def x_lower(x, y, theta):
raise ValueError("Neither upper nor lower side selected in the call.")





def get_naca_points(naca_digits, number_of_points=100,
sharp_trailing_edge=True,
abscissa_map=lambda x: 0.03*x+0.97*x**2,
sharp_trailing_edge=True,
abscissa_map=lambda x: 0.03*x+0.97*x**2,
verbose=False):
"""
Return a list of coordinates of NACA 4-digit and 5-digit series
Expand All @@ -145,16 +135,15 @@ def explain(*s):
def explain(*s):
pass

explain("Airfoil: NACA-%s" %(naca_digits))
explain("Airfoil: NACA-%s" % naca_digits)

if sharp_trailing_edge == True:
if sharp_trailing_edge:
explain("Sharp trailing edge")
edge_coeff = 0.1036
else:
explain("Blunt trailing edge")
edge_coeff = 0.1015


raw_abscissae = numpy.linspace(0, 1, number_of_points, endpoint=True)
abscissae = numpy.empty_like(raw_abscissae)
for i in xrange(number_of_points):
Expand All @@ -179,10 +168,11 @@ def explain(*s):
points = FourDigitsSymmetric(thickness, edge_coeff)
elif max_camber != 0 and max_camber_pos != 0:
explain("Cambered 4-digit airfoil")
points = FourDigitsCambered(thickness, max_camber,
points = FourDigitsCambered(thickness, max_camber,
max_camber_pos, edge_coeff)
else:
raise NotImplementedError("You must decide whether your airfoil shall be cambered or not!")
raise NotImplementedError(
"You must decide whether your airfoil shall be cambered or not!")

elif len(naca_digits) == 5:
thickness = (digits_int % 100)
Expand Down Expand Up @@ -221,30 +211,25 @@ def explain(*s):
raise NotImplementedError(
"Only the 4-digit and 5-digit series are implemented!")

points_upper = numpy.zeros((len(abscissae),2))
points_lower = numpy.zeros((len(abscissae),2))
points_upper = numpy.zeros((len(abscissae), 2))
points_lower = numpy.zeros((len(abscissae), 2))

for i in range(len(abscissae)):
points_upper[i] = points(abscissae[i], "upper")
points_lower[i] = points(abscissae[i], "lower")

if sharp_trailing_edge == True:
if sharp_trailing_edge:
return list(points_upper)[1:-1] + list(points_lower[::-1])
else:
return list(points_upper)[1:] + list(points_lower[::-1])





def write_points(points, filename):
file = open(filename, "w")
for pt in points:
print >>file, "\t".join(repr(p_comp) for p_comp in pt)




def main():
from optparse import OptionParser

Expand All @@ -269,7 +254,7 @@ def main():
options.points = 100

digits = args[0]
points = generate_naca(digits,
points = get_naca_points(digits,
number_of_points=options.points,
sharp_trailing_edge=options.sharp_trailing_edge,
uniform_distribution=options.uniform_distribution,
Expand All @@ -282,7 +267,5 @@ def main():
write_points(points, options.output)




if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion setup.cfg
@@ -1,3 +1,3 @@
[flake8]
ignore = E126,E127,E128,E123,E226,E241,E242
ignore = E126,E127,E128,E123,E226,E241,E242,E265
max-line-length=85

0 comments on commit fa8ef2d

Please sign in to comment.