CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Read fields from viscosity model (https://www.cfd-online.com/Forums/openfoam-programming-development/126540-read-fields-viscosity-model.html)

Gaetano November 20, 2013 06:45

Read fields from viscosity model
 
Hi all.

I'm having a I/O related problem. To put it simple: I need to read some scalar fields defined in the main solver (based on interFoam, OpenFOAM 2.1.1).
Here's what I've done (myModel.C):

Code:

// * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //

Foam::tmp<Foam::volScalarField>
Foam::viscosityModels::myModel::calcNu() const
{

    const volScalarField& myField = U_.db().lookupObject<volScalarField>("myField");
//    THE SAME WITH:
//    const volScalarField& myField = U_.mesh().lookupObject<volScalarField>("myField");

    return
    (
        min
        (
            nu0_,
            //MY FUNCTION GOES HERE
      )
    );
}

Both the viscosityModel (wmake libso) and the solver compiles without errors/warnings.
Here's the output of the simulation:

Code:

Reading transportProperties

./mySolver: symbol lookup error: ./mySolver: undefined symbol: _ZN4Foam15twoPhaseMixtureC1ERKNS_14GeometricFieldINS_6VectorIdEENS_12fvPatchFieldENS_7volMeshEEERKNS1_IdNS_13fvsPatchFieldENS_11surfaceMeshEEERKNS_4wordE

The field is defined (in createFields.H, before defining "twoPhaseProperties") as:
Code:

    volScalarField myField
    (
        IOobject
        (
            "myField",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );

What am I doing wrong? What does that error mean? Are those weird sequence of character interpretable or not (I found here that 1ERKNS is the representation base 33 of the number 56731153!!!)?

Another question: how can I access the overall rho field from within my viscosity model?

Thanks in advance :)
Gaetano

Bernhard November 20, 2013 08:51

I think what you need, is probably to look up the fields from the object registry database, which you can access via the mesh.

There are multiple topics that should help you find how to do it, using these keywords
http://www.cfd-online.com/Forums/ope...-registry.html contains a lot of info.

Aurelien Thinat November 21, 2013 05:29

Hi Gaetano and Bernhard,

I'm dealing with the same problem.

- In incompressible models, the viscosity object constructor contains the reference of the volScalarField U. So we can define an object "mesh" :
Code:

mesh& myMesh = U.mesh();
And then with look up object, we can get everything (not tested, but I guess it may be right) :
Code:

volScalarField& T = myMesh().lookupObject<volScalarField>("T");
- Now for compressible models. The constructor doesn't contain any volVectorField or volScalarField. And the function "mu()" takes only two scalars p and T in arguments.
How can I get an access to the mesh without modifying the transport object's constructor ?
I also saw this :
Code:

const volVectorField& U = obr_.lookupObject<volvectorField>("U");
But I need to find out how to declare the object "obr_".

Gaetano November 26, 2013 12:37

As said by Bernhard and Aurelien it is possible to access fields in this way:

Code:

const volScalarField& myField = U_.mesh().lookupObject<volScalarField>("myField");
For future reference, a useful step-by-step tutorial is this implementation of a temperature dependent viscosity model.

Thanks for your help! :)


All times are GMT -4. The time now is 22:46.