Changeset 8367


Ignore:
Timestamp:
Mar 26, 2012, 5:35:53 PM (13 years ago)
Author:
steve
Message:

Starting to add in well balanced gravity term

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/shallow_water/shallow_water_ext.c

    r8308 r8367  
    11431143  return Py_BuildValue("");
    11441144}
     1145
     1146
     1147PyObject *gravity_new(PyObject *self, PyObject *args) {
     1148  //
     1149  //  gravity_new(g, h, v, x, xmom, ymom)
     1150  //
     1151
     1152
     1153  PyArrayObject *h, *z, *x, *xmom, *ymom;
     1154  int k, N, k3, k6;
     1155  double g, avg_h, zx, zy;
     1156  double x0, y0, x1, y1, x2, y2, z0, z1, z2;
     1157  //double epsilon;
     1158
     1159  if (!PyArg_ParseTuple(args, "dOOOOO",
     1160            &g, &h, &z, &x,
     1161            &xmom, &ymom)) {
     1162    //&epsilon)) {
     1163      report_python_error(AT, "could not parse input arguments");
     1164      return NULL;
     1165  }
     1166
     1167  // check that numpy array objects arrays are C contiguous memory
     1168  CHECK_C_CONTIG(h);
     1169  CHECK_C_CONTIG(z);
     1170  CHECK_C_CONTIG(x);
     1171  CHECK_C_CONTIG(xmom);
     1172  CHECK_C_CONTIG(ymom);
     1173
     1174  N = h -> dimensions[0];
     1175  for (k=0; k<N; k++) {
     1176    k3 = 3*k;  // base index
     1177
     1178    // Get bathymetry
     1179    z0 = ((double*) z -> data)[k3 + 0];
     1180    z1 = ((double*) z -> data)[k3 + 1];
     1181    z2 = ((double*) z -> data)[k3 + 2];
     1182
     1183    // Optimise for flat bed
     1184    // Note (Ole): This didn't produce measurable speed up.
     1185    // Revisit later
     1186    //if (fabs(z0-z1)<epsilon && fabs(z1-z2)<epsilon) {
     1187    //  continue;
     1188    //}
     1189
     1190    // Get average depth from centroid values
     1191    avg_h = ((double *) h -> data)[k];
     1192
     1193    // Compute bed slope
     1194    k6 = 6*k;  // base index
     1195
     1196    x0 = ((double*) x -> data)[k6 + 0];
     1197    y0 = ((double*) x -> data)[k6 + 1];
     1198    x1 = ((double*) x -> data)[k6 + 2];
     1199    y1 = ((double*) x -> data)[k6 + 3];
     1200    x2 = ((double*) x -> data)[k6 + 4];
     1201    y2 = ((double*) x -> data)[k6 + 5];
     1202
     1203
     1204    _gradient(x0, y0, x1, y1, x2, y2, z0, z1, z2, &zx, &zy);
     1205
     1206    // Update momentum
     1207    ((double*) xmom -> data)[k] += -g*zx*avg_h;
     1208    ((double*) ymom -> data)[k] += -g*zy*avg_h;
     1209  }
     1210
     1211  return Py_BuildValue("");
     1212}
     1213
    11451214
    11461215
     
    29543023  {"compute_fluxes_ext_kinetic", compute_fluxes_ext_kinetic, METH_VARARGS, "Print out"},
    29553024  {"gravity", gravity, METH_VARARGS, "Print out"},
     3025  {"gravity_new", gravity, METH_VARARGS, "Print out"},
    29563026  {"manning_friction_flat", manning_friction_flat, METH_VARARGS, "Print out"},
    29573027  {"manning_friction_sloped", manning_friction_sloped, METH_VARARGS, "Print out"},
Note: See TracChangeset for help on using the changeset viewer.