I used the explanation for using Mixed finite element space as follows
VFS = ufl.VectorElement('CG',domain.ufl_cell(), dim=2)
TFS = ufl.TensorElement('CG', domain.ufl_cell(),degree=2)
mel = MixedElement([VFS,TFS])
V = FunctionSpace(domain, VFS)
Q = FunctionSpace(domain, TFS)
Y = FunctionSpace(domain, mel)
# Trial and test functions
u, q = TrialFunctions(Y)
v, p = TestFunctions(Y)
but now, when I try to induce boundary conditions using the following code:
#impose clamped boundary conditions
def upper_boundary(x):
return np.isclose(x[1],+L/2);
fdim = domain.topology.dim - 1
boundary_facets_up = mesh.locate_entities_boundary(domain, fdim, upper_boundary)
dofs_up = fem.locate_dofs_topological(V, fdim, boundary_facets_up)
u_up = ScalarType((0,+Delta/2))
bc_up = fem.dirichletbc(u_up, dofs_up, V)
I get the the error
TypeError: ‘FunctionSpace’ object is not iterable
What did I do wrong?
dokken
2
You have not added a degree to this element.
Here is a working MWE:
import ufl
import dolfinx
from mpi4py import MPI
from petsc4py import PETSc
import numpy as np
domain = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
VFS = ufl.VectorElement('Lagrange',domain.ufl_cell(), 1, dim=2)
TFS = ufl.TensorElement('Lagrange', domain.ufl_cell(), degree=2)
mel = ufl.MixedElement([VFS,TFS])
V = dolfinx.fem.FunctionSpace(domain, VFS)
Q = dolfinx.fem.FunctionSpace(domain, TFS)
Y = dolfinx.fem.FunctionSpace(domain, mel)
# Trial and test functions
u, q = ufl.TrialFunctions(Y)
v, p = ufl.TestFunctions(Y)
#impose clamped boundary conditions
def upper_boundary(x):
return np.isclose(x[1],1)
Delta = 0.1
fdim = domain.topology.dim - 1
boundary_facets_up = dolfinx.mesh.locate_entities_boundary(domain, fdim, upper_boundary)
dofs_up = dolfinx.fem.locate_dofs_topological(V, fdim, boundary_facets_up)
u_up = PETSc.ScalarType((0,+Delta/2))
bc_up = dolfinx.fem.dirichletbc(u_up, dofs_up, V)
Note that you should make all examples reproducible, i.e. should be possible to copy paste and run the code without modifications.