PtrList problems
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>::ptr_’, 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>::ptr_’, which is of non-class type ‘int’ /opt/openfoam171/src/OpenFOAM/lnInclude/tmpI.H: In member function ‘T* Foam::tmp<T>::ptr() 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! |
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. |
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 |
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. |
solution to the problems
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 */ |
Quote:
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. |
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[] kuczmas. |
Quote:
Code:
Code:
|
Dear Mark,
That was the piece of the code I actually was interested in and it works perfectly without any errors. Thanks a lot :) ! |
All times are GMT -4. The time now is 10:25. |