def run_simulation(parallel=False, verbose=False):

    #--------------------------------------------------------------------------
    # Setup computational domain and quantities
    #--------------------------------------------------------------------------
    domain = rectangular_cross_domain(M, N)
    domain.set_name('odomain')                    # Set sww filename
    domain.set_datadir('.')   
    domain.set_quantity('elevation', topography) # Use function for elevation
    domain.set_quantity('friction', 0.0)         # Constant friction 
    domain.set_quantity('stage', expression='elevation') # Dry initial stage
    
    domain.set_quantities_to_be_stored({'elevation': 2,'stage': 2,'xmomentum': 2,'ymomentum': 2})
    domain.set_store_vertices_uniquely(False)
    domain.set_flow_algorithm('DE1')
    georef = Geo_reference(zone=56,xllcorner=100000.0,yllcorner=200000.0)
    domain.set_georeference(georef)
        
    #--------------------------------------------------------------------------
    # Create pickled partition
    #--------------------------------------------------------------------------
    if myid == 0:
        if verbose: print 'DUMPING PARTITION DATA'
        sequential_distribute_dump(domain, numprocs, verbose=verbose, parameters=new_parameters)    

    #--------------------------------------------------------------------------
    # Create the parallel domains
    #--------------------------------------------------------------------------
    if parallel:
        
        if myid == 0 and verbose : print 'DISTRIBUTING TO PARALLEL DOMAIN'
        pdomain = distribute(domain, verbose=verbose, parameters=new_parameters)
        pdomain.set_name('pdomain')
        
        if myid == 0 and verbose : print 'LOADING IN PARALLEL DOMAIN'
        sdomain = sequential_distribute_load(filename='odomain', verbose = verbose)
        sdomain.set_name('sdomain')
        

        assert domain.get_datadir() == pdomain.get_datadir()
        assert domain.get_store() == pdomain.get_store()
        assert domain.get_store_centroids() == pdomain.get_store_centroids()
        assert domain.smooth == pdomain.smooth
        assert domain.reduction == pdomain.reduction
        assert domain.minimum_storable_height == pdomain.minimum_storable_height
        assert domain.get_flow_algorithm() == pdomain.get_flow_algorithm()
        assert domain.get_minimum_allowed_height() == pdomain.get_minimum_allowed_height()
        assert domain.geo_reference == pdomain.geo_reference
        
        assert domain.get_datadir() == sdomain.get_datadir()
        assert domain.get_store() == sdomain.get_store()
        assert domain.get_store_centroids() == sdomain.get_store_centroids()
        assert domain.smooth == sdomain.smooth
        assert domain.reduction == sdomain.reduction
        assert domain.minimum_storable_height == sdomain.minimum_storable_height
        assert domain.get_flow_algorithm() == sdomain.get_flow_algorithm()
        assert domain.get_minimum_allowed_height() == sdomain.get_minimum_allowed_height()
        assert domain.geo_reference == sdomain.geo_reference
Example #2
0
    def _setup_original_domain(self, np=None):
        """
        Create sequential domain and partition

        """
        verbose = self.verbose
        outname = self.outname
        partition_dir = self.partition_dir

        if np is None:
            np = numprocs

        # Only create the sequential domain on processor 0
        if myid == 0:

            if verbose: print('CREATING PARTITIONED DOMAIN')

            # Let's see if we have already pickled this domain
            pickle_name = outname+'_P%g_%g.pickle'% (1,0)
            pickle_name = join(partition_dir,pickle_name)

            if os.path.exists(pickle_name):
                if verbose: print('Saved domain seems to already exist')
            else:
                domain = self.setup_domain(self)

                if verbose: print('Saving Domain')
                sequential_distribute_dump(domain, 1, partition_dir=partition_dir, verbose=verbose)


            # Now partition the domain


            if verbose: print('Load in saved sequential pickled domain')
            domain = sequential_distribute_load_pickle_file(pickle_name, np=1, verbose = verbose)

            par_pickle_name = outname+'_P%g_%g.pickle'% (np,0)
            par_pickle_name = join(partition_dir,par_pickle_name)
            if os.path.exists(par_pickle_name):
                if verbose: print('Saved partitioned domain seems to already exist')
            else:
                if verbose: print('Dump partitioned domains')
                sequential_distribute_dump(domain, np, partition_dir=partition_dir, verbose=verbose)

        barrier()

        #===============================================================================
        # Setup parallel domain
        #===============================================================================
        if myid == 0 and verbose: print('LOADING PARTITIONED DOMAIN')

        self.domain = sequential_distribute_load(filename=join(partition_dir,outname), verbose = self.verbose)
