Changeset 1402
- Timestamp:
- May 16, 2005, 5:25:56 PM (20 years ago)
- Location:
- inundation/ga/storm_surge
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/parallel/parallel_advection.py
r1393 r1402 16 16 from advection import * 17 17 Advection_Domain = Domain 18 from Numeric import zeros, Float, Int 18 from Numeric import zeros, Float, Int, ones 19 19 20 20 class Parallel_Domain(Advection_Domain): 21 21 22 def __init__(self, coordinates, vertices, boundary = None, velocity = None, 23 processor = 0, global_ids = None): 22 def __init__(self, coordinates, vertices, boundary = None, ghosts = None, velocity = None): 24 23 25 24 Advection_Domain.__init__(self, coordinates, vertices, boundary, velocity) 26 25 27 self.processor = processor28 29 26 N = self.number_of_elements 30 27 31 if global_ids == None: 32 self.global_ids = global_ids 28 if ghosts == None: 29 self.ghosts = None 30 self.full = ones( N, Float) 33 31 else: 34 self.global_ids = zeros(N, Int) 35 32 self.ghosts = ghosts 33 self.full = ones( N, Int) 34 keys = self.ghosts.keys() 35 for key in keys: 36 self.full[key] = -1 36 37 37 38 def check_integrity(self): … … 42 43 43 44 44 45 def update_ghosts(self): 46 if self.ghosts is not None: 47 stage_cv = self.quantities['stage'].centroid_values 48 for triangle in self.ghosts: 49 stage_cv[triangle] = stage_cv[self.ghosts[triangle]] 45 50 46 51 def evolve(self, yieldstep = None, finaltime = None): … … 64 69 65 70 66 def rectangular_ with_ghosts(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):71 def rectangular_periodic(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)): 67 72 68 73 … … 141 146 ghosts[nt] = E(m-2,j) 142 147 148 if j == n-1: 149 ghosts[nt] = E(i,1) 150 151 if j == 0: 152 ghosts[nt] = E(i,n-2) 153 143 154 if i == m-1: 144 155 boundary[nt, 2] = 'right' … … 154 165 ghosts[nt] = E(m-2,j)+1 155 166 167 if j == n-1: 168 ghosts[nt] = E(i,1)+1 169 170 if j == 0: 171 ghosts[nt] = E(i,n-2)+1 172 156 173 if i == 0: 157 174 boundary[nt, 2] = 'left' … … 160 177 elements[nt,:] = [i1,i2,i3] 161 178 179 #bottom left 180 nt = E(0,0) 181 nf = E(m-2,n-2) 182 ghosts[nt] = nf 183 ghosts[nt+1] = nf+1 184 185 #bottom right 186 nt = E(m-1,0) 187 nf = E(1,n-2) 188 ghosts[nt] = nf 189 ghosts[nt+1] = nf+1 190 191 #top left 192 nt = E(0,n-1) 193 nf = E(m-2,1) 194 ghosts[nt] = nf 195 ghosts[nt+1] = nf+1 196 197 #top right 198 nt = E(m-1,n-1) 199 nf = E(1,1) 200 ghosts[nt] = nf 201 ghosts[nt+1] = nf+1 202 162 203 return points, elements, boundary, ghosts 163 204 205 def rectangular_periodic_lr(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)): 206 207 208 """Setup a rectangular grid of triangles 209 with m+1 by n+1 grid points 210 and side lengths len1, len2. If side lengths are omitted 211 the mesh defaults to the unit square. 212 213 len1: x direction (left to right) 214 len2: y direction (bottom to top) 215 216 Return to lists: points and elements suitable for creating a Mesh or 217 FVMesh object, e.g. Mesh(points, elements) 218 """ 219 220 from config import epsilon 221 from Numeric import zeros, Float, Int 222 223 delta1 = float(len1)/m 224 delta2 = float(len2)/n 225 226 #Calculate number of points 227 Np = (m+1)*(n+1) 228 229 class VIndex: 230 231 def __init__(self, n,m): 232 self.n = n 233 self.m = m 234 235 def __call__(self, i,j): 236 return j+i*(self.n+1) 237 238 class EIndex: 239 240 def __init__(self, n,m): 241 self.n = n 242 self.m = m 243 244 def __call__(self, i,j): 245 return 2*(j+i*self.n) 246 247 248 I = VIndex(n,m) 249 E = EIndex(n,m) 250 251 points = zeros( (Np,2), Float) 252 253 for i in range(m+1): 254 for j in range(n+1): 255 256 points[I(i,j),:] = [i*delta1 + origin[0], j*delta2 + origin[1]] 257 258 #Construct 2 triangles per rectangular element and assign tags to boundary 259 #Calculate number of triangles 260 Nt = 2*m*n 261 262 263 elements = zeros( (Nt,3), Int) 264 boundary = {} 265 ghosts = {} 266 nt = -1 267 for i in range(m): 268 for j in range(n): 269 270 i1 = I(i,j+1) 271 i2 = I(i,j) 272 i3 = I(i+1,j+1) 273 i4 = I(i+1,j) 274 275 #Lower Element 276 nt = E(i,j) 277 if i == m-1: 278 ghosts[nt] = E(1,j) 279 if i == 0: 280 ghosts[nt] = E(m-2,j) 281 282 if i == m-1: 283 boundary[nt, 2] = 'right' 284 if j == 0: 285 boundary[nt, 1] = 'bottom' 286 elements[nt,:] = [i4,i3,i2] 287 288 #Upper Element 289 nt = E(i,j)+1 290 if i == m-1: 291 ghosts[nt] = E(1,j)+1 292 if i == 0: 293 ghosts[nt] = E(m-2,j)+1 294 295 if i == 0: 296 boundary[nt, 2] = 'left' 297 if j == n-1: 298 boundary[nt, 1] = 'top' 299 elements[nt,:] = [i1,i2,i3] 300 301 302 return points, elements, boundary, ghosts -
inundation/ga/storm_surge/parallel/run_parallel_advection.py
r1393 r1402 9 9 from Numeric import array 10 10 11 from mesh_factory import rectangular 11 N = 40 12 M = 40 12 13 13 N = 4 14 M = 4 15 16 points, vertices, boundary, ghosts = rectangular_with_ghosts(N, M) 17 18 19 print ghosts 14 points, vertices, boundary, ghosts = rectangular_periodic_lr(N, M) 20 15 21 16 #Create advection domain with direction (1,-1) 22 domain = Parallel_Domain(points, vertices, boundary, velocity=[1.0, 0.0])17 domain = Parallel_Domain(points, vertices, boundary, ghosts, velocity=[1.0, 0.0]) 23 18 24 19 # Initial condition is zero by default … … 53 48 54 49 #Check that the boundary value gets propagated to all elements 55 for t in domain.evolve(yieldstep = 0.01, finaltime = 0.01):50 for t in domain.evolve(yieldstep = 0.01, finaltime = 1.0): 56 51 domain.write_time() -
inundation/ga/storm_surge/pyvolution/domain.py
r1387 r1402 431 431 self.distribute_to_vertices_and_edges() 432 432 433 #Initial update boundary values 434 self.update_boundary() 433 435 434 436 #Or maybe restore from latest checkpoint … … 436 438 self.goto_latest_checkpoint() 437 439 438 439 440 yield(self.time) #Yield initial values 440 441 441 442 while True: 443 444 #Compute fluxes across each element edge 445 self.compute_fluxes() 446 447 #Update timestep to fit yieldstep and finaltime 448 self.update_timestep(yieldstep, finaltime) 449 450 #Update conserved quantities 451 self.update_conserved_quantities() 452 453 #update ghosts 454 self.update_ghosts() 455 456 #Update vertex and edge values 457 self.distribute_to_vertices_and_edges() 458 442 459 #Update boundary values 443 460 self.update_boundary() 444 445 #Compute fluxes across each element edge446 self.compute_fluxes()447 448 #Update timestep to fit yieldstep and finaltime449 self.update_timestep(yieldstep, finaltime)450 451 #Update conserved quantities452 self.update_conserved_quantities()453 454 #Update vertex and edge values455 self.distribute_to_vertices_and_edges()456 461 457 462 #Update time … … 604 609 Q.semi_implicit_update[:] = 0.0 605 610 611 def update_ghosts(self): 612 pass 606 613 607 614
Note: See TracChangeset
for help on using the changeset viewer.