Hello,
I do not know how to approach a simple 3D problem with FEniCS although I have it figured it out on paper.
I found an expression for the weak form of a particular problem, where a term of that weak form must be of the form “a^T B a” where a is a vector, and B a 3x3 matrix (or rank 2 tensor). The ^T denotes the transpose I’d like to implement it correctly into FEniCS. Note that on paper it’s the product of “matrices” of dimension (1x3) x (3x3) x (3x1) = (1x1), i.e. a scalar.
First of all, a is not given, it must be computed as B^-1 grad(V) - C grad(W) where ^-1 denotes the inverse, V and W are scalar valued functions. B and C are explicitly given.
In my code I have
from fenics import *
import numpy as np
(skipped the mesh and boundary conditions)
B = as_matrix(np.array([[10.0, 0, 0], [0, 10.0, 0], [0, 0, 23.0]]))
C = as_matrix(np.array([[18.0, 0, 0], [0, 18.0, 0], [0, 0, 3.0]]))
u, v = TestFunctions(ME)
VW = Function(ME)
V, W = split(VW)
weak_form = (inv(B)* grad(V) - C * grad(W)) * B * (inv(B) * grad(V) - C * grad(W))
But that line yields the error “UFLException: Invalid ranks 1 and 2 in product.”
I have tried many, many variants (including PETsc matrices, but I did something wrong because the program would not halt). For example using as_tensor() instead of as_matri). I tried to use inner() instead of dot(). I also tried transpose(1st term) * the other 2 terms. I tried nesting innner() and dot(), as to compute first a^T * B and then a^T * B * a. I tried to use nabla_grad instead of grad, etc. All my attempts have failed, some of them returned 0 hit in Google.
Examples of errors were “UFLException: Shapes do not match: <ListTensor id=139896187419224> and <Grad id=139896175492936>.” And “AttributeError: ‘Expression2LatexHandler’ object has no attribute ‘visit’”.
I am really at a loss. I do not know how to approach this problem with FEniCS even though on paper I know how each term should be defined and computed.