
/* ===purpose=== */

/**********************************************************************************************************************************/
/*****************************************************  Computational cells  ******************************************************/
/*****************************  Definitions of wide range variables, arrays, functions and parameters  ****************************/
/**********************************************************************************************************************************/

/* Developer: Sylvain Nintcheu Fata, Oak Ridge National Laboratory */
/* Version:   V.1.0                                                */
/* Released:  Apr 21, 2011                                         */


#ifndef _CBEM_CELL_UTIL_H_
#define _CBEM_CELL_UTIL_H_


/* Singly Linked List Structure */
typedef struct slnlst { int id;
                        struct slnlst *next;
                      } ilst_t; 


/* A computational box containing the boundary mesh is subdivided into parallelepipeds called cells */
/* cellinfo_t == Structure to store information about a computational cell */
 typedef struct { int nec;           /* nec == Number of boundary elements in the current cell */
 		  int *elt_id;       /* elt_id[k] == Global index of the k-th boundary element in the current computational cell */
		                     /* Length of array elt_id is nec */
		  ilst_t *ptr_list;  /* ptr_list == Linked list */
		  double bbox[3][2]; /* Bounding Box of the current cell */
		  int nnnc;          /* nnnc = Number of Near-Neighboring cells to the current cell including itself */
		  int *nbor;         /* nbor[k] == Global index of the k-th near-neighboring cell to the current cell including itself */
		                     /* Length of array nbor is nnnc */
		  int nnbsprs;       /* nnbsprs == Number of Near-Neighboring cells to the current cell used */
                                     /*            in the Sparse approximation of the Discretized BIE        */
                                     /* nnbsprs <= nnnc */
		} cellinfo_t;


/* Cell Arrays and Parameters
 * A computational box containing the boundary mesh is subdivided into parallelepipeds called cells
 *--cell[k]--= Structure containing information about the k-th cell
 *----note---= cell is allocated and partially initialized in function "cbem_cell_init" (see cbem_cell_util.c)

 *---ncwelt--= Number of computional Cells containing boundary elements
 *---cwelt---= Array containing index of Computational Cells with boundary elements
 *----note---= Array cwelt is allocated and initialized in function "cbem_cell_init" (see cbem_cell_util.c)

 *----ncx----= Total number of cells in the computational box in the x-coordinate direction
 *----ncy----= Total number of cells in the computational box in the y-coordinate direction
 *----ncz----= Total number of cells in the computational box in the z-coordinate direction
 *---ncell---= Total number of cells in the homogeneous computational box: ncell = ncx*ncy*ncz
 *---nbfac---= Factor characterizing the near-neighboring region of a giving cell
 */
int ncwelt,ncell;
int ncx,ncy,ncz;
double nbfac;
int *cwelt;    /* cwelt == Computational Cells with boundary elements */
cellinfo_t *cell;


void cbem_cell_init(void); /* Construct the computational box and distribute without repetition boundary elements into cells */
void cbem_cell_neighbor(void); /* For all non-empty cell, find "Near-neighboring" cells */

#endif /* _CBEM_CELL_UTIL_H_ */
