[1500] | 1 | ######################################################### |
---|
[1510] | 2 | # |
---|
[1500] | 3 | # Given the subdivision of the grid assigned to the |
---|
| 4 | # current processor convert it into a form that is |
---|
[1510] | 5 | # appropriate for the GA datastructure. |
---|
| 6 | # |
---|
[1500] | 7 | # The main function of these modules is to change the |
---|
| 8 | # node numbering. The GA datastructure assumes they |
---|
| 9 | # are numbered consecutively from 0. |
---|
| 10 | # |
---|
| 11 | # The module also changes the communication pattern |
---|
| 12 | # datastructure into a form needed by parallel_advection |
---|
| 13 | # |
---|
| 14 | # Authors: Linda Stals and Matthew Hardy, June 2005 |
---|
[2091] | 15 | # Modified: Linda Stals, Nov 2005 (optimise python code) |
---|
[1500] | 16 | # |
---|
| 17 | # |
---|
| 18 | ######################################################### |
---|
| 19 | |
---|
[2130] | 20 | from Numeric import zeros, Float, Int, concatenate, \ |
---|
| 21 | take, arrayrange, put, sort, compress, equal |
---|
[1500] | 22 | |
---|
[2130] | 23 | |
---|
[1500] | 24 | ######################################################### |
---|
| 25 | # Convert the format of the data to that used by |
---|
| 26 | # pyvolution |
---|
| 27 | # |
---|
| 28 | # |
---|
| 29 | # *) Change the nodes global ID's to an integer value, |
---|
| 30 | #starting from 0. |
---|
| 31 | # |
---|
| 32 | # *) The triangles and boundary edges must also be |
---|
| 33 | # updated accordingly. |
---|
| 34 | # |
---|
| 35 | # ------------------------------------------------------- |
---|
| 36 | # |
---|
| 37 | # *) The nodes, triangles and boundary edges defined by |
---|
| 38 | # the new numbering scheme are returned |
---|
| 39 | # |
---|
| 40 | ######################################################### |
---|
| 41 | |
---|
[2625] | 42 | def build_local_GA(nodes, triangles, boundaries, tri_index): |
---|
[1510] | 43 | |
---|
[1500] | 44 | Nnodes =len(nodes) |
---|
| 45 | Ntriangles = len(triangles) |
---|
[2090] | 46 | |
---|
[2130] | 47 | # Extract the nodes (using the local ID) |
---|
[2090] | 48 | |
---|
| 49 | GAnodes = take(nodes, (1, 2), 1) |
---|
[1510] | 50 | |
---|
[2130] | 51 | # Build a global ID to local ID mapping |
---|
[1500] | 52 | |
---|
[2090] | 53 | NGlobal = 0 |
---|
| 54 | for i in range(Nnodes): |
---|
| 55 | if nodes[i][0] > NGlobal: |
---|
| 56 | NGlobal = nodes[i][0] |
---|
| 57 | index = zeros(int(NGlobal)+1, Int) |
---|
[2130] | 58 | put(index, take(nodes, (0,), 1).astype(Int), \ |
---|
| 59 | arrayrange(Nnodes)) |
---|
[2090] | 60 | |
---|
[2130] | 61 | # Change the global IDs in the triangles to the local IDs |
---|
[1500] | 62 | |
---|
[2090] | 63 | GAtriangles = zeros((Ntriangles, 3), Int) |
---|
| 64 | GAtriangles[:,0] = take(index, triangles[:,0]) |
---|
| 65 | GAtriangles[:,1] = take(index, triangles[:,1]) |
---|
| 66 | GAtriangles[:,2] = take(index, triangles[:,2]) |
---|
[2625] | 67 | |
---|
| 68 | # Change the triangle numbering in the boundaries |
---|
| 69 | |
---|
| 70 | GAboundaries = {} |
---|
| 71 | for b in boundaries: |
---|
| 72 | GAboundaries[tri_index[b[0]], b[1]] = boundaries[b] |
---|
| 73 | |
---|
| 74 | del (index) |
---|
[2090] | 75 | |
---|
[2625] | 76 | return GAnodes, GAtriangles, GAboundaries |
---|
[1510] | 77 | |
---|
[1500] | 78 | |
---|
| 79 | ######################################################### |
---|
| 80 | # Change the communication format to that needed by the |
---|
| 81 | # parallel advection file. |
---|
| 82 | # |
---|
| 83 | # *) The index contains [global triangle no, |
---|
| 84 | # local triangle no.] |
---|
| 85 | # |
---|
| 86 | # ------------------------------------------------------- |
---|
| 87 | # |
---|
| 88 | # *) The ghost_recv and full_send dictionaries are |
---|
| 89 | # returned. |
---|
| 90 | # |
---|
| 91 | # *) ghost_recv dictionary is local id, global id, value |
---|
| 92 | # |
---|
| 93 | # *) full_recv dictionary is local id, global id, value |
---|
| 94 | # |
---|
[2091] | 95 | # *) The information is ordered by the global id. This |
---|
| 96 | # means that the communication order is predetermined and |
---|
| 97 | # local and global id do not need to be |
---|
| 98 | # compared when the information is sent/received. |
---|
[1500] | 99 | # |
---|
| 100 | ######################################################### |
---|
| 101 | |
---|
| 102 | def build_local_commun(index, ghostc, fullc, nproc): |
---|
| 103 | |
---|
[2130] | 104 | # Initialise |
---|
[1510] | 105 | |
---|
[1500] | 106 | full_send = {} |
---|
| 107 | ghost_recv = {} |
---|
| 108 | |
---|
[2130] | 109 | # Build the ghost_recv dictionary (sort the |
---|
[1500] | 110 | # information by the global numbering) |
---|
[2090] | 111 | |
---|
| 112 | ghostc = sort(ghostc, 0) |
---|
| 113 | |
---|
| 114 | for c in range(nproc): |
---|
| 115 | s = ghostc[:,0] |
---|
| 116 | d = compress(equal(ghostc[:,1],c), s) |
---|
| 117 | if len(d) > 0: |
---|
| 118 | ghost_recv[c] = [0, 0] |
---|
| 119 | ghost_recv[c][1] = d |
---|
| 120 | ghost_recv[c][0] = take(index, d) |
---|
| 121 | |
---|
[2130] | 122 | # Build a temporary copy of the full_send dictionary |
---|
[1500] | 123 | # (this version allows the information to be stored |
---|
| 124 | # by the global numbering) |
---|
[1510] | 125 | |
---|
[1500] | 126 | tmp_send = {} |
---|
| 127 | for global_id in fullc: |
---|
| 128 | for i in range(len(fullc[global_id])): |
---|
| 129 | neigh = fullc[global_id][i] |
---|
| 130 | if not tmp_send.has_key(neigh): |
---|
| 131 | tmp_send[neigh] = [] |
---|
[2130] | 132 | tmp_send[neigh].append([global_id, \ |
---|
| 133 | index[global_id]]) |
---|
[1500] | 134 | |
---|
[2130] | 135 | # Extract the full send information and put it in the form |
---|
[1500] | 136 | # required for the full_send dictionary |
---|
[1510] | 137 | |
---|
[1500] | 138 | for neigh in tmp_send: |
---|
[2090] | 139 | neigh_commun = sort(tmp_send[neigh], 0) |
---|
[1563] | 140 | full_send[neigh] = [0, 0] |
---|
[2090] | 141 | full_send[neigh][0] = neigh_commun[:,1] |
---|
| 142 | full_send[neigh][1] = neigh_commun[:,0] |
---|
[1500] | 143 | |
---|
| 144 | return ghost_recv, full_send |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | ######################################################### |
---|
| 148 | # Convert the format of the data to that used by |
---|
| 149 | # pyvolution |
---|
| 150 | # |
---|
| 151 | # |
---|
| 152 | # *) Change the nodes global ID's to an integer value, |
---|
| 153 | # starting from 0. The node numbering in the triangles |
---|
[2091] | 154 | # must also be updated to take this into account. |
---|
[1500] | 155 | # |
---|
| 156 | # *) The triangle number will also change, which affects |
---|
| 157 | # the boundary tag information and the communication |
---|
| 158 | # pattern. |
---|
| 159 | # |
---|
| 160 | # ------------------------------------------------------- |
---|
| 161 | # |
---|
| 162 | # *) The nodes, triangles, boundary edges and communication |
---|
| 163 | # pattern defined by the new numbering scheme are returned |
---|
| 164 | # |
---|
| 165 | ######################################################### |
---|
| 166 | |
---|
| 167 | def build_local_mesh(submesh, lower_t, upper_t, nproc): |
---|
| 168 | |
---|
[2130] | 169 | # Combine the full nodes and ghost nodes |
---|
[1510] | 170 | |
---|
[2130] | 171 | nodes = concatenate((submesh["full_nodes"], \ |
---|
| 172 | submesh["ghost_nodes"])) |
---|
[2090] | 173 | |
---|
[2130] | 174 | # Combine the full triangles and ghost triangles |
---|
[1510] | 175 | |
---|
[2090] | 176 | gtri = take(submesh["ghost_triangles"],(1, 2, 3),1) |
---|
| 177 | triangles = concatenate((submesh["full_triangles"], gtri)) |
---|
[1500] | 178 | |
---|
[2625] | 179 | # Combine the full boundaries and ghost boundaries |
---|
[1510] | 180 | |
---|
[2625] | 181 | boundaries = submesh["full_boundary"] |
---|
| 182 | for b in submesh["ghost_boundary"]: |
---|
| 183 | boundaries[b]=submesh["ghost_boundary"][b] |
---|
[1500] | 184 | |
---|
[2130] | 185 | # Make note of the new triangle numbers, including the ghost |
---|
[1510] | 186 | # triangles |
---|
| 187 | |
---|
[2090] | 188 | NGlobal = upper_t |
---|
[1500] | 189 | for i in range(len(submesh["ghost_triangles"])): |
---|
[2090] | 190 | id = submesh["ghost_triangles"][i][0] |
---|
| 191 | if id > NGlobal: |
---|
| 192 | NGlobal = id |
---|
| 193 | index = zeros(int(NGlobal)+1, Int) |
---|
| 194 | index[lower_t:upper_t]=arrayrange(upper_t-lower_t) |
---|
| 195 | for i in range(len(submesh["ghost_triangles"])): |
---|
[1500] | 196 | index[submesh["ghost_triangles"][i][0]] = i+upper_t-lower_t |
---|
[2625] | 197 | |
---|
[2130] | 198 | # Change the node numbering (and update the numbering in the |
---|
[1500] | 199 | # triangles) |
---|
[1510] | 200 | |
---|
[2625] | 201 | [GAnodes, GAtriangles, GAboundary] = build_local_GA(nodes, triangles, boundaries, index) |
---|
[1500] | 202 | |
---|
[2130] | 203 | # Extract the local quantities |
---|
[1580] | 204 | |
---|
| 205 | quantities ={} |
---|
| 206 | for k in submesh["full_quan"]: |
---|
| 207 | Nf = len(submesh["full_quan"][k]) |
---|
| 208 | Ng = len(submesh["ghost_quan"][k]) |
---|
| 209 | quantities[k] = zeros((Nf+Ng, 3), Float) |
---|
| 210 | quantities[k][0:Nf] = submesh["full_quan"][k] |
---|
| 211 | quantities[k][Nf:Nf+Ng] = submesh["ghost_quan"][k] |
---|
| 212 | |
---|
[2130] | 213 | # Change the communication pattern into a form needed by |
---|
| 214 | # the parallel_adv |
---|
[1510] | 215 | |
---|
[1500] | 216 | gcommun = submesh["ghost_commun"] |
---|
| 217 | fcommun = submesh["full_commun"] |
---|
[2130] | 218 | [ghost_rec, full_send] = \ |
---|
| 219 | build_local_commun(index, gcommun, fcommun, nproc) |
---|
[1500] | 220 | |
---|
[2130] | 221 | # Clean up before exiting |
---|
[1510] | 222 | |
---|
[1500] | 223 | del(index) |
---|
[1510] | 224 | |
---|
[2130] | 225 | return GAnodes, GAtriangles, GAboundary, quantities, ghost_rec, \ |
---|
| 226 | full_send |
---|