I have read a lot of related content, but I still cannot achieve the desired functionality in dolfinx:https://fenicsproject.discourse.group/t/how-to-extract-meshs-coordinates-and-values-according-to-facet-markers/11420/2?u=french_fries
I can only compute all the coordinates:
coordinates = mesh.geometry.x
Here is my current code:
import dolfinx
import numpy as np
from mpi4py import MPI
from dolfinx.io import gmshio
from ufl import (Measure, TestFunction, TrialFunction, dot, dx, grad)
from dolfinx.fem import (Function, functionspace, dirichletbc, locate_dofs_topological)
from dolfinx.fem.petsc import LinearProblem
import material_properties
T_hp = 100
g = material_properties.g * material_properties.K
# Create mesh and define function space
mesh, cell_markers, facet_markers = gmshio.read_from_msh("trapezoid.msh", MPI.COMM_WORLD, gdim=2)
VT = functionspace(mesh, ("CG", 1))
ds = Measure('ds', domain=mesh, subdomain_data=facet_markers)
# Define boundary condition
facets = facet_markers.find(562)
fdim = mesh.topology.dim - 1
dofs = locate_dofs_topological(VT, fdim, facets)
bcT = dirichletbc(T_hp, dofs, VT)
# Define variational problem
T_ = TestFunction(VT)
dT = TrialFunction(VT)
aT = dot(grad(dT), grad(T_)) * dx
LT = -g * T_ * ds(563)
# Compute solution
Delta_T = Function(VT, name="Temperature")
problem = LinearProblem(aT, LT, bcs=[bcT], petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
Delta_T = problem.solve()
# obtain Temperature on boundary 561
mesh.topology.create_connectivity(mesh.topology.dim-1, mesh.topology.dim)
boundary_facets = facet_markers.find(561)
boundary_vertices = dolfinx.mesh.compute_incident_entities(mesh.topology, boundary_facets, mesh.topology.dim-1, 0)
vertex_to_geometry = dolfinx.cpp.mesh.entities_to_geometry(mesh._cpp_object, 0, boundary_vertices, False)
c_to_v = mesh.topology.connectivity(mesh.topology.dim, 0)
mesh.topology.create_connectivity(0, mesh.topology.dim)
v_to_c = mesh.topology.connectivity(0, mesh.topology.dim)
num_dofs = VT.dofmap.index_map.size_local+ VT.dofmap.index_map.num_ghosts
dof_to_geometry_map = np.full(num_dofs, -1, dtype=np.int32)
dofmap = VT.dofmap
layout = dofmap.dof_layout
for i, (vertex, node) in enumerate(zip(boundary_vertices, vertex_to_geometry)):
cell = v_to_c.links(vertex)[0]
cell_dofs = dofmap.cell_dofs(cell)
cvs = c_to_v.links(cell)
local_index = np.flatnonzero(cvs == vertex)[0]
dof = cell_dofs[layout.entity_dofs(0, local_index)]
dof_to_geometry_map[dof] = node
I don’t know what to do next.and I hope to get some help to achieve the same functionality as in my previous post (old version of dolfin):https://fenicsproject.discourse.group/t/how-to-output-the-data-results-on-the-boundary/13227/2?u=french_fries
Thank you!