- Timestamp:
- Jun 26, 2008, 1:21:05 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/shallow_water_ext.c
r5315 r5442 538 538 539 539 int _balance_deep_and_shallow(int N, 540 double beta_h,541 540 double* wc, 542 541 double* zc, … … 623 622 alpha = 1.0; 624 623 for (i=0; i<3; i++) { 625 626 // FIXME (Ole): Simplify (remove) when (if) hvbar gets retired627 if (beta_h > epsilon) {628 hc_k = hvbar[k3+i]; // Depth to be used at vertices629 }630 624 631 625 h_diff = hc_k - hv[i]; … … 674 668 for (i=0; i<3; i++) { 675 669 676 // FIXME (Ole): Simplify when (if) hvbar gets retired 677 if (beta_h > epsilon) { 678 wv[k3+i] = zv[k3+i] + (1-alpha)*hvbar[k3+i] + alpha*hv[i]; 679 } else { 680 wv[k3+i] = zv[k3+i] + (1-alpha)*hc_k + alpha*hv[i]; 681 } 670 wv[k3+i] = zv[k3+i] + (1-alpha)*hc_k + alpha*hv[i]; 682 671 683 672 // Update momentum at vertices … … 2332 2321 // modes. 2333 2322 // 2334 // balance_deep_and_shallow( beta_h,wc, zc, wv, zv,2323 // balance_deep_and_shallow(wc, zc, wv, zv, 2335 2324 // xmomc, ymomc, xmomv, ymomv) 2336 2325 … … 2350 2339 2351 2340 double alpha_balance = 2.0; 2352 double H0 , beta_h;2341 double H0; 2353 2342 2354 2343 int N, tight_slope_limiters, use_centroid_velocities; //, err; 2355 2344 2356 2345 // Convert Python arguments to C 2357 if (!PyArg_ParseTuple(args, "O dOOOOOOOOO",2346 if (!PyArg_ParseTuple(args, "OOOOOOOOOO", 2358 2347 &domain, 2359 &beta_h,2360 2348 &wc, &zc, 2361 2349 &wv, &zv, &hvbar, … … 2411 2399 N = wc -> dimensions[0]; 2412 2400 _balance_deep_and_shallow(N, 2413 beta_h,2414 2401 (double*) wc -> data, 2415 2402 (double*) zc -> data, … … 2432 2419 2433 2420 2434 PyObject *h_limiter(PyObject *self, PyObject *args) {2435 2436 PyObject *domain, *Tmp;2437 PyArrayObject2438 *hv, *hc, //Depth at vertices and centroids2439 *hvbar, //Limited depth at vertices (return values)2440 *neighbours;2441 2442 int k, i, n, N, k3;2443 int dimensions[2];2444 double beta_h; // Safety factor (see config.py)2445 double *hmin, *hmax, hn;2446 2447 // Convert Python arguments to C2448 if (!PyArg_ParseTuple(args, "OOO", &domain, &hc, &hv)) {2449 PyErr_SetString(PyExc_RuntimeError, "shallow_water_ext.c: h_limiter could not parse input arguments");2450 return NULL;2451 }2452 2453 neighbours = get_consecutive_array(domain, "neighbours");2454 2455 //Get safety factor beta_h2456 Tmp = PyObject_GetAttrString(domain, "beta_h");2457 if (!Tmp) {2458 PyErr_SetString(PyExc_RuntimeError, "shallow_water_ext.c: h_limiter could not obtain object beta_h from domain");2459 return NULL;2460 }2461 beta_h = PyFloat_AsDouble(Tmp);2462 2463 Py_DECREF(Tmp);2464 2465 N = hc -> dimensions[0];2466 2467 //Create hvbar2468 dimensions[0] = N;2469 dimensions[1] = 3;2470 hvbar = (PyArrayObject *) PyArray_FromDims(2, dimensions, PyArray_DOUBLE);2471 2472 2473 //Find min and max of this and neighbour's centroid values2474 hmin = malloc(N * sizeof(double));2475 hmax = malloc(N * sizeof(double));2476 for (k=0; k<N; k++) {2477 k3=k*3;2478 2479 hmin[k] = ((double*) hc -> data)[k];2480 hmax[k] = hmin[k];2481 2482 for (i=0; i<3; i++) {2483 n = ((long*) neighbours -> data)[k3+i];2484 2485 // Initialise hvbar with values from hv2486 ((double*) hvbar -> data)[k3+i] = ((double*) hv -> data)[k3+i];2487 2488 if (n >= 0) {2489 hn = ((double*) hc -> data)[n]; // Neighbour's centroid value2490 2491 hmin[k] = min(hmin[k], hn);2492 hmax[k] = max(hmax[k], hn);2493 }2494 }2495 }2496 2497 // Call underlying standard routine2498 _limit_old(N, beta_h, (double*) hc -> data, (double*) hvbar -> data, hmin, hmax);2499 2500 // // //Py_DECREF(domain); //FIXME: Necessary?2501 free(hmin);2502 free(hmax);2503 2504 // Return result using PyArray to avoid memory leak2505 return PyArray_Return(hvbar);2506 }2507 2508 PyObject *h_limiter_sw(PyObject *self, PyObject *args) {2509 //a faster version of h_limiter above2510 PyObject *domain, *Tmp;2511 PyArrayObject2512 *hv, *hc, //Depth at vertices and centroids2513 *hvbar, //Limited depth at vertices (return values)2514 *neighbours;2515 2516 int k, i, N, k3,k0,k1,k2;2517 int dimensions[2];2518 double beta_h; //Safety factor (see config.py)2519 double hmin, hmax, dh[3];2520 // Convert Python arguments to C2521 if (!PyArg_ParseTuple(args, "OOO", &domain, &hc, &hv)) {2522 PyErr_SetString(PyExc_RuntimeError, "shallow_water_ext.c: h_limiter_sw could not parse input arguments");2523 return NULL;2524 }2525 neighbours = get_consecutive_array(domain, "neighbours");2526 2527 //Get safety factor beta_h2528 Tmp = PyObject_GetAttrString(domain, "beta_h");2529 if (!Tmp) {2530 PyErr_SetString(PyExc_RuntimeError, "shallow_water_ext.c: h_limiter_sw could not obtain object beta_h from domain");2531 return NULL;2532 }2533 beta_h = PyFloat_AsDouble(Tmp);2534 2535 Py_DECREF(Tmp);2536 2537 N = hc -> dimensions[0];2538 2539 //Create hvbar2540 dimensions[0] = N;2541 dimensions[1] = 3;2542 hvbar = (PyArrayObject *) PyArray_FromDims(2, dimensions, PyArray_DOUBLE);2543 for (k=0;k<N;k++){2544 k3=k*3;2545 //get the ids of the neighbours2546 k0 = ((long*) neighbours -> data)[k3];2547 k1 = ((long*) neighbours -> data)[k3+1];2548 k2 = ((long*) neighbours -> data)[k3+2];2549 //set hvbar provisionally2550 for (i=0;i<3;i++){2551 ((double*) hvbar -> data)[k3+i] = ((double*) hv -> data)[k3+i];2552 dh[i]=((double*) hvbar -> data)[k3+i]-((double*) hc -> data)[k];2553 }2554 hmin=((double*) hc -> data)[k];2555 hmax=hmin;2556 if (k0>=0){2557 hmin=min(hmin,((double*) hc -> data)[k0]);2558 hmax=max(hmax,((double*) hc -> data)[k0]);2559 }2560 if (k1>=0){2561 hmin=min(hmin,((double*) hc -> data)[k1]);2562 hmax=max(hmax,((double*) hc -> data)[k1]);2563 }2564 if (k2>=0){2565 hmin=min(hmin,((double*) hc -> data)[k2]);2566 hmax=max(hmax,((double*) hc -> data)[k2]);2567 }2568 hmin-=((double*) hc -> data)[k];2569 hmax-=((double*) hc -> data)[k];2570 limit_gradient(dh,hmin,hmax,beta_h);2571 for (i=0;i<3;i++)2572 ((double*) hvbar -> data)[k3+i] = ((double*) hc -> data)[k]+dh[i];2573 }2574 return PyArray_Return(hvbar);2575 }2576 2421 2577 2422 PyObject *assign_windfield_values(PyObject *self, PyObject *args) { … … 2637 2482 {"balance_deep_and_shallow", balance_deep_and_shallow, 2638 2483 METH_VARARGS, "Print out"}, 2639 {"h_limiter", h_limiter,2640 METH_VARARGS, "Print out"},2641 {"h_limiter_sw", h_limiter_sw,2642 METH_VARARGS, "Print out"},2643 2484 {"protect", protect, METH_VARARGS | METH_KEYWORDS, "Print out"}, 2644 2485 {"assign_windfield_values", assign_windfield_values,
Note: See TracChangeset
for help on using the changeset viewer.