3

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)]);
}
Nathan Reed
  • 25,002
  • 2
  • 68
  • 107
Anas Alaa
  • 85
  • 6
  • 1
    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? – Nathan Reed May 23 '17 at 14:35
  • http://www.dgp.toronto.edu/people/stam/reality/Research/pdf/ns.pdf this is it I thought the links are banned or something – Anas Alaa May 23 '17 at 14:46
  • https://www.autodeskresearch.com/sites/default/files/TheArtOfFluidAnimationCode.zip 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. – Anas Alaa May 27 '17 at 23:57

1 Answers1

3

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.

Fei Zhu
  • 146
  • 3
  • 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! – Anas Alaa May 24 '17 at 11:42
  • @AnasAlaa if you have a new question you can post it as a question rather than a comment. – trichoplax is on Codidact now May 24 '17 at 20:14
  • I am sorry but it's really the same question but in another form. And it's a complete of his answer too. – Anas Alaa May 24 '17 at 22:05
  • 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. – Fei Zhu May 25 '17 at 01:49
  • So, if I just want to solve the pressure poisson equations with the PCG method, can I just use these boundaries in the code? – Anas Alaa May 25 '17 at 23:07
  • Yes, I think so. – Fei Zhu May 26 '17 at 01:50
  • I think the answer is not correct. The two options are either homogenous Neumann boundary conditions (if the value is copied) or homogenous dirichlet boundary condition as negating the value represents a zero value in between the interface. Furthermore I doubt that you can use this function for a cg solver. To which variables do you want apply it? For a cg solver I would recommend to check Robert bridsons book fluid simulation for computer graphics, although he uses a slightly modified (superior) discretization (staggered grid). – dweber May 26 '17 at 19:18
  • I don't understand how the boundaries will be dirchlet and neuman at the same time. Bridson book is good but he has no code to implement what he said about boundaries and PCG... etc – Anas Alaa May 27 '17 at 03:05
  • Boundary conditions are either dirichlet or Neumann, I don't know from which part of the code you see this. Neumann conditions are realized by modifying the matrix. You might want to check a finite difference book for details. This function from stam emulates a modified matrix for a gauss seidel iteration. I fear you have to do the transition from text / equations to code. You can't just copy and paste everything from different sources... – dweber May 27 '17 at 13:15
  • I understand you, in the code, the boundaries are dirichlet or neuman in the code. But I doubt if I can just use the same boundaries for cg solver you can see the full code here – Anas Alaa May 27 '17 at 23:55
  • https://www.autodeskresearch.com/sites/default/files/TheArtOfFluidAnimationCode.zip

    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.

    – Anas Alaa May 28 '17 at 02:42
  • Where are you? I need help – Anas Alaa May 30 '17 at 17:47