|
[Sponsors] |
January 9, 2012, 03:29 |
Initializing a template variable
|
#1 |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29 |
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];
__________________
*On twitter @akidTwit *Spend as much time formulating your questions as you expect people to spend on their answer. |
|
January 9, 2012, 14:35 |
|
#2 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
|
||
January 10, 2012, 02:38 |
|
#3 |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29 |
Thanks a lot! If anyone wants to use the code as well, I pushed it to http://code.google.com/p/foamcalcex/
__________________
*On twitter @akidTwit *Spend as much time formulating your questions as you expect people to spend on their answer. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
emag beta feature: charge density | charlotte | CFX | 4 | March 22, 2011 09:14 |
Initializing reference variable of type objectRegistry | deji | OpenFOAM | 8 | August 6, 2010 13:50 |
error in COMSOL:'ERROR:6164 Duplicate Variable' | bhushas | COMSOL | 1 | May 30, 2008 04:35 |
Env variable not set | gruber2 | OpenFOAM Installation | 5 | December 30, 2005 04:27 |
Replace periodic by inlet-outlet pair | lego | CFX | 3 | November 5, 2002 20:09 |