Hello everyone,
I am using the FEniCSx documentation and blow is my code. I don’t know why I got a this error:
.
And here is my code:
import numpy as np
from mpi4py import MPI
from petsc4py import PETSc
from dolfinx import fem, io, plot
from dolfinx import mesh as Mesh
from dolfinx.mesh import locate_entities_boundary
from dolfinx.fem import VectorFunctionSpace, TensorFunctionSpace, Function
from dolfinx.io import XDMFFile
from dolfinx.io import gmshio
import meshio
from petsc4py.PETSc import ScalarType
from ufl import (SpatialCoordinate, TestFunction, TrialFunction,
dx, grad, inner, FacetNormal, VectorElement, TensorElement, FiniteElement, MixedElement, FunctionSpace,
TrialFunctions, TestFunctions, ds)
from dolfinx.mesh import create_unit_square
… Reading mesh file
mesh = create_unit_square(MPI.COMM_WORLD, 10, 10)
… Define Loading
L = 1000e-9
H = 100e-9
h = 20e-9
… Define Elements
v = VectorElement(“CG”, mesh.ufl_cell(), 2) # Displacement
s = TensorElement(“CG”, mesh.ufl_cell(), 1) # Relaxed strain
lm = TensorElement(“CG”, mesh.ufl_cell(), 1) # Lagrange multipliers
p = FiniteElement(“CG”, mesh.ufl_cell(), 1) # Electric Potential
… Define function spaces
V = FunctionSpace(mesh, v)
S = FunctionSpace(mesh, s)
LM = FunctionSpace(mesh, lm)
P = FunctionSpace(mesh, p)
… Define Trail and Test Functions
u = TrialFunction(V)
del_u = TestFunction(V)
gradu = TrialFunction(S)
del_gradu = TestFunction(S)
lamu = TrialFunction(LM)
del_lamu = TestFunction(LM)
p = TrialFunction(P)
del_p = TestFunction(P)
… Mark boundary regions
def Left(x):
return np.isclose(x[0], 0)
fdim = mesh.topology.dim - 1
boundary_facets = Mesh.locate_entities_boundary(mesh, fdim, Left)
u_D = np.array([0, 0, 0], dtype=ScalarType)
bc = fem.dirichletbc(u_D, fem.locate_dofs_topological(V, fdim, boundary_facets), V)