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/)
-   -   objectRegistry::lookupObject<scalar> (http://www.cfd-online.com/Forums/openfoam-programming-development/126758-objectregistry-lookupobject-scalar.html)

chyczewski November 25, 2013 17:00

objectRegistry::lookupObject<scalar>
 
(I have tried to add to an existing thread of the same title initiated by Brent Craven a couple years ago but don't seem to have been successful. I'm reposting here to cover my bases. Sorry for duplication, if any).


I have followed the procedure outlined in an earlier post (quoted at bottom) to update the boundary value in the course of a run and seem to have it working. But I get a warning message that is troubling me and I'd like to eliminate it. Here is the warning:

--> FOAM Warning :
From function Field<Type>::Field(const word& keyword, const dictionary&, const label)
in file /....../Field.C at line 262
Reading "myDict" from line 0 to line 0
expected keyword 'uniform' or 'nonuniform', assuming deprecated Field format from Foam version 2.0.

Here is my coding:
The dictionary is created in createFields.H:
Code:

IOdictionary myDict
(
    IOobject
    (
        "myDict",
        runTime.constant(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
        )
);

The variable is set in my main loop
Code:

myDict.set("myValue",aeq[m][n]);
Finally, refValue is assigned the value of this variable in updateCoeffs() (I copied inletOutletFvPatchField and customized)
Code:

const dictionary& myDict = this->db().objectRegistry::lookupObject<IOdictionary>("myDict");
this->refValue() = Field<Type>("myValue",myDict,this->refValue().size());

If I print the value of refValue over the patch it changes appropriately with changes in m and n (used in the set command). So I think it is working properly. Does anyone know how to eliminate the warning or if it can be ignored? If it can be ignored, how do I suppress printing it? I took a look at line 262 of Field.C and get lost when it appears to be using a scalar as a boolean. Any help would be appreciated. Thanks.

Quote:

Originally Posted by brent_craven (Post 314078)
Yes. The methodology discussed by David above (http://www.cfd-online.com/Forums/ope...tml#post309556) worked well for me:

1. Declare the scalar as an IOobject
2. Calculate the scalar in your solver
3. Update the new scalar value with: scalarDict.set("nameOfScalar", valueOfScalar);
4. Access the new scalar value in your BC via a "db().lookupObject<IOdictionary>" (e.g., http://www.cfd-online.com/Forums/ope...tml#post309443)


Bernhard November 26, 2013 02:58

May I ask why you are using a dictionary, if you define the variable in the source code anyhow?

chyczewski November 26, 2013 08:09

Hi Bernhard,

My understanding is that this is a good way to bring a variable from the scope of the main solver into the boundary condition (following the discussion in the quoted thread). It is not practical to calculate this value within the boundary condition because a cubic equation needs to be solved at each point in wavenumber space to fill the array (aeq[m][n]) and it doesn't change over the course of the run. Also, I would have to bring a number of additional variables into the bc to do the calculation.

chyczewski November 27, 2013 12:36

Thanks to help from Dave Boger and Brent Craven, the solution was found to be replacing

Code:

myDict.set("myValue",aeq[m][n]);
with
Code:

std::stringstream strs;
strs<<"uniform "<< aeq[m][n];
myDict.set("myValue",strs.str().c_str()));



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