Dear FEniCSx community,
I am trying to compute a stress vector in one of the boundaries of my geometry. In order to achieve this, I need to define the stress tensor and the normal vector associated to that boundary, and take the dot product of both variables.
The problem is that if I define the normal vector as usual, i.e., n=FacetNormal(mesh)
, I get the normal vector of all the boundaries. Therefore, if I take the dot product of the stress tensor and the normal vector, I get the stress vector over all the boundaries.
Is it possible to define the normal vector of, for example, the left boundary?
Here is a minimal example:
# Import
import dolfinx
from ufl import Identity, div, dot, ds, dx, inner, lhs, grad, nabla_grad, rhs, sym, FacetNormal
from ufl import FiniteElement, VectorElement, TrialFunctions, TestFunctions, MixedElement
from mpi4py import MPI
# Mesh
mesh = dolfinx.UnitSquareMesh(MPI.COMM_WORLD, 10, 10)
n = FacetNormal(mesh)
# Function spaces
v_cg2 = VectorElement('CG', mesh.ufl_cell(), 2)
p_cg1 = FiniteElement('CG', mesh.ufl_cell(), 1)
mel = MixedElement([v_cg2, p_cg1])
V = dolfinx.FunctionSpace(mesh, v_cg2)
Q = dolfinx.FunctionSpace(mesh, p_cg1)
u_n = dolfinx.fem.Function(V)
p_n = dolfinx.fem.Function(Q)
# Stress tensor
mu = 0.01
def sigma(u, p):
return 2*mu*sym(nabla_grad(u)) - p*Identity(u.geometric_dimension())
# Stress vector
stress = dot(sigma(u_n,p_n),n)
Many thanks in advance.