Page 322 - The Combined Finite-Discrete Element Method
P. 322

NBS CONTACT DETECTION ALGORITHM IN 3D       305

                    .........continued from previous listing.............
               /* add forces into global vector */
               for(i=0;i<4;i++)
               { d1ncfx[ipc[i]]]=d1ncfx[ipc[i]]]+fc[i]*xnc;
                d1ncfy[ipc[i]]=d1ncfy[ipc[i]]+fc[i]*ync;
                d1ncfz[ipc[i]]=d1ncfz[ipc[i]]+fc[i]*znc;
                d1ncfx[ipt[i]]]=d1ncfx[ipt[i]]]-ft[i]*xnc;
                d1ncfy[ipt[i]]=d1ncfy[ipt[i]]-ft[i]*ync;
                d1ncfz[ipt[i]]=d1ncfz[ipt[i]]-ft[i]*znc;
            } }}}
                           Listing 10.20  Adding forces to the global force vector.


                   void TsortINT(n,nsort,nrear,i2)
            /* Sorts nsort arrays - smallest...largest */
            /* and rearrange nrear-nsort arrays same way */
             INT n; INT nsort; INT nrear; INT **i2;
            { INT iblock,i,j,k,isort,tmp,m;
             INT *il, *ilr;
             INT ibig[50];
             INT iend[50];
             ibig[0]=0;
             iend[0]=n-1;
             iblock=0;
                  Listing 10.21  Sorting a set of one-dimensional integer arrays– local variables.



             First the space boundaries are calculated using a loop over all discrete elements, as
           shown in Listing 10.24. The second step is a calculation of total number of cells in the
           x, y and z direction (ncelx, ncely, ncelz) (Listing 10.25).
             Once the required number of cells in each direction is known, dynamic memory allo-
           cation is performed and dynamic arrays are created (Listing 10.26).
             A one-dimensional integer array i1cfz[ncelz] is allocated to store the first element
           (head) of each of the lists containing discrete elements mapped onto the same layer of
           cells (z direction).
             Two one-dimensional arrays, i2cfy[0] and i2cfy[1], are allocated for storing the heads
           of y-lists for layers (iz-1)and iz, respectively (where iz is the current central layer). Two
           one-dimensional arrays, i2cfx[0] and i2cfx[1], are allocated to store the heads of x-lists.
           Array i2cfx[0] stores the heads of all x-lists for the central row iy; array i2cfx[1] stores the
           heads of all x-lists containing all the discrete elements from all y-rows that are neighbouring
           rows of the central row iy according to the contact map. Arrays i1cnz, i1cny and i1cnx are
           one-dimensional arrays used to store, for each discrete element, the next discrete element
           that is in the same z-list, y-list or x-list, respectively. Listing 10.27 represents initialisation,
           where all lists are initialised in such a way that they represent empty lists. The first loop in
           the listing makes all z-lists empty lists. The second loop makes all lists of both sets of y-lists
           empty. The third loop makes all lists of both sets of x-lists empty.
             In Listing 10.28, all discrete elements are placed onto the corresponding z-list according
           to the z-coordinates of each discrete element. This is done using the loop over all discrete
   317   318   319   320   321   322   323   324   325   326   327