Minimal example
from dolfin import *
from ufl import JacobianInverse, indices
T = 1
num_steps = 10
dt = T/num_steps
mesh = UnitSquareMesh(2,2)
# Define Function Spaces
V = VectorElement("Lagrange", mesh.ufl_cell(), 1)
W = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
R = FiniteElement("Real", mesh.ufl_cell(), 0)
me = MixedElement([V, W, R])
Z= FunctionSpace(mesh,me)
###Define Test and trial function
up = Function(Z)
u, p, rho = split(up)
v, q, lamda = TestFunctions(Z)
u_exact = Expression(("20*x[0]*x[0]*(1-x[0])*(1-x[0])*x[1]*(2-3*x[1])","-20*x[1]*x[1]*(1-x[1])*(2*x[0]-6*x[0]*x[0]+4*x[0]*x[0]*x[0])"), domain=mesh, degree = 4, t=0)
u_n = project(u_exact,Z.sub(0).collapse())
# define weak formulation
nu=0.01
K = JacobianInverse(mesh)
i, j, k = indices(3)
G = as_tensor(K[k, i]*K[k, j], (i, j))
g = as_vector(K[k, i], i)
T_M = pow(((1/(dt*dt))+inner(u,dot(u,G))+30*nu*nu*inner(G,G)),-0.5)
T_C = pow((dot(inner(T_M,g),g)),-1)
error:
hwloc/linux: Ignoring PCI device with non-16bit domain.
Pass --enable-32bits-pci-domain to configure to support such devices
(warning: it would break the library ABI, don't enable unless really needed).
hwloc/linux: Ignoring PCI device with non-16bit domain.
Pass --enable-32bits-pci-domain to configure to support such devices
(warning: it would break the library ABI, don't enable unless really needed).
Shapes do not match: <Power id=140559681360192> and <ComponentTensor id=140559685521376>.
Traceback (most recent call last):
File "/home/ayush/cc.py", line 31, in <module>
T_C = pow((dot(inner(T_M,g),g)),-1)
File "/usr/lib/python3/dist-packages/ufl/operators.py", line 158, in inner
return Inner(a, b)
File "/usr/lib/python3/dist-packages/ufl/tensoralgebra.py", line 147, in __new__
error("Shapes do not match: %s and %s." % (ufl_err_str(a), ufl_err_str(b)))
File "/usr/lib/python3/dist-packages/ufl/log.py", line 158, in error
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Shapes do not match: <Power id=140559681360192> and <ComponentTensor id=140559685521376>.
I am trying to write equation 3.27 given in above screenshot.