3
$\begingroup$

In the paper Stable Fluids by Jos Stam, I am confused about the boundaries in the set_bnd function in the code. I don't know what kind of boundaries is this. Is it Neumann boundary condition or Dirichlet boundaries?

Here is the set_bnd function; the full code can be found here.

void set_bnd ( int N, int b, float * x )
{
    int i;

    for ( i=1 ; i<=N ; i++ ) {
        x[IX(0  ,i)] = b==1 ? -x[IX(1,i)] : x[IX(1,i)];
        x[IX(N+1,i)] = b==1 ? -x[IX(N,i)] : x[IX(N,i)];
        x[IX(i,0  )] = b==2 ? -x[IX(i,1)] : x[IX(i,1)];
        x[IX(i,N+1)] = b==2 ? -x[IX(i,N)] : x[IX(i,N)];
    }
    x[IX(0  ,0  )] = 0.5f*(x[IX(1,0  )]+x[IX(0  ,1)]);
    x[IX(0  ,N+1)] = 0.5f*(x[IX(1,N+1)]+x[IX(0  ,N)]);
    x[IX(N+1,0  )] = 0.5f*(x[IX(N,0  )]+x[IX(N+1,1)]);
    x[IX(N+1,N+1)] = 0.5f*(x[IX(N,N+1)]+x[IX(N+1,N)]);
}
$\endgroup$
3
  • 1
    $\begingroup$ Can you please add a link to the paper or book you're referring to, and a relevant excerpt from the code you're talking about? $\endgroup$ Commented May 23, 2017 at 14:35
  • $\begingroup$ dgp.toronto.edu/people/stam/reality/Research/pdf/ns.pdf this is it I thought the links are banned or something $\endgroup$
    – Anas Alaa
    Commented May 23, 2017 at 14:46
  • $\begingroup$ autodeskresearch.com/sites/default/files/… Here is the code and you just use the set_bnd for div in the project function to whom I want just to replace the gauss seidel with PCG. $\endgroup$
    – Anas Alaa
    Commented May 27, 2017 at 23:57

1 Answer 1

3
$\begingroup$

It's Dirichlet boundary condition. The quantities at domain boundaries will take either the same value as its inner neighbor or the negated value, depending on the condition $\mathbf{b}$. Take velocity field for instance, velocity of fluid will either gets reflected or not change at domain boundary. The condition $\mathbf{b}$ is a user option, $\mathbf{b}==1$ is used to set reflected values at the horizonal boundaries, and $\mathbf{b}==2$ is to set reflected values at vertical boundaries. To be more clear:

  • $\mathbf{b}==1$: field values at horizonal boundaries get reflected, field values at vertical boundaries do not change.
  • $\mathbf{b}==2$: field values at vertical boundaries get reflected, field values at horizonal boundaries do not change.
  • $\mathbf{b}== other\ value$: field values at neither vertical nor horizonal boundaries do not change.

set_bnd could be called multiple times to set desired boundary values.

$\endgroup$
12
  • $\begingroup$ What about if b is not 1 and 2? Another thing, where is the Neuman boundaries? Those are slip or no-slip? Is it a solid boundaries? If i use the PCG, will something change in the boundaries? Sorry for all of these stupid questions but I want to understand. Thanks cheers! $\endgroup$
    – Anas Alaa
    Commented May 24, 2017 at 11:42
  • $\begingroup$ @AnasAlaa if you have a new question you can post it as a question rather than a comment. $\endgroup$ Commented May 24, 2017 at 20:14
  • $\begingroup$ I am sorry but it's really the same question but in another form. And it's a complete of his answer too. $\endgroup$
    – Anas Alaa
    Commented May 24, 2017 at 22:05
  • $\begingroup$ There's a little mistake in my previous answer, and I've editted the answer. About Neuman boundaries, this demo code didn't implement it. $\endgroup$
    – Fei Zhu
    Commented May 25, 2017 at 1:49
  • $\begingroup$ So, if I just want to solve the pressure poisson equations with the PCG method, can I just use these boundaries in the code? $\endgroup$
    – Anas Alaa
    Commented May 25, 2017 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.