CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Running, Solving & CFD

PtrList problems

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree4Likes
  • 1 Post By hjasak
  • 1 Post By olesen
  • 2 Post By olesen

Reply
 
LinkBack Thread Tools Display Modes
Old   February 8, 2011, 09:24
Default PtrList problems
  #1
New Member
 
Paweł Kuczyński
Join Date: Feb 2011
Location: Warsaw, Poland
Posts: 19
Rep Power: 6
kuczmas is on a distinguished road
Dear forumers,

Firstly I will shortly describe my problem. I would like to set up an Array of Arrays (2d array), which is of size: N_boundFaces x N_boundFaces. Such an array will correspond to the coefficients of heat exchange between a given boundary-cell-face and the rest of boundary-cell-faces. Having read some hints in this forum, I came up with an idea of constructing a PtrList. But at the beginning I have problems with setting up a single 1d-PtrList:

The code is following...:
(...)
const int N_boundFaces = mesh.boundaryMesh().size() * mesh.boundaryMesh()[0].size(); //N_boundFaces = N_patches * N_faces_in_patch
PtrList< int > D(N_boundFaces);
Info << "size of PtrList D = " << D.size() << endl ;

for( int i = 0; i != N_boundFaces ; i++ )
{
D.set(i, 2); // set all the values in the PtrList to 2
}
(...)


and the compiling errors are:
(...)
In file included from /opt/openfoam171/src/OpenFOAM/lnInclude/tmp.H:142,
from /opt/openfoam171/src/OpenFOAM/lnInclude/PtrListI.H:29,
from /opt/openfoam171/src/OpenFOAM/lnInclude/PtrList.H:311,
from /opt/openfoam171/src/OpenFOAM/lnInclude/List.C:30,
from /opt/openfoam171/src/OpenFOAM/lnInclude/List.H:262,
from /opt/openfoam171/src/OpenFOAM/lnInclude/labelList.H:36,
from /opt/openfoam171/src/OpenFOAM/lnInclude/Pstream.H:43,
from /opt/openfoam171/src/OpenFOAM/lnInclude/OPstream.H:35,
from /opt/openfoam171/src/OpenFOAM/lnInclude/parRun.H:35,
from /opt/openfoam171/src/finiteVolume/lnInclude/fvCFD.H:4,
from laplacianFoamModifiedRandomNumberV03.C:32:
/opt/openfoam171/src/OpenFOAM/lnInclude/tmpI.H: In destructor ‘Foam::tmp<T>::~tmp() [with T = int]’:
rayTracing.H:43: instantiated from here
/opt/openfoam171/src/OpenFOAM/lnInclude/tmpI.H:76: error: request for member ‘okToDelete’ in ‘*((Foam::tmp<int>*)this)->Foam::tmp<int>:tr_’, which is of non-class type ‘int’
/opt/openfoam171/src/OpenFOAM/lnInclude/tmpI.H:83: error: request for member ‘operator--’ in ‘*((Foam::tmp<int>*)this)->Foam::tmp<int>:tr_’, which is of non-class type ‘int’
/opt/openfoam171/src/OpenFOAM/lnInclude/tmpI.H: In member function ‘T* Foam::tmp<T>:tr() const [with T = int]’:
/opt/openfoam171/src/OpenFOAM/lnInclude/PtrListI.H:90: instantiated from ‘Foam::autoPtr<T> Foam::PtrList<T>::set(Foam::label, const Foam::tmp<T>&) [with T = int]’
rayTracing.H:43: instantiated from here
/opt/openfoam171/src/OpenFOAM/lnInclude/tmpI.H:127: error: request for member ‘resetRefCount’ in ‘* ptr’, which is of non-class type ‘int’
make: *** [Make/linuxGccDPOpt/laplacianFoamModifiedRandomNumberV03.o] Błąd 1


So my questions are the following:
1. what is the best way to loop over the elements in PtrList?
a) use simple for loop with int counter: for( int i = 0; != N_boundFaces; i++ )
b) use iterator: for ( PtrList<int>::iterator i = D.begin(); i != D.end(); ++i)
c) use: forAll( D, i )
2. how successfuly replace a given entity in the PtrList? use D.set(i, 200)??
3. how print out the value of a given entity, e.g. D[i]? Info << D[i] ;??

