本文整理汇总了Python中pymor.tools.quadratures.GaussQuadratures类的典型用法代码示例。如果您正苦于以下问题:Python GaussQuadratures类的具体用法?Python GaussQuadratures怎么用?Python GaussQuadratures使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GaussQuadratures类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
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
示例2: test_other_functions
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)
示例3: test_other_functions
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})'
示例4: test_polynomials
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)
示例5: test_polynomials
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})'
示例6: __init__
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
示例7: quadrature
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"')
示例8: test_points
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
示例9: test_weights
def test_weights(self):
for order in GaussQuadratures.orders:
_, W = GaussQuadratures.quadrature(order)
assert float_cmp(sum(W), 1)
示例10: test_points
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)
示例11: test_weights
def test_weights(self):
for order in GaussQuadratures.orders:
_, W = GaussQuadratures.quadrature(order)
self.assertAlmostEqual(sum(W), 1)