[7388] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | import unittest |
---|
| 4 | import sys |
---|
| 5 | from math import sqrt |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | from anuga.interface import Domain |
---|
| 9 | from anuga.interface import rectangular_cross |
---|
| 10 | |
---|
| 11 | from parallel_shallow_water import Parallel_Domain |
---|
| 12 | |
---|
| 13 | from anuga_parallel.pmesh_divide import pmesh_divide_metis |
---|
| 14 | from anuga_parallel.build_submesh import build_submesh |
---|
[7391] | 15 | from anuga_parallel.build_submesh import submesh_full, submesh_ghost, submesh_quantities |
---|
[7388] | 16 | from anuga_parallel.build_commun import extract_hostmesh, rec_submesh, send_submesh |
---|
| 17 | |
---|
[7391] | 18 | #import numpy as num |
---|
| 19 | import Numeric as num |
---|
[7388] | 20 | |
---|
| 21 | def topography(x,y): |
---|
| 22 | return -x/2 |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | def xcoord(x,y): |
---|
| 26 | return x |
---|
| 27 | |
---|
| 28 | def ycoord(x,y): |
---|
| 29 | return y |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | |
---|
[7394] | 33 | class Test_Distribute_Mesh(unittest.TestCase): |
---|
[7388] | 34 | def setUp(self): |
---|
| 35 | pass |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | def tearDown(self): |
---|
| 39 | pass |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | def test_pmesh_1(self): |
---|
| 44 | |
---|
| 45 | points, vertices, boundary = rectangular_cross(2,2) |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | true_points = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] |
---|
| 49 | |
---|
| 50 | true_vertices = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]] |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | assert num.allclose(points,true_points) |
---|
| 54 | assert num.allclose(vertices,true_vertices) |
---|
| 55 | |
---|
| 56 | domain = Domain(points, vertices, boundary) |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
| 60 | domain.set_quantity('friction', 0.0) # Constant friction |
---|
| 61 | domain.set_quantity('stage', expression='elevation') # Dry initial stage |
---|
| 62 | domain.set_quantity('xmomentum', expression='friction + 2.0') # |
---|
| 63 | domain.set_quantity('ymomentum', ycoord) # |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | #print domain.quantities['ymomentum'].centroid_values |
---|
| 67 | |
---|
| 68 | nodes, triangles, boundary, triangles_per_proc, quantities = pmesh_divide_metis(domain,1) |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | true_nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] |
---|
| 72 | |
---|
| 73 | true_triangles = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]] |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | assert num.allclose(nodes,true_nodes) |
---|
| 77 | assert num.allclose(triangles,true_triangles) |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | assert num.allclose(triangles_per_proc,[16]) |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | def test_pmesh_2(self): |
---|
| 85 | |
---|
| 86 | points, vertices, boundary = rectangular_cross(2,2) |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | true_points = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] |
---|
| 90 | |
---|
| 91 | true_vertices = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]] |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | assert num.allclose(points,true_points) |
---|
| 95 | assert num.allclose(vertices,true_vertices) |
---|
| 96 | |
---|
| 97 | domain = Domain(points, vertices, boundary) |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
| 101 | domain.set_quantity('friction', 0.0) # Constant friction |
---|
| 102 | domain.set_quantity('stage', expression='elevation') # Dry initial stage |
---|
| 103 | domain.set_quantity('xmomentum', expression='friction + 2.0') # |
---|
| 104 | domain.set_quantity('ymomentum', ycoord) # |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | #print domain.quantities['ymomentum'].centroid_values |
---|
| 108 | |
---|
| 109 | nodes, triangles, boundary, triangles_per_proc, quantities = pmesh_divide_metis(domain,2) |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | true_nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | true_triangles = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [4, 10, 1], [3, 11, 4], [4, 11, 7], [4, 12, 5], [1, 10, 2], [5, 10, 4], [2, 10, 5], [6, 11, 3], [7, 11, 6], [7, 12, 4], [8, 12, 7], [5, 12, 8]] |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | assert num.allclose(nodes,true_nodes) |
---|
| 119 | assert num.allclose(triangles,true_triangles) |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | assert num.allclose(triangles_per_proc,[8,8]) |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | print triangles_per_proc |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | def test_distibute_3(self): |
---|
| 129 | |
---|
| 130 | import pypar |
---|
| 131 | |
---|
| 132 | myid = pypar.rank() |
---|
| 133 | numprocs = pypar.size() |
---|
| 134 | |
---|
| 135 | assert numprocs == 3, 'Should be run on 3 processors' |
---|
| 136 | |
---|
| 137 | if myid == 0: |
---|
| 138 | |
---|
| 139 | points, vertices, boundary = rectangular_cross(2,2) |
---|
| 140 | |
---|
| 141 | domain = Domain(points, vertices, boundary) |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
| 145 | domain.set_quantity('friction', 0.0) # Constant friction |
---|
| 146 | domain.set_quantity('stage', expression='elevation') # Dry initial stage |
---|
| 147 | domain.set_quantity('xmomentum', expression='friction + 2.0') # |
---|
| 148 | domain.set_quantity('ymomentum', ycoord) # |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | #---------------------------------------------------------------------------------- |
---|
| 154 | # Test pmesh_divide_metis |
---|
| 155 | #---------------------------------------------------------------------------------- |
---|
| 156 | nodes, triangles, boundary, triangles_per_proc, quantities = pmesh_divide_metis(domain,numprocs) |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | assert num.allclose(nodes,points) |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | true_vertices = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]] |
---|
| 163 | |
---|
| 164 | true_triangles = [[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8], [0, 9, 1], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 9, 0], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7]] |
---|
| 165 | |
---|
| 166 | assert num.allclose(vertices,true_vertices) |
---|
| 167 | assert num.allclose(triangles,true_triangles) |
---|
| 168 | |
---|
| 169 | assert num.allclose(triangles_per_proc,[5,6,5]) |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | #---------------------------------------------------------------------------------- |
---|
| 173 | # Test build_submesh |
---|
| 174 | #---------------------------------------------------------------------------------- |
---|
| 175 | submesh = build_submesh(nodes, triangles, boundary, quantities, triangles_per_proc) |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | assert num.allclose(submesh['full_nodes'][0],[[3.0, 0.5, 0.0], [4.0, 0.5, 0.5], [5.0, 0.5, 1.0], [7.0, 1.0, 0.5], [8.0, 1.0, 1.0], [9.0, 0.25, 0.25], [12.0, 0.75, 0.75]]) |
---|
| 179 | assert num.allclose(submesh['full_nodes'][1],[[0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 0.0, 1.0], [4.0, 0.5, 0.5], [5.0, 0.5, 1.0], [9.0, 0.25, 0.25], [10.0, 0.25, 0.75]]) |
---|
| 180 | assert num.allclose(submesh['full_nodes'][2],[[0.0, 0.0, 0.0], [3.0, 0.5, 0.0], [4.0, 0.5, 0.5], [6.0, 1.0, 0.0], [7.0, 1.0, 0.5], [9.0, 0.25, 0.25], [11.0, 0.75, 0.25]]) |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | assert num.allclose(submesh['ghost_nodes'][0],[[0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 0.0, 1.0], [6.0, 1.0, 0.0], [10.0, 0.25, 0.75], [11.0, 0.75, 0.25]]) |
---|
| 184 | assert num.allclose(submesh['ghost_nodes'][1],[[3.0, 0.5, 0.0], [7.0, 1.0, 0.5], [8.0, 1.0, 1.0], [11.0, 0.75, 0.25], [12.0, 0.75, 0.75]]) |
---|
| 185 | assert num.allclose(submesh['ghost_nodes'][2],[[1.0, 0.0, 0.5], [5.0, 0.5, 1.0], [8.0, 1.0, 1.0], [12.0, 0.75, 0.75]]) |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | true_full_triangles = [num.array([[ 4, 9, 3], |
---|
| 190 | [ 4, 12, 5], |
---|
| 191 | [ 7, 12, 4], |
---|
| 192 | [ 8, 12, 7], |
---|
| 193 | [ 5, 12, 8]]), |
---|
| 194 | num.array([[ 0, 9, 1], |
---|
| 195 | [ 1, 9, 4], |
---|
| 196 | [ 1, 10, 2], |
---|
| 197 | [ 4, 10, 1], |
---|
| 198 | [ 5, 10, 4], |
---|
| 199 | [ 2, 10, 5]]), |
---|
| 200 | num.array([[ 3, 9, 0], |
---|
| 201 | [ 3, 11, 4], |
---|
| 202 | [ 6, 11, 3], |
---|
| 203 | [ 7, 11, 6], |
---|
| 204 | [ 4, 11, 7]])] |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | assert num.allclose(submesh['full_triangles'][0],true_full_triangles[0]) |
---|
| 208 | assert num.allclose(submesh['full_triangles'][1],true_full_triangles[1]) |
---|
| 209 | assert num.allclose(submesh['full_triangles'][2],true_full_triangles[2]) |
---|
| 210 | |
---|
| 211 | true_ghost_triangles = [num.array([[ 5, 0, 9, 1], |
---|
| 212 | [ 6, 1, 9, 4], |
---|
| 213 | [ 8, 4, 10, 1], |
---|
| 214 | [ 9, 5, 10, 4], |
---|
| 215 | [10, 2, 10, 5], |
---|
| 216 | [11, 3, 9, 0], |
---|
| 217 | [12, 3, 11, 4], |
---|
| 218 | [13, 6, 11, 3], |
---|
| 219 | [14, 7, 11, 6], |
---|
| 220 | [15, 4, 11, 7]]), |
---|
| 221 | num.array([[ 0, 4, 9, 3], |
---|
| 222 | [ 1, 4, 12, 5], |
---|
| 223 | [ 2, 7, 12, 4], |
---|
| 224 | [ 4, 5, 12, 8], |
---|
| 225 | [11, 3, 9, 0], |
---|
| 226 | [12, 3, 11, 4]]), |
---|
| 227 | num.array([[ 0, 4, 9, 3], |
---|
| 228 | [ 1, 4, 12, 5], |
---|
| 229 | [ 2, 7, 12, 4], |
---|
| 230 | [ 3, 8, 12, 7], |
---|
| 231 | [ 5, 0, 9, 1], |
---|
| 232 | [ 6, 1, 9, 4]])] |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | assert num.allclose(submesh['ghost_triangles'][0],true_ghost_triangles[0]) |
---|
| 237 | assert num.allclose(submesh['ghost_triangles'][1],true_ghost_triangles[1]) |
---|
| 238 | assert num.allclose(submesh['ghost_triangles'][2],true_ghost_triangles[2]) |
---|
| 239 | |
---|
| 240 | true_full_commun = [{0: [1, 2], 1: [1, 2], 2: [1, 2], 3: [2], 4: [1]}, {5: [0, 2], 6: [0, 2], 7: [], 8: [0], 9: [0], 10: [0]}, {11: [0, 1], 12: [0, 1], 13: [0], 14: [0], 15: [0]}] |
---|
| 241 | |
---|
| 242 | assert true_full_commun == submesh['full_commun'] |
---|
| 243 | |
---|
| 244 | |
---|
| 245 | true_ghost_commun = [num.array([[ 5, 1], |
---|
| 246 | [ 6, 1], |
---|
| 247 | [ 8, 1], |
---|
| 248 | [ 9, 1], |
---|
| 249 | [10, 1], |
---|
| 250 | [11, 2], |
---|
| 251 | [12, 2], |
---|
| 252 | [13, 2], |
---|
| 253 | [14, 2], |
---|
| 254 | [15, 2]]), |
---|
| 255 | num.array([[ 0, 0], |
---|
| 256 | [ 1, 0], |
---|
| 257 | [ 2, 0], |
---|
| 258 | [ 4, 0], |
---|
| 259 | [11, 2], |
---|
| 260 | [12, 2]]), |
---|
| 261 | num.array([[0, 0], |
---|
| 262 | [1, 0], |
---|
| 263 | [2, 0], |
---|
| 264 | [3, 0], |
---|
| 265 | [5, 1], |
---|
| 266 | [6, 1]])] |
---|
| 267 | |
---|
| 268 | assert num.allclose(submesh['ghost_commun'][0],true_ghost_commun[0]) |
---|
| 269 | assert num.allclose(submesh['ghost_commun'][1],true_ghost_commun[1]) |
---|
| 270 | assert num.allclose(submesh['ghost_commun'][2],true_ghost_commun[2]) |
---|
| 271 | |
---|
| 272 | |
---|
| 273 | #---------------------------------------------------------------------------------- |
---|
| 274 | # Test send_submesh |
---|
| 275 | #---------------------------------------------------------------------------------- |
---|
| 276 | for p in range(1, numprocs): |
---|
| 277 | send_submesh(submesh, triangles_per_proc, p) |
---|
| 278 | |
---|
| 279 | #---------------------------------------------------------------------------------- |
---|
| 280 | # Test extract_hostmesh |
---|
| 281 | #---------------------------------------------------------------------------------- |
---|
| 282 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict =\ |
---|
| 283 | extract_hostmesh(submesh, triangles_per_proc) |
---|
| 284 | |
---|
| 285 | |
---|
| 286 | true_points = [[0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.75, 0.75], [0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [1.0, 0.0], [0.25, 0.75], [0.75, 0.25]] |
---|
| 287 | |
---|
| 288 | true_vertices = [[1, 5, 0], [1, 6, 2], [3, 6, 1], [4, 6, 3], [2, 6, 4], [7, 5, 8], [8, 5, 1], [1, 11, 8], [2, 11, 1], [9, 11, 2], [0, 5, 7], [0, 12, 1], [10, 12, 0], [3, 12, 10], [1, 12, 3]] |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | true_ghost_recv = {1: [num.array([5, 6, 7, 8, 9]), num.array([ 5, 6, 8, 9, 10])], 2: [num.array([10, 11, 12, 13, 14]), num.array([11, 12, 13, 14, 15])]} |
---|
| 292 | |
---|
| 293 | |
---|
| 294 | true_full_send = {1: [num.array([0, 1, 2, 4]), num.array([0, 1, 2, 4])], 2: [num.array([0, 1, 2, 3]), num.array([0, 1, 2, 3])]} |
---|
| 295 | |
---|
| 296 | assert num.allclose(points, true_points) |
---|
| 297 | assert num.allclose(vertices, true_vertices) |
---|
| 298 | assert num.allclose(ghost_recv_dict[1],true_ghost_recv[1]) |
---|
| 299 | assert num.allclose(ghost_recv_dict[2],true_ghost_recv[2]) |
---|
| 300 | assert num.allclose(full_send_dict[1],true_full_send[1]) |
---|
| 301 | assert num.allclose(full_send_dict[2],true_full_send[2]) |
---|
| 302 | |
---|
| 303 | #print triangles_per_proc |
---|
| 304 | |
---|
| 305 | else: |
---|
| 306 | #---------------------------------------------------------------------------------- |
---|
| 307 | # Test rec_submesh |
---|
| 308 | #---------------------------------------------------------------------------------- |
---|
| 309 | points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict, no_full_nodes, no_full_trigs = rec_submesh(0) |
---|
| 310 | |
---|
| 311 | if myid == 1: |
---|
| 312 | |
---|
| 313 | |
---|
| 314 | true_points = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.5], [0.5, 1.0], [0.25, 0.25], [0.25, 0.75], [0.5, 0.0], [1.0, 0.5], [1.0, 1.0], [0.75, 0.25], [0.75, 0.75]] |
---|
| 315 | |
---|
| 316 | true_vertices = [[0, 5, 1], [1, 5, 3], [1, 6, 2], [3, 6, 1], [4, 6, 3], [2, 6, 4], [3, 5, 7], [3, 11, 4], [8, 11, 3], [4, 11, 9], [7, 5, 0], [7, 10, 3]] |
---|
| 317 | |
---|
| 318 | true_ghost_recv = {0: [num.array([6, 7, 8, 9]), num.array([0, 1, 2, 4])], 2: [num.array([10, 11]), num.array([11, 12])]} |
---|
| 319 | |
---|
| 320 | true_full_send = {0: [num.array([0, 1, 3, 4, 5]), num.array([ 5, 6, 8, 9, 10])], 2: [num.array([0, 1]), num.array([5, 6])]} |
---|
| 321 | |
---|
| 322 | assert num.allclose(points, true_points) |
---|
| 323 | assert num.allclose(vertices, true_vertices) |
---|
| 324 | assert num.allclose(ghost_recv_dict[0],true_ghost_recv[0]) |
---|
| 325 | assert num.allclose(ghost_recv_dict[2],true_ghost_recv[2]) |
---|
| 326 | assert num.allclose(full_send_dict[0],true_full_send[0]) |
---|
| 327 | assert num.allclose(full_send_dict[2],true_full_send[2]) |
---|
| 328 | |
---|
| 329 | |
---|
| 330 | if myid == 2: |
---|
| 331 | |
---|
| 332 | true_points = [[0.0, 0.0], [0.5, 0.0], [0.5, 0.5], [1.0, 0.0], [1.0, 0.5], [0.25, 0.25], [0.75, 0.25], [0.0, 0.5], [0.5, 1.0], [1.0, 1.0], [0.75, 0.75]] |
---|
| 333 | |
---|
| 334 | true_vertices = [[1, 5, 0], [1, 6, 2], [3, 6, 1], [4, 6, 3], [2, 6, 4], [2, 5, 1], [2, 10, 8], [4, 10, 2], [9, 10, 4], [0, 5, 7], [7, 5, 2]] |
---|
| 335 | |
---|
| 336 | |
---|
| 337 | true_ghost_recv = {0: [num.array([5, 6, 7, 8]), num.array([0, 1, 2, 3])], 1: [num.array([ 9, 10]), num.array([5, 6])]} |
---|
| 338 | |
---|
| 339 | true_full_send = {0: [num.array([0, 1, 2, 3, 4]), num.array([11, 12, 13, 14, 15])], 1: [num.array([0, 1]), num.array([11, 12])]} |
---|
| 340 | |
---|
| 341 | |
---|
| 342 | assert num.allclose(points, true_points) |
---|
| 343 | assert num.allclose(vertices, true_vertices) |
---|
| 344 | assert num.allclose(ghost_recv_dict[0],true_ghost_recv[0]) |
---|
| 345 | assert num.allclose(ghost_recv_dict[1],true_ghost_recv[1]) |
---|
| 346 | assert num.allclose(full_send_dict[0],true_full_send[0]) |
---|
| 347 | assert num.allclose(full_send_dict[1],true_full_send[1]) |
---|
| 348 | |
---|
| 349 | |
---|
| 350 | par_domain = Parallel_Domain(points, vertices, boundary, |
---|
| 351 | full_send_dict = full_send_dict, |
---|
| 352 | ghost_recv_dict = ghost_recv_dict) |
---|
| 353 | |
---|
| 354 | |
---|
| 355 | |
---|
| 356 | |
---|
| 357 | |
---|
| 358 | |
---|
| 359 | |
---|
| 360 | |
---|
| 361 | def test_build_submesh_3(self): |
---|
| 362 | |
---|
| 363 | |
---|
| 364 | nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] |
---|
| 365 | |
---|
| 366 | |
---|
| 367 | triangles = [[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8], [0, 9, 1], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 9, 0], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7]] |
---|
| 368 | |
---|
| 369 | |
---|
[7391] | 370 | edges = {(13, 1): 'bottom', (7, 1): 'left', (3, 1): 'right', (14, 1): 'right', (11, 1): 'bottom', (10, 1): 'top', (5, 1): 'left', (4, 1): 'top'} |
---|
[7388] | 371 | |
---|
| 372 | triangles_per_proc = [5, 6, 5] |
---|
| 373 | |
---|
| 374 | |
---|
| 375 | quantities = {'stage': num.array([[-0.25 , -0.125, -0.25 ], |
---|
| 376 | [-0.25 , -0.375, -0.25 ], |
---|
| 377 | [-0.5 , -0.375, -0.25 ], |
---|
| 378 | [-0.5 , -0.375, -0.5 ], |
---|
| 379 | [-0.25 , -0.375, -0.5 ], |
---|
| 380 | [-0. , -0.125, -0. ], |
---|
| 381 | [-0. , -0.125, -0.25 ], |
---|
| 382 | [-0. , -0.125, -0. ], |
---|
| 383 | [-0.25 , -0.125, -0. ], |
---|
| 384 | [-0.25 , -0.125, -0.25 ], |
---|
| 385 | [-0. , -0.125, -0.25 ], |
---|
| 386 | [-0.25 , -0.125, -0. ], |
---|
| 387 | [-0.25 , -0.375, -0.25 ], |
---|
| 388 | [-0.5 , -0.375, -0.25 ], |
---|
| 389 | [-0.5 , -0.375, -0.5 ], |
---|
| 390 | [-0.25 , -0.375, -0.5 ]]), 'elevation': num.array([[-0.25 , -0.125, -0.25 ], |
---|
| 391 | [-0.25 , -0.375, -0.25 ], |
---|
| 392 | [-0.5 , -0.375, -0.25 ], |
---|
| 393 | [-0.5 , -0.375, -0.5 ], |
---|
| 394 | [-0.25 , -0.375, -0.5 ], |
---|
| 395 | [-0. , -0.125, -0. ], |
---|
| 396 | [-0. , -0.125, -0.25 ], |
---|
| 397 | [-0. , -0.125, -0. ], |
---|
| 398 | [-0.25 , -0.125, -0. ], |
---|
| 399 | [-0.25 , -0.125, -0.25 ], |
---|
| 400 | [-0. , -0.125, -0.25 ], |
---|
| 401 | [-0.25 , -0.125, -0. ], |
---|
| 402 | [-0.25 , -0.375, -0.25 ], |
---|
| 403 | [-0.5 , -0.375, -0.25 ], |
---|
| 404 | [-0.5 , -0.375, -0.5 ], |
---|
| 405 | [-0.25 , -0.375, -0.5 ]]), 'ymomentum': num.array([[ 0.5 , 0.25, 0. ], |
---|
| 406 | [ 0.5 , 0.75, 1. ], |
---|
| 407 | [ 0.5 , 0.75, 0.5 ], |
---|
| 408 | [ 1. , 0.75, 0.5 ], |
---|
| 409 | [ 1. , 0.75, 1. ], |
---|
| 410 | [ 0. , 0.25, 0.5 ], |
---|
| 411 | [ 0.5 , 0.25, 0.5 ], |
---|
| 412 | [ 0.5 , 0.75, 1. ], |
---|
| 413 | [ 0.5 , 0.75, 0.5 ], |
---|
| 414 | [ 1. , 0.75, 0.5 ], |
---|
| 415 | [ 1. , 0.75, 1. ], |
---|
| 416 | [ 0. , 0.25, 0. ], |
---|
| 417 | [ 0. , 0.25, 0.5 ], |
---|
| 418 | [ 0. , 0.25, 0. ], |
---|
| 419 | [ 0.5 , 0.25, 0. ], |
---|
| 420 | [ 0.5 , 0.25, 0.5 ]]), 'friction': num.array([[ 0., 0., 0.], |
---|
| 421 | [ 0., 0., 0.], |
---|
| 422 | [ 0., 0., 0.], |
---|
| 423 | [ 0., 0., 0.], |
---|
| 424 | [ 0., 0., 0.], |
---|
| 425 | [ 0., 0., 0.], |
---|
| 426 | [ 0., 0., 0.], |
---|
| 427 | [ 0., 0., 0.], |
---|
| 428 | [ 0., 0., 0.], |
---|
| 429 | [ 0., 0., 0.], |
---|
| 430 | [ 0., 0., 0.], |
---|
| 431 | [ 0., 0., 0.], |
---|
| 432 | [ 0., 0., 0.], |
---|
| 433 | [ 0., 0., 0.], |
---|
| 434 | [ 0., 0., 0.], |
---|
| 435 | [ 0., 0., 0.]]), 'xmomentum': num.array([[ 2., 2., 2.], |
---|
| 436 | [ 2., 2., 2.], |
---|
| 437 | [ 2., 2., 2.], |
---|
| 438 | [ 2., 2., 2.], |
---|
| 439 | [ 2., 2., 2.], |
---|
| 440 | [ 2., 2., 2.], |
---|
| 441 | [ 2., 2., 2.], |
---|
| 442 | [ 2., 2., 2.], |
---|
| 443 | [ 2., 2., 2.], |
---|
| 444 | [ 2., 2., 2.], |
---|
| 445 | [ 2., 2., 2.], |
---|
| 446 | [ 2., 2., 2.], |
---|
| 447 | [ 2., 2., 2.], |
---|
| 448 | [ 2., 2., 2.], |
---|
| 449 | [ 2., 2., 2.], |
---|
| 450 | [ 2., 2., 2.]])} |
---|
| 451 | |
---|
| 452 | |
---|
| 453 | |
---|
| 454 | #---------------------------------------------------------------------------------- |
---|
| 455 | # Test build_submesh |
---|
| 456 | #---------------------------------------------------------------------------------- |
---|
[7391] | 457 | #submesh = build_submesh(nodes, triangles, edges, quantities, triangles_per_proc) |
---|
[7388] | 458 | |
---|
[7391] | 459 | # Temporarily build the mesh to find the neighbouring |
---|
| 460 | # triangles and true boundary polygon |
---|
[7388] | 461 | |
---|
[7393] | 462 | true_submesh = {'full_boundary': [{(3, 1): 'right', (4, 1): 'top'}, {(5, 1): 'left', (10, 1): 'top', (7, 1): 'left'}, {(13, 1): 'bottom', (14, 1): 'right', (11, 1): 'bottom'}], |
---|
| 463 | 'ghost_nodes': [num.array([[ 0. , 0. , 0. ], |
---|
| 464 | [ 1. , 0. , 0.5 ], |
---|
| 465 | [ 2. , 0. , 1. ], |
---|
| 466 | [ 6. , 1. , 0. ], |
---|
| 467 | [ 10. , 0.25, 0.75], |
---|
| 468 | [ 11. , 0.75, 0.25]]), num.array([[ 3. , 0.5 , 0. ], |
---|
| 469 | [ 7. , 1. , 0.5 ], |
---|
| 470 | [ 8. , 1. , 1. ], |
---|
| 471 | [ 11. , 0.75, 0.25], |
---|
| 472 | [ 12. , 0.75, 0.75]]), num.array([[ 1. , 0. , 0.5 ], |
---|
| 473 | [ 5. , 0.5 , 1. ], |
---|
| 474 | [ 8. , 1. , 1. ], |
---|
[7394] | 475 | [ 12. , 0.75, 0.75]])], |
---|
| 476 | 'full_nodes': [num.array([[ 3. , 0.5 , 0. ], |
---|
[7391] | 477 | [ 4. , 0.5 , 0.5 ], |
---|
| 478 | [ 5. , 0.5 , 1. ], |
---|
| 479 | [ 7. , 1. , 0.5 ], |
---|
| 480 | [ 8. , 1. , 1. ], |
---|
| 481 | [ 9. , 0.25, 0.25], |
---|
| 482 | [ 12. , 0.75, 0.75]]), num.array([[ 0. , 0. , 0. ], |
---|
| 483 | [ 1. , 0. , 0.5 ], |
---|
| 484 | [ 2. , 0. , 1. ], |
---|
| 485 | [ 4. , 0.5 , 0.5 ], |
---|
| 486 | [ 5. , 0.5 , 1. ], |
---|
| 487 | [ 9. , 0.25, 0.25], |
---|
| 488 | [ 10. , 0.25, 0.75]]), num.array([[ 0. , 0. , 0. ], |
---|
| 489 | [ 3. , 0.5 , 0. ], |
---|
| 490 | [ 4. , 0.5 , 0.5 ], |
---|
| 491 | [ 6. , 1. , 0. ], |
---|
| 492 | [ 7. , 1. , 0.5 ], |
---|
| 493 | [ 9. , 0.25, 0.25], |
---|
[7394] | 494 | [ 11. , 0.75, 0.25]])], |
---|
| 495 | 'ghost_triangles': [num.array([[ 5, 0, 9, 1], |
---|
[7393] | 496 | [ 6, 1, 9, 4], |
---|
| 497 | [ 8, 4, 10, 1], |
---|
| 498 | [ 9, 5, 10, 4], |
---|
| 499 | [10, 2, 10, 5], |
---|
| 500 | [11, 3, 9, 0], |
---|
| 501 | [12, 3, 11, 4], |
---|
| 502 | [13, 6, 11, 3], |
---|
| 503 | [14, 7, 11, 6], |
---|
| 504 | [15, 4, 11, 7]]), num.array([[ 0, 4, 9, 3], |
---|
| 505 | [ 1, 4, 12, 5], |
---|
| 506 | [ 2, 7, 12, 4], |
---|
| 507 | [ 4, 5, 12, 8], |
---|
| 508 | [11, 3, 9, 0], |
---|
| 509 | [12, 3, 11, 4]]), num.array([[ 0, 4, 9, 3], |
---|
| 510 | [ 1, 4, 12, 5], |
---|
| 511 | [ 2, 7, 12, 4], |
---|
| 512 | [ 3, 8, 12, 7], |
---|
| 513 | [ 5, 0, 9, 1], |
---|
[7394] | 514 | [ 6, 1, 9, 4]])], |
---|
| 515 | 'ghost_boundary': [{(13, 1): 'ghost', (8, 0): 'ghost', (14, 1): 'ghost', (11, 1): 'ghost', (10, 1): 'ghost', (5, 1): 'ghost', (10, 2): 'ghost'}, {(12, 2): 'ghost', (12, 0): 'ghost', (2, 1): 'ghost', (11, 1): 'ghost', (2, 2): 'ghost', (4, 1): 'ghost', (4, 0): 'ghost'}, {(3, 2): 'ghost', (6, 1): 'ghost', (3, 1): 'ghost', (5, 1): 'ghost', (1, 0): 'ghost', (1, 1): 'ghost'}], |
---|
| 516 | 'full_triangles': [[[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]], [[0, 9, 1], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5]], [[3, 9, 0], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7]]], |
---|
| 517 | 'full_commun': [{0: [1, 2], 1: [1, 2], 2: [1, 2], 3: [2], 4: [1]}, {5: [0, 2], 6: [0, 2], 7: [], 8: [0], 9: [0], 10: [0]}, {11: [0, 1], 12: [0, 1], 13: [0], 14: [0], 15: [0]}], |
---|
| 518 | 'ghost_commun': [num.array([[ 5, 1], |
---|
[7393] | 519 | [ 6, 1], |
---|
| 520 | [ 8, 1], |
---|
| 521 | [ 9, 1], |
---|
| 522 | [10, 1], |
---|
| 523 | [11, 2], |
---|
| 524 | [12, 2], |
---|
| 525 | [13, 2], |
---|
| 526 | [14, 2], |
---|
| 527 | [15, 2]]), num.array([[ 0, 0], |
---|
| 528 | [ 1, 0], |
---|
| 529 | [ 2, 0], |
---|
| 530 | [ 4, 0], |
---|
| 531 | [11, 2], |
---|
| 532 | [12, 2]]), num.array([[0, 0], |
---|
| 533 | [1, 0], |
---|
| 534 | [2, 0], |
---|
| 535 | [3, 0], |
---|
| 536 | [5, 1], |
---|
| 537 | [6, 1]])]} |
---|
[7391] | 538 | |
---|
[7394] | 539 | from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh |
---|
| 540 | |
---|
| 541 | mesh = Mesh(nodes, triangles) |
---|
| 542 | boundary_polygon = mesh.get_boundary_polygon() |
---|
| 543 | |
---|
| 544 | |
---|
| 545 | # Subdivide into non-overlapping partitions |
---|
[7391] | 546 | |
---|
[7394] | 547 | submesh = submesh_full(nodes, triangles, edges, \ |
---|
| 548 | triangles_per_proc) |
---|
[7391] | 549 | |
---|
[7394] | 550 | #print submesh |
---|
| 551 | |
---|
| 552 | |
---|
[7393] | 553 | for i in range(3): |
---|
[7394] | 554 | assert num.allclose(true_submesh['full_triangles'][i],submesh['full_triangles'][i]) |
---|
| 555 | assert num.allclose(true_submesh['full_nodes'][i],submesh['full_nodes'][i]) |
---|
| 556 | assert true_submesh['full_boundary'] == submesh['full_boundary'] |
---|
[7393] | 557 | |
---|
[7391] | 558 | # Add any extra ghost boundary layer information |
---|
| 559 | |
---|
[7394] | 560 | submesh = submesh_ghost(submesh, mesh, triangles_per_proc) |
---|
[7391] | 561 | |
---|
[7394] | 562 | for i in range(3): |
---|
| 563 | assert num.allclose(true_submesh['ghost_triangles'][i],submesh['ghost_triangles'][i]) |
---|
| 564 | assert num.allclose(true_submesh['ghost_nodes'][i],submesh['ghost_nodes'][i]) |
---|
| 565 | assert true_submesh['full_commun'] == submesh['full_commun'] |
---|
| 566 | assert true_submesh['ghost_commun'] == submesh['ghost_commun'] |
---|
[7393] | 567 | |
---|
[7391] | 568 | # Order the quantities information to be the same as the triangle |
---|
| 569 | # information |
---|
| 570 | |
---|
| 571 | submesh = submesh_quantities(submeshg, quantities, \ |
---|
| 572 | triangles_per_proc) |
---|
| 573 | |
---|
| 574 | submesh["boundary_polygon"] = boundary_polygon |
---|
| 575 | |
---|
| 576 | |
---|
| 577 | #-------------------------------------------------------- |
---|
| 578 | # Results we expect from build_submesh |
---|
| 579 | #-------------------------------------------------------- |
---|
| 580 | |
---|
[7394] | 581 | """ |
---|
[7388] | 582 | assert num.allclose(submesh['full_nodes'][0],[[3.0, 0.5, 0.0], [4.0, 0.5, 0.5], [5.0, 0.5, 1.0], [7.0, 1.0, 0.5], [8.0, 1.0, 1.0], [9.0, 0.25, 0.25], [12.0, 0.75, 0.75]]) |
---|
| 583 | assert num.allclose(submesh['full_nodes'][1],[[0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 0.0, 1.0], [4.0, 0.5, 0.5], [5.0, 0.5, 1.0], [9.0, 0.25, 0.25], [10.0, 0.25, 0.75]]) |
---|
| 584 | assert num.allclose(submesh['full_nodes'][2],[[0.0, 0.0, 0.0], [3.0, 0.5, 0.0], [4.0, 0.5, 0.5], [6.0, 1.0, 0.0], [7.0, 1.0, 0.5], [9.0, 0.25, 0.25], [11.0, 0.75, 0.25]]) |
---|
[7394] | 585 | """ |
---|
| 586 | """ |
---|
[7388] | 587 | assert num.allclose(submesh['ghost_nodes'][0],[[0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 0.0, 1.0], [6.0, 1.0, 0.0], [10.0, 0.25, 0.75], [11.0, 0.75, 0.25]]) |
---|
| 588 | assert num.allclose(submesh['ghost_nodes'][1],[[3.0, 0.5, 0.0], [7.0, 1.0, 0.5], [8.0, 1.0, 1.0], [11.0, 0.75, 0.25], [12.0, 0.75, 0.75]]) |
---|
| 589 | assert num.allclose(submesh['ghost_nodes'][2],[[1.0, 0.0, 0.5], [5.0, 0.5, 1.0], [8.0, 1.0, 1.0], [12.0, 0.75, 0.75]]) |
---|
[7394] | 590 | """ |
---|
[7388] | 591 | |
---|
[7394] | 592 | """ |
---|
[7388] | 593 | true_full_triangles = [num.array([[ 4, 9, 3], |
---|
| 594 | [ 4, 12, 5], |
---|
| 595 | [ 7, 12, 4], |
---|
| 596 | [ 8, 12, 7], |
---|
| 597 | [ 5, 12, 8]]), |
---|
| 598 | num.array([[ 0, 9, 1], |
---|
| 599 | [ 1, 9, 4], |
---|
| 600 | [ 1, 10, 2], |
---|
| 601 | [ 4, 10, 1], |
---|
| 602 | [ 5, 10, 4], |
---|
| 603 | [ 2, 10, 5]]), |
---|
| 604 | num.array([[ 3, 9, 0], |
---|
| 605 | [ 3, 11, 4], |
---|
| 606 | [ 6, 11, 3], |
---|
| 607 | [ 7, 11, 6], |
---|
| 608 | [ 4, 11, 7]])] |
---|
| 609 | |
---|
| 610 | |
---|
| 611 | assert num.allclose(submesh['full_triangles'][0],true_full_triangles[0]) |
---|
| 612 | assert num.allclose(submesh['full_triangles'][1],true_full_triangles[1]) |
---|
| 613 | assert num.allclose(submesh['full_triangles'][2],true_full_triangles[2]) |
---|
[7394] | 614 | """ |
---|
| 615 | """ |
---|
[7388] | 616 | true_ghost_triangles = [num.array([[ 5, 0, 9, 1], |
---|
| 617 | [ 6, 1, 9, 4], |
---|
| 618 | [ 8, 4, 10, 1], |
---|
| 619 | [ 9, 5, 10, 4], |
---|
| 620 | [10, 2, 10, 5], |
---|
| 621 | [11, 3, 9, 0], |
---|
| 622 | [12, 3, 11, 4], |
---|
| 623 | [13, 6, 11, 3], |
---|
| 624 | [14, 7, 11, 6], |
---|
| 625 | [15, 4, 11, 7]]), |
---|
| 626 | num.array([[ 0, 4, 9, 3], |
---|
| 627 | [ 1, 4, 12, 5], |
---|
| 628 | [ 2, 7, 12, 4], |
---|
| 629 | [ 4, 5, 12, 8], |
---|
| 630 | [11, 3, 9, 0], |
---|
| 631 | [12, 3, 11, 4]]), |
---|
| 632 | num.array([[ 0, 4, 9, 3], |
---|
| 633 | [ 1, 4, 12, 5], |
---|
| 634 | [ 2, 7, 12, 4], |
---|
| 635 | [ 3, 8, 12, 7], |
---|
| 636 | [ 5, 0, 9, 1], |
---|
| 637 | [ 6, 1, 9, 4]])] |
---|
| 638 | |
---|
[7394] | 639 | """ |
---|
| 640 | """ |
---|
[7388] | 641 | assert num.allclose(submesh['ghost_triangles'][0],true_ghost_triangles[0]) |
---|
| 642 | assert num.allclose(submesh['ghost_triangles'][1],true_ghost_triangles[1]) |
---|
| 643 | assert num.allclose(submesh['ghost_triangles'][2],true_ghost_triangles[2]) |
---|
| 644 | |
---|
| 645 | true_full_commun = [{0: [1, 2], 1: [1, 2], 2: [1, 2], 3: [2], 4: [1]}, {5: [0, 2], 6: [0, 2], 7: [], 8: [0], 9: [0], 10: [0]}, {11: [0, 1], 12: [0, 1], 13: [0], 14: [0], 15: [0]}] |
---|
| 646 | |
---|
| 647 | assert true_full_commun == submesh['full_commun'] |
---|
| 648 | |
---|
| 649 | |
---|
| 650 | true_ghost_commun = [num.array([[ 5, 1], |
---|
| 651 | [ 6, 1], |
---|
| 652 | [ 8, 1], |
---|
| 653 | [ 9, 1], |
---|
| 654 | [10, 1], |
---|
| 655 | [11, 2], |
---|
| 656 | [12, 2], |
---|
| 657 | [13, 2], |
---|
| 658 | [14, 2], |
---|
| 659 | [15, 2]]), |
---|
| 660 | num.array([[ 0, 0], |
---|
| 661 | [ 1, 0], |
---|
| 662 | [ 2, 0], |
---|
| 663 | [ 4, 0], |
---|
| 664 | [11, 2], |
---|
| 665 | [12, 2]]), |
---|
| 666 | num.array([[0, 0], |
---|
| 667 | [1, 0], |
---|
| 668 | [2, 0], |
---|
| 669 | [3, 0], |
---|
| 670 | [5, 1], |
---|
| 671 | [6, 1]])] |
---|
| 672 | |
---|
| 673 | assert num.allclose(submesh['ghost_commun'][0],true_ghost_commun[0]) |
---|
| 674 | assert num.allclose(submesh['ghost_commun'][1],true_ghost_commun[1]) |
---|
| 675 | assert num.allclose(submesh['ghost_commun'][2],true_ghost_commun[2]) |
---|
| 676 | |
---|
[7394] | 677 | """ |
---|
[7388] | 678 | |
---|
| 679 | #------------------------------------------------------------- |
---|
| 680 | |
---|
| 681 | if __name__ == "__main__": |
---|
[7394] | 682 | suite = unittest.makeSuite(Test_Distribute_Mesh,'test') |
---|
[7388] | 683 | runner = unittest.TextTestRunner() |
---|
| 684 | runner.run(suite) |
---|