CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   Initializing reference variable of type objectRegistry (

deji August 5, 2010 15:05

Initializing reference variable of type objectRegistry
Hey there foamers. I would like to initialize a reference variable of type objectRegistry and not so certain how to do that. In this line of code,

const Foam::compressible::LESModel & sgs = obr2.lookupObject<compressible::LESModel>("LESProperties");
obr2 is the reference variable of type objectRegistry. I initially defined a class and a constructor to help initialize it, but I am not quite getting it to work. Can anyone help?:confused:

deji August 5, 2010 15:39

so can i say something like:

const objectRegistry var1
const objectRegistry& obr2 = var1

so that i initialized obr2 ?? :confused:


deji August 5, 2010 19:19

i am still unable to get the initialization to work. there has to be someone on the forum that can help me with this question as i am not that experienced with OpenFOAM.

jaswi August 6, 2010 03:39

Hi Deji

There are some issues with that code line. You are basically using the
object lookup mechanism. You search for a type (i.e. class) of object. Here, if I am not wrong, you are looking up an object LESProperties of type IODictionary. In your code line there is no mention of the type of the object LESProperties. All you have is

const Foam::compressible::LESModel & sgs =
and that is nothing but namespaces. search forum for the keyword lookUpobject and you will find numerous examples on how to do that properly. If you will not get that right then please post the error as well so that we have more info.

Hope that helps

deji August 6, 2010 09:12

Hello Jaswi.

The error that I am getting states that: "obr_ was not defined in that scope"
Essentially, I would like to read the alphaEff and alpha field at the wall. I did try to read these quantities, but I saw that they were not defined in my constant folder that has the LESProperties dictionary. Should I add these variables to my LESProperties dictionary?


************************************Code********** **************************************************
1) const Foam::compressible::LESModel & sgs = obr_.lookupObject<compressible::LESModel>("LESProp erties");
2) const scalarField alphaEffw = sgs.alphaEff()().boundaryField()[patchK];
3) const scalarField alphaw = sgs.alpha().boundaryField()[patchK];

************************************Code********** **************************************************

deji August 6, 2010 09:36

By the way, Foam::compressible is a namespace that has the LESModel as a class contained within it.


jaswi August 6, 2010 11:06

Hi Deji

I still could not understand your question.
Aas far as i know LESProperties is an IOdictionary. If I want to read something directly from it then first I first create a reference to it like this:

const IOdictionary& myLesDict = mesh.lookupObject<IOdictionary>("LESProperties");

This will create the reference. To check that it really works, just write:

Info << myLesDict << endl;

It will print the whole dictionary on the screen.

you can also print just the part relevant to your model like this:

Info << myLesDict.subDict("smoothCoeffs") << endl;

then it just prints that part of the dictionary.

Perhaps you want to read some thing from the dictionary then you can add another subdictionary to the existing LESProperties, something like dejiCoeffs and put your values in it. For example i added at the end of my LESProperties

myValue1 10;
myValue2 20.0;

and then

Info << myLesDict.subDict("dejiCoeffs") << endl;

prints these values from the dict.
In case you want to read these values into a variable then you will do like this:

const scalar myValue(readScalar(myLesDict.subDict("dejiCoeffs") .lookup("myValue1")));

Info << myValue << endl;

shall now print 10.

Hope this is what you were looking for. If not then please write again explaining what are the types of object you want to read becuase you say


would like to read the alphaEff and alpha field at the wall.
if these variables are of type patchFields then I think LESProperties is not the right place to read in these fields.

Let us know a bit more and we will try to help you :-).

deji August 6, 2010 11:30

Thanks for your replies Jaswi. You are right, that those quantities (alphaEff and alpha) are not in the LESProperties dictionaries. I checked the doxygen sourceguide and they are volScalarFields.

Well, I am writing a post-processor to compute the Nusselt # along the wall in a turbulent free convection flow. And, the Nusselt # is a function of alphaEff and alpha amongst other variables, and I am trying to read these values at the wall. And, I did verify that they cannot be in the LESProperties dictionary. Thanks.

Best regards

deji August 6, 2010 13:50

i was looking into this an discovered that this:
virtual tmp<volScalarField> alphaEff , so since alphaEff is a temporary object, and is destroyed during the simulation, does that mean that i cannot i basically cannot read such quantities for my post-processor ?


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