def evaluate(self, vol_id=None, edge_id=None):
        # FIXME (Ole): I think this should be get_time(), see ticket:306

        [x,y] = self.domain.get_edge_midpoint_coordinate(vol_id, edge_id)

        try:
            res = self.function(self.domain.get_time(), x, y)
        except Modeltime_too_early, e:
            raise Modeltime_too_early(e)
示例#2
0
    def __call__(self, domain):
        """Apply inflow function at time specified in domain, update stage"""

        # Call virtual method allowing local modifications
        t = domain.get_time()
        try:
            rate = self.update_rate(t)
        except Modeltime_too_early, e:
            raise Modeltime_too_early(e)
    def get_boundary_values(self, t=None):

        if t is None:
            t = self.get_time()
            
        try:
            res = self.f(t)
        except Modeltime_too_early, e:
            raise Modeltime_too_early(e)
    def __call__(self, domain):
        """Apply inflow function at time specified in domain, update stage"""

        # Call virtual method allowing local modifications
        t = domain.get_time(relative_time=self.relative_time)
        try:
            rate = self.update_rate(t)
        except Modeltime_too_early as e:
            raise Modeltime_too_early(e)
        except Modeltime_too_late as e:
            if self.default_rate is None:
                msg = '%s: ANUGA is trying to run longer than specified data.\n' % str(
                    e)
                msg += 'You can specify keyword argument default_rate in the '
                msg += 'forcing function to tell it what to do in the absence of time data.'
                raise Modeltime_too_late(msg)
            else:
                # Pass control to default rate function
                rate = self.default_rate(t)

                if self.default_rate_invoked is False:
                    # Issue warning the first time
                    msg = ('%s\n'
                           'Instead I will use the default rate: %s\n'
                           'Note: Further warnings will be supressed' %
                           (str(e), str(self.default_rate)))
                    warn(msg)

                    # FIXME (Ole): Replace this crude flag with
                    # Python's ability to print warnings only once.
                    # See http://docs.python.org/lib/warning-filter.html
                    self.default_rate_invoked = True

        if rate is None:
            msg = ('Attribute rate must be specified in General_forcing '
                   'or its descendants before attempting to call it')
            raise Exception(msg)

        # Now rate is a number
        if self.verbose is True:
            log.critical(
                'Rate of %s at time = %.2f = %f' %
                (self.quantity_name,
                 domain.get_time(relative_time=self.relative_time), rate))

        if self.exchange_indices is None:
            self.update[:] += rate
        else:
            # Brute force assignment of restricted rate
            for k in self.exchange_indices:
                self.update[k] += rate
    def evaluate(self, vol_id=None, edge_id=None):
        """Return linearly interpolated values based on domain.time
        at midpoint of segment defined by vol_id and edge_id.
        """

        # FIXME (Ole): I think this should be get_time(), see ticket:306
        t = self.domain.time
        
        if vol_id is not None and edge_id is not None:
            i = self.boundary_indices[ vol_id, edge_id ]
            
            try:
                res = self.F(t, point_id=i)
            except Modeltime_too_early, e:
                raise Modeltime_too_early(e)
            except Modeltime_too_late, e:
                if self.default_boundary is None:
                    raise Exception(e) # Reraise exception
                else:
                    # Pass control to default boundary
                    res = self.default_boundary.evaluate(vol_id, edge_id)
                    
                    # Ensure that result cannot be manipulated
                    # This is a real danger in case the 
                    # default_boundary is a Dirichlet type 
                    # for instance. 
                    res = res.copy() 
                    
                    if self.default_boundary_invoked is False:
                        # Issue warning the first time
                        if self.verbose:
                            msg = '%s' %str(e)
                            msg += 'Instead I will use the default boundary: %s\n'\
                                %str(self.default_boundary) 
                            msg += 'Note: Further warnings will be supressed'
                            log.critical(msg)
                   
                        # FIXME (Ole): Replace this crude flag with
                        # Python's ability to print warnings only once.
                        # See http://docs.python.org/lib/warning-filter.html
                        self.default_boundary_invoked = True
    def get_boundary_values(self, t=None):

        if t is None:
            t = self.get_time()

        try:
            res = self.function(t)
        except Modeltime_too_early as e:
            raise Modeltime_too_early(e)
        except Modeltime_too_late as e:
            if self.default_boundary is None:
                raise Modeltime_too_late(e)  # Reraise exception
            else:
                # Pass control to default boundary
                res = self.default_boundary

                # Ensure that result cannot be manipulated
                # This is a real danger in case the
                # default_boundary is a Dirichlet type
                # for instance.
                from copy import deepcopy
                res = deepcopy(res)

                if self.default_boundary_invoked is False:
                    if self.verbose:
                        # Issue warning the first time
                        msg = '%s' % str(e)
                        msg += 'Instead I will use the default boundary value: %s\n'\
                            %str(self.default_boundary)
                        msg += 'Note: Further warnings will be suppressed'
                        log.critical(msg)

                    # FIXME (Ole): Replace this crude flag with
                    # Python's ability to print warnings only once.
                    # See http://docs.python.org/lib/warning-filter.html
                    self.default_boundary_invoked = True

        return res
    def evaluate(self, vol_id=None, edge_id=None):
        # FIXME (Ole): I think this should be get_time(), see ticket:306

        [x, y] = self.domain.get_edge_midpoint_coordinate(vol_id, edge_id)

        try:
            res = self.function(self.domain.get_time(), x, y)
        except Modeltime_too_early as e:
            raise Modeltime_too_early(e)
        except Modeltime_too_late as e:
            if self.default_boundary is None:
                raise Exception(e)  # Reraise exception
            else:
                # Pass control to default boundary
                res = self.default_boundary.evaluate(vol_id, edge_id)

                # Ensure that result cannot be manipulated
                # This is a real danger in case the
                # default_boundary is a Dirichlet type
                # for instance.
                res = res.copy()

                if self.default_boundary_invoked is False:
                    if self.verbose:
                        # Issue warning the first time
                        msg = '%s' % str(e)
                        msg += 'Instead I will use the default boundary: %s\n'\
                            %str(self.default_boundary)
                        msg += 'Note: Further warnings will be supressed'
                        log.critical(msg)

                    # FIXME (Ole): Replace this crude flag with
                    # Python's ability to print warnings only once.
                    # See http://docs.python.org/lib/warning-filter.html
                    self.default_boundary_invoked = True

        return res
