- Timestamp:
- Oct 30, 2007, 5:13:17 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/shallow_water_ext.c
r4733 r4769 194 194 195 195 // Innermost flux function (using stage w=z+h) 196 int flux_function_central(double *q_left, double *q_right,197 double z_left, double z_right,198 double n1, double n2,199 double epsilon, double H0, double g,200 double *edgeflux, double *max_speed) {196 int _flux_function_central(double *q_left, double *q_right, 197 double z_left, double z_right, 198 double n1, double n2, 199 double epsilon, double H0, double g, 200 double *edgeflux, double *max_speed) { 201 201 202 202 /*Compute fluxes between volumes for the shallow water wave equation … … 737 737 /////////////////////////////////////////////////////////////////// 738 738 // Gateways to Python 739 740 741 742 PyObject *flux_function_central(PyObject *self, PyObject *args) { 743 // 744 // Gateway to innermost flux function. 745 // This is only used by the unit tests as the c implementation is 746 // normally called by compute_fluxes in this module. 747 748 749 PyArrayObject *normal, *ql, *qr, *edgeflux; 750 double g, epsilon, max_speed, H0, zl, zr; 751 752 if (!PyArg_ParseTuple(args, "OOOddOddd", 753 &normal, &ql, &qr, &zl, &zr, &edgeflux, 754 &epsilon, &g, &H0)) { 755 PyErr_SetString(PyExc_RuntimeError, "shallow_water_ext.c: flux_function_central could not parse input arguments"); 756 return NULL; 757 } 758 759 760 _flux_function_central((double*) ql -> data, 761 (double*) qr -> data, 762 zl, 763 zr, 764 ((double*) normal -> data)[0], 765 ((double*) normal -> data)[1], 766 epsilon, H0, g, 767 (double*) edgeflux -> data, 768 &max_speed); 769 770 return Py_BuildValue("d", max_speed); 771 } 772 773 739 774 740 775 PyObject *gravity(PyObject *self, PyObject *args) { … … 1494 1529 } 1495 1530 1496 // Input checks (convert sequences into numeric arrays)1531 // Input checks (convert sequences into numeric arrays) 1497 1532 q = (PyArrayObject *) 1498 1533 PyArray_ContiguousFromObject(Q, PyArray_DOUBLE, 0, 0); … … 1506 1541 } 1507 1542 1508 // Allocate space for return vector r (don't DECREF)1543 // Allocate space for return vector r (don't DECREF) 1509 1544 dimensions[0] = 3; 1510 1545 r = (PyArrayObject *) PyArray_FromDims(1, dimensions, PyArray_DOUBLE); 1511 1546 1512 // Copy1547 // Copy 1513 1548 for (i=0; i<3; i++) { 1514 1549 ((double *) (r -> data))[i] = ((double *) (q -> data))[i]; 1515 1550 } 1516 1551 1517 // Get normal and direction1552 // Get normal and direction 1518 1553 n1 = ((double *) normal -> data)[0]; 1519 1554 n2 = ((double *) normal -> data)[1]; 1520 1555 if (direction == -1) n2 = -n2; 1521 1556 1522 // Rotate1557 // Rotate 1523 1558 _rotate((double *) r -> data, n1, n2); 1524 1559 1525 // Release numeric arrays1560 // Release numeric arrays 1526 1561 Py_DECREF(q); 1527 1562 Py_DECREF(normal); 1528 1563 1529 // return result using PyArray to avoid memory leak1564 // Return result using PyArray to avoid memory leak 1530 1565 return PyArray_Return(r); 1531 1566 } … … 1642 1677 1643 1678 // Edge flux computation (triangle k, edge i) 1644 flux_function_central(ql, qr, zl, zr,1645 normals[ki2], normals[ki2+1],1646 epsilon, H0, g,1647 edgeflux, &max_speed);1679 _flux_function_central(ql, qr, zl, zr, 1680 normals[ki2], normals[ki2+1], 1681 epsilon, H0, g, 1682 edgeflux, &max_speed); 1648 1683 1649 1684 … … 1898 1933 *xmom_explicit_update, 1899 1934 *ymom_explicit_update, 1900 *already_computed_flux; //tracks whether the flux across an edge has already been computed1901 1902 1903 // Local variables1935 *already_computed_flux; // Tracks whether the flux across an edge has already been computed 1936 1937 1938 // Local variables 1904 1939 double timestep, max_speed, epsilon, g, H0; 1905 1940 double normal[2], ql[3], qr[3], zl, zr; … … 2060 2095 2061 2096 PyObject *balance_deep_and_shallow(PyObject *self, PyObject *args) { 2097 // Compute linear combination between stage as computed by 2098 // gradient-limiters limiting using w, and stage computed by 2099 // gradient-limiters limiting using h (h-limiter). 2100 // The former takes precedence when heights are large compared to the 2101 // bed slope while the latter takes precedence when heights are 2102 // relatively small. Anything in between is computed as a balanced 2103 // linear combination in order to avoid numerical disturbances which 2104 // would otherwise appear as a result of hard switching between 2105 // modes. 2062 2106 // 2063 2107 // balance_deep_and_shallow(beta_h, wc, zc, wv, zv, … … 2160 2204 int k, i, n, N, k3; 2161 2205 int dimensions[2]; 2162 double beta_h; // Safety factor (see config.py)2206 double beta_h; // Safety factor (see config.py) 2163 2207 double *hmin, *hmax, hn; 2164 2208 … … 2201 2245 n = ((long*) neighbours -> data)[k3+i]; 2202 2246 2203 // Initialise hvbar with values from hv2247 // Initialise hvbar with values from hv 2204 2248 ((double*) hvbar -> data)[k3+i] = ((double*) hv -> data)[k3+i]; 2205 2249 2206 2250 if (n >= 0) { 2207 hn = ((double*) hc -> data)[n]; // Neighbour's centroid value2251 hn = ((double*) hc -> data)[n]; // Neighbour's centroid value 2208 2252 2209 2253 hmin[k] = min(hmin[k], hn); … … 2216 2260 _limit(N, beta_h, (double*) hc -> data, (double*) hvbar -> data, hmin, hmax); 2217 2261 2218 // // //Py_DECREF(domain); //FIXME: N Ecessary?2262 // // //Py_DECREF(domain); //FIXME: Necessary? 2219 2263 free(hmin); 2220 2264 free(hmax); 2221 2265 2222 // return result using PyArray to avoid memory leak2266 // Return result using PyArray to avoid memory leak 2223 2267 return PyArray_Return(hvbar); 2224 //return Py_BuildValue("");2225 2268 } 2226 2269 … … 2337 2380 2338 2381 2339 // ////////////////////////////////////////2382 //------------------------------- 2340 2383 // Method table for python module 2384 //------------------------------- 2341 2385 static struct PyMethodDef MethodTable[] = { 2342 2386 /* The cast of the function is necessary since PyCFunction values … … 2351 2395 {"gravity", gravity, METH_VARARGS, "Print out"}, 2352 2396 {"manning_friction", manning_friction, METH_VARARGS, "Print out"}, 2397 {"flux_function_central", flux_function_central, METH_VARARGS, "Print out"}, 2353 2398 {"balance_deep_and_shallow", balance_deep_and_shallow, 2354 2399 METH_VARARGS, "Print out"}, … … 2360 2405 {"assign_windfield_values", assign_windfield_values, 2361 2406 METH_VARARGS | METH_KEYWORDS, "Print out"}, 2362 //{"distribute_to_vertices_and_edges",2363 // distribute_to_vertices_and_edges, METH_VARARGS},2364 //{"update_conserved_quantities",2365 // update_conserved_quantities, METH_VARARGS},2366 //{"set_initialcondition",2367 // set_initialcondition, METH_VARARGS},2368 2407 {NULL, NULL} 2369 2408 };
Note: See TracChangeset
for help on using the changeset viewer.