I believe this simple question must have been asked at least a million times and yet I still fail to find the answer. What is the simplest way to plot some spatial partial derivative of the solution over a part of the boundary (specified by SubDomain
)? The solution is from a mixed function space of degree higher than 1, but it is alright to get the values of the derivative only on the boundary mesh vertices. I am asking this because I want to plot the wall shear stress (which is just a specific type of flux) along the boundary. I want to get ordered vectors of coordinates of the specified part of the boundary, and of the derivative values at those vertices. Below are some of my recent failed attempts.
def LocalFrictionCoefficient(w,subdomain):
# Inputs
W = w.function_space()
mesh = W.mesh()
# Mark boundary belonging to sub domain
plate_id = 7
ds = BoundaryIntegral(mesh, subdomain, plate_id)
# Get function space for single velocity component
V = W.sub(0).sub(0).collapse()
v = TestFunction(V)
#v2dof = vertex_to_dof_map(V) # this throws an error, so I replace it with:
v2dof = V.dofmap().dofs()
# Compute vector of local shear values
shear = SurfaceShear(w) # some function involving derivatives and boundary normal
form = shear *v *ds(7)
vector = assemble(form)
array = vector.get_local()[v2dof]
return array
I also tried replacing
V = W.sub(0).sub(0).collapse()
v2dof = V.dofmap().dofs()
with
V = FunctionSpace(mesh, "CG", 1)
v2dof = vertex_to_dof_map(V)
but the order of the final array does not seem to match the order of the vertices of the mesh.
Thanks for any hints! I believe most of you are doing this routinely, so there must be some trivial solution. I cannot imagine a more basic task and yet I already spent a crazy amount of time on this.