Ignore:
Timestamp:
Aug 14, 2008, 10:26:06 AM (15 years ago)
Author:
ole
Message:

Implemented default_boundary option in File_boundary and Field_boundary as
per ticket:293 and added a note in the user manual.

File:
1 edited

Legend:

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

    r5373 r5657  
    22"""
    33
     4from warnings import warn
     5
    46from anuga.utilities.numerical_tools import NAN   
     7from anuga.fit_interpolate.interpolate import Modeltime_too_late
     8from anuga.fit_interpolate.interpolate import Modeltime_too_early
    59
    610
     
    183187    Note that the resulting solution history is not exactly the same as if
    184188    the models were coupled as there is no feedback into the source model.
     189   
     190    Optional keyword argument default_boundary must be either None or
     191    an instance of class descending from class Boundary.
     192    This will be used in case model time exceeds that available in the
     193    underlying data.
    185194       
    186195    """
     
    189198    # rather than File_boundary
    190199
    191     def __init__(self, filename, domain, time_thinning=1,
    192                  use_cache=False, verbose=False, boundary_polygon=None):
     200    def __init__(self, filename, domain,
     201                 time_thinning=1,
     202                 boundary_polygon=None,   
     203                 default_boundary=None,
     204                 use_cache=False,
     205                 verbose=False):
     206
    193207        import time
    194208        from Numeric import array, zeros, Float
     
    251265                               verbose=verbose,
    252266                               boundary_polygon=boundary_polygon)
    253 
     267                             
     268        # Check and store default_boundary
     269        msg = 'Keyword argument default_boundary must be either None '
     270        msg += 'or a boundary object.\n I got %s' %(str(default_boundary))
     271        assert default_boundary is None or isinstance(default_boundary, Boundary), msg
     272        self.default_boundary = default_boundary
     273        self.default_boundary_invoked = False    # Flag
     274
     275        # Store pointer to domain
    254276        self.domain = domain
     277       
     278        self.verbose = verbose
    255279
    256280        # Test
     
    293317
    294318        t = self.domain.time
     319       
    295320        if vol_id is not None and edge_id is not None:
    296321            i = self.boundary_indices[ vol_id, edge_id ]
    297             res = self.F(t, point_id = i)
     322           
     323           
     324            #res = self.F(t, point_id = i)           
     325            try:
     326                res = self.F(t, point_id = i)
     327            except (Modeltime_too_late, Modeltime_too_early), e:
     328                if self.default_boundary is None:
     329                    raise Exception, e # Reraise exception
     330                else:
     331                    if self.default_boundary_invoked is False:
     332                        # Issue warning the first time
     333                        msg = '%s' %str(e)
     334                        msg += 'Instead I will using the default boundary: %s\n'\
     335                            %str(self.default_boundary)
     336                        msg += 'Note: Further warnings will be supressed'
     337                        warn(msg)
     338                   
     339                        # FIXME (Ole): Replace this crude flag with
     340                        # Python's ability to print warnings only once.
     341                        # See http://docs.python.org/lib/warning-filter.html
     342                        self.default_boundary_invoked = True
     343                   
     344                    # Pass control to default boundary
     345                    res = self.default_boundary.evaluate(vol_id, edge_id)
     346                   
     347               
    298348            if res == NAN:
    299349                x,y=self.midpoint_coordinates[i,:]
Note: See TracChangeset for help on using the changeset viewer.