As stated by nate, your code is a mixture of import syntax from dolfinx and dolfin, and running your code with the docker container ghcr.io/scientificcomputing/fenics:2023-04-21
yields
Traceback (most recent call last):
File "/root/shared/mwe.py", line 5, in <module>
parameters["form_compiler"]["cpp_optimize"] = True
NameError: name 'parameters' is not defined
as your imports are not correct.
For interpolation syntax of legacy Dolfin, I would advice you to consider the following MWE:
from dolfin import *
parameters["form_compiler"]["quadrature_degree"] = 4
# Overall dimensions of rectangular prism device
scaleX = 2.0
scaleY = 1.0
scaleZ = 1.0
# N number of elements in each direction
Xelem = 2
Yelem = 2
Zelem = 2
# Define a uniformly spaced box mesh
mesh = BoxMesh(Point(0.0, 0.0, 0.0), Point(scaleX, scaleY, scaleZ), Xelem, Yelem, Zelem)
T1 = TensorElement(
"Quadrature",
mesh.ufl_cell(),
degree=parameters["form_compiler"]["quadrature_degree"],
symmetry=True,
shape=(3, 3),
quad_scheme="default",
)
W3 = FunctionSpace(mesh, T1) # Tensor space
A1 = Function(W3)
T = Expression(
(("1.0", "0.0", "0.0"), ("0.0", "1.0", "0.0"), ("0.0", "0.0", "1.0")), degree=1
)
A1.interpolate(T)
Please note that new users are adviced to use DOLFINx: GitHub - FEniCS/dolfinx: Next generation FEniCS problem solving environment as legacy FEniCS has not actively been developed since 2019.
See: The new DOLFINx solver is now recommended over DOLFIN for more details.