I am wondering if it is possible to define Dirichlet boundary conditions on a subdomain.
For instance, if one primary variable is not of interest in a certain subdomain, I would like to set a DBC with the value 0 in order to save computational time. In the legacy fenics, this was possible.
Given V as a mixed function space, how can I find the corresponding coordinates of the DOF with the all zero rows?
My attempt is attached. Any suggestions on improvement?
for i in range(V.num_sub_spaces):
v_sub, sub_to_parent = V.sub(i).collapse()
if len(zero_rows_values_local) > 0:
coords = v_sub.tabulate_dof_coordinates()
for dof in zero_rows_values_local:
if dof in sub_to_parent:
index = sub_to_parent.index(dof)
print(f"Found coordinates: {dof = }, {coords[index] = }", flush = True)
This can easily be done without a for-loop for the dof in zero_rows_values_local, if you create the inverse map parent_to_sub mapping from the parent space to the sub-space (where some entries will have nonsensical values, as there is nothing mapping from the parent to the sub-space).
for i in range(V.num_sub_spaces):
v_sub, sub_to_parent = V.sub(i).collapse()
num_parent_dofs = V.dofmap.index_map.size_local * V.dofmap.index_map_bs
parent_to_sub = np.full(num_parent_dofs, -1, dtype=np.int32)
parent_to_sub[sub_to_parent] = np.arange(len(sub_to_parent))
sub_indices = parent_to_sub[zero_rows_values_local]
assert np.allclose(sub_indices >= 0, 1)