How do I locate entities with given Cartesian coordinate value

Hi.
I want to perform calculation with complex-shaped domain.
To apply Dirichlet bcs to the domain, I have to locate entities but I cannot use “dolfinx.fem.locate_entities” due to complexity of mesh shape.
I mean, I have to define the function “locateEntitiesOnPoint” s.t.

import dolfinx.fem
import dolfinx.mesh
import numpy as np
import pyvista
from mpi4py import MPI
import ufl
import basix.ufl

mesh = pyvista.read(mesh.vtu)
points = np.array(mesh.points)
cells = mesh.cells_dict[pyvista.CellType.TETRA]
elm  = ufl.Mesh(basix.ufl.element("Lagrange", "tetrahedron", 1, shape=(3,)))
mesh = dolfinx.mesh.create_mesh(MPI.COMM_WORLD, cells, points, elm)

def locateEntitiesOnPoint(mesh, x, X, Y, Z):
 ~some computation~

X, Y, Z = 0, 0, 0
facets = locateEntitiesOnPoint(mesh, x, X, Y, Z):

Is there any examples or tutorials?
Version of dolfinx is 0.8.0.
Thanks.

As you are reading your mesh from somewhere, does it have the boundary markers in that original file?

Hi, @dokken. Thank you for your reply.
I constructed “mesh.vtu” from a medical image so it doesn’t have the boundary markers.
Could you tell me if there are any methods to mark the boundaries of VTK files for dolfinx?

Then I am a bit confused. If your VTK file doesn’t have markers, and you can’t write an expression based of spatial coordinates to define them, you would need a GUI to manually mark the appropriate boundaries?

You could use for instance gmsh (first convert your vtu to msh) and manually mark it there.

However, if the mesh is based of a medical image, surely your meshing tool must have some marking capability?

I might be misunderstanding meaning of the word “marker”.
Anyway, this VTK file can be visualized by paraview, and be read by pyvista and dolfinx.

You mean I can add boundary information to a VTK file by some methods and give this information to dolfinx, right?

Yes. This is for instance illustrated in:
https://jsdokken.com/dolfinx-tutorial/chapter2/ns_code2.html#loading-mesh-and-boundary-markers
and
http://jsdokken.com/FEniCS-workshop/src/external_mesh.html
here using gmsh to add the marker information to the mesh.

In general, if you define your facet through the set of vertex indices of your input file, you can use dolfinx to create meshtags of this. See for instance the «long tutorial» in: Using the GMSH Python API to generate complex meshes | Jørgen S. Dokken

Hi @dokken. Thank you for your information. Finally I’ve generated the mesh successfully.
But I have another question now.
How do I set different value of material constants to each physical volumes?
Is there any dolfinx function to locate dofs using physical volume tag?

There are plenty of posts on this subject.

See for instance:
https://jsdokken.com/dolfinx-tutorial/chapter3/subdomains.html
and Want to import already defined physical groups of Microstructure in Gmsh to FEnics - #23 by dokken