Example #3
0
    def _setup_original_domain(self, np=None):
        """
        Create sequential domain and partition

        """
        verbose = self.verbose
        outname = self.outname
        partition_dir = self.partition_dir

        if np is None:
            np = numprocs

        # Only create the sequential domain on processor 0
        if myid == 0:

            if verbose: print 'CREATING PARTITIONED DOMAIN'

            # Let's see if we have already pickled this domain
            pickle_name = outname+'_P%g_%g.pickle'% (1,0)
            pickle_name = join(partition_dir,pickle_name)

            if os.path.exists(pickle_name):
                if verbose: print 'Saved domain seems to already exist'
            else:
                domain = self.setup_domain(self)

                if verbose: print 'Saving Domain'
                sequential_distribute_dump(domain, 1, partition_dir=partition_dir, verbose=verbose)


            # Now partition the domain


            if verbose: print 'Load in saved sequential pickled domain'
            domain = sequential_distribute_load_pickle_file(pickle_name, np=1, verbose = verbose)

            par_pickle_name = outname+'_P%g_%g.pickle'% (np,0)
            par_pickle_name = join(partition_dir,par_pickle_name)
            if os.path.exists(par_pickle_name):
                if verbose: print 'Saved partitioned domain seems to already exist'
            else:
                if verbose: print 'Dump partitioned domains'
                sequential_distribute_dump(domain, np, partition_dir=partition_dir, verbose=verbose)

        barrier()

        #===============================================================================
        # Setup parallel domain
        #===============================================================================
        if myid == 0 and verbose: print 'LOADING PARTITIONED DOMAIN'

        self.domain = sequential_distribute_load(filename=join(partition_dir,outname), verbose = self.verbose)
