Newer
Older
def test_extract_vk_hk(verbose=False):
"""
tests a NACA profile in a random angle as a minimal example.
:return:
"""
from ntrfc.turbo.profile_tele_extraction import extract_vk_hk
from ntrfc.turbo.airfoil_generators.naca_airfoil_creator import naca
import numpy as np
import pyvista as pv
# d1,d2,d3,d4 = np.random.randint(0,9),np.random.randint(0,9),np.random.randint(0,9),np.random.randint(0,9)
# digitstring = str(d1)+str(d2)+str(d3)+str(d4)
# manifold problems with other profiles with veronoi-mid and other unoptimized code. therefor tests only 0009
# todo: currently we cant test half_cosine_spacing profiles, as the resolution is too good for extract_vk_hk
xs, ys = naca(naca_code, res, half_cosine_spacing=False, finite_te=False)
sorted_poly = pv.PolyData(np.stack([xs[:-1], ys[:-1], np.zeros(len(xs) - 1)]).T)
X, Y = sorted_poly.points[::, 0], sorted_poly.points[::, 1]
ind_1 = res
ind_2 = 0
points = np.stack((X[:], Y[:], np.zeros(len(X)))).T
profile_points = pv.PolyData(points)
sorted_poly = pv.PolyData(profile_points)
ind_vk, ind_hk = extract_vk_hk(sorted_poly)
p.add_mesh(sorted_poly.points[ind_hk], color="yellow", point_size=20)
p.add_mesh(sorted_poly.points[ind_vk], color="red", point_size=20)
p.add_mesh(sorted_poly)
assert ind_hk == ind_2, "wrong hk-index chosen"
assert ind_vk == ind_1, "wrong vk-index chosen"

Malte Nyhuis
committed
from ntrfc.turbo.cascade_case.utils.domain_utils import Blade2D
from ntrfc.math.vectorcalc import vecAbs
from ntrfc.turbo.airfoil_generators.naca_airfoil_creator import naca
import numpy as np
import pyvista as pv

Malte Nyhuis
committed
res = 240

Malte Nyhuis
committed
points = np.stack((x[:], y[:], np.zeros(res * 2))).T
blade = Blade2D(points)
blade.compute_all_frompoints()

Malte Nyhuis
committed
length = blade.skeletonline_pv.length
testlength = vecAbs(blade.ss_pv.points[0] - blade.ss_pv.points[-1])
p.add_mesh(blade.sortedpointsrolled_pv)
p.add_mesh(blade.skeletonline_pv)
p.add_mesh(blade.sortedpointsrolled_pv.points[blade.ite], color="k", label="hk", point_size=20)
p.add_mesh(blade.sortedpointsrolled_pv.points[blade.ile], color="g", label="vk", point_size=20)
p.add_legend()
assert np.isclose(length, testlength, rtol=1e-3), "midline not accurate"

Malte Nyhuis
committed
def test_midLength():
from ntrfc.turbo.pointcloud_methods import mid_length

Malte Nyhuis
committed
import numpy as np
import pyvista as pv
radius = 0.5
res = 100
mid = int(res / 2)
theta = np.linspace(0, 2 * np.pi, 100)
x = radius * np.cos(theta)
y = radius * np.sin(theta)
fake_vk = 0
fake_hk = mid
circle = pv.PolyData(np.stack([x, y, np.zeros(len(x))]).T)
length = mid_length(fake_vk, fake_hk, circle)
assert np.isclose(2 * radius, length, rtol=5e-4), "length should be two times the size of the defined test-circle"

Malte Nyhuis
committed
@pytest.mark.parametrize("xs, ys, expected_result", [
([0, 1, 2, 2, 1, 0], [0, 0, 1, 2, 2, 1], True),
([0, 1, 2, 2, 1, 0], [0, 1, 2, 2, 1, 0], False),
])
def test_orientation_of_circle(xs, ys, expected_result):
from ntrfc.turbo.pointcloud_methods import is_counterclockwise
assert is_counterclockwise(xs, ys) is expected_result
from ntrfc.geometry.plane import inside_poly
# Test for a simple polygon and point
polygon = [(0, 0), (0, 1), (1, 1), (1, 0)]
point = [(0.5, 0.5)]
assert inside_poly(polygon, point)[0] == True
# Test for a point outside the polygon
polygon = [(0, 0), (0, 1), (1, 1), (1, 0)]
point = [(1.5, 1.5)]
assert inside_poly(polygon, point)[0] == False
# Test for a point on the boundary of the polygon
polygon = [(0, 0), (0, 1), (1, 1), (1, 0)]
point = [(1, 1)]
assert inside_poly(polygon, point)[0] == False