CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Different ways to treat source terms of an additional transport equation in OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 23, 2021, 19:48
Default Different ways to treat source terms of an additional transport equation in OpenFOAM
  #1
New Member
 
Join Date: Jan 2015
Posts: 22
Rep Power: 11
adib_mohammad is on a distinguished road
I have created a modified solver based on simpleFoam and called it twosimpleFoam. I added one scalar tranport equation to track number density of particles (N_{agg}) in a laminar flow.
Below is the transport equation I am trying to solve.

\frac{\partial N_{agg}}{\partial t}+\frac{\partial}{\partial x_i} (u_i. N_{agg}-D.\frac{ \partial N_{agg}}{\partial x_i\ })=-\frac{1}{2}\beta. N_p^2\ .Av.\rho_{gas}

I have created "NEqn.H" file similar and included it in twosimpleFoam.C. I have two versions of "NEqn.H". The only difference how I solve the source source term.
The first one ends up with "core dump", but second one converges. I don't understand which one is the correct way to solve this equation and how these two implementations are different.

First Implementation (DIVERGES!):

Code:
{
    fvScalarMatrix NEqn
    (
        fvm::ddt(N_agg)
        + fvm::div(phi, N_agg)
        - fvm::laplacian(diff_prefactor*diff_p, N_agg)
    ==
        -fvm::Sp(0.5 * beta * N_agg * Av * rho, N_agg))

    );

    NEqn.relax();
    fvOptions.constrain(NEqn);
    NEqn.solve();
    fvOptions.correct(N_agg);
}
Second Implementation (CONVERGES!):

Code:
{
    fvScalarMatrix NEqn
    (
        fvm::ddt(N_agg)
        + fvm::div(phi, N_agg)
        - fvm::laplacian(diff_prefactor*diff_p, N_agg)
    ==
        fvOptions(N_agg)

    );

    NEqn.relax();
    fvOptions.constrain(NEqn);
    solve(NEqn == -fvm::Sp(0.5 * beta * N_agg * Av * rho, N_agg));
    fvOptions.correct(N_agg);
}
adib_mohammad is offline   Reply With Quote

Old   December 26, 2021, 11:17
Default
  #2
New Member
 
Join Date: Jan 2015
Posts: 22
Rep Power: 11
adib_mohammad is on a distinguished road
Any suggestion?
adib_mohammad is offline   Reply With Quote

Old   December 27, 2021, 04:26
Default
  #3
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 730
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
I would like to understand this as well.

In the case where the simulations do converge, does the computed solution make physical sense? And if it does, do you obtain convergence by flipping the sign, i.e., solve == + fvm::Sp(...).

Same question in case where simulations diverge. Should you flip the sign? Or should you replace the function fvm::Sp() by fvm::SuSp()? See e.g. this post fvMatrix, fvOptions and SuSp: automatic implicit/explicit source-term treatment.

How good is converge in case you do converge?

More advanced, and possibly not worth the effort: can you run in a debugger, print the matrix to file and check diagonal dominance of the matrix?

Let us know.
dlahaye is online now   Reply With Quote

Old   December 27, 2021, 17:33
Default
  #4
New Member
 
Join Date: Dec 2021
Posts: 23
Rep Power: 4
MamboJambo is on a distinguished road
Hello,

Regarding the printing of the matrix to a file.



You can just use.diag(), lower() and uppper() and .source(). However, this does not include the boundary contributions, right? Is there a way to print the matrix with boundary conditions contributions?
MamboJambo is offline   Reply With Quote

Old   December 28, 2021, 17:50
Default
  #5
New Member
 
Join Date: Jan 2015
Posts: 22
Rep Power: 11
adib_mohammad is on a distinguished road
The converged solution is not physical. I am looking into it to figure out how to get physical results from this. I tested fvm::SuSp, and I am fairly familiar with its difference from fvm::Sp.

The convergence is acheived only by placing the source term after NEqn.relax();

I have also tested the signs, but it did not affect the results.

