akidess |
January 9, 2012 03:29 |
Initializing a template variable
I'm extending the foamCalc tool to calculate a volume integral of a given field. The code in the foamCalcFunctions library is templated to deal with the various field types (scalar, vector, ...). My problem is that when I define a templated variable to store the result of the computations, I'm not sure how I can initialize the variable nicely to be zero (again scalar(0), vector(0,0,0), ...). My current solution is just to misuse a value from the field and subtract it again, but of course that's not very elegant. Can anyone help me with a nicer solution?
Code:
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
if (header.headerClassName() == fieldType::typeName)
{
Info<< " Reading " << header.name() << endl;
fieldType field(header, mesh);
//Initialization
dimensioned<Type> volInt ("volInt", field[0]);
volInt -= field[0];
|