source: inundation/parallel/build_local.py @ 2091

Last change on this file since 2091 was 2091, checked in by linda, 19 years ago

nomsg

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