Page 323 - The Combined Finite-Discrete Element Method
P. 323
306 ALGORITHM IMPLEMENTATION
while(iblock>=0)
{ i=ibig[iblock];
j=iend[iblock];
iblock=iblock-1;
if(j>i)
{ tmp=0; m=0; isort=0;
while((isort<nsort)&&(m==tmp))
{ i1=i2[isort];
isort=isort+1;
tmp=i1[j];
m=tmp;
for(k=i;k<j;k++)
{ tmp=MINIM(tmp,i1[k]);
m=MAXIM(m,i1[k]);
}}
if(tmp!=m)
{ m=(tmp+m)/2;
while(i<=j)
{ while((i<=j)&&(i1[i]<=m)) {i=i+1;}
while((j>=i)&&(i1[j]>m)) {j=j-1;}
if(j>i)
{ for(isort=0;isort<nrear;isort++)
{ i1r=i2[isort];
tmp=i1r[j];
i1r[j]=i1r[i];
i1r[i]=tmp;
}} }
ibig[iblock+2]=ibig[iblock+1];
iend[iblock+2]=j;
ibig[iblock+1]=i;
iblock=iblock+2;
}}}}
Listing 10.22 Sorting a set of one-dimensional integer arrays– sorting procedure.
elements. All z-lists are at this stage considered to be ‘new z-lists’. Many of these ‘new’
z-lists are empty, i.e. lists with no discrete elements assigned to them. By default, the head
of each empty list is −1, which indicates non-existing discrete elements. All non-empty
lists have heads greater than or equal to zero. This is because in C, numbering starts
with zero.
To identify non-empty z-lists, a loop over all discrete elements is performed. As each
discrete element belongs to one and only one list, the list to which a particular discrete
element belongs is, by default, a non-empty list. This list is identified by the integerised z
coordinate of the particular discrete element. However, the list may contain more than one
discrete element, thus the same list would be visited as many times as there are discrete
elements in a particular list. To avoid this, as soon as the ‘new’ list is detected, it is marked
as an old list, as shown in Listing 10.29. In that way, when another discrete element from
the same list points to this list, it will be found to be an ‘old’ list, and will therefore
be ignored. Marking a list as an old list is done by setting i1cfz[iz]=i1cfz[iz]+nelemd;,