tem_varSys_append_operVar Subroutine

public subroutine tem_varSys_append_operVar(operVar, varSys, pos, solverData_evalElem)

subroutine to add the variables from the input lua script to the varsys

If not satisfied then it is not possible to append current variable to varSys

Arguments

Type IntentOptional Attributes Name
type(tem_variable_type), intent(in) :: operVar

variables defined in the lua file

type(tem_varSys_type), intent(inout) :: varSys

global variable system to which operVar to be appended

integer, intent(out), optional :: pos

Position of the variable in the system.

type(tem_varSys_solverData_evalElem_type), intent(in), optional :: solverData_evalElem

A setter routine that allows the caller to define routine for the construction of an element representation.


Calls

proc~~tem_varsys_append_opervar~~CallsGraph proc~tem_varsys_append_opervar tem_varSys_append_operVar proc~check_opvar_prerequisites check_opVar_prerequisites proc~tem_varsys_append_opervar->proc~check_opvar_prerequisites proc~tem_get_new_varsys_data_ptr tem_get_new_varSys_data_ptr proc~tem_varsys_append_opervar->proc~tem_get_new_varsys_data_ptr proc~tem_varsys_append_dervar tem_varSys_append_derVar proc~tem_varsys_append_opervar->proc~tem_varsys_append_dervar interface~positionofval~5 positionofval proc~check_opvar_prerequisites->interface~positionofval~5 proc~tem_abort tem_abort proc~check_opvar_prerequisites->proc~tem_abort interface~append~29 append proc~tem_varsys_append_dervar->interface~append~29 proc~tem_varsys_append_dervar->interface~positionofval~5 proc~append_da_label append_da_label interface~append~29->proc~append_da_label proc~append_da_veclabel append_da_veclabel interface~append~29->proc~append_da_veclabel proc~posofval_label posofval_label interface~positionofval~5->proc~posofval_label mpi_abort mpi_abort proc~tem_abort->mpi_abort interface~expand~27 expand proc~append_da_label->interface~expand~27 interface~sortedposofval~5 sortedposofval proc~append_da_label->interface~sortedposofval~5 proc~append_da_veclabel->interface~expand~27 proc~posofval_label->interface~sortedposofval~5

Called by

proc~~tem_varsys_append_opervar~~CalledByGraph proc~tem_varsys_append_opervar tem_varSys_append_operVar proc~tem_varsys_append_luavar tem_varSys_append_luaVar proc~tem_varsys_append_luavar->proc~tem_varsys_append_opervar

