initialize the type sgrid with number of elements
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(t_sGrid), | intent(inout) | :: | sf |
self |
||
| integer, | intent(in) | :: | nElems_in |
total number of elements |
||
| integer, | intent(in) | :: | grid_type_in |
GRID_TYPE_UNIFORM, GRID_TYPE_SQRT_S, GRID_TYPE_S2, GRID_TYPE_BUMP |
||
| real(kind=wp), | intent(in), | optional | :: | sp_in(0:nElems_in) |
inner grid point positions, first position should be 0, last should be 1. |
SUBROUTINE sGrid_init( sf, nElems_in,grid_type_in,sp_in) ! MODULES USE MODgvec_GLobals, ONLY: PI,myRank, nRanks IMPLICIT NONE !----------------------------------------------------------------------------------------------------------------------------------- ! INPUT VARIABLES INTEGER , INTENT(IN ) :: nElems_in !! total number of elements INTEGER , INTENT(IN ) :: grid_type_in !! GRID_TYPE_UNIFORM, GRID_TYPE_SQRT_S, GRID_TYPE_S2, GRID_TYPE_BUMP REAL(wp),INTENT(IN),OPTIONAL :: sp_in(0:nElems_in) !! inner grid point positions, first position should be 0, last should be 1. !----------------------------------------------------------------------------------------------------------------------------------- ! OUTPUT VARIABLES CLASS(t_sgrid), INTENT(INOUT) :: sf !! self !----------------------------------------------------------------------------------------------------------------------------------- ! LOCAL VARIABLES INTEGER :: iElem,iRank !=================================================================================================================================== IF(.NOT.test_called)THEN SWRITE(UNIT_stdOut,'(4X,A,I6,A,I3,A)')'INIT sGrid type nElems= ',nElems_in,' grid_type= ',grid_type_in, ' ...' END IF IF(sf%initialized) THEN SWRITE(UNIT_stdOut,'(A)')'WARNING!! reinit of sGrid type!' CALL sf%free() END IF sf%nElems = nElems_in ! MPI PSEUDO-DOMAIN DECOMPOSITION (full domain is allocated, but only part of it is actually used on the MPI task) ALLOCATE(sf%offset_elem(0:nRanks)) sf%offset_elem(0)=0 DO iRank=0,nRanks-1 sf%offset_elem(iRank+1)=(nElems_in*(iRank+1))/nRanks END DO sf%nElems_str = sf%offset_elem(myRank ) +1 sf%nElems_end = sf%offset_elem(myRank+1) IF (sf%nElems_end-sf%nElems_str+1 .EQ. 0) THEN CALL abort(__STAMP__, & 'number of MPI tasks can not be larger than nElems!') END IF sf%grid_Type = grid_type_in ALLOCATE(sf%sp(0:nElems_in)) ALLOCATE(sf%ds(1:nElems_in)) ASSOCIATE( & nElems => sf%nElems & , grid_Type => sf%grid_Type ) IF(PRESENT(sp_in))THEN IF(SIZE(sp_in) .NE. nElems+1) THEN CALL abort(__STAMP__, & 'sGrid_init: size of sp_in does not match nElems + 1!') END IF IF(ABS(sp_in(0)).GT.EPSILON(1.0_wp) .OR. & ABS(sp_in(nElems)-1.0_wp).GT.EPSILON(1.0_wp)) THEN CALL abort(__STAMP__, & 'sGrid_init: sp_in(0) and sp_in(nElems) should be 0 and 1!') END IF sf%sp=sp_in ELSE !uniform [0,1] DO iElem=0,nElems sf%sp(iElem)=REAL(iElem,wp)/REAL(nElems,wp) END DO SELECT CASE(grid_type) CASE(GRID_TYPE_UNIFORM) !do nothing CASE(GRID_TYPE_SQRT_S) !finer at the edge sf%sp(:)=SQRT(sf%sp(:)) CASE(GRID_TYPE_S2) !finer at the center sf%sp(:)=sf%sp(:)*sf%sp(:) CASE(GRID_TYPE_BUMP) !finer towards axis and edge sf%sp(:)=sf%sp(:)-0.05_wp*SIN(PI*2.0_wp*sf%sp(:)) CASE(GRID_TYPE_BUMP_EDGE) ! more equidistnat at the axis and finer towards edge sf%sp(:)=(sf%sp(:)-0.75_wp*((sf%sp(:)-0.4_wp)**3 + 0.4_wp**3))/(1.0_wp-0.75_wp*((1.0_wp-0.4_wp)**3+0.4**3)) CASE DEFAULT CALL abort(__STAMP__, & 'given grid type does not exist') END SELECT END IF!PRESENT(sp_in) !compute delta s DO iElem=1,nElems sf%ds(iElem)=sf%sp(iElem)-sf%sp(iElem-1) END DO END ASSOCIATE !sf sf%initialized=.TRUE. IF(.NOT.test_called)THEN SWRITE(UNIT_stdOut,'(4X,A)')'... DONE' CALL sGrid_test(sf) END IF END SUBROUTINE sGrid_init