Changeset 9225


Ignore:
Timestamp:
Jun 30, 2014, 2:19:32 PM (10 years ago)
Author:
davies
Message:

Bug fix for riverwalls + more tests

Location:
trunk
Files:
5 edited

Legend:

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

    r9165 r9225  
    607607            if (already_computed_flux[ki] == call) {
    608608                // We've already computed the flux across this edge
     609                // Check if it is a riverwall
     610                if(edge_flux_type[ki]==1){
     611                    // Update counter of riverwall edges == index of
     612                    // riverwall_elevation + riverwall_rowIndex
     613                    RiverWall_count+=1;
     614                }
    609615                continue;
    610616            }
  • trunk/anuga_core/source/anuga/structures/riverwall.py

    r9167 r9225  
     1import os
     2from anuga_parallel import barrier, numprocs, myid
    13import numpy
    24
     
    1315    so long as the riverwall is not too deeply submerged.
    1416
    15     As of 22/04/2014, they are only implemented for DE0 and DE1 [the shallow water
     17    As of 22/04/2014, they are only implemented for DE algorithms [the shallow water
    1618    component would be more difficult to implement with other algorithms]
    1719       
     
    146148    def create_riverwalls(self, riverwalls, riverwallPar={ },
    147149                          default_riverwallPar={ },
    148                           tol=1.0e-04, verbose=True):
     150                          tol=1.0e-4, verbose=True,
     151                          output_dir=None):
    149152        """Add riverwalls at chosen locations along the mesh
    150153
    151         As of 22/04/2014, these only work with DE0 and DE1 [for which the concept is natural]
     154        As of 22/04/2014, these only work with DE algorithms [for which the concept is natural]
    152155
    153156        The walls MUST EXACTLY COINCIDE with edges along the mesh
     
    205208            verbose: TRUE/FALSE Print lots of information
    206209
     210            output_dir: Text representation of riverwalls is written to output_dir, unless output_dir=None
     211
    207212        Outputs:
    208213            None, but it sets domain.edge_flux_type = 1 for every edge on a riverwall
     
    213218        """
    214219
    215         if(verbose):       
     220        if(verbose and myid==0):       
    216221            print ' '
    217222            print 'WARNING: Riverwall is an experimental feature'
    218223            print '         At each riverwall edge, we place a thin "wall" between'
    219             print '          the 2 edges -- so each sees its neighbour edge as having'
    220             print '          bed elevation = max(levee height, neighbour bed elevation)'
     224            print '         the 2 edges -- so each sees its neighbour edge as having'
     225            print '         bed elevation = max(levee height, neighbour bed elevation)'
    221226            print '         We also force the discharge with a weir relation, blended with'
    222             print '          the shallow water flux solution as the ratio (min_head)/(weir_height) becomes '
    223             print '          large, or the ratio (downstream_head)/(upstream_head) becomes large'
     227            print '         the shallow water flux solution as the ratio (min_head)/(weir_height) becomes '
     228            print '         large, or the ratio (downstream_head)/(upstream_head) becomes large'
    224229            print ' '
    225230            print '  It works in parallel, but you must use domain.riverwallData.create_riverwall AFTER distributing the mesh'
    226231            print ' '
    227232
    228         # NOTE: domain.riverwallData is initialised in shallow_water_domain.py for DE0 and DE1
    229 
     233        # NOTE: domain.riverwallData is initialised in shallow_water_domain.py for DE algorithms
    230234        domain=self.domain
    231235
     
    233237        # Check flow algorithm
    234238        if(not domain.get_using_discontinuous_elevation()):
    235             raise Exception, 'Riverwalls are currently only supported when domain.flow_algorithm="DE0" and "DE1"'
     239            raise Exception, 'Riverwalls are currently only supported for discontinuous elevation flow algorithms'
    236240
    237241        if(len(self.names)>0):
     
    248252        self.input_riverwallPar=riverwallPar
    249253
    250         # Update self.default_riverwallPar
     254        # Update self.default_riverwallPar (defined in __init__)
    251255        for i in self.default_riverwallPar.keys():
    252256            if(default_riverwallPar.has_key(i)):
     
    278282       
    279283        if(verbose):
    280             print 'Setting riverwall elevations ...'
     284            print 'Setting riverwall elevations (P'+str(myid)+')...'
    281285
    282286        # Set up geometry
     
    295299        nw=range(len(riverwalls))
    296300        nw_names=riverwalls.keys() # Not guarenteed to be in deterministic order
     301
     302        if(verbose):
     303            # Use variable to record messages, allows cleaner parallel printing
     304            printInfo=''
     305
    297306        for i in nw:
    298307            # Name of riverwall
     
    303312            ns=len(riverwalli)-1
    304313
    305             if(verbose):
    306                 print 'Wall ' + str(i) +' ....'
     314            if(verbose): 
     315                printInfo=printInfo + '  Wall ' + str(i) +' ....\n'
    307316
    308317            for j in range(ns):
    309318                if(verbose):
    310                     print '    Segment ' + str(j) +' ....'
     319                    printInfo=printInfo + '    Segment ' + str(j) +' ....\n'
    311320                # Start and end xyz coordinates
    312321                start=riverwalli[j]
     
    320329                segLen=( (start[0]-end[0])**2+(start[1]-end[1])**2)**0.5
    321330                if(segLen<tol):
    322                     print 'Segment with length < tolerance ' + str(tol) +' ignored'
     331                    if(verbose):
     332                        printInfo=printInfo+'  Segment with length < tolerance ' + str(tol) +' ignored\n'
    323333                    continue
    324334               
     
    353363
    354364                if(verbose):
    355                     print '       Finding ' + str(len(onLevee)) + ' edges on this segment '
     365                    printInfo=printInfo+'       Finding ' + str(len(onLevee)) + ' edges on this segment\n'
    356366           
    357367                # Levee has Edge_flux_type=1 
     
    369379        # Now, condense riverwall_elevation to array with length = number of riverwall edges
    370380        #
    371         # FIXME: We do this to avoid storing a riverwall_elevation for every edge in the mesh
    372         #        However, the data structure ends up being quite complex -- maybe there is a better way?
     381        # We do this to avoid storing a riverwall_elevation for every edge in the mesh
     382        #  However, the data structure ends up being quite complex -- maybe there is a better way?
    373383        #
    374384        # The zeroth index in domain.edge_flux_type which = 1 will correspond to riverwall_elevation[0]
     
    383393        self.hydraulic_properties_rowIndex=\
    384394            riverwall_rowIndex[riverwallInds].astype(int)
    385         # index of edges which are riverwalls [FIXME: Not really needed, can easily back-calculate from edge_flux_type]
     395        # index of edges which are riverwalls
    386396        self.riverwall_edges=riverwallInds
    387397
     
    389399        self.names=nw_names
    390400
    391         
     401       
    392402        # Now create the hydraulic properties table
    393403
     
    412422                if((riverwalli_Par is not None) and (riverwalli_Par.has_key(hydraulicVar))):
    413423                    if(verbose):
    414                         print 'Using provided ', hydraulicVar,\
    415                            riverwalli_Par[hydraulicVar], ' for riverwall ', name_riverwalli
     424                        printInfo=printInfo+ '  Using provided '+ str(hydraulicVar)+' '+\
     425                           str(riverwalli_Par[hydraulicVar])+ ' for riverwall '+ str(name_riverwalli)+'\n'
    416426                    hydraulicTmp[i,j]=riverwalli_Par[hydraulicVar]
    417427                else:
    418428                    if(verbose):
    419                         print 'Using default ',  hydraulicVar,\
    420                             default_riverwallPar[hydraulicVar], ' for riverwall ', name_riverwalli
     429                        printInfo=printInfo+ '  Using default '+ str(hydraulicVar)+' '+\
     430                            str(default_riverwallPar[hydraulicVar])+' for riverwall '+ str(name_riverwalli)+'\n'
    421431                    hydraulicTmp[i,j]=default_riverwallPar[hydraulicVar]
    422432
     
    442452        # Define the hydraulic properties
    443453        self.hydraulic_properties=hydraulicTmp
    444 
     454     
    445455        # Check for riverwall 'connectedness' errors (e.g. theoretically possible
    446456        # to miss an edge due to round-off)
    447         self.check_riverwall_connectedness(domain, verbose,tol=tol)
    448          
    449         return()
     457        connectedness=self.check_riverwall_connectedness(verbose=verbose)
     458
     459        self.export_riverwalls_to_text(output_dir=output_dir)
     460       
     461        # Pretty printing of riverwall information in parallel
     462        if(verbose):
     463            barrier()
     464            for i in range(numprocs):
     465                if(myid==i):
     466                    print 'Processor '+str(myid)
     467                    print printInfo
     468                    print connectedness[0]
     469                    msg='Riverwall discontinuity -- possible round-off error in'+\
     470                         'finding edges on wall -- try increasing value of tol'
     471                    if(not connectedness[1]):
     472                        raise Exception, msg
     473                barrier()
     474        return
    450475   
    451476    #####################################################################################
     
    462487    #####################################################################################
    463488
    464     def get_vertices_corresponding_to_edgeInds(self, riverwalledgeInds, tol=1.0e-04):
     489    def get_vertices_corresponding_to_edgeInds(self, riverwalledgeInds, checkCoords=True):
    465490        """
    466491         Get indices of vertices corresponding to edges at index riverwalledgeInds
     
    471496        """
    472497
    473         domain=self.domain
    474 
    475         riverwallCentInds=self.get_centroids_corresponding_to_edgeInds(riverwalledgeInds)
     498
     499        #riverwallCentInds=self.get_centroids_corresponding_to_edgeInds(riverwalledgeInds)
    476500
    477501        rwEI_mod3=riverwalledgeInds%3
     
    484508        riverwallV2Inds=riverwalledgeInds+rwV2_adjustment
    485509
     510        if(checkCoords):
     511            ####################################################
     512            # Check that vertices and edges really do correspond
     513            domain=self.domain
     514            # X coordinates
     515            assert( numpy.allclose(
     516                    domain.edge_coordinates[riverwalledgeInds,0],
     517                    0.5*(domain.vertex_coordinates[riverwallV1Inds,0]+domain.vertex_coordinates[riverwallV2Inds,0]))
     518                    )
     519            # Y coordinates
     520            assert( numpy.allclose(
     521                    domain.edge_coordinates[riverwalledgeInds,1],
     522                    0.5*(domain.vertex_coordinates[riverwallV1Inds,1]+domain.vertex_coordinates[riverwallV2Inds,1]))
     523                    )
     524            ####################################################
     525
    486526        return riverwallV1Inds, riverwallV2Inds
    487527   
    488528    #####################################################################################
    489 
    490     def check_riverwall_connectedness(self, warn_only=False, verbose=True, tol=1.0e-04):
    491         """
    492             We expect riverwalls to be connected [unless they pass over a hole]
    493             However, round-off could potentially cause riverwalls to be dis-connected
     529    def is_vertex_on_boundary(self, vertexIndices):
     530        """
     531            Determine whether a vertex is on the boundary of the domain
     532            (i.e. it's connected with an edge that is a boundary edge)
     533
     534            INPUTS: self -- riverwallData
     535                    vertexIndices -- indices of vertices on the domain which are on the riverwall
     536
     537            OUTPUT:
     538                    TRUE if the vertex is on a domain boundary, FALSE otherwise
     539
     540        """
     541        domain=self.domain
     542
     543        # Get edge/vertex indices for boundaries
     544        boundary_index_info=domain.boundary.keys()
     545        boundary_edges=[ boundary_index_info[i][0]*3+boundary_index_info[i][1] for i in range(len(boundary_index_info))]
     546        boundary_edges=numpy.array(boundary_edges)
     547        tmp=self.get_vertices_corresponding_to_edgeInds(boundary_edges, checkCoords=False)
     548        boundary_vertices=numpy.hstack([tmp[0], tmp[1]]).tolist()
     549
     550        # Get 'unique' vertex coordinates on boundary
     551        node_complex=domain.vertex_coordinates[boundary_vertices,0]+1j*domain.vertex_coordinates[boundary_vertices,1]
     552
     553        # Get riverwall vertex coordinates as complex numbers (for equality testing)
     554        complex_vertex_coords=domain.vertex_coordinates[vertexIndices.tolist(),0]+\
     555                                1j*domain.vertex_coordinates[vertexIndices.tolist(),1]
     556
     557        # Flag telling us if the vertex is on the boundary (1=True, 0=False)
     558        isOnBoundary=[ 1 if complex_vertex_coords[i] in node_complex else 0 for i in range(len(complex_vertex_coords))]
     559        isOnBoundary=numpy.array(isOnBoundary)
     560
     561        return isOnBoundary
     562
     563    #####################################################################################
     564    def check_riverwall_connectedness(self, verbose=True):
     565        """
     566            We expect riverwalls to be connected
     567             (although they can pass through the bounding polygon several times, especially in parallel)
     568            Round-off can potentially cause riverwalls to be dis-connected
    494569            Use this routine to check for that
    495570
    496571            Basically, we search for edges which are connected to vertices which
    497                 themselves are not connected to other edges
     572                themselves are not connected to other edges. We ignore vertices on the domain's bounding-polygon
    498573           
    499             For a continuous riverwall, this should only occur twice (at the end points)
    500 
    501             Otherwise, the riverwall appears discontinous
     574            For a continuous riverwall, there can be at most 2 endpoints inside the domain
     575
     576            Otherwise, the riverwall is discontinuous, which is an error
     577
    502578        """
    503579
    504580        domain=self.domain
    505581
     582        # Preliminary definitions
     583        isConnected=True
     584        printInfo=''
     585
    506586        if(len(self.names)==0):
    507             print 'There are no riverwalls'
    508             return
     587            if(verbose):
     588                printInfo=printInfo+'  There are no riverwalls (P'+str(myid)+')\n'
     589            return [printInfo, isConnected]
    509590
    510591        # Shorthand notation
    511592        rwd=self
    512            
     593
    513594        for i, name in enumerate(rwd.names):
    514595            # Get indices of edges on this riverwall
    515596            riverwalledgeInds=rwd.riverwall_edges[(rwd.hydraulic_properties_rowIndex==i).nonzero()[0]]
    516             # Get their corresponding centroids
    517             riverwallCentInds=rwd.get_centroids_corresponding_to_edgeInds(riverwalledgeInds)
     597
     598            if(len(riverwalledgeInds)==0):
     599                printInfo=printInfo+'Riverwall '+name+' was not found on this mesh (if this is wrong, adjust tol in create_riverwalls)\n'
     600                continue
    518601            # Get their corresponding vertices
    519             riverwallV1Inds, riverwallV2Inds = rwd.get_vertices_corresponding_to_edgeInds(riverwalledgeInds, tol=tol)
     602            riverwallV1Inds, riverwallV2Inds = rwd.get_vertices_corresponding_to_edgeInds(riverwalledgeInds)
     603
     604            # Flag telling us if vertex points are on the boundary of the model
     605            # Used to help detect disconnected riverwalls (due to round-off)
     606            v1_on_boundary=rwd.is_vertex_on_boundary(riverwallV1Inds)
     607            v2_on_boundary=rwd.is_vertex_on_boundary(riverwallV2Inds)
    520608
    521609            # With discontinuous triangles, we expect edges to occur twice
     
    539627            # Finally, get 'unqiue' edges in the riverwall
    540628            uEdges=riverwalledgeInds[unique_riverwall_edge_indices]
    541             #uCentroids=riverwallCentInds[unique_riverwall_edge_indices]
    542629            uV1=riverwallV1Inds[unique_riverwall_edge_indices]
    543630            uV2=riverwallV2Inds[unique_riverwall_edge_indices]
     631            uV1_boundary=v1_on_boundary[unique_riverwall_edge_indices]
     632            uV2_boundary=v2_on_boundary[unique_riverwall_edge_indices]
    544633
    545634            # Next, count how many times each vertex value occurs.
    546             # For a 'connected' riverwall, we only want 2 edges where a vertex occurs only once.
     635            # For a 'connected' riverwall, we only want 2 edges where a vertex occurs only once,
     636            #   unless the vertex is on the boundary of the domain
    547637            lure=len(uEdges)
    548638            complex_v1_coordinates=domain.vertex_coordinates[uV1,0]+\
     
    558648                             (complex_v2_coordinates==complex_v2_coordinates[j]).sum()
    559649
    560             num_disconnected_edges=(v1Counter==1).sum()+(v2Counter==1).sum()
    561            
     650            num_disconnected_edges=((v1Counter==1)*(1-uV1_boundary)).sum()+\
     651                                   ((v2Counter==1)*(1-uV2_boundary)).sum()
     652         
    562653            if(verbose):   
    563                 print 'There are ', num_disconnected_edges, ' vertices with only 1 connection on riverwall ', name
    564 
    565             if(num_disconnected_edges==0):
    566                 print 'Riverwall '+name+' is not on this mesh [typical for a sub-mesh in parallel]'
    567             elif(num_disconnected_edges==2):
     654                printInfo=printInfo+ '  On riverwall '+ str(name) +' there are '+ str(num_disconnected_edges)+\
     655                         ' endpoints inside the domain [ignoring points on the boundary polygon] (P'+str(myid)+')\n'
     656
     657            if(num_disconnected_edges<=2):
    568658                if(verbose):
    569                     print "  That's Good, it means the wall is continuous"
    570                     print ' '
     659                    pass
     660                    #printInfo=printInfo+ "  This is consistent with a continuous wall \n"
    571661            else:
    572                 msg='Riverwall ' + name +', appears to be discontinuous, possibly due to round-off issues,'+\
    573                     ' be careful [try adjusting tol, or use warn_only=True to avoid error] '
    574                 if(warn_only):
    575                     print msg
    576                 else:
    577                     raise Exception, msg
     662                isConnected=False
     663                printInfo=printInfo+'  Riverwall ' + name +' appears to be discontinuous. (P'+str(myid)+')\n'+\
     664                    '  This suggests there is a gap in the wall, which should not occur\n'
     665       
     666        return [printInfo, isConnected]
     667
     668    ###################################################################
     669
     670    def export_riverwalls_to_text(self, output_dir=None):
     671        """
     672            Function for dumping riverwall outputs to text file (useful for QC)
     673
     674            This will overwrite any existing files with the same location/name
     675
     676            INPUT: output_dir = Directory where the outputs will be written
     677
     678            OUTPUT:
     679                    None, but writes files as a side effect
     680
     681        """
     682        if(output_dir is None):
     683            return
     684   
     685        if(myid==0):
     686            # Make output directory
     687            try:
     688                os.mkdir(output_dir)
     689            except:
     690                pass
     691            # Make output files with empty contents
     692            for i, riverWallFile in enumerate(self.names):
     693                newFile=open(output_dir+'/'+riverWallFile+'.txt','w')
     694                # Write hydraulic variable information
     695                hydraulicVars=self.hydraulic_properties[i,:]
     696                newFile.write('## Hydraulic Variable values below ## \n')
     697                newFile.write(str(self.hydraulic_variable_names)+'\n')
     698                newFile.write(str(hydraulicVars)+'\n')
     699                newFile.write('\n')
     700                newFile.write('## xyElevation at edges below. Order may be erratic for parallel runs ##\n')
     701                newFile.close()
     702        else:
     703            pass
     704
     705        # Files must be created before writing out
     706        barrier()   
     707
     708        domain=self.domain
     709        # Now dump the required info to the files
     710        for i in range(numprocs):
     711            # Write 1 processor at a time
     712            if(myid==i):
     713                for j, riverWallname in enumerate(self.names):
     714                    # Get xyz data for riverwall j
     715                    riverWallInds=(self.hydraulic_properties_rowIndex==j).nonzero()[0].tolist()
     716                    riverWallDomainInds=self.riverwall_edges[riverWallInds].tolist()
     717                    myXCoords=domain.edge_coordinates[riverWallDomainInds,0]+domain.geo_reference.xllcorner
     718                    myYCoords=domain.edge_coordinates[riverWallDomainInds,1]+domain.geo_reference.yllcorner
     719                    myElev=self.riverwall_elevation[riverWallInds]
     720               
     721                    # Open file for appending data
     722                    theFile=open(output_dir+'/'+riverWallname+'.txt','a')
     723                    for k in range(len(myElev)):
     724                        theFile.write(str(myXCoords[k])+','+str(myYCoords[k])+','+str(myElev[k])+'\n')
     725                    theFile.close()
     726                       
     727            else:
     728                pass
     729
     730            barrier()
    578731
    579732        return
    580 
  • trunk/anuga_core/source/anuga/structures/test_riverwall_structure.py

    r9125 r9225  
    3737        pass
    3838   
    39     def create_domain_DE0(self, wallHeight, InitialOceanStage, InitialLandStage):
     39    def create_domain_DE0(self, wallHeight, InitialOceanStage, InitialLandStage, riverWall=None, riverWall_Par=None):
    4040        # Riverwall = list of lists, each with a set of x,y,z (and optional QFactor) values
    41         riverWall={ 'centralWall':
    42                         [ [wallLoc, 0.0, wallHeight],
    43                           [wallLoc, 100.0, wallHeight]]
    44                   }
    45         riverWall_Par={'centralWall':{'Qfactor':1.0}}
     41
     42        if(riverWall is None):
     43            riverWall={ 'centralWall':
     44                            [ [wallLoc, 0.0, wallHeight],
     45                              [wallLoc, 100.0, wallHeight]]
     46                      }
     47        if(riverWall_Par is None):
     48            riverWall_Par={'centralWall':{'Qfactor':1.0}}
    4649        # Make the domain
    4750        anuga.create_mesh_from_regions(boundaryPolygon,
     
    491494        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
    492495   
    493      
    494  
     496    def test_riverwall_includes_specified_points_in_domain(self):
     497        """
     498            Check that all domain points that should be on the riverwall
     499            actually are, and that there are no 'non-riverwall' points on the riverwall
     500        """
     501        wallHeight=-0.2
     502        InitialOceanStage=-0.3
     503        InitialLandStage=-999999.
     504       
     505        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage)
     506
     507        edgeInds_on_wall=domain.riverwallData.riverwall_edges.tolist()
     508
     509        riverWall_x_coord=domain.edge_coordinates[edgeInds_on_wall,0]-wallLoc
     510
     511        assert(numpy.allclose(riverWall_x_coord,0.))
     512   
     513        # Now check that all the other domain edge coordinates are not on the wall
     514        # Note the threshold requires a sufficiently coarse mesh
     515        notriverWall_x_coord=numpy.delete(domain.edge_coordinates[:,0], edgeInds_on_wall)
     516        assert(min(abs(notriverWall_x_coord-wallLoc))>1.0e-01)
     517
     518    def test_is_vertex_on_boundary(self):
     519        """
     520            Check that is_vertex_on_boundary is working as expected
     521        """
     522        wallHeight=-0.2
     523        InitialOceanStage=-0.3
     524        InitialLandStage=-999999.
     525       
     526        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage)
     527
     528        allVertices=numpy.array(range(len(domain.vertex_coordinates)))
     529        boundaryFlag=domain.riverwallData.is_vertex_on_boundary(allVertices)
     530        boundaryVerts=boundaryFlag.nonzero()[0].tolist()
     531
     532        # Check that all boundary vertices are on the boundary
     533        check2=(domain.vertex_coordinates[boundaryVerts,0]==0.)+\
     534               (domain.vertex_coordinates[boundaryVerts,0]==100.)+\
     535               (domain.vertex_coordinates[boundaryVerts,1]==100.)+\
     536               (domain.vertex_coordinates[boundaryVerts,1]==0.)
     537
     538        assert(all(check2>0.))
     539
     540        # Check that all non-boundary vertices are not
     541        nonboundaryVerts=(boundaryFlag==0).nonzero()[0].tolist()
     542        check2=(domain.vertex_coordinates[nonboundaryVerts,0]==0.)+\
     543               (domain.vertex_coordinates[nonboundaryVerts,0]==100.)+\
     544               (domain.vertex_coordinates[nonboundaryVerts,1]==100.)+\
     545               (domain.vertex_coordinates[nonboundaryVerts,1]==0.)
     546
     547        assert(all(check2==0))
     548
     549    def test_multiple_riverwalls(self):
     550        """
     551            Testcase with multiple riverwalls -- check all is working as required
     552
     553         Idea -- add other riverwalls with different Qfactor / height.
     554                 Set them up to have no hydraulic effect, but
     555                 so that we are likely to catch bugs if the code is not right
     556        """
     557        wallHeight=2.
     558        InitialOceanStage=2.50
     559        InitialLandStage=-999999.
     560       
     561       
     562        riverWall={ 'awall1':
     563                        [ [wallLoc+20., 0.0, -9999.],
     564                          [wallLoc+20., 100.0, -9999.]], 
     565                    'centralWall':
     566                        [ [wallLoc, 0.0, wallHeight],
     567                          [wallLoc, 100.0, wallHeight]] ,
     568                    'awall2':
     569                        [ [wallLoc-20., 0.0, 30.],
     570                          [wallLoc-20., 100.0, 30.]], 
     571                  }
     572
     573        newQfac=2.0
     574        riverWall_Par={'centralWall':{'Qfactor':newQfac}, 'awall1':{'Qfactor':100.}, 'awall2':{'Qfactor':0.}}
     575
     576        domain=self.create_domain_DE0(wallHeight,InitialOceanStage, InitialLandStage, riverWall=riverWall,riverWall_Par=riverWall_Par)
     577       
     578
     579        domain.riverwallData.create_riverwalls(riverWall,riverWall_Par,verbose=verbose)
     580
     581        # Run the model for a few fractions of a second
     582        # Any longer, and the evolution of stage starts causing
     583        # significant changes to the flow
     584        yst=1.0e-04
     585        ft=1.0e-03
     586        for t in domain.evolve(yieldstep=yst,finaltime=ft):
     587            if(verbose):
     588                print domain.timestepping_statistics()
     589
     590        # Compare with theoretical result
     591        L= 100. # Length of riverwall
     592        H=InitialOceanStage-wallHeight # Upstream head
     593        dt=ft
     594        theoretical_flux_vol=newQfac*dt*L*2./3.*H*(2./3.*g*H)**0.5
     595
     596        # Indices landward of the riverwall
     597        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
     598        # Compute volume of water landward of riverwall
     599        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]           
     600        landVol=landVol.sum()
     601
     602        if(verbose):
     603            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
     604
     605        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
     606
    495607# =========================================================================
    496608if __name__ == "__main__":
  • trunk/anuga_core/validation_tests/behaviour_only/weir_1/runup.py

    r9224 r9225  
    77
    88import numpy
    9 from anuga import myid, finalize, distribute
     9from anuga import myid, finalize, distribute, barrier
    1010
    1111from math import exp
     
    9898domain = distribute(domain)
    9999
    100 
    101100domain.riverwallData.create_riverwalls(riverWall, riverWall_Par)
    102101
  • trunk/anuga_work/development/gareth/tests/levee/channel_levee.py

    r9105 r9225  
    154154#
    155155print 'Setting riverwall elevations & hydraulic parameters'
    156 domain.riverwallData.create_riverwalls(riverWalls,riverWallPar)
     156domain.riverwallData.create_riverwalls(riverWalls,riverWallPar, output_dir='riverwall_text')
    157157
    158158# Define inlet operator
Note: See TracChangeset for help on using the changeset viewer.