Hi everybody, I am trying to impose non homogeneous dirichletbcs but I can’t understand how I can give my array a type (this is the error I think). I attach the code and the error generated.
CODE:
“”“GENERATE MESH AND TIME STEP”“”
side = np.pi
mesh = create_rectangle(MPI.COMM_WORLD, [np.array([0.0, 0.0]), np.array([side, side])], [10, 10])
t = 0
T = 10
num_steps = 200
dt = T / num_steps
“”“DEFINE THE FINITE ELEMENT FUNCTION SPACE”“”
v_cg2 = VectorElement(“Lagrange”, mesh.ufl_cell(), 2)
s_cg1 = FiniteElement(“Lagrange”, mesh.ufl_cell(), 1)
V = FunctionSpace(mesh, v_cg2)
Q = FunctionSpace(mesh, s_cg1)
u = TrialFunction(V)
v = TestFunction(V)
p = TrialFunction(Q)
q = TestFunction(Q)
“”“DEFINE BOUNDARY CONDITIONS”“”
def bound_loop(dofs, f, xy): #x = 1, y = 0 mi dice quale delle due variabili voglio che sia nulla
array_2d = np.zeros((dofs, 2), dtype=PETSc.ScalarType)
for i in range(dofs):
if xy == 1:
array_2d = (0, f(i * side / dofs))
else:
array_2d = (f(i * side / dofs), 0)
return array_2d
def right_wall(x):
return np.isclose(x[0], side)
right_wall_dofs = locate_dofs_geometrical(V, right_wall)
right_wall_D = bound_loop(len(right_wall_dofs), np.sin, 0)
right_bc = dirichletbc(right_wall_D, right_wall_dofs)
AND THE ERROR:
Traceback (most recent call last):
File “/opt/anaconda3/envs/provax/lib/python3.12/site-packages/dolfinx/fem/bcs.py”, line 150, in dirichletbc
dtype = value.dtype
^^^^^^^^^^^
AttributeError: ‘tuple’ object has no attribute ‘dtype’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/Users/niccolobaldi/Desktop/from_pf_to_tgv.py”, line 57, in
right_bc = dirichletbc(right_wall_D, right_wall_dofs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/anaconda3/envs/provax/lib/python3.12/site-packages/dolfinx/fem/bcs.py”, line 162, in dirichletbc
raise AttributeError(“Boundary condition value must have a dtype attribute.”)
AttributeError: Boundary condition value must have a dtype attribute.
Can everybody help me?
Thanks in advance