Hi
import ufl
from dolfinx.fem import (Constant, Function, FunctionSpace,
assemble_scalar, dirichletbc, form, locate_dofs_geometrical)
from dolfinx.fem.petsc import LinearProblem
from dolfinx.mesh import create_unit_square
from mpi4py import MPI
from ufl import SpatialCoordinate, TestFunction, TrialFunction, dot, dx, ds, grad, Measure
from petsc4py.PETSc import ScalarType
from dolfinx import *
from dolfinx.io import XDMFFile
from mpi4py import MPI
Read mesh from file
infile = io.XDMFFile(MPI.COMM_WORLD, “Domain.xdmf”, “r”)
just read a mesh
msh = infile.read_mesh(name=“Grid”)
read a all domain
domain =infile.read_meshtags(msh,name=“Grid”)
infile.close()
this is for full domain
newValues = [-i for i in domain.values]
domain = mesh.meshtags(msh, domain.dim, domain.indices, newValues)
#fdim=domain.topology.create_connectivity(domain.topology.dim, domain.topology.dim-1)
msh.topology.create_connectivity(2, 0)
read a boundary file
boundaryInfile = io.XDMFFile(MPI.COMM_WORLD, “Domain_boundary.xdmf”, “r”)
boundary_msh = boundaryInfile.read_mesh(name=“Grid”)
boundaryMeshTags = boundaryInfile.read_meshtags(msh, name=“Grid”)
boundaryInfile.close()
this is for full boundary
newValues = [-i for i in boundaryMeshTags.values]
boundaryMeshTags = mesh.meshtags(msh, boundaryMeshTags.dim, boundaryMeshTags.indices, newValues)
del newValues
V=FunctionSpace(msh,(“Lagrange”,2))
boundaryTags = {“left” : 1, “right” : 2,“up” : 3 }
leftFacets = boundaryMeshTags.find(boundaryTags[“left”])
rightFacets = boundaryMeshTags.find(boundaryTags[“right”])
upFacets = boundaryMeshTags.find(boundaryTags[“up”])
downFacets =boundaryMeshTags.find(boundaryTags[“down”])
fronttFacets =boundaryMeshTags.find(boundaryTags[“front”])
backFacets =boundaryMeshTags.find(boundaryTags[“back”])
headDofs = fem.locate_dofs_topological(V=V, entity_dim=2, entities=leftFacets)
handsDofs = fem.locate_dofs_topological(V=V, entity_dim=2, entities=rightFacets)
bcs = [
fem.dirichletbc(value=ScalarType(0), dofs=headDofs, V=V),
fem.dirichletbc(value=ScalarType(0), dofs=handsDofs, V=V),
fem.dirichletbc(value=ScalarType(0), dofs=headDofs, V=V),
]
boundaryMeshTags.values[upFacets] = 1
dx = Measure(“dx”, msh, subdomain_data=domain)
ds = Measure(“ds”, msh, subdomain_data=boundaryMeshTags)
u = TrialFunction(V)
v = TestFunction(V)
x = ufl.SpatialCoordinate(msh)
f = Constant(msh, (0.0))
g = Constant(msh, (0.0))
a = dot(grad(u), grad(v)) * dx
L = dot(f, v) * dx + dot(g, v) * ds (boundaryTags[“up”])
problem = fem.petsc.LinearProblem(a, L, bcs=bcs, petsc_options={“ksp_type”: “preonly”, “pc_type”: “lu”})
uh = problem.solve()
with io.XDMFFile(msh.comm, “domain_boundary.xdmf”, “w”) as file:
file.write_mesh(msh)
file.write_function(uh)
I have applied neumann boundary condition and dirichletbc conditions I don’t know why but it is not applying can you tell what should I do
Regards
Minha