# Cannot align integratoin points and weights in a mesh cell

**URL:** <https://fenicsproject.discourse.group/t/cannot-align-integratoin-points-and-weights-in-a-mesh-cell/12283>\
**Category:** General\
**Created:** [September 25, 2023, 7:53am UTC](https://fenicsproject.discourse.group/t/cannot-align-integratoin-points-and-weights-in-a-mesh-cell/12283 "2023-09-25T07:53:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![xi\_wang](https://avatars.discourse-cdn.com/v4/letter/x/8c91f0/32.png) [@xi\_wang](https://fenicsproject.discourse.group/u/xi_wang)\
**Post date:** [September 25, 2023, 7:53am UTC](https://fenicsproject.discourse.group/t/cannot-align-integratoin-points-and-weights-in-a-mesh-cell/12283/1 "2023-09-25T07:53:25Z")

</div>

With dolfin and ffc, I found the post to generate physical quadrature points in the following post.

[quadrature points](https://fenicsproject.discourse.group/t/how-to-determine-gauss-point-coordinates-in-a-mesh/5027/4)

Since there is no weights, I use create\_quadrature trying to get the quadrature weights. These two block of codes are run as follows:

```auto
# fristly get the quad points
import ffc
from dolfin import *

mesh = UnitSquareMesh(1, 1)

el = FiniteElement("Quadrature", mesh.ufl_cell(), degree=1, quad_scheme="default")
V = FunctionSpace(mesh, el)
print(V.tabulate_dof_coordinates())

points, weights = ffc.fiatinterface.create_quadrature(mesh.cell_name(), degree=1, scheme="default")
print(points, weights)

```

Get the result:

Calling FFC just-in-time (JIT) compiler, this may take some time.  
[[0.66666667 0.33333333]  
[0.33333333 0.66666667]]  
[[0.33333333 0.33333333]] [0.5]

With the same mesh cell, they generate different number of quadrature points, let alone match them precisely. How can I get the quadrature points and relevant weights of a physical mesh cell ?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [September 25, 2023, 10:44am UTC](https://fenicsproject.discourse.group/t/cannot-align-integratoin-points-and-weights-in-a-mesh-cell/12283/2 "2023-09-25T10:44:03Z")

</div>

> [@xi\_wang](#):
>
> `points, weights = ffc.fiatinterface.create_quadrature(mesh.cell_name(), degree=1, scheme="default")`

This quadrature is based on the reference element.

The quadrature extracted with:

> [@xi\_wang](#):
>
> `print(V.tabulate_dof_coordinates())`

Gives you the quadrature points in physical space, i.e.

```python
# fristly get the quad points
import ffc
from dolfin import *

mesh = UnitSquareMesh(1, 1)

el = FiniteElement("Quadrature", mesh.ufl_cell(), degree=2, quad_scheme="default")
V = FunctionSpace(mesh, el)
x = V.tabulate_dof_coordinates()

for cell in cells(mesh):
    print(V.dofmap().cell_dofs(cell.index()), x[V.dofmap().cell_dofs(cell.index())])

```

gives you

```bash
[1 0 2] [[0.33333333 0.16666667]
 [0.83333333 0.66666667]
 [0.83333333 0.16666667]]
[4 3 5] [[0.16666667 0.33333333]
 [0.66666667 0.83333333]
 [0.16666667 0.83333333]]

```

which are the three quadrature points in each cell.

---

<div class="post-metadata">

**Author:** ![xi\_wang](https://avatars.discourse-cdn.com/v4/letter/x/8c91f0/32.png) [@xi\_wang](https://fenicsproject.discourse.group/u/xi_wang)\
**Post date:** [September 25, 2023, 11:31am UTC](https://fenicsproject.discourse.group/t/cannot-align-integratoin-points-and-weights-in-a-mesh-cell/12283/3 "2023-09-25T11:31:21Z")

</div>

Thanks. I see that the mesh function gives two triangular elements for the square. With the following code

```auto
# fristly get the quad points
import ffc
from dolfin import *

degree=4

mesh = UnitSquareMesh(1, 1)

el = FiniteElement("Quadrature", mesh.ufl_cell(), degree=degree, quad_scheme="default")
V = FunctionSpace(mesh, el)
x = V.tabulate_dof_coordinates()

print("\n physical cel")

for cell in cells(mesh):
    print("cell",cell.index(),"cell nodes",V.dofmap().cell_dofs(cell.index()),'\n', x[V.dofmap().cell_dofs(cell.index())],'\n')

print("\nreference cel, cell name is " ,mesh.cell_name())
points, weights = ffc.fiatinterface.create_quadrature(mesh.cell_name(), degree=degree, scheme="default")
print("weights of ref cel: \n", weights)

```

I get the results:

```auto
 physical cel
cell 0 cell nodes [1 0 2 3 4 5] 
 [[0.90842379 0.09157621]
 [0.90842379 0.81684757]
 [0.18315243 0.09157621]
 [0.55405151 0.44594849]
 [0.55405151 0.10810302]
 [0.89189698 0.44594849]] 

cell 1 cell nodes [7 6 8 9 10 11] 
 [[0.09157621 0.90842379]
 [0.81684757 0.90842379]
 [0.09157621 0.18315243]
 [0.44594849 0.55405151]
 [0.10810302 0.55405151]
 [0.44594849 0.89189698]] 

reference cel, cell name is triangle
weights of ref cel: 
 [0.05497587 0.05497587 0.05497587 0.11169079 0.11169079 0.11169079]

```

Does it mean that I can multiply the weights form the ref cel accordingly with the quad points above? Do the quad points from the physical cell automatically align with the weights from the ref cell?

---

<div class="post-metadata">

**Author:** ![xi\_wang](https://avatars.discourse-cdn.com/v4/letter/x/8c91f0/32.png) [@xi\_wang](https://fenicsproject.discourse.group/u/xi_wang)\
**Post date:** [September 25, 2023, 11:38am UTC](https://fenicsproject.discourse.group/t/cannot-align-integratoin-points-and-weights-in-a-mesh-cell/12283/4 "2023-09-25T11:38:53Z")

</div>

The sum of weights should equal to the volume of the physical cell. If I just use the quad weights from the ref cell, it surely won’t get correct integration because the volume of general physical cell != volume of the ref cell.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [September 25, 2023, 11:44am UTC](https://fenicsproject.discourse.group/t/cannot-align-integratoin-points-and-weights-in-a-mesh-cell/12283/5 "2023-09-25T11:44:41Z")

</div>

Now you are mixing quadrature weights and the absolute value of the determinant of the Jacobian of the mapping from the physical element to the reference element.

That determinant can be found as shown here: [Spatial coordinate local values - #4 by dokken](https://fenicsproject.discourse.group/t/spatial-coordinate-local-values/11021/4)

---

<div class="post-metadata">

**Author:** ![xi\_wang](https://avatars.discourse-cdn.com/v4/letter/x/8c91f0/32.png) [@xi\_wang](https://fenicsproject.discourse.group/u/xi_wang)\
**Post date:** [September 25, 2023, 11:54am UTC](https://fenicsproject.discourse.group/t/cannot-align-integratoin-points-and-weights-in-a-mesh-cell/12283/6 "2023-09-25T11:54:07Z")

</div>

Thanks, got it. So the order of weights in ref cell will exactly match with the order of quad points in physical cell, right?

> [@Cannot align integratoin points and weights in a mesh cell](https://fenicsproject.discourse.group/t/cannot-align-integratoin-points-and-weights-in-a-mesh-cell/12283/3):
>
> Thanks. I see that the mesh function gives two triangular elements for the square. With the following code # fristly get the quad points import ffc from dolfin import \* degree=4 mesh = UnitSquareMesh(1, 1) el = FiniteElement("Quadrature", mesh.ufl\_cell(), degree=degree, quad\_scheme="default") V = FunctionSpace(mesh, el) x = V.tabulate\_dof\_coordinates() print("\n physical cel") for cell in cells(mesh): print("cell",cell.index(),"cell nodes",V.dofmap().cell\_dofs(cell.index()),'\n', x[V.…

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [September 25, 2023, 2:22pm UTC](https://fenicsproject.discourse.group/t/cannot-align-integratoin-points-and-weights-in-a-mesh-cell/12283/7 "2023-09-25T14:22:18Z")

</div>

> [@xi\_wang](#):
>
> Thanks, got it. So the order of weights in ref cell will exactly match with the order of quad points in physical cell, right?

Yes, they should match.
