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

functionObject solver, storing fields in dataBase

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By theBananaTrick

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 25, 2022, 14:06
Default functionObject solver, storing fields in dataBase
  #1
New Member
 
Join Date: Feb 2022
Posts: 25
Rep Power: 4
theBananaTrick is on a distinguished road
Hello,


I am taking a look at the functionObject solver scalarTransport. Here, a function exists to create a new field if not found in the dataBase and return a reference to it.

Code:
volScalarField& transportedField();
The implementation reads:

Code:
Foam::volScalarField& Foam::functionObjects::scalarTransport::transportedField()
{
    if (!foundObject<volScalarField>(fieldName_))
    {
        auto tfldPtr = tmp<volScalarField>::New
        (
            IOobject
            (
                fieldName_,
                mesh_.time().timeName(),
                mesh_,
                IOobject::MUST_READ,
                IOobject::AUTO_WRITE
            ),
            mesh_
        );
        store(fieldName_, tfldPtr);

        if (phaseName_ != "none")
        {
            mesh_.setFluxRequired(fieldName_);
        }
    }

    return lookupObjectRef<volScalarField>(fieldName_);
 }
A pointer to the field is being stored in
Code:
store(fieldName_, tfldPtr);
I would like to know the intent of this approach. Is it to be able to access this field from inside the solver?

e.g.,

Code:
volScalarField& myTransportedField = mesh.lookupObjectRef<volScalarField>("nameOfmyTransportedField")
Some calculation with this field
Or something else?

Wouldn't it be helpful to have a variable defined inside the functionObject to store the reference to the volScalarField given by the function?

Code:
volScalarField& transportedField_ (transportedField())
This way, it wouldn't be necessary to call the function twice (line 205 and 251)
wht likes this.
theBananaTrick is offline   Reply With Quote

Old   February 25, 2022, 14:13
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,695
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
The idea is not some silly handling of local field storage but rather to define/update a field that should be visible outside of the function object. For example, you might want to use a sampled surface function object to sample and write a slice through the field. For any of this to happen, the field has to be globally available - aka objectRegistry
olesen is offline   Reply With Quote

Old   February 26, 2022, 08:59
Default
  #3
New Member
 
Join Date: Feb 2022
Posts: 25
Rep Power: 4
theBananaTrick is on a distinguished road
Quote:
Originally Posted by olesen View Post
The idea is not some silly handling of local field storage but rather to define/update a field that should be visible outside of the function object. For example, you might want to use a sampled surface function object to sample and write a slice through the field. For any of this to happen, the field has to be globally available - aka objectRegistry

Hello Mr Olesen,


Thank you very much for your insight! Now I know what is the intent!
theBananaTrick 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
Population Balance Modeling (PBM) - Ansys Fluent chittipo FLUENT 164 November 18, 2023 11:54
How do I connect a geometry to my solver devansh.purohit Main CFD Forum 4 November 16, 2021 08:51
Floating Point Exception Error nyox FLUENT 11 November 30, 2018 12:31
[ANSYS Meshing] Help with element size sandri_92 ANSYS Meshing & Geometry 14 November 14, 2018 07:54
Can you help me with a problem in ansys static structural solver? sourabh.porwal Structural Mechanics 0 March 27, 2016 17:07


All times are GMT -4. The time now is 06:15.