Quote:
Originally Posted by dlahaye View Post
I would like to understand this as well.

In the case where the simulations do converge, does the computed solution make physical sense? And if it does, do you obtain convergence by flipping the sign, i.e., solve == + fvm::Sp(...).

Same question in case where simulations diverge. Should you flip the sign? Or should you replace the function fvm::Sp() by fvm::SuSp()? See e.g. this post fvMatrix, fvOptions and SuSp: automatic implicit/explicit source-term treatment.

How good is converge in case you do converge?

More advanced, and possibly not worth the effort: can you run in a debugger, print the matrix to file and check diagonal dominance of the matrix?

Let us know.
adib_mohammad is offline   Reply With Quote

Old   December 29, 2021, 06:16
Default
  #6
New Member
 
Anup Singh
Join Date: Mar 2020
Posts: 22
Rep Power: 6
Anup Singh is on a distinguished road
I think you need to linearize your equation first or look you into what you have written, as for RHS you are putting Np^2 both as value to be calculated and value to be used.
As for why its working for second implementation, I think that might be because the matrix is formed with the declaration done with fvScalarMatrix which is only modified later on with solve function but as the implementation is incorrect (As it appears to me) you are getting nonphysical results.
Anup Singh is offline   Reply With Quote

Old   December 30, 2021, 10:19
Default
  #7
New Member
 
Join Date: Jan 2015
Posts: 22
Rep Power: 11
adib_mohammad is on a distinguished road
I think the currect implementation of the source term (in both cases) can be considered as a standard linearization.
Code:
-fvm::Sp(0.5 * beta * N_agg * Av * rho, N_agg))
I got the idea of the second implementation from U equation (UEqn.h) in simpleFoam. Please see how the gradient of pressure is treated in U equation.
Code:
    if (simple.momentumPredictor())
    {
        solve(UEqn == -fvc::grad(p));

        fvOptions.correct(U);
    }
Quote:
Originally Posted by Anup Singh View Post
I think you need to linearize your equation first or look you into what you have written, as for RHS you are putting Np^2 both as value to be calculated and value to be used.
As for why its working for second implementation, I think that might be because the matrix is formed with the declaration done with fvScalarMatrix which is only modified later on with solve function but as the implementation is incorrect (As it appears to me) you are getting nonphysical results.
adib_mohammad is offline   Reply With Quote

Old   December 30, 2021, 13:33
Default
  #8
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 730
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
@adib_mohammad:
pls. observe that your implementation employs fvm (implicit, method) while the simpeFoam example you refer to employs fvc (explit, calculus).
question: do you have a reference solution in literature that one could employ as a reference? Thx.

@mambojambo:
for the boundary contribution. I found this post ldUMatrix building indexing in parallel to explain the matter well.

@anup:
could you pls. further elaborate your point of view on this matter. Thx.
dlahaye is online now   Reply With Quote

Old   December 30, 2021, 21:13
Default
  #9
New Member
 
Join Date: Jan 2015
Posts: 22
Rep Power: 11
adib_mohammad is on a distinguished road
I see your point about fvc and fvm.
I have a refernece analytical solution for a case without the source term, and I have validated the numerical results with that. It is basically a monodisperse population balance model. The problem occurs when I add coagulation source term.


Quote:
Originally Posted by dlahaye View Post
@adib_mohammad:
pls. observe that your implementation employs fvm (implicit, method) while the simpeFoam example you refer to employs fvc (explit, calculus).
question: do you have a reference solution in literature that one could employ as a reference? Thx.

@mambojambo:
for the boundary contribution. I found this post ldUMatrix building indexing in parallel to explain the matter well.

@anup:
could you pls. further elaborate your point of view on this matter. Thx.
adib_mohammad is offline   Reply With Quote

Old   December 31, 2021, 05:58
Default
  #10
New Member
 
Anup Singh
Join Date: Mar 2020
Posts: 22
Rep Power: 6
Anup Singh is on a distinguished road
adib .. I get your point but the thing is that you have to be clear on how to use your source terms in its implementation..

