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

Getting access to mesh (fvMesh) via object registry

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

Reply
 
LinkBack Thread Tools Display Modes
Old   July 14, 2012, 15:31
Default Getting access to mesh (fvMesh) via object registry
  #1
Senior Member
 
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 198
Rep Power: 7
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, 07:25
Default
  #2
Member
 
Gregor Olenik
Join Date: Jun 2009
Location: http://greole.github.io/
Posts: 78
Rep Power: 8
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, 04:50
Default
  #3
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 259
Blog Entries: 5
Rep Power: 11
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, 03:23
Default
  #4
Senior Member
 
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 198
Rep Power: 7
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, 07:48
Default
  #5
Member
 
Gregor Olenik
Join Date: Jun 2009
Location: http://greole.github.io/
Posts: 78
Rep Power: 8
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 10:13.
gregor is offline   Reply With Quote

Old   July 19, 2012, 03:11
Default
  #6
Senior Member
 
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 198
Rep Power: 7
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, 06:44
Default
  #7
Member
 
Gregor Olenik
Join Date: Jun 2009
Location: http://greole.github.io/
Posts: 78
Rep Power: 8
gregor is on a distinguished road
What happens if you use
Code:
 dictionary dict(IFstream(dictName)());
and then do a dict.read(Istream &) ?
gregor is offline   Reply With Quote

Old   July 24, 2012, 08:55
Default
  #8
Senior Member
 
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 198
Rep Power: 7
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: 19
Rep Power: 7
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: 19
Rep Power: 7
wavemaster is on a distinguished road
The error about incomplete Types was caused by a missing header file...
#include "volFields.H"
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: 19
Rep Power: 7
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: 397
Rep Power: 12
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".
__________________
~~~
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: 19
Rep Power: 7
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, 11:07
Default How to access mesh from fvSolution dictionary
  #14
Member
 
AleDR's Avatar
 
Alessandro
Join Date: May 2009
Location: Genova
Posts: 43
Rep Power: 8
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.
AleDR is offline   Reply With Quote

Old   June 4, 2014, 05:52
Default
  #15
Member
 
AleDR's Avatar
 
Alessandro
Join Date: May 2009
Location: Genova
Posts: 43
Rep Power: 8
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

Reply

Thread Tools
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 On
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 05: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 09:08.