|
[Sponsors] |
December 16, 2014, 14:21 |
OF templates < >
|
#1 |
Senior Member
Join Date: Nov 2012
Location: Bavaria
Posts: 145
Rep Power: 13 |
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 ); - 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 |
|
December 16, 2014, 15:37 |
|
#2 |
Senior Member
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25 |
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. |
|
|
|
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 05:37 |
Fluid travels: Zone 1 --> Zone 2 --> Zone 3. How can I modify diffusivity in each??? | ANT | FLUENT | 1 | August 1, 2012 08:55 |
1.7.x -> buoyantPimpleFoam -> hRhoThermo -> incompressible and icoPoly3ThermoPhysics? | will.logie | OpenFOAM Programming & Development | 1 | February 16, 2011 21:52 |
1.7.x -> buoyantPimpleFoam -> hRhoThermo -> incompressible and icoPoly3ThermoPhysics? | will.logie | OpenFOAM | 0 | December 16, 2010 08:08 |
CAD -> gMsh -> enGrid -> OpenFOAM Problem | AlGates | OpenFOAM | 7 | August 6, 2010 13:46 |