Getting access to mesh (fvMesh) via object registry
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 |
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 |
Foam::Time is an objectRegistry, you can register the IOdictionary to it:
Code:
IOdictionary myDict Quote:
|
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 |
Quote:
|
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 |
What happens if you use
Code:
dictionary dict(IFstream(dictName)()); |
Hi,
thanks for the help. I tried to use the code, but it didn't work. :mad: Best Regards Christian |
Accessing mesh over Time and Objectregistry
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 Code:
const volVectorField& U = time_.db().lookupObject<volVectorField>("U"); // use object registry to acces U Code:
error: invalid use of incomplete type ‘const volVectorField {aka const struct Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>}’ Any comments as always much appreciated, Cheers, Pal |
Header Files
The error about incomplete Types was caused by a missing header file...
#include "volFields.H" |
Access to U fails
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 |
"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".
|
Thank You!!!!!!!!!!!
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 |
How to access mesh from fvSolution dictionary
Hi everybody!
I am trying to access the mesh object from fvSolution dictionary when using codeStream. My last attempt was: Code:
PISO 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. |
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! ;) |
Quote:
|
Quote:
Is there any way I can solve this? |
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 |
I think you need to declare the mesh object. Something like
Code:
const Foam::word polyMeshPath = "target"; 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. |
All times are GMT -4. The time now is 20:49. |