### How to find the quadrature points and weights of a mesh?

241
views
1
6 months ago by
Hi,

Is there any way to find all the quadrature points and weights of a given function space? I tried the solution in this post, but it does not work for the current version of fenics.
https://fenicsproject.org/qa/9633/quadrature-points?show=9633#q9633​

Community: FEniCS Project

2
6 months ago by
Based on the post you mentioned and on https://fenicsproject.org/qa/9635/quadrature-element and https://fenicsproject.org/qa/3932/accessing-the-coordinates-of-a-degree-of-freedom, this should work in the current version
from fenics import *

mesh = UnitSquareMesh(10, 10)
gdim = mesh.geometry().dim()

cell = mesh.ufl_cell(),
degree = 2,

xq = V.tabulate_dof_coordinates().reshape((-1, gdim))
xq0 = xq[V.sub(0).dofmap().dofs()]
​
Thanks for the reply. This code works for finding the quadrature points. Will there be any way to find the associate quadrature weight? Like in this post:
https://fenicsproject.org/qa/12309/quadrature-weights (which does not work either).
written 6 months ago by Mohan Wu
The code from the post works with
from ffc.fiatinterface import create_quadrature​
written 6 months ago by Adam Janecka
This will give the quadrature points and weights for a reference cell, how to get this relation for the global index?
written 6 months ago by Mohan Wu
There surely must be a better solution but I was only able to come up with this ugly (hopefully correct) one:
from __future__ import print_function

from fenics import *

mesh = UnitSquareMesh(2, 2)
gdim = mesh.geometry().dim()

shape = mesh.ufl_cell()
degree = 4
scheme = 'default'

cell = shape,
degree = degree,

xq = V.tabulate_dof_coordinates().reshape((-1, gdim))

print('\n\t Point \t\t\t Weight')
for i in range(len(xq)):
u = Function(V)
u.vector()[i] = 1.0;
print(xq[i], ':\t', assemble(u*dx))

(points, weights) = create_quadrature(str(shape), degree, scheme)
print('\nReference element:')
print(' Points:\n', points)
print(' Weights:\n', weights)
​
written 6 months ago by Adam Janecka