Hello,
I am interested in finding the strains at the nodes of the mesh. The following provides the strain values at Gauss points. How can I extend it to find the strains at the nodes?
import dolfin
mesh = dolfin.UnitSquareMesh(10, 10)
V = dolfin.VectorFunctionSpace(mesh, "Lagrange", 2)
u = dolfin.Function(V)
u.interpolate(dolfin.Expression(("2*x[0]*x[0]", "x[1]"), degree=2))
degree = 2
el = dolfin.FiniteElement("Quadrature", mesh.ufl_cell(),
degree=degree, quad_scheme="default")
Q = dolfin.FunctionSpace(mesh, el)
qh = dolfin.Function(Q)
p = dolfin.TrialFunction(Q)
q = dolfin.TestFunction(Q)
dx = dolfin.Measure("dx", domain=mesh, metadata={
"representation": "quadrature",
"quadrature_degree": degree})
a = dolfin.inner(p, q)*dx
strain = dolfin.sym(dolfin.grad(u))
L = dolfin.inner(strain[0, 0], q)*dx
dolfin.solve(a == L, qh)
Thanks
dokken
December 17, 2022, 8:27am
2
Project the strains into a suitable function space
Thanks for the reply, @dokken !
I tried it, but it does not work for some reason.
strain_at_nodes = project(strain, V)
I got the following error:
UFLException: Shapes do not match: Argument id=5287909344 and Sym id=4847112096.
dokken
December 17, 2022, 10:07am
4
The strain is a tensor, thus you need to create a tensor-function space.
Note that even if the projection is unique, you are projecting a discontinuous quantity into a continuous space.
Is there a specific motivation to have the values at the mesh nodes (where they are non-unique?)
Thanks again, @dokken !
I see.
I tried the following, and it seems that it worked, but it is not able to convert it to numpy array.
V1 = dolfin.TensorFunctionSpace(mesh, "Lagrange", 2)
strain_at_nodes = project(strain, V1)
e11 = strain_at_nodes[0,0]
e11 = e11.vector().get_local()
AttributeError: ‘Indexed’ object has no attribute ‘vector’
Regarding motivation, I just need a rough estimate of the strain values at the nodes.
dokken
December 17, 2022, 10:42am
6
Consider:
import dolfin
mesh = dolfin.UnitSquareMesh(10, 10)
V = dolfin.VectorFunctionSpace(mesh, "Lagrange", 2)
u = dolfin.Function(V)
u.interpolate(dolfin.Expression(("2*x[0]*x[0]", "x[1]"), degree=2))
degree = 2
el = dolfin.FiniteElement("Quadrature", mesh.ufl_cell(),
degree=degree, quad_scheme="default")
Q = dolfin.FunctionSpace(mesh, el)
qh = dolfin.Function(Q)
p = dolfin.TrialFunction(Q)
q = dolfin.TestFunction(Q)
dx = dolfin.Measure("dx", domain=mesh, metadata={
"representation": "quadrature",
"quadrature_degree": degree})
a = dolfin.inner(p, q)*dx
strain = dolfin.sym(dolfin.grad(u))
W = dolfin.TensorFunctionSpace(mesh, "Lagrange", 1)
strain_cg_1 = dolfin.project(strain, W)
strain00 = strain_cg_1.sub(0, deepcopy=True)
strain10 = strain_cg_1.sub(2, deepcopy=True)
print(strain00.function_space().tabulate_dof_coordinates())
print(strain00.vector().get_local())
print(strain10.function_space().tabulate_dof_coordinates())
print(strain10.vector().get_local())
1 Like