def __init__(self):
        def tensor_points(P):
            PP0, PP1 = np.array(np.meshgrid(P, P))
            return np.array((PP0.ravel(), PP1.ravel())).T

        def tensor_weights(W):
            return np.dot(W[:, np.newaxis], W[np.newaxis, :]).ravel()
        self._quadrature_points = [tensor_points(GaussQuadratures.quadrature(npoints=p + 1)[0])
                                   for p in xrange(GaussQuadratures.maxpoints())]
        self._quadrature_weights = [tensor_weights(GaussQuadratures.quadrature(npoints=p + 1)[1])
                                    for p in xrange(GaussQuadratures.maxpoints())]
        self._quadrature_npoints = np.arange(1, GaussQuadratures.maxpoints() + 1) ** 2
        self._quadrature_orders = GaussQuadratures.orders
        self._quadrature_order_map = GaussQuadratures.order_map
Exemple #2
0
 def test_other_functions(self):
     order = GaussQuadratures.orders[-1]
     for name, function, integral in FUNCTIONS:
         Q = GaussQuadratures.iter_quadrature(order)
         ret = sum([function(p) * w for (p, w) in Q])
         assert float_cmp(ret, integral), \
             f'{name} integral wrong: {integral} vs {ret} (quadrature order {order})'
Exemple #3
0
 def test_other_functions(self):
     order = GaussQuadratures.orders[-1]
     for name, function, integral in FUNCTIONS:
         Q = GaussQuadratures.iter_quadrature(order)
         ret = sum([function(p) * w for (p, w) in Q])
         assert float_cmp(ret, integral), '{} integral wrong: {} vs {} (quadrature order {})'.format(
             name, integral, ret, order)
Exemple #4
0
 def test_other_functions(self):
     order = GaussQuadratures.orders[-1]
     for name, function, integral in FUNCTIONS:
         Q = GaussQuadratures.iter_quadrature(order)
         ret = sum([function(p) * w for (p, w) in Q])
         assert float_cmp(ret, integral), '{} integral wrong: {} vs {} (quadrature order {})'.format(
             name, integral, ret, order)
Exemple #5
0
 def quadrature(self, order=None, npoints=None, quadrature_type='default'):
     if quadrature_type == 'default' or quadrature_type == 'gauss':
         P, W = GaussQuadratures.quadrature(order, npoints)
         return P[:, np.newaxis], W
     else:
         raise NotImplementedError(
             'quadrature_type must be "default" or "gauss"')
Exemple #6
0
 def test_other_functions(self):
     order = GaussQuadratures.orders[-1]
     for name, function, integral in FUNCTIONS:
         Q = GaussQuadratures.iter_quadrature(order)
         ret = sum([function(p) * w for (p, w) in Q])
         assert float_cmp(ret, integral), \
             f'{name} integral wrong: {integral} vs {ret} (quadrature order {order})'
Exemple #7
0
 def test_polynomials(self):
     for n, function, _, integral in polynomials(GaussQuadratures.orders[-1]):
         name = 'x^{}'.format(n)
         for order in GaussQuadratures.orders:
             if n > order / 2:
                 continue
             Q = GaussQuadratures.iter_quadrature(order)
             ret = sum([function(p) * w for (p, w) in Q])
             assert float_cmp(ret, integral), '{} integral wrong: {} vs {} (quadrature order {})'.format(
                 name, integral, ret, order)
Exemple #8
0
 def test_polynomials(self):
     for n, function, _, integral in polynomials(GaussQuadratures.orders[-1]):
         name = 'x^{}'.format(n)
         for order in GaussQuadratures.orders:
             if n > order / 2:
                 continue
             Q = GaussQuadratures.iter_quadrature(order)
             ret = sum([function(p) * w for (p, w) in Q])
             assert float_cmp(ret, integral), '{} integral wrong: {} vs {} (quadrature order {})'.format(
                 name, integral, ret, order)
Exemple #9
0
 def __init__(self, flux, flux_derivative, gausspoints=5, intervals=1):
     self.__auto_init(locals())
     self.build_parameter_type(flux, flux_derivative)
     points, weights = GaussQuadratures.quadrature(npoints=self.gausspoints)
     points = points / intervals
     points = ((np.arange(self.intervals, dtype=np.float)[:, np.newaxis] *
                (1 / intervals)) + points[np.newaxis, :]).ravel()
     weights = np.tile(weights, intervals) * (1 / intervals)
     self.points = points
     self.weights = weights
