CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How does 'solve' work? (http://www.cfd-online.com/Forums/openfoam-programming-development/120656-how-does-solve-work.html)

zxj160 July 11, 2013 11:43

How does 'solve' work?
 
Dear Foamers,

Could anybody explain how the 'solve' work? Is there any difference between the following approaches concerning the Source term for a passive scalar?

The first one includes the SourceC in the solve equation as follows:
....
solve
(
fvm::ddt(C)
+ fvm::div(phi, C)
- fvm::laplacian(turbulence->nut()/0.72, C)
==
SourceC
);
....

The second one excludes the SourceC in the solve equation, but then add this SourceC to C as two sub-cycles for each time step:
.......
solve
(
fvm::ddt(C)
+ fvm::div(phi, C)
- fvm::laplacian(turbulence->nut()/0.72, C)
==
);
// two sub-cycles
C=C+SourceC*0.5*runTime.deltaT();
C=C+SourceC*0.5*runTime.deltaT();
.........


My best regards,
Jian

ARTem July 22, 2013 05:18

Hi, zxj160.
solve(fvScalarMatrix) just solves system of linear algebraical equations: A_p*C_p = sum over all neighbours (A_nb * C_nb) + source_p.

In first case you solve for C being affected by source term. This means that C_p is influenced by C_nb (neighbour) already changed by source.
In second case you solve for C without source influence on neighbours, which will be taking into account only on next time step.

First, consider explicit equal source, not depending of C variable.
My guess is that if you use just diffusive fluxes without upwinding interpolation for your scalar transport, you always will get same results for your C. Because diffusive flux is difference between adjacent values ((c_i + dc)-(c_(i+1)+dc) = (c_i - c_(i+1))).

In other cases (non-equal source in whole domain, upwinding interpolations, convective fluxes, implicit source, etc.) you will get different results.

In nutshell, always put all your sources in one solve() which gives you better coupling between parts of equation and better compatibility of your difference equation with an original differential equation.

zxj160 July 26, 2013 06:19

Hi Artem,

Many thanks for your reply. I use the second method since the solve() takes more computational cost than the direct assignment. If I use the first method (i.e. put all my sources terms into one solver) with the same deltaT as the subcylce time step of the second method, the computational time is unaffordable for me. So do you think that there is any other way to achieve this with less computational cost?

My best regards,
Jian

ARTem July 26, 2013 06:55

hello, zxj160.
Just out of curiosity, why you use "two sub-cycles" in second method instead of one with whole deltaT?
A process you solve is steady-state or transient? May be you should lower time step with second method if a process is transient? Can you compare results of simulations with second method but with different timesteps?
To tell the truth, I've never used to play with source terms. But I met interesting method for stabilisation (it may be useful for you):
http://www.cfd-online.com/Forums/ope...ensmoke-7.html post #125 by Tobias Holzmann.


All times are GMT -4. The time now is 00:49.