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

lookupObject meaning

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By Severus
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 19, 2024, 09:29
Default lookupObject meaning
  #1
Member
 
Ching Liu
Join Date: Sep 2017
Posts: 46
Rep Power: 8
qingqingliu is on a distinguished road
I am learning the programming in interCondensatingEvaporatingFoam solver. In the constant folder, the following is used to define T:
const volScalarField& T = mesh_.lookupObject<volScalarField>("T");
I am wondering what the "mesh_" mean?

In the other solver, interPhaseChangeFoam, they use the following to define p:
const volScalarField& p = alpha1_.db().lookupObject<volScalarField>("p")

One uses mesh_, while the other one uses alpha1_.db(), what are the differences between these two terms?
qingqingliu is offline   Reply With Quote

Old   March 19, 2024, 12:16
Default
  #2
Member
 
Shravan
Join Date: Mar 2017
Posts: 60
Rep Power: 9
Severus is on a distinguished road
Hello,
We will make full use of the API guide (Doxygen) to understand.

objectRegistry and lookupObject
With both mesh_ and db you call the lookupObject member function. Note that lookupObject is a member function in the objectRegistry class: https://www.openfoam.com/documentati...ce.html#l00541. For the documentation regarding lookupObject member function, see line 482 - https://www.openfoam.com/documentati...8H_source.html

You can understand the objectRegistry better here: https://openfoamwiki.net/index.php/Contrib/IOReferencer

mesh_ and db
mesh_ is a reference to the fvMesh class defined in temperaturePhaseChangeTwoPhaseMixture class. See line 69: https://www.openfoam.com/documentati...ce.html#l00068
You are able to access mesh_ in the constant class because the constant class inherits temperaturePhaseChangeTwoPhaseMixture class (https://www.openfoam.com/documentati...1constant.html)

db is also a reference to the objectRegistry class, but is defined in IOobject.H class (https://www.openfoam.com/documentati...8H_source.html)

In other words, in both the cases you are calling the lookupObject member function of the objectRegistry class but with different instances that have been created from the derived classes. With both you are able to access all your field variables such as temperature and pressure in the mesh.

I am not an expert in C++, so feel free to correct me if I messed up somewhere.

Thanks
olesen likes this.
Severus is offline   Reply With Quote

Old   March 19, 2024, 12:38
Default
  #3
Member
 
Ching Liu
Join Date: Sep 2017
Posts: 46
Rep Power: 8
qingqingliu is on a distinguished road
Quote:
Originally Posted by Severus View Post
Hello,
We will make full use of the API guide (Doxygen) to understand.

objectRegistry and lookupObject
With both mesh_ and db you call the lookupObject member function. Note that lookupObject is a member function in the objectRegistry class: https://www.openfoam.com/documentati...ce.html#l00541. For the documentation regarding lookupObject member function, see line 482 - https://www.openfoam.com/documentati...8H_source.html

You can understand the objectRegistry better here: https://openfoamwiki.net/index.php/Contrib/IOReferencer

mesh_ and db
mesh_ is a reference to the fvMesh class defined in temperaturePhaseChangeTwoPhaseMixture class. See line 69: https://www.openfoam.com/documentati...ce.html#l00068
You are able to access mesh_ in the constant class because the constant class inherits temperaturePhaseChangeTwoPhaseMixture class (https://www.openfoam.com/documentati...1constant.html)

db is also a reference to the objectRegistry class, but is defined in IOobject.H class (https://www.openfoam.com/documentati...8H_source.html)

In other words, in both the cases you are calling the lookupObject member function of the objectRegistry class but with different instances that have been created from the derived classes. With both you are able to access all your field variables such as temperature and pressure in the mesh.

I am not an expert in C++, so feel free to correct me if I messed up somewhere.

Thanks
Thanks for the explanation. Do you think the following two definitions will get the same "p"? I am modifying a solver, but get the wrong results. I am not sure if the definition of "p" caused the problem.

const volScalarField& p = alpha1_.db().lookupObject<volScalarField>("p")
const volScalarField& p = mesh_.lookupObject<volScalarField>("p")
qingqingliu is offline   Reply With Quote

Old   March 19, 2024, 12:46
Default
  #4
Member
 
Shravan
Join Date: Mar 2017
Posts: 60
Rep Power: 9
Severus is on a distinguished road
Hello,
I think it should be the same. But we can check it out.
Code:
const volScalarField& p1 = alpha1_.db().lookupObject<volScalarField>("p")
const volScalarField& p2 = mesh_.lookupObject<volScalarField>("p")
Then you can print these fields and open it and check, or even check in Paraview.

Let us say you want to write it out every output time, then use the following,
Code:
 if(runTime.outputTime())
 {
 p1.write();
 p2.write();
 }
You can even subtract these fields to see if they are zero (or machine precision value)

Thanks
Severus is offline   Reply With Quote

Old   March 19, 2024, 12:49
Default
  #5
Member
 
Ching Liu
Join Date: Sep 2017
Posts: 46
Rep Power: 8
qingqingliu is on a distinguished road
Quote:
Originally Posted by Severus View Post
Hello,
I think it should be the same. But we can check it out.
Code:
const volScalarField& p1 = alpha1_.db().lookupObject<volScalarField>("p")
const volScalarField& p2 = mesh_.lookupObject<volScalarField>("p")
Then you can print these fields and open it and check, or even check in Paraview.

Let us say you want to write it out every output time, then use the following,
Code:
 if(runTime.outputTime())
 {
 p1.write();
 p2.write();
 }
You can even subtract these fields to see if they are zero (or machine precision value)

Thanks
Thanks for your help. I will check.
qingqingliu is offline   Reply With Quote

Old   March 20, 2024, 12:23
Default
  #6
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
The important part to note is that most volume fields will also be registered onto the corresponding volume mesh (ie, polyMesh, which is also an objectRegistry). Thus the db() referenced by the volume field will be identical to the mesh (or mesh.thisDb() to be even pickier).
The only current exception would be for volume internal fields for lagrangian sources. These are constructed on the mesh, but registered separately.
olesen is offline   Reply With Quote

Old   March 20, 2024, 12:27
Default
  #7
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
When in doubt, check things yourself. For example, print the address returned by db() and the memory location occupied by the mesh - if they have the same address, they are the same
Severus likes this.
olesen is offline   Reply With Quote

Reply

Tags
lookupobject, openfoam


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
meaning of this formula FluidKo Main CFD Forum 5 October 8, 2022 02:57
What's the meaning of 'w' in 'wmake'? random_ran OpenFOAM Programming & Development 1 February 11, 2019 16:53
Meaning of values in combustion kane OpenFOAM Running, Solving & CFD 1 May 14, 2018 05:13
Meaning of Ychar and Ypmma aylalisa OpenFOAM Pre-Processing 2 October 20, 2013 05:49
What's meaning of UDF FUNCTION zhaoxinyu Fluent UDF and Scheme Programming 0 March 31, 2010 08:04


All times are GMT -4. The time now is 05:59.