Ignore:
Timestamp:
Sep 20, 2009, 6:35:14 PM (15 years ago)
Author:
steve
Message:

Have been playing with using a slope limited velocity to calculate
fluxes (hence the addition of evolved_quantities as well as conserved
quantities.

But the commit is to fix a problem Rudy found with sww2dem. Seems
numpy.array2string is a little too clever, in that it summarizes
output if there is a long sequence of zeros to
[0.0, 0.0, 0.0, ... 0.0, 0.0 ,0.0] To get around this I have added
a call to numpy.set_options(threshold=sys.max_int) to turn this
behaviour off!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py

    r7498 r7519  
    6565                       boundary=None,
    6666                       conserved_quantities=None,
     67                       evolved_quantities=None,
    6768                       other_quantities=None,
    6869                       tagged_elements=None,
     
    9091          conserved_quantities: List of quantity names entering the
    9192                                conservation equations
     93          evolved_quantities:   List of all quantities that evolve
    9294          other_quantities:     List of other quantity names
    9395
     
    154156            self.conserved_quantities = conserved_quantities
    155157
     158        if evolved_quantities is None:
     159            self.evolved_quantities = self.conserved_quantities
     160        else:
     161            self.evolved_quantities = evolved_quantities
     162           
    156163        # List of other quantity names
    157164        if other_quantities is None:
     
    160167            self.other_quantities = other_quantities
    161168
     169        # Test that conserved_quantities are stored in the first entries of evolved_quantities
     170        for i, quantity in enumerate(self.conserved_quantities):
     171            msg = 'The conserved quantities must be the first entries of evolved_quantities'
     172            assert quantity == self.evolved_quantities[i], msg
     173           
     174
    162175        # Build dictionary of Quantity instances keyed by quantity names
    163176        self.quantities = {}
    164177
    165         for name in self.conserved_quantities:
     178        for name in self.evolved_quantities:
    166179            self.quantities[name] = Quantity(self)
    167180        for name in self.other_quantities:
     
    325338        return self.mesh.get_number_of_nodes(*args, **kwargs)
    326339
     340    def get_number_of_triangles(self, *args, **kwargs):
     341        return self.mesh.get_number_of_triangles(*args, **kwargs)   
     342
    327343    def get_normal(self, *args, **kwargs):
    328344        return self.mesh.get_normal(*args, **kwargs)
     
    415431
    416432        return q
     433
     434    ##
     435    # @brief Get evolved quantities for a volume.
     436    # @param vol_id ID of the volume we want the conserved quantities for.
     437    # @param vertex If specified, use as index for edge values.
     438    # @param edge If specified, use as index for edge values.
     439    # @return Vector of conserved quantities.
     440    # @note If neither 'vertex' or 'edge' specified, use centroid values.
     441    # @note If both 'vertex' and 'edge' specified, raise exception.
     442    def get_evolved_quantities(self, vol_id,
     443                               vertex=None,
     444                               edge=None):
     445        """Get evolved quantities at volume vol_id.
     446
     447        If vertex is specified use it as index for vertex values
     448        If edge is specified use it as index for edge values
     449        If neither are specified use centroid values
     450        If both are specified an exeception is raised
     451
     452        Return value: Vector of length == number_of_conserved quantities
     453        """
     454
     455        if not (vertex is None or edge is None):
     456            msg = 'Values for both vertex and edge was specified.'
     457            msg += 'Only one (or none) is allowed.'
     458            raise Exception, msg
     459
     460        q = num.zeros(len(self.evolved_quantities), num.float)
     461
     462        for i, name in enumerate(self.evolved_quantities):
     463            Q = self.quantities[name]
     464            if vertex is not None:
     465                q[i] = Q.vertex_values[vol_id, vertex]
     466            elif edge is not None:
     467                q[i] = Q.edge_values[vol_id, edge]
     468            else:
     469                q[i] = Q.centroid_values[vol_id]
     470
     471        return q
     472
     473  ##
     474    # @brief
     475    # @param flag
     476    def set_CFL(self, cfl=1.0):
     477        """Set CFL parameter, warn if greater than 1.0
     478        """
     479        if cfl > 1.0:
     480            self.CFL = cfl
     481            log.warn('Setting CFL > 1.0')
     482
     483        assert cfl > 0.0
     484        self.CFL = cfl
     485
     486
    417487
    418488    ##
     
    876946            assert quantity in self.quantities, msg
    877947
    878         ##assert hasattr(self, 'boundary_objects')
     948
     949        for i, quantity in enumerate(self.conserved_quantities):
     950            msg = 'Conserved quantities must be the first entries of evolved_quantities'
     951            assert quantity == self.evolved_quantities[i], msg
     952 
    879953
    880954    ##
     
    16541728
    16551729    ##
    1656     # @brief Backup conserved quantities.
     1730    # @brief Backup conserved quantities 
    16571731    def backup_conserved_quantities(self):
    1658         N = len(self) # Number_of_triangles
    16591732
    16601733        # Backup conserved_quantities centroid values
     
    16641737
    16651738    ##
    1666     # @brief ??
    1667     # @param a ??
    1668     # @param b ??
     1739    # @brief Combines current C and saved centroid values S as C = aC + bS
     1740    # @param a factor in combination
     1741    # @param b factor in combination
    16691742    def saxpy_conserved_quantities(self, a, b):
    1670         N = len(self) #number_of_triangles
    16711743
    16721744        # Backup conserved_quantities centroid values
     
    16751747            Q.saxpy_centroid_values(a, b)
    16761748
     1749           
     1750
     1751
     1752    ##
     1753    # @brief Mapping between conserved quantites and evolved quantities
     1754    # @param q_cons array of conserved quantity values
     1755    # @param q_evolved array of current evolved quantity values
     1756    def  conserved_to_evolved(self, q_cons, q_evolved):
     1757        """Needs to be overridden by Domain subclass
     1758        """
     1759
     1760        if len(q_cons) == len(q_evolved):
     1761            q_evolved[:] = q_cons
     1762        else:
     1763            msg = 'Method conserved_to_evolved must be overridden by Domain subclass'
     1764            raise Exception, msg
     1765   
    16771766    ##
    16781767    # @brief Update boundary values for all conserved quantities.
     
    16921781                log.critical('WARNING: Ignored boundary segment (None)')
    16931782            else:
    1694                 q = B.evaluate(vol_id, edge_id)
    1695 
    1696                 for j, name in enumerate(self.conserved_quantities):
     1783                q_cons = B.evaluate(vol_id, edge_id)
     1784
     1785                if len(q_cons) == len(self.evolved_quantities):
     1786                    # conserved and evolved quantities are the same
     1787                    q_evol = q_cons
     1788                elif len(q_cons) == len(self.conserved_quantities):
     1789                    # boundary just returns conserved quantities
     1790                    # Need to calculate all the evolved quantities
     1791                    # Use default conversion
     1792
     1793                    q_evol = self.get_evolved_quantities(vol_id, edge = edge_id)
     1794
     1795                    self.conserved_to_evolved(q_cons, q_evol)
     1796                else:
     1797                    msg = 'Boundary must return array of either conserved or evolved quantities'
     1798                    raise Exception, msg
     1799               
     1800                for j, name in enumerate(self.evolved_quantities):
    16971801                    Q = self.quantities[name]
    1698                     Q.boundary_values[i] = q[j]
     1802                    Q.boundary_values[i] = q_evol[j]
    16991803
    17001804    ##
Note: See TracChangeset for help on using the changeset viewer.