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

Getting access to mesh (fvMesh) via object registry

Register Blogs Community New Posts Updated Threads Search

Like Tree8Likes
  • 4 Post By gregor
  • 1 Post By gregor
  • 1 Post By wavemaster
  • 1 Post By marupio
  • 1 Post By AleDR

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 14, 2012, 16:31
Default Getting access to mesh (fvMesh) via object registry
  #1
Senior Member
 
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18
Chris Lucas is on a distinguished road
Hi

I want to read a dictionary within a class. I can do this e.g. with a code similar to this

IOdictionary myDict
(
IOobject
(
"myDict",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);

The problem is that I need the access to "mesh" for this. However, the class is not connected to the mesh (or any other field that has access to the mesh). Additionally, giving the class direct access to mesh would be very difficult.

Therefore the question, can I get access to the mesh via the object registry? If yes, how?

Or this there another way to load the dict without the mesh?

Thanks for the help

Christian
Chris Lucas is offline   Reply With Quote

Old   July 16, 2012, 08:25
Default
  #2
Member
 
Gregor Olenik
Join Date: Jun 2009
Location: http://greole.github.io/
Posts: 89
Rep Power: 17
gregor is on a distinguished road
Hi Christian,

Yes you can. A simple but by no means the most elegant way could look like this

Code:
const volVectorField& U = obr_.lookupObject<volVectorField>("U"); //  use object registry to acces U

fvMesh & mesh  =  U.mesh();
I am using the U reference to acces the mesh because i need U anyways. May be that helps
gregor is offline   Reply With Quote

Old   July 17, 2012, 05:50
Default
  #3
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Foam::Time is an objectRegistry, you can register the IOdictionary to it:


Code:
    IOdictionary myDict 
    (
        IOobject
        (
            "myDict", 
            runTime.constant(),
            runTime, 
            IOobject::MUST_READ, 
            IOobject::AUTO_WRITE
        )
    );
Quote:
Originally Posted by Chris Lucas View Post
Hi

I want to read a dictionary within a class. I can do this e.g. with a code similar to this

IOdictionary myDict
(
IOobject
(
"myDict",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);

The problem is that I need the access to "mesh" for this. However, the class is not connected to the mesh (or any other field that has access to the mesh). Additionally, giving the class direct access to mesh would be very difficult.

Therefore the question, can I get access to the mesh via the object registry? If yes, how?

Or this there another way to load the dict without the mesh?

Thanks for the help

Christian
tomislav_maric is offline   Reply With Quote

Old   July 18, 2012, 04:23
Default
  #4
Senior Member
 
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18
Chris Lucas is on a distinguished road
Hi,

thank you both for your help. Unfortunately, both ideas don't work in my case.

@gregor

for your idea (as I understand it), I need to provide the object registry in the constructor (as shown in the class "probes"). However, this is not possible without changing a larger part of the library.

@tomislav_maric

I know that option but I have the same problem as with the mesh, I have no direct access to runTime.

I guess the simplest way (unless someone has another idea) is to read the file using "fstream" and then get the data I need

Best Regards,
Christian
Chris Lucas is offline   Reply With Quote

Old   July 18, 2012, 08:48
Default
  #5
Member
 
Gregor Olenik
Join Date: Jun 2009
Location: http://greole.github.io/
Posts: 89
Rep Power: 17
gregor is on a distinguished road
Quote:
Originally Posted by Chris Lucas View Post
However, this is not possible without changing a larger part of the library.
Christian
Which library are you working on ? I think almost everywhere you have some acces to the object registry either through a geometricField (like U,p ...) or directly through runTime. All the constructor needs is a reference to an object registry.

Last edited by gregor; July 18, 2012 at 11:13.
gregor is offline   Reply With Quote

Old   July 19, 2012, 04:11
Default
  #6
Senior Member
 
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18
Chris Lucas is on a distinguished road
Hi,

thank you for your help.

Your right, I should have started with this .

I'm working in the thermophysical library (OpenFoam 1.6 ext.) at a class similar to the perfectGas (I need to modify my realGasMixtureEOS class)

I know that my problem is gone when I switch to OpenFOAM 2.x.x. But for now, I need to use OpenFOAM 1.6 ext.

Best Regards,
Christian
Chris Lucas is offline   Reply With Quote

Old   July 23, 2012, 07:44
Default
  #7
Member
 
Gregor Olenik
Join Date: Jun 2009
Location: http://greole.github.io/
Posts: 89
Rep Power: 17
gregor is on a distinguished road
What happens if you use
Code:
 dictionary dict(IFstream(dictName)());
and then do a dict.read(Istream &) ?
atulkjoy likes this.
gregor is offline   Reply With Quote

Old   July 24, 2012, 09:55
Default
  #8
Senior Member
 
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18
Chris Lucas is on a distinguished road
Hi,

thanks for the help. I tried to use the code, but it didn't work.

Best Regards
Christian
Chris Lucas is offline   Reply With Quote

Old   November 7, 2012, 11:04
Default Accessing mesh over Time and Objectregistry
  #9
New Member
 
Pal Schmitt
Join Date: Aug 2010
Location: Belfast
Posts: 21
Rep Power: 16
wavemaster is on a distinguished road
Dear All,
I need to access the fvMesh inside a motionFunction which is to be used in a solidBodyMotionFvMesh.
I am able to access gravity for example via
Code:
  uniformDimensionedVectorField g
     (
         IOobject
         (
             "g",
             time_.constant(),
             time_.db(),
             IOobject::MUST_READ,
             IOobject::NO_WRITE
         )
     );
but I have not managed to access a reference to the fvMesh. The recommended solution above does not seem to work,
Code:
const volVectorField& U = time_.db().lookupObject<volVectorField>("U"); //  use object registry to acces U

const fvMesh & mesh  =  U.mesh();
I get

Code:
 error: invalid use of incomplete type ‘const volVectorField {aka const struct Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>}’
/home/pal/OpenFOAM/OpenFOAM-2.1.x/src/finiteVolume/lnInclude/volFieldsFwd.H:52:7: error: declaration of ‘const volVectorField {aka const struct Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>}’
As you can see I am using OpenFOAM-2.1.x. There should definitely be an elegant way to do this, but I am stuck...
Any comments as always much appreciated,
Cheers,
Pal
wavemaster is offline   Reply With Quote

Old   November 7, 2012, 11:10
Default Header Files
  #10
New Member
 
Pal Schmitt
Join Date: Aug 2010
Location: Belfast
Posts: 21
Rep Power: 16
wavemaster is on a distinguished road
The error about incomplete Types was caused by a missing header file...
#include "volFields.H"
gaza likes this.
wavemaster is offline   Reply With Quote

Old   November 7, 2012, 11:26
Default Access to U fails
  #11
New Member
 
Pal Schmitt
Join Date: Aug 2010
Location: Belfast
Posts: 21
Rep Power: 16
wavemaster is on a distinguished road
So when I run my code it fails because it does not find U although the velocity field exists.
Quote:
const volVectorField& U = time_.lookupObject<volVectorField>("U");
At the same time using time_ (runTime) I can access g in the constant folder...
Since time_ is of Type Time and a reference from runTime I thought I could access any value in the object registry. According to http://openfoamwiki.net/index.php/Op...istry#Overview the fvmesh is below runTime in memory. In my error message
Quote:
--> FOAM FATAL ERROR:

request for fvMesh mesh from objectRegistry flapAMIfreemotion failed
available objects of type fvMesh are

1
(
region0
)
, I can see that the objectRegistry where it is searching is my library(?) but still cannot figure out why I can access g but not fields or fvMesh.
Do I need to use a function of objectRegistry to access fvMesh? parent() should give me the parent registry but does not seem to do anything...
The nicest solution would be of the kind
Quote:
const fvMesh & mesh = time_.db().parent().lookupObject<fvMesh>("mesh");
but I really cannot make it work..

Any clues on why it is more difficult to access fields?
Cheers,
Pal

Last edited by wavemaster; November 7, 2012 at 13:36. Reason: Additional information
wavemaster is offline   Reply With Quote

Old   November 8, 2012, 00:47
Default
  #12
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
"fvMesh" is the class name. The instance is "mesh". In nearly all solvers, "mesh" has the name i.e. mesh.name() "region0". Lookup "region0", not "fvMesh".
granzer likes this.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   November 8, 2012, 05:13
Default Thank You!!!!!!!!!!!
  #13
New Member
 
Pal Schmitt
Join Date: Aug 2010
Location: Belfast
Posts: 21
Rep Power: 16
wavemaster is on a distinguished road
Hi Marupio,
Thank you so much, it works fine now. I could have noticed before since Foam even tells you, but sometimes its quite hard to see the obvious.
You saved my day (and the rest of the week)...
Cheers,
Pal
wavemaster is offline   Reply With Quote

Old   May 30, 2014, 12:07
Default How to access mesh from fvSolution dictionary
  #14
Member
 
AleDR's Avatar
 
Alessandro
Join Date: May 2009
Location: Genova
Posts: 47
Rep Power: 17
AleDR is on a distinguished road
Hi everybody!

I am trying to access the mesh object from fvSolution dictionary when using codeStream.
My last attempt was:
Code:
PISO
{
    nCorrectors     2;
    nNonOrthogonalCorrectors 0;
    pRefCell        0;
    pRefValue       #codeStream  //to set level from analytical solution
{
    code
    #{
        const volScalarField& fieldRef = db().lookupObject<volScalarField>("p");
        const scalar xCoord = fieldRef.mesh()[0].x();
        const scalar yCoord = fieldRef.mesh()[0].y();

        const scalar pi_ = Foam::constant::mathematical::pi;
        scalar pRefA = -0.25 * (cos(2.0*pi_*xCoord) + cos(2.0*pi_*yCoord));
        os << pRefA;
    #};
};
But it ended with a:
Code:
error: ‘volScalarField’ does not name a type
I tried other combinations to directly access the mesh without relying on a field, but without success... Can anyone help me?
Finally I should be able to access runTime.timeValue()as well, but again it seems out of reach!

If you are curious the reason is that I would like to give a pRefValue in line with the analytic solution of Taylor vortex test case, in order to compute error norms via a coded functionObject. It worked fine for the U field, but now I would like to remove indeterminacy on the pressure field to evaluate p norms as well!

Thank you all!

.A.
BlnPhoenix likes this.
AleDR is offline   Reply With Quote

Old   June 4, 2014, 06:52
Default
  #15
Member
 
AleDR's Avatar
 
Alessandro
Join Date: May 2009
Location: Genova
Posts: 47
Rep Power: 17
AleDR is on a distinguished road
Mmmh, since as already shown in this post the pRefValue is only weakly enforced, probably a better idea is to reverse the procedure: translate the analytical solution for pressure the right amount of units (i.e. the actual value of the volScalarField p in the pRefCell).

Anyway for the problem above I suppose that the most natural way should be to access the cell centres volVectorField by mesh object available in the master objectRegistry and then to extract the x and y components corresponding to the cell with ID equal to pRefCell. But I will be extremely happy if anybody can suggest alternative procedures!
AleDR is offline   Reply With Quote

Old   July 29, 2016, 22:17
Default
  #16
New Member
 
Fidel Vallejo
Join Date: Dec 2015
Location: Santiago
Posts: 7
Rep Power: 10
fvallejog is on a distinguished road
Quote:
Originally Posted by tomislav_maric View Post
Foam::Time is an objectRegistry, you can register the IOdictionary to it:


Code:
    IOdictionary myDict 
    (
        IOobject
        (
            "myDict", 
            runTime.constant(),
            runTime, 
            IOobject::MUST_READ, 
            IOobject::AUTO_WRITE
        )
    );
Thank yo very much. I have the following problem: I wanted to put the diffusion coefficient in only region, but the solver calculated new values for this. The error was I had "mesh", and not "RunTime". You are the best, friend.
fvallejog is offline   Reply With Quote

Old   January 23, 2018, 21:05
Default
  #17
Senior Member
 
Join Date: Oct 2017
Location: United States
Posts: 233
Blog Entries: 1
Rep Power: 10
TurbJet is on a distinguished road
Quote:
Originally Posted by gregor View Post
Hi Christian,

Yes you can. A simple but by no means the most elegant way could look like this

Code:
const volVectorField& U = obr_.lookupObject<volVectorField>("U"); //  use object registry to acces U

fvMesh & mesh  =  U.mesh();
I am using the U reference to acces the mesh because i need U anyways. May be that helps
I tried this, but the compiler informed me that "obr_ is not declared in the scope".

Is there any way I can solve this?
TurbJet is offline   Reply With Quote

Old   February 4, 2022, 01:00
Default
  #18
Member
 
hari charan
Join Date: Sep 2021
Location: India,hyderabad
Posts: 97
Rep Power: 5
saicharan662000@gmail.com is on a distinguished road
Hi guys,
@tomislav_maric
I want to use cell volumes in twoPhaseMixtureThermo.C in compressibleInterfoam.
const volScalarField& cellVolume = mesh.V();


I used the above line in my code.
But I got error saying that

mesh was not declared in this scope
Can anyone help me with this?
Thanks in advance
saicharan662000@gmail.com is offline   Reply With Quote

Old   January 15, 2024, 03:57
Default
  #19
Member
 
Uttam
Join Date: May 2020
Location: Southampton, United Kingdom
Posts: 35
Rep Power: 6
openfoam_aero is on a distinguished road
I think you need to declare the mesh object. Something like
Code:
const Foam::word polyMeshPath = "target";
const Foam::IOobject meshIO("target", polyMeshPath, runTime, Foam::IOobject::MUST_READ);

// Create the fvMesh object using the updated path to the polyMesh directory
Foam::fvMesh target(meshIO);
should work. I have defined the IO dictionary that consists of the regioin, the path, runTime object and then i used it to create my mesh object. Once this is done, you can access the member functions that are part of the mesh object such as mesh.C(), mesh.V() and so on.

I forgot to mention - the above code creates the mesh object for a non default location (default is constant/polyMesh) but in this case you need to have a constant/target/polyMesh and a system/target for it to work.
__________________
Best Regards
Uttam

-----------------------------------------------------------------

“When everything seem to be going against you, remember that the airplane takes off against the wind, not with it.” – Henry Ford.
openfoam_aero 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
variables missing from object registry ganeshv OpenFOAM Running, Solving & CFD 1 February 29, 2012 08:12
using the object registry to access a particle cloud gregor OpenFOAM 1 June 8, 2011 06:58
A question on adaptive remeshing or mesh deformation for handling object motions daveatstyacht OpenFOAM 10 November 13, 2010 10:29
fluent add additional zones for the mesh file SSL FLUENT 2 January 26, 2008 12:55
Mesh Mignard FLUENT 2 March 22, 2000 06:12


All times are GMT -4. The time now is 18:04.