# Bounce back in cavity.m

I have a question regarding line 85 to 93 in the example code “cavity.m” on the palabos wiki. First of all, I’m wondering about fOut and fIn, does fOut indicate particle distribution functions f_i streaming OUT of a node, while fIn indicates functions f_i streaming INTO a node?

Secondly, I’m wondering how the bounce back in the cavity.m file works. As far as I can see, lines 86 to 88 is some preprocessing step to facilitate the use of circshift. For every i, f_i in the boundary nodes are replaced with f_i from the mysterious fIn pointing in the opposite direction. Every boundary node now has functions f_i that point in the opposite direction, as if they’ve already hit the wall and bounced back with opposite directions.

1. How does this make sense? Let’s say we have a node on the northern boundary, I understand that populations with directions pointing outside the domain need to have their directions reversed, but populations that point to the laft or right, i.e. along the northern boundary certainly have no need to change direction as they are not hitting any walls, or…?

Lines 91 to 93 is the streaming step, the populations in every node are moved one step in the directions indicated by i.
2) This seems like a really neat way to use circshift to enable streaming.,The f_i situated on the western boundary will stream (at the correct iteration i in the for loop) to the left, but instead of bouncing back off the wall and remaining in the node, but with opposite direction, it now ends up on the eastern boundary (because of circshift). How is this a bounce back?

Obviously, the code have been written and tested by smarter people than me, so I’m confident it is working, I just don’t understand how…

Appreciate any help I can get

For reference, here are the lines in question

[code=“matlab” number=“85”]
% MICROSCOPIC BOUNDARY CONDITIONS: NO-SLIP WALLS (bounce-back)
for i=1:9
fOut(i,bbRegion) = fIn(opp(i),bbRegion);
end

% STREAMING STEP
for i=1:9
fIn(i,:,: ) = circshift(fOut(i,:,: ), [0,cx(i),cy(i)]);
end