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

OF templates < >

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

Like Tree3Likes
  • 3 Post By deepsterblue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 16, 2014, 13:21
Default OF templates < >
  #1
Senior Member
 
Join Date: Nov 2012
Location: Bavaria
Posts: 145
Rep Power: 13
aylalisa is on a distinguished road
Dear Foamers,

I try to decipher following code snippet, representative for advanced usage of templating in OF (e.g. fvcGrad.H):

Code:
template<class Type>    
    64     tmp
    65     <
    66         GeometricField
    67         <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
    68     > grad
    69     (
    70         const tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >&
    71     );
Is that a template for a class or a function? I miss the class keyword before classname and see a return type of grad(), therefore I think it's a function template whose return type is wrapped tmp<> due to its size and is of class type GeometricField which again is a templated type, but a class which can be of type:
- outerProduct<vector, Type>::type
- fvPatchField
- volMesh
Whereas I have no glue if that is correct or completely wrong.
I can't understand outerProduct<vector, Type>::type, especially the double colon irritates me.

Could somebody help?

Ayla
aylalisa is offline   Reply With Quote

Old   December 16, 2014, 14:37
Default
  #2
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25
deepsterblue will become famous soon enough
Yes, it's a templated function which computes the gradient of a geometric field. The template parameter Type typically refers to a scalar or vector. Now, when you take the gradient of a scalar field, you get a vector field. And when you take the gradient of a vector field, you get a tensor field.
Notice a pattern? This effectively increased the rank of the field by one. That's what the outerProduct operator does - the outer product of a vector (due to the gradient operator) and Type will yield a new type whose rank is increased by one. Since we need to refer to it somehow, we get it using the outerProduct<vector, Type>::type member. When you write it out (the compiler does this automagically for you), it's defined this way:

outerProduct<vector, scalar>::type = vector;

and

outerProduct<vector, vector>::type = tensor;

At the end of it all, the grad function returns a reference-counted geometric field using the tmp<> class, with a higher rank.
aylalisa, meshman and randolph like this.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue 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
[Commercial meshers] ccm26ToFoam --> checkMesh --> too many errors kornickel OpenFOAM Meshing & Mesh Conversion 0 August 16, 2013 04:37
Fluid travels: Zone 1 --> Zone 2 --> Zone 3. How can I modify diffusivity in each??? ANT FLUENT 1 August 1, 2012 07:55
1.7.x -> buoyantPimpleFoam -> hRhoThermo -> incompressible and icoPoly3ThermoPhysics? will.logie OpenFOAM Programming & Development 1 February 16, 2011 20:52
1.7.x -> buoyantPimpleFoam -> hRhoThermo -> incompressible and icoPoly3ThermoPhysics? will.logie OpenFOAM 0 December 16, 2010 07:08
CAD -> gMsh -> enGrid -> OpenFOAM Problem AlGates OpenFOAM 7 August 6, 2010 12:46


All times are GMT -4. The time now is 05:58.