Howdy so I am interested in how FENICS does:
\int_{\partial \Omega} \frac{\partial u}{\partial n} \phi_i d\partial \Omega.
I tried to implement my own code to do this and compare it againist fenics, and make sure I am consistent with FENICs. In my example \Omega=[0,1]^2. So I equated the boundary integral as just doing 4 single variable integrals over each piece of the square e.g
\int_{\partial \Omega} \frac{\partial u}{\partial n} \phi_i d \partial \Omega = \sum_{k=1}^{4} \int_{\partial \Omega_k} \frac{\partial u}{\partial n} \phi_i d \partial \Omega_k. When I do the parameterization I am assuming a counter clockwise direction and unit normal direction is away to the boundary.
For number of spatial steps in x,y n_x = n_y = 4, u = (1-e^{-40*0.18577451194110492} )\sin(x+y) , and using 1st order CG function space, in fenics I find
[-0.03479013012456555 -0.36843906652131203 0.16037662990915336
-0.44233785896861144 0. 0.03698621853083948
-0.48873422577385034 0. 0.
-0.08870381677587287 -0.5071948204741705 0.
0. 0. -0.17113570884227985
-0.48873422577384973 0. 0.
-0.08870381677587416 -0.44233785896861166 0.
0.03698621853083943 -0.36843906652131264 0.16037662990915247
-0.03479013012456598]
and my approach summing up 4 trapezoid rules yeilds:
[ 3.6011973638567771e-02 3.6372709534368586e-01 -1.5674840269030646e-01
4.3625154263040461e-01 3.7511950124057651e-18 -3.5163886213076721e-02
4.8165211621456028e-01 0.0000000000000000e+00 1.6396557130485909e-20
8.8606939572731996e-02 6.9388939039072284e-18 0.0000000000000000e+00
0.0000000000000000e+00 1.9055622563599055e-20 8.6736173798840355e-18
-4.8165211621456028e-01 0.0000000000000000e+00 -1.1795716457097733e-20
-8.8606939572731983e-02 -4.3625154263040455e-01 -3.6212215813760475e-18
3.5163886213076714e-02 -3.6372709534368580e-01 1.5674840269030646e-01
-3.3849883070490583e-02]
I’m noticing a pattern for my answer is either the answer for a specific \phi_i is consistent (up to error) with the FENICs value, negative of the FENICs value, or is 0 when it FENICS says it is not zero.
To extract the basis functions I do the following:
def basis_func(i,pt):
cell_index = tree.compute_first_entity_collision(Point(*pt))
cell_global_dofs = V.dofmap().cell_dofs(cell_index)
for local_dof in range(0,len(cell_global_dofs)):
if(i==cell_global_dofs[local_dof]):
cell = Cell(mesh, cell_index)
values = np.array([0,])
return V.element().evaluate_basis(local_dof,pt,
cell.get_vertex_coordinates(),
cell.orientation())[0]
# If none of this cell's shape functions map to the i-th basis function,
# then the i-th basis function is zero at x.
return 0.0
def basis_func_list():
list_of_basis_functions=[]
for i in range(0,V.dim()):
list_of_basis_functions +=[(lambda i: lambda x : basis_func_temp(i,x))(i),]
return list_of_basis_functions
my_basis_list =basis_func_list()
My understanding then is if I have point x, to evaluate the ith basis function at this point I would need to only do:
my_basis_list[i](x)
Am I doing something that is not consistent with how fenics would do the boundary integral?
Thank you for the help!