Exemple #10
0
 def test_polynomials(self):
     for n, function, _, integral in polynomials(GaussQuadratures.orders[-1]):
         name = f'x^{n}'
         for order in GaussQuadratures.orders:
             if n > order / 2:
                 continue
             Q = GaussQuadratures.iter_quadrature(order)
             ret = sum([function(p) * w for (p, w) in Q])
             assert float_cmp(ret, integral), \
                 f'{name} integral wrong: {integral} vs {ret} (quadrature order {order})'
Exemple #11
0
 def test_polynomials(self):
     for n, function, _, integral in polynomials(
             GaussQuadratures.orders[-1]):
         name = f'x^{n}'
         for order in GaussQuadratures.orders:
             if n > order / 2:
                 continue
             Q = GaussQuadratures.iter_quadrature(order)
             ret = sum([function(p) * w for (p, w) in Q])
             assert float_cmp(ret, integral), \
                 f'{name} integral wrong: {integral} vs {ret} (quadrature order {order})'
Exemple #12
0
    def __init__(self):
        def tensor_points(P):
            PP0, PP1 = np.array(np.meshgrid(P, P))
            return np.array((PP0.ravel(), PP1.ravel())).T

        def tensor_weights(W):
            return np.dot(W[:, np.newaxis], W[np.newaxis, :]).ravel()

        self._quadrature_points = [
            tensor_points(GaussQuadratures.quadrature(npoints=p + 1)[0])
            for p in range(GaussQuadratures.maxpoints())
        ]
        self._quadrature_weights = [
            tensor_weights(GaussQuadratures.quadrature(npoints=p + 1)[1])
            for p in range(GaussQuadratures.maxpoints())
        ]
        self._quadrature_npoints = np.arange(1,
                                             GaussQuadratures.maxpoints() +
                                             1)**2
        self._quadrature_orders = GaussQuadratures.orders
        self._quadrature_order_map = GaussQuadratures.order_map
Exemple #13
0
 def __init__(self, flux, flux_derivative, gausspoints=5, intervals=1):
     self.flux = flux
     self.flux_derivative = flux_derivative
     self.gausspoints = gausspoints
     self.intervals = intervals
     self.build_parameter_type(inherits=(flux, flux_derivative))
     points, weights = GaussQuadratures.quadrature(npoints=self.gausspoints)
     points = points / intervals
     points = ((np.arange(self.intervals, dtype=np.float)[:, np.newaxis] * (1 / intervals))
               + points[np.newaxis, :]).ravel()
     weights = np.tile(weights, intervals) * (1 / intervals)
     self.points = points
     self.weights = weights
Exemple #14
0
 def test_points(self):
     for order in GaussQuadratures.orders:
         P, _ = GaussQuadratures.quadrature(order)
         assert float_cmp_all(P, np.sort(P))
         assert 0.0 < P[0]
         assert P[-1] < 1.0
Exemple #15
0
 def test_weights(self):
     for order in GaussQuadratures.orders:
         _, W = GaussQuadratures.quadrature(order)
         self.assertAlmostEqual(sum(W), 1)
Exemple #16
0
 def test_points(self):
     for order in GaussQuadratures.orders:
         P, _ = GaussQuadratures.quadrature(order)
         assert float_cmp_all(P, np.sort(P))
         assert 0.0 < P[0]
         assert P[-1] < 1.0
Exemple #17
0
 def test_weights(self):
     for order in GaussQuadratures.orders:
         _, W = GaussQuadratures.quadrature(order)
         assert float_cmp(sum(W), 1)
Exemple #18
0
 def test_points(self):
     for order in GaussQuadratures.orders:
         P, _ = GaussQuadratures.quadrature(order)
         np.testing.assert_array_equal(P, np.sort(P))
         self.assertLess(0.0, P[0])
         self.assertLess(P[-1], 1.0)
Exemple #19
0
 def test_weights(self):
     for order in GaussQuadratures.orders:
         _, W = GaussQuadratures.quadrature(order)
         assert float_cmp(sum(W), 1)
 def quadrature(self, order=None, npoints=None, quadrature_type='default'):
     if quadrature_type == 'default' or quadrature_type == 'gauss':
         P, W = GaussQuadratures.quadrature(order, npoints)
         return P[:, np.newaxis], W
     else:
         raise NotImplementedError('quadrature_type must be "default" or "gauss"')