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

Why is dictionary read twice in the scalarTransport functionObject?

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By simrego

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 21, 2021, 10:04
Default Why is dictionary read twice in the scalarTransport functionObject?
  #1
Member
 
Rishikesh
Join Date: Apr 2016
Posts: 63
Rep Power: 9
mrishi is on a distinguished road
Hi,


in the ESI OpenFOAM source code for the file scalarTransport.C, if we look at the constructor, I understand that the bold text initializes members of the object. However, after this, read(dict) is called by the constructor, where it seems to me that the same dictionary is read again. Do these two calls to dictionary achieve different things and can we remove some redundancy here?


The constructor:

Code:
 Foam::functionObjects::scalarTransport::scalarTransport
(
    const word& name,
    const Time& runTime,
    const dictionary& dict
)
:
    fvMeshFunctionObject(name, runTime, dict),
    fieldName_(dict.getOrDefault<word>("field", "s")),
    phiName_(dict.getOrDefault<word>("phi", "phi")),
    rhoName_(dict.getOrDefault<word>("rho", "rho")),
    nutName_(dict.getOrDefault<word>("nut", "none")),
    phaseName_(dict.getOrDefault<word>("phase", "none")),
    phasePhiCompressedName_
    (
        dict.getOrDefault<word>("phasePhiCompressed", "alphaPhiUn")
    ),
    D_(0),
    constantD_(false),
    nCorr_(0),
    resetOnStartUp_(false),
    schemesField_("unknown-schemesField"),
    fvOptions_(mesh_),
    bounded01_(dict.getOrDefault("bounded01", true))
{
    read(dict);

    // Force creation of transported field so any BCs using it can
    // look it up
    volScalarField& s = transportedField();

    if (resetOnStartUp_)
    {
        s == dimensionedScalar(dimless, Zero);
    }
}
The read(dict) function:
Code:
bool Foam::functionObjects::scalarTransport::read(const dictionary& dict)
{
    fvMeshFunctionObject::read(dict);

    dict.readIfPresent("phi", phiName_);
    dict.readIfPresent("rho", rhoName_);
    dict.readIfPresent("nut", nutName_);
    dict.readIfPresent("phase", phaseName_);
    dict.readIfPresent("bounded01", bounded01_);

    schemesField_ = dict.getOrDefault("schemesField", fieldName_);
    constantD_ = dict.readIfPresent("D", D_);
    alphaD_ = dict.getOrDefault<scalar>("alphaD", 1);
    alphaDt_ = dict.getOrDefault<scalar>("alphaDt", 1);

    dict.readIfPresent("nCorr", nCorr_);
    dict.readIfPresent("resetOnStartUp", resetOnStartUp_);

    if (dict.found("fvOptions"))
    {
        fvOptions_.reset(dict.subDict("fvOptions"));
    }

    return true;
}
mrishi is offline   Reply With Quote

Old   June 22, 2021, 03:59
Default
  #2
Senior Member
 
anonymous
Join Date: Jan 2016
Posts: 416
Rep Power: 14
simrego is on a distinguished road
Hi!

It is not exactly the same. In the constructor you set default values (getOrDefault). In the read() you read IF present (readIfPresent)
I guess it makes possible to reread the file during runtime, and yes there is a little redundancy but in the constructor you have to give values for these members that's why you use getOrDefault. But read() does some more so you have to call it.



So I think it is totally reasonable as long as you can modify it in runtime and you have to reread the file.
olesen likes this.
simrego is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
how to calculate mass flow rate on patches and summation of that during the run? immortality OpenFOAM Post-Processing 104 February 16, 2021 08:46
Dictionary in turbulence model NewKid OpenFOAM Programming & Development 4 February 18, 2019 21:16
How read viscosity on Chinese rotational viscometer? abuhafss Main CFD Forum 0 January 22, 2019 02:44
driftFluxFoam viscosity model modification problem dleduc OpenFOAM Programming & Development 15 October 1, 2018 09:37
Read properties per component from an input file dictionary Cyp OpenFOAM Programming & Development 29 November 1, 2015 21:41


All times are GMT -4. The time now is 07:44.