Example #4
0
def run_simulation(parallel=False, verbose=False):

    #--------------------------------------------------------------------------
    # Setup computational domain and quantities
    #--------------------------------------------------------------------------
    if myid == 0:
        domain = rectangular_cross_domain(M, N)
        domain.set_name('odomain')                    # Set sww filename
        domain.set_datadir('.')   
        domain.set_quantity('elevation', topography) # Use function for elevation
        domain.set_quantity('friction', 0.0)         # Constant friction 
        domain.set_quantity('stage', expression='elevation') # Dry initial stage
    else:
        domain = None
        
    #--------------------------------------------------------------------------
    # Create pickled partition
    #--------------------------------------------------------------------------
    if myid == 0:
        if verbose: print 'DUMPING PARTITION DATA'
        sequential_distribute_dump(domain, numprocs, verbose=verbose, parameters=new_parameters)    

    #--------------------------------------------------------------------------
    # Create the parallel domains
    #--------------------------------------------------------------------------
    if parallel:
        
        if myid == 0 and verbose : print 'DISTRIBUTING TO PARALLEL DOMAIN'
        pdomain = distribute(domain, verbose=verbose, parameters=new_parameters)
        pdomain.set_name('pdomain')
        
        if myid == 0 and verbose : print 'LOADING IN PARALLEL DOMAIN'
        sdomain = sequential_distribute_load(filename='odomain', verbose = verbose)
        sdomain.set_name('sdomain')
        
    if myid == 0 and verbose: print 'EVOLVING pdomain'    
    setup_and_evolve(pdomain, verbose=verbose)
 
    if myid == 0 and verbose: print 'EVOLVING sdomain'   
    setup_and_evolve(sdomain, verbose=verbose)
    
    if myid == 0:
        if verbose: print 'EVOLVING odomain'   
        setup_and_evolve(domain, verbose=verbose)
    

    if myid == 0 and verbose:
        parameter_file=open('odomain.txt', 'w')
        from pprint import pprint
        pprint(domain.get_algorithm_parameters(),parameter_file,indent=4)
        parameter_file.close()

        parameter_file=open('sdomain.txt', 'w')
        from pprint import pprint
        pprint(sdomain.get_algorithm_parameters(),parameter_file,indent=4)
        parameter_file.close()

        parameter_file=open('pdomain.txt', 'w')
        from pprint import pprint
        pprint(pdomain.get_algorithm_parameters(),parameter_file,indent=4)
        parameter_file.close()        
    
    assert num.allclose(pdomain.quantities['stage'].centroid_values, sdomain.quantities['stage'].centroid_values)
    assert num.allclose(pdomain.quantities['stage'].vertex_values, sdomain.quantities['stage'].vertex_values)
    
    assert num.allclose(pdomain.vertex_coordinates, sdomain.vertex_coordinates)
    assert num.allclose(pdomain.centroid_coordinates, sdomain.centroid_coordinates)
    
    

    #---------------------------------
    # Now compare the merged sww files
    #---------------------------------
    if myid == 0:
        if verbose: print 'COMPARING SWW FILES'
        
        odomain_v = util.get_output('odomain.sww')
        odomain_c = util.get_centroids(odomain_v)

        pdomain_v = util.get_output('pdomain.sww')
        pdomain_c = util.get_centroids(pdomain_v)
        
        sdomain_v = util.get_output('sdomain.sww')
        sdomain_c = util.get_centroids(sdomain_v)

        # Test some values against the original ordering
        
        if verbose:
            
            order = 2
            print 'PDOMAIN CENTROID VALUES'
            print num.linalg.norm(odomain_c.x-pdomain_c.x,ord=order)
            print num.linalg.norm(odomain_c.y-pdomain_c.y,ord=order)
            print num.linalg.norm(odomain_c.stage[-1]-pdomain_c.stage[-1],ord=order)
            print num.linalg.norm(odomain_c.xmom[-1]-pdomain_c.xmom[-1],ord=order)
            print num.linalg.norm(odomain_c.ymom[-1]-pdomain_c.ymom[-1],ord=order)
            print num.linalg.norm(odomain_c.xvel[-1]-pdomain_c.xvel[-1],ord=order)
            print num.linalg.norm(odomain_c.yvel[-1]-pdomain_c.yvel[-1],ord=order)        
            
             
            print 'SDOMAIN CENTROID VALUES'        
            print num.linalg.norm(odomain_c.x-sdomain_c.x,ord=order)
            print num.linalg.norm(odomain_c.y-sdomain_c.y,ord=order)
            print num.linalg.norm(odomain_c.stage[-1]-sdomain_c.stage[-1],ord=order)
            print num.linalg.norm(odomain_c.xmom[-1]-sdomain_c.xmom[-1],ord=order)
            print num.linalg.norm(odomain_c.ymom[-1]-sdomain_c.ymom[-1],ord=order)
            print num.linalg.norm(odomain_c.xvel[-1]-sdomain_c.xvel[-1],ord=order)
            print num.linalg.norm(odomain_c.yvel[-1]-sdomain_c.yvel[-1],ord=order)
            
            print 'PDOMAIN VERTEX VALUES'        
            print num.linalg.norm(odomain_v.stage[-1]-pdomain_v.stage[-1],ord=order)
            print num.linalg.norm(odomain_v.xmom[-1]-pdomain_v.xmom[-1],ord=order)
            print num.linalg.norm(odomain_v.ymom[-1]-pdomain_v.ymom[-1],ord=order)
            print num.linalg.norm(odomain_v.xvel[-1]-pdomain_v.xvel[-1],ord=order)
            print num.linalg.norm(odomain_v.yvel[-1]-pdomain_v.yvel[-1],ord=order)
            
            print 'SDOMAIN VERTEX VALUES'     
            print num.linalg.norm(odomain_v.stage[-1]-sdomain_v.stage[-1],ord=order)
            print num.linalg.norm(odomain_v.xmom[-1]-sdomain_v.xmom[-1],ord=order)
            print num.linalg.norm(odomain_v.ymom[-1]-sdomain_v.ymom[-1],ord=order)
            print num.linalg.norm(odomain_v.xvel[-1]-sdomain_v.xvel[-1],ord=order)
            print num.linalg.norm(odomain_v.yvel[-1]-sdomain_v.yvel[-1],ord=order)
            
            
            

        assert num.allclose(odomain_c.stage,pdomain_c.stage)
        assert num.allclose(odomain_c.xmom,pdomain_c.xmom)
        assert num.allclose(odomain_c.ymom,pdomain_c.ymom)
        assert num.allclose(odomain_c.xvel,pdomain_c.xvel)
        assert num.allclose(odomain_c.yvel,pdomain_c.yvel)
        
        assert num.allclose(odomain_v.x,pdomain_v.x)
        assert num.allclose(odomain_v.y,pdomain_v.y)
                
        assert num.linalg.norm(odomain_v.x-pdomain_v.x,ord=0) == 0
        assert num.linalg.norm(odomain_v.y-pdomain_v.y,ord=0) == 0
        assert num.linalg.norm(odomain_v.stage[-1]-pdomain_v.stage[-1],ord=0) < 100
        assert num.linalg.norm(odomain_v.xmom[-1]-pdomain_v.xmom[-1],ord=0) < 100 
        assert num.linalg.norm(odomain_v.ymom[-1]-pdomain_v.ymom[-1],ord=0) < 100
        assert num.linalg.norm(odomain_v.xvel[-1]-pdomain_v.xvel[-1],ord=0) < 100
        assert num.linalg.norm(odomain_v.yvel[-1]-pdomain_v.yvel[-1],ord=0) < 100     
        
        assert num.allclose(odomain_c.x,sdomain_c.x)
        assert num.allclose(odomain_c.y,sdomain_c.y)
        assert num.allclose(odomain_c.stage,sdomain_c.stage)
        assert num.allclose(odomain_c.xmom,sdomain_c.xmom)
        assert num.allclose(odomain_c.ymom,sdomain_c.ymom)
        assert num.allclose(odomain_c.xvel,sdomain_c.xvel)
        assert num.allclose(odomain_c.yvel,sdomain_c.yvel)
        
        assert num.allclose(odomain_v.x,sdomain_v.x)
        assert num.allclose(odomain_v.y,sdomain_v.y)
        
        order = 0
        assert num.linalg.norm(odomain_v.x-sdomain_v.x,ord=order) == 0
        assert num.linalg.norm(odomain_v.y-sdomain_v.y,ord=order) == 0
        assert num.linalg.norm(odomain_v.stage[-1]-sdomain_v.stage[-1],ord=order) < 100
        assert num.linalg.norm(odomain_v.xmom[-1]-sdomain_v.xmom[-1],ord=order) < 100
        assert num.linalg.norm(odomain_v.ymom[-1]-sdomain_v.ymom[-1],ord=order) < 100
        assert num.linalg.norm(odomain_v.xvel[-1]-sdomain_v.xvel[-1],ord=order) < 100
        assert num.linalg.norm(odomain_v.yvel[-1]-sdomain_v.yvel[-1],ord=order) < 100        
                
        # COMPARE CENTROID PDOMAIN SDOMAIN  
        assert num.allclose(pdomain_c.x,sdomain_c.x)
        assert num.allclose(pdomain_c.y,sdomain_c.y)
        assert num.allclose(pdomain_c.stage[-1],sdomain_c.stage[-1])
        assert num.allclose(pdomain_c.xmom[-1],sdomain_c.xmom[-1])
        assert num.allclose(pdomain_c.ymom[-1],sdomain_c.ymom[-1])
        assert num.allclose(pdomain_c.xvel[-1],sdomain_c.xvel[-1])
        assert num.allclose(pdomain_c.yvel[-1],sdomain_c.yvel[-1])
            
            
        # COMPARE VERTEX PDOMAIN SDOMAIN
        assert num.allclose(pdomain_v.x,sdomain_v.x)
        assert num.allclose(pdomain_v.y,sdomain_v.y)
        assert num.allclose(pdomain_v.stage[-1],sdomain_v.stage[-1])
        assert num.allclose(pdomain_v.xmom[-1],sdomain_v.xmom[-1])
        assert num.allclose(pdomain_v.ymom[-1],sdomain_v.ymom[-1])
        assert num.allclose(pdomain_v.xvel[-1],sdomain_v.xvel[-1])
        assert num.allclose(pdomain_v.yvel[-1],sdomain_v.yvel[-1])   
        
        
        import os
        os.remove('odomain.sww')
        os.remove('pdomain.sww')
        os.remove('sdomain.sww')
        os.remove('odomain_P4_0.pickle')
        os.remove('odomain_P4_1.pickle')
        os.remove('odomain_P4_2.pickle')
        os.remove('odomain_P4_3.pickle')
