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/)
-   -   Read IOdictionary entries from within turbulence model (http://www.cfd-online.com/Forums/openfoam-programming-development/105559-read-iodictionary-entries-within-turbulence-model.html)

Arnoldinho August 2, 2012 10:40

Read IOdictionary entries from within turbulence model
 
Hi all,

I'm "unable" to read a IOdictionary from within a modified kOmegaSST turbulence model. How can I implement such a behaviour, so that I can use the variables from the dictionary for some calculations within the turbulence model?

I so far was able to make an entry of the dictionary in kOmegaSST.C (in the constructor), and in kOmegaSST.H (in the class declaration). An entry of dimensionedScalar d_grain is also in the constructor - but I'm not able to make an entry in the constructur for d_grain...

kOmegaSST.H:
Quote:

class kOmegaSSTRough
:
public RASModel
{
...
IOdictionary sedTransDict_;
dimensionedScalar dgrain;
...
}
kOmegaSST.C:
Quote:

kOmegaSSTRough::kOmegaSSTRough
(
const volVectorField& U,
const surfaceScalarField& phi,
transportModel& lamTransportModel
)
:
...
sedTransDict_
(
IOobject
(
"sedTransDict",
runTime_.system(),
runTime_,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
{
...
dgrain(sedTransDict_.lookup("d_grain")/1000);
}
The latter entry does not compile, whatever I write here. I also tried variants of
Quote:

dgrain
(
"dgrain",
dimensionSet(0,1,0,0,0,0,0),
scalar(readScalar(sedTransDict_.lookup("d_grain"))/1000)
);
Maybe someone can make me a bit more 'familiar' with such declarations?

Arne

Bernhard August 3, 2012 03:02

It would help if you post the first of your compilation errors.


Instead of creating a complete new dictionary file, it may be a nicer solution to include your dictionary in the RASProperties file, by using a subDict. That is relatively easy to construct I suppose. You can also have a look at how it is implemented for certain LES models. It seems a bit overkill to me to define a new dictionary file here.

Arnoldinho August 3, 2012 03:15

Yes thats true Bernhard, I should have posted the error message.

To simplify the problem, I eliminated the dimensionality and used a normal scalar. Therefore in kOmegaSSTRough.H I have
Quote:

class kOmegaSSTRough
:
public RASModel
{
...
IOdictionary sedTransDict_;
scalar dgrain;
...
public:
...
}
and in kOmegaSSTRough.C:
Quote:

kOmegaSSTRough::kOmegaSSTRough
(
const volVectorField& U,
const surfaceScalarField& phi,
transportModel& lamTransportModel
)
:
sedTransDict_
(
IOobject
(
"sedTransDict",
runTime_.system(),
runTime_,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
...
{
dgrain(readScalar(sedTransDict_.lookup("d_grain")) );
}
The compilation error in kOmegaSSTRough.C then is
Quote:

kOmegaSSTRough.C:293: error: ‘((Foam::incompressible::RASModels::kOmegaSSTRough *)this)->Foam::incompressible::RASModels::kOmegaSSTRough:: dgrain’ cannot be used as a function
In my case, using a seperate dictionary is not an overkill, as a lot more entries are written there which are used by the solver. The d_grain entry is used by the solver as well, so I'd like to avoid a seperate dictionary with same entries.

Arne

Arnoldinho August 7, 2012 11:59

Are there any hints on how to read values from a dictionary?

wyldckat August 7, 2012 14:36

Greetings to all!

@Arne:
The short DIY answer ;):
Code:

cd $FOAM_UTILITIES
find . -name "*Dict"
cd $FOAM_TUTORIALS
find . -name "*Properties"

The semi-short answer:
  1. From the list of files given by the above commands, you can have a look at the source code for "topoSet" for coding ideas. The downside is that there you won't find any cases with units in them.
  2. After searching a bit more, I found this valuable example of a direct access to a dictionary: "applications/solvers/compressible/rhoCentralFoam/readThermophysicalProperties.H" - online: https://github.com/OpenFOAM/OpenFOAM...alProperties.H
    There you should find how to read a value with units in it.
    I found by running:
    Code:

    cd $FOAM_APP
    find . -name "*.H" | xargs grep -sl thermophysicalProperties

Have fun!
Bruno

Arnoldinho August 8, 2012 11:31

Thanks for your help and hints Bruno!

My problem seems nevertheless more related to "where to put the variables and declarations in the source code", i.e. public or private member functions, the constructor, namespaces, class declaration and so on. I'm afraid that I'm not familiar enough with this - but maybe this is a "standard" c++ problem and not directly related to OF.

Arne

Arnoldinho August 8, 2012 12:38

Ok, it seems that I was thinking a bit too complicated. So now I have just put it in void kOmegaSSTRough::correct(), where I need the value, and it works fine:

Code:

void kOmegaSSTRough::correct()
{
    IOdictionary sedTransDict_
    (
        IOobject
        (
            "sedTransDict",
            runTime_.system(),
            runTime_,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );

    dimensionedScalar dgrain_
    (
            "dgrain_",
            dimensionSet(0,1,0,0,0,0,0),
            scalar(readScalar(sedTransDict_.lookup("d_grain")))
    );
    dgrain_ /= 1000;    // convert m -> mm
    ...
}

There is just one more (not that important) thing: is dgrain_ now read every single time step? If so, how can I change this, in oder to save some time? The values are not changing and therefore need to be read only once when the simulation starts.

Arne

Hisham August 11, 2012 06:59

Hello Arne,

Code:

IOobject::MUST_READ_IF_MODIFIED
Regards
Hisham

Arnoldinho August 11, 2012 07:13

Thanks Hisham,

but I have already tried that: If gives me the error message
Quote:

error: ‘MUST_READ_IF_MODIFIED’ is not a member of ‘Foam::IOobject’
which is curious as I have already seen this used with an IOobject somewhere.

Any hints?

Hisham August 11, 2012 07:15

Maybe it is the OF version???


All times are GMT -4. The time now is 12:13.