amun-code/src/forcing.F90

239 lines
5.9 KiB
Fortran
Raw Normal View History

!!******************************************************************************
!!
!! This file is part of the AMUN source code, a program to perform
!! Newtonian or relativistic magnetohydrodynamical simulations on uniform or
!! adaptive mesh.
!!
!! Copyright (C) 2017 Grzegorz Kowal <grzegorz@amuncode.org>
!!
!! This program is free software: you can redistribute it and/or modify
!! it under the terms of the GNU General Public License as published by
!! the Free Software Foundation, either version 3 of the License, or
!! (at your option) any later version.
!!
!! This program is distributed in the hope that it will be useful,
!! but WITHOUT ANY WARRANTY; without even the implied warranty of
!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!! GNU General Public License for more details.
!!
!! You should have received a copy of the GNU General Public License
!! along with this program. If not, see <http://www.gnu.org/licenses/>.
!!
!!*****************************************************************************
!!
!! module: FORCING
!!
!! This module provides energy injection, e.g. turbulence driving, supernova
!! explosions, etc.
!!
!!*****************************************************************************
!
module forcing
#ifdef PROFILE
! import external subroutines
!
use timers, only : set_timer, start_timer, stop_timer
#endif /* PROFILE */
! module variables are not implicit by default
!
implicit none
#ifdef PROFILE
! timer indices
!
integer, save :: ifi, ifu
#endif /* PROFILE */
! flag indicating if the energy injection is enabled
!
logical, save :: forcing_enabled = .false.
! by default everything is private
!
private
! declare public subroutines
!
public :: initialize_forcing, finalize_forcing
public :: update_forcing
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!
contains
!
!===============================================================================
!!
!!*** PUBLIC SUBROUTINES *****************************************************
!!
!===============================================================================
!
!===============================================================================
!
! subroutine INITIALIZE_FORCING:
! -----------------------------
!
! Subroutine initializes module FORCING.
!
! Arguments:
!
! verbose - flag determining if the subroutine should be verbose;
! iret - return flag of the procedure execution status;
!
!===============================================================================
!
subroutine initialize_forcing(verbose, iret)
! import external procedures and variables
!
use parameters, only : get_parameter_string
! local variables are not implicit by default
!
implicit none
! subroutine arguments
!
logical, intent(in) :: verbose
integer, intent(inout) :: iret
! local variables
!
character(len=64) :: injection_method = "none"
!
!-------------------------------------------------------------------------------
!
#ifdef PROFILE
! set timer descriptions
!
call set_timer('forcing:: initialization', ifi)
call set_timer('forcing:: update' , ifu)
! start accounting time for initialization/finalization
!
call start_timer(ifi)
#endif /* PROFILE */
! obtain the chosen injection method
!
call get_parameter_string("injection_method", injection_method)
! select the energy injection method
!
select case(trim(injection_method))
case default
injection_method = "none"
end select
! print information about the energy injection
!
if (verbose) then
write (*,"(4x,a16, 7x,'=',1x,a)") "energy injection" &
, trim(injection_method)
end if
#ifdef PROFILE
! stop accounting time
!
call stop_timer(ifi)
#endif /* PROFILE */
!-------------------------------------------------------------------------------
!
end subroutine initialize_forcing
!
!===============================================================================
!
! subroutine FINALIZE_FORCING:
! ---------------------------
!
! Subroutine releases memory used by the module variables.
!
! Arguments:
!
! iret - return flag of the procedure execution status;
!
!===============================================================================
!
subroutine finalize_forcing(iret)
! local variables are not implicit by default
!
implicit none
! subroutine arguments
!
integer, intent(inout) :: iret
!
!-------------------------------------------------------------------------------
!
#ifdef PROFILE
! start accounting time for initialization/finalization
!
call start_timer(ifi)
#endif /* PROFILE */
#ifdef PROFILE
! stop accounting time
!
call stop_timer(ifi)
#endif /* PROFILE */
!-------------------------------------------------------------------------------
!
end subroutine finalize_forcing
!
!===============================================================================
!
! subroutine UPDATE_FORCING:
! -------------------------
!
! Subroutine adds the energy injection terms.
!
! Arguments:
!
! t, dt - time and its increment;
!
!===============================================================================
!
subroutine update_forcing(t, dt)
! local variables are not implicit by default
!
implicit none
! subroutine arguments
!
real(kind=8), intent(in) :: t, dt
!
!-------------------------------------------------------------------------------
!
#ifdef PROFILE
! start accounting time for forcing term update
!
call start_timer(ifu)
#endif /* PROFILE */
! proceed only if forcing is enabled
!
if (forcing_enabled) then
end if ! forcing enabled
#ifdef PROFILE
! stop accounting time
!
call stop_timer(ifu)
#endif /* PROFILE */
!-------------------------------------------------------------------------------
!
end subroutine update_forcing
!===============================================================================
!
end module forcing