Ignore:
Timestamp:
Mar 19, 2009, 1:43:34 PM (16 years ago)
Author:
rwilson
Message:

Merged trunk into numpy, all tests and validations work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/numpy/anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py

    r6533 r6553  
    8888    # FIXME (Ole): We should rename f to function to be consistent with
    8989    # Transmissive_Momentum_Set_Stage_Boundary (cf posting by rrraman)
    90     def __init__(self, domain = None, f = None):
     90    def __init__(self, domain=None,
     91                 f=None,
     92                 default_boundary=None,
     93                 verbose=False):
    9194        Boundary.__init__(self)
     95        self.default_boundary = default_boundary
     96        self.default_boundary_invoked = False    # Flag
     97        self.domain = domain
     98        self.verbose = verbose
    9299
    93100        try:
     
    122129    def evaluate(self, vol_id=None, edge_id=None):
    123130        # FIXME (Ole): I think this should be get_time(), see ticket:306
    124         return self.f(self.domain.time)
     131        try:
     132            res = self.f(self.domain.time)
     133        except Modeltime_too_early, e:
     134            raise Modeltime_too_early, e
     135        except Modeltime_too_late, e:
     136            if self.default_boundary is None:
     137                raise Exception, e # Reraise exception
     138            else:
     139                # Pass control to default boundary
     140                res = self.default_boundary.evaluate(vol_id, edge_id)
     141               
     142                # Ensure that result cannot be manipulated
     143                # This is a real danger in case the
     144                # default_boundary is a Dirichlet type
     145                # for instance.
     146                res = res.copy()
     147               
     148                if self.default_boundary_invoked is False:
     149                    if self.verbose:               
     150                        # Issue warning the first time
     151                        msg = '%s' %str(e)
     152                        msg += 'Instead I will use the default boundary: %s\n'\
     153                            %str(self.default_boundary)
     154                        msg += 'Note: Further warnings will be supressed'
     155                        print msg
     156               
     157                    # FIXME (Ole): Replace this crude flag with
     158                    # Python's ability to print warnings only once.
     159                    # See http://docs.python.org/lib/warning-filter.html
     160                    self.default_boundary_invoked = True
     161
     162        return res
    125163
    126164
     
    299337                    if self.default_boundary_invoked is False:
    300338                        # Issue warning the first time
    301                         msg = '%s' %str(e)
    302                         msg += 'Instead I will use the default boundary: %s\n'\
    303                             %str(self.default_boundary)
    304                         msg += 'Note: Further warnings will be supressed'
    305                         warn(msg)
     339                        if self.verbose:
     340                            msg = '%s' %str(e)
     341                            msg += 'Instead I will use the default boundary: %s\n'\
     342                                %str(self.default_boundary)
     343                            msg += 'Note: Further warnings will be supressed'
     344                            print msg
    306345                   
    307346                        # FIXME (Ole): Replace this crude flag with
Note: See TracChangeset for help on using the changeset viewer.