|
[Sponsors] |
December 4, 2013, 07:42 |
method surfaceSum(...) of class fvc
|
#1 |
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 |
hi,
I' m having problems with understanding the method surfaceSum(...) below: Code:
template<class Type> 192 tmp<GeometricField<Type, fvPatchField, volMesh> > surfaceSum 193 ( 194 const tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >& tssf 195 ) 196 { 197 tmp<GeometricField<Type, fvPatchField, volMesh> > tvf = surfaceSum(tssf()); //QUESTION 198 tssf.clear(); 199 return tvf; 200 } Code:
template<class T> 213*inline const T& Foam::tmp<T>::operator()() const 214*{ 215* if (isTmp_) // bool isTmp_; //- Flag for whether object is a temporary or a constant object 216* { 217* if (!ptr_) //mutable T* ptr_; //- Pointer to temporary object 218* { 219* FatalErrorIn("const T& Foam::tmp<T>::operator()() const") 220* << "temporary deallocated" 221* << abort(FatalError); 222* } 223* 224* return *ptr_; 225* } 226* else 227* { 228* return ref_; //const T& ref_ //- Const reference to constant object 229* } 230*} In method surfaceSum(...) the input parameter tssf is passed to "another" surfaceSum(...) method. Wouldn t that cause some kind of endless loop, because in the new called method surfaceSum(...) the method gets called again and so on? |
|
December 4, 2013, 08:22 |
|
#2 |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29 |
The ()-operator strips the object from it's tmp-"shell", so the following call to surfaceSum leads to a different method, namely one that is called when a GeometricField is passed: http://foam.sourceforge.net/docs/cpp...ce.html#l00138
__________________
*On twitter @akidTwit *Spend as much time formulating your questions as you expect people to spend on their answer. |
|
December 4, 2013, 08:50 |
|
#3 | |
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 |
hi again,
Quote:
All I can see in the method operator () is that in line 215 it is proved if the object is tmp (temporary) and in line 217 if the pointer ptr_ is not NULL. If both these conditions are fullfilled the pointer ptr_ is dereferenced and returned in line 224. Last edited by maybee; December 4, 2013 at 12:04. |
||
December 5, 2013, 03:35 |
|
#4 |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29 |
Code:
224* return *ptr_; It dereferences the pointer stored in the tmp<> object, and returns the dereferenced pointer. * What happens if you dereference a pointer pointing to an object? You get access to that object. Note that in our case, the object in question is a vol*Field. Does that make things clear? Recommended reading: http://openfoamwiki.net/index.php/OpenFOAM_guide/tmp
__________________
*On twitter @akidTwit *Spend as much time formulating your questions as you expect people to spend on their answer. |
|
December 5, 2013, 04:12 |
|
#5 | |
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 |
Quote:
2. Furthermore, how do you know it is a vol*Field? I have the following source code: Code:
scalarField sumPhi ( fvc::surfaceSum(mag(phi))().internalField() ); Code:
const surfaceScalarField& phi Code:
→ template<class Type, template<class> class PatchField, class GeoMesh> 323*tmp<GeometricField<scalar, PatchField, GeoMesh> > mag 324*( 325* const GeometricField<Type, PatchField, GeoMesh>& gf 326*) 327*{ 328* tmp<GeometricField<scalar, PatchField, GeoMesh> > tMag 329* ( 330* new GeometricField<scalar, PatchField, GeoMesh> 331* ( 332* IOobject 333* ( 334* "mag(" + gf.name() + ')', 335* gf.instance(), 336* gf.db(), 337* IOobject::NO_READ, 338* IOobject::NO_WRITE 339* ), 340* gf.mesh(), 341* gf.dimensions() 342* ) 343* ); 344* 345* mag(tMag(), gf); 346* 347* return tMag; 348*} |
||
December 5, 2013, 04:21 |
|
#6 | |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29 |
Quote:
tmp<GeometricField<scalar, PatchField, GeoMesh> > tMag stores a pointer to a GeometricField<scalar, PatchField, GeoMesh>, which is the same thing as a volScalarField. So when you call tMag() you will end up with the underlying volScalarField. - Anton
__________________
*On twitter @akidTwit *Spend as much time formulating your questions as you expect people to spend on their answer. |
||
December 5, 2013, 04:36 |
|
#7 |
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 |
, now I got it. Just one more question:
How did you know that ptr_ points to the geometricfield and not to the tmp<"geometricfield">? |
|
December 5, 2013, 05:34 |
|
#8 |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29 |
On line 330 of the code you posted a new object of GeometricField<> is allocated and it's pointer is passed on to the constructor of tmp<>: http://foam.sourceforge.net/docs/cpp...bf3c32f4c76004
__________________
*On twitter @akidTwit *Spend as much time formulating your questions as you expect people to spend on their answer. |
|
December 5, 2013, 05:42 |
|
#9 |
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 |
Ok, thx alot. Question solved.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
On the alpha Eqn of VOF method when using Immersed boundary method in OpenFOAM | keepfit | OpenFOAM | 4 | January 31, 2014 14:32 |
init() method of class UpStream | maybee | OpenFOAM Programming & Development | 0 | November 26, 2013 16:19 |
Help about the preconditioner in gmres method | Dan Gao | Main CFD Forum | 3 | July 5, 2008 01:18 |
About flowfield-dependent variation(FDV) method? | Jinwon | Main CFD Forum | 1 | December 4, 2007 21:13 |
tidal flow simulation using finite volume method | Jason Qiu | Main CFD Forum | 0 | October 20, 2002 02:34 |