CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   adding values to transportProperties in interFoam (

dgadensg April 15, 2010 04:13

adding values to transportProperties in interFoam
Hi all!

I am trying to implement a temperature equation to the interFoam solver for simulation of the filling stage in a injection molding process. I have looked at the implementation made in: Diverging result for Temperature field in interFoam.

The solver compiles just fine, but when i try to run a case, the solver stops before the equations are solved. I have found out that the error occurs in createFields.H when reading the specifik heat (cp) and thermal conductivity (kT) that i have added. Somehow OF reads the values i have specified in transportProperties wrong! Can anyone give me some idea as too what might be the problem?

Code from createFields.H:

    const dimensionedScalar& rho1 = twoPhaseProperties.rho1();
    const dimensionedScalar& rho2 = twoPhaseProperties.rho2();

    const dimensionedScalar& cp1 = twoPhaseProperties.cp1();
    const dimensionedScalar& cp2 = twoPhaseProperties.cp2();

    const dimensionedScalar& kT1 = twoPhaseProperties.kT1();
    const dimensionedScalar& kT2 = twoPhaseProperties.kT2();
Info << "Read transportproperties succesfully\n" << endl;

    // Need to store rho for ddt(rho, U)
    volScalarField rho
        alpha1*rho1 + (scalar(1) - alpha1)*rho2,

        // Need to store cp for TEqn!
        Info << "Saving cp values!\n" << endl;
    volScalarField cp
        alpha1*cp1 + (scalar(1) - alpha1)*cp2,
    // cp.oldTime(); // what does this do?

        // Need to store kT for TEqn!
        Info << "Saving kT values!\n" << endl;   
        volScalarField kT
        alpha1*kT1 + (scalar(1) - alpha1)*kT2,
    // kT.oldTime(); // what does this do?

My transportproperties file:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  1.6                                  |
|  \\  /    A nd          | Web:                      |
|    \\/    M anipulation  |                                                |
    version    2.0;
    format      ascii;
    class      dictionary;
    location    "constant";
    object      transportProperties;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

phase1 // Liquid
    transportModel  Newtonian;
    nu              nu [ 0 2 -1 0 0 0 0 ] 1e-06;
    rho            rho [ 1 -3 0 0 0 0 0 ] 1000;
    cp                  cp [ 0 2 -2 -1 0 0 0 ] 660;
    kT              kT [ 1 1 -3 -1 0 0 0 ] 1.54;

phase2 // Air
    transportModel  Newtonian;
    nu              nu [ 0 2 -1 0 0 0 0 ] 1.48e-05;
    rho            rho [ 1 -3 0 0 0 0 0 ] 1;
    cp                      cp [ 0 2 -2 -1 0 0 0 ] 1009;
    kT              kT [ 1 1 -3 -1 0 0 0 ] 2.85e-02;

sigma          sigma [ 1 0 -2 0 0 0 0 ] 0.07;

// ************************************************************************* //

herbert April 15, 2010 08:27


I've successfully implemented exactly this some time ago. Try this for reading cp (and kT as well):

dictionary phase1 = transportProperties.subDict("phase1");
dimensionedScalar cp1 = phase1.lookup("cp");

Good luck

dgadensg April 15, 2010 09:13

Thanks a lot herbert!

That worked like a charm!

linch January 17, 2011 09:46

Hi interFoamers,

if I want to define temperature-dependent densities for each phase, which implementation of twoPhaseMixture would you suggest me?

Simply imitating already existing fields I came up with a couple of variants, but I haven't a clue what's the difference between them:

in twoPhaseMixture.H:

volScalarField rho1_;
virtual tmp<volScalarField> rho1() const
            return rho1_;


tmp<volScalarField> rho1() const;
or neither of them would be correct? What does tmp<> mean?

I will also need the T-field (temperature), so should I add following lines:

const surfaceScalarField& T_;

like it is implemented for U or phi?

And why twoPhaseMixture.C looks so complicated for alpha1?

alpha1_(U_.db().lookupObject<const volScalarField> (alpha1Name)),
Why not


linch January 17, 2011 09:53

Well, yet another question:
Defining a temperature dependent rho1()-field would imply calculation of rho1-values even for those cells without phase1. Is there a more efficient way?

Trying to answer my own question from the previous post (the first one), I guess that the a) variant makes sense since rho1_ is being used repeatedly in twoPhaseMixture.C. But it's still isn't clear to me if the public rho1() field has to be declared as virtual and tmp<>. The T_(T)-question is still open.

