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

Why isn't there a #include in the createField.H header file?

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

Like Tree2Likes
  • 1 Post By GerhardHolzinger
  • 1 Post By GerhardHolzinger

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 19, 2019, 09:13
Default Why isn't there a #include in the createField.H header file?
  #1
Senior Member
 
Mandeep Shetty
Join Date: Apr 2016
Posts: 188
Rep Power: 10
granzer is on a distinguished road
Hello, Why isnt there a #include in the createField.H header file of the icoFoam solver?

#
Info<< "Reading transportProperties\n" << endl;

IOdictionary transportProperties
(
IOobject
(
"transportProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);

dimensionedScalar nu
(
transportProperties.lookup("nu")
);
#
It's my understanding that here an object named "transportProperties" of class "IOdictionary" is created. But where is the class declaration for IOdictionary?. Shouldn't there be a header file having the declaration for the IOdictionary be included here?


informative:
1) IOobject and objectRegistry
2) https://stackoverflow.com/questions/...g-code-example
3) Explained: http://openfoamwiki.net/index.php/Ho..._with_OpenFOAM

Last edited by granzer; November 21, 2019 at 01:40.
granzer is offline   Reply With Quote

Old   November 20, 2019, 05:12
Default
  #2
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 342
Rep Power: 28
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
You shouldn't look at these files individually. The file createFields is part of the solver icoFoam. Take a look at how the C/C++ compilation process works. There is the concept of a compilation unit, and createFields is part of the compilation unit icoFoam. Thus, all the includes that define types, such as IOdictionary, have been included somewhere in icoFoam.

Below, are all the lines of icoFoam up to the point, where createFields gets included.

Code:
#include "fvCFD.H"
#include "pisoControl.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
    #include "setRootCaseLists.H"
    #include "createTime.H"
    #include "createMesh.H"

    pisoControl piso(mesh);

    #include "createFields.H"
If you want to know, where icoFoam gets its definition of the type IOdictionary, I suggest to take a look at what fvCFD.H contains.
granzer likes this.
GerhardHolzinger is offline   Reply With Quote

Old   November 20, 2019, 08:24
Default
  #3
Senior Member
 
Mandeep Shetty
Join Date: Apr 2016
Posts: 188
Rep Power: 10
granzer is on a distinguished road
Quote:
Originally Posted by GerhardHolzinger View Post
You shouldn't look at these files individually. The file createFields is part of the solver icoFoam. Take a look at how the C/C++ compilation process works. There is the concept of a compilation unit, and createFields is part of the compilation unit icoFoam. Thus, all the includes that define types, such as IOdictionary, have been included somewhere in icoFoam.

Below, are all the lines of icoFoam up to the point, where createFields gets included.

Code:
#include "fvCFD.H"
#include "pisoControl.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
    #include "setRootCaseLists.H"
    #include "createTime.H"
    #include "createMesh.H"

    pisoControl piso(mesh);

    #include "createFields.H"
If you want to know, where icoFoam gets its definition of the type IOdictionary, I suggest taking a look at what fvCFD.H contains.
Thank you very much!. I am a beginner to C++ and thought all header had all the 'other' headers that are required in it, with something like ifandef to make sure multiple copies are not included in the compilation unit. Guess IOobject is important enough that it is included in a separate 'for all case' kind of header which is included before everything else like 'fvCFD.H'.

Can you please tell me about the way in which IOdictionary class is used here? there is no object name next to the class name. Instead, am I right in thinking, the object name 'transportProperties' is given as an argument in the IOobject constructor? Why not give it something like:

IOobject transportProperties
(
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)

?
I thought it could be an anonymous class object but it does have object name 'transportProperties'.
granzer is offline   Reply With Quote

Old   November 21, 2019, 06:28
Default
  #4
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 342
Rep Power: 28
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
Quote:
Originally Posted by granzer View Post
Guess IOobject is important enough that it is included in a separate 'for all case' kind of header which is included before everything else like 'fvCFD.H'.
This is an aspect that separates a good software design from a bad one.

If you compare multiple solvers, e.g. icoFoam, simpleFoam and pimpleFoam, you will find many similarities between them. Furthermore, compare an incompressible with a compressible solver, you will commonalities and differences.

As you have said, it is best to define/implement things that are often used just once, and reuse this unique implementation.


Quote:
Originally Posted by granzer View Post
IOdictionary transportProperties
(
IOobject
(
"transportProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);

dimensionedScalar nu
(
transportProperties.lookup("nu")
);
#
It's my understanding that here an object named "transportProperties" of class "IOdictionary" is created. But where is the class declaration for IOdictionary?. Shouldn't there be a header file having the declaration for the IOdictionary be included here?
The first statement is correct, an object of the type IOdictionary is created by the name of transport properties. The declaration is in one of the headers. Here there is some digging involved.

Think of the #include statements as a formalized copy&paste, the compiler pastes the content of the header file where the include statement is found. This also works recursively, i.e. a header can include another header. gcc has an option to write the final product of the preprocesser, i.e. the result of all includes



The best way to learn about OpenFOAM is to study its code.
granzer likes this.
GerhardHolzinger is offline   Reply With Quote

Reply

Tags
icofoam

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
Using PengRobinsonGas EoS with sprayFoam Jabo OpenFOAM Running, Solving & CFD 36 July 16, 2024 04:52
Custom Thermophysical Properties wsmith02 OpenFOAM 4 June 1, 2023 15:30
[swak4Foam] swak4foam for OpenFOAM 4.0 mnikku OpenFOAM Community Contributions 80 May 17, 2022 09:06
[swak4Foam] swak4foam building problem GGerber OpenFOAM Community Contributions 54 April 24, 2015 17:02
OpenFoam install script Error during paraFoam installation SePe OpenFOAM Installation 10 June 19, 2010 16:15


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