Hi,
I am dealing with 2 dynamic submeshes contacting one to each other. I would like to get the paired nodes that are colliding.
To do so, I am trying to use BoundingBoxTree and in particular its method compute_collisions(tree) (see code below) but I do not understand how to properly use it.
Here are my questions:
-
What exactly does BoundingBoxTree.compute_collisions(tree) method return? I thought it was two lists: list of DOFs in mesh 1 and list of DOFs in mesh 2 that are colliding between each other, and classified by colliding pairs (i.e. collinding_pair_1 = list1[0], list2[0]). Is it? When I plot the pairs, it does not seem to be so and the pairs are distant?
-
What is the best way to get colliding paired-nodes?
Many thanks for your help,
Anne
dimension = 3
V = fenics.VectorFunctionSpace(mesh, "CG", 1)
mesh1 = fenics.SubMesh(mesh, sudomains, 1)
mesh2 = fenics.SubMesh(mesh, sudomains, 2)
# build mesh1 & mesh2 trees
bbtree1 = fenics.BoundingBoxTree()
bbtree1.build(mesh1)
bbtree2= fenics.BoundingBoxTree()
bbtree2.build(mesh2)
# compute colliding entities between 2 trees
colliding_entities_DOFs_1, colliding_entities_DOFs_2= bbtree1.compute_collisions(bbtree2)
# Get node_index to dofs correspondance map
nodeindex_to_dofs = fenics.vertex_to_dof_map(V)
nodeindex_to_dofs = nodeindex_to_dofs.reshape((-1, dimension))
# Convert DOF into node_index in colliding_entities_DOFs_1
colliding_nodes_indices_1 = np.zeros( (len(colliding_entities_DOFs_1)), dtype=int )
for i, dof in enumerate(np.array(colliding_entities_DOFs_1)):
if len(np.where(nodeindex_to_dofs[:,0] == dof)[0]) != 0: # find node_index value for which DOFs contain dof (get array with node index value)
colliding_nodes_indices_1[i] = np.where(nodeindex_to_dofs[:,0] == dof)[0][0] # get node_index value
elif len(np.where(nodeindex_to_dofs[:,1] == dof)[0]) != 0:
colliding_nodes_indices_1[i] = np.where(nodeindex_to_dofs[:,1] == dof)[0][0]
else:
colliding_nodes_indices_1[i] = np.where(nodeindex_to_dofs[:,2] == dof)[0][0]
# Same conversion for colliding_entities_DOFs_2
colliding_nodes_indices_2 = np.zeros( (len(colliding_entities_DOFs_2)), dtype=int )
for i, dof in enumerate(np.array(colliding_entities_DOFs_2)):
if len(np.where(nodeindex_to_dofs[:,0] == dof)[0]) != 0:
colliding_nodes_indices_2[i] = np.where(nodeindex_to_dofs[:,0] == dof)[0][0]
elif len(np.where(nodeindex_to_dofs[:,2] == dof)[0]) != 0:
colliding_nodes_indices_2[i] = np.where(nodeindex_to_dofs[:,1] == dof)[0][0]
else:
colliding_nodes_indices_2[i] = np.where(nodeindex_to_dofs[:,2] == dof)[0][0]
# Get the colliding-nodes pairs indices
pairs_colliding_nodes = np.zeros((len(colliding_entities_DOFs_1), 2), dtype=int)
pairs_colliding_nodes[:,0], pairs_colliding_nodes[:,1] = colliding_nodes_indices_1[:], colliding_nodes_indices_2[:]