|
[Sponsors] |
March 13, 2008, 16:20 |
I'm having trouble initializin
|
#1 |
New Member
Mateusz Slowikowski
Join Date: Mar 2009
Location: Waterloo, Canada
Posts: 12
Rep Power: 17 |
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. |
|
March 13, 2008, 16:44 |
Hi,
Just a thought... maybe
|
#2 |
Senior Member
Philippose Rajan
Join Date: Mar 2009
Location: Germany
Posts: 552
Rep Power: 25 |
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 |
|
March 14, 2008, 09:53 |
Philippose,
I've tried maki
|
#3 |
New Member
Mateusz Slowikowski
Join Date: Mar 2009
Location: Waterloo, Canada
Posts: 12
Rep Power: 17 |
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. |
|
March 14, 2008, 10:14 |
Hi Mateusz,
maybe if you tr
|
#4 |
Member
Francesco Boschetto
Join Date: Mar 2009
Location: Italy
Posts: 56
Rep Power: 17 |
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 |
|
March 14, 2008, 14:31 |
Hi again,
I was checking up
|
#5 |
Senior Member
Philippose Rajan
Join Date: Mar 2009
Location: Germany
Posts: 552
Rep Power: 25 |
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 |
|
March 15, 2008, 00:27 |
Actually... this is exactly wh
|
#6 |
New Member
Mateusz Slowikowski
Join Date: Mar 2009
Location: Waterloo, Canada
Posts: 12
Rep Power: 17 |
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!
|
|
February 22, 2012, 13:50 |
|
#7 |
Member
Join Date: Jun 2011
Posts: 42
Rep Power: 15 |
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? |
|
March 19, 2012, 08:09 |
|
#8 |
New Member
Terrence Nguyen
Join Date: Jan 2012
Posts: 13
Rep Power: 14 |
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. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Initialization problem | Parag Gadgil | FLUENT | 2 | January 2, 2009 21:43 |
Initialization problem when using Axisymmetry BC | Eduardo | FLUENT | 0 | August 4, 2008 10:23 |
PtrList deletion | grtabor | OpenFOAM | 1 | September 22, 2007 18:55 |
coal combustion initialization problem | Chetan Prahsant | CFX | 1 | May 1, 2007 06:41 |
Initialization Problem...Please Help!!! | Ryan | FLUENT | 4 | July 28, 2006 20:13 |