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

Index out of range fatal error

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Rahand

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 13, 2016, 08:11
Default Index out of range fatal error
  #1
New Member
 
Rahand
Join Date: Mar 2016
Posts: 10
Rep Power: 10
Rahand is on a distinguished road
Hello everyone,

I am trying to implement a new scalar (Bt) in ReactingParcelIO.C in OF 2.4.0 to write and read.
The compiling works, but when I run the solver it crushes as soon as the variable should be written with this message:

Code:
--> FOAM FATAL ERROR: 
index 1 out of range 0 ... 0

    From function UList<T>::checkIndex(const label)
    in file /home/user/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/lnInclude/UListI.H at line 109.

FOAM aborting

#0  Foam::error::printStack(Foam::Ostream&) at ~/OpenFOAM/OpenFOAM-2.4.0/src/OSspecific/POSIX/printStack.C:219
#1  Foam::error::abort() at ~/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/lnInclude/error.C:249
#2  Foam::Ostream& Foam::operator<< <Foam::error>(Foam::Ostream&, Foam::errorManip<Foam::error>) at ~/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/lnInclude/errorManip.H:85 (discriminator 3)
#3  Foam::UList<double>::checkIndex(int) const at ~/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/lnInclude/UListI.H:113
#4  Foam::UList<double>::operator[](int) at ~/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/lnInclude/UListI.H:168
#5  ? at ~/OpenFOAM/user-2.4.0/src/mylagrangian/myintermediate/lnInclude/ReactingParcelIO.C:209 (discriminator 1)
#6  ? at ~/OpenFOAM/user-2.4.0/src/mylagrangian/myspray/lnInclude/SprayParcelIO.C:249
#7  ? at ~/OpenFOAM/user-2.4.0/src/mylagrangian/myintermediate/lnInclude/ReactingCloud.C:368
#8  ? at ~/OpenFOAM/OpenFOAM-2.4.0/src/lagrangian/basic/lnInclude/CloudIO.C:287
#9  Foam::objectRegistry::writeObject(Foam::IOstream::streamFormat, Foam::IOstream::versionNumber, Foam::IOstream::compressionType) const at ~/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/db/objectRegistry/objectRegistry.C:364
#10  Foam::objectRegistry::writeObject(Foam::IOstream::streamFormat, Foam::IOstream::versionNumber, Foam::IOstream::compressionType) const at ~/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/db/objectRegistry/objectRegistry.C:364
#11  Foam::Time::writeObject(Foam::IOstream::streamFormat, Foam::IOstream::versionNumber, Foam::IOstream::compressionType) const at ~/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/db/Time/TimeIO.C:518
#12  Foam::regIOobject::write() const at ~/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C:134
#13  ? at ~/OpenFOAM/user-2.4.0/applications/solvers/mysprayFoam/mysprayFoam.C:101 (discriminator 2)
#14  __libc_start_main in "/lib64/libc.so.6"
#15  ? at /home/abuild/rpmbuild/BUILD/glibc-2.19/csu/../sysdeps/x86_64/start.S:125
I checked UListI.H and there it checks for a size and an index. Like
Code:
// Check index i is within valid range (0 ... size-1).
template<class T>
inline void Foam::UList<T>::checkIndex(const label i) const
{
    if (!size_)
    {
        FatalErrorIn("UList<T>::checkIndex(const label)")
            << "attempt to access element from zero sized list"
            << abort(FatalError);
    }
    else if (i<0 || i>=size_)
    {
        FatalErrorIn("UList<T>::checkIndex(const label)")
            << "index " << i << " out of range 0 ... " << size_-1
            << abort(FatalError);
    }
}
But which index and size are meant here? Do I have to set something somewhere else or extend?

This is the lines where the solver fails. I added Bt there and at some other places to it:

Code:
        
IOField<scalar> mass0(c.fieldIOobject("mass0", IOobject::NO_READ), np);

IOField<scalar> Bt(c.fieldIOobject("Bt", IOobject::NO_READ), np);

label i = 0;
forAllConstIter(typename Cloud<ReactingParcel<ParcelType> >, c, iter)
        {
            const ReactingParcel<ParcelType>& p = iter();
            mass0[i++] = p.mass0_;
            Bt[i++] = p.Bt_;
 
        }
        mass0.write();
        Bt.write();
BTW if I remove mass0 and just keep Bt everything will run without errors. It also will run when I add a new scalar to SprayParcelIo.C.

Does anyone know a solution? I'll appreciate any help.

Thanks!
Rahand is offline   Reply With Quote

Old   April 13, 2016, 13:35
Default Solved!
  #2
New Member
 
Rahand
Join Date: Mar 2016
Posts: 10
Rep Power: 10
Rahand is on a distinguished road
I solved the problem. It was an array mistake. Changed and works:

Code:
    label i = 0;
    forAllIter(typename Cloud<ReactingParcel<ParcelType> >, c, iter)
    {
        ReactingParcel<ParcelType>& p = iter();
        p.mass0_ = mass0[i];
        p.Bt_ = Bt[i];
        i++;

    }
mikulo likes this.
Rahand 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
[OpenFOAM.org] compile error in dynamicMesh and thermophysicalModels libraries NickG OpenFOAM Installation 3 December 30, 2019 00:21
Undeclared Identifier Errof UDF SteveGoat Fluent UDF and Scheme Programming 7 October 15, 2014 07:11
Errors in UDF shashank312 Fluent UDF and Scheme Programming 6 May 30, 2013 20:30
[swak4Foam] groovyBC: problems compiling: "flex: not found" and "undefined reference to ..." sega OpenFOAM Community Contributions 12 February 17, 2010 09:30
Version 15 on Mac OS X gschaider OpenFOAM Installation 113 December 2, 2009 10:23


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