CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   periodic boundary conditions with a gradient term (https://www.cfd-online.com/Forums/main/114150-periodic-boundary-conditions-gradient-term.html)

Hooman March 6, 2013 04:11

periodic boundary conditions with a gradient term
 
Hi,
I have been trying to implement periodic bc's in my 1D code, I have a gradient term in my code, which I have discretized by using central differencing, so I have
du/dx = (u_i+1 - u_i)/(x_i+1 - x_i)
so for a periodic bc at the left and right boundaries I have used
du/dx = (u_1 - u_N)/(x_1 - x_N)

where N is the final cell, but for some reason I get weird results at the boundaries.
Could someone please confirm that what I am doing it correct.
Thanks!

andy_ March 6, 2013 06:49

Quote:

Originally Posted by Hooman (Post 411878)
Hi,
I have been trying to implement periodic bc's in my 1D code, I have a gradient term in my code, which I have discretized by using central differencing, so I have
du/dx = (u_i+1 - u_i)/(x_i+1 - x_i)
so for a periodic bc at the left and right boundaries I have used
du/dx = (u_1 - u_N)/(x_1 - x_N)

where N is the final cell, but for some reason I get weird results at the boundaries.
Could someone please confirm that what I am doing it correct.
Thanks!

You expression looks one-sided rather than central?

du/dx = (u_i+1 - u_i-1)/(x_i+1 - x_i-1) ???

For a pure upwind scheme the downstream value is not used and so can take any value. Setting it to the first solved value would look tidy but is not required. Is this what you are seeing?

Do you need to perform a line sweep to handle the unknown upstream boundary value? The code for periodic line sweeps is different to that for Dirichlet and Neumann line sweeps.

Hooman March 6, 2013 07:07

oooh! Thanks! Stupid of me to think I was using CDS!

I want to avoid a scheme that is based on the direction of the flow, are there such schemes that can be used just with 2 neighbouring cells involved, like in 1sr order upwind? I don't see how that would be possible but I though I'd ask just in case ...

about CDS, would the expression "du/dx = (u_i+1 - u_i-1)/(x_i+1 - x_i-1) " give du/dx across the east face or the west face of node i?
or would they both be the same. I am using collocated grid. Slightly confused by that for some reason. Would really appreciate you help.


Many Thanks!

andy_ March 6, 2013 07:27

Quote:

Originally Posted by Hooman (Post 411944)
oooh! Thanks! Stupid of me to think I was using CDS!

I want to avoid a scheme that is based on the direction of the flow, are there such schemes that can be used just with 2 neighbouring cells involved, like in 1sr order upwind? I don't see how that would be possible but I though I'd ask just in case ...

Many Thanks!

You don't say which equations you are solving. Diffusion works well with central schemes but convection does not. To make convection dominated flows behave some form of upwinding is usually used because it is physically the correct thing to do. An alternative is to use some form of energy preserving differencing but in the absence of some diffusion these often produce unreasonable solution over a long time period. There is of course loads of stuff on the topic in the literature going back to the 1960s.

Hooman March 6, 2013 07:37

Thanks Andy,

just added a bit to my previous question, I would appreciate you answer to that as well:
about CDS, would the expression "du/dx = (u_i+1 - u_i-1)/(x_i+1 - x_i-1) " give du/dx across the east face or the west face of node i?
or would they both be the same. I am using collocated grid.

Many Thanks

andy_ March 6, 2013 08:15

Quote:

Originally Posted by Hooman (Post 411951)
about CDS, would the expression "du/dx = (u_i+1 - u_i-1)/(x_i+1 - x_i-1) " give du/dx across the east face or the west face of node i? or would they both be the same. I am using collocated grid.

The expression is the usual central difference approximation for the gradient of u at the location i. If you are evaluating the gradient at cell walls then this looks to be part of doing something more. Perhaps part of an upwinding scheme or the first stage of working out the second derivatives? I think you might be better off reading a book for answers to this level of question.

Hooman March 6, 2013 08:26

This forum was my last resort not first! I've read Versteeg, and other books, etc. I couldn't find what I wanted, perhaps because my equations are slightly different.
Thanks anyways! Your replies helped.

Hooman March 6, 2013 08:37

This is the term I'm trying to discretize using FVM:

\intop_{\Gamma}\frac{\partial\underline{u}}{\partial x}.\underline{n}d\Gamma\overline{}

where {\Gamma} , is the cell surface.

Versteeg upwinds in this case.

michujo March 6, 2013 08:53

Hi, apart from the comments you got on the numerical schemes, I think there is a mistake in the first expression you showed for the discretization of the derivative at the boundary. You are dividing by (x1-xN) which, if I understand the notation, is about the whole length of the channel!. I think you should divide by something like 0.5\cdot\Delta x_N+0.5\cdot\Delta x_1, where [\Delta x_i] is the cell size. This expression is the length between the nodes N and 1 assuming the nodes are centered within the cells.

Maybe you could give it a try.

Cheers,
Michujo.

Hooman March 6, 2013 09:07

Quote:

Originally Posted by michujo (Post 411977)
You are dividing by (x1-xN) which, if I understand the notation, is about the whole length of the channel!. I think you should divide by something like 0.5\cdot\Delta x_N+0.5\cdot\Delta x_1, where [\Delta x_i] is the cell size. This expression is the length between the nodes N and 1 assuming the nodes are centered within the cells.

aaa! well spotted! that improved the results a little. Many Thanks!

still looking for a central differenced scheme if anyone has any ideas ... I will keep looking myself!

andy_ March 6, 2013 11:46

Quote:

Originally Posted by Hooman (Post 411974)
This is the term I'm trying to discretize using FVM:

\intop_{\Gamma}\frac{\partial\underline{u}}{\partial x}.\underline{n}d\Gamma\overline{}

where {\Gamma} , is the cell surface.

Versteeg upwinds in this case.

This looks like diffusion rather than convection? If so, that is a much better behaved problem and is possibly better tackled by placing the unknowns at the cell faces and not the cell centres. That is, a standard Galerkin FEM approach. But the best arrangement of grid and unknowns may well be determined by where you are going with whatever you are trying to solve.

Hooman March 6, 2013 12:05

Quote:

Originally Posted by andy_ (Post 412032)
This looks like diffusion rather than convection? If so, that is a much better behaved problem and is possibly better tackled by placing the unknowns at the cell faces and not the cell centres. That is, a standard Galerkin FEM approach. But the best arrangement of grid and unknowns may well be determined by where you are going with whatever you are trying to solve.

Thanks again!
I have thought about moving the nodes but was trying my best to stick with FVM with nodes in the centre, because I have convection terms as well. I will give it some serious thought now ... Thanks!

Hooman March 6, 2013 12:25

I just took the average of the CDS obtained for the cell centres to the two sides of the faces of the current cell and it seems to work OK so far ... It involves more cells, but for now I think it's doing the job, fingers crossed!
Thanks for you guidance!


All times are GMT -4. The time now is 13:05.