Changeset 9105


Ignore:
Timestamp:
May 5, 2014, 5:21:42 PM (11 years ago)
Author:
davies
Message:

Fixed conflicts

Location:
trunk
Files:
7 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/pmesh/mesh_interface.py

    r8699 r9105  
    3333                             breaklines=None,
    3434                             use_cache=False,
    35                              verbose=True):
     35                             verbose=True,
     36                             regionPtArea=None):
    3637    """Create mesh from bounding polygons, and resolutions.
    3738
     
    107108              'fail_if_polygons_outside': fail_if_polygons_outside,
    108109              'breaklines': breaklines,
    109               'verbose': verbose}   # FIXME (Ole): Should be bypassed one day. See ticket:14
     110              'verbose': verbose,
     111              'regionPtArea': regionPtArea}   # FIXME (Ole): Should be bypassed one day. See ticket:14
    110112
    111113    # Call underlying engine with or without caching
     
    145147                              fail_if_polygons_outside=True,
    146148                              breaklines=None,
    147                               verbose=True):
     149                              verbose=True,
     150                              regionPtArea=None):
    148151    """_create_mesh_from_regions - internal function.
    149152
     
    151154    """
    152155
    153    
    154156    # check the segment indexes - throw an error if they are out of bounds
    155157    if boundary_tags is not None:
     
    301303    else:
    302304        bounding_polygon_absolute = bounding_polygon
    303     
     305   
    304306    inner_point = point_in_polygon(bounding_polygon_absolute)
    305307    inner = m.add_region(inner_point[0], inner_point[1])
     
    339341                                    segment_tags=tags,
    340342                                    geo_reference=poly_geo_reference)
    341        
     343
     344
     345    # 22/04/2014
     346    # Add user-specified point-based regions with max area
     347    if(regionPtArea is not None):
     348        for i in range(len(regionPtArea)):
     349            inner = m.add_region(regionPtArea[i][0], regionPtArea[i][1])
     350            inner.setMaxArea(regionPtArea[i][2])
     351       
     352               
    342353
    343354
  • trunk/anuga_core/source/anuga/shallow_water/okada_tsunami.py

    r8943 r9105  
    136136                 width  = the width of the sub-fault (km) DOWN THE DIP (i.e. width=surface_width/cos(dip))
    137137
    138                  dis1, dis2, dis3 are the fault displacement components in the
     138                 dis1, dis2, dis3 are the fault displacement components (m) in the
    139139                 directions 'along strike', 'up-dip', and 'perpendicular to the slip plain'.
    140140                 
  • trunk/anuga_core/source/anuga/shallow_water/shallow_water_domain.py

    r9104 r9105  
    225225        self.quantities['y'].set_values(self.vertex_coordinates[:,1].reshape(n,3))
    226226        self.quantities['y'].set_boundary_values_from_edges()
     227
     228        # For riverwalls, we need to know the 'edge_flux_type' for each edge
     229        # Edge-flux-type of 0 == Normal edge, with shallow water flux
     230        #                   1 == riverwall
     231        #                   2 == ?
     232        #                   etc
     233        self.edge_flux_type=num.zeros(len(self.edge_coordinates[:,0])).astype(int)
     234
     235        # Riverwalls -- initialise with dummy values
     236        # Presently only works with DE1, will fail otherwise
     237        import anuga.structures.riverwall
     238        self.riverwallData=anuga.structures.riverwall.RiverWall(self)
    227239
    228240
     
    445457        self.edge_coordinates=self.get_edge_midpoint_coordinates()
    446458
    447         # Hold elevation of riverwalls along cell edges
    448         from anuga.config import max_float
    449         self.riverwall_elevation=self.edge_coordinates[:,0]*0.0 - max_float
    450 
    451459        # By default vertex values are NOT stored uniquely
    452460        # for storage efficiency. We may override this (but not so important since
     
    12941302                                               Bed.centroid_values,
    12951303                                               height.centroid_values,
    1296                                                Bed.vertex_values,
    1297                                                self.riverwall_elevation)
     1304                                               #Bed.vertex_values,
     1305                                               self.edge_flux_type,
     1306                                               self.riverwallData.riverwall_elevation,
     1307                                               self.riverwallData.hydraulic_properties_rowIndex,
     1308                                               int(self.riverwallData.ncol_hydraulic_properties),
     1309                                               self.riverwallData.hydraulic_properties)
    12981310
    12991311            ## FIXME: This won't work in parallel since the timestep has not been updated to include other processors.
  • trunk/anuga_core/source/anuga/shallow_water/swDE1_domain_ext.c

    r9104 r9105  
    148148
    149149  // Compute speeds in x-direction
    150   w_left = q_left_rotated[0];         
     150  //w_left = q_left_rotated[0];         
    151151  uh_left=q_left_rotated[1];
    152152  vh_left=q_left_rotated[2];
     
    164164  //            epsilon, h0, limiting_threshold);
    165165
    166   w_right = q_right_rotated[0];
     166  //w_right = q_right_rotated[0];
    167167  uh_right = q_right_rotated[1];
    168168  vh_right = q_right_rotated[2];
     
    257257}
    258258
     259double adjust_edgeflux_with_weir(double* edgeflux,
     260                                 double h_left, double h_right,
     261                                 double g, double weir_height,
     262                                 double weirScale,
     263                                 double s1, double s2,
     264                                 double h1, double h2
     265                                ){
     266    // Adjust the edgeflux to agree with a weir relation [including
     267    // subergence], but smoothly vary to shallow water solution when
     268    // the flow over the weir is much deeper than the weir, or the
     269    // upstream/downstream water elevations are too similar
     270    double rw, rw2; // 'Raw' weir fluxes
     271    double rwRat, hdRat,hdWrRat, scaleFlux, scaleFluxS, minhd, maxhd;
     272    double w1,w2; // Weights for averaging
     273    double newFlux;
     274    // Following constants control the 'blending' with the shallow water solution
     275    // They are now user-defined
     276    //double s1=0.9; // At this submergence ratio, begin blending with shallow water solution
     277    //double s2=0.95; // At this submergence ratio, completely use shallow water solution
     278    //double h1=1.0; // At this (tailwater height above weir) / (weir height) ratio, begin blending with shallow water solution
     279    //double h2=1.5; // At this (tailwater height above weir) / (weir height) ratio, completely use the shallow water solution
     280
     281    minhd=min(h_left, h_right);
     282    maxhd=max(h_left,h_right);
     283    // 'Raw' weir discharge = weirScale*2/3*H*(2/3*g*H)**0.5
     284    rw=weirScale*2./3.*maxhd*sqrt(2./3.*g*maxhd);
     285    // Factor for villemonte correction
     286    rw2=weirScale*2./3.*minhd*sqrt(2./3.*g*minhd);
     287    // Useful ratios
     288    rwRat=rw2/max(rw, 1.0e-100);
     289    hdRat=minhd/max(maxhd,1.0e-100);
     290    // (tailwater height above weir)/weir_height ratio
     291    hdWrRat=minhd/max(weir_height,1.0e-100);
     292       
     293    // Villemonte (1947) corrected weir flow with submergence
     294    // Q = Q1*(1-Q2/Q1)**0.385
     295    rw = rw*pow(1.0-rwRat,0.385);
     296
     297    if(h_right>h_left){
     298        rw*=-1.0;
     299    }
     300
     301    if( (hdRat<s2) & (hdWrRat< h2) ){
     302        // Rescale the edge fluxes so that the mass flux = desired flux
     303        // Linearly shift to shallow water solution between hdRat = s1 and s2 
     304        // and between hdWrRat = h1 and h2
     305
     306        //       
     307        // WEIGHT WITH RAW SHALLOW WATER FLUX BELOW
     308        // This ensures that as the weir gets very submerged, the
     309        // standard shallow water equations smoothly take over
     310        //
     311
     312        // Weighted average constants to transition to shallow water eqn flow
     313        w1=min( max(hdRat-s1,0.)/(s2-s1), 1.0);
     314        //w2=1.0-w1;
     315        //
     316        // Adjust again when the head is too deep relative to the weir height
     317        w2=min( max(hdWrRat-h1,0.)/(h2-h1), 1.0);
     318        //w2=1.0-w1;
     319
     320        newFlux=(rw*(1.0-w1)+w1*edgeflux[0])*(1.0-w2) + w2*edgeflux[0];
     321       
     322        if(fabs(edgeflux[0])>1.0e-100){
     323            scaleFlux=newFlux/edgeflux[0];
     324
     325            // FINAL ADJUSTED FLUX
     326            edgeflux[0]*=scaleFlux;
     327            edgeflux[1]*=scaleFlux;
     328            edgeflux[2]*=scaleFlux;
     329        }else{
     330            // Can't divide by edgeflux
     331            edgeflux[0] = newFlux;
     332            edgeflux[1]*=0.;
     333            edgeflux[2]*=0.;
     334        }
     335    }
     336
     337    //printf("%e, %e, %e, %e , %e, %e \n", weir_height, h_left, h_right, edgeflux[0], w1, w2);
     338
     339    return 0;
     340}
    259341
    260342// Computational function for flux computation
     
    293375        double* bed_centroid_values,
    294376        double* height_centroid_values,
    295         double* bed_vertex_values,
    296         double* riverwall_elevation) {
     377        //double* bed_vertex_values,
     378        long* edge_flux_type,
     379        double* riverwall_elevation,
     380        long* riverwall_rowIndex,
     381        int ncol_riverwall_hydraulic_properties,
     382        double* riverwall_hydraulic_properties) {
    297383    // Local variables
    298384    double max_speed, length, inv_area, zl, zr;
    299385    //double h0 = H0*H0;//H0*H0;//H0*0.1;//H0*H0;//H0*H0; // This ensures a good balance when h approaches H0.
    300386    double h_left, h_right, z_half ;  // For andusse scheme
    301 
     387    // FIXME: limiting_threshold is not used for DE1
    302388    double limiting_threshold = 10*H0;//10 * H0 ;//H0; //10 * H0; // Avoid applying limiter below this
    303389    // threshold for performance reasons.
     
    305391    int k, i, m, n,j, ii;
    306392    int ki, nm = 0, ki2,ki3, nm3; // Index shorthands
    307 
     393    //int num_hydraulic_properties=1; // FIXME: Move to function call
    308394    // Workspace (making them static actually made function slightly slower (Ole))
    309395    double ql[3], qr[3], edgeflux[3]; // Work array for summing up fluxes
     
    311397    double bedslope_work, local_timestep;
    312398    int neighbours_wet[3];//Work array
    313     int useint;
    314     double hle, hre, zc, zc_n;
     399    int RiverWall_count;
     400    double hle, hre, zc, zc_n, Qfactor, s1, s2, h1, h2;
    315401    double stage_edge_lim, outgoing_mass_edges, bedtop, bedbot, pressure_flux, hc, hc_n, tmp, tmp2;
    316402    static long call = 1; // Static local variable flagging already computed flux
    317     double speed_max_last, vol, smooth, local_speed;
     403    double speed_max_last, vol, smooth, local_speed, weir_height;
    318404
    319405    double *edgeflux_store, *pressuregrad_store;
     
    331417
    332418    local_timestep=timestep;
     419    RiverWall_count=0;
    333420
    334421
     
    390477            z_half=max(z_half,riverwall_elevation[ki]);
    391478
     479            // Account for riverwalls
     480            if(edge_flux_type[ki]==1){
     481                // Update counter of riverwall edges == index of
     482                // riverwall_elevation + riverwall_rowIndex
     483                RiverWall_count+=1;
     484                // Set central bed to riverwall elevation
     485                z_half=riverwall_elevation[RiverWall_count-1];
     486                // Since there is a wall, use first order extrapolation for this edge
     487                // This also makes more sense from the viewpoint of weir relations
     488                ql[0]=stage_centroid_values[k];
     489                ql[1]=xmom_centroid_values[k];
     490                ql[2]=ymom_centroid_values[k];
     491                hle=hc;
     492                zl=zc;
     493                if(n>=0){
     494                    qr[0]=stage_centroid_values[n];
     495                    qr[1]=xmom_centroid_values[n];
     496                    qr[2]=ymom_centroid_values[n];
     497                    hre=hc_n;
     498                    zr = zc_n;
     499                }
     500
     501            }
     502
     503            // Define h left/right for Audusse flux method
    392504            h_left= max(hle+zl-z_half,0.);
    393505            h_right= max(hre+zr-z_half,0.);
     
    402514                    speed_max_last);
    403515
     516            // Force weir discharge to match weir theory
     517            if(edge_flux_type[ki]==1){
     518                //printf("%e \n", z_half);
     519                weir_height=riverwall_elevation[RiverWall_count-1]-min(zl,zr); // Reference weir height 
     520
     521                // Get Qfactor index - multiply the idealised weir discharge by this constant factor
     522                ii=riverwall_rowIndex[RiverWall_count-1]*ncol_riverwall_hydraulic_properties;
     523                Qfactor=riverwall_hydraulic_properties[ii];
     524                //printf("%e \n", Qfactor);
     525                // Get s1, submergence ratio at which we start blending with the shallow water solution
     526                ii+=1;
     527                s1=riverwall_hydraulic_properties[ii];
     528                // Get s2, submergence ratio at which we entirely use the shallow water solution
     529                ii+=1;
     530                s2=riverwall_hydraulic_properties[ii];
     531                // Get h1, tailwater head / weir height at which we start blending with the shallow water solution
     532                ii+=1;
     533                h1=riverwall_hydraulic_properties[ii];
     534                // Get h2, tailwater head / weir height at which we entirely use the shallow water solution
     535                ii+=1;
     536                h2=riverwall_hydraulic_properties[ii];
     537
     538                //printf("%e, %e, %e, %e, %e \n", Qfactor, s1, s2, h1, h2);
     539
     540                adjust_edgeflux_with_weir(edgeflux, h_left, h_right, g,
     541                                          weir_height, Qfactor,
     542                                          s1, s2, h1, h2);
     543                // NOTE: Should perhaps also adjust the wave-speed here?? Small chance of instability??
     544                //printf("%e \n", edgeflux[0]);
     545            }
     546           
    404547            // Multiply edgeflux by edgelength
    405548            length = edgelengths[ki];
     
    407550            edgeflux[1] *= length;
    408551            edgeflux[2] *= length;
     552
    409553
    410554            //// Don't allow an outward advective flux if the cell centroid stage
     
    15541698    domain.timestep = compute_fluxes(timestep,
    15551699                                     domain.epsilon,
    1556                      domain.H0,
     1700                                     domain.H0,
    15571701                                     domain.g,
    15581702                                     domain.neighbours,
     
    16111755    *height_centroid_values,
    16121756    *bed_vertex_values,
    1613     *riverwall_elevation;
     1757    *edge_flux_type,
     1758    *riverwall_elevation,
     1759    *riverwall_rowIndex,
     1760    *riverwall_hydraulic_properties;
    16141761   
    16151762  double timestep, epsilon, H0, g;
    1616   int optimise_dry_cells, timestep_fluxcalls;
     1763  int optimise_dry_cells, timestep_fluxcalls, ncol_riverwall_hydraulic_properties;
    16171764   
    16181765  // Convert Python arguments to C
    1619   if (!PyArg_ParseTuple(args, "ddddOOOOOOOOOOOOOOOOOOOOOOiiOOOOOOO",
     1766  if (!PyArg_ParseTuple(args, "ddddOOOOOOOOOOOOOOOOOOOOOOiiOOOOOOOOiO",
    16201767            &timestep,
    16211768            &epsilon,
     
    16491796            &bed_centroid_values,
    16501797            &height_centroid_values,
    1651             &bed_vertex_values,
    1652             &riverwall_elevation)) {
     1798            //&bed_vertex_values,
     1799            &edge_flux_type,
     1800            &riverwall_elevation,
     1801            &riverwall_rowIndex,
     1802            &ncol_riverwall_hydraulic_properties,
     1803            &riverwall_hydraulic_properties
     1804            )) {
    16531805    report_python_error(AT, "could not parse input arguments");
    16541806    return NULL;
     
    16821834  CHECK_C_CONTIG(bed_centroid_values);
    16831835  CHECK_C_CONTIG(height_centroid_values);
    1684   CHECK_C_CONTIG(bed_vertex_values);
     1836  //CHECK_C_CONTIG(bed_vertex_values);
     1837  CHECK_C_CONTIG(edge_flux_type);
    16851838  CHECK_C_CONTIG(riverwall_elevation);
     1839  CHECK_C_CONTIG(riverwall_rowIndex);
     1840  CHECK_C_CONTIG(riverwall_hydraulic_properties);
    16861841
    16871842  int number_of_elements = stage_edge_values -> dimensions[0];
     
    17231878                     (double*) bed_centroid_values -> data,
    17241879                     (double*) height_centroid_values -> data,
    1725                      (double*) bed_vertex_values -> data,
    1726                      (double*) riverwall_elevation -> data);
    1727  
     1880                     //(double*) bed_vertex_values -> data,
     1881                     (long*)   edge_flux_type-> data,
     1882                     (double*) riverwall_elevation-> data,
     1883                     (long*)   riverwall_rowIndex-> data,
     1884                     ncol_riverwall_hydraulic_properties,
     1885                     (double*) riverwall_hydraulic_properties ->data);
    17281886  // Return updated flux timestep
    17291887  return Py_BuildValue("d", timestep);
Note: See TracChangeset for help on using the changeset viewer.