Beispiel #1
0
 def test_check_values(self):
     with self.assertRaises(SystemExit):
         ut.check_value(None, None)
     a = ut.check_value(value=f, default_value=None)
     self.assertEqual(a, f, msg='Expect user defined return')
     a = ut.check_value(value=None, default_value=f)
     self.assertEqual(a, f, msg='Expect default return')
Beispiel #2
0
    def update_weights(self, alpha=None):
        '''
        Update quadrature weights.

        The quadrature weights are a function of :math:`\\alpha`.  To
        facilitate usage of the quadrature object, you can update the
        weights with a new :math:`\\alpha` without creating a whole
        new object.

        Args:
            * **alpha** (:py:class:`float`): Exponent of singular kernel.
        '''
        alpha = check_value(alpha, self.alpha, 'fractional order - alpha')
        self.alpha = alpha
        span = self.singularity - self.lower
        # check if sympy
        if isinstance(self.points, sp.Array):
            coef = self.points.applyfunc(
                lambda x: span**(1-alpha)*(1-x)**(-alpha))
            wtmp = []
            for _, (c, w) in enumerate(zip(coef, self.initial_weights)):
                wtmp.append(c*w)
            self.weights = sp.Array(wtmp)
        else:
            coef = span**(1-alpha)*(1-self.points)**(-alpha)
            self.weights = self.initial_weights*coef
Beispiel #3
0
    def integrate(self, f=None):
        '''
        Evaluate the integral.

        The user can assign a function during initial creation of the
        quadrature object, or they can send it here.

        Kwargs: name (type) - default
            * **f** (def) - `None`: Function handle.

        .. note::
            The function, **f**, should output an array, with
            shape (n,) or (n, 1).
        '''
        f = check_value(f, self.f, 'function - f')
        self.f = f
        # transform kernel
        span = self.upper - self.lower
        # check if sympy
        if isinstance(self.points, sp.Array):
            evalpoints = self.points.applyfunc(
                lambda x: span*x + self.lower)
            feval = evalpoints.applyfunc(f)
            s = 0
            for _, (w, f) in enumerate(zip(self.weights, feval)):
                s += w*f
            return np.float(s)
        else:
            feval = f(span*self.points + self.lower).reshape(
                    self.weights.shape)
            s = (self.weights*(feval)).sum()
            return s
Beispiel #4
0
    def update_weights(self, alpha=None):
        '''
        Update quadrature weights.

        The quadrature weights are a function of :math:`\\alpha`.  To
        facilitate usage of the quadrature object, you can update the
        weights with a new :math:`\\alpha` without creating a whole
        new object.

        Args:
            * **alpha** (:py:class:`float`): Exponent of singular kernel.
        '''
        alpha = check_value(alpha, self.alpha, 'fractional order - alpha')
        self.alpha = alpha
        self.gleg.update_weights(alpha=alpha)
        self.glag.update_weights(alpha=alpha)
Beispiel #5
0
    def integrate(self, f=None):
        '''
        Evaluate the integral.

        The user can assign a function during initial creation of the
        quadrature object, or they can send it here.

        Kwargs: name (type) - default
            * **f** (def) - `None`: Function handle.

        .. note::
            The function, **f**, should output an array, with
            shape (n,) or (n, 1).
        '''
        f = check_value(f, self.f, 'function - f')
        self.f = f
        return self.gleg.integrate(f=f) + self.glag.integrate(f=f)