ERROR: attempt to access element from zero sized list
// loop over faces
label faceI = faces[facei];
label patchI = psi.mesh().boundaryMesh().whichPatch(faceI);
// if facei is in patch: patchI < -1
if (patchI > -1)
faceI = psi.mesh().boundaryMesh()[patchI].whichFace(faceI);
psiBoundary = psi.boundaryField()[patchI][faceI];
Info << " Face: " << faceI << " Psi value: " << psiBoundary;
I am using the above code to access the value of psi (a distance function) at the boundaries. But during the execution of the "psiBoundary"( as seen above) I am getting this error
--> FOAM FATAL ERROR:
attempt to access element from zero sized list
From function UList<T>::checkIndex(const label)
in file /opt/openfoam220/src/OpenFOAM/lnInclude/UListI.H at line 103.
#0 Foam::error::printStack(Foam::Ostream&) in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#1 Foam::error::abort() in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#6 __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
I just know this is something related to the index " i " in the UListI.H but I couldn't figure out what exactly is going on there.:confused:
Thanks in advance,
First, I get that error when the list / field has been declared, but has not yet been allocated, and I try accessing it. It usually means it wasn't built properly. Maybe psi isn't built properly.
Second, are you mixing up facei and faceI? (This is bad practice to differentiate variables by case alone, but OpenFOAM is guilty of this too.)
Just some thoughts.
Thank you for the reply,
I checked everything but I dint see any mistake in psi field. According to the error, it is accessing value from zero sized array but when I printed out the value of "psi.boundaryField().size()", I got the value as 6, and I even tried printing out "psi.boundaryField()", It gave the correct boundary conditions as defined by me. That means it's not a zero sized array. But I still get the same error at Cell=0 ,patchI=0 and faceI=0 when I use "psi.boundaryField()[patchI][faceI] "
I think it might be accessing an empty patch. How to give a condition so that it doesn't access an empty patch?
It's true that empty patch fields do not initialize the boundary fields, so that would explain the error you are getting.
psi.boundaryField().size() would tell you how many boundary patches you have... that's not where the error would lie. If you try psi.boundaryfield().size(), or , , etc. what do you get?
Also, why are you finding which patch the face is in? It seems unnecessary. You have psi.boundaryField(), so why not restructure it just to loop over the structure of psi.boundaryField(), rather than all the faces? Such as:
|All times are GMT -4. The time now is 18:14.|