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/)
-   -   Accessing transportProperties from coded functionObject (https://www.cfd-online.com/Forums/openfoam-programming-development/235557-accessing-transportproperties-coded-functionobject.html)

Shibi April 19, 2021 11:35

Accessing transportProperties from coded functionObject
 
Hello to all,


I would like to create a custom functionObject to use in laplacianFoam.



For this purpose, I need the parameter DT in the dictionary transportProperties.


I have:


Code:

functions
{
    myCodedFunction
    {
        type coded;
        libs (utilityFunctionObjects);
        writeControl runTime;
        writeInterval $writeInterval;


        // Name of on-the-fly generated functionObject
        name test;
       
        codeWrite
        #{
            // Lookup for T
            const volScalarField& T = mesh().lookupObject<volScalarField>("T");

            // Gets the DT coefficient from
          const dictionary& transportProperties = mesh().lookupObject<IOdictionary>
          (
            "transportProperties"
          );   

            const scalar alpha (transportProperties.getScalar("DT"));

            Info << "Alpha is: " << alpha << endl;

        #};
    }

}

However, I get the error:

Code:


    request for dictionary transportProperties from objectRegistry region0 failed
    available objects of type dictionary are
4(fvSchemes fvOptions fvSolution data)


It the transportProperties not created yet? Am I looking for it in a wrong manner?

clapointe April 19, 2021 15:26

A quick look at the laplacianFoam code suggests that the transportProperties dictionary is only created (inside an if statement) if DT doesn't exist (otherwise it's read). So to guess at a fix you could create a custom version of laplacianFoam in which you force the creation of the dictionary without the if statement, or create a dummy/copy of it inside your function object like :

Code:


    IOdictionary dummyTransportProperties //ensure the original isn't duplicated
    (
        IOobject
        (
            "transportProperties",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        )
    );

    //then read from dict
    const scalar alpha (transportProperties.getScalar("DT"));

Note that I've not tested the above code, but hopefully it will lead you in the right direction.

Caelan


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