|
[Sponsors] |
March 19, 2024, 10:29 |
lookupObject meaning
|
#1 |
Member
Ching Liu
Join Date: Sep 2017
Posts: 52
Rep Power: 9 |
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? |
|
March 19, 2024, 13:16 |
|
#2 |
Member
Shravan
Join Date: Mar 2017
Posts: 75
Rep Power: 9 |
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 |
|
March 19, 2024, 13:38 |
|
#3 | |
Member
Ching Liu
Join Date: Sep 2017
Posts: 52
Rep Power: 9 |
Quote:
const volScalarField& p = alpha1_.db().lookupObject<volScalarField>("p") const volScalarField& p = mesh_.lookupObject<volScalarField>("p") |
||
March 19, 2024, 13:46 |
|
#4 |
Member
Shravan
Join Date: Mar 2017
Posts: 75
Rep Power: 9 |
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") Let us say you want to write it out every output time, then use the following, Code:
if(runTime.outputTime()) { p1.write(); p2.write(); } Thanks |
|
March 19, 2024, 13:49 |
|
#5 | |
Member
Ching Liu
Join Date: Sep 2017
Posts: 52
Rep Power: 9 |
Quote:
|
||
March 20, 2024, 13:23 |
|
#6 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
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. |
|
March 20, 2024, 13:27 |
|
#7 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
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
|
|
Tags |
lookupobject, openfoam |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
meaning of this formula | FluidKo | Main CFD Forum | 5 | October 8, 2022 03:57 |
What's the meaning of 'w' in 'wmake'? | random_ran | OpenFOAM Programming & Development | 1 | February 11, 2019 17:53 |
Meaning of values in combustion | kane | OpenFOAM Running, Solving & CFD | 1 | May 14, 2018 06:13 |
Meaning of Ychar and Ypmma | aylalisa | OpenFOAM Pre-Processing | 2 | October 20, 2013 06:49 |
What's meaning of UDF FUNCTION | zhaoxinyu | Fluent UDF and Scheme Programming | 0 | March 31, 2010 09:04 |