Changeset 8455


Ignore:
Timestamp:
Jul 5, 2012, 5:17:34 PM (13 years ago)
Author:
steve
Message:

Added in a Set_stage_operator

Location:
trunk/anuga_core/source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/__init__.py

    r8447 r8455  
    150150
    151151
    152 
     152indent = '   '
    153153
    154154#-----------------------------
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/generic_domain.py

    r8420 r8455  
    113113
    114114        self.number_of_boundaries = self.mesh.number_of_boundaries
     115        self.boundary_length = self.mesh.boundary_length
     116        self.tag_boundary_cells = self.mesh.tag_boundary_cells
    115117        #self.number_of_full_nodes = self.mesh.number_of_full_nodes
    116118        #self.number_of_full_triangles = self.mesh.number_of_full_triangles
     
    13161318        self._order_ = self.default_order
    13171319
    1318         assert finaltime > self.get_starttime(), 'finaltime is less than starttime!'
     1320        assert finaltime >= self.get_starttime(), 'finaltime is less than starttime!'
    13191321       
    13201322        if finaltime is not None and duration is not None:
     
    16911693        return q_evol
    16921694   
    1693     def update_boundary(self):
     1695    def update_boundary_old(self):
    16941696        """Go through list of boundary objects and update boundary values
    16951697        for all conserved quantities on boundary.
     
    17281730                    Q = self.quantities[name]
    17291731                    Q.boundary_values[i] = q_evol[j]
     1732
     1733
     1734    def update_boundary_old_2(self):
     1735        """Go through list of boundary objects and update boundary values
     1736        for all conserved quantities on boundary.
     1737        It is assumed that the ordering of conserved quantities is
     1738        consistent between the domain and the boundary object, i.e.
     1739        the jth element of vector q must correspond to the jth conserved
     1740        quantity in domain.
     1741        """
     1742
     1743
     1744        for i in range(self.boundary_length):
     1745            vol_id  = self.boundary_cells[i]
     1746            edge_id = self.boundary_edges[i]
     1747            blah, B = self.boundary_objects[i]
     1748
     1749            if B is None:
     1750                log.critical('WARNING: Ignored boundary segment (None)')
     1751            else:
     1752                q_bdry = B.evaluate(vol_id, edge_id)
     1753
     1754                if len(q_bdry) == len(self.evolved_quantities):
     1755                    # conserved and evolved quantities are the same
     1756                    q_evol = q_bdry
     1757                elif len(q_bdry) == len(self.conserved_quantities):
     1758                    # boundary just returns conserved quantities
     1759                    # Need to calculate all the evolved quantities
     1760                    # Use default conversion
     1761
     1762                    q_evol = self.get_evolved_quantities(vol_id, edge = edge_id)
     1763
     1764                    q_evol = self.conserved_values_to_evolved_values \
     1765                                                            (q_bdry, q_evol)
     1766                else:
     1767                    msg = 'Boundary must return array of either conserved'
     1768                    msg += ' or evolved quantities'
     1769                    raise Exception(msg)
     1770
     1771                for j, name in enumerate(self.evolved_quantities):
     1772                    Q = self.quantities[name]
     1773                    Q.boundary_values[i] = q_evol[j]
     1774
     1775
     1776
     1777#        for i, ((vol_id, edge_id), B) in enumerate(self.boundary_objects):
     1778#            if B is None:
     1779#                log.critical('WARNING: Ignored boundary segment (None)')
     1780#            else:
     1781#                q_bdry = B.evaluate(vol_id, edge_id)
     1782#
     1783#                if len(q_bdry) == len(self.evolved_quantities):
     1784#                    # conserved and evolved quantities are the same
     1785#                    q_evol = q_bdry
     1786#                elif len(q_bdry) == len(self.conserved_quantities):
     1787#                    # boundary just returns conserved quantities
     1788#                    # Need to calculate all the evolved quantities
     1789#                    # Use default conversion
     1790#
     1791#                    q_evol = self.get_evolved_quantities(vol_id, edge = edge_id)
     1792#
     1793#                    q_evol = self.conserved_values_to_evolved_values \
     1794#                                                            (q_bdry, q_evol)
     1795#                else:
     1796#                    msg = 'Boundary must return array of either conserved'
     1797#                    msg += ' or evolved quantities'
     1798#                    raise Exception(msg)
     1799#
     1800#                for j, name in enumerate(self.evolved_quantities):
     1801#                    Q = self.quantities[name]
     1802#                    Q.boundary_values[i] = q_evol[j]
     1803
     1804
     1805    def update_boundary(self):
     1806        """Go through list of boundary objects and update boundary values
     1807        for all conserved quantities on boundary.
     1808        It is assumed that the ordering of conserved quantities is
     1809        consistent between the domain and the boundary object, i.e.
     1810        the jth element of vector q must correspond to the jth conserved
     1811        quantity in domain.
     1812        """
     1813
     1814
     1815        for tag in self.tag_boundary_cells:
     1816
     1817            #print tag
     1818           
     1819            B = self.boundary_map[tag]
     1820           
     1821            #if B is None:
     1822            #        log.critical('WARNING: Ignored boundary segment (None)')
     1823
     1824            for i in self.tag_boundary_cells[tag]:
     1825                vol_id  = self.boundary_cells[i]
     1826                edge_id = self.boundary_edges[i]
     1827
     1828                if B is None:
     1829                    pass
     1830                else:
     1831                    q_bdry = B.evaluate(vol_id, edge_id)
     1832
     1833                    if len(q_bdry) == len(self.evolved_quantities):
     1834                        # conserved and evolved quantities are the same
     1835                        q_evol = q_bdry
     1836                    elif len(q_bdry) == len(self.conserved_quantities):
     1837                        # boundary just returns conserved quantities
     1838                        # Need to calculate all the evolved quantities
     1839                        # Use default conversion
     1840
     1841                        q_evol = self.get_evolved_quantities(vol_id, edge = edge_id)
     1842
     1843                        q_evol = self.conserved_values_to_evolved_values \
     1844                                                                (q_bdry, q_evol)
     1845                    else:
     1846                        msg = 'Boundary must return array of either conserved'
     1847                        msg += ' or evolved quantities'
     1848                        raise Exception(msg)
     1849
     1850                    for j, name in enumerate(self.evolved_quantities):
     1851                        Q = self.quantities[name]
     1852                        Q.boundary_values[i] = q_evol[j]
     1853
    17301854
    17311855    def compute_fluxes(self):
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/neighbour_mesh.py

    r8280 r8455  
    191191        #Update boundary indices FIXME: OBSOLETE
    192192        #self.build_boundary_structure()
     193
     194
    193195
    194196        #FIXME check integrity?
     
    376378
    377379        self.boundary = boundary
     380        self.boundary_length = len(self.boundary)
    378381
    379382
     
    402405        return self.tagged_elements
    403406
    404     def build_boundary_structure(self):
    405         """Traverse boundary and
    406         enumerate neighbour indices from -1 and
    407         counting down.
    408 
    409         Precondition:
    410             self.boundary is defined.
    411         Post condition:
    412             neighbour array has unique negative indices for boundary
    413             boundary_segments array imposes an ordering on segments
    414             (not otherwise available from the dictionary)
    415 
    416         Note: If a segment is listed in the boundary dictionary
    417         it *will* become a boundary - even if there is a neighbouring triangle.
    418         This would be the case for internal boundaries
    419         """
    420 
    421         #FIXME: Now Obsolete - maybe use some comments from here in
    422         #domain.set_boundary
    423 
    424         if self.boundary is None:
    425             msg = 'Boundary dictionary must be defined before '
    426             msg += 'building boundary structure'
    427             raise Exception(msg)
    428 
    429 
    430         self.boundary_segments = self.boundary.keys()
    431         self.boundary_segments.sort()
    432 
    433         index = -1
    434         for id, edge in self.boundary_segments:
    435 
    436             #FIXME: One would detect internal boundaries as follows
    437             #if self.neighbours[id, edge] > -1:
    438             #    log.critical('Internal boundary')
    439 
    440             self.neighbours[id, edge] = index
    441 
    442             self.boundary_enumeration[id,edge] = index
    443 
    444             index -= 1
    445 
     407#    def build_boundary_structure(self):
     408#        """Traverse boundary and
     409#        enumerate neighbour indices from -1 and
     410#        counting down.
     411#
     412#        Precondition:
     413#            self.boundary is defined.
     414#        Post condition:
     415#            neighbour array has unique negative indices for boundary
     416#            boundary_segments array imposes an ordering on segments
     417#            (not otherwise available from the dictionary)
     418#
     419#        Note: If a segment is listed in the boundary dictionary
     420#        it *will* become a boundary - even if there is a neighbouring triangle.
     421#        This would be the case for internal boundaries
     422#        """
     423#
     424#        #FIXME: Now Obsolete - maybe use some comments from here in
     425#        #domain.set_boundary
     426#
     427#        if self.boundary is None:
     428#            msg = 'Boundary dictionary must be defined before '
     429#            msg += 'building boundary structure'
     430#            raise Exception(msg)
     431#
     432#
     433#        self.boundary_segments = self.boundary.keys()
     434#        self.boundary_segments.sort()
     435#
     436#        index = -1
     437#        for id, edge in self.boundary_segments:
     438#
     439#            #FIXME: One would detect internal boundaries as follows
     440#            #if self.neighbours[id, edge] > -1:
     441#            #    log.critical('Internal boundary')
     442#
     443#            self.neighbours[id, edge] = index
     444#
     445#            self.boundary_enumeration[id,edge] = index
     446#
     447#            index -= 1
     448#
    446449
    447450
     
    467470        self.boundary_enumeration = {}
    468471
     472
     473
    469474        X = self.boundary.keys()
    470475        X.sort()
    471476
     477        #print 'X', X
    472478        index = -1
    473479        for id, edge in X:
     
    484490
    485491        for id, edge in X:
    486 
    487492            j = self.boundary_enumeration[id,edge]
    488493            self.boundary_cells[j] = id
    489494            self.boundary_edges[j] = edge
    490495
     496        # For each tag create list of boundary edges
     497        self.tag_boundary_cells = {}
     498
     499        tags = self.get_boundary_tags()
     500
     501        #print tags
     502
     503        for tag in tags:
     504            self.tag_boundary_cells[tag] = []
     505
     506
     507        for j in range(self.boundary_length):
     508            id  = self.boundary_cells[j]
     509            edge = self.boundary_edges[j]
     510            tag = self.boundary[id, edge]
     511            #print tag, id, edge
     512            self.tag_boundary_cells[tag].append(j)
     513
     514
     515        #print self.tag_boundary_cells
    491516
    492517    def get_boundary_tags(self):
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py

    r8164 r8455  
    7272
    7373        # Allocate space for boundary values
    74         self.boundary_length = L = len(domain.boundary)
     74        #self.boundary_length = domain.boundary_length
     75        self.boundary_length = L = self.domain.boundary_length
    7576        self.boundary_values = num.zeros(L, num.float)
    7677
  • trunk/anuga_core/source/anuga/file/test_sww.py

    r8405 r8455  
    4141        yiel=0.01
    4242        points, vertices, boundary = rectangular(10,10)
     43
     44        #print "=============== boundary rect ======================="
     45        #print boundary
    4346
    4447        #Create shallow water domain
     
    7679            pass
    7780
     81        #print boundary
    7882
    7983
     
    8185        domain2 = load_sww_as_domain(filename, None, fail_if_NaN=False,
    8286                                        verbose=self.verbose)
     87
     88        # Unfortunately we loss the boundaries top, bottom, left and right,
     89        # they are now all lumped into "exterior"
     90
     91        #print "=============== boundary domain2 ======================="
     92        #print domain2.boundary
     93       
     94
     95        #print domain2.get_boundary_tags()
     96       
    8397        #points, vertices, boundary = rectangular(15,15)
    8498        #domain2.boundary = boundary
     
    110124        domain.set_quantity('friction', 0.1)
    111125        domain.store = False
    112         domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
     126        domain.set_boundary({'exterior': Bd, 'left' : Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
    113127
    114128
     
    131145        #print 'domain2.boundary'
    132146        #print domain2.boundary
    133         domain2.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
     147        domain2.set_boundary({'exterior': Bd, 'left' : Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
    134148        #domain2.set_boundary({'exterior': Bd})
    135149
  • trunk/anuga_core/source/anuga/operators/run_set_stage.py

    r8454 r8455  
    6060from anuga.operators.set_value_operators import Circular_set_stage_operator
    6161
    62 cop1 = Circular_set_stage_operator(domain, stage=h0+20.0, center=(0.0, 0.0), radius=100.0 )
    63 cop2 = Circular_set_stage_operator(domain, stage=h0+20.0, center=(2000.0, 1000.0), radius=100.0 )
     62import math
     63
     64stage1 = lambda t: h0 + 20.0 * math.sin(t/3.0)
     65cop1 = Circular_set_stage_operator(domain, stage=stage1, center=(0.0, 0.0), radius=100.0 )
     66
     67stage2 = lambda t: h0 + 30.0 * math.sin(t/6.0)
     68cop2 = Circular_set_stage_operator(domain, stage=stage2, center=(2000.0, 1000.0), radius=100.0 )
    6469
    6570#print cop1.statistics()
  • trunk/anuga_core/source/anuga/shallow_water/shallow_water_domain.py

    r8418 r8455  
    304304        self.store = flag
    305305
     306    def get_store(self):
     307        """Get whether data saved to sww file.
     308        """
     309
     310        return self.store
     311
    306312       
    307313    def set_sloped_mannings_function(self, flag=True):
     
    342348        """Get method for computing fluxes.
    343349
    344         Currently
    345            original
    346            wb_1
     350        See set_compute_fluxes_method for possible choices.
    347351        """
    348352
     
    10101014
    10111015
     1016   
    10121017    def evolve(self,
    10131018               yieldstep=None,
  • trunk/anuga_core/source/anuga/shallow_water/shallow_water_ext.c

    r8400 r8455  
    451451
    452452    /*Compute fluxes between volumes for the shallow water wave equation
    453       cast in terms of the 'stage', w = h+z using
    454       the 'central scheme' as described in
    455 
    456       Kurganov, Noelle, Petrova. 'Semidiscrete Central-Upwind Schemes For
    457       Hyperbolic Conservation Laws and Hamilton-Jacobi Equations'.
    458       Siam J. Sci. Comput. Vol. 23, No. 3, pp. 707-740.
    459 
    460       The implemented formula is given in equation (3.15) on page 714
     453     * cast in terms of the 'stage', w = h+z using
     454     * the 'central scheme' as described in
     455     *
     456     * Kurganov, Noelle, Petrova. 'Semidiscrete Central-Upwind Schemes For
     457     * Hyperbolic Conservation Laws and Hamilton-Jacobi Equations'.
     458     * Siam J. Sci. Comput. Vol. 23, No. 3, pp. 707-740.
     459     *
     460     * The implemented formula is given in equation (3.15) on page 714.
     461     *
     462     * The pressure term is calculated using simpson's rule so that it
     463     * will well balance with the standard ghz_x gravity term
    461464     */
    462465
     
    464467    int i;
    465468    //double hl, hr;
    466     double uh_left, vh_left, u_left;
    467     double uh_right, vh_right, u_right;
     469    double uh_left, vh_left, u_left, v_left;
     470    double uh_right, vh_right, u_right, v_right;
    468471    double s_min, s_max, soundspeed_left, soundspeed_right;
    469472    double denom, inverse_denominator;
     
    531534    // Momentum in y-direction
    532535    vh_left = q_left_rotated[2];
     536    v_left = _compute_speed(&vh_left, &h_left,
     537            epsilon, h0, limiting_threshold);
     538
    533539    vh_right = q_right_rotated[2];
     540    v_right = _compute_speed(&vh_right, &h_right,
     541            epsilon, h0, limiting_threshold);
    534542
    535543    // Limit y-momentum if necessary
     
    615623            edgeflux[i] *= inverse_denominator;
    616624        }
     625/*
     626        if (edgeflux[0] > 0.0) {
     627            edgeflux[2] = edgeflux[0]*v_left;
     628        } else {
     629            edgeflux[2] = edgeflux[0]*v_right;
     630        }
     631*/
    617632
    618633        // Maximal wavespeed
  • trunk/anuga_core/source/anuga_parallel/parallel_api.py

    r8282 r8455  
    6262        domain_name = domain.get_name()
    6363        domain_dir = domain.get_datadir()
     64        domain_store = domain.get_store()
    6465        georef = domain.geo_reference
    6566        number_of_global_triangles = domain.number_of_triangles
     
    6970
    7071        for p in range(1, numprocs):
    71             send((domain_name, domain_dir, georef, \
     72            send((domain_name, domain_dir, domain_store, georef, \
    7273                  number_of_global_triangles, number_of_global_nodes), p)
    7374    else:
    7475        if verbose: print 'P%d: Receiving domain attributes' %(myid)
    7576
    76         domain_name, domain_dir, georef, \
     77        domain_name, domain_dir, domain_store, georef, \
    7778                  number_of_global_triangles, number_of_global_nodes = receive(0)
    7879
     
    177178    #------------------------------------------------------------------------
    178179    domain.set_name(domain_name)
    179     domain.set_datadir(domain_dir)     
     180    domain.set_datadir(domain_dir)
     181    domain.set_store(domain_store)
    180182    domain.geo_reference = georef   
    181183
  • trunk/anuga_core/source/anuga_parallel/parallel_generic_communications.py

    r8209 r8455  
    3333    """
    3434
    35     pypar.barrier()
     35
    3636
    3737    import time
  • trunk/anuga_core/source/anuga_parallel/parallel_shallow_water.py

    r8301 r8455  
    1818
    1919import numpy as num
     20from os.path import join
    2021
    2122
     
    131132    def sww_merge(self, verbose=False, delete_old=False):
    132133
    133         if self.processor == 0 and self.numproc > 1:
     134        if self.processor == 0 and self.numproc > 1 and self.store :
    134135            import anuga.utilities.sww_merge as merge
     136
     137            global_name = join(self.get_datadir(),self.get_global_name())
    135138           
    136             merge.sww_merge_parallel(self.get_global_name(),self.numproc,verbose,delete_old)
     139            merge.sww_merge_parallel(global_name,self.numproc,verbose,delete_old)
    137140
    138141
  • trunk/anuga_core/source/anuga_parallel/run_parallel_sw_merimbula.py

    r8447 r8455  
    8585    domain = create_domain_from_file(mesh_filename)
    8686    domain.set_quantity('stage', Set_Stage(x0, x1, 2.0))
     87    domain.set_datadir('Data')
     88    domain.set_name('merimbula_new')
     89    domain.set_store(False)
    8790    #domain.set_quantity('elevation', Set_Elevation(500.0))
    8891
     
    106109#--------------------------------------------------------------------------
    107110
     111   
    108112#domain.smooth = False
    109113domain.set_default_order(2)
     
    111115#domain.set_CFL(0.7)
    112116#domain.set_beta(1.5)
    113 domain.set_name('merimbula')
     117
    114118
    115119#for p in range(numprocs):
     
    144148t0 = time.time()
    145149
    146 for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
     150for t in domain.evolve(yieldstep = yieldtime, finaltime = finaltime):
    147151    if myid == 0:
    148152        domain.write_time()
Note: See TracChangeset for help on using the changeset viewer.