Changeset 5587
- Timestamp:
- Jul 30, 2008, 5:03:47 PM (16 years ago)
- Location:
- anuga_work/development/anuga_1d
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/development/anuga_1d/comp_flux_ext.c
r5564 r5587 21 21 22 22 23 24 25 // Function to obtain speed from momentum and depth. 26 // This is used by flux functions 27 // Input parameters uh and h may be modified by this function. 28 double _compute_speed(double *uh, 29 double *h, 30 double epsilon, 31 double h0) { 32 33 double u; 34 35 if (*h < epsilon) { 36 *h = 0.0; //Could have been negative 37 u = 0.0; 38 } else { 39 u = *uh/(*h + h0/ *h); 40 } 41 42 43 // Adjust momentum to be consistent with speed 44 *uh = u * *h; 45 46 return u; 47 } 48 49 50 23 51 //Innermost flux function (using w=z+h) 24 52 int _flux_function(double *q_left, double *q_right, 25 53 double z_left, double z_right, 26 double normals, double g, double epsilon,54 double normals, double g, double epsilon, double h0, 27 55 double *edgeflux, double *max_speed) { 28 56 … … 33 61 double s_max, s_min, denom; 34 62 35 63 //printf("h0 = %f \n",h0); 36 64 ql[0] = q_left[0]; 37 65 ql[1] = q_left[1]; … … 54 82 h_left = w_left-z; 55 83 uh_left = ql[1]; 56 if (h_left < epsilon) { 57 u_left = 0.0; h_left = 0.0; 58 } 59 else { 60 u_left = uh_left/h_left; 61 } 62 84 85 u_left = _compute_speed(&uh_left, &h_left, epsilon, h0); 86 63 87 w_right = qr[0]; 64 88 h_right = w_right-z; 65 89 uh_right = qr[1]; 66 if (h_right < epsilon) { 67 u_right = 0.0; h_right = 0.0; 68 } 69 else { 70 u_right = uh_right/h_right; 71 } 90 91 u_right = _compute_speed(&uh_right, &h_right, epsilon, h0); 72 92 73 93 soundspeed_left = sqrt(g*h_left); … … 113 133 // Computational function for flux computation 114 134 double _compute_fluxes_ext(double timestep, 115 double epsilon, 116 double g, 117 long* neighbours, 118 long* neighbour_vertices, 119 double* normals, 120 double* areas, 121 double* stage_edge_values, 122 double* xmom_edge_values, 123 double* bed_edge_values, 124 double* stage_boundary_values, 125 double* xmom_boundary_values, 126 double* stage_explicit_update, 127 double* xmom_explicit_update, 128 int number_of_elements, 129 double* max_speed_array) { 130 131 double flux[2], ql[2], qr[2], edgeflux[2]; 135 double epsilon, 136 double g, 137 double h0, 138 long* neighbours, 139 long* neighbour_vertices, 140 double* normals, 141 double* areas, 142 double* stage_edge_values, 143 double* xmom_edge_values, 144 double* bed_edge_values, 145 double* stage_boundary_values, 146 double* xmom_boundary_values, 147 double* stage_explicit_update, 148 double* xmom_explicit_update, 149 int number_of_elements, 150 double* max_speed_array) { 151 152 double flux[2], ql[2], qr[2], edgeflux[2]; 132 153 double zl, zr, max_speed, normal; 133 154 int k, i, ki, n, m, nm=0; … … 159 180 160 181 normal = normals[ki]; 161 _flux_function(ql, qr, zl, zr, normal, g, epsilon, edgeflux, &max_speed);182 _flux_function(ql, qr, zl, zr, normal, g, epsilon, h0, edgeflux, &max_speed); 162 183 flux[0] -= edgeflux[0]; 163 184 flux[1] -= edgeflux[1]; … … 209 230 *max_speed_array; 210 231 211 double timestep, epsilon, g ;232 double timestep, epsilon, g, h0; 212 233 int number_of_elements; 213 234 214 235 // Convert Python arguments to C 215 if (!PyArg_ParseTuple(args, "ddd OOOOOOOOOOOiO",236 if (!PyArg_ParseTuple(args, "ddddOOOOOOOOOOOiO", 216 237 ×tep, 217 238 &epsilon, 218 239 &g, 240 &h0, 219 241 &neighbours, 220 242 &neighbour_vertices, … … 240 262 epsilon, 241 263 g, 264 h0, 242 265 (long*) neighbours -> data, 243 266 (long*) neighbour_vertices -> data, … … 281 304 *max_speed_array; 282 305 283 double timestep, epsilon, g ;306 double timestep, epsilon, g, h0; 284 307 int number_of_elements; 285 308 … … 299 322 epsilon = get_python_double(domain,"epsilon"); 300 323 g = get_python_double(domain,"g"); 324 h0 = get_python_double(domain,"h0"); 301 325 302 326 … … 327 351 // the explicit update arrays 328 352 timestep = _compute_fluxes_ext(timestep, 329 epsilon, 330 g, 331 (long*) neighbours -> data, 332 (long*) neighbour_vertices -> data, 333 (double*) normals -> data, 334 (double*) areas -> data, 335 (double*) stage_vertex_values -> data, 336 (double*) xmom_vertex_values -> data, 337 (double*) bed_vertex_values -> data, 338 (double*) stage_boundary_values -> data, 339 (double*) xmom_boundary_values -> data, 340 (double*) stage_explicit_update -> data, 341 (double*) xmom_explicit_update -> data, 342 number_of_elements, 343 (double*) max_speed_array -> data); 353 epsilon, 354 g, 355 h0, 356 (long*) neighbours -> data, 357 (long*) neighbour_vertices -> data, 358 (double*) normals -> data, 359 (double*) areas -> data, 360 (double*) stage_vertex_values -> data, 361 (double*) xmom_vertex_values -> data, 362 (double*) bed_vertex_values -> data, 363 (double*) stage_boundary_values -> data, 364 (double*) xmom_boundary_values -> data, 365 (double*) stage_explicit_update -> data, 366 (double*) xmom_explicit_update -> data, 367 number_of_elements, 368 (double*) max_speed_array -> data); 344 369 345 370 -
anuga_work/development/anuga_1d/config.py
r5535 r5587 1 """Module where global model parameters are set 1 """Module where global model parameters are set for anuga_1d 2 2 """ 3 3 4 4 epsilon = 1.0e-12 5 h0 = 1.0e-6 5 6 6 7 default_boundary_tag = 'exterior' … … 75 76 76 77 77 beta_w = 0.978 beta_w = 1.5 78 79 beta_h = 0.2 79 80 CFL = 1.0 #FIXME (ole): Is this in use yet?? -
anuga_work/development/anuga_1d/dam_h_sudi.py
r5535 r5587 1 1 import os 2 2 from math import sqrt 3 from shallow_water_h import * 3 #from shallow_water_h import * 4 from shallow_water_domain import * 4 5 from Numeric import zeros, Float 5 6 from analytic_dam_sudi import AnalyticDam … … 31 32 32 33 L=2000.0 33 N= 10034 N=400 34 35 35 36 cell_len=L/N … … 41 42 domain=Domain(points) 42 43 43 domain.default_order = 144 domain.default_order = 2 44 45 domain.default_time_order = 1 45 #domain.cfl = 1.046 #domain.limiter = "minmod"46 domain.cfl = 1.0 47 domain.limiter = "vanleer" 47 48 48 49 49 50 50 51 52 53 54 51 def height(x): 55 52 y=zeros(len(x), Float) … … 63 60 return y 64 61 65 domain.set_quantity(' height', height)62 domain.set_quantity('stage',height) #('height', height) 66 63 domain.order=domain.default_order 67 64 print "domain order", domain.order … … 78 75 t0=time.time() 79 76 yieldstep=30.0 80 finaltime= 30.081 print "integral", domain.quantities[' height'].get_integral()77 finaltime=20.0 78 print "integral", domain.quantities['stage'].get_integral() #['height'].get_integral() 82 79 for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime): 83 80 domain.write_time() 84 print "integral", domain.quantities[' height'].get_integral()81 print "integral", domain.quantities['stage'].get_integral() #['height'].get_integral() 85 82 if t>0.0: 86 HeightQ=domain.quantities[' height'].vertex_values83 HeightQ=domain.quantities['stage'].vertex_values #['height'].vertex_values 87 84 MomentumQ=domain.quantities['xmomentum'].vertex_values 88 85 h, uh=analytical_sol(X.flat, domain.time) -
anuga_work/development/anuga_1d/dry_dam_sudi.py
r5565 r5587 22 22 # Calculate Analytical Solution at time t > 0 23 23 u3 = 2.0/3.0*(sqrt(g*h1)+x[i]/t) 24 h3 = 4.0/(9.0*g)*(sqrt(g*h1)-x[i]/(2.0*t))*(sqrt(g*h1)-x[i]/(2.0*t)) 24 h3 = 4.0/(9.0*g)*(sqrt(g*h1)-x[i]/(2.0*t))*(sqrt(g*h1)-x[i]/(2.0*t)) 25 u3_ = 2.0/3.0*((x[i]+L/2.0)/t-sqrt(g*h1)) 26 h3_ = 1.0/(9.0*g)*((x[i]+L/2.0)/t+2*sqrt(g*h1))*((x[i]+L/2.0)/t+2*sqrt(g*h1)) 25 27 26 if ( x[i] <= -t*sqrt(g*h1) ): 28 if ( x[i] <= -1*L/2.0+2*(-sqrt(g*h1)*t)): 29 u[i] = 0.0 30 h[i] = h0 31 elif ( x[i] <= -1*L/2.0-(-sqrt(g*h1)*t)): 32 u[i] = u3_ 33 h[i] = h3_ 34 35 elif ( x[i] <= -t*sqrt(g*h1) ): 27 36 u[i] = 0.0 28 37 h[i] = h1 … … 57 66 58 67 L = 2000.0 # Length of channel (m) 59 N = 100 # Number of compuational cells68 N = 800 # Number of computational cells 60 69 cell_len = L/N # Origin = 0.0 61 70 … … 85 94 yieldstep = 1.0 86 95 L = 2000.0 # Length of channel (m) 87 number_of_cells = [ 100]#,200,500,1000,2000,5000,10000,20000]96 number_of_cells = [200]#,200,500,1000,2000,5000,10000,20000] 88 97 h_error = zeros(len(number_of_cells),Float) 89 98 uh_error = zeros(len(number_of_cells),Float) … … 102 111 domain.set_boundary({'exterior': Reflective_boundary(domain)}) 103 112 domain.default_order = 2 104 domain.default_time_order = 1113 domain.default_time_order = 2 105 114 domain.cfl = 1.0 106 domain.limiter = " vanleer"115 domain.limiter = "minmod" 107 116 108 117 t0 = time.time() 109 118 110 119 for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): 111 pass120 domain.write_time() 112 121 113 122 N = float(N) -
anuga_work/development/anuga_1d/run_profile_dry.py
r5565 r5587 114 114 115 115 S = pstats.Stats(FN) 116 s = S.sort_stats('cumulative').print_stats( 20)116 s = S.sort_stats('cumulative').print_stats(30) 117 117 118 118 print s -
anuga_work/development/anuga_1d/shallow_water_domain.py
r5563 r5587 59 59 tagged_elements) 60 60 61 from config import minimum_allowed_height, g 61 from config import minimum_allowed_height, g, h0 62 62 self.minimum_allowed_height = minimum_allowed_height 63 63 self.g = g 64 self.h0 = h0 64 65 65 66 #forcing terms not included in 1d domain ?WHy? … … 308 309 """ 309 310 310 from config import g, epsilon 311 from config import g, epsilon, h0 311 312 from math import sqrt 312 313 from Numeric import array … … 333 334 h_left = 0.0 334 335 else: 335 u_left = uh_left/h_left 336 u_left = uh_left/(h_left + h0/h_left) 337 338 339 uh_left = u_left*h_left 336 340 337 341 … … 339 343 h_right = w_right-z 340 344 uh_right = q_right[1] 341 342 345 343 346 if h_right < epsilon: … … 345 348 h_right = 0.0 346 349 else: 347 u_right = uh_right/h_right 350 u_right = uh_right/(h_right + h0/h_right) 351 352 uh_right = u_right*h_right 348 353 349 354 #vh_left = q_left[2] -
anuga_work/development/anuga_1d/test_shallow_water.py
r5563 r5587 50 50 zr = 0.0 51 51 52 #This assumes h0 = 1.0e-3!! 52 53 edgeflux, maxspeed = flux_function(normal, ql,qr,zl,zr) 53 54 assert allclose(array([2.0, 8.9],Float), edgeflux) 55 assert allclose(5.1304951685, maxspeed) 54 #print maxspeed 55 #print edgeflux 56 57 assert allclose(array([1.998002, 8.89201198],Float), edgeflux) 58 assert allclose(5.1284971665, maxspeed) 56 59 57 60 normal = -1.0 … … 63 66 edgeflux, maxspeed = flux_function(normal, ql,qr,zl,zr) 64 67 65 assert allclose(array([-2.0, -8.9],Float), edgeflux) 66 assert allclose(5.1304951685, maxspeed) 68 69 #print maxspeed 70 #print edgeflux 71 72 assert allclose(array([-1.998002, -8.89201198],Float), edgeflux) 73 assert allclose(5.1284971665, maxspeed) 67 74 68 75 def test_domain_flux_function(self): … … 231 238 """ 232 239 233 from config import g, epsilon 240 from config import g, epsilon, h0 234 241 from math import sqrt 235 242 from Numeric import array … … 256 263 h_left = 0.0 257 264 else: 258 u_left = uh_left/h_left 259 265 u_left = uh_left/(h_left + h0/h_left) 266 267 268 uh_left = u_left*h_left 260 269 261 270 w_right = q_right[0] #w=h+z … … 268 277 h_right = 0.0 269 278 else: 270 u_right = uh_right/h_right 271 279 u_right = uh_right/(h_right + h0/h_right) 280 281 uh_right = u_right*h_right 282 272 283 #vh_left = q_left[2] 273 284 #vh_right = q_right[2]
Note: See TracChangeset
for help on using the changeset viewer.