How to create a volumetric (tdim) boundary condition u = u_D on \Omega_partial

Since I have a shape without a completly flat surface, I would like it to set to points where there is no material deformation. u =0

  1. On the “core of the material”, example inside a ball arround the center of Radius R.

  2. On a rectangular prism | z - z_0 | < tol

Is there a way to do this? Or do I need tools to “cut” my mesh and remove a part of it. Then, I’d have flat 2d boundary at can set u = 0 on them.

That’s because I’m applying external pressure on the material. But I don’t want it to move. It’s more about the local behavior.

In DOLFINx, you can use locate_entities and locate_dofs_topological (or locate_dofs_geometrical) to set constraints on any degree of freedom given a spatial function.
A minimal working example follows:

import dolfinx.fem.function
from mpi4py import MPI
import numpy as np
import dolfinx


mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 50, 50, dolfinx.cpp.mesh.CellType.triangle)
V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1))


def condition(x):
    return np.logical_or(x[0]**2+x[1]**2 > 0.5, x[1] < 0.2)

mesh.topology.create_connectivity(mesh.topology.dim, mesh.topology.dim)
entities = dolfinx.mesh.locate_entities(mesh, mesh.topology.dim, condition)
dofs = dolfinx.fem.locate_dofs_topological(V, mesh.topology.dim, entities)

u_bc = dolfinx.fem.Constant(mesh, 10.)
bc = dolfinx.fem.dirichletbc(u_bc, dofs, V)

uh = dolfinx.fem.Function(V)
bc.set(uh.x.array)
uh.x.scatter_forward()

with dolfinx.io.VTXWriter(mesh.comm, "output.bp", [uh]) as vtx:
    vtx.write(0.0)

1 Like