sGrid_init Subroutine

private subroutine sGrid_init(sf, nElems_in, grid_type_in, sp_in)

Uses

  • proc~~sgrid_init~~UsesGraph proc~sgrid_init t_sGrid%sGrid_init module~modgvec_globals MODgvec_Globals proc~sgrid_init->module~modgvec_globals iso_fortran_env iso_fortran_env module~modgvec_globals->iso_fortran_env

initialize the type sgrid with number of elements

Type Bound

t_sGrid

Arguments

Type IntentOptional 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.


Calls

proc~~sgrid_init~~CallsGraph proc~sgrid_init t_sGrid%sGrid_init proc~sgrid_test sGrid_test proc~sgrid_init->proc~sgrid_test swrite swrite proc~sgrid_init->swrite proc~sgrid_test->proc~sgrid_init proc~sgrid_test->swrite proc~sgrid_compare t_sGrid%sGrid_compare proc~sgrid_test->proc~sgrid_compare proc~sgrid_find_elem t_sGrid%sGrid_find_elem proc~sgrid_test->proc~sgrid_find_elem

Called by

proc~~sgrid_init~~CalledByGraph proc~sgrid_init t_sGrid%sGrid_init proc~sgrid_test sGrid_test proc~sgrid_init->proc~sgrid_test proc~initmhd3d t_functional_mhd3d%InitMHD3D proc~initmhd3d->proc~sgrid_init proc~readstatefilefromascii ReadStateFileFromASCII proc~readstatefilefromascii->proc~sgrid_init proc~sgrid_copy t_sGrid%sGrid_copy proc~sgrid_copy->proc~sgrid_init proc~sgrid_test->proc~sgrid_init interface~readstate ReadState interface~readstate->proc~readstatefilefromascii proc~transform_sfl_new transform_sfl_new proc~transform_sfl_new->proc~sgrid_copy proc~init_gvec_to_jorek init_gvec_to_jorek proc~init_gvec_to_jorek->interface~readstate proc~restartfromstate RestartFromState proc~restartfromstate->interface~readstate

Source Code

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