CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Accessing transportProperties from coded functionObject

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 19, 2021, 11:35
Default Accessing transportProperties from coded functionObject
  #1
Member
 
Join Date: Feb 2020
Posts: 90
Rep Power: 6
Shibi is on a distinguished road
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?
Shibi is offline   Reply With Quote

Old   April 19, 2021, 15:26
Default
  #2
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
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
__________________
Public git repository : https://github.com/clapointe2011/public
clapointe is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing 0 time directory in coded functionObject JM27 OpenFOAM Programming & Development 3 May 26, 2023 16:50
Cannot find functionObject file residuals vava10 OpenFOAM Pre-Processing 2 November 14, 2020 12:21
accessing 0 time directory in coded functionObject JM27 OpenFOAM Post-Processing 0 November 21, 2018 08:41
Coded FunctionObject to calculate distance to axis? Nothing written be_inspired OpenFOAM Programming & Development 0 February 22, 2018 18:23
codeInclude in coded function in controlDict, and yPlus LuisAlberto OpenFOAM Programming & Development 4 August 18, 2015 12:48


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