Results of my master's thesis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

#### 148 lines 3.7KB Raw Blame History

 ``````from grid import exact_func import numpy as np import sys def get_phis(X, r): """ The get_phis function is used to get barycentric coordonites for a point on a triangle. X -- the destination point (2D) X = [0,0] r -- the three points that make up the triangle (2D) r = [[-1, -1], [0, 2], [1, -1]] this will return [0.333, 0.333, 0.333] """ # baker: eq 7 A = np.array([ [ 1, 1, 1], [r, r, r], [r, r, r], ]) b = np.array([ 1, X, X ]) try: phi = np.linalg.solve(A,b) except: print >> sys.stderr, "warning: calculation of phis yielded a linearly dependant system" phi = np.dot(np.linalg.pinv(A), b) return phi def get_phis_3D(X, r): """ The get_phis function is used to get barycentric coordonites for a point on a triangle. X -- the destination point (3D) X = [0,0,0] r -- the four points that make up the tetrahedron (3D) r = [[-1, -1], [0, 2], [1, -1]] this will return [0.333, 0.333, 0.333] """ # baker: eq 7 A = np.array([ [ 1, 1, 1, 1 ], [r, r, r, r], [r, r, r, r], [r, r, r, r], ]) b = np.array([ 1, X, X, X ]) try: phi = np.linalg.solve(A,b) except: print >> sys.stderr, "warning: calculation of phis yielded a linearly dependant system" phi = np.dot(np.linalg.pinv(A), b) return phi def qlinear(X, r, q): """ this calculates the linear portion of q from X to r X = destination point r = simplex points q = CFD quantities of interest at the simplex points """ phis = get_phis(X, r) qlin = sum([q_i * phi_i for q_i, phi_i in zip(q[:len(phis)], phis)]) return qlin def qlinear_3D(X, r, q): """ this calculates the linear portion of q from X to r X = destination point r = simplex points q = CFD quantities of interest at the simplex points(r) """ phis = get_phis_3D(X, r) qlin = sum([q_i * phi_i for q_i, phi_i in zip(q[:len(phis)], phis)]) return qlin def run_baker(X, g, tree, extra_points = 3, verbose = False): """ This is the main function to call to get an interpolation to X from the tree X -- the destination point (2D) X = [0,0] g -- the grid object tree -- the kdtree search object (built from the g mesh) """ (dist, indicies) = tree.query(X, 3 + extra_points) nn = [g.points[i] for i in indicies] nq = [g.q[i] for i in indicies] # calculate values only for the triangle phi = get_phis(X, nn[:3]) qlin = qlinear(X, nn[:3], nq[:3])# nq * phi + nq * phi + nq * phi error_term = 0.0 if extra_points != 0: B = [] # baker eq 9 w = [] # baker eq 11 for index in indicies[3:]: (phi1,phi2,phi3) = get_phis(g.points[index], nn) B.append([phi1 * phi2, phi2*phi3, phi3*phi1]) w.append(g.q[index] - qlinear(g.points[index], nn, nq)) B = np.array(B) w = np.array(w) A = np.dot(B.T, B) b = np.dot(B.T, w) # baker solve eq 10 try: (a, b, c) = np.linalg.solve(A,b) except: print >> sys.stderr, "warning: linear calculation went bad, resorting to np.linalg.pinv" (a, b, c) = np.dot(np.linalg.pinv(A), b) error_term = a * phi * phi\ + b * phi * phi\ + c * phi * phi q_final = qlin + error_term return qlin, error_term, q_final``````