Changeset 8456


Ignore:
Timestamp:
Jul 6, 2012, 5:45:58 PM (13 years ago)
Author:
steve
Message:

Adding in some of gareth's methods

Location:
trunk/anuga_core/source/anuga
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/generic_domain.py

    r8455 r8456  
    100100        self.centroid_coordinates = self.mesh.centroid_coordinates
    101101        self.vertex_coordinates = self.mesh.vertex_coordinates
     102        self.edge_coordinates = self.mesh.edge_midpoint_coordinates
    102103        self.boundary = self.mesh.boundary
    103104        self.boundary_enumeration = self.mesh.boundary_enumeration
  • trunk/anuga_core/source/anuga/operators/kinematic_viscosity_operator.py

    r8454 r8456  
    2727    """
    2828
    29     def __init__(self, domain, use_triangle_areas=True, verbose=False):
     29    def __init__(self, domain, diffusivity=None, use_triangle_areas=True, verbose=False):
     30
    3031        if verbose: log.critical('Kinematic Viscosity: Beginning Initialisation')
    3132       
     
    3738        self.boundary = domain.boundary
    3839        self.boundary_enumeration = domain.boundary_enumeration
    39        
     40
     41        self.diffusivity = diffusivity
    4042        # Setup a quantity as diffusivity
    41         # FIXME SR: Could/Should pass a quantity which already exists
    42         self.diffusivity = Quantity(self.domain)
    43         self.diffusivity.set_values(1.0)
    44         self.diffusivity.set_boundary_values(1.0)
     43        if diffusivity is None:
     44            self.diffusivity = Quantity(self.domain)
     45            self.diffusivity.set_values(1.0)
     46            self.diffusivity.set_boundary_values(1.0)
     47
     48        if isinstance(diffusivity, (int, float)):
     49            self.diffusivity = Quantity(self.domain)
     50            self.diffusivity.set_values(diffusivity)
     51            self.diffusivity.set_boundary_values(diffusivity)
     52
     53   
     54        assert isinstance(self.diffusivity, Quantity)
    4555       
    4656
  • trunk/anuga_core/source/anuga/shallow_water/boundaries.py

    r8124 r8456  
    117117
    118118        self.domain = domain
     119
     120        if isinstance(function, (int, float)):
     121            tmp = function
     122            function = lambda t: tmp
     123           
    119124        self.function = function
    120125
  • trunk/anuga_core/source/anuga/shallow_water/shallow_water_domain.py

    r8455 r8456  
    798798        """Call correct module function
    799799            (either from this module or C-extension)"""
    800         extrapolate_second_order_sw(self)
     800        extrapolate_second_order_sw_old(self)
    801801
    802802    def compute_fluxes(self):
     
    14361436################################################################################
    14371437
    1438 def extrapolate_second_order_sw(domain):
     1438def extrapolate_second_order_sw_old(domain):
    14391439    """Wrapper calling C version of extrapolate_second_order_sw.
    14401440
     
    14451445    """
    14461446
    1447     from shallow_water_ext import extrapolate_second_order_sw as extrapol2
     1447    from shallow_water_ext import extrapolate_second_order_sw_old as extrapol2
    14481448
    14491449    # Shortcuts
     
    14681468              int(domain.optimise_dry_cells),
    14691469              int(domain.extrapolate_velocity_second_order))
     1470
     1471
     1472def extrapolate_second_order_sw(domain):
     1473    """Wrapper calling C version of extrapolate_second_order_sw.
     1474
     1475    domain  the domain to operate on
     1476
     1477    Note MH090605: The following method belongs to the shallow_water domain
     1478    class, see comments in the corresponding method in shallow_water_ext.c
     1479    """
     1480
     1481    from shallow_water_ext import extrapolate_second_order_sw as extrapol2
     1482    extrapol2(domain)
     1483
    14701484
    14711485def distribute_using_vertex_limiter(domain):
  • trunk/anuga_core/source/anuga/shallow_water/shallow_water_ext.c

    r8455 r8456  
    20602060// Computational routine
    20612061
     2062int _extrapolate_second_order_sw_old(int number_of_elements,
     2063        double epsilon,
     2064        double minimum_allowed_height,
     2065        double beta_w,
     2066        double beta_w_dry,
     2067        double beta_uh,
     2068        double beta_uh_dry,
     2069        double beta_vh,
     2070        double beta_vh_dry,
     2071        long* surrogate_neighbours,
     2072        long* number_of_boundaries,
     2073        double* centroid_coordinates,
     2074        double* stage_centroid_values,
     2075        double* xmom_centroid_values,
     2076        double* ymom_centroid_values,
     2077        double* elevation_centroid_values,
     2078        double* vertex_coordinates,
     2079        double* stage_vertex_values,
     2080        double* xmom_vertex_values,
     2081        double* ymom_vertex_values,
     2082        double* elevation_vertex_values,
     2083        int optimise_dry_cells,
     2084        int extrapolate_velocity_second_order) {
     2085
     2086
     2087
     2088    // Local variables
     2089    double a, b; // Gradient vector used to calculate vertex values from centroids
     2090    int k, k0, k1, k2, k3, k6, coord_index, i;
     2091    double x, y, x0, y0, x1, y1, x2, y2, xv0, yv0, xv1, yv1, xv2, yv2; // Vertices of the auxiliary triangle
     2092    double dx1, dx2, dy1, dy2, dxv0, dxv1, dxv2, dyv0, dyv1, dyv2, dq0, dq1, dq2, area2, inv_area2;
     2093    double dqv[3], qmin, qmax, hmin, hmax;
     2094    double hc, h0, h1, h2, beta_tmp, hfactor;
     2095    double xmom_centroid_store[number_of_elements], ymom_centroid_store[number_of_elements], dk, dv0, dv1, dv2;
     2096
     2097    if (extrapolate_velocity_second_order == 1) {
     2098        // Replace momentum centroid with velocity centroid to allow velocity
     2099        // extrapolation This will be changed back at the end of the routine
     2100        for (k = 0; k < number_of_elements; k++) {
     2101
     2102            dk = max(stage_centroid_values[k] - elevation_centroid_values[k], minimum_allowed_height);
     2103            xmom_centroid_store[k] = xmom_centroid_values[k];
     2104            xmom_centroid_values[k] = xmom_centroid_values[k] / dk;
     2105
     2106            ymom_centroid_store[k] = ymom_centroid_values[k];
     2107            ymom_centroid_values[k] = ymom_centroid_values[k] / dk;
     2108        }
     2109    }
     2110
     2111    // Begin extrapolation routine
     2112    for (k = 0; k < number_of_elements; k++) {
     2113        k3 = k * 3;
     2114        k6 = k * 6;
     2115
     2116        if (number_of_boundaries[k] == 3) {
     2117            // No neighbours, set gradient on the triangle to zero
     2118
     2119            stage_vertex_values[k3] = stage_centroid_values[k];
     2120            stage_vertex_values[k3 + 1] = stage_centroid_values[k];
     2121            stage_vertex_values[k3 + 2] = stage_centroid_values[k];
     2122            xmom_vertex_values[k3] = xmom_centroid_values[k];
     2123            xmom_vertex_values[k3 + 1] = xmom_centroid_values[k];
     2124            xmom_vertex_values[k3 + 2] = xmom_centroid_values[k];
     2125            ymom_vertex_values[k3] = ymom_centroid_values[k];
     2126            ymom_vertex_values[k3 + 1] = ymom_centroid_values[k];
     2127            ymom_vertex_values[k3 + 2] = ymom_centroid_values[k];
     2128
     2129            continue;
     2130        } else {
     2131            // Triangle k has one or more neighbours.
     2132            // Get centroid and vertex coordinates of the triangle
     2133
     2134            // Get the vertex coordinates
     2135            xv0 = vertex_coordinates[k6];
     2136            yv0 = vertex_coordinates[k6 + 1];
     2137            xv1 = vertex_coordinates[k6 + 2];
     2138            yv1 = vertex_coordinates[k6 + 3];
     2139            xv2 = vertex_coordinates[k6 + 4];
     2140            yv2 = vertex_coordinates[k6 + 5];
     2141
     2142            // Get the centroid coordinates
     2143            coord_index = 2 * k;
     2144            x = centroid_coordinates[coord_index];
     2145            y = centroid_coordinates[coord_index + 1];
     2146
     2147            // Store x- and y- differentials for the vertices of
     2148            // triangle k relative to the centroid
     2149            dxv0 = xv0 - x;
     2150            dxv1 = xv1 - x;
     2151            dxv2 = xv2 - x;
     2152            dyv0 = yv0 - y;
     2153            dyv1 = yv1 - y;
     2154            dyv2 = yv2 - y;
     2155        }
     2156
     2157
     2158
     2159        if (number_of_boundaries[k] <= 1) {
     2160            //==============================================
     2161            // Number of boundaries <= 1
     2162            //==============================================
     2163
     2164
     2165            // If no boundaries, auxiliary triangle is formed
     2166            // from the centroids of the three neighbours
     2167            // If one boundary, auxiliary triangle is formed
     2168            // from this centroid and its two neighbours
     2169
     2170            k0 = surrogate_neighbours[k3];
     2171            k1 = surrogate_neighbours[k3 + 1];
     2172            k2 = surrogate_neighbours[k3 + 2];
     2173
     2174            // Get the auxiliary triangle's vertex coordinates
     2175            // (really the centroids of neighbouring triangles)
     2176            coord_index = 2 * k0;
     2177            x0 = centroid_coordinates[coord_index];
     2178            y0 = centroid_coordinates[coord_index + 1];
     2179
     2180            coord_index = 2 * k1;
     2181            x1 = centroid_coordinates[coord_index];
     2182            y1 = centroid_coordinates[coord_index + 1];
     2183
     2184            coord_index = 2 * k2;
     2185            x2 = centroid_coordinates[coord_index];
     2186            y2 = centroid_coordinates[coord_index + 1];
     2187
     2188            // Store x- and y- differentials for the vertices
     2189            // of the auxiliary triangle
     2190            dx1 = x1 - x0;
     2191            dx2 = x2 - x0;
     2192            dy1 = y1 - y0;
     2193            dy2 = y2 - y0;
     2194
     2195            // Calculate 2*area of the auxiliary triangle
     2196            // The triangle is guaranteed to be counter-clockwise
     2197            area2 = dy2 * dx1 - dy1*dx2;
     2198
     2199            // If the mesh is 'weird' near the boundary,
     2200            // the triangle might be flat or clockwise
     2201            // Default to zero gradient
     2202            if (area2 <= 0) {
     2203                //printf("Error negative triangle area \n");
     2204                //report_python_error(AT, "Negative triangle area");
     2205                //return -1;
     2206
     2207                stage_vertex_values[k3] = stage_centroid_values[k];
     2208                stage_vertex_values[k3 + 1] = stage_centroid_values[k];
     2209                stage_vertex_values[k3 + 2] = stage_centroid_values[k];
     2210                xmom_vertex_values[k3] = xmom_centroid_values[k];
     2211                xmom_vertex_values[k3 + 1] = xmom_centroid_values[k];
     2212                xmom_vertex_values[k3 + 2] = xmom_centroid_values[k];
     2213                ymom_vertex_values[k3] = ymom_centroid_values[k];
     2214                ymom_vertex_values[k3 + 1] = ymom_centroid_values[k];
     2215                ymom_vertex_values[k3 + 2] = ymom_centroid_values[k];
     2216
     2217                continue;
     2218            }
     2219
     2220            // Calculate heights of neighbouring cells
     2221            hc = stage_centroid_values[k] - elevation_centroid_values[k];
     2222            h0 = stage_centroid_values[k0] - elevation_centroid_values[k0];
     2223            h1 = stage_centroid_values[k1] - elevation_centroid_values[k1];
     2224            h2 = stage_centroid_values[k2] - elevation_centroid_values[k2];
     2225            hmin = min(min(h0, min(h1, h2)), hc);
     2226            //hfactor = hc/(hc + 1.0);
     2227
     2228            hfactor = 0.0;
     2229            if (hmin > 0.001) {
     2230                hfactor = (hmin - 0.001) / (hmin + 0.004);
     2231            }
     2232
     2233            if (optimise_dry_cells) {
     2234                // Check if linear reconstruction is necessary for triangle k
     2235                // This check will exclude dry cells.
     2236
     2237                hmax = max(h0, max(h1, h2));
     2238                if (hmax < epsilon) {
     2239                    continue;
     2240                }
     2241            }
     2242
     2243            //-----------------------------------
     2244            // stage
     2245            //-----------------------------------
     2246
     2247            // Calculate the difference between vertex 0 of the auxiliary
     2248            // triangle and the centroid of triangle k
     2249            dq0 = stage_centroid_values[k0] - stage_centroid_values[k];
     2250
     2251            // Calculate differentials between the vertices
     2252            // of the auxiliary triangle (centroids of neighbouring triangles)
     2253            dq1 = stage_centroid_values[k1] - stage_centroid_values[k0];
     2254            dq2 = stage_centroid_values[k2] - stage_centroid_values[k0];
     2255
     2256            inv_area2 = 1.0 / area2;
     2257            // Calculate the gradient of stage on the auxiliary triangle
     2258            a = dy2 * dq1 - dy1*dq2;
     2259            a *= inv_area2;
     2260            b = dx1 * dq2 - dx2*dq1;
     2261            b *= inv_area2;
     2262
     2263            // Calculate provisional jumps in stage from the centroid
     2264            // of triangle k to its vertices, to be limited
     2265            dqv[0] = a * dxv0 + b*dyv0;
     2266            dqv[1] = a * dxv1 + b*dyv1;
     2267            dqv[2] = a * dxv2 + b*dyv2;
     2268
     2269            // Now we want to find min and max of the centroid and the
     2270            // vertices of the auxiliary triangle and compute jumps
     2271            // from the centroid to the min and max
     2272            find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
     2273
     2274            // Playing with dry wet interface
     2275            //hmin = qmin;
     2276            //beta_tmp = beta_w_dry;
     2277            //if (hmin>minimum_allowed_height)
     2278            beta_tmp = beta_w_dry + (beta_w - beta_w_dry) * hfactor;
     2279
     2280            //printf("min_alled_height = %f\n",minimum_allowed_height);
     2281            //printf("hmin = %f\n",hmin);
     2282            //printf("beta_w = %f\n",beta_w);
     2283            //printf("beta_tmp = %f\n",beta_tmp);
     2284            // Limit the gradient
     2285            limit_gradient(dqv, qmin, qmax, beta_tmp);
     2286
     2287            //for (i=0;i<3;i++)
     2288            stage_vertex_values[k3 + 0] = stage_centroid_values[k] + dqv[0];
     2289            stage_vertex_values[k3 + 1] = stage_centroid_values[k] + dqv[1];
     2290            stage_vertex_values[k3 + 2] = stage_centroid_values[k] + dqv[2];
     2291
     2292
     2293            //-----------------------------------
     2294            // xmomentum
     2295            //-----------------------------------
     2296
     2297            // Calculate the difference between vertex 0 of the auxiliary
     2298            // triangle and the centroid of triangle k
     2299            dq0 = xmom_centroid_values[k0] - xmom_centroid_values[k];
     2300
     2301            // Calculate differentials between the vertices
     2302            // of the auxiliary triangle
     2303            dq1 = xmom_centroid_values[k1] - xmom_centroid_values[k0];
     2304            dq2 = xmom_centroid_values[k2] - xmom_centroid_values[k0];
     2305
     2306            // Calculate the gradient of xmom on the auxiliary triangle
     2307            a = dy2 * dq1 - dy1*dq2;
     2308            a *= inv_area2;
     2309            b = dx1 * dq2 - dx2*dq1;
     2310            b *= inv_area2;
     2311
     2312            // Calculate provisional jumps in stage from the centroid
     2313            // of triangle k to its vertices, to be limited
     2314            dqv[0] = a * dxv0 + b*dyv0;
     2315            dqv[1] = a * dxv1 + b*dyv1;
     2316            dqv[2] = a * dxv2 + b*dyv2;
     2317
     2318            // Now we want to find min and max of the centroid and the
     2319            // vertices of the auxiliary triangle and compute jumps
     2320            // from the centroid to the min and max
     2321            find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
     2322            //beta_tmp = beta_uh;
     2323            //if (hmin<minimum_allowed_height)
     2324            //beta_tmp = beta_uh_dry;
     2325            beta_tmp = beta_uh_dry + (beta_uh - beta_uh_dry) * hfactor;
     2326
     2327            // Limit the gradient
     2328            limit_gradient(dqv, qmin, qmax, beta_tmp);
     2329
     2330            for (i = 0; i < 3; i++) {
     2331                xmom_vertex_values[k3 + i] = xmom_centroid_values[k] + dqv[i];
     2332            }
     2333
     2334            //-----------------------------------
     2335            // ymomentum
     2336            //-----------------------------------
     2337
     2338            // Calculate the difference between vertex 0 of the auxiliary
     2339            // triangle and the centroid of triangle k
     2340            dq0 = ymom_centroid_values[k0] - ymom_centroid_values[k];
     2341
     2342            // Calculate differentials between the vertices
     2343            // of the auxiliary triangle
     2344            dq1 = ymom_centroid_values[k1] - ymom_centroid_values[k0];
     2345            dq2 = ymom_centroid_values[k2] - ymom_centroid_values[k0];
     2346
     2347            // Calculate the gradient of xmom on the auxiliary triangle
     2348            a = dy2 * dq1 - dy1*dq2;
     2349            a *= inv_area2;
     2350            b = dx1 * dq2 - dx2*dq1;
     2351            b *= inv_area2;
     2352
     2353            // Calculate provisional jumps in stage from the centroid
     2354            // of triangle k to its vertices, to be limited
     2355            dqv[0] = a * dxv0 + b*dyv0;
     2356            dqv[1] = a * dxv1 + b*dyv1;
     2357            dqv[2] = a * dxv2 + b*dyv2;
     2358
     2359            // Now we want to find min and max of the centroid and the
     2360            // vertices of the auxiliary triangle and compute jumps
     2361            // from the centroid to the min and max
     2362            find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
     2363
     2364            //beta_tmp = beta_vh;
     2365            //
     2366            //if (hmin<minimum_allowed_height)
     2367            //beta_tmp = beta_vh_dry;
     2368            beta_tmp = beta_vh_dry + (beta_vh - beta_vh_dry) * hfactor;
     2369
     2370            // Limit the gradient
     2371            limit_gradient(dqv, qmin, qmax, beta_tmp);
     2372
     2373            for (i = 0; i < 3; i++) {
     2374                ymom_vertex_values[k3 + i] = ymom_centroid_values[k] + dqv[i];
     2375            }
     2376        }// End number_of_boundaries <=1
     2377        else {
     2378
     2379            //==============================================
     2380            // Number of boundaries == 2
     2381            //==============================================
     2382
     2383            // One internal neighbour and gradient is in direction of the neighbour's centroid
     2384
     2385            // Find the only internal neighbour (k1?)
     2386            for (k2 = k3; k2 < k3 + 3; k2++) {
     2387                // Find internal neighbour of triangle k
     2388                // k2 indexes the edges of triangle k
     2389
     2390                if (surrogate_neighbours[k2] != k) {
     2391                    break;
     2392                }
     2393            }
     2394
     2395            if ((k2 == k3 + 3)) {
     2396                // If we didn't find an internal neighbour
     2397                report_python_error(AT, "Internal neighbour not found");
     2398                return -1;
     2399            }
     2400
     2401            k1 = surrogate_neighbours[k2];
     2402
     2403            // The coordinates of the triangle are already (x,y).
     2404            // Get centroid of the neighbour (x1,y1)
     2405            coord_index = 2 * k1;
     2406            x1 = centroid_coordinates[coord_index];
     2407            y1 = centroid_coordinates[coord_index + 1];
     2408
     2409            // Compute x- and y- distances between the centroid of
     2410            // triangle k and that of its neighbour
     2411            dx1 = x1 - x;
     2412            dy1 = y1 - y;
     2413
     2414            // Set area2 as the square of the distance
     2415            area2 = dx1 * dx1 + dy1*dy1;
     2416
     2417            // Set dx2=(x1-x0)/((x1-x0)^2+(y1-y0)^2)
     2418            // and dy2=(y1-y0)/((x1-x0)^2+(y1-y0)^2) which
     2419            // respectively correspond to the x- and y- gradients
     2420            // of the conserved quantities
     2421            dx2 = 1.0 / area2;
     2422            dy2 = dx2*dy1;
     2423            dx2 *= dx1;
     2424
     2425
     2426            //-----------------------------------
     2427            // stage
     2428            //-----------------------------------
     2429
     2430            // Compute differentials
     2431            dq1 = stage_centroid_values[k1] - stage_centroid_values[k];
     2432
     2433            // Calculate the gradient between the centroid of triangle k
     2434            // and that of its neighbour
     2435            a = dq1*dx2;
     2436            b = dq1*dy2;
     2437
     2438            // Calculate provisional vertex jumps, to be limited
     2439            dqv[0] = a * dxv0 + b*dyv0;
     2440            dqv[1] = a * dxv1 + b*dyv1;
     2441            dqv[2] = a * dxv2 + b*dyv2;
     2442
     2443            // Now limit the jumps
     2444            if (dq1 >= 0.0) {
     2445                qmin = 0.0;
     2446                qmax = dq1;
     2447            } else {
     2448                qmin = dq1;
     2449                qmax = 0.0;
     2450            }
     2451
     2452            // Limit the gradient
     2453            limit_gradient(dqv, qmin, qmax, beta_w);
     2454
     2455            //for (i=0; i < 3; i++)
     2456            //{
     2457            stage_vertex_values[k3] = stage_centroid_values[k] + dqv[0];
     2458            stage_vertex_values[k3 + 1] = stage_centroid_values[k] + dqv[1];
     2459            stage_vertex_values[k3 + 2] = stage_centroid_values[k] + dqv[2];
     2460            //}
     2461
     2462            //-----------------------------------
     2463            // xmomentum
     2464            //-----------------------------------
     2465
     2466            // Compute differentials
     2467            dq1 = xmom_centroid_values[k1] - xmom_centroid_values[k];
     2468
     2469            // Calculate the gradient between the centroid of triangle k
     2470            // and that of its neighbour
     2471            a = dq1*dx2;
     2472            b = dq1*dy2;
     2473
     2474            // Calculate provisional vertex jumps, to be limited
     2475            dqv[0] = a * dxv0 + b*dyv0;
     2476            dqv[1] = a * dxv1 + b*dyv1;
     2477            dqv[2] = a * dxv2 + b*dyv2;
     2478
     2479            // Now limit the jumps
     2480            if (dq1 >= 0.0) {
     2481                qmin = 0.0;
     2482                qmax = dq1;
     2483            } else {
     2484                qmin = dq1;
     2485                qmax = 0.0;
     2486            }
     2487
     2488            // Limit the gradient
     2489            limit_gradient(dqv, qmin, qmax, beta_w);
     2490
     2491            //for (i=0;i<3;i++)
     2492            //xmom_vertex_values[k3] = xmom_centroid_values[k] + dqv[0];
     2493            //xmom_vertex_values[k3 + 1] = xmom_centroid_values[k] + dqv[1];
     2494            //xmom_vertex_values[k3 + 2] = xmom_centroid_values[k] + dqv[2];
     2495
     2496            for (i = 0; i < 3; i++) {
     2497                xmom_vertex_values[k3 + i] = xmom_centroid_values[k] + dqv[i];
     2498            }
     2499
     2500            //-----------------------------------
     2501            // ymomentum
     2502            //-----------------------------------
     2503
     2504            // Compute differentials
     2505            dq1 = ymom_centroid_values[k1] - ymom_centroid_values[k];
     2506
     2507            // Calculate the gradient between the centroid of triangle k
     2508            // and that of its neighbour
     2509            a = dq1*dx2;
     2510            b = dq1*dy2;
     2511
     2512            // Calculate provisional vertex jumps, to be limited
     2513            dqv[0] = a * dxv0 + b*dyv0;
     2514            dqv[1] = a * dxv1 + b*dyv1;
     2515            dqv[2] = a * dxv2 + b*dyv2;
     2516
     2517            // Now limit the jumps
     2518            if (dq1 >= 0.0) {
     2519                qmin = 0.0;
     2520                qmax = dq1;
     2521            }
     2522            else {
     2523                qmin = dq1;
     2524                qmax = 0.0;
     2525            }
     2526
     2527            // Limit the gradient
     2528            limit_gradient(dqv, qmin, qmax, beta_w);
     2529
     2530            //for (i=0;i<3;i++)
     2531            //ymom_vertex_values[k3] = ymom_centroid_values[k] + dqv[0];
     2532            //ymom_vertex_values[k3 + 1] = ymom_centroid_values[k] + dqv[1];
     2533            //ymom_vertex_values[k3 + 2] = ymom_centroid_values[k] + dqv[2];
     2534
     2535            for (i = 0; i < 3; i++) {
     2536                ymom_vertex_values[k3 + i] = ymom_centroid_values[k] + dqv[i];
     2537            }
     2538            //ymom_vertex_values[k3] = ymom_centroid_values[k] + dqv[0];
     2539            //ymom_vertex_values[k3 + 1] = ymom_centroid_values[k] + dqv[1];
     2540            //ymom_vertex_values[k3 + 2] = ymom_centroid_values[k] + dqv[2];
     2541        } // else [number_of_boundaries==2]
     2542    } // for k=0 to number_of_elements-1
     2543
     2544    if (extrapolate_velocity_second_order == 1) {
     2545        // Convert back from velocity to momentum
     2546        for (k = 0; k < number_of_elements; k++) {
     2547            k3 = 3 * k;
     2548            //dv0 = max(stage_vertex_values[k3]-elevation_vertex_values[k3],minimum_allowed_height);
     2549            //dv1 = max(stage_vertex_values[k3+1]-elevation_vertex_values[k3+1],minimum_allowed_height);
     2550            //dv2 = max(stage_vertex_values[k3+2]-elevation_vertex_values[k3+2],minimum_allowed_height);
     2551            dv0 = max(stage_vertex_values[k3] - elevation_vertex_values[k3], 0.);
     2552            dv1 = max(stage_vertex_values[k3 + 1] - elevation_vertex_values[k3 + 1], 0.);
     2553            dv2 = max(stage_vertex_values[k3 + 2] - elevation_vertex_values[k3 + 2], 0.);
     2554
     2555            //Correct centroid and vertex values
     2556            xmom_centroid_values[k] = xmom_centroid_store[k];
     2557            xmom_vertex_values[k3] = xmom_vertex_values[k3] * dv0;
     2558            xmom_vertex_values[k3 + 1] = xmom_vertex_values[k3 + 1] * dv1;
     2559            xmom_vertex_values[k3 + 2] = xmom_vertex_values[k3 + 2] * dv2;
     2560
     2561            ymom_centroid_values[k] = ymom_centroid_store[k];
     2562            ymom_vertex_values[k3] = ymom_vertex_values[k3] * dv0;
     2563            ymom_vertex_values[k3 + 1] = ymom_vertex_values[k3 + 1] * dv1;
     2564            ymom_vertex_values[k3 + 2] = ymom_vertex_values[k3 + 2] * dv2;
     2565
     2566        }
     2567    }
     2568
     2569    return 0;
     2570}
     2571
     2572
     2573
     2574// Computational routine
     2575int _extrapolate_second_order_sw(struct domain *D) {
     2576
     2577
     2578  // Domain Variables
     2579    int number_of_elements;
     2580    double epsilon;
     2581    double minimum_allowed_height;
     2582    double beta_w;
     2583    double beta_w_dry;
     2584    double beta_uh;
     2585    double beta_uh_dry;
     2586    double beta_vh;
     2587    double beta_vh_dry;
     2588    long* surrogate_neighbours;
     2589    long* number_of_boundaries;
     2590    double* centroid_coordinates;
     2591    double* stage_centroid_values;
     2592    double* xmom_centroid_values;
     2593    double* ymom_centroid_values;
     2594    double* bed_centroid_values;
     2595    double* edge_coordinates;
     2596    double* vertex_coordinates;
     2597    double* stage_edge_values;
     2598    double* xmom_edge_values;
     2599    double* ymom_edge_values;
     2600    double* bed_edge_values;
     2601    double* stage_vertex_values;
     2602    double* xmom_vertex_values;
     2603    double* ymom_vertex_values;
     2604    double* bed_vertex_values;
     2605    int optimise_dry_cells;
     2606    int extrapolate_velocity_second_order;
     2607
     2608    // Local variables
     2609    double a, b; // Gradient vector used to calculate edge values from centroids
     2610    int k, k0, k1, k2, k3, k6, coord_index, i;
     2611    double x, y, x0, y0, x1, y1, x2, y2, xv0, yv0, xv1, yv1, xv2, yv2; // Vertices of the auxiliary triangle
     2612    double dx1, dx2, dy1, dy2, dxv0, dxv1, dxv2, dyv0, dyv1, dyv2, dq0, dq1, dq2, area2, inv_area2;
     2613    double dqv[3], qmin, qmax, hmin, hmax;
     2614    double hc, h0, h1, h2, beta_tmp, hfactor;
     2615    //double dk, dv0, dv1, dv2, de[3], demin, dcmax, r0scale;
     2616    double dk, dv0, dv1, dv2;
     2617
     2618    double *xmom_centroid_store, *ymom_centroid_store, *stage_centroid_store;
     2619
     2620
     2621    // Associate memory location of Domain varialbe with local aliases
     2622    number_of_elements     = D->number_of_elements;
     2623    epsilon                = D->epsilon;
     2624    minimum_allowed_height = D->minimum_allowed_height;
     2625    beta_w                 = D->beta_w;
     2626    beta_w_dry             = D->beta_w_dry;
     2627    beta_uh                = D->beta_uh;
     2628    beta_uh_dry            = D->beta_uh_dry;
     2629    beta_vh                = D->beta_vh;
     2630    beta_vh_dry            = D->beta_vh_dry;
     2631    optimise_dry_cells     = D->optimise_dry_cells;
     2632    extrapolate_velocity_second_order = D->extrapolate_velocity_second_order;
     2633
     2634    surrogate_neighbours      = D->surrogate_neighbours;
     2635    number_of_boundaries      = D->number_of_boundaries;
     2636    centroid_coordinates      = D->centroid_coordinates;
     2637    stage_centroid_values     = D->stage_centroid_values;
     2638    xmom_centroid_values      = D->xmom_centroid_values;
     2639    ymom_centroid_values      = D->ymom_centroid_values;
     2640    bed_centroid_values       = D->bed_centroid_values;
     2641    edge_coordinates          = D->edge_coordinates;
     2642    vertex_coordinates        = D->vertex_coordinates;
     2643    stage_edge_values         = D->stage_edge_values;
     2644    xmom_edge_values          = D->xmom_edge_values;
     2645    ymom_edge_values          = D->ymom_edge_values;
     2646    bed_edge_values           = D->bed_edge_values;
     2647    stage_vertex_values       = D->stage_vertex_values;
     2648    xmom_vertex_values        = D->xmom_vertex_values;
     2649    ymom_vertex_values        = D->ymom_vertex_values;
     2650    bed_vertex_values         = D->bed_vertex_values;
     2651
     2652
     2653
     2654
     2655/*
    20622656int _extrapolate_second_order_sw(int number_of_elements,
    20632657        double epsilon,
     
    20942688    double hc, h0, h1, h2, beta_tmp, hfactor;
    20952689    double xmom_centroid_store[number_of_elements], ymom_centroid_store[number_of_elements], dk, dv0, dv1, dv2;
     2690*/
     2691
     2692   // Use malloc to avoid putting these variables on the stack, which can cause
     2693   // segfaults in large model runs
     2694    xmom_centroid_store = malloc(number_of_elements*sizeof(double));
     2695    ymom_centroid_store = malloc(number_of_elements*sizeof(double));
     2696    stage_centroid_store = malloc(number_of_elements*sizeof(double));
    20962697
    20972698    if (extrapolate_velocity_second_order == 1) {
     
    21002701        for (k = 0; k < number_of_elements; k++) {
    21012702
    2102             dk = max(stage_centroid_values[k] - elevation_centroid_values[k], minimum_allowed_height);
     2703            dk = max(stage_centroid_values[k] - bed_centroid_values[k], minimum_allowed_height);
    21032704            xmom_centroid_store[k] = xmom_centroid_values[k];
    21042705            xmom_centroid_values[k] = xmom_centroid_values[k] / dk;
     
    22192820
    22202821            // Calculate heights of neighbouring cells
    2221             hc = stage_centroid_values[k] - elevation_centroid_values[k];
    2222             h0 = stage_centroid_values[k0] - elevation_centroid_values[k0];
    2223             h1 = stage_centroid_values[k1] - elevation_centroid_values[k1];
    2224             h2 = stage_centroid_values[k2] - elevation_centroid_values[k2];
     2822            hc = stage_centroid_values[k] - bed_centroid_values[k];
     2823            h0 = stage_centroid_values[k0] - bed_centroid_values[k0];
     2824            h1 = stage_centroid_values[k1] - bed_centroid_values[k1];
     2825            h2 = stage_centroid_values[k2] - bed_centroid_values[k2];
    22252826            hmin = min(min(h0, min(h1, h2)), hc);
    22262827            //hfactor = hc/(hc + 1.0);
     
    25463147        for (k = 0; k < number_of_elements; k++) {
    25473148            k3 = 3 * k;
    2548             //dv0 = max(stage_vertex_values[k3]-elevation_vertex_values[k3],minimum_allowed_height);
    2549             //dv1 = max(stage_vertex_values[k3+1]-elevation_vertex_values[k3+1],minimum_allowed_height);
    2550             //dv2 = max(stage_vertex_values[k3+2]-elevation_vertex_values[k3+2],minimum_allowed_height);
    2551             dv0 = max(stage_vertex_values[k3] - elevation_vertex_values[k3], 0.);
    2552             dv1 = max(stage_vertex_values[k3 + 1] - elevation_vertex_values[k3 + 1], 0.);
    2553             dv2 = max(stage_vertex_values[k3 + 2] - elevation_vertex_values[k3 + 2], 0.);
     3149            //dv0 = max(stage_vertex_values[k3]-bed_vertex_values[k3],minimum_allowed_height);
     3150            //dv1 = max(stage_vertex_values[k3+1]-bed_vertex_values[k3+1],minimum_allowed_height);
     3151            //dv2 = max(stage_vertex_values[k3+2]-bed_vertex_values[k3+2],minimum_allowed_height);
     3152            dv0 = max(stage_vertex_values[k3] - bed_vertex_values[k3], 0.);
     3153            dv1 = max(stage_vertex_values[k3 + 1] - bed_vertex_values[k3 + 1], 0.);
     3154            dv2 = max(stage_vertex_values[k3 + 2] - bed_vertex_values[k3 + 2], 0.);
    25543155
    25553156            //Correct centroid and vertex values
     
    25663167        }
    25673168    }
     3169   
     3170    free(xmom_centroid_store);
     3171    free(ymom_centroid_store);
     3172    free(stage_centroid_store);
     3173
    25683174
    25693175    return 0;
    25703176}
    25713177
    2572 PyObject *extrapolate_second_order_sw(PyObject *self, PyObject *args) {
     3178
     3179// Computational routine
     3180int _extrapolate_second_order_edge_sw(struct domain *D) {
     3181
     3182
     3183  // Domain Variables
     3184    int number_of_elements;
     3185    double epsilon;
     3186    double minimum_allowed_height;
     3187    double beta_w;
     3188    double beta_w_dry;
     3189    double beta_uh;
     3190    double beta_uh_dry;
     3191    double beta_vh;
     3192    double beta_vh_dry;
     3193    long* surrogate_neighbours;
     3194    long* number_of_boundaries;
     3195    double* centroid_coordinates;
     3196    double* stage_centroid_values;
     3197    double* xmom_centroid_values;
     3198    double* ymom_centroid_values;
     3199    double* bed_centroid_values;
     3200    double* edge_coordinates;
     3201    double* stage_edge_values;
     3202    double* xmom_edge_values;
     3203    double* ymom_edge_values;
     3204    double* bed_edge_values;
     3205    double* stage_vertex_values;
     3206    double* xmom_vertex_values;
     3207    double* ymom_vertex_values;
     3208    double* bed_vertex_values;
     3209    int optimise_dry_cells;
     3210    int extrapolate_velocity_second_order;
     3211
     3212    // Local variables
     3213    double a, b; // Gradient vector used to calculate edge values from centroids
     3214    int k, k0, k1, k2, k3, k6, coord_index, i;
     3215    double x, y, x0, y0, x1, y1, x2, y2, xv0, yv0, xv1, yv1, xv2, yv2; // Vertices of the auxiliary triangle
     3216    double dx1, dx2, dy1, dy2, dxv0, dxv1, dxv2, dyv0, dyv1, dyv2, dq0, dq1, dq2, area2, inv_area2;
     3217    double dqv[3], qmin, qmax, hmin, hmax;
     3218    double hc, h0, h1, h2, beta_tmp, hfactor;
     3219    //double dk, dv0, dv1, dv2, de[3], demin, dcmax, r0scale;
     3220    double dk, de[3];
     3221
     3222    double *xmom_centroid_store, *ymom_centroid_store, *stage_centroid_store;
     3223
     3224
     3225    // Associate memory location of Domain varialbe with local aliases
     3226    number_of_elements     = D->number_of_elements;
     3227    epsilon                = D->epsilon;
     3228    minimum_allowed_height = D->minimum_allowed_height;
     3229    beta_w                 = D->beta_w;
     3230    beta_w_dry             = D->beta_w_dry;
     3231    beta_uh                = D->beta_uh;
     3232    beta_uh_dry            = D->beta_uh_dry;
     3233    beta_vh                = D->beta_vh;
     3234    beta_vh_dry            = D->beta_vh_dry;
     3235    optimise_dry_cells     = D->optimise_dry_cells;
     3236    extrapolate_velocity_second_order = D->extrapolate_velocity_second_order;
     3237
     3238    surrogate_neighbours      = D->surrogate_neighbours;
     3239    number_of_boundaries      = D->number_of_boundaries;
     3240    centroid_coordinates      = D->centroid_coordinates;
     3241    stage_centroid_values     = D->stage_centroid_values;
     3242    xmom_centroid_values      = D->xmom_centroid_values;
     3243    ymom_centroid_values      = D->ymom_centroid_values;
     3244    bed_centroid_values       = D->bed_centroid_values;
     3245    edge_coordinates          = D->edge_coordinates;
     3246    stage_edge_values         = D->stage_edge_values;
     3247    xmom_edge_values          = D->xmom_edge_values;
     3248    ymom_edge_values          = D->ymom_edge_values;
     3249    bed_edge_values           = D->bed_edge_values;
     3250    stage_vertex_values       = D->stage_vertex_values;
     3251    xmom_vertex_values        = D->xmom_vertex_values;
     3252    ymom_vertex_values        = D->ymom_vertex_values;
     3253    bed_vertex_values         = D->bed_vertex_values;
     3254
     3255
     3256
     3257  // Use malloc to avoid putting these variables on the stack, which can cause
     3258  // segfaults in large model runs
     3259  xmom_centroid_store = malloc(number_of_elements*sizeof(double));
     3260  ymom_centroid_store = malloc(number_of_elements*sizeof(double));
     3261  stage_centroid_store = malloc(number_of_elements*sizeof(double));
     3262
     3263  if(extrapolate_velocity_second_order==1){
     3264      // Replace momentum centroid with velocity centroid to allow velocity
     3265      // extrapolation This will be changed back at the end of the routine
     3266      for (k=0; k<number_of_elements; k++){
     3267
     3268          dk = max(stage_centroid_values[k]-bed_centroid_values[k],minimum_allowed_height);
     3269          xmom_centroid_store[k] = xmom_centroid_values[k];
     3270          xmom_centroid_values[k] = xmom_centroid_values[k]/dk;
     3271
     3272          ymom_centroid_store[k] = ymom_centroid_values[k];
     3273          ymom_centroid_values[k] = ymom_centroid_values[k]/dk;
     3274
     3275      }
     3276  }
     3277
     3278  // Begin extrapolation routine
     3279  for (k = 0; k < number_of_elements; k++)
     3280  {
     3281    k3=k*3;
     3282    k6=k*6;
     3283
     3284    if (number_of_boundaries[k]==3)
     3285    //if (0==0)
     3286    {
     3287      // No neighbours, set gradient on the triangle to zero
     3288
     3289      stage_edge_values[k3]   = stage_centroid_values[k];
     3290      stage_edge_values[k3+1] = stage_centroid_values[k];
     3291      stage_edge_values[k3+2] = stage_centroid_values[k];
     3292      xmom_edge_values[k3]    = xmom_centroid_values[k];
     3293      xmom_edge_values[k3+1]  = xmom_centroid_values[k];
     3294      xmom_edge_values[k3+2]  = xmom_centroid_values[k];
     3295      ymom_edge_values[k3]    = ymom_centroid_values[k];
     3296      ymom_edge_values[k3+1]  = ymom_centroid_values[k];
     3297      ymom_edge_values[k3+2]  = ymom_centroid_values[k];
     3298
     3299      continue;
     3300    }
     3301    else
     3302    {
     3303      // Triangle k has one or more neighbours.
     3304      // Get centroid and edge coordinates of the triangle
     3305
     3306      // Get the edge coordinates
     3307      xv0 = edge_coordinates[k6];
     3308      yv0 = edge_coordinates[k6+1];
     3309      xv1 = edge_coordinates[k6+2];
     3310      yv1 = edge_coordinates[k6+3];
     3311      xv2 = edge_coordinates[k6+4];
     3312      yv2 = edge_coordinates[k6+5];
     3313
     3314      // Get the centroid coordinates
     3315      coord_index = 2*k;
     3316      x = centroid_coordinates[coord_index];
     3317      y = centroid_coordinates[coord_index+1];
     3318
     3319      // Store x- and y- differentials for the edges of
     3320      // triangle k relative to the centroid
     3321      dxv0 = xv0 - x;
     3322      dxv1 = xv1 - x;
     3323      dxv2 = xv2 - x;
     3324      dyv0 = yv0 - y;
     3325      dyv1 = yv1 - y;
     3326      dyv2 = yv2 - y;
     3327      // Compute the minimum distance from the centroid to an edge
     3328      //demin=min(dxv0*dxv0 +dyv0*dyv0, min(dxv1*dxv1+dyv1*dyv1, dxv2*dxv2+dyv2*dyv2));
     3329      //demin=sqrt(demin);
     3330    }
     3331
     3332
     3333
     3334    if (number_of_boundaries[k]<=1)
     3335    {
     3336      //==============================================
     3337      // Number of boundaries <= 1
     3338      //==============================================
     3339
     3340
     3341      // If no boundaries, auxiliary triangle is formed
     3342      // from the centroids of the three neighbours
     3343      // If one boundary, auxiliary triangle is formed
     3344      // from this centroid and its two neighbours
     3345
     3346      k0 = surrogate_neighbours[k3];
     3347      k1 = surrogate_neighbours[k3 + 1];
     3348      k2 = surrogate_neighbours[k3 + 2];
     3349
     3350      // Test to see whether we accept the surrogate neighbours
     3351      // Note that if ki is replaced with k in more than 1 neighbour, then the
     3352      // triangle area will be zero, and a first order extrapolation will be
     3353      // used
     3354      if(stage_centroid_values[k2]<=bed_centroid_values[k2]){
     3355          k2 = k ;
     3356      }
     3357      if(stage_centroid_values[k0]<=bed_centroid_values[k0]){
     3358          k0 = k ;
     3359      }
     3360      if(stage_centroid_values[k1]<=bed_centroid_values[k1]){
     3361          k1 = k ;
     3362      }
     3363      // Alternative approach (BRUTAL) -- if the max neighbour bed elevation is greater
     3364      // than the min neighbour stage, then we use first order extrapolation
     3365      //bedmax = max(bed_centroid_values[k],
     3366      //             max(bed_centroid_values[k0],
     3367      //                 max(bed_centroid_values[k1], bed_centroid_values[k2])));
     3368      //stagemin = min(stage_centroid_values[k],
     3369      //             min(stage_centroid_values[k0],
     3370      //                 min(stage_centroid_values[k1], stage_centroid_values[k2])));
     3371      //
     3372      //if(stagemin < bedmax){
     3373      //   // This will cause first order extrapolation
     3374      //   k2 = k;
     3375      //   k0 = k;
     3376      //   k1 = k;
     3377      //}
     3378
     3379      // Get the auxiliary triangle's vertex coordinates
     3380      // (really the centroids of neighbouring triangles)
     3381      coord_index = 2*k0;
     3382      x0 = centroid_coordinates[coord_index];
     3383      y0 = centroid_coordinates[coord_index+1];
     3384
     3385      coord_index = 2*k1;
     3386      x1 = centroid_coordinates[coord_index];
     3387      y1 = centroid_coordinates[coord_index+1];
     3388
     3389      coord_index = 2*k2;
     3390      x2 = centroid_coordinates[coord_index];
     3391      y2 = centroid_coordinates[coord_index+1];
     3392
     3393      // compute the maximum distance from the centroid to a neighbouring
     3394      // centroid
     3395      //dcmax=max( (x0-x)*(x0-x) + (y0-y)*(y0-y),
     3396      //           max((x1-x)*(x1-x) + (y1-y)*(y1-y),
     3397      //               (x2-x)*(x2-x) + (y2-y)*(y2-y)));
     3398      //dcmax=sqrt(dcmax);
     3399      //// Ratio of centroid to edge distance -- useful in attempting to adapt limiter
     3400      //if(dcmax>0.){
     3401      //    r0scale=demin/dcmax;
     3402      //    //printf("%f \n", r0scale);
     3403      //}else{
     3404      //    r0scale=0.5;
     3405      //}
     3406
     3407      // Store x- and y- differentials for the vertices
     3408      // of the auxiliary triangle
     3409      dx1 = x1 - x0;
     3410      dx2 = x2 - x0;
     3411      dy1 = y1 - y0;
     3412      dy2 = y2 - y0;
     3413
     3414      // Calculate 2*area of the auxiliary triangle
     3415      // The triangle is guaranteed to be counter-clockwise
     3416      area2 = dy2*dx1 - dy1*dx2;
     3417
     3418      // If the mesh is 'weird' near the boundary,
     3419      // the triangle might be flat or clockwise
     3420      // Default to zero gradient
     3421      if (area2 <= 0)
     3422      {
     3423          //printf("Error negative triangle area \n");
     3424          //report_python_error(AT, "Negative triangle area");
     3425          //return -1;
     3426
     3427          stage_edge_values[k3]   = stage_centroid_values[k];
     3428          stage_edge_values[k3+1] = stage_centroid_values[k];
     3429          stage_edge_values[k3+2] = stage_centroid_values[k];
     3430          xmom_edge_values[k3]    = xmom_centroid_values[k];
     3431          xmom_edge_values[k3+1]  = xmom_centroid_values[k];
     3432          xmom_edge_values[k3+2]  = xmom_centroid_values[k];
     3433          ymom_edge_values[k3]    = ymom_centroid_values[k];
     3434          ymom_edge_values[k3+1]  = ymom_centroid_values[k];
     3435          ymom_edge_values[k3+2]  = ymom_centroid_values[k];
     3436
     3437          continue;
     3438      }
     3439
     3440      // Calculate heights of neighbouring cells
     3441      hc = stage_centroid_values[k]  - bed_centroid_values[k];
     3442      h0 = stage_centroid_values[k0] - bed_centroid_values[k0];
     3443      h1 = stage_centroid_values[k1] - bed_centroid_values[k1];
     3444      h2 = stage_centroid_values[k2] - bed_centroid_values[k2];
     3445      hmin = min(min(h0, min(h1, h2)), hc);
     3446      //hmin = min(h0, min(h1, h2));
     3447      //hmin = max(hmin, 0.0);
     3448      //hfactor = hc/(hc + 1.0);
     3449
     3450      hfactor = 0.0;
     3451      //if (hmin > 0.001)
     3452      if (hmin > 0.)
     3453      //if (hc>0.0)
     3454      {
     3455        hfactor = 1.0 ;//hmin/(hmin + 0.004);
     3456        //hfactor=hmin/(hmin + 0.004);
     3457      }
     3458
     3459      if (optimise_dry_cells)
     3460      {
     3461        // Check if linear reconstruction is necessary for triangle k
     3462        // This check will exclude dry cells.
     3463
     3464        //hmax = max(h0, max(h1, max(h2, hc)));
     3465        hmax = max(h0, max(h1, h2));
     3466        if (hmax < epsilon)
     3467        {
     3468            continue;
     3469        }
     3470      }
     3471
     3472      //-----------------------------------
     3473      // stage
     3474      //-----------------------------------
     3475
     3476      // Calculate the difference between vertex 0 of the auxiliary
     3477      // triangle and the centroid of triangle k
     3478      dq0 = stage_centroid_values[k0] - stage_centroid_values[k];
     3479
     3480      // Calculate differentials between the vertices
     3481      // of the auxiliary triangle (centroids of neighbouring triangles)
     3482      dq1 = stage_centroid_values[k1] - stage_centroid_values[k0];
     3483      dq2 = stage_centroid_values[k2] - stage_centroid_values[k0];
     3484
     3485      inv_area2 = 1.0/area2;
     3486      // Calculate the gradient of stage on the auxiliary triangle
     3487      a = dy2*dq1 - dy1*dq2;
     3488      a *= inv_area2;
     3489      b = dx1*dq2 - dx2*dq1;
     3490      b *= inv_area2;
     3491
     3492      // Calculate provisional jumps in stage from the centroid
     3493      // of triangle k to its vertices, to be limited
     3494      dqv[0] = a*dxv0 + b*dyv0;
     3495      dqv[1] = a*dxv1 + b*dyv1;
     3496      dqv[2] = a*dxv2 + b*dyv2;
     3497
     3498      // Now we want to find min and max of the centroid and the
     3499      // vertices of the auxiliary triangle and compute jumps
     3500      // from the centroid to the min and max
     3501      find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
     3502
     3503      beta_tmp = beta_w_dry + (beta_w - beta_w_dry) * hfactor;
     3504
     3505      // Limit the gradient
     3506      limit_gradient(dqv, qmin, qmax, beta_tmp);
     3507      //limit_gradient2(dqv, qmin, qmax, beta_tmp,r0scale);
     3508
     3509      //for (i=0;i<3;i++)
     3510      stage_edge_values[k3+0] = stage_centroid_values[k] + dqv[0];
     3511      stage_edge_values[k3+1] = stage_centroid_values[k] + dqv[1];
     3512      stage_edge_values[k3+2] = stage_centroid_values[k] + dqv[2];
     3513
     3514      //-----------------------------------
     3515      // xmomentum
     3516      //-----------------------------------
     3517
     3518      // Calculate the difference between vertex 0 of the auxiliary
     3519      // triangle and the centroid of triangle k
     3520      dq0 = xmom_centroid_values[k0] - xmom_centroid_values[k];
     3521
     3522      // Calculate differentials between the vertices
     3523      // of the auxiliary triangle
     3524      dq1 = xmom_centroid_values[k1] - xmom_centroid_values[k0];
     3525      dq2 = xmom_centroid_values[k2] - xmom_centroid_values[k0];
     3526
     3527      // Calculate the gradient of xmom on the auxiliary triangle
     3528      a = dy2*dq1 - dy1*dq2;
     3529      a *= inv_area2;
     3530      b = dx1*dq2 - dx2*dq1;
     3531      b *= inv_area2;
     3532
     3533      // Calculate provisional jumps in stage from the centroid
     3534      // of triangle k to its vertices, to be limited
     3535      dqv[0] = a*dxv0+b*dyv0;
     3536      dqv[1] = a*dxv1+b*dyv1;
     3537      dqv[2] = a*dxv2+b*dyv2;
     3538
     3539      // Now we want to find min and max of the centroid and the
     3540      // vertices of the auxiliary triangle and compute jumps
     3541      // from the centroid to the min and max
     3542      //
     3543      find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
     3544
     3545      beta_tmp = beta_uh_dry + (beta_uh - beta_uh_dry) * hfactor;
     3546
     3547      // Limit the gradient
     3548      limit_gradient(dqv, qmin, qmax, beta_tmp);
     3549      //limit_gradient2(dqv, qmin, qmax, beta_tmp,r0scale);
     3550
     3551
     3552      for (i=0; i < 3; i++)
     3553      {
     3554        xmom_edge_values[k3+i] = xmom_centroid_values[k] + dqv[i];
     3555      }
     3556
     3557      //-----------------------------------
     3558      // ymomentum
     3559      //-----------------------------------
     3560
     3561      // Calculate the difference between vertex 0 of the auxiliary
     3562      // triangle and the centroid of triangle k
     3563      dq0 = ymom_centroid_values[k0] - ymom_centroid_values[k];
     3564
     3565      // Calculate differentials between the vertices
     3566      // of the auxiliary triangle
     3567      dq1 = ymom_centroid_values[k1] - ymom_centroid_values[k0];
     3568      dq2 = ymom_centroid_values[k2] - ymom_centroid_values[k0];
     3569
     3570      // Calculate the gradient of xmom on the auxiliary triangle
     3571      a = dy2*dq1 - dy1*dq2;
     3572      a *= inv_area2;
     3573      b = dx1*dq2 - dx2*dq1;
     3574      b *= inv_area2;
     3575
     3576      // Calculate provisional jumps in stage from the centroid
     3577      // of triangle k to its vertices, to be limited
     3578      dqv[0] = a*dxv0 + b*dyv0;
     3579      dqv[1] = a*dxv1 + b*dyv1;
     3580      dqv[2] = a*dxv2 + b*dyv2;
     3581
     3582      // Now we want to find min and max of the centroid and the
     3583      // vertices of the auxiliary triangle and compute jumps
     3584      // from the centroid to the min and max
     3585      //
     3586      find_qmin_and_qmax(dq0, dq1, dq2, &qmin, &qmax);
     3587
     3588      beta_tmp = beta_vh_dry + (beta_vh - beta_vh_dry) * hfactor;
     3589
     3590      // Limit the gradient
     3591      limit_gradient(dqv, qmin, qmax, beta_tmp);
     3592      //limit_gradient2(dqv, qmin, qmax, beta_tmp,r0scale);
     3593
     3594      for (i=0;i<3;i++)
     3595      {
     3596        ymom_edge_values[k3 + i] = ymom_centroid_values[k] + dqv[i];
     3597      }
     3598
     3599    } // End number_of_boundaries <=1
     3600    else
     3601    {
     3602
     3603      //==============================================
     3604      // Number of boundaries == 2
     3605      //==============================================
     3606
     3607      // One internal neighbour and gradient is in direction of the neighbour's centroid
     3608
     3609      // Find the only internal neighbour (k1?)
     3610      for (k2 = k3; k2 < k3 + 3; k2++)
     3611      {
     3612      // Find internal neighbour of triangle k
     3613      // k2 indexes the edges of triangle k
     3614
     3615          if (surrogate_neighbours[k2] != k)
     3616          {
     3617             break;
     3618          }
     3619      }
     3620
     3621      if ((k2 == k3 + 3))
     3622      {
     3623        // If we didn't find an internal neighbour
     3624        report_python_error(AT, "Internal neighbour not found");
     3625        return -1;
     3626      }
     3627
     3628      k1 = surrogate_neighbours[k2];
     3629
     3630      // The coordinates of the triangle are already (x,y).
     3631      // Get centroid of the neighbour (x1,y1)
     3632      coord_index = 2*k1;
     3633      x1 = centroid_coordinates[coord_index];
     3634      y1 = centroid_coordinates[coord_index + 1];
     3635
     3636      // Compute x- and y- distances between the centroid of
     3637      // triangle k and that of its neighbour
     3638      dx1 = x1 - x;
     3639      dy1 = y1 - y;
     3640
     3641      // Set area2 as the square of the distance
     3642      area2 = dx1*dx1 + dy1*dy1;
     3643
     3644      // Set dx2=(x1-x0)/((x1-x0)^2+(y1-y0)^2)
     3645      // and dy2=(y1-y0)/((x1-x0)^2+(y1-y0)^2) which
     3646      // respectively correspond to the x- and y- gradients
     3647      // of the conserved quantities
     3648      dx2 = 1.0/area2;
     3649      dy2 = dx2*dy1;
     3650      dx2 *= dx1;
     3651
     3652
     3653      //-----------------------------------
     3654      // stage
     3655      //-----------------------------------
     3656
     3657      // Compute differentials
     3658      dq1 = stage_centroid_values[k1] - stage_centroid_values[k];
     3659
     3660      // Calculate the gradient between the centroid of triangle k
     3661      // and that of its neighbour
     3662      a = dq1*dx2;
     3663      b = dq1*dy2;
     3664
     3665      // Calculate provisional edge jumps, to be limited
     3666      dqv[0] = a*dxv0 + b*dyv0;
     3667      dqv[1] = a*dxv1 + b*dyv1;
     3668      dqv[2] = a*dxv2 + b*dyv2;
     3669
     3670      // Now limit the jumps
     3671      if (dq1>=0.0)
     3672      {
     3673        qmin=0.0;
     3674        qmax=dq1;
     3675      }
     3676      else
     3677      {
     3678        qmin = dq1;
     3679        qmax = 0.0;
     3680      }
     3681
     3682      // Limit the gradient
     3683      limit_gradient(dqv, qmin, qmax, beta_w);
     3684
     3685      //for (i=0; i < 3; i++)
     3686      //{
     3687      stage_edge_values[k3] = stage_centroid_values[k] + dqv[0];
     3688      stage_edge_values[k3 + 1] = stage_centroid_values[k] + dqv[1];
     3689      stage_edge_values[k3 + 2] = stage_centroid_values[k] + dqv[2];
     3690      //}
     3691
     3692      //-----------------------------------
     3693      // xmomentum
     3694      //-----------------------------------
     3695
     3696      // Compute differentials
     3697      dq1 = xmom_centroid_values[k1] - xmom_centroid_values[k];
     3698
     3699      // Calculate the gradient between the centroid of triangle k
     3700      // and that of its neighbour
     3701      a = dq1*dx2;
     3702      b = dq1*dy2;
     3703
     3704      // Calculate provisional edge jumps, to be limited
     3705      dqv[0] = a*dxv0+b*dyv0;
     3706      dqv[1] = a*dxv1+b*dyv1;
     3707      dqv[2] = a*dxv2+b*dyv2;
     3708
     3709      // Now limit the jumps
     3710      if (dq1 >= 0.0)
     3711      {
     3712        qmin = 0.0;
     3713        qmax = dq1;
     3714      }
     3715      else
     3716      {
     3717        qmin = dq1;
     3718        qmax = 0.0;
     3719      }
     3720
     3721      // Limit the gradient
     3722      limit_gradient(dqv, qmin, qmax, beta_w);
     3723
     3724      //for (i=0;i<3;i++)
     3725      //xmom_edge_values[k3] = xmom_centroid_values[k] + dqv[0];
     3726      //xmom_edge_values[k3 + 1] = xmom_centroid_values[k] + dqv[1];
     3727      //xmom_edge_values[k3 + 2] = xmom_centroid_values[k] + dqv[2];
     3728
     3729      for (i = 0; i < 3;i++)
     3730      {
     3731          xmom_edge_values[k3 + i] = xmom_centroid_values[k] + dqv[i];
     3732      }
     3733
     3734      //-----------------------------------
     3735      // ymomentum
     3736      //-----------------------------------
     3737
     3738      // Compute differentials
     3739      dq1 = ymom_centroid_values[k1] - ymom_centroid_values[k];
     3740
     3741      // Calculate the gradient between the centroid of triangle k
     3742      // and that of its neighbour
     3743      a = dq1*dx2;
     3744      b = dq1*dy2;
     3745
     3746      // Calculate provisional edge jumps, to be limited
     3747      dqv[0] = a*dxv0 + b*dyv0;
     3748      dqv[1] = a*dxv1 + b*dyv1;
     3749      dqv[2] = a*dxv2 + b*dyv2;
     3750
     3751      // Now limit the jumps
     3752      if (dq1>=0.0)
     3753      {
     3754        qmin = 0.0;
     3755        qmax = dq1;
     3756      }
     3757      else
     3758      {
     3759        qmin = dq1;
     3760        qmax = 0.0;
     3761      }
     3762
     3763      // Limit the gradient
     3764      limit_gradient(dqv, qmin, qmax, beta_w);
     3765
     3766      for (i=0;i<3;i++)
     3767              {
     3768              ymom_edge_values[k3 + i] = ymom_centroid_values[k] + dqv[i];
     3769              }
     3770    } // else [number_of_boundaries==2]
     3771  } // for k=0 to number_of_elements-1
     3772
     3773  // Compute vertex values of quantities
     3774  for (k=0; k<number_of_elements; k++){
     3775      k3=3*k;
     3776
     3777      // Compute stage vertex values
     3778      stage_vertex_values[k3] = stage_edge_values[k3+1] + stage_edge_values[k3+2] -stage_edge_values[k3] ;
     3779      stage_vertex_values[k3+1] =  stage_edge_values[k3] + stage_edge_values[k3+2]-stage_edge_values[k3+1];
     3780      stage_vertex_values[k3+2] =  stage_edge_values[k3] + stage_edge_values[k3+1]-stage_edge_values[k3+2];
     3781
     3782     // Compute xmom vertex values
     3783      xmom_vertex_values[k3] = xmom_edge_values[k3+1] + xmom_edge_values[k3+2] -xmom_edge_values[k3] ;
     3784      xmom_vertex_values[k3+1] =  xmom_edge_values[k3] + xmom_edge_values[k3+2]-xmom_edge_values[k3+1];
     3785      xmom_vertex_values[k3+2] =  xmom_edge_values[k3] + xmom_edge_values[k3+1]-xmom_edge_values[k3+2];
     3786
     3787      // Compute ymom vertex values
     3788      ymom_vertex_values[k3] = ymom_edge_values[k3+1] + ymom_edge_values[k3+2] -ymom_edge_values[k3] ;
     3789      ymom_vertex_values[k3+1] =  ymom_edge_values[k3] + ymom_edge_values[k3+2]-ymom_edge_values[k3+1];
     3790      ymom_vertex_values[k3+2] =  ymom_edge_values[k3] + ymom_edge_values[k3+1]-ymom_edge_values[k3+2];
     3791
     3792      // If needed, convert from velocity to momenta
     3793      if(extrapolate_velocity_second_order==1){
     3794          //Convert velocity back to momenta at centroids
     3795          xmom_centroid_values[k] = xmom_centroid_store[k];
     3796          ymom_centroid_values[k] = ymom_centroid_store[k];
     3797
     3798          // Re-compute momenta at edges
     3799          for (i=0; i<3; i++){
     3800              de[i] = max(stage_edge_values[k3+i]-bed_edge_values[k3+i],0.0);
     3801              xmom_edge_values[k3+i]=xmom_edge_values[k3+i]*de[i];
     3802              ymom_edge_values[k3+i]=ymom_edge_values[k3+i]*de[i];
     3803          }
     3804
     3805          // Re-compute momenta at vertices
     3806          for (i=0; i<3; i++){
     3807              de[i] = max(stage_vertex_values[k3+i]-bed_vertex_values[k3+i],0.0);
     3808              xmom_vertex_values[k3+i]=xmom_vertex_values[k3+i]*de[i];
     3809              ymom_vertex_values[k3+i]=ymom_vertex_values[k3+i]*de[i];
     3810          }
     3811
     3812      }
     3813
     3814
     3815  }
     3816
     3817  free(xmom_centroid_store);
     3818  free(ymom_centroid_store);
     3819  free(stage_centroid_store);
     3820
     3821  return 0;
     3822}
     3823
     3824
     3825
     3826
     3827
     3828
     3829
     3830PyObject *extrapolate_second_order_sw_old(PyObject *self, PyObject *args) {
    25733831    /*Compute the vertex values based on a linear reconstruction
    25743832      on each triangle
     
    26813939
    26823940    // Call underlying computational routine
    2683     e = _extrapolate_second_order_sw(number_of_elements,
     3941    e = _extrapolate_second_order_sw_old(number_of_elements,
    26843942            epsilon,
    26853943            minimum_allowed_height,
     
    27133971    return Py_BuildValue("");
    27143972
     3973}// extrapolate_second-order_sw_old
     3974
     3975PyObject *extrapolate_second_order_sw(PyObject *self, PyObject *args) {
     3976  /*Compute the edge values based on a linear reconstruction
     3977    on each triangle
     3978
     3979    Python call:
     3980    extrapolate_second_order_edge_sw(domain)
     3981
     3982    Post conditions:
     3983        The edges of each triangle have values from a
     3984        limited linear reconstruction
     3985        based on centroid values
     3986
     3987  */
     3988
     3989    struct domain D;
     3990    PyObject *domain;
     3991    int err;
     3992
     3993    if (!PyArg_ParseTuple(args, "O", &domain)) {
     3994        report_python_error(AT, "could not parse input arguments");
     3995        return NULL;
     3996    }
     3997
     3998    // populate the C domain structure with pointers
     3999    // to the python domain data
     4000    get_python_domain(&D, domain);
     4001
     4002    print_domain_struct(&D);
     4003
     4004    // Call underlying flux computation routine and update
     4005    // the explicit update arrays
     4006    err = _extrapolate_second_order_sw(&D);
     4007
     4008    if (err == -1) {
     4009        // Use error string set inside computational routine
     4010        return NULL;
     4011    }
     4012
     4013  return Py_BuildValue("");
     4014
    27154015}// extrapolate_second-order_sw
     4016
     4017PyObject *extrapolate_second_order_edge_sw(PyObject *self, PyObject *args) {
     4018  /*Compute the edge values based on a linear reconstruction
     4019    on each triangle
     4020
     4021    Python call:
     4022    extrapolate_second_order_edge_sw(domain)
     4023
     4024    Post conditions:
     4025        The edges of each triangle have values from a
     4026        limited linear reconstruction
     4027        based on centroid values
     4028
     4029  */
     4030   
     4031    struct domain D;
     4032    PyObject *domain;
     4033    int err;
     4034
     4035    if (!PyArg_ParseTuple(args, "O", &domain)) {
     4036        report_python_error(AT, "could not parse input arguments");
     4037        return NULL;
     4038    }
     4039
     4040    // populate the C domain structure with pointers
     4041    // to the python domain data
     4042    get_python_domain(&D, domain);
     4043
     4044    // Call underlying flux computation routine and update
     4045    // the explicit update arrays
     4046    err = _extrapolate_second_order_edge_sw(&D);
     4047
     4048    if (err == -1) {
     4049        // Use error string set inside computational routine
     4050        return NULL;
     4051    }
     4052
     4053  return Py_BuildValue("");
     4054
     4055}// extrapolate_second-order_edge_sw
     4056
     4057
    27164058
    27174059PyObject *rotate(PyObject *self, PyObject *args, PyObject *kwargs) {
     
    44165758    {"rotate", (PyCFunction) rotate, METH_VARARGS | METH_KEYWORDS, "Print out"},
    44175759    {"extrapolate_second_order_sw", extrapolate_second_order_sw, METH_VARARGS, "Print out"},
     5760    {"extrapolate_second_order_sw_old", extrapolate_second_order_sw_old, METH_VARARGS, "Print out"},
     5761    {"extrapolate_second_order_edge_sw", extrapolate_second_order_edge_sw, METH_VARARGS, "Print out"},
    44185762    {"compute_fluxes_ext_wb", compute_fluxes_ext_wb, METH_VARARGS, "Print out"},
    44195763    {"compute_fluxes_ext_wb_3", compute_fluxes_ext_wb_3, METH_VARARGS, "Print out"},
  • trunk/anuga_core/source/anuga/shallow_water/sw_domain.h

    r8390 r8456  
    1818    long    optimise_dry_cells;
    1919    double  evolve_max_timestep;
    20 
    21     // The values in the python object will be changed
     20    long    extrapolate_velocity_second_order;
     21    double  minimum_allowed_height;
     22
     23    double beta_w;
     24    double beta_w_dry;
     25    double beta_uh;
     26    double beta_uh_dry;
     27    double beta_vh;
     28    double beta_vh_dry;
     29
     30
     31    // Changing values in these arrays will change the values in the python object
    2232    long*   neighbours;
    2333    long*   neighbour_edges;
     34    long*   surrogate_neighbours;
    2435    double* normals;
    2536    double* edgelengths;
     
    2738    double* areas;
    2839
     40
     41
    2942    long*   tri_full_flag;
    3043    long*   already_computed_flux;
     
    3245
    3346    double* vertex_coordinates;
    34 
     47    double* edge_coordinates;
     48    double* centroid_coordinates;
     49
     50    long*   number_of_boundaries;
    3551    double* stage_edge_values;
    3652    double* xmom_edge_values;
     
    139155            *already_computed_flux,
    140156            *vertex_coordinates,
     157            *edge_coordinates,
     158            *centroid_coordinates,
     159            *number_of_boundaries,
     160            *surrogate_neighbours,
    141161            *max_speed;
    142162
    143163    PyObject *quantities;
    144164
    145     D->number_of_elements = get_python_integer(domain, "number_of_elements");
    146     D->epsilon = get_python_double(domain, "epsilon");
    147     D->H0 = get_python_double(domain, "H0");
    148     D->g = get_python_double(domain, "g");
    149     D->optimise_dry_cells = get_python_integer(domain, "optimise_dry_cells");
    150     D->evolve_max_timestep = get_python_double(domain, "evolve_max_timestep");
    151 
     165    D->number_of_elements   = get_python_integer(domain, "number_of_elements");
     166    D->epsilon              = get_python_double(domain, "epsilon");
     167    D->H0                   = get_python_double(domain, "H0");
     168    D->g                    = get_python_double(domain, "g");
     169    D->optimise_dry_cells   = get_python_integer(domain, "optimise_dry_cells");
     170    D->evolve_max_timestep  = get_python_double(domain, "evolve_max_timestep");
     171    D->minimum_allowed_height = get_python_double(domain, "minimum_allowed_height");
     172
     173    D->extrapolate_velocity_second_order  = get_python_integer(domain, "extrapolate_velocity_second_order");
     174
     175    D->beta_w      = get_python_double(domain, "beta_w");;
     176    D->beta_w_dry  = get_python_double(domain, "beta_w_dry");
     177    D->beta_uh     = get_python_double(domain, "beta_uh");
     178    D->beta_uh_dry = get_python_double(domain, "beta_uh_dry");
     179    D->beta_vh     = get_python_double(domain, "beta_vh");
     180    D->beta_vh_dry = get_python_double(domain, "beta_vh_dry");
     181
     182
     183   
    152184    neighbours = get_consecutive_array(domain, "neighbours");
    153185    D->neighbours = (long *) neighbours->data;
    154186
     187    surrogate_neighbours = get_consecutive_array(domain, "surrogate_neighbours");
     188    D->surrogate_neighbours = (long *) surrogate_neighbours->data;
     189
    155190    neighbour_edges = get_consecutive_array(domain, "neighbour_edges");
    156191    D->neighbour_edges = (long *) neighbour_edges->data;
     
    176211    vertex_coordinates = get_consecutive_array(domain, "vertex_coordinates");
    177212    D->vertex_coordinates = (double *) vertex_coordinates->data;
     213
     214    edge_coordinates = get_consecutive_array(domain, "edge_coordinates");
     215    D->edge_coordinates = (double *) edge_coordinates->data;
     216
     217
     218    centroid_coordinates = get_consecutive_array(domain, "centroid_coordinates");
     219    D->edge_coordinates = (double *) centroid_coordinates->data;
    178220   
    179221    max_speed = get_consecutive_array(domain, "max_speed");
    180222    D->max_speed = (double *) max_speed->data;
     223
     224    number_of_boundaries = get_consecutive_array(domain, "number_of_boundaries");
     225    D->number_of_boundaries = (long *) number_of_boundaries->data;
     226
    181227
    182228
     
    210256    return D;
    211257}
     258
     259
     260
     261int print_domain_struct(struct domain *D) {
     262
     263
     264    printf("D->number_of_elements %ld  \n", D->number_of_elements);
     265    printf("D->epsilon %g \n", D->epsilon);
     266    printf("D->H0 %g \n", D->H0);
     267    printf("D->g %g \n", D->g);
     268    printf("D->optimise_dry_cells %ld \n", D->optimise_dry_cells);
     269    printf("D->evolve_max_timestep %g \n", D->evolve_max_timestep);
     270    printf("D->minimum_allowed_height %g \n", D->minimum_allowed_height);
     271    printf("D->extrapolate_velocity_second_order %ld \n", D->extrapolate_velocity_second_order);
     272    printf("D->beta_w %g \n", D->beta_w);
     273    printf("D->beta_w_dry %g \n", D->beta_w_dry);
     274    printf("D->beta_uh %g \n", D->beta_uh);
     275    printf("D->beta_uh_dry %g \n", D->beta_uh_dry);
     276    printf("D->beta_vh %g \n", D->beta_vh);
     277    printf("D->beta_vh_dry %g \n", D->beta_vh_dry);
     278
     279
     280
     281    printf("D->neighbours            %p \n", D->neighbours);
     282    printf("D->surrogate_neighbours  %p \n", D->surrogate_neighbours);
     283    printf("D->neighbour_edges       %p \n", D->neighbour_edges);
     284    printf("D->normals               %p \n", D->normals);
     285    printf("D->edgelengths           %p \n", D->edgelengths);
     286    printf("D->radii                 %p \n", D->radii);
     287    printf("D->areas                 %p \n", D->areas);
     288    printf("D->tri_full_flag         %p \n", D->tri_full_flag);
     289    printf("D->already_computed_flux %p \n", D->already_computed_flux);
     290    printf("D->vertex_coordinates    %p \n", D->vertex_coordinates);
     291    printf("D->neighbours %p \n", D->neighbours);
     292    printf("D->neighbours %p \n", D->neighbours);
     293    printf("D->neighbours %p \n", D->neighbours);
     294    printf("D->neighbours %p \n", D->neighbours);
     295    printf("D->neighbours %p \n", D->neighbours);
     296    printf("D->neighbours %p \n", D->neighbours);
     297    printf("D->neighbours %p \n", D->neighbours);
     298    printf("D->neighbours %p \n", D->neighbours);
     299    printf("D->neighbours %p \n", D->neighbours);
     300    printf("D->neighbours %p \n", D->neighbours);
     301    printf("D->neighbours %p \n", D->neighbours);
     302    printf("D->neighbours %p \n", D->neighbours);
     303    printf("D->neighbours %p \n", D->neighbours);
     304    printf("D->neighbours %p \n", D->neighbours);
     305    printf("D->neighbours %p \n", D->neighbours);
     306    printf("D->neighbours %p \n", D->neighbours);
     307    printf("D->neighbours %p \n", D->neighbours);
     308    printf("D->neighbours %p \n", D->neighbours);
     309    printf("D->neighbours %p \n", D->neighbours);
     310    printf("D->neighbours %p \n", D->neighbours);
     311    printf("D->neighbours %p \n", D->neighbours);
     312    printf("D->neighbours %p \n", D->neighbours);
     313
     314
     315
     316//
     317//    edge_coordinates = get_consecutive_array(domain, "edge_coordinates");
     318//    D->edge_coordinates = (double *) edge_coordinates->data;
     319//
     320//
     321//    centroid_coordinates = get_consecutive_array(domain, "centroid_coordinates");
     322//    D->edge_coordinates = (double *) centroid_coordinates->data;
     323//
     324//    max_speed = get_consecutive_array(domain, "max_speed");
     325//    D->max_speed = (double *) max_speed->data;
     326//
     327//    number_of_boundaries = get_consecutive_array(domain, "number_of_boundaries");
     328//    D->number_of_boundaries = (long *) number_of_boundaries->data;
     329//
     330//
     331//
     332//    quantities = get_python_object(domain, "quantities");
     333//
     334//    D->stage_edge_values     = get_python_array_data_from_dict(quantities, "stage",     "edge_values");
     335//    D->xmom_edge_values      = get_python_array_data_from_dict(quantities, "xmomentum", "edge_values");
     336//    D->ymom_edge_values      = get_python_array_data_from_dict(quantities, "ymomentum", "edge_values");
     337//    D->bed_edge_values       = get_python_array_data_from_dict(quantities, "elevation", "edge_values");
     338//
     339//    D->stage_centroid_values     = get_python_array_data_from_dict(quantities, "stage",     "centroid_values");
     340//    D->xmom_centroid_values      = get_python_array_data_from_dict(quantities, "xmomentum", "centroid_values");
     341//    D->ymom_centroid_values      = get_python_array_data_from_dict(quantities, "ymomentum", "centroid_values");
     342//    D->bed_centroid_values       = get_python_array_data_from_dict(quantities, "elevation", "centroid_values");
     343//
     344//    D->stage_vertex_values     = get_python_array_data_from_dict(quantities, "stage",     "vertex_values");
     345//    D->xmom_vertex_values      = get_python_array_data_from_dict(quantities, "xmomentum", "vertex_values");
     346//    D->ymom_vertex_values      = get_python_array_data_from_dict(quantities, "ymomentum", "vertex_values");
     347//    D->bed_vertex_values       = get_python_array_data_from_dict(quantities, "elevation", "vertex_values");
     348//
     349//    D->stage_boundary_values = get_python_array_data_from_dict(quantities, "stage",     "boundary_values");
     350//    D->xmom_boundary_values  = get_python_array_data_from_dict(quantities, "xmomentum", "boundary_values");
     351//    D->ymom_boundary_values  = get_python_array_data_from_dict(quantities, "ymomentum", "boundary_values");
     352//    D->bed_boundary_values   = get_python_array_data_from_dict(quantities, "elevation", "boundary_values");
     353//
     354//    D->stage_explicit_update = get_python_array_data_from_dict(quantities, "stage",     "explicit_update");
     355//    D->xmom_explicit_update  = get_python_array_data_from_dict(quantities, "xmomentum", "explicit_update");
     356//    D->ymom_explicit_update  = get_python_array_data_from_dict(quantities, "ymomentum", "explicit_update");
     357//
     358
     359    return 0;
     360}
     361
  • trunk/anuga_core/source/anuga/shallow_water/test_shallow_water_domain.py

    r8405 r8456  
    38363836        assert num.allclose(Y[1,:], Y_EX)
    38373837
     3838
     3839
     3840
     3841    def Xtest_extrapolate_second_order_sw_real_data(self):
     3842        #Using test data generated by abstract_2d_finite_volumes-2
     3843        #Assuming no friction and flat bed (0.0)
     3844
     3845        a = [0.0, 0.0]
     3846        b = [0.0, 1.0/5]
     3847        c = [0.0, 2.0/5]
     3848        d = [1.0/5, 0.0]
     3849        e = [1.0/5, 1.0/5]
     3850        f = [1.0/5, 2.0/5]
     3851        g = [2.0/5, 2.0/5]
     3852
     3853        points = [a, b, c, d, e, f, g]
     3854        #             bae,     efb,     cbf,     feg
     3855        vertices = [[1,0,4], [4,5,1], [2,1,5], [5,4,6]]
     3856
     3857        domain = Domain(points, vertices)
     3858
     3859        def slope(x, y):
     3860            return -x/3
     3861
     3862        domain.set_quantity('elevation', slope)
     3863        domain.set_quantity('stage',
     3864                            [0.01298164, 0.00365611,
     3865                             0.01440365, -0.0381856437096],
     3866                            location='centroids')
     3867        domain.set_quantity('xmomentum',
     3868                            [0.00670439, 0.01263789,
     3869                             0.00647805, 0.0178180740668],
     3870                            location='centroids')
     3871        domain.set_quantity('ymomentum',
     3872                            [-7.23510980e-004, -6.30413883e-005,
     3873                             6.30413883e-005, 0.000200907255866],
     3874                            location='centroids')
     3875
     3876        E = domain.quantities['elevation'].vertex_values
     3877        L = domain.quantities['stage'].vertex_values
     3878        X = domain.quantities['xmomentum'].vertex_values
     3879        Y = domain.quantities['ymomentum'].vertex_values
     3880
     3881        domain._order_ = 2
     3882        domain.beta_w = 0.9
     3883        domain.beta_w_dry = 0.9
     3884        domain.beta_uh = 0.9
     3885        domain.beta_uh_dry = 0.9
     3886        domain.beta_vh = 0.9
     3887        domain.beta_vh_dry = 0.9
     3888
     3889        # FIXME (Ole): Need tests where this is commented out
     3890        domain.tight_slope_limiters = 0       # Backwards compatibility (14/4/7)
     3891        domain.use_centroid_velocities = 0    # Backwards compatibility (7/5/8)
     3892        domain.optimised_gradient_limiter = True
     3893
     3894        #domain.extrapolate_second_order_sw()
     3895
     3896
     3897        from  anuga.shallow_water.shallow_water_domain import extrapolate_second_order_sw
     3898
     3899        extrapolate_second_order_sw(domain)
     3900
     3901        #domain.distribute_to_vertices_and_edges()
     3902
     3903
     3904        print L[1,:]
     3905        print X[1,:]
     3906        print Y[1,:]
     3907
     3908        L_EX = [-0.00137913, -0.00098143,  0.0133289 ]
     3909        X_EX = [ 0.01998251,  0.01948814,  0.00247195]
     3910        Y_EX = [ -2.18223005e-04,   2.25636080e-04,  -5.36417393e-05]
     3911
     3912       
     3913        #L_EX = [-0.00825736, -0.00801881,  0.0272445 ]
     3914        #X_EX = [ 0.0170432 ,  0.01674667,  0.00654035]
     3915        #Y_EX = [ -1.56119371e-04,   1.10107449e-04,  -5.74034758e-05]
     3916
     3917        assert num.allclose(L[1,:], L_EX)
     3918        assert num.allclose(X[1,:], X_EX)
     3919        assert num.allclose(Y[1,:], Y_EX)
     3920
    38383921    def test_balance_deep_and_shallow(self):
    38393922        """Test that balanced limiters preserve conserved quantites.
     
    83488431
    83498432if __name__ == "__main__":
    8350     #suite = unittest.makeSuite(Test_Shallow_Water, 'test_rainfall_forcing_with_evolve')
     8433    #suite = unittest.makeSuite(Test_Shallow_Water, 'test_extrapolate_second_order_sw')
    83518434    suite = unittest.makeSuite(Test_Shallow_Water, 'test_')
    83528435    runner = unittest.TextTestRunner(verbosity=1)
Note: See TracChangeset for help on using the changeset viewer.