Skip to content

Commit

Permalink
Use TensorProductQuadrature instead of Quadrature in `TensorProdu…
Browse files Browse the repository at this point in the history
…ctElementGroupBase` (#436)

* create TensorProductQuadrature by default instead of Quadrature in TP element groups

* use all 1d bases and 1d nodes to create quadrature

* fix ruff complaints

* unpack in loop header

Co-authored-by: Alex Fikl <alexfikl@gmail.com>

* small change

* clean ups; check that nodes match

---------

Co-authored-by: Alex Fikl <alexfikl@gmail.com>
  • Loading branch information
a-alveyblanc and alexfikl authored Oct 11, 2024
1 parent 75c8fa8 commit 6bfbc81
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions meshmode/discretization/poly_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,30 @@ def basis_obj(self):

@memoize_method
def quadrature_rule(self):
basis = self._basis
nodes = self._nodes
mass_matrix = mp.mass_matrix(basis, nodes)
weights = np.dot(mass_matrix,
np.ones(len(basis.functions)))
return mp.Quadrature(nodes, weights, exact_to=self.order)
from modepy.tools import reshape_array_for_tensor_product_space

quads = []

if self.dim != 1:
nodes_tp = reshape_array_for_tensor_product_space(self.space,
self._nodes)
else:
nodes_tp = self._nodes

for idim, (nodes, basis) in enumerate(zip(nodes_tp, self._basis.bases)):
# get current dimension's nodes from fastest varying axis
nodes = nodes[*(0,)*idim, :, *(0,)*(self.dim-idim-1)]

nodes_1d = nodes.reshape(1, -1)
mass_matrix = mp.mass_matrix(basis, nodes_1d)
weights = np.dot(mass_matrix, np.ones(len(basis.functions)))

quads.append(mp.Quadrature(nodes_1d, weights, exact_to=self.order))

tp_quad = mp.TensorProductQuadrature(quads)
assert np.allclose(tp_quad.nodes, self._nodes)

return tp_quad

@property
@memoize_method
Expand Down

0 comments on commit 6bfbc81

Please sign in to comment.