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

GeometricField -> mesh() Function

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

Like Tree7Likes
  • 2 Post By Zeppo
  • 1 Post By Michael@UW
  • 2 Post By Zeppo
  • 1 Post By olesen
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 31, 2019, 08:25
Default GeometricField -> mesh() Function
  #1
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Augsburg
Posts: 2,616
Blog Entries: 6
Rep Power: 48
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi all,

I am just wondering, if I am getting things correct (but my analysis will show that I am not correct). Assuming that we do have an object based on a volScalarField which is actually a GeometricField. For this field, we can apply the function named mesh(). This function is not implemented in the GeometricField class but as this class includes the DimensionedField class, we can see that it is implemented there. As I cannot find any other function named »mesh()«, I expect that this is correct. The mesh function returns a reference to an object based on the class Mesh:
Code:
const Mesh&  mesh() const;
The class Mesh is actually
Code:
GeoMesh::Mesh Mesh;
So while we call the mesh function, e.g.,
Code:
volScalarField T = ...;


const Mesh& foobar = T.mesh();
we get an object of type Mesh (GeoMesh::Mesh). I guess there is already a mistake in my analysis as I have no idea how we can do the follow:


Code:
.... = T.mesh().ddtScheme("foobar");
The ddtScheme function here is based on the class fvSchemes, which is not inherited by GeoMesh. Actually the code:
Code:
T.mesh()
has to return somehow the reference to the fvMesh class because this class inherites the functions from the fvSchemes class. Furthermore, one can program the following:


Code:
const fvMesh& test = T.mesh();
However, I do not get the connection between the function mesh() that returns the fvMesh object. I am working with FOAM for 9 years now and I do not get the simplest things. Yesterday I saw a report on the TV that the youngest German hacker is 18 years old and has a security company in Hamburg with 23 employees. And I am not even able to connect the mesh() function call to the fvMesh class.


The only thing that I could image is the following:
  • the GeoMesh class is a template based on the class MESH
  • the GeoMesh is constructed somewhen using the fvMesh class
  • If so, the returned object of the DimensionedField mesh() function, which is of class Mesh (typedef GeoMesh::Mesh) would return an fvMesh object because the Mesh is:
