
/* ===purpose=== */

/**********************************************************************************************************************************/
/**********************************  GALERKIN BEM for 3D LAPLACE EQUATION: SINGULAR FORMULATION  **********************************/
/************************************  3-NODED TRIANGULAR ELEMENT: SEMI-ANALYTIC INTEGRATION  *************************************/
/************************************************  PIECEWISE LINEAR APPROXIMATION  ************************************************/
/*****************************  Definitions of wide range variables, arrays, functions and parameters  ****************************/
/**********************************************************************************************************************************/

/* Developer: Sylvain Nintcheu Fata */
/* Version:   V.1.1                 */
/* Released:  Jun 14, 2012          */


#ifndef _GBEM_LAP_GLOBAL_VAR_H_
#define _GBEM_LAP_GLOBAL_VAR_H_

#include <time.h>
#include "gbem_util.h"


/* Parameters
 *----gm_eps---= Tolerance on the geometry
 *----f_eps----= Tolerance on the argument of a function
 *-----pi------= pi = 3.1415926535897932
 *----pix2-----= pix2 = 2*pi
 *-----fac-----= Factor of the Green's function: fac = 1/(4*pi)
 */
double pi,pix2,fac;
double gm_eps,f_eps;


/* Potential and Flux
 *-----pbv-----= Vector containing Prescribed Boundary Values
 *-------------- pbv is allocated and initialized in function "gbem_lap_input" (see gbem_lap_input.c) 
 *-----phi-----= Vector containing boundary potentials
 *-------------- phi is allocated and initialized in function "gbem_lap_lrhs" (see gbem_lap_lrhs.c)
 *-----flx-----= Vector containing boundary fluxes
 *-------------- flx is allocated and initialized in function "gbem_lap_lrhs" (see gbem_lap_lrhs.c)
 */
double *pbv;
double *phi, *flx;


/* Boundary Conditions
 *----ndbc-----= Array specifying boundary condition at a boundary node: 0 for Dirichlet and 1 for Neumann
 *-------------- ndbc[k] = 0 ==> Dirichlet boundary condition is prescribed at bnd[k][0:2]
                 ndbc[k] = 1 ==> Neumann boundary condition is prescribed at bnd[k][0:2]
 *-------------- Array ndbc is allocated and initialized in function "gbem_lap_input" (see gbem_lap_input.c)
 */
int *ndbc;


/* Surface Geometry
 *--mx_nd_elt--= Maximum number of nodes per element
 *----nbnd-----= Total number of boundary nodes
 *----nbelt----= Total number of boundary elements
 *-smx_nd_elt--= smx_nd_elt = mx_nd_elt*mx_nd_elt

 *----belt-----= Array defining boundary element connectivity
 *-------------- belt[k][i] == Global index of the i-th node on the boundary element k, i=0,1,2
 *-------------- Array belt is allocated and initialized in function "gbem_lap_input" (see gbem_lap_input.c)

 *----bnd------= Cartesian coordinates of all boundary nodes
 *-------------- Array bnd is allocated and initialized in function "gbem_lap_input" (see gbem_lap_input.c)

 *-----pp------= pp[k] == Global index of the k-th node of the boundary element P
 *-----qq------= qq[k] == Global index of the k-th node of the boundary element Q
 *-------------- Arrays pp and qq are allocated and initialized in function "gbem_lap_init" (see gbem_lap_init.c)

 *-----xeP-----= xeP[k][0:2] == Cartesian coordinates of the k-th node of the boundary element P
 *-----xeQ-----= xeQ[k][0:2] == Cartesian coordinates of the k-th node of the boundary element Q
 *-------------- Arrays xeP and xeQ are allocated and initialized in function "gbem_lap_init" (see gbem_lap_init.c)

 *---DistPQ----= Distance between element P and element Q defined as 
 *-------------- minimum distance between vertices of element P and vertices of element Q

 *--PQmLocId---= PQmLocId[0] == Local index of the vertex of element P at which DistPQ is attained
 *-------------- PQmLocId[1] == Local index of the vertex of element Q at which DistPQ is attained
 *-------------- (PQmLocId[0],PQmLocId[1]) is also used to give vertex-adjacent pair and
 *-------------- edge-adjacent pair (see function "int_type" in gbem_util.c)

 *---EltDiam---= EltDiam[k] == Diameter of the k-th boundary element
 *--EltAreax2--= EltAreax2[k] = 2*Area of the k-th boundary element
 *-LocCBasisElt-= LocCBasisElt[k][0:8] == Local Companion Basis associated with the k-th boundary element
 *--thetaElt---= thetaElt[k][i] == Angle at the i-th vertex of the k-th boundary element
 *----xvElt----= xvElt[k][0] == Base of the k-th boundary element
 *-------------- xvElt[k][1] == Geometric parameter associated with the k-th boundary element
 *----zvElt----= zvElt[k] == Height of the k-th boundary element
 *-------------- Arrays EltDiam,EltAreax2,LocCBasisElt,xvElt,zvElt,thetaElt are allocated
 *-------------- and initialized in function "gbem_lap_init" (see gbem_lap_init.c)

 *----shfv-----= shfv[i][k][l] == l-th shape function evaluated at Gauss point (k,i) for vertex-adjacent integration
 *----shfe1----= shfe1[i][k][l] == l-th shape function evaluated at Gauss point (k,i) for edge-adjacent integration: E'
 *----shfe2----= shfe2[i][k][l] == l-th shape function evaluated at Gauss point (k,i) for edge-adjacent integration: E"
 *-------------- Arrays shfv,shfe1,shfe2 are allocated and initialized in function "gbem_lap_init" (see gbem_lap_init.c)

 * A Multiple Node is a set of boundary nodes which represent the same geometric position (i.e. have the same Cartesian coordinates)
 *--------------  but are located at the intersection of smooth patches forming the surface mesh
 * A Multiple Node is, for example, a boundary node at a corner of a cube
 *--nmltplnd---= Number of Multiple nodes on the boundary mesh <==> Number of class of Multiple Nodes on the boundary mesh
 *---mltplnd---= Array of Multiple nodes, allocated and initialized in function "mltpl_nd" in mltpl_nd.c
 */
