Changeset 1463
- Timestamp:
- May 25, 2005, 5:24:14 PM (19 years ago)
- Location:
- inundation/ga/storm_surge
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/parallel/advection.py
r1424 r1463 90 90 return flux, max_speed 91 91 92 93 92 def compute_fluxes(self): 93 94 self.compute_fluxes_python() 95 96 def compute_fluxes_python(self): 94 97 """Compute all fluxes and the timestep suitable for all volumes 95 98 in domain. … … 178 181 self.timestep = timestep 179 182 180 183 def compute_fluxes_weave(self): 184 """Compute all fluxes and the timestep suitable for all volumes 185 in domain. 186 187 Compute total flux for each conserved quantity using "flux_function" 188 189 Fluxes across each edge are scaled by edgelengths and summed up 190 Resulting flux is then scaled by area and stored in 191 domain.explicit_update 192 193 The maximal allowable speed computed by the flux_function 194 for each volume 195 is converted to a timestep that must not be exceeded. The minimum of 196 those is computed as the next overall timestep. 197 198 Post conditions: 199 domain.explicit_update is reset to computed flux values 200 domain.timestep is set to the largest step satisfying all volumes. 201 """ 202 203 import sys 204 from Numeric import zeros, Float 205 from config import max_timestep 206 207 import weave 208 from weave import converters 209 210 N = self.number_of_elements 211 212 local_timestep = float(max_timestep) #FIXME: Get rid of this 213 214 #Shortcuts 215 Stage = self.quantities['stage'] 216 217 #Arrays 218 neighbours = self.neighbours 219 neighbour_edges = self.neighbour_edges 220 normals = self.normals 221 areas = self.areas 222 radii = self.radii 223 edgelengths = self.edgelengths 224 225 stage_edge = Stage.edge_values 226 stage_bdry = Stage.boundary_values 227 stage_update = Stage.explicit_update 228 229 huge_timestep = float(sys.maxint) 230 231 v1 = self.velocity[0] 232 v2 = self.velocity[1] 233 234 code = """ 235 //Loop 236 237 double qr,ql; 238 int m,n; 239 double normal[2]; 240 double normal_velocity; 241 double flux, edgeflux; 242 double max_speed; 243 double optimal_timestep; 244 for (int k=0; k<N; k++){ 245 246 optimal_timestep = huge_timestep; 247 flux = 0.0; //Reset work array 248 for (int i=0; i<3; i++){ 249 //Quantities inside volume facing neighbour i 250 ql = stage_edge(k, i); 251 252 //Quantities at neighbour on nearest face 253 n = neighbours(k,i); 254 if (n < 0) { 255 m = -n-1; //Convert neg flag to index 256 qr = stage_bdry(m); 257 } else { 258 m = neighbour_edges(k,i); 259 qr = stage_edge(n, m); 260 } 261 262 263 //Outward pointing normal vector 264 for (int j=0; j<2; j++){ 265 normal[j] = normals(k, 2*i+j); 266 } 267 268 269 //Flux computation using provided function 270 normal_velocity = v1*normal[0] + v2*normal[1]; 271 272 if (normal_velocity < 0) { 273 edgeflux = qr * normal_velocity; 274 } else { 275 edgeflux = ql * normal_velocity; 276 } 277 278 max_speed = fabs(normal_velocity); 279 flux = flux - edgeflux * edgelengths(k,i); 280 281 //Update optimal_timestep 282 if (max_speed != 0.0) { 283 optimal_timestep = (optimal_timestep>radii(k)/max_speed) ? radii(k)/max_speed : optimal_timestep; 284 } 285 286 } 287 288 //Normalise by area and store for when all conserved 289 //quantities get updated 290 stage_update(k) = flux/areas(k); 291 292 local_timestep = (local_timestep>optimal_timestep) ? optimal_timestep : local_timestep; 293 std::cout << local_timestep << std::endl; 294 } 295 """ 296 297 weave.inline(code, ['stage_edge','stage_bdry','stage_update', 298 'neighbours','neighbour_edges','normals', 299 'areas','radii','edgelengths','huge_timestep', 300 'local_timestep','v1','v2','N'], 301 type_converters = converters.blitz, compiler='gcc'); 302 303 self.timestep = local_timestep 304 print local_timestep 181 305 182 306 def evolve(self, yieldstep = None, finaltime = None): -
inundation/ga/storm_surge/parallel/run_parallel_advection.py
r1461 r1463 19 19 20 20 #N = 50 21 N = 5022 M = 5021 N = 10 22 M = 10 23 23 24 24 points, vertices, boundary, full_send_dict, ghost_recv_dict = parallel_rectangular(N, M, len1=1.0) … … 60 60 61 61 #Check that the boundary value gets propagated to all elements 62 for t in domain.evolve(yieldstep = 0.05, finaltime = 0.1):62 for t in domain.evolve(yieldstep = 0.05, finaltime = 3.0): 63 63 if myid == 0: 64 64 domain.write_time()
Note: See TracChangeset
for help on using the changeset viewer.