|
[Sponsors] |
Advice on understanding namespace and classes in MRF |
![]() |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
![]() |
![]() |
#1 |
New Member
Join Date: Jan 2024
Posts: 13
Rep Power: 3 ![]() |
Hi everyone, I've read a lot of useful information on this forum and today I wanted to learn more about c++ in OpenFoam.
I'm trying to introduce variable rotation axes into MRF. I came across a syntax that I often encounter in code but that I didn't completely understand, I report the part of the code that I'm trying to understand below: Code:
Foam::IOobject Foam::IOMRFZoneList::createIOobject ( const fvMesh& mesh, const word& solverName ) const { IOobject io ( "MRFProperties" + solverName, mesh.time().constant(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE ); if (io.typeHeaderOk<IOdictionary>(true)) { Info<< "Creating MRF zone list from " << io.name() << endl; io.readOpt(IOobject::MUST_READ_IF_MODIFIED); } else { Info<< "No MRF models present" << nl << endl; io.readOpt(IOobject::NO_READ); } return io; } Code:
IOobject Code:
FOAM Code:
Foam::IOMRFZoneList::createIOobject But in reality I don't understand this exactly, why do I create an object and then specify a method of creation for that object. Maybe I'm not understanding well what this line in C++ means and for this reason I ask you if you can describe to me what this type of writing represents. I tried to replicate this writing by creating code like this: .H Code:
#include<iostream> namespaceSchim{ classBase{ public: voidmess(){ std::cout<<" classe base"<<std::endl; } voidfunc(); int a; }; classDeri: publicBase{ public: voidmess(){ std::cout<<" classe deri"<<std::endl; } }; } namespaceSchim{ namespacederivato { classnnsd: publicBase{ public: voidfunc(int ); voidmess(){ std::cout<<" classe dentro name dentro name"<<std::endl; } }; } } Code:
#include"class.H" void Schim::derivato::nnsd::Base::func(){ std::cout<<" sono nuovo"<<std::endl; }; intmain(){ int a; a =2; Schim::Base t1; Schim::derivato::nnsd t2; //Schim::Base Schim::derivato::nnsd::func(int a); t1.mess(); t1.func(); t2.mess(); t2.func(2); return0; } Code:
Schim::Base Schim::derivato::nnsd::func(){ some stuf} |
|
![]() |
![]() |
![]() |
![]() |
#2 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 41 ![]() ![]() |
You are right, the code there is pretty weird. If you imagine the IOobject is something like the Java File class as a somewhat lightweight representation of a file + path location, plus some preferences about reading/writing etc.
It starts initially by declaring the io thing as "MUST_READ", but doesn't actually do anything. The next bit of magic occurs with the typeHeaderOk method. There it attempts to open the file location which was described by the IOobject. If it can find the file, it reads the first bit for the "FoamFile ..." header and checks that against the IOdictionary type id. If all that goes well, tag it as "MUST_READ_IF_MODIFIED" for later use. If it fails (file not found, wrong type etc), mark as NO_READ and don't use it again. For whatever reason, this helper has been declared as method. It should really be a file-static or class static method, but that is just a question of style, not functionality. |
|
![]() |
![]() |
![]() |
![]() |
#3 | |
New Member
Join Date: Jan 2024
Posts: 13
Rep Power: 3 ![]() |
Quote:
Thanks for the reply, now I understand that it uses this method to determine whether the MRF file exists or not. One thing that still eludes me is the use of the class: Code:
Foam::IOobject Code:
Foam::IOobject Foam::IOMRFZoneList::createIOobject I'll try to explain it because I might be wrong. From what I see in the .H file the Namespace Foam is expanded Code:
Foam{ class IOMRFZoneList: .[..]} Code:
IOobject createIOobject(const fvMesh& mesh) const; If what I described is correct then when I try to build this object Code:
IOobject createIOobject(const fvMesh& mesh) const; Code:
Foam::IOobject I think I've made a bit of confusion, but if this is the interpretation then I can't replicate it by writing code from scratch. Thanks for the reply. |
||
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|