[246] | 1 | // Python - C extension module for shallow_water.py |
---|
| 2 | // |
---|
| 3 | // To compile (Python2.3): |
---|
| 4 | // gcc -c domain_ext.c -I/usr/include/python2.3 -o domain_ext.o -Wall -O |
---|
| 5 | // gcc -shared domain_ext.o -o domain_ext.so |
---|
| 6 | // |
---|
| 7 | // or use python compile.py |
---|
| 8 | // |
---|
| 9 | // See the module shallow_water.py |
---|
| 10 | // |
---|
| 11 | // |
---|
| 12 | // Ole Nielsen, GA 2004 |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | #include "Python.h" |
---|
| 16 | #include "Numeric/arrayobject.h" |
---|
| 17 | #include "math.h" |
---|
| 18 | |
---|
[258] | 19 | //Shared code snippets |
---|
| 20 | #include "util_ext.h" |
---|
[246] | 21 | |
---|
| 22 | |
---|
| 23 | // Computational function for rotation |
---|
| 24 | int _rotate(double *q, double n1, double n2) { |
---|
| 25 | /*Rotate the momentum component q (q[1], q[2]) |
---|
| 26 | from x,y coordinates to coordinates based on normal vector (n1, n2). |
---|
| 27 | |
---|
| 28 | Result is returned in array 3x1 r |
---|
| 29 | To rotate in opposite direction, call rotate with (q, n1, -n2) |
---|
| 30 | |
---|
| 31 | Contents of q are changed by this function */ |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | double q1, q2; |
---|
| 35 | |
---|
| 36 | //Shorthands |
---|
| 37 | q1 = q[1]; //uh momentum |
---|
| 38 | q2 = q[2]; //vh momentum |
---|
| 39 | |
---|
| 40 | //Rotate |
---|
| 41 | q[1] = n1*q1 + n2*q2; |
---|
| 42 | q[2] = -n2*q1 + n1*q2; |
---|
| 43 | |
---|
| 44 | return 0; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | // Computational function for flux computation (using stage w=z+h) |
---|
| 50 | int flux_function(double *q_left, double *q_right, |
---|
| 51 | double z_left, double z_right, |
---|
| 52 | double n1, double n2, |
---|
| 53 | double epsilon, double g, |
---|
| 54 | double *edgeflux, double *max_speed) { |
---|
| 55 | |
---|
| 56 | /*Compute fluxes between volumes for the shallow water wave equation |
---|
| 57 | cast in terms of the 'stage', w = h+z using |
---|
| 58 | the 'central scheme' as described in |
---|
| 59 | |
---|
| 60 | Kurganov, Noelle, Petrova. 'Semidiscrete Central-Upwind Schemes For |
---|
| 61 | Hyperbolic Conservation Laws and Hamilton-Jacobi Equations'. |
---|
| 62 | Siam J. Sci. Comput. Vol. 23, No. 3, pp. 707-740. |
---|
| 63 | |
---|
| 64 | The implemented formula is given in equation (3.15) on page 714 |
---|
| 65 | */ |
---|
| 66 | |
---|
| 67 | int i; |
---|
| 68 | |
---|
| 69 | double w_left, h_left, uh_left, vh_left, u_left; |
---|
| 70 | double w_right, h_right, uh_right, vh_right, u_right; |
---|
| 71 | double s_min, s_max, soundspeed_left, soundspeed_right; |
---|
| 72 | double denom, z; |
---|
| 73 | double q_left_copy[3], q_right_copy[3]; |
---|
| 74 | double flux_right[3], flux_left[3]; |
---|
| 75 | |
---|
| 76 | //Copy conserved quantities to protect from modification |
---|
| 77 | for (i=0; i<3; i++) { |
---|
| 78 | q_left_copy[i] = q_left[i]; |
---|
| 79 | q_right_copy[i] = q_right[i]; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | //Align x- and y-momentum with x-axis |
---|
| 83 | _rotate(q_left_copy, n1, n2); |
---|
| 84 | _rotate(q_right_copy, n1, n2); |
---|
| 85 | |
---|
| 86 | z = (z_left+z_right)/2; //Take average of field values |
---|
| 87 | |
---|
| 88 | //Compute speeds in x-direction |
---|
| 89 | w_left = q_left_copy[0]; // h+z |
---|
| 90 | h_left = w_left-z; |
---|
| 91 | uh_left = q_left_copy[1]; |
---|
| 92 | |
---|
| 93 | if (h_left < epsilon) { |
---|
| 94 | h_left = 0.0; //Could have been negative |
---|
| 95 | u_left = 0.0; |
---|
| 96 | } else { |
---|
| 97 | u_left = uh_left/h_left; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | w_right = q_right_copy[0]; |
---|
| 101 | h_right = w_right-z; |
---|
| 102 | uh_right = q_right_copy[1]; |
---|
| 103 | |
---|
| 104 | if (h_right < epsilon) { |
---|
| 105 | h_right = 0.0; //Could have been negative |
---|
| 106 | u_right = 0.0; |
---|
| 107 | } else { |
---|
| 108 | u_right = uh_right/h_right; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | //Momentum in y-direction |
---|
| 112 | vh_left = q_left_copy[2]; |
---|
| 113 | vh_right = q_right_copy[2]; |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | //Maximal and minimal wave speeds |
---|
| 117 | soundspeed_left = sqrt(g*h_left); |
---|
| 118 | soundspeed_right = sqrt(g*h_right); |
---|
| 119 | |
---|
| 120 | s_max = max(u_left+soundspeed_left, u_right+soundspeed_right); |
---|
| 121 | if (s_max < 0.0) s_max = 0.0; |
---|
| 122 | |
---|
| 123 | s_min = min(u_left-soundspeed_left, u_right-soundspeed_right); |
---|
| 124 | if (s_min > 0.0) s_min = 0.0; |
---|
| 125 | |
---|
| 126 | //Flux formulas |
---|
| 127 | flux_left[0] = u_left*h_left; |
---|
| 128 | flux_left[1] = u_left*uh_left + 0.5*g*h_left*h_left; |
---|
| 129 | flux_left[2] = u_left*vh_left; |
---|
| 130 | |
---|
| 131 | flux_right[0] = u_right*h_right; |
---|
| 132 | flux_right[1] = u_right*uh_right + 0.5*g*h_right*h_right; |
---|
| 133 | flux_right[2] = u_right*vh_right; |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | //Flux computation |
---|
| 137 | denom = s_max-s_min; |
---|
| 138 | if (denom == 0.0) { |
---|
| 139 | for (i=0; i<3; i++) edgeflux[i] = 0.0; |
---|
| 140 | *max_speed = 0.0; |
---|
| 141 | } else { |
---|
| 142 | for (i=0; i<3; i++) { |
---|
| 143 | edgeflux[i] = s_max*flux_left[i] - s_min*flux_right[i]; |
---|
| 144 | edgeflux[i] += s_max*s_min*(q_right_copy[i]-q_left_copy[i]); |
---|
| 145 | edgeflux[i] /= denom; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | //Maximal wavespeed |
---|
| 149 | *max_speed = max(fabs(s_max), fabs(s_min)); |
---|
| 150 | |
---|
| 151 | //Rotate back |
---|
| 152 | _rotate(edgeflux, n1, -n2); |
---|
| 153 | } |
---|
| 154 | return 0; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | void _manning_friction(double g, double eps, int N, |
---|
| 158 | double* w, double* uh, double* vh, |
---|
| 159 | double* eta, double* xmom, double* ymom) { |
---|
| 160 | |
---|
| 161 | int k; |
---|
| 162 | double S; |
---|
| 163 | |
---|
| 164 | for (k=0; k<N; k++) { |
---|
| 165 | if (w[k] >= eps) { |
---|
| 166 | S = -g * eta[k]*eta[k] * sqrt((uh[k]*uh[k] + vh[k]*vh[k])); |
---|
| 167 | S /= pow(w[k], 7.0/3); |
---|
| 168 | |
---|
| 169 | //Update momentum |
---|
| 170 | xmom[k] += S*uh[k]; |
---|
| 171 | ymom[k] += S*vh[k]; |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | /////////////////////////////////////////////////////////////////// |
---|
| 180 | // Gateways to Python |
---|
| 181 | |
---|
| 182 | PyObject *gravity(PyObject *self, PyObject *args) { |
---|
| 183 | // |
---|
| 184 | // gravity(g, h, v, x, xmom, ymom) |
---|
| 185 | // |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | PyArrayObject *h, *v, *x, *xmom, *ymom; |
---|
| 189 | int k, i, N, k3, k6; |
---|
| 190 | double g, avg_h, zx, zy; |
---|
| 191 | double x0, y0, x1, y1, x2, y2, z0, z1, z2; |
---|
| 192 | |
---|
| 193 | if (!PyArg_ParseTuple(args, "dOOOOO", |
---|
| 194 | &g, &h, &v, &x, |
---|
| 195 | &xmom, &ymom)) |
---|
| 196 | return NULL; |
---|
| 197 | |
---|
| 198 | N = h -> dimensions[0]; |
---|
| 199 | for (k=0; k<N; k++) { |
---|
| 200 | k3 = 3*k; // base index |
---|
| 201 | k6 = 6*k; // base index |
---|
| 202 | |
---|
| 203 | avg_h = 0.0; |
---|
| 204 | for (i=0; i<3; i++) { |
---|
| 205 | avg_h += ((double *) h -> data)[k3+i]; |
---|
| 206 | } |
---|
| 207 | avg_h /= 3; |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | //Compute bed slope |
---|
| 211 | x0 = ((double*) x -> data)[k6 + 0]; |
---|
| 212 | y0 = ((double*) x -> data)[k6 + 1]; |
---|
| 213 | x1 = ((double*) x -> data)[k6 + 2]; |
---|
| 214 | y1 = ((double*) x -> data)[k6 + 3]; |
---|
| 215 | x2 = ((double*) x -> data)[k6 + 4]; |
---|
| 216 | y2 = ((double*) x -> data)[k6 + 5]; |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | z0 = ((double*) v -> data)[k3 + 0]; |
---|
| 220 | z1 = ((double*) v -> data)[k3 + 1]; |
---|
| 221 | z2 = ((double*) v -> data)[k3 + 2]; |
---|
| 222 | |
---|
| 223 | _gradient(x0, y0, x1, y1, x2, y2, z0, z1, z2, &zx, &zy); |
---|
| 224 | |
---|
| 225 | //Update momentum |
---|
| 226 | ((double*) xmom -> data)[k] += -g*zx*avg_h; |
---|
| 227 | ((double*) ymom -> data)[k] += -g*zy*avg_h; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | return Py_BuildValue(""); |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | |
---|
| 234 | PyObject *manning_friction(PyObject *self, PyObject *args) { |
---|
| 235 | // |
---|
| 236 | // manning_friction(g, eps, w, uh, vh, eta, xmom_update, ymom_update) |
---|
| 237 | // |
---|
| 238 | |
---|
| 239 | |
---|
| 240 | PyArrayObject *w, *uh, *vh, *eta, *xmom, *ymom; |
---|
| 241 | int N; |
---|
| 242 | double g, eps; |
---|
| 243 | |
---|
| 244 | if (!PyArg_ParseTuple(args, "ddOOOOOO", |
---|
| 245 | &g, &eps, &w, &uh, &vh, &eta, |
---|
| 246 | &xmom, &ymom)) |
---|
| 247 | return NULL; |
---|
| 248 | |
---|
| 249 | N = w -> dimensions[0]; |
---|
| 250 | _manning_friction(g, eps, N, |
---|
| 251 | (double*) w -> data, |
---|
| 252 | (double*) uh -> data, |
---|
| 253 | (double*) vh -> data, |
---|
| 254 | (double*) eta -> data, |
---|
| 255 | (double*) xmom -> data, |
---|
| 256 | (double*) ymom -> data); |
---|
| 257 | |
---|
| 258 | return Py_BuildValue(""); |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | PyObject *rotate(PyObject *self, PyObject *args, PyObject *kwargs) { |
---|
| 262 | // |
---|
| 263 | // r = rotate(q, normal, direction=1) |
---|
| 264 | // |
---|
| 265 | // Where q is assumed to be a Float numeric array of length 3 and |
---|
| 266 | // normal a Float numeric array of length 2. |
---|
| 267 | |
---|
| 268 | |
---|
| 269 | PyObject *Q, *Normal; |
---|
| 270 | PyArrayObject *q, *r, *normal; |
---|
| 271 | |
---|
| 272 | static char *argnames[] = {"q", "normal", "direction", NULL}; |
---|
| 273 | int dimensions[1], i, direction=1; |
---|
| 274 | double n1, n2; |
---|
| 275 | |
---|
| 276 | // Convert Python arguments to C |
---|
| 277 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|i", argnames, |
---|
| 278 | &Q, &Normal, &direction)) |
---|
| 279 | return NULL; |
---|
| 280 | |
---|
| 281 | //Input checks (convert sequences into numeric arrays) |
---|
| 282 | q = (PyArrayObject *) |
---|
| 283 | PyArray_ContiguousFromObject(Q, PyArray_DOUBLE, 0, 0); |
---|
| 284 | normal = (PyArrayObject *) |
---|
| 285 | PyArray_ContiguousFromObject(Normal, PyArray_DOUBLE, 0, 0); |
---|
| 286 | |
---|
| 287 | //Allocate space for return vector r (don't DECREF) |
---|
| 288 | dimensions[0] = 3; |
---|
| 289 | r = (PyArrayObject *) PyArray_FromDims(1, dimensions, PyArray_DOUBLE); |
---|
| 290 | |
---|
| 291 | //Copy |
---|
| 292 | for (i=0; i<3; i++) { |
---|
| 293 | ((double *) (r -> data))[i] = ((double *) (q -> data))[i]; |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | //Get normal and direction |
---|
| 297 | n1 = ((double *) normal -> data)[0]; |
---|
| 298 | n2 = ((double *) normal -> data)[1]; |
---|
| 299 | if (direction == -1) n2 = -n2; |
---|
| 300 | |
---|
| 301 | //Rotate |
---|
| 302 | _rotate((double *) r -> data, n1, n2); |
---|
[259] | 303 | |
---|
[260] | 304 | //Release numeric arrays |
---|
[259] | 305 | Py_DECREF(q); |
---|
| 306 | Py_DECREF(normal); |
---|
| 307 | |
---|
[246] | 308 | //return result using PyArray to avoid memory leak |
---|
| 309 | return PyArray_Return(r); |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | |
---|
| 313 | |
---|
| 314 | |
---|
| 315 | |
---|
| 316 | PyObject *compute_fluxes(PyObject *self, PyObject *args) { |
---|
| 317 | /*Compute all fluxes and the timestep suitable for all volumes |
---|
| 318 | in domain. |
---|
| 319 | |
---|
| 320 | Compute total flux for each conserved quantity using "flux_function" |
---|
| 321 | |
---|
| 322 | Fluxes across each edge are scaled by edgelengths and summed up |
---|
| 323 | Resulting flux is then scaled by area and stored in |
---|
| 324 | explicit_update for each of the three conserved quantities |
---|
| 325 | level, xmomentum and ymomentum |
---|
| 326 | |
---|
| 327 | The maximal allowable speed computed by the flux_function for each volume |
---|
| 328 | is converted to a timestep that must not be exceeded. The minimum of |
---|
| 329 | those is computed as the next overall timestep. |
---|
| 330 | |
---|
| 331 | Python call: |
---|
| 332 | domain.timestep = compute_fluxes(timestep, |
---|
| 333 | domain.epsilon, |
---|
| 334 | domain.g, |
---|
| 335 | domain.neighbours, |
---|
| 336 | domain.neighbour_edges, |
---|
| 337 | domain.normals, |
---|
| 338 | domain.edgelengths, |
---|
| 339 | domain.radii, |
---|
| 340 | domain.areas, |
---|
| 341 | Level.edge_values, |
---|
| 342 | Xmom.edge_values, |
---|
| 343 | Ymom.edge_values, |
---|
| 344 | Bed.edge_values, |
---|
| 345 | Level.boundary_values, |
---|
| 346 | Xmom.boundary_values, |
---|
| 347 | Ymom.boundary_values, |
---|
| 348 | Level.explicit_update, |
---|
| 349 | Xmom.explicit_update, |
---|
| 350 | Ymom.explicit_update) |
---|
| 351 | |
---|
| 352 | |
---|
| 353 | Post conditions: |
---|
| 354 | domain.explicit_update is reset to computed flux values |
---|
| 355 | domain.timestep is set to the largest step satisfying all volumes. |
---|
| 356 | |
---|
| 357 | |
---|
| 358 | */ |
---|
| 359 | |
---|
| 360 | |
---|
| 361 | PyArrayObject *neighbours, *neighbour_edges, |
---|
| 362 | *normals, *edgelengths, *radii, *areas, |
---|
| 363 | *level_edge_values, |
---|
| 364 | *xmom_edge_values, |
---|
| 365 | *ymom_edge_values, |
---|
| 366 | *bed_edge_values, |
---|
| 367 | *level_boundary_values, |
---|
| 368 | *xmom_boundary_values, |
---|
| 369 | *ymom_boundary_values, |
---|
| 370 | *level_explicit_update, |
---|
| 371 | *xmom_explicit_update, |
---|
| 372 | *ymom_explicit_update; |
---|
| 373 | |
---|
| 374 | |
---|
| 375 | //Local variables |
---|
| 376 | double timestep, max_speed, epsilon, g; |
---|
| 377 | double normal[2], ql[3], qr[3], zl, zr; |
---|
| 378 | double flux[3], edgeflux[3]; //Work arrays for summing up fluxes |
---|
| 379 | |
---|
| 380 | int number_of_elements, k, i, j, m, n; |
---|
| 381 | int ki, nm, ki2; //Index shorthands |
---|
| 382 | |
---|
| 383 | |
---|
| 384 | // Convert Python arguments to C |
---|
| 385 | if (!PyArg_ParseTuple(args, "dddOOOOOOOOOOOOOOOO", |
---|
| 386 | ×tep, |
---|
| 387 | &epsilon, |
---|
| 388 | &g, |
---|
| 389 | &neighbours, |
---|
| 390 | &neighbour_edges, |
---|
| 391 | &normals, |
---|
| 392 | &edgelengths, &radii, &areas, |
---|
| 393 | &level_edge_values, |
---|
| 394 | &xmom_edge_values, |
---|
| 395 | &ymom_edge_values, |
---|
| 396 | &bed_edge_values, |
---|
| 397 | &level_boundary_values, |
---|
| 398 | &xmom_boundary_values, |
---|
| 399 | &ymom_boundary_values, |
---|
| 400 | &level_explicit_update, |
---|
| 401 | &xmom_explicit_update, |
---|
| 402 | &ymom_explicit_update)) { |
---|
| 403 | PyErr_SetString(PyExc_RuntimeError, "Input arguments failed"); |
---|
| 404 | return NULL; |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | number_of_elements = level_edge_values -> dimensions[0]; |
---|
| 408 | |
---|
| 409 | |
---|
| 410 | for (k=0; k<number_of_elements; k++) { |
---|
| 411 | |
---|
| 412 | //Reset work array |
---|
| 413 | for (j=0; j<3; j++) flux[j] = 0.0; |
---|
| 414 | |
---|
| 415 | //Loop through neighbours and compute edge flux for each |
---|
| 416 | for (i=0; i<3; i++) { |
---|
| 417 | ki = k*3+i; |
---|
| 418 | ql[0] = ((double *) level_edge_values -> data)[ki]; |
---|
| 419 | ql[1] = ((double *) xmom_edge_values -> data)[ki]; |
---|
| 420 | ql[2] = ((double *) ymom_edge_values -> data)[ki]; |
---|
| 421 | zl = ((double *) bed_edge_values -> data)[ki]; |
---|
| 422 | |
---|
| 423 | //Quantities at neighbour on nearest face |
---|
| 424 | n = ((int *) neighbours -> data)[ki]; |
---|
| 425 | if (n < 0) { |
---|
| 426 | m = -n-1; //Convert negative flag to index |
---|
| 427 | qr[0] = ((double *) level_boundary_values -> data)[m]; |
---|
| 428 | qr[1] = ((double *) xmom_boundary_values -> data)[m]; |
---|
| 429 | qr[2] = ((double *) ymom_boundary_values -> data)[m]; |
---|
| 430 | zr = zl; //Extend bed elevation to boundary |
---|
| 431 | } else { |
---|
| 432 | m = ((int *) neighbour_edges -> data)[ki]; |
---|
| 433 | |
---|
| 434 | nm = n*3+m; |
---|
| 435 | qr[0] = ((double *) level_edge_values -> data)[nm]; |
---|
| 436 | qr[1] = ((double *) xmom_edge_values -> data)[nm]; |
---|
| 437 | qr[2] = ((double *) ymom_edge_values -> data)[nm]; |
---|
| 438 | zr = ((double *) bed_edge_values -> data)[nm]; |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | // Outward pointing normal vector |
---|
| 442 | // normal = domain.normals[k, 2*i:2*i+2] |
---|
| 443 | ki2 = 2*ki; //k*6 + i*2 |
---|
| 444 | normal[0] = ((double *) normals -> data)[ki2]; |
---|
| 445 | normal[1] = ((double *) normals -> data)[ki2+1]; |
---|
| 446 | |
---|
| 447 | //Edge flux computation |
---|
| 448 | flux_function(ql, qr, zl, zr, |
---|
| 449 | normal[0], normal[1], |
---|
| 450 | epsilon, g, |
---|
| 451 | edgeflux, &max_speed); |
---|
| 452 | |
---|
| 453 | |
---|
| 454 | //flux -= edgeflux * edgelengths[k,i] |
---|
| 455 | for (j=0; j<3; j++) { |
---|
| 456 | flux[j] -= edgeflux[j]*((double *) edgelengths -> data)[ki]; |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | //Update timestep |
---|
| 460 | //timestep = min(timestep, domain.radii[k]/max_speed) |
---|
| 461 | if (max_speed > epsilon) { |
---|
| 462 | timestep = min(timestep, ((double *) radii -> data)[k]/max_speed); |
---|
| 463 | } |
---|
| 464 | } // end for i |
---|
| 465 | |
---|
| 466 | //Normalise by area and store for when all conserved |
---|
| 467 | //quantities get updated |
---|
| 468 | // flux /= areas[k] |
---|
| 469 | for (j=0; j<3; j++) { |
---|
| 470 | flux[j] /= ((double *) areas -> data)[k]; |
---|
| 471 | } |
---|
| 472 | |
---|
| 473 | ((double *) level_explicit_update -> data)[k] = flux[0]; |
---|
| 474 | ((double *) xmom_explicit_update -> data)[k] = flux[1]; |
---|
| 475 | ((double *) ymom_explicit_update -> data)[k] = flux[2]; |
---|
| 476 | |
---|
| 477 | } //end for k |
---|
| 478 | |
---|
| 479 | return Py_BuildValue("d", timestep); |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | |
---|
| 483 | |
---|
| 484 | |
---|
| 485 | |
---|
| 486 | |
---|
| 487 | |
---|
| 488 | |
---|
| 489 | ////////////////////////////////////////// |
---|
| 490 | // Method table for python module |
---|
| 491 | static struct PyMethodDef MethodTable[] = { |
---|
| 492 | /* The cast of the function is necessary since PyCFunction values |
---|
| 493 | * only take two PyObject* parameters, and rotate() takes |
---|
| 494 | * three. |
---|
| 495 | */ |
---|
| 496 | |
---|
| 497 | {"rotate", (PyCFunction)rotate, METH_VARARGS | METH_KEYWORDS, "Print out"}, |
---|
| 498 | {"compute_fluxes", compute_fluxes, METH_VARARGS, "Print out"}, |
---|
| 499 | {"gravity", gravity, METH_VARARGS, "Print out"}, |
---|
| 500 | {"manning_friction", manning_friction, METH_VARARGS, "Print out"}, |
---|
| 501 | //{"distribute_to_vertices_and_edges", |
---|
| 502 | // distribute_to_vertices_and_edges, METH_VARARGS}, |
---|
| 503 | //{"update_conserved_quantities", |
---|
| 504 | // update_conserved_quantities, METH_VARARGS}, |
---|
| 505 | //{"set_initialcondition", |
---|
| 506 | // set_initialcondition, METH_VARARGS}, |
---|
| 507 | {NULL, NULL} |
---|
| 508 | }; |
---|
| 509 | |
---|
| 510 | // Module initialisation |
---|
| 511 | void initshallow_water_ext(void){ |
---|
| 512 | Py_InitModule("shallow_water_ext", MethodTable); |
---|
| 513 | |
---|
| 514 | import_array(); //Necessary for handling of NumPY structures |
---|
| 515 | } |
---|