示例#8
0
def evaluate_temporal_function(function,
                               t,
                               default_left_value=None,
                               default_right_value=None):

    if callable(function):
        try:
            result = function(t)
        except Modeltime_too_early, e:

            if default_left_value is None:
                msg = '%s: Trying to evaluate function earlier than specified in the data set.\n' % str(
                    e)
                raise Modeltime_too_early(msg)
            else:
                # Pass control to default left function

                warnings.warn('Using default_left_value')
                if callable(default_left_value):
                    result = default_left_value(t)
                else:
                    result = default_left_value

        except Modeltime_too_late, e:
            if default_right_value is None:
                msg = '%s: Trying to evaluate function later than specified in the data set.\n' % str(
                    e)
                raise Modeltime_too_late(msg)
            else:
                # Pass control to default right function

                warnings.warn('Using default_right_value')
                if callable(default_right_value):
                    result = default_right_value(t)
                else:
                    result = default_right_value
    def evaluate(self, vol_id=None, edge_id=None):
        """Return linearly interpolated values based on domain.time
        at midpoint of segment defined by vol_id and edge_id.
        """

        # FIXME (Ole): I think this should be get_time(), see ticket:306
        t = self.domain.time

        if vol_id is not None and edge_id is not None:
            i = self.boundary_indices[vol_id, edge_id]

            try:
                res = self.F(t, point_id=i)
            except Modeltime_too_early as e:
                raise Modeltime_too_early(e)
            except Modeltime_too_late as e:
                if self.default_boundary is None:
                    raise Exception(e)  # Reraise exception
                else:
                    # Pass control to default boundary
                    res = self.default_boundary.evaluate(vol_id, edge_id)

                    # Ensure that result cannot be manipulated
                    # This is a real danger in case the
                    # default_boundary is a Dirichlet type
                    # for instance.
                    res = res.copy()

                    if self.default_boundary_invoked is False:
                        # Issue warning the first time
                        if self.verbose:
                            msg = '%s' % str(e)
                            msg += 'Instead I will use the default boundary: %s\n'\
                                %str(self.default_boundary)
                            msg += 'Note: Further warnings will be supressed'
                            log.critical(msg)

                        # FIXME (Ole): Replace this crude flag with
                        # Python's ability to print warnings only once.
                        # See http://docs.python.org/lib/warning-filter.html
                        self.default_boundary_invoked = True

            if num.any(res == NAN):
                x, y = self.midpoint_coordinates[i, :]
                msg = 'NAN value found in file_boundary at '
                msg += 'point id #%d: (%.2f, %.2f).\n' % (i, x, y)

                if hasattr(self.F, 'indices_outside_mesh') and\
                       len(self.F.indices_outside_mesh) > 0:
                    # Check if NAN point is due it being outside
                    # boundary defined in sww file.

                    if i in self.F.indices_outside_mesh:
                        msg += 'This point refers to one outside the '
                        msg += 'mesh defined by the file %s.\n'\
                               %self.F.filename
                        msg += 'Make sure that the file covers '
                        msg += 'the boundary segment it is assigned to '
                        msg += 'in set_boundary.'
                    else:
                        msg += 'This point is inside the mesh defined '
                        msg += 'the file %s.\n' % self.F.filename
                        msg += 'Check this file for NANs.'
                raise Exception(msg)

            return res
        else:
            msg = 'Boundary call without point_id not implemented.\n'
            msg += 'vol_id=%s, edge_id=%s' % (str(vol_id), str(edge_id))
            raise Exception(msg)