const int mx_nd_elt=3;
int nbnd, nbelt;
int smx_nd_elt;
int **belt;
int PQmLocId[2];
int *pp, *qq;
double **bnd;
double **xeP, **xeQ;
double DistPQ; /* DistPQ == Distance between element P and element Q */
double *EltDiam, *EltAreax2;
double **LocCBasisElt;
double **xvElt, *zvElt, **thetaElt;
double ***shfv,***shfe1,***shfe2;
int nmltplnd; /* nmltplnd == Number of Multiple nodes (or Number of class of Multiple Nodes) on the boundary mesh */
mltndinfo_t *mltplnd; /* mltplnd[k] == Structure containing information about the k-th class of multiple nodes */


/* Discretized BIE
 *------h------= Potential influence matrix <==> Coefficient matrix multiplying the vector of boundary potentials
 *------g------= Flux influence matrix <==> Coefficient matrix multiplying the vector of boundary fluxes
 *-------------- Arrays h and g are allocated and initialized in function "gbem_lap_assem" (see gbem_lap_assem.c)

 *-----rhs-----= Right-hand side of the Discretized BIE
 *-------------- Array rhs is allocated and initialized in function "gbem_lap_lrhs" (see gbem_lap_lrhs.c)

 *----int_p----= Local contribution for potential influence matrix
 *----int_f----= Local contribution for flux influence matrix
 *----int_r----= Local contribution for potential/flux influence matrix
 *-------------- Arrays int_p,int_f,int_r are allocated and initialized in function "gbem_lap_init" (see gbem_lap_init.c)

 *----dwrk-----= Temporary working array, dwrk[mx_nd_elt][mx_nd_elt]
 */
double *h, *g;
double *rhs;
double *int_p, *int_f, *int_r;
double **dwrk;


/* One-dimensional Gauss-Legendre quadrature
 *-----ng1-----= Number of Gauss-Legendre points over a segment [0,1] for Singular (Edge-adjacent and Vertex-adjacent) integrations
 *-----ng2-----= Number of Gauss-Legendre points over a segment [0,1] for Quasi-singular integration
 *-----ng3-----= Number of Gauss-Legendre points over a segment [0,1] for Non-singular integration
 *-----xi1-----= Array to store Gauss-Legendre points over a segment [0,1] for Singular (Edge-adjacent and Vertex-adjacent) integrations
 *-----xi2-----= Array to store Gauss-Legendre points over a segment [0,1] for Quasi-singular integration
 *-----xi3-----= Array to store Gauss-Legendre points over a segment [0,1] for Non-singular integration
 *----wwg1-----= wwg1[i][k] = wg1[i]*wg1[k], where wg1[k] is the k-th Gauss-Legendre weight factor corresponding to xi1[k]
 *----wwg2-----= wwg2[i][k] = wg2[i]*wg2[k], where wg2[k] is the k-th Gauss-Legendre weight factor corresponding to xi2[k]
 *----wwg3-----= wwg3[i][k] = wg3[i]*wg3[k], where wg3[k] is the k-th Gauss-Legendre weight factor corresponding to xi3[k]
 */
int ng1, ng2, ng3;
double *xi1, *xi2, *xi3;
double **wwg1, **wwg2, **wwg3;


void gbem_lap_srf_eval(const char *InfParams,const char *InfData,clock_t tm0); /* Solve the Singular BIE for the Laplace equation */
void gbem_lap_fld_eval(int nip,double **ipts,double *fldvl); /* Compute the potential at interior points */
void gbem_lap_del(void); /* Deallocate remaining global arrays associated with the GALERKIN BEM */

#endif /* _GBEM_LAP_GLOBAL_VAR_H_ */