Code:
typedef MESH Mesh
  • and while the returned object of the function mesh() of the DimensionedField class is of type Mesh, while MESH is the class template parameter of the GeoMesh class, the type Mesh could be a fvMesh (related to the construction of the GeoMesh object.


I hope that the last statement was clear


Any hint is welcomed.
Thanks in advance.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   January 2, 2020, 17:11
Default
  #2
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 259
Rep Power: 19
Zeppo will become famous soon enough
Your analysis is quite correct. Here some code snippets to support your considerations:
Code:
//--- GeometricField.H ---
 template<class Type, template<class> class PatchField, class GeoMesh>
 class GeometricField
 :
     public DimensionedField<Type, GeoMesh>
 {

Code:
//--- DimensionedField.H ---
 template<class Type, class GeoMesh>
 class DimensionedField
 :
     public regIOobject,
     public Field<Type>
 {
 
 public:
 
     // Public Typedefs
 
         //- Type of mesh on which this DimensionedField is instantiated
         typedef typename GeoMesh::Mesh Mesh;
...
         //- Return mesh
         inline const Mesh& mesh() const;

Code:
//--- volFieldsFwd.H ---
 typedef GeometricField<scalar, fvPatchField, volMesh> volScalarField;

Code:
//--- volMesh.H ---
 class volMesh
 :
     public GeoMesh<fvMesh>
 {

Code:
//--- GeoMesh.H ---
 template<class MESH>
 class GeoMesh
 {
 
...

 public:
 
     // Public Typedefs
 
         typedef MESH Mesh;
Tobi and Daniel_Khazaei like this.
Zeppo is offline   Reply With Quote

Old   January 3, 2020, 18:03
Default
  #3
Senior Member
 
Join Date: Jan 2019
Posts: 101
Blog Entries: 1
Rep Power: 5
Michael@UW is on a distinguished road
volVectorField T
(
IOobject
(
"T",
runTime.timeName(),
mesh, // 1
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh // 2
);

mesh 1 is a registered object only for IOobject and DimensionedField, I guess it is transformed to GeoMesh even it is fvMesh.

mesh 2 is the mesh where the filed lives, so it is volMesh for a volVectorField, which is actually fvMesh.

T.mesh is not accessible and you need only use the global variable 'mesh' itself, as all the volVectorFields use the same 'mesh', otherwise you may have U.mesh(), p.mesh() and so on (stagger mesh technique uses different meshes for different fields, but OpenFOAM use collocated mesh).

Above is just my analysis, please correct me if I am wrong.

Actually, I am always wondering why volVectorField constructed from IOobject uses the second mesh argument. Your analysis inspired me and partially solves the puzzle. The first mesh could be runTime which is also an registryObject. For simplicity, even if the IOobject is registered to a fvMesh, we still pass the second mesh to construct a volVectorField. What do you think about the construction mechanism?
granzer likes this.
Michael@UW is offline   Reply With Quote

Old   January 3, 2020, 20:10
Default
  #4
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Augsburg
Posts: 2,616
Blog Entries: 6
Rep Power: 48
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
The object mesh in your post is based on the fvMesh class. Both, your first end second mesh are identical, it is the same object but you know that. The only nice magic that happens here is the fact that the programming language is smart enough to return the object needed at the corresponding line but only due to the fact that the constructors are having the fvMesh class as argument or the code is smart enough to return the correct object.

The second mesh is of type Mesh which is actually GeoMesh::Mesh Mesh and the template type MESH is set to fvMesh. So here things are clear. The first mesh will return the registry object.

Actually I don't know your Intension for your post as it is not related to mine and Zeppo already showed that my analysis was correct. Using this information you can resolve your topic.
By the way. T.mesh is not even a function. So what should this peace of code do? I guess if you want direct access you have do do it with the scope operator.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   March 22, 2020, 04:56
Default
  #5
Senior Member
 
Mandeep Shetty
Join Date: Apr 2016
Posts: 168
Rep Power: 7
granzer is on a distinguished road
Quote:
Originally Posted by Tobi View Post
The object mesh in your post is based on the fvMesh class. Both, your first end second mesh are identical, it is the same object but you know that. The only nice magic that happens here is the fact that the programming language is smart enough to return the object needed at the corresponding line but only due to the fact that the constructors are having the fvMesh class as argument or the code is smart enough to return the correct object.

The second mesh is of type Mesh which is actually GeoMesh::Mesh Mesh and the template type MESH is set to fvMesh. So here things are clear. The first mesh will return the registry object.

Actually I don't know your Intension for your post as it is not related to mine and Zeppo already showed that my analysis was correct. Using this information you can resolve your topic.
By the way. T.mesh is not even a function. So what should this peace of code do? I guess if you want direct access you have do do it with the scope operator.
Can you please tell me how the first 'mesh' object is an object of type objectRegistry? I have seen that in place of the first 'mesh' we can also have 'runTime' object, which is an object of class Time. So if runTime is a object of class Time how can it be an object of class objectRegistry too?
granzer is offline   Reply With Quote

Old   April 1, 2020, 13:01
Default
  #6
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 259
Rep Power: 19
Zeppo will become famous soon enough
Quote:
Originally Posted by granzer View Post
Can you please tell me how the first 'mesh' object is an object of type objectRegistry? I have seen that in place of the first 'mesh' we can also have 'runTime' object, which is an object of class Time. So if runTime is a object of class Time how can it be an object of class objectRegistry too?
Both Time and fvMesh classes are derived from objectRegistry class.
Daniel_Khazaei and granzer like this.
Zeppo is offline   Reply With Quote

Old   April 2, 2020, 11:16
Default
  #7
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,371
Rep Power: 33
olesen will become famous soon enougholesen will become famous soon enough
Quote:
Originally Posted by Zeppo View Post
Both Time and fvMesh classes are derived from objectRegistry class.

It does get a bit confusing sometimes, but you can think of an objectRegistry as being a database for holding objects (objects of type regIOobject to be specific). Since the objectRegistry itself is derived from a regIOobject, an objectRegistry can thus contain other object registries, and can potentially have a parent registry as well. Time is a special case of an objectRegistry that is also used to define the time coordination for multiple registries.


At this stage it probably helps to think in terms of a file-system. The objectRegistry is analogous to a directory, the regIOobject is analogous to a file/directory.
granzer likes this.
olesen is offline   Reply With Quote

Old   April 7, 2020, 09:04
Default
  #8
Senior Member
 
Mandeep Shetty
Join Date: Apr 2016
Posts: 168
Rep Power: 7
granzer is on a distinguished road
Quote:
Originally Posted by olesen View Post
It does get a bit confusing sometimes, but you can think of an objectRegistry as being a database for holding objects (objects of type regIOobject to be specific). Since the objectRegistry itself is derived from a regIOobject, an objectRegistry can thus contain other object registries, and can potentially have a parent registry as well. Time is a special case of an objectRegistry that is also used to define the time coordination for multiple registries.


At this stage it probably helps to think in terms of a file-system. The objectRegistry is analogous to a directory, the regIOobject is analogous to a file/directory.
Yes exactly! I have come to visualize it as the Linux file system with runTime taking the place of 'root' directory and all other objectRegistry type objects coming under runTime object.
Am I right in understanding that a class like 'volScalarField' is also derived from 'regIOobject' and an object of volScalarField, say T, can be called a volScalarObject or a regIOobject?
granzer is offline   Reply With Quote

Old   April 7, 2020, 15:09
Default
  #9
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,371
Rep Power: 33
olesen will become famous soon enougholesen will become famous soon enough
Yup, your "T" is a volScalarField, which derives from a regIOobject. Continuing with the filesystem analogy, the volScalarField is like a file (not a directory). Your choice if you want to deal with it along with other "files" (eg a volVectorField) or want to dispatch something particular to its type. In the latter case, you can dynamic cast it from the regIOobject to the volScalarField.
granzer likes this.
olesen is offline   Reply With Quote

Old   November 11, 2020, 12:31
Default
  #10
New Member
 
Elol
Join Date: Feb 2020
Posts: 15
Rep Power: 3
Elol is on a distinguished road
Hi Foamers,

I just have a simple question, I don't know if it is related to this thread or not. Anyway, If I want to calculate something like that

K= delta x^2 / deltat

which x is the local cell distance (x,y,z) and deltat is the runTime.deltaT(). what function or how exactly represent delta x^2 in terms of programming ?

Thanks in advance.
Elol is offline   Reply With Quote

Old   November 19, 2020, 12:33
Default
  #11
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 390
Rep Power: 9
Tobermory will become famous soon enough
Umm ... this topic seems to be completely unrelated to the previous one, so I hesitate to respond at all. Please start a new thread when you have a new, unrelated question ... you are also more likely to get a reply!

As for your question, take a look at a utility like postChannel. You can get the cell centre coords from

Code:
const vectorField& centres = mesh.C();
and that will be a start. Good luck.
Tobermory is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[snappyHexMesh] SnappyHexMesh/splitMeshRegion : region1 in zone "-1" GuiMagyar OpenFOAM Meshing & Mesh Conversion 1 September 10, 2019 10:59
is internalField(U) equivalent to zeroGradient? immortality OpenFOAM Running, Solving & CFD 7 March 29, 2013 02:27
[Gmsh] 2D Mesh Generation Tutorial for GMSH aeroslacker OpenFOAM Meshing & Mesh Conversion 12 January 19, 2012 04:52
Icemcfd 11: Loss of mesh from surface mesh option? Joe CFX 2 March 26, 2007 19:10
Droplet Evaporation Christian Main CFD Forum 2 February 27, 2007 07:27


All times are GMT -4. The time now is 14:27.