CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   Source Term on Scalar Transport Equation ( January 27, 2011 12:59

Source Term on Scalar Transport Equation

I have to add a transport scalar equation on the variable "C" but the problem is how to add the source term.

Using for instance SimpleFoam and modifying the solver I obtain the following equation for C "Ceqn.H":

+fvm::div(phi, C)
-fvm::laplacian(nu, C)

This is without source term and it works after I tested, including all the changes I have to do in the NewSimpleFoam.C and in createFields.H

Suppose that I want to add the sorce term with the following expression ST=C*(1-C), considering that I have to respect the dimensions in the solving, how can I set this ?

thanks in advance


santos January 28, 2011 06:20


You can just include your source term as 'C*(1-C)' in the Ceqn.H equation. In this way it will be defined explicitly. I am not sure if you can work out the dimensions of this source term so it is consistent with the other terms.

Probably you want the source term to be implicit for better convergence stability, so you need to include it as: 'fvm::Sp(k,C)', where k is a constant that is to be multiplied by C.

Jose January 28, 2011 06:32

Hi, thanks for the reply. If I consider the second option, implicit ST, and I write the fvm::Sp(k,C) to the Ceqn.H, do you think I should also declare the k in the createFields.H? regards alex

santos January 28, 2011 06:56


k is a placeholder for the constants that are multiplied by C in your source term.

Hence, if your source term is 2*C, it is defined implicitly as: fvm::Sp(2,C). The Programmers Guide that comes with OpenFOAM has more information on this.

Jose January 28, 2011 08:01

thanks a lot! I will try to fix it.


alex January 31, 2011 04:49

re: Source Term on Scalar Transport Equation
Hi I setted the equation as follows, but everytime there is an error. Do you know how can I solve it?

Actually, considering I need a source term dimensioned as [00-10000] I wrote the equation in this was, but I still don't get the error. Regards. alex



+fvm::div(phi, C)
-fvm::laplacian(nu, C)==

Making dependency list for source file SourceFanzySimple.C
SOURCE=SourceFanzySimple.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3 -DNoRepository -ftemplate-depth-40 -I/cvos/shared/apps/OpenFOAM/OpenFOAM-1.7.1/src/turbulenceModels -I/cvos/shared/apps/OpenFOAM/OpenFOAM-1.7.1/src/turbulenceModels/incompressible/RAS/RASModel -I/cvos/shared/apps/OpenFOAM/OpenFOAM-1.7.1/src/transportModels -I/cvos/shared/apps/OpenFOAM/OpenFOAM-1.7.1/src/transportModels/incompressible/singlePhaseTransportModel -I/cvos/shared/apps/OpenFOAM/OpenFOAM-1.7.1/src/finiteVolume/lnInclude -IlnInclude -I. -I/cvos/shared/apps/OpenFOAM/OpenFOAM-1.7.1/src/OpenFOAM/lnInclude -I/cvos/shared/apps/OpenFOAM/OpenFOAM-1.7.1/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64GccDPOpt/SourceFanzySimple.o
In file included from SourceFanzySimple.C:63:
Ceqn.H: In function ‚int main(int, char**)‚:
Ceqn.H:6: error: no matching function for call to ‚ddt(Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >)‚
/cvos/shared/apps/OpenFOAM/OpenFOAM-1.7.1/src/finiteVolume/lnInclude/readSIMPLEControls.H:6: warning: unused variable ‚momentumPredictor‚
/cvos/shared/apps/OpenFOAM/OpenFOAM-1.7.1/src/finiteVolume/lnInclude/readSIMPLEControls.H:9: warning: unused variable ‚transonic‚
make: *** [Make/linux64GccDPOpt/SourceFanzySimple.o] Error 1

santos January 31, 2011 05:52


I am not sure you can include your source term like that, ddt should be in the form ddt(C) or ddt(rho,C).

If you need: (C*(1-C))/dt, then try:

+fvm::div(phi, C)
-fvm::laplacian(nu, C)==

The source term is not fully implicit, as 1-C is defined explicitly. Maybe someone else knows how to define the whole term implicit.

Jose January 31, 2011 06:04

Thanks Josť!

I have also another way, just I want you to give me an opinion about it:

if I write explicitly the ST as (C*a*(1-C)) where "a" has the dimension of [1/time] to keep the dimension in the parabolic equation, setted in the transportproperties, do you think is it reasonable?

santos January 31, 2011 06:19

Actually I have used in the past a 'quick and dirty' trick that allows you to do just that:
sourceTerm = (1-C)*C*runTime.deltaT().value()/runTime.deltaT();

Therefore, you get the correct dimension, without needing to care about the deltat value.

Jose January 31, 2011 08:56

thanks again for the reply! :)



All times are GMT -4. The time now is 20:51.