|
[Sponsors] |
Getting access to mesh (fvMesh) via object registry |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
July 14, 2012, 16:31 |
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 |
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 |
|
July 16, 2012, 08:25 |
|
#2 |
Member
Gregor Olenik
Join Date: Jun 2009
Location: http://greole.github.io/
Posts: 89
Rep Power: 17 |
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(); |
|
July 17, 2012, 05:50 |
|
#3 | |
Senior Member
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21 |
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:
|
||
July 18, 2012, 04:23 |
|
#4 |
Senior Member
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18 |
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 |
|
July 18, 2012, 08:48 |
|
#5 |
Member
Gregor Olenik
Join Date: Jun 2009
Location: http://greole.github.io/
Posts: 89
Rep Power: 17 |
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. |
|
July 19, 2012, 04:11 |
|
#6 |
Senior Member
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18 |
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 |
|
July 23, 2012, 07:44 |
|
#7 |
Member
Gregor Olenik
Join Date: Jun 2009
Location: http://greole.github.io/
Posts: 89
Rep Power: 17 |
What happens if you use
Code:
dictionary dict(IFstream(dictName)()); |
|
July 24, 2012, 09:55 |
|
#8 |
Senior Member
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18 |
Hi,
thanks for the help. I tried to use the code, but it didn't work. Best Regards Christian |
|
November 7, 2012, 11:04 |
Accessing mesh over Time and Objectregistry
|
#9 |
New Member
Pal Schmitt
Join Date: Aug 2010
Location: Belfast
Posts: 21
Rep Power: 16 |
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 ) ); Code:
const volVectorField& U = time_.db().lookupObject<volVectorField>("U"); // use object registry to acces U const fvMesh & mesh = U.mesh(); 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>}’ Any comments as always much appreciated, Cheers, Pal |
|
November 7, 2012, 11:10 |
Header Files
|
#10 |
New Member
Pal Schmitt
Join Date: Aug 2010
Location: Belfast
Posts: 21
Rep Power: 16 |
The error about incomplete Types was caused by a missing header file...
#include "volFields.H" |
|
November 7, 2012, 11:26 |
Access to U fails
|
#11 | |||
New Member
Pal Schmitt
Join Date: Aug 2010
Location: Belfast
Posts: 21
Rep Power: 16 |
So when I run my code it fails because it does not find U although the velocity field exists.
Quote:
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:
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:
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 |
||||
November 8, 2012, 00:47 |
|
#12 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
"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 |
|
November 8, 2012, 05:13 |
Thank You!!!!!!!!!!!
|
#13 |
New Member
Pal Schmitt
Join Date: Aug 2010
Location: Belfast
Posts: 21
Rep Power: 16 |
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 |
|
May 30, 2014, 12:07 |
How to access mesh from fvSolution dictionary
|
#14 |
Member
Alessandro
Join Date: May 2009
Location: Genova
Posts: 47
Rep Power: 17 |
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; #}; }; Code:
error: ‘volScalarField’ does not name a type 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. |
|
June 4, 2014, 06:52 |
|
#15 |
Member
Alessandro
Join Date: May 2009
Location: Genova
Posts: 47
Rep Power: 17 |
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! |
|
July 29, 2016, 22:17 |
|
#16 |
New Member
Fidel Vallejo
Join Date: Dec 2015
Location: Santiago
Posts: 7
Rep Power: 10 |
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.
|
|
January 23, 2018, 21:05 |
|
#17 | |
Senior Member
|
Quote:
Is there any way I can solve this? |
||
February 4, 2022, 01:00 |
|
#18 |
Member
hari charan
Join Date: Sep 2021
Location: India,hyderabad
Posts: 97
Rep Power: 5 |
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 |
|
January 15, 2024, 03:57 |
|
#19 |
Member
Uttam
Join Date: May 2020
Location: Southampton, United Kingdom
Posts: 35
Rep Power: 6 |
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); 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. |
|
|
|
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 |