Hi,
I tried to implement a symmetric tensor form in a variational problem as you suggested. I simplified the code to give you an idea of whta does not work. Basically only the non-diagonal results are given. This beahirvoir I see also when using
TensorFunctionSpace(mesh, 'Lagrange', 2,symmetry=True)
.
However with the method above I also get different results then using M=TensorFunctionSpace(mesh, 'Lagrange', 2)
. Basically hte cahnges in th enon diagonal part are very small. Could you help me further?
from fenics import *
mesh=UnitSquareMesh(10,10)
Me = VectorElement(“Lagrange”, mesh.ufl_cell(), 2, dim=3)
M = FunctionSpace(mesh, Me)
#In a_n as initial condition
a_0 = Expression(((‘0’, ‘1’, ‘0’)), degree=2)
a_n_v = project(a_0, M)
a_n = as_tensor([[a_n_v[0], a_n_v[1]],
[a_n_v[1], a_n_v[2]]])
#a_t as TrialTensor and a m as TestTensor
a_vec = TrialFunction(M)
a_t = as_tensor([[a_vec[0], a_vec[2]],
[a_vec[2], a_vec[1]]])
m_vec = TestFunction(M)
m = as_tensor([[m_vec[0], m_vec[2]],
[m_vec[2], m_vec[1]]])
#a as solution
a=Function(M)
#Variational example problem
k=Constant(0.01)
Fa = inner((a_t - a_n) / k, m)dx +
-2inner(a_n,m)*dx
a4=lhs(Fa)
L4=rhs(Fa)
#Construct matrics
A4=assemble(a4)
#Solve iteration
num_steps=10
t = 0
for n in range(num_steps):
b4 = assemble(L4)
solve(A4, a.vector(),b4)
print('print a value of a', a(0.5,0.5))
a_n=as_tensor([[a[0], a[2]],
[a[2], a[1]]])
Thanks!