Source Code

  subroutine tem_varSys_append_operVar( operVar, varSys, pos,     &
    &                                   solverData_evalElem       )
    !--------------------------------------------------------------------------
    !> variables defined in the lua file
    type(tem_variable_type), intent(in)           :: operVar

    !> global variable system to which operVar to be appended
    type(tem_varSys_type), intent(inout)            :: varSys

    !> Position of the variable in the system.
    integer, optional, intent(out) :: pos

    !> A setter routine that allows the caller to define routine for the
    !! construction of an element representation.
    type(tem_varSys_solverData_evalElem_type), &
      &  optional, intent(in) :: solverData_evalElem
    !--------------------------------------------------------------------------
    integer :: addedPos
    integer :: nComps, nInputs
    integer, allocatable :: inPos(:)
    logical :: wasAdded
    character(len=labelLen), allocatable :: input_varname(:)
    integer, allocatable :: input_varIndex(:)
    logical :: isSatisfied
    procedure(tem_varSys_proc_point), pointer :: get_point => NULL()
    procedure(tem_varSys_proc_element), pointer :: get_element => NULL()
    procedure(tem_varSys_proc_setParams), pointer :: set_params => NULL()
    procedure(tem_varSys_proc_getParams), pointer :: get_params => NULL()
    procedure(tem_varSys_proc_setupIndices), pointer :: &
      &                                      setup_indices => NULL()
    procedure(tem_varSys_proc_getValOfIndex), pointer :: &
      &                                       get_valOfIndex => NULL()
    type(c_ptr) ::  method_data
    type(tem_varSys_op_data_type), pointer :: opData
    !--------------------------------------------------------------------------
    nullify(get_point, get_element, set_params, get_params, setup_indices, &
      &     get_valOfIndex)

    nComps = operVar%nComponents

    nInputs = size(operVar%input_varname)
    allocate(input_varname(nInputs))
    input_varname = operVar%input_varname

    ! check if input_varnames satisfy requirements for operType
    ! and correct user defined nComps if it does not match operType
    call check_opVar_prerequisites( operType      = operVar%operType, &
      &                             nInputs       = nInputs,          &
      &                             input_varname = input_varname,    &
      &                             varSys        = varSys,           &
      &                             nComps        = nComps,           &
      &                             isSatisfied   = isSatisfied       )

    !> If not satisfied then it is not possible to append current variable
    !! to varSys
    if (.not. isSatisfied) then
      write(logUnit(1),*) 'WARNING: input varnames does not satisfy'
      write(logUnit(1),*) '         requirements for operType '&
        &               //trim(operVar%operType)
      write(logUnit(1),*) 'Variable: "'//trim(operVar%label) &
        &              //'" is not appended.'
      return
    end if

    ! for operation variables, set_params, get_params and setup_indices are same
    ! since they send information to depend variables
    set_params => tem_opVar_setParams
    get_params => tem_opVar_getParams
    setup_indices => tem_opVar_setupIndices
    ! Get method data container to store indices for getValOfIndex
    ! Overwrite this method data with solver method data if operation
    ! is solver-specific
    method_data = tem_get_new_varSys_data_ptr()
    call C_F_POINTER(method_data, opData)

    select case(trim(operVar%operType))
    ! magnitude, division, multiplication are solver specific
    ! so set using getEvalFuncionsCallback
    case( 'difference' )
      get_element => tem_evalDiff_forElement
      get_point => tem_evalDiff_forPoint
      get_valOfIndex => tem_evalDiff_fromIndex

    case( 'rel_difference' )
      get_element => evalRelDiff_forElement
      get_point => evalRelDiff_forPoint
      get_valOfIndex => evalRelDiff_fromIndex

    case( 'addition' )
      get_element => tem_evalAdd_forElement
      get_point => tem_evalAdd_forPoint
      get_valOfIndex => tem_evalAdd_fromIndex

    case ('multiplication')
      get_point => tem_evalMultiply_forPoint
      get_element => tem_evalMultiply_forElement
      get_valOfindex => tem_evalMultiply_fromIndex

    case( 'multiply_scalar_times_vector' )
      get_point => tem_multiplyScalTimesVec_forPoint
      get_element => multiplyScalTimesVec_forElement
      get_valOfindex => tem_multiplyScalTimesVec_fromIndex

    case( 'division', 'div' )
      get_point => tem_division_forPoint
      get_element => tem_division_forElement
      get_valOfindex => tem_division_fromIndex

    case( 'divide_vector_by_scalar' )
      get_point => tem_divideVecByScal_forPoint
      get_element => divideVecByScal_forElement
      get_valOfindex => tem_divideVecByScal_fromIndex

    case( 'gradient', 'grad', 'gradientX', 'gradX','gradientY','gradY', &
      &   'gradientZ', 'gradZ'                                          )
    ! Pointers set by the solvers using opVar_setter callback, see below

    case( 'magnitude' )
      get_point => tem_evalMag_forPoint
      get_element => tem_evalMag_forElement
      get_valOfindex => tem_evalMag_fromIndex

    case( 'extract' )
      allocate( input_varIndex(size(operVar%input_varIndex)) )
      input_varIndex = operVar%input_varIndex

      get_element => extract_forElement
      get_point => extract_forPoint
      get_valOfIndex => extract_fromIndex

    case( 'combine' )
      get_element => combine_forElement
      get_point => combine_forPoint
      get_valOfIndex => combine_fromIndex

    case( 'greater_than', 'gt', '>' )
      get_point => evalLogicalGreater_forPoint
      get_element => evalLogicalGreater_forElement
      get_valOfIndex => evalLogicalGreater_fromIndex

    case( 'greater_than_or_equal', 'ge', '>=' )
      get_point => evalLogicalGreaterOrEqual_forPoint
      get_element => evalLogicalGreaterOrEqual_forElement
      get_valOfIndex => evalLogicalGreaterOrEqual_fromIndex

    case( 'less_than', 'lt', '<' )
      get_point => evalLogicalLess_forPoint
      get_element => evalLogicalLess_forElement
      get_valOfIndex => evalLogicalLess_fromIndex

    case( 'less_than_or_equal', 'le', '<=' )
      get_point => evalLogicalLessOrEqual_forPoint
      get_Element => evalLogicalLessOrEqual_forElement
      get_valOfIndex => evalLogicalLessOrEqual_fromIndex

    case( 'equal', 'eq', '=' )
      get_point => evalLogicalEqual_forPoint
      get_Element => evalLogicalEqual_forElement
      get_valOfIndex => evalLogicalEqual_fromIndex

    case( 'not_equal', 'ne', '/=' )
      get_point => evalLogicalNotEqual_forPoint
      get_Element => evalLogicalNotEqual_forElement
      get_valOfIndex => evalLogicalNotEqual_fromIndex

    case( 'and' )
      get_point => evalLogicalAnd_forPoint
      get_Element => evalLogicalAnd_forElement
      get_valOfIndex => evalLogicalAnd_fromIndex

    case( 'or' )
      get_point => evalLogicalOr_forPoint
      get_Element => evalLogicalOr_forElement
      get_valOfIndex => evalLogicalOr_fromIndex

    case('reduction_transient')
      opData%redTrans%config = operVar%redTransConfig
      get_point => reductionTransient_forPoint
      get_Element => reductionTransient_forElement
      get_valOfIndex => reductionTransient_fromIndex

    case default
      if (.not. (associated(get_point)      &
        &   .or. associated(get_element)    &
        &   .or. associated(set_params)     &
        &   .or. associated(get_params)     &
        &   .or. associated(setup_indices)  &
        &   .or. associated(get_valOfIndex))) then
        write(logUnit(3),*) 'operType: '                 &
          & // trim(operVar%operType)                    &
          & // ' not supported. Variable is not appended.'
        return ! go to next variable
      end if
    end select

    ! Workaround for Intel 15 compiler
    if ( .not. allocated(input_varname) ) then
      allocate( input_varname(0) )
    end if

    if ( .not. allocated(input_varIndex) ) then
      allocate( input_varIndex(0) )
    end if

    ! append variable to varSys
    call tem_varSys_append_derVar(          &
      &  me             = varSys,           &
      &  varName        = operVar%label,    &
      &  operType       = operVar%operType, &
      &  nComponents    = nComps,           &
      &  input_varname  = input_varname,    &
      &  input_varIndex = input_varIndex,   &
      &  method_data    = method_data,      &
      &  get_point      = get_point,        &
      &  get_element    = get_element,      &
      &  set_params     = set_params,       &
      &  get_params     = get_params,       &
      &  setup_indices  = setup_indices,    &
      &  get_valOfIndex = get_valOfIndex,   &
      &  pos            = addedPos,         &
      &  wasAdded       = wasAdded          )

    if (wasAdded) then
      if (present(solverData_evalElem)) then
        ! If an solverData_evalElem operation is provided, override the
        ! get_element pointer and use the provided setter solverData_evalElem
        ! instead to define the get_element routine.
        call solverData_evalElem%opVar_setter(varSys%method%val(addedPos))
      end if
      write(logUnit(9),*) 'Successfully appended variable "' &
        & // trim(operVar%label)// '" to the variable system'
    else if (addedpos < 1) then
      write(logUnit(7),*) 'WARNING: variable '//trim(operVar%label)// &
        &                 ' is not added to variable system'
    end if

    if (present(pos)) pos = addedPos

    ! deallocate here to be allocated for next variable
    deallocate(input_varname)
    if (allocated(input_varIndex)) deallocate(input_varIndex)
    if (allocated(inPos)) deallocate(inPos)

  end subroutine tem_varSys_append_operVar