# How to implement boundary conditions in arbitrary geometries, in MD\Lagrangian FD simulations

Let's say I have a random arbitrary geometry, like this one https://ibb.co/dG8fUa (something I just made up). I make one of these in 3D in SolidWorks. I have molecules/particles coming in through the inlet and leaving out of the two outlets. In a standard geometry, like a pipe or square channel, a simple way to implement a wall BC is something like

if(y_particle>0.3)
v_particle=-v_particle


assuming a square channel height of 0.15 and the origin along the lengthwise axis. This obviously wont work for a complicated geometry with wildly varying X and Y. How might one implement codes which can work on any generated geometry? I am trying for MD simulations through such geometries.

• Try conservation of momentum for elastic collisions: $\vec{p}_{before}=\vec{p}_{bounceback}$ and project this equation for an element of your (I assume) cartesian grid, which will hold over the face of some element of your discretisation.
– HBR
Jul 6 '17 at 20:02
• As mentioned by @HBR, you need to check 1) which element of your geometry mesh is your particle is colliding with? 2) use the normal direction of that element to reverse the direction of normal momentum (multiplied by a restitution coefficient if required) Jul 19 '17 at 18:35