Extended documentation for InteriorFacetBasis #826
Replies: 1 comment 2 replies
-
Another very important feature of the def plot_normal_arrows(ax):
arrow_style = dict(width=.0, length_includes_head=True, head_width=.025, head_length=.025, facecolor='k', fill=True)
def _form(w):
print('w.x.shape, w.n.shape =', w.x.shape, w.n.shape)
pp = w.x.reshape(2,-1).T # array is shaped to group by facet, but we just want all the points by x,y
nn = w.n.reshape(2,-1).T # array is shaped to group by facet, but we just want all the normals by dx,dy
for p, n in zip(pp, nn):
# when calling functions, (...,*arg,...) will expand the list `arg` as if we had used `...,arg[0],arg[1],etc,...`
ax.arrow(*p, *(0.075*n), **arrow_style) # 0.075 so arrows look nice on this plot
ax.plot(p[0], p[1], 'or')
return w.x[0]
return skfem.Functional(_form)
fig, ax = plt.subplots(1,2,figsize=(12,6))
ax[0].set_title('normal vectors with side==0')
skfem.visuals.matplotlib.plot(cell_basis_p0, f, ax=ax[0], cmap='Set2')
skfem.visuals.matplotlib.draw(mesh, ax=ax[0])
skfem.asm(plot_normal_arrows(ax[0]), fbasis_s0)
ax[1].set_title('normal vectors with side==1')
skfem.visuals.matplotlib.plot(cell_basis_p0, f, ax=ax[1], cmap='Set2')
skfem.visuals.matplotlib.draw(mesh, ax=ax[1])
skfem.asm(plot_normal_arrows(ax[1]), fbasis_s1)
This snippet also shows how |
Beta Was this translation helpful? Give feedback.
-
Let's project a goofey piecewise constant function into P0 on our familiar toy mesh. This function is contrived to index the elements for us, so we can see what happens when we build an interior facet basis.
skfem
can construct a special kind of basis from the interior facets of this mesh. "Interior" facets are those that are an edge for two triangles. This can be contrasted with boundary facets which are an edge for only one triangle.This basis spans the same space as the
CellBasis
we constructed from the same mesh (since we used the same element), but has a different set of quadrature points.Computing the integral of our function on the
CellBasis
is straight forward. The function has a unique value at every quadrature point. We can use theFunctional
decorator and assembly to compute this integral.This should be the area of each triangle times the value in that triangle, all summed up, since this is just a piecewise constant projection.
Now suppose we want the integral along the interior edges only. In the present consideration, that's a single integral over length (as opposed to the double integral over area we just calculated for the
CellBasis
). This is were theInteriorFacetBasis
comes in handy. We should be able to do the exact same assembly... except which value should be used for each edge? Comparing the annotations in the two plots below reveals the problem.This snippet also shows how the
side
argument is used when constructing anInteriorFacetBasis
. It is important to note that this class doesn't directly allow specifying which side to use in a facet-by-facet manner. Nevertheless, changingside
from 0 to 1 will change every the element association for every facet in the set. So, while in theory these integrals over interior facets form a combintorial problem,skfem
makes two (arbitrary) ones readily available:We can easily check these values using some visual inspection of the above plots and integrating over the line segments, keeping in mind for this toy problem everything is piecewise constant.
Beta Was this translation helpful? Give feedback.
All reactions