def test_alpha_quality_measure(): f = Face() n1 = Node(0, 0, 0) n2 = Node(1, 0, 0) n3 = Node(0.5, 0, 0.866) e1 = Edge() e1.nodes = [n1, n2] e2 = Edge() e2.nodes = [n2, n3] e3 = Edge() e3.nodes = [n3, n1] f.edges = [e1, e2, e3] f.nodes = [n1, n2, n3] assert 1 - f.alpha_quality_measure() < 10e-6, print( f.alpha_quality_measure())
def test_comparing_of_nodes(): n1 = Node(0, 0, 0, 1) n2 = Node(1, 0, 0, 2) n3 = Node(10e-18, 0, 0) n4 = Node(10e-17, 0, 0) n5 = Node(0, 10e-18, 0) n6 = Node(0, 10e-17, 0) n7 = Node(0, 0, 10e-18) n8 = Node(0, 0, 10e-17) assert AVLTree.is_node_less(n1, n2), 'Wrong node comparison' assert AVLTree.is_node_less(n3, n4), 'Wrong node comparison' assert AVLTree.is_node_less(n5, n6), 'Wrong node comparison' assert AVLTree.is_node_less(n7, n8), 'Wrong node comparison' print('Node comparison OK')
def test_area(): n1 = Node(0, 0, 0) n2 = Node(0, -0.5, 0) n3 = Node(1, -0.5, 0) f = Face() f.nodes = [n1, n2, n3] assert f.area() == 0.25, 'Wrong area' n1 = Node(10, -7, 1.45) n2 = Node(82, -0.5, 0) n3 = Node(1.222, 56, -18) f = Face() f.nodes = [n1, n2, n3] assert f.area() == 2402.8282235671577, 'Wrong area' n1 = Node(0.0001, 0.1122, -0.00012) n2 = Node(0.000001, -0.23123, -0.00000005) n3 = Node(1.222, -0.231200000001, -18) f = Face() f.nodes = [n1, n2, n3] assert f.area() == 3.0979846549411496, print(f.area())
def test3(): avl = AVLTree() n1 = Node(0, 0, 0, 1) n2 = Node(1, 0, 0, 2) n4 = Node(-1, 1, 0, 4) n3 = Node(-1, 0, 0, 3) n5 = Node(-1, 2, 0, 5) n6 = Node(-1, 3, 0, 6) n8 = Node(-1, 1.0000000000001, 0, 8) n9 = Node(0.0000000000000001, 0, 0, 9) nodes = [n1, n2, n3, n4, n5, n6] for n in nodes: avl.insert(n) assert not avl.find(n8), 'Wrong nearest neighbour found. test3.' assert not avl.find(n9), 'Wrong nearest neighbour found. test3.' print('Test 3 OK')
def test2(): avl = AVLTree() n1 = Node(0, 0, 0, 1) n2 = Node(1, 0, 0, 2) n3 = Node(-1, 0, 0, 3) n4 = Node(1, 1, 0, 4) n5 = Node(1, -1, 0.000000000000001, 5) n6 = Node(1, -1, 0.0000000000000001, 6) nodes = [n1, n2, n3, n4, n5] for n in nodes: avl.insert(n) assert avl.find(n5).Id == 5, 'Wrong node found' assert not avl.find(n6), 'Wrong node found' print('Test 2 OK')
def test_normals(): n1 = Node(0, 0, 0) n2 = Node(0, -1, 0) n3 = Node(1, 0, 0) f = Face() f.nodes = [n1, n2, n3] assert f.normal().x == 0, 'Wrong normal' assert f.normal().y == 0, 'Wrong normal' assert f.normal().z == 1, 'Wrong normal' n1 = Node(0, 0, 0) n2 = Node(0, -1, 0) n3 = Node(0, -2, 1) f = Face() f.nodes = [n1, n2, n3] assert f.normal().x == -1, 'Wrong normal' assert f.normal().y == 0, 'Wrong normal' assert f.normal().z == 0, 'Wrong normal'
def parce_nodes_and_faces(lines): """ Parce node and faces from tecplot file. Creates list of nodes and list of faces. Set the x, y coordinates of nodes. Add list of nodes' ids to each face. :param lines: tecplot lines representing the value and connectivity lists. :return: tuple (list, list): nodes and faces for a zone. """ # Read all nodes of zone 1. # x coords. xs = map(parcer, lines[0].split(' ')) # y coords. ys = map(parcer, lines[1].split(' ')) # z coords. zs = map(parcer, lines[2].split(' ')) t = map(parcer, lines[3].split(' ')[:-1]) hw = map(parcer, lines[4].split(' ')[:-1]) hi = map(parcer, lines[5].split(' ')[:-1]) htc = map(parcer, lines[6].split(' ')[:-1]) beta = map(parcer, lines[7].split(' ')[:-1]) taux = map(parcer, lines[8].split(' ')[:-1]) tauy = map(parcer, lines[9].split(' ')[:-1]) tauz = map(parcer, lines[10].split(' ')[:-1]) # Nodes of zone 1. nodes = list() # Initialize node array for zone 1. i = 1 for x, y, z in zip(xs, ys, zs): if x is None: continue if y is None: continue if z is None: continue n = Node() n.x = x n.y = y n.z = z n.Id = i i += 1 nodes.append(n) del xs, ys, zs faces = list() j = 0 for line in lines[NUMBER_OF_VARIABLES:]: f = Face(j) j += 1 ids = line.split(' ') if len(ids) > 3: ids = ids[:-1] try: ids = list(map(int, ids)) except ValueError: print('Unable to convert to int') f.nodes_ids = ids faces.append(f) if ids[0] == ids[1] or ids[1] == ids[2] or ids[0] == ids[2]: print(ids[0], ids[1], ids[2]) raise ValueError('Identical ids in the triangular_grid') for f, t_, hw_, hi_, htc_, beta_, taux_, tauy_, tauz_ in zip(faces, t, hw, hi, htc, beta, taux, tauy, tauz): f.T = t_ f.Hw = hw_ f.Hi = hi_ f.HTC = htc_ f.Beta = beta_ f.TauX = taux_ f.TauY = tauy_ f.TauZ = tauz_ return nodes, faces