- Timestamp:
- Aug 1, 2007, 10:22:11 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/fit_interpolate/search_functions.py
r4599 r4649 97 97 98 98 # Find triangle that contains x (if any) and interpolate 99 element_found, sigma0, sigma1, sigma2, k =\ 100 find_triangle_compute_interpolation(mesh, 101 triangle_list, 102 x) 99 100 for k, _ in triangle_list: 101 element_found, sigma0, sigma1, sigma2, k =\ 102 find_triangle_compute_interpolation(mesh, 103 k, 104 x) 105 106 if element_found is True: 107 # Don't look for any other triangles in the triangle list 108 break 103 109 104 110 if element_found is True: 105 # Don't look for any other triangle 111 # Don't look for any other triangle_lists from the 112 # candidate_vertices 106 113 break 107 108 114 109 115 return element_found, sigma0, sigma1, sigma2, k … … 111 117 112 118 113 def find_triangle_compute_interpolation(mesh, triangle_list, x):119 def find_triangle_compute_interpolation(mesh, k, x): 114 120 """Compute linear interpolation of point x and triangle k in mesh. 115 121 It is assumed that x belongs to triangle k. 116 122 """ 117 123 118 element_found = False 119 for k, _ in triangle_list: 120 # Get the three vertex_points of candidate triangle k 121 xi0, xi1, xi2 = mesh.get_vertex_coordinates(triangle_id=k) 122 123 # Get the three normals 124 n0 = mesh.get_normal(k, 0) 125 n1 = mesh.get_normal(k, 1) 126 n2 = mesh.get_normal(k, 2) 124 # Get the three vertex_points of candidate triangle k 125 xi0, xi1, xi2 = mesh.get_vertex_coordinates(triangle_id=k) 126 127 # this is where we can call some fast c code. 128 xmax = max(xi0[0], xi1[0], xi2[0]) 129 xmin = min(xi0[0], xi1[0], xi2[0]) 130 ymax = max(xi0[1], xi1[1], xi2[1]) 131 ymin = min(xi0[1], xi1[1], xi2[1]) 132 133 # Integrity check - machine precision is too hard 134 # so we use hardwired single precision 135 epsilon = 1.0e-6 136 137 if x[0] > xmax + epsilon: 138 return False,0,0,0,0 139 if x[0] < xmin - epsilon: 140 return False,0,0,0,0 141 if x[1] > ymax + epsilon: 142 return False,0,0,0,0 143 if x[1] < ymin - epsilon: 144 return False,0,0,0,0 145 146 147 # Get the three normals 148 n0 = mesh.get_normal(k, 0) 149 n1 = mesh.get_normal(k, 1) 150 n2 = mesh.get_normal(k, 2) 127 151 128 152 129 130 131 132 153 # Compute interpolation 154 sigma2 = dot((x-xi0), n2)/dot((xi2-xi0), n2) 155 sigma0 = dot((x-xi1), n0)/dot((xi0-xi1), n0) 156 sigma1 = dot((x-xi2), n1)/dot((xi1-xi2), n1) 133 157 134 # Integrity check - machine precision is too hard 135 # so we use hardwired single precision 136 epsilon = 1.0e-6 137 delta = abs(sigma0+sigma1+sigma2-1.0) # Should be close to zero 138 msg = 'abs(sigma0+sigma1+sigma2-1) = %.15e, eps = %.15e'\ 139 %(delta, epsilon) 140 assert delta < epsilon, msg 158 delta = abs(sigma0+sigma1+sigma2-1.0) # Should be close to zero 159 msg = 'abs(sigma0+sigma1+sigma2-1) = %.15e, eps = %.15e'\ 160 %(delta, epsilon) 161 assert delta < epsilon, msg 141 162 142 163 143 144 145 146 147 148 149 break150 164 # Check that this triangle contains the data point 165 # Sigmas are allowed to get negative within 166 # machine precision on some machines (e.g. nautilus) 167 epsilon = get_machine_precision() * 2 168 if sigma0 >= -epsilon and sigma1 >= -epsilon and sigma2 >= -epsilon: 169 element_found = True 170 else: 171 element_found = False 151 172 return element_found, sigma0, sigma1, sigma2, k
Note: See TracChangeset
for help on using the changeset viewer.