Hi,
I have posted my question, but it doesn’t show in my posts, hence I’m posting it again…
I’m trying to solve the problem:
grad p + curl ω = f, in Ω
ω − rot u = 0, in Ω
div u = 0, in Ω
u = 0, on ∂Ω.
I’m trying to implement the Dirichlet BC on the velocity u.
The code is as follows:
from dolfinx.io import XDMFFile, gmshio
try:
import gmsh # type: ignore
except ImportError:
print("This demo requires gmsh to be installed")
exit(0)
#----------------------------------------------------
import ufl
import basix.ufl
from dolfinx.mesh import create_unit_square, create_box, CellType
from dolfinx import mesh, fem
from dolfinx.fem import Function, functionspace, Expression, Constant, form, locate_dofs_geometrical
import pyvista # visualizing the mesh using pyvista, an interface to the VTK toolkit.
print(pyvista.global_theme.jupyter_backend)
# pyvista.start_xvfb()
import dolfinx.plot as plot
import dolfinx
print(f"DOLFINx version: {dolfinx.__version__} based on GIT commit: {dolfinx.git_commit_hash} of https://github.com/FEniCS/dolfinx/")
from ufl import TrialFunction, TestFunction, dot, div, inner , grad, rot, curl, dx
import numpy as np
from petsc4py import PETSc
from slepc4py import SLEPc
import matplotlib.pyplot as plt
import math
from mpi4py import MPI
import sys, io, slepc4py, os.path
I set the mixed element and the mixed_space:
num_of_elements =4
domain = mesh.create_unit_square(MPI.COMM_WORLD, num_of_elements, num_of_elements)
# Dimension of the space
tdim = domain.topology.dim
# print(tdim)
topology, cell_types, geometry = plot.vtk_mesh(domain, tdim)
grid = pyvista.UnstructuredGrid(topology, cell_types, geometry)
plotter = pyvista.Plotter()
plotter.add_mesh(grid, show_edges=True)
plotter.view_xy()
# To view the mesh
plotter.show()
tdim = domain.topology.dim
fdim = domain.topology.dim-1
#----------the elements
P1_vect_el = basix.ufl.element("CG", domain.basix_cell(), 1, shape=(domain.geometry.dim, ))
P1_scal_el = basix.ufl.element("CG", domain.basix_cell(), 1)
Rel = basix.ufl.element("DG", domain.basix_cell(), 0)
V = dolfinx.fem.functionspace(domain, P1_vect_el)
''' The mixed_element and mixed_space'''
mixedElement = basix.ufl.mixed_element([P1_vect_el, P1_scal_el,P1_scal_el,Rel]) #imposing zero avrage
mixed_space = dolfinx.fem.functionspace(domain, mixedElement)
'''Trial and test functions'''
u,w,p,m = ufl.TrialFunctions(mixed_space)
v,s,q,l = ufl.TestFunctions(mixed_space)
Now I impose the Homog. Dirchlet BC
#-----------------------------------Dirichlebc BC-------------------------------
def homogs_boundary(x):
return np.isclose(x[0], -1) | np.isclose(x[0], 1) | np.isclose(x[1], -1) | np.isclose(x[1], 1)
#u_noslip = np.zeros(domain.geometry.dim)
u_noslip = np.array((0,) * domain.geometry.dim, dtype=PETSc.ScalarType)
boundary_facets = mesh.locate_entities_boundary(domain, fdim, homogs_boundary)
V0 = mixed_space.sub(0)
boundary_dofs = dolfinx.fem.locate_dofs_topological((V0, V), fdim, boundary_facets)
bc0 = dolfinx.fem.dirichletbc(u_noslip, boundary_dofs , mixed_space.sub(0))
and I get the following error:
bc = bctype(_value, dofs, V._cpp_object)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: __init__(): incompatible function arguments. The following argument types are supported:
1. __init__(self, g: ndarray[dtype=float64, writable=False, order='C'], dofs: ndarray[dtype=int32, writable=False, shape=(*), order='C'], V: dolfinx.cpp.fem.FunctionSpace_float64) -> None
2. __init__(self, g: dolfinx.cpp.fem.Constant_float64, dofs: ndarray[dtype=int32, writable=False, shape=(*), order='C'], V: dolfinx.cpp.fem.FunctionSpace_float64) -> None
3. __init__(self, g: dolfinx.cpp.fem.Function_float64, dofs: ndarray[dtype=int32, writable=False, shape=(*), order='C']) -> None
4. __init__(self, g: dolfinx.cpp.fem.Function_float64, dofs: list[ndarray[dtype=int32, writable=False, shape=(*), order='C']], V: dolfinx.cpp.fem.FunctionSpace_float64) -> None
Invoked with types: dolfinx.cpp.fem.DirichletBC_float64, ndarray, list, dolfinx.cpp.fem.FunctionSpace_float64
Can anyone please explain to me the problem? I don’t seem to understand the error.