- **OpenFOAM Programming & Development**
(*https://www.cfd-online.com/Forums/openfoam-programming-development/*)

- - **OF templates < >**
(*https://www.cfd-online.com/Forums/openfoam-programming-development/146008-templates.html*)

OF templates < >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> ` - 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 |

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. |

All times are GMT -4. The time now is 01:32. |