def run_simulation(parallel=False, verbose=False):

    #--------------------------------------------------------------------------
    # Setup computational domain and quantities
    #--------------------------------------------------------------------------
    domain = rectangular_cross_domain(M, N)
    domain.set_name('odomain')  # Set sww filename
    domain.set_datadir('.')
    domain.set_quantity('elevation', topography)  # Use function for elevation
    domain.set_quantity('friction', 0.0)  # Constant friction
    domain.set_quantity('stage', expression='elevation')  # Dry initial stage

    domain.set_quantities_to_be_stored({
        'elevation': 2,
        'stage': 2,
        'xmomentum': 2,
        'ymomentum': 2
    })
    domain.set_store_vertices_uniquely(False)
    domain.set_flow_algorithm('DE1')
    georef = Geo_reference(zone=56, xllcorner=100000.0, yllcorner=200000.0)
    domain.set_georeference(georef)

    #--------------------------------------------------------------------------
    # Create pickled partition
    #--------------------------------------------------------------------------
    if myid == 0:
        if verbose: print 'DUMPING PARTITION DATA'
        sequential_distribute_dump(domain,
                                   numprocs,
                                   verbose=verbose,
                                   parameters=new_parameters)

    #--------------------------------------------------------------------------
    # Create the parallel domains
    #--------------------------------------------------------------------------
    if parallel:

        if myid == 0 and verbose: print 'DISTRIBUTING TO PARALLEL DOMAIN'
        pdomain = distribute(domain,
                             verbose=verbose,
                             parameters=new_parameters)
        pdomain.set_name('pdomain')

        if myid == 0 and verbose: print 'LOADING IN PARALLEL DOMAIN'
        sdomain = sequential_distribute_load(filename='odomain',
                                             verbose=verbose)
        sdomain.set_name('sdomain')

        assert domain.get_datadir() == pdomain.get_datadir()
        assert domain.get_store() == pdomain.get_store()
        assert domain.get_store_centroids() == pdomain.get_store_centroids()
        assert domain.smooth == pdomain.smooth
        assert domain.reduction == pdomain.reduction
        assert domain.minimum_storable_height == pdomain.minimum_storable_height
        assert domain.get_flow_algorithm() == pdomain.get_flow_algorithm()
        assert domain.get_minimum_allowed_height(
        ) == pdomain.get_minimum_allowed_height()
        assert domain.geo_reference == pdomain.geo_reference

        assert domain.get_datadir() == sdomain.get_datadir()
        assert domain.get_store() == sdomain.get_store()
        assert domain.get_store_centroids() == sdomain.get_store_centroids()
        assert domain.smooth == sdomain.smooth
        assert domain.reduction == sdomain.reduction
        assert domain.minimum_storable_height == sdomain.minimum_storable_height
        assert domain.get_flow_algorithm() == sdomain.get_flow_algorithm()
        assert domain.get_minimum_allowed_height(
        ) == sdomain.get_minimum_allowed_height()
        assert domain.geo_reference == sdomain.geo_reference