I know that some answers to my questions were previously mentioned, but I couldn't manage to solve my problem. Every help would be greatly appreciated.

Thanks!
__________________
Best regards
P. Kuczynski.
kuczmas is offline   Reply With Quote

Old   February 10, 2011, 04:14
Default
  #2
New Member
 
Paweł Kuczyński
Join Date: Feb 2011
Location: Warsaw, Poland
Posts: 19
Rep Power: 6
kuczmas is on a distinguished road
I'm still tackling the problem, but hopefully I see an end. I will try to post some conclusions from my little experience :-).

Still I really appreciate any help.
__________________
Best regards
P. Kuczynski.
kuczmas is offline   Reply With Quote

Old   February 11, 2011, 05:56
Default
  #3
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,758
Rep Power: 21
hjasak will become famous soon enough
PtrList is a container for pointers to objects and there is a bunch of templates in it. Why don't you just use a labelList?

If you want an example of PtrList, try a PtrList<fvPatch> or similar.

Hrv
luiscardona likes this.
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   February 16, 2011, 07:41
Default
  #4
New Member
 
Paweł Kuczyński
Join Date: Feb 2011
Location: Warsaw, Poland
Posts: 19
Rep Power: 6
kuczmas is on a distinguished road
Hello Hrvoje,

Thanks for your suggestions! I have to lean more about them. I'm fresh user of OpenFoam, so for now I managed to solve the problem just by creating a new scalar array. I decided not to use ptrList because the size of the array is constant during the program execution. Once again thanks.
__________________
Best regards
P. Kuczynski.
kuczmas is offline   Reply With Quote

Old   May 18, 2011, 09:44
Default solution to the problems
  #5
New Member
 
Paweł Kuczyński
Join Date: Feb 2011
Location: Warsaw, Poland
Posts: 19
Rep Power: 6
kuczmas is on a distinguished road
Dear forumers,

Finally I succeded in finding out how to do basic operations with ptrList< type >. Below I posted some lines of my code. Hope it will be useful, because previously I searched the forum and didn't find basic info on this subject.

Code:
    /* Defining pointer list of scalars */
    PtrList< scalar > U_ ;
    scalar A = 3.1415;
    scalar *Aptr ;

    Aptr = &A ;

    U_.setSize( 10 ) ;

    for (label i = 0; i < 10; i++)
    {
        U_.set(i, Aptr) ;            // the ptrList can be filled in passing the pointer Aptr to scalar A
        Info << " if is set U_[i] = " << U_.set(i);    //checking if the list element U_[i] is already set --> if not the value of U_.set(i) == 0 ;
        Info << " U_[i] = " << U_[i] << endl ;         // prints out the values of prtList
    }
Bye! :-)
__________________
Best regards
P. Kuczynski.
kuczmas is offline   Reply With Quote

Old   May 19, 2011, 02:17
Default
  #6
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: http://olesenm.github.io/
Posts: 777
Rep Power: 18
olesen will become famous soon enough
Quote:
Originally Posted by kuczmas View Post
Dear forumers,

Finally I succeded in finding out how to do basic operations with ptrList< type >. Below I posted some lines of my code. Hope it will be useful, because previously I searched the forum and didn't find basic info on this subject.

Code:
    /* Defining pointer list of scalars */
    PtrList< scalar > U_ ;
    scalar A = 3.1415;
    scalar *Aptr ;
 
    Aptr = &A ;
 
    U_.setSize( 10 ) ;
 
    for (label i = 0; i < 10; i++)
    {
        U_.set(i, Aptr) ;            // the ptrList can be filled in passing the pointer Aptr to scalar A
        Info << " if is set U_[i] = " << U_.set(i);    //checking if the list element U_[i] is already set --> if not the value of U_.set(i) == 0 ;
        Info << " U_[i] = " << U_[i] << endl ;         // prints out the values of prtList
    }
Bye! :-)

Are you really certain that your code works correctly with PtrList?
Have you checked with valgrind that everything actually works properly when the U_ variable is destroyed? I have my doubts. Take a look at the destructor for PtrList and you'll see that it is doing a 'delete'. Your code will not mix well with this at all.
kuczmas likes this.
olesen is offline   Reply With Quote