linch May 27, 2011 12:04

Some more questions:
Being newcomer in C++ I don't really understand the implementation of the constructor for twoPhaseMixture objects.

I walked though a C++ tutorial and learned, that a constructor for an object of the class

class someClass {...};
should look like:

someClass::someClass (inputParameters,...) {...};
But in case of twoPhaseMixture it looks different:

twoPhaseMixture::twoPhaseMixture (inputParameters,...):somethingElse,... {...};
What does the stuff after the colon mean?

2). For example

const volVectorField& U_; //intern protected parameter
const volVectorField& U, //public input parameter

Do I understand it right, that both of them (because of &) are pointers to U?
twoPhaseMixture.C (within the constructor):

Is it a common way to initialize a constant in C++ and means something like &U_=&U;? What's the reason for doing this since &U is already a constant and can't be changed even being public?

l_r_mcglashan May 28, 2011 14:06

1) The stuff after the colon is the initialiser list. It constructs other objects (such as transportModel) and its own member variables that you can see declared in the header file.

2) U_ is a reference to the velocity, U, that is passed by reference through the constructor for twoPhaseMixture.

linch May 30, 2011 05:16

1) Thanks a lot, I've got it

2) What's the need of creating U_ if it is equal to U (both are const and both are pointers to the U-storage)?

l_r_mcglashan May 30, 2011 06:41

Don't think of references as pointers. Think of a reference as an alias for an object; U_is in fact U. U_ is needed if any of the member functions in twoPhaseMixture require knowledge of U.

linch May 30, 2011 07:30


Originally Posted by l_r_mcglashan (Post 309738)
U_is in fact U. U_ is needed if any of the member functions in twoPhaseMixture require knowledge of U.

But then, why can't U be used directly? What's the reason for declaring an alias?

l_r_mcglashan May 30, 2011 07:41

You can use U in the class constructor to initialize objects and variables, but functions in the class cannot see U. Try accessing it from within a class member function and you'll see it doesn't compile.

That's why there is an alias, U_.

linch May 30, 2011 07:50

I see...Thank you very much once again.

linch May 30, 2011 08:20

And how can one understand the initialisation of alpha1_ with:

U_.db().lookupObject<const volScalarField> (alpha1Name)

siavash_abadeh September 4, 2011 02:27

hi dear
i have a case that i want to solve 2 phase (liq-air) with heat transfer.
i read your note then i ask u to help me for solve this problem.(if its possible give me your code)
thanks in advance.

bunni September 27, 2012 17:59

newbie question about changes to interFoam

I've been using openFoam for a couple of years now, have gotten comfortable with using the solvers that exist. Now it's time to get elbows deep and change a solver to deal with a new problem. I've read through the programmer's guide, and managed a tutorial or two I found on the web.

In principle, I should be able to make the changes I need in a local solver, and not make changes at the top(library) level, is that correct? I'd like to add a new scalar and vector field to the interFoam example. Not unlike the transport discussed here (we'll save the vector field for another day).

As the original poster had trouble defining the variables in createFields.H, I too had problems there. The solution which seemed to work was:

dictionary phase1 = transportProperties.subDict("phase1");
dimensionedScalar cp1 = phase1.lookup("cp");

My question is: where does this get defined? In createFields.H ? or do I have to edit the class twoPhaseMixture?

One of the examples I worked through just had a new vector field that got its own *.H in the */applications/solvers/(example) directory. The new data was included in the case/0 directory, and a local compile was all that was necessary.

Any help would be appreciated. Or, more examples to work through. I have found tutorials of new variables specifically applied to interFoam, so if anyone knows of those I'd really appreciate that.


xena April 16, 2019 09:29


What does (sigma) in the transportproporties script mean?
is it a constraint ? what does induce it ?

All times are GMT -4. The time now is 04:02.