Example #6
0
def run_simulation(parallel=False, verbose=False):

    #--------------------------------------------------------------------------
    # Setup computational domain and quantities
    #--------------------------------------------------------------------------
    domain = rectangular_cross_domain(M, N)
    domain.set_name('odomain')                    # Set sww filename
    domain.set_datadir('.')   
    domain.set_quantity('elevation', topography) # Use function for elevation
    domain.set_quantity('friction', 0.0)         # Constant friction 
    domain.set_quantity('stage', expression='elevation') # Dry initial stage
    
    domain.set_quantities_to_be_stored({'elevation': 2,'stage': 2,'xmomentum': 2,'ymomentum': 2})
    domain.set_store_vertices_uniquely(False)
    domain.set_flow_algorithm('DE1')
    georef = Geo_reference(zone=56,xllcorner=100000.0,yllcorner=200000.0)
    domain.set_georeference(georef)
        
    #--------------------------------------------------------------------------
    # Create pickled partition
    #--------------------------------------------------------------------------
    if myid == 0:
        if verbose: print('DUMPING PARTITION DATA')
        sequential_distribute_dump(domain, numprocs, verbose=verbose, parameters=new_parameters)    

    #--------------------------------------------------------------------------
    # Create the parallel domains
    #--------------------------------------------------------------------------
    if parallel:
        
        if myid == 0 and verbose : print('DISTRIBUTING TO PARALLEL DOMAIN')
        pdomain = distribute(domain, verbose=verbose, parameters=new_parameters)
        pdomain.set_name('pdomain')
        
        if myid == 0 and verbose : print('LOADING IN PARALLEL DOMAIN')
        sdomain = sequential_distribute_load(filename='odomain', verbose = verbose)
        sdomain.set_name('sdomain')
        
        if myid == 0 and verbose : print('TESTING AGAINST SEQUENTIAL DOMAIN')
        assert domain.get_datadir() == pdomain.get_datadir()
        assert domain.get_store() == pdomain.get_store()
        assert domain.get_store_centroids() == pdomain.get_store_centroids()
        assert domain.smooth == pdomain.smooth
        assert domain.reduction == pdomain.reduction
        assert domain.minimum_storable_height == pdomain.minimum_storable_height
        assert domain.get_flow_algorithm() == pdomain.get_flow_algorithm()
        assert domain.get_minimum_allowed_height() == pdomain.get_minimum_allowed_height()
        assert domain.geo_reference == pdomain.geo_reference
        
        assert domain.get_datadir() == sdomain.get_datadir()
        assert domain.get_store() == sdomain.get_store()
        assert domain.get_store_centroids() == sdomain.get_store_centroids()
        assert domain.smooth == sdomain.smooth
        assert domain.reduction == sdomain.reduction
        assert domain.minimum_storable_height == sdomain.minimum_storable_height
        assert domain.get_flow_algorithm() == sdomain.get_flow_algorithm()
        assert domain.get_minimum_allowed_height() == sdomain.get_minimum_allowed_height()
        assert domain.geo_reference == sdomain.geo_reference

        if myid == 0 and verbose : print('REMOVING DATA FILES')
        if myid == 0:
            import os
            #os.remove('odomain.sww')
            #os.remove('pdomain.sww')
            #os.remove('sdomain.sww')
            try:
                os.remove('odomain_P4_0.pickle')
                os.remove('odomain_P4_1.pickle')
                os.remove('odomain_P4_2.pickle')
                os.remove('odomain_P4_3.pickle')
                import glob
                [ os.remove(fl) for fl in glob.glob('*.npy') ]
            except: 
                if verbose: print('remove files failed')

        if myid == 0 and verbose : print('FINISHED')