FOAM FATAL ERROR: index -1 out of range when try to access neighbor cell

93 views
Skip to first unread message

kumaresh...@gmail.com

unread,
Nov 30, 2021, 10:39:02 PM11/30/21
to OpenFOAM
Hello Foamers,
In my work, I accessed neighbor cells. Here is the sample code for 1D problem.
//************************************************//
Foam::Map<label> niTableW, niTableE; // index tables
forAll(T_, cellI)
{
const Foam::List<label> neigbhorcellI = regionMesh().cellCells(cellI);
label nIW = -1, nIE = -1;

forAll(neigbhorcellI, I)
{
const label nI = neigbhorcellI[I];
if (regionMesh().cellCentres()[nI][0] < regionMesh().cellCentres()[cellI][0])
{
nIW = nI;
}

if (regionMesh().cellCentres()[nI][0] > regionMesh().cellCentres()[cellI][0])
{
nIE = nI;
}
//if (nIW >= 0 && nIE >= 0) break;
}
niTableW.insert(cellI, nIW);
niTableE.insert(cellI, nIE);
///////////////////////////////////////////

if (T_[cellI] == Tliq && alpha_[cellI] > scalar(0.0)
{
QB_[cellI] = K_[nIW]* ((T_[nIW] - Tliq) /DX.value());

QBMAX_[cellI] = (Lboil.value()* (DX.value() - XB_[cellI]) *RHOO.value() *alpha_[cellI] ) /dtime;
}

if (T_[nIE] < Tliq)
{
QC_[cellI] = K_[nIE]* ((Tliq - T_[nIE]) /DX.value());
QERR_[cellI] = QB_[cellI] - QC_[cellI];
}
//************************************************//
Hereby attaching the figure, where
nI = reference plane at 100deg (from where neighbor cells are accessed)
nIW = west node
nIE = east node
As per the figure and above description of code, when the OpenFOAM try to access east node (nIE) at the end of the domain, the error appears as following,

//************************************************//
--> FOAM FATAL ERROR:
index -1 out of range 0 ... 13


From function UList<T>::checkIndex(const label)
in file /home/kumaresh/OpenFOAM/OpenFOAM-2.1.1/src/OpenFOAM/lnInclude/UListI.H at line 109.
//************************************************//
And this error is reasonable. How to inform/code OpenFOAM not to access the last node (near the boundary), in order to avoid this error..
If someone can share the thoughts to resolve this error, it will be highly helpful.
Thank you

Figure.PNG

kumaresh...@gmail.com

unread,
Dec 4, 2021, 12:02:28 AM12/4/21
to OpenFOAM

Neighbour -1 indicates the loop arrived at a boundary cell. So thinking of condition if(!neigbhorcellI[nIE]==-1) to handle at the boundary but still it leads to error at the same line.. 
Any thoughts ?
Thank you 
Reply all
Reply to author
Forward
0 new messages