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)
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 all(sorted_poly.points[ind_2] == sorted_poly.points[ind_hk])
assert all(sorted_poly.points[ind_1] == sorted_poly.points[ind_vk])

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

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
@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