!----------------------------------------------------------------------------------------------------------------------------------!
SUBROUTINE gbem_lap_input(InfParams,InfData)
!----------------------------------------------------------------------------------------------------------------------------------!

!===purpose===! 

!**********************************************************************************************************************************!
!**********************************  GALERKIN BEM for 3D LAPLACE EQUATION: SINGULAR FORMULATION  **********************************!
!************************************  3-NODED TRIANGULAR ELEMENT: SEMI-ANALYTIC INTEGRATION  *************************************!
!************************************************  PIECEWISE LINEAR APPROXIMATION  ************************************************!
!**********************************************  Data input for 3D Laplace Equation  **********************************************!
!**********************************************************************************************************************************!

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

 
USE KINDS
USE PARAMS,   ONLY: gm_eps,f_eps ! gm_eps == Tolerance on the geometry, f_eps == Tolerance on the argument of a function
USE SRF_GEOM, ONLY: mx_nd_elt    ! mx_nd_elt == Maximum number of nodes per element
USE SRF_GEOM, ONLY: nbnd,nbelt   ! nbnd == Total number of boundary nodes, nbelt == Total number of boundary elements
USE SRF_GEOM, ONLY: belt         ! belt(:,i) == Global indices of boundary nodes on the i-th element
USE SRF_GEOM, ONLY: bnd          ! bnd(:,i) == Cartesian coordinates of the i-th boundary node
USE SRF_COND, ONLY: ndbc	 ! ndbc(i) = {0,1} ==> {Dirichlet,Neunamm} boundary condition is prescribed at bnd(:,i)
USE POTFLUX,  ONLY: pbv          ! pbv(i) == Prescribed Boundary Value at the i-th boundary node
USE GAUSS1D,  ONLY: ng1,ng2,ng3  ! ng1 == Number of Gauss-Legendre points over a segment [0,1] for Singular 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
USE ITER_SOLV,ONLY: ldim         ! ldim == Dimension of the iterative solver BiCGSTAB(ldim)
USE ITER_SOLV,ONLY: mxmatvec     ! mxmatvec == Maximum number of matrix-vector mutiplications in the iterative solver BiCGSTAB(ldim)
USE ITER_SOLV,ONLY: slv_eps      ! slv_eps == Tolerance on the BiCGSTAB(ldim) iterative solver
USE CELL_ARP, ONLY: ncx,ncy,ncz  ! ncx,ncy,ncz == Total number of cells in the computational box in the x,y,z-coordinate
				 ! directions respectively
USE CELL_ARP, ONLY: nbfac        ! nbfac == Parameter characterizing the near-neighboring region of a given cell
USE PRECOND,  ONLY: sparseflg    ! sparseflg == Parameter that determines the sparsity pattern of the preconditoner
				 ! sparseflg = 0 ==> no preconditoner
				 ! sparseflg = 1 ==> the sparsity pattern of the preconditoner is given by Cell self-interactions
				 ! sparseflg = 1+n ==> the sparsity pattern of the preconditoner is given by Cell + n Neighbors interactions


IMPLICIT NONE

 character(len=72) :: InfParams,InfData 
 integer(kind=k9) :: i,alloc_st,alloc_st1,alloc_st2



    open (unit=54, file=InfParams, action='read')

!*** Read parameters
     read(54,*)ng1         ! ng1 == Number of Gauss-Legendre points over a segment [0,1] for Singular integrations
     read(54,*)ng2         ! ng2 == Number of Gauss-Legendre points over a segment [0,1] for Quasi-singular integration
     read(54,*)ng3         ! ng3 == Number of Gauss-Legendre points over a segment [0,1] for Non-singular integration
     read(54,*)gm_eps      ! gm_eps == Tolerance on the geometry
     read(54,*)f_eps       ! f_eps == Tolerance on the argument of a function
     read(54,*)ldim        ! ldim == Dimension of the BiCGSTAB(ldim)
     read(54,*)mxmatvec    ! mxmatvec == Maximum number of matrix-vector mutiplication in the iterative solver BiCGSTAB(ldim)
     read(54,*)slv_eps     ! slv_eps == Tolerance on the BiCGSTAB(ldim) iterative solver 
     read(54,*)ncx,ncy,ncz ! Parameters of the computational box containing the boundary mesh
     read(54,*)nbfac       ! nbfac == Neighbor Factor
     read(54,*)sparseflg   ! sparseflg == Parameter that determines the sparsity pattern of the preconditoner
    close(54)

    open (unit=55, file=InfData, action='read')

    read(55,*) nbnd  ! nbnd == Total number of boundary nodes
    read(55,*) nbelt ! nbelt == Total number of boundary elements

    allocate(bnd(3,nbnd),STAT=alloc_st) ! (bnd(1,i),bnd(2,i),bnd(3,i)) == Cartesian coordinates of the i-th boundary node
    allocate(pbv(nbnd),  STAT=alloc_st1)
    allocate(ndbc(nbnd), STAT=alloc_st2)
     if ( (alloc_st == 0) .and. (alloc_st1 == 0) .and. (alloc_st2 == 0) ) then ! If bnd, pbv, ndbc are successfully allocated
!*** Read the Cartesian coordinates, Prescribed Boundary Value and characteristics of each boundary node
          loop0: do i=1,nbnd ! Loop over all boundary nodes
             read(55,*)  bnd(1,i), bnd(2,i), bnd(3,i), pbv(i), ndbc(i)
          enddo loop0
     else
          if ( alloc_st /= 0 ) then ! If bnd is not successfully allocated 
                write(*,*)'gbem_lap_input: Allocate array "bnd" failed with Status=',alloc_st
	        stop
          endif

          if ( alloc_st1 /= 0 ) then ! If pbv is not successfully allocated 
                write(*,*)'gbem_lap_input: Allocate array "pbv" failed with Status=',alloc_st1
	        stop
          endif

          if ( alloc_st2 /= 0 ) then ! If ndbc is not successfully allocated 
                write(*,*)'gbem_lap_input: Allocate array "ndbc" failed with Status=',alloc_st2
	        stop
          endif
     endif


    allocate(belt(mx_nd_elt,nbelt),STAT=alloc_st)
     if ( alloc_st == 0 ) then ! If belt is successfully allocated 
!*** Read the connectivity of each boundary element
          loop1: do i=1,nbelt ! Loop over boundary elements
             read(55,*) belt(1,i),belt(2,i),belt(3,i) ! element connectivity of the i-th boundary element
          enddo loop1
     else
          write(*,*)'gbem_lap_input: Allocate array "belt" failed with Status=',alloc_st
	  stop
     endif

close (unit=55, status='keep')

!----------------------------------------------------------------------------------------------------------------------------------!
END SUBROUTINE gbem_lap_input
!----------------------------------------------------------------------------------------------------------------------------------!
