CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   Inheriting kOmega: why can't I change the constructor? (

AlmostSurelyRob October 26, 2011 05:34

Inheriting kOmega: why can't I change the constructor?
Dear All,

I am modifying some RAS models in order for them to work better with two-phase stratified flows. It was observed that standard models produce excessive viscosity at the interface and due to this overpredict pressure gradients.

Anyway, I am having a problem with a fairly simple, I should think, piece of code. Please have a look at this:


#ifndef kOmegaStrat_H
#define kOmegaStrat_H

#include "kOmega.H"

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

namespace Foam
namespace incompressible
namespace RASModels

                          Class kOmega Declaration

class kOmegaStrat
    public kOmega
    const volScalarField& alpha1_;


    //- Runtime type information

    // Constructors

        //- Construct from components

            const volVectorField& U,
            const surfaceScalarField& phi,
            transportModel& transport,
            const volScalarField& alpha1, //ADDED!
            const word& turbulenceModelName = turbulenceModel::typeName,
            const word& modelName = typeName
        kOmega(U, phi, transport, turbulenceModelName, modelName),
        alpha1_(alpha1) //ADDED!

    //- Destructor
    virtual ~kOmegaStrat()

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

} // End namespace RASModels
} // End namespace incompressible
} // End namespace Foam

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


So the only change I wanted to make so far is to include phase fraction from VOF equation. The error I am getting from wmake libso is:
Description Resource Path Location Type
no matching function for call to

‘Foam::incompressible::RASModels::kOmegaStrat::kOmegaStrat(const Foam::volVectorField&, const Foam::surfaceScalarField&, Foam::transportModel&, const Foam::word&)’    stratTurbulence        line 126, external location: /home/c111269/OpenFOAM/OpenFOAM-2.0.x/src/turbulenceModels/incompressible/RAS/lnInclude/RASModel.H    C/C++ Problem
Is there anything I can do about this? Please advise. If I remove alpha1 and the appropriate entries in the constructor the library compiles fine.

In fact, I have already written a small library by writing my own super class equivalent to RASModel. Then I create particular turbulence models by inheriting from this class. This approach, however, has certain drawbacks. For example I also had to rewrite yPlusRAS tool and all the Wall Functions I am using. It is a bit tedious, especially that the changes I have to implement are usually minute. Is there any way to do it more elegantly and more... pragmatically?

nimasam October 26, 2011 09:34

a class can accept different constructor , so instead of changing the present constructor, add ur new constructor beside it , may be it works

AlmostSurelyRob October 26, 2011 12:09

Thanks for the reply.

I know that the class can have several constructors and indeed I have already checked that if I use a constructor without alpha1 in the argument list, the library compiles. But still I have a duty to my class to initialise alpha1 with a reasonable value and I do not feel competent to fulfil this duty without a proper reference. :-)

At the end of the day, I would like to be able to use this class in a VOF solver like interFoam in the same manner it works now i.e. by invoking turbulenceModel constructor, perhaps with a different set of parameters.

So I think that that my problem can be solved by changing the super class i.e. turbulenceModel. There's this part I don't quite understand:


            const volVectorField& U,
            const surfaceScalarField& phi,
            transportModel& transport,
            const word& turbulenceModelName = typeName

    // Selectors

        //- Return a reference to the selected turbulence model
        static autoPtr<turbulenceModel> New
            const volVectorField& U,
            const surfaceScalarField& phi,
            transportModel& transport,
            const word& turbulenceModelName = typeName

What is a selector? What is autoPtr? Any help, references or hints will be greatly appreciated!

adhiraj October 26, 2011 21:31

You probably broke the runtime selection. take a look at this link, it may be useful.

It is a very useful feature, especially if you do not know apriori which model will be used. But it can be touchy.

AlmostSurelyRob October 27, 2011 04:34

Thank you - that was a very important article. Now it all makes sense. Just to make it clear - I haven't broken the run time selection mechanism yet! I intend to do it at some point, but not now.

Hopefully after reading this article I will be able to fix it.

I have also realised that for my purposes it's probably better to work with nu field which is available in standard incompressible RAS model. This would allow me to avoid changing the constructors and avoid a possibility of breaking run time selection mechanism. I simply have to save the lowest and the highest viscosity and make sure that the initial field contains the two extremes. The main idea is that I want to treat the gas phase differently than the liquid phase, so this is why I am going through all of this.

But anyhow this was a very informative discussion - thank you for all the comments.

All times are GMT -4. The time now is 10:17.