# yade-users team mailing list archive

## Re: [Question #698778]: Problem with imposing flux in a cavity in flow engine

```Question #698778 on Yade changed:

Robert Caulk proposed the following answer:
Hey Zoheir,

Thanks for the good question.

So when I was creating this functionality, I came to the conclusion that
it was actually more effective to keep the bodies in the cavity, but
"unbound" them so that they do not mechanically interact with the rest
of the specimen. This allows the triangulation to more properly
triangulate the cavity space, so we don't end up with possibly
overlapping cell centers or cell centers outside of cells.

So to do this I would recommend *not* deleting any bodies. Instead do
something like:

CavityList=[]
for b in O.bodies:
if isinstance(b.shape,Sphere):
if np.linalg.norm(b.state.pos-(maxX-dx/2.,maxY-dy/2.,maxZ-dz/2.))<dz/4.:
CavityList.append(b.state.pos)
b.bounded = False # this body will not find interactions with other bodies. Careful if the specimen itself needs displacement/rotation as these unbounded bodies will not displace/rotate with it. If it is the case, we need to assign the same motion to these bodies as we do to the rigid specimen.

and then flow.imposeCavity is meant for the cells, not the bodies (cells
are the ones participating in the flow problem. Better to iterate
through your cell list and find the cells that match your spatial
criterion:

for i in range(0,flow.nCells()):
coords = flow.getCellCenter(i)
if np.linalg.norm(coords[0] - maxX-dx/2., coords[1] - maxY-dy/2., coords[2] - maxZ-dz/2.))<dz/4.:
flow.imposeCavity((coords[0], coords[1], coords[2]))

then I would simply assign the total flux to one of your cavity cells:

flow.imposeFlux((maxX-dx/2,maxY-dy/2.,maxZ-dz/2.),-1e-5)

Make sure to keep flow.controlCavityPressure=False unless you want all the cells to have an equivalent imposed pressure.

You can then use flow.getCavityFlux() to get the total flux across the
boundary of this assigned cavity.

Please let me know if you are able to get the results you expect. If you
have any issues don't hesitate to continue the thread - this is a good
feature to ensure we have working and documented.