Old   May 26, 2011, 04:50
Default
  #7
New Member
 
Paweł Kuczyński
Join Date: Feb 2011
Location: Warsaw, Poland
Posts: 19
Rep Power: 6
kuczmas is on a distinguished road
Dear olesen, many thanks for pointing out the problem. As I said before I am a beginner in openFoam, so I really appreciate all replies. I tried checking the code with valgrind and it shouts for some errors indeed. You have a valgrind response below:

Code:
==4315== Invalid free() / delete / delete[]
==4315==    at 0x4C26DCF: operator delete(void*) (vg_replace_malloc.c:387)
==4315==    by 0x5445C23: Foam::PtrList<double>::~PtrList() (PtrList.C:133)
==4315==    by 0x5442D79: Foam::pkModel::pk::checkDij_reciprocity() 
==4315==    by 0x44D031: main (hEqn.H:19)
==4315==  Address 0x7feffc260 is on thread 1's stack
==4315== 

...
...


==4315== 
==4315== HEAP SUMMARY:
==4315==     in use at exit: 300 bytes in 11 blocks
==4315==   total heap usage: 387,720 allocs, 387,719 frees, 41,168,150 bytes allocated
==4315== 
==4315== LEAK SUMMARY:
==4315==    definitely lost: 60 bytes in 1 blocks
==4315==    indirectly lost: 240 bytes in 10 blocks
==4315==      possibly lost: 0 bytes in 0 blocks
==4315==    still reachable: 0 bytes in 0 blocks
==4315==         suppressed: 0 bytes in 0 blocks
==4315== Rerun with --leak-check=full to see details of leaked memory
==4315== 
==4315== For counts of detected and suppressed errors, rerun with: -v
==4315== ERROR SUMMARY: 10 errors from 1 contexts (suppressed: 4 from 4)
In that case could you show how to properly define and use PtrList<> in order not to have memory problems?

kuczmas.
__________________
Best regards
P. Kuczynski.
kuczmas is offline   Reply With Quote

Old   May 26, 2011, 05:25
Default
  #8
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: http://olesenm.github.io/
Posts: 777
Rep Power: 18
olesen will become famous soon enough
Quote:
Originally Posted by kuczmas View Post
...
In that case could you show how to properly define and use PtrList<> in order not to have memory problems?
The fundamental question you should ask yourself: "why use PtrList if List will do?"

Code:
 
// Defining list of scalars
    List<scalar> U_ ;
    scalar A = 3.1415;

    U_.setSize(10) ;
    forAll(U_, i)
    {
        U_[i] = A;
        Info << " U_[i] = " << U_[i] << endl;
    }

Code:
 
// Defining list of scalars
    PtrList<scalar> U_ ;
    scalar A = 3.1415;

    U_.setSize(10) ;
    forAll(U_, i)
    {
        U_.set(i, new scalar(A));
        Info << " U_[i] = " << U_[i] << endl;
    }
If you don't actually need pointers for something special, you should generally stick with a "normal" List instead of using a PtrList.
Hanzo and luiscardona like this.
olesen is offline   Reply With Quote

Old   May 26, 2011, 07:07
Default
  #9
New Member
 
Paweł Kuczyński
Join Date: Feb 2011
Location: Warsaw, Poland
Posts: 19
Rep Power: 6
kuczmas is on a distinguished road
Dear Mark,

That was the piece of the code I actually was interested in and it works perfectly without any errors. Thanks a lot !
__________________
Best regards
P. Kuczynski.
kuczmas is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Needed Benchmark Problems for FSI Mechstud Main CFD Forum 4 July 26, 2011 12:13
Two-phase air water flow problems by activating Wall Lubrication Force challenger85 CFX 5 November 5, 2009 06:44
Help required to solve Hydraulic related problems aero CFX 0 October 30, 2006 12:00
Some problems with Star CD Micha CD-adapco 0 August 6, 2003 13:55
Airpak: Problems with heat flow contour conditions Ivan de Miguel Urain FLUENT 1 November 16, 2001 10:36


All times are GMT -4. The time now is 12:04.