you can either employ your source term entirely explicitly ie by using fvc...
or employ your source term implicitly ie. by using fvm..

Though you have to keep into account that you need to linearize your source term before its implementation in case you are implementing it implicitly...

For the implicit implementation of your source term, I would suggest you refer to the source term linearization by SV Patanker..

or there are other examples as well...

for example, you can look into the implementation of NS equation in OpenFOAM...
you can notice that the div term should be div(u, u) but it is implemented as div(phi, u) which actually linearizes the non-linear term by taking phi as know value...

you also have to implement the same approach in your problem....

As for how to visualize it ...

I assume you know how that the final solution matrix takes the form
AX = B

Then you can roughly assume that fvm contributes to the formation of the coefficient matrix A whereas fvc contributes the formation of matrix B..

Also if you still have some doubts you can simply discretize your equation and see what you get out of it..
Anup Singh is offline   Reply With Quote

Old   December 31, 2021, 07:09
Default
  #11
New Member
 
Join Date: Dec 2021
Posts: 23
Rep Power: 4
MamboJambo is on a distinguished road
Quote:
Originally Posted by Anup Singh View Post

you can either employ your source term entirely explicitly ie by using fvc...
or employ your source term implicitly ie. by using fvm..
Just a complement here. If you want to implement the source term explicitly you just need to equate it to a DimensionedField<Type, volMesh>. You do not need to call any particular function from fvc.

E.g.

Code:
            fvScalarMatrix TEqn
            (
                fvm::ddt(T) - fvm::laplacian(DT, T)
             ==
                someVolScalarField
            );
MamboJambo is offline   Reply With Quote

Old   December 31, 2021, 09:20
Default
  #12
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 730
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
@adib_mohammad:
can you please share note on the analytical reference solution? We can try to extend the model with a linear source term first and a non-linear source term subsequently.

Cheers.
dlahaye is online now   Reply With Quote

Old   December 31, 2021, 16:25
Default
  #13
New Member
 
Anup Singh
Join Date: Mar 2020
Posts: 22
Rep Power: 6
Anup Singh is on a distinguished road
Yup, that's true in case you have already calculated your source term but if you have to calculate it at the instance then you have to use fvc utility to calculate on the spot which also saves space for you.
Anup Singh is offline   Reply With Quote

Old   January 4, 2022, 14:33
Default
  #14
New Member
 
Join Date: Jan 2015
Posts: 22
Rep Power: 11
adib_mohammad is on a distinguished road
@dlahaye

The number density equation (mentioned in the post) without the source term is used to describe particle deposition on pipe walls, which is a widely used engineering. You can find analytical solution in "Smoke, Dust, and Haze: Fundamentals of Aerosol Behavior" or "Aerosol Technology: Properties, Behavior, and Measurement of Airborne Particles". The so-called peneration curves are plotted used the analytical solution of this equation (penetration tells you the pecentage of initial number of particles that passes through a channel without being deposited on the walls).

adib_mohammad is offline   Reply With Quote

Old   January 6, 2022, 05:18
Default
  #15
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 730
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Thanks. How do you expect the plot to change in case that the source term is added? I.e., what is the influence of the additional source term.
dlahaye is online now   Reply With Quote

Reply

Tags
scalar transport, source term


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[foam-extend.org] Problems installing foam-extend-4.0 on openSUSE 42.2 and Ubuntu 16.04 ordinary OpenFOAM Installation 19 September 3, 2019 18:13
SparceImage v1.7.x Issue on MAC OS X rcarmi OpenFOAM Installation 4 August 14, 2014 06:42
[swak4Foam] Error bulding swak4Foam sfigato OpenFOAM Community Contributions 18 August 22, 2013 12:41
[swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 05:18
emag beta feature: charge density charlotte CFX 4 March 22, 2011 09:14


All times are GMT -4. The time now is 06:47.