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

PtrList initialization problem

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By philippose

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 13, 2008, 15:20
Default I'm having trouble initializin
  #1
New Member
 
Mateusz Slowikowski
Join Date: Mar 2009
Location: Waterloo, Canada
Posts: 12
Rep Power: 17
mateusz_slowikowski is on a distinguished road
I'm having trouble initializing some pointers. The code compiles fine, but when I run my case (which, at the moment is very basic) and run my createFields.H file, it says that I'm trying to assign a value to a null reference: is there a way of initializing the pointer list to non-null values?

This is part of my createFields.H file:

const N_Bins = 6;
PtrList<volvectorfield> U_;
U_.setSize(N_Bins);

{
std::stringstream converter;
for (int i = 0; i < N_Bins; i++)
{
converter.str("");
converter << (i+1);
word phaseNumber = word(converter.str());

volVectorField Utemp(
IOobject
(
"Ua"
mesh.time().timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
Ua
);

U_[i] = Utemp;
}
}

This is the error that is generated when I run the case:

--> FOAM FATAL ERROR : hanging pointer, cannot dereference#0 Foam::error::printStack(Foam:stream&)
#1 Foam::error::abort()
#2 main
#3 __libc_start_main
#4 __gxx_personality_v0


From function PtrList::operator[]
in file /usr/local/OpenFOAM/OpenFOAM-1.4/src/OpenFOAM/lnInclude/PtrListI.H at line 92.
mateusz_slowikowski is offline   Reply With Quote

Old   March 13, 2008, 15:44
Default Hi, Just a thought... maybe
  #2
Senior Member
 
Philippose Rajan
Join Date: Mar 2009
Location: Germany
Posts: 552
Rep Power: 25
philippose will become famous soon enough
Hi,

Just a thought... maybe PtrList starts from index "1" and not index "0".... not sure, but that error message seems to kind of point to that.

Have a nice day!

Philippose
philippose is offline   Reply With Quote

Old   March 14, 2008, 08:53
Default Philippose, I've tried maki
  #3
New Member
 
Mateusz Slowikowski
Join Date: Mar 2009
Location: Waterloo, Canada
Posts: 12
Rep Power: 17
mateusz_slowikowski is on a distinguished road
Philippose,

I've tried making a loop from i=1 -> N_Bins, but I get the same error:

--> FOAM FATAL ERROR : hanging pointer, cannot dereference#0 Foam::error::printStack(Foam:stream&)
#1 Foam::error::abort()
#2 main
#3 __libc_start_main
#4 __gxx_personality_v0


From function PtrList::operator[]
in file /usr/local/OpenFOAM/OpenFOAM-1.4/src/OpenFOAM/lnInclude/PtrListI.H at line 92.

I have a suspision that it's making a list of pointers of null values - and I tried to make a pointer array of volVectorFields, declare the loop, then pass the variables into the PtrList, but this also did not work. Thanks for the input either way - it was a worthy idea to check.
mateusz_slowikowski is offline   Reply With Quote

Old   March 14, 2008, 09:14
Default Hi Mateusz, maybe if you tr
  #4
Member
 
Francesco Boschetto
Join Date: Mar 2009
Location: Italy
Posts: 56
Rep Power: 17
francesco_b is on a distinguished road
Hi Mateusz,

maybe if you try to do make the loop from i=0 to N_binc-1 you'll fix the issue, I don't know if this is the problem, but it seems something about 0 value

Hope this helps

Regards

Francesco
francesco_b is offline   Reply With Quote

Old   March 14, 2008, 13:31
Default Hi again, I was checking up
  #5
Senior Member
 
Philippose Rajan
Join Date: Mar 2009
Location: Germany
Posts: 552
Rep Power: 25
philippose will become famous soon enough
Hi again,

I was checking up in the Doxygen help system online, and found the following....

T & operator[](const label)[inline]

Return element reference.


Now.... the operator [] returns a reference to the element.... which means, it can be used on the RHS of an assignment... not on the LHS.

As far as I can see, I don't think you can use this to actually assign elements to the pointer list... you need to use the following member function of the PtrList class:

U_.set(i,Utemp)

"set" is the member function which actually lets you fill the list.

Hope this helps :-)!

Philippose
Kummi likes this.
philippose is offline   Reply With Quote

Old   March 14, 2008, 23:27
Default Actually... this is exactly wh
  #6
New Member
 
Mateusz Slowikowski
Join Date: Mar 2009
Location: Waterloo, Canada
Posts: 12
Rep Power: 17
mateusz_slowikowski is on a distinguished road
Actually... this is exactly what I was looking for - I changed the code and the program (with fixing some other... elementary... errors) ran perfectly. Thank you for the help!
mateusz_slowikowski is offline   Reply With Quote

Old   February 22, 2012, 12:50
Default
  #7
Member
 
Join Date: Jun 2011
Posts: 42
Rep Power: 14
mikeP is on a distinguished road
Hello, I have a problem on this issue.

It works well for me. I use the volVectorField's in equations using U_[0], U_[1], etc.
However, when the runtime is complete, it does not output the resulting vectorfields although it is mentioned AUTO_WRITE.

why would that be the case?
mikeP is offline   Reply With Quote

Old   March 19, 2012, 07:09
Default
  #8
New Member
 
Terrence Nguyen
Join Date: Jan 2012
Posts: 13
Rep Power: 14
hismother is on a distinguished road
Hi MikeP,

I am having the same problem that you mentioned. Have you figured out why it is like that?

If yes, could you show me how to solve this problem.

Terrence.
hismother is offline   Reply With Quote

Old   March 19, 2012, 14:32
Default
  #9
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
Can you post up your code and a case if possible?
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialization problem Parag Gadgil FLUENT 2 January 2, 2009 20:43
Initialization problem when using Axisymmetry BC Eduardo FLUENT 0 August 4, 2008 09:23
PtrList deletion grtabor OpenFOAM 1 September 22, 2007 17:55
coal combustion initialization problem Chetan Prahsant CFX 1 May 1, 2007 05:41
Initialization Problem...Please Help!!! Ryan FLUENT 4 July 28, 2006 19:13


All times are GMT -4. The time now is 06:27.