2010-10-13 03:32:10 -03:00
|
|
|
!!******************************************************************************
|
2008-12-07 18:57:08 -06:00
|
|
|
!!
|
2011-05-05 18:37:53 -03:00
|
|
|
!! module: EVOLUTION - handling the time evolution of the block structure
|
2008-12-07 18:57:08 -06:00
|
|
|
!!
|
2011-05-05 18:37:53 -03:00
|
|
|
!! Copyright (C) 2008-2011 Grzegorz Kowal <grzegorz@amuncode.org>
|
2008-12-07 18:57:08 -06:00
|
|
|
!!
|
2010-10-13 03:32:10 -03:00
|
|
|
!!******************************************************************************
|
2008-12-07 18:57:08 -06:00
|
|
|
!!
|
2011-05-05 18:37:53 -03:00
|
|
|
!! This file is part of the AMUN code.
|
2008-12-07 18:57:08 -06:00
|
|
|
!!
|
2011-04-29 11:21:30 -03:00
|
|
|
!! 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 2
|
|
|
|
!! of the License, or (at your option) any later version.
|
2008-12-07 18:57:08 -06:00
|
|
|
!!
|
2011-04-29 11:21:30 -03:00
|
|
|
!! This program is distributed in the hope that it will be useful,
|
2008-12-07 18:57:08 -06:00
|
|
|
!! 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
|
2011-04-29 11:21:30 -03:00
|
|
|
!! along with this program; if not, write to the Free Software Foundation,
|
|
|
|
!! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-07 18:57:08 -06:00
|
|
|
!!
|
2010-10-13 03:32:10 -03:00
|
|
|
!!******************************************************************************
|
2008-12-07 18:57:08 -06:00
|
|
|
!!
|
|
|
|
!
|
|
|
|
module evolution
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
integer, save :: n
|
2010-12-01 13:13:27 -02:00
|
|
|
real , save :: t, dt, dtn
|
2008-12-07 18:57:08 -06:00
|
|
|
|
|
|
|
contains
|
|
|
|
!
|
2008-12-08 21:07:10 -06:00
|
|
|
!===============================================================================
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
2008-12-08 21:07:10 -06:00
|
|
|
! evolve: subroutine sweeps over all leaf blocks and performs one step time
|
|
|
|
! evolution for each according to the selected integration scheme
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
2008-12-08 21:07:10 -06:00
|
|
|
!===============================================================================
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
2010-12-01 15:14:07 -02:00
|
|
|
subroutine evolve()
|
2008-12-07 18:57:08 -06:00
|
|
|
|
2010-12-08 18:19:16 -02:00
|
|
|
use blocks , only : block_data, list_data
|
|
|
|
use boundaries, only : boundary_variables
|
2011-04-30 15:10:02 -03:00
|
|
|
#ifdef CONSERVATIVE
|
|
|
|
use boundaries, only : boundary_correct_fluxes
|
|
|
|
#endif /* CONSERVATIVE */
|
2011-04-26 12:37:25 -03:00
|
|
|
#ifdef REFINE
|
|
|
|
use config , only : maxlev
|
|
|
|
#endif /* REFINE */
|
2011-03-18 15:33:24 -03:00
|
|
|
#ifdef VISCOSITY
|
|
|
|
use config , only : visc
|
|
|
|
#endif /* VISCOSITY */
|
2011-03-22 17:24:28 -03:00
|
|
|
#if defined MHD && defined RESISTIVITY
|
2010-12-14 17:29:38 -02:00
|
|
|
use config , only : ueta
|
2011-03-22 17:24:28 -03:00
|
|
|
#endif /* MHD & RESISTIVITY */
|
2010-12-08 18:19:16 -02:00
|
|
|
#ifdef FORCE
|
2011-03-07 00:08:31 -03:00
|
|
|
use forcing , only : fourier_transform, evolve_forcing
|
2010-12-08 18:19:16 -02:00
|
|
|
#endif /* FORCE */
|
|
|
|
use mesh , only : update_mesh
|
|
|
|
use mesh , only : dx_min
|
|
|
|
use scheme , only : cmax
|
2011-05-03 00:01:00 -03:00
|
|
|
use timer , only : start_timer, stop_timer
|
2011-03-07 00:08:31 -03:00
|
|
|
use variables , only : idn, imz
|
2008-12-07 18:57:08 -06:00
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! local variables
|
|
|
|
!
|
2009-09-14 18:28:17 -03:00
|
|
|
type(block_data), pointer :: pblock
|
2010-12-01 10:39:18 -02:00
|
|
|
real :: cm
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
2008-12-08 21:07:10 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
2011-05-03 00:01:00 -03:00
|
|
|
! start the evolution timer
|
|
|
|
!
|
|
|
|
call start_timer(2)
|
|
|
|
|
2010-12-08 18:19:16 -02:00
|
|
|
#ifdef FORCE
|
2011-03-07 00:08:31 -03:00
|
|
|
! perform the Fourier transform of the velocity field
|
|
|
|
!
|
|
|
|
pblock => list_data
|
|
|
|
do while (associated(pblock))
|
|
|
|
|
|
|
|
if (pblock%meta%leaf) &
|
|
|
|
call fourier_transform(pblock%meta%level &
|
|
|
|
, pblock%meta%xmin, pblock%meta%ymin, pblock%meta%zmin &
|
|
|
|
, pblock%u(idn:imz,:,:,:))
|
|
|
|
|
|
|
|
pblock => pblock%next ! assign pointer to the next block
|
|
|
|
|
|
|
|
end do
|
|
|
|
|
2010-12-08 18:19:16 -02:00
|
|
|
! evolve the forcing source terms by the time interval dt
|
|
|
|
!
|
|
|
|
call evolve_forcing(dt)
|
|
|
|
#endif /* FORCE */
|
|
|
|
|
2009-09-14 18:28:17 -03:00
|
|
|
! iterate over all data blocks and perform one step of time evolution
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
2009-09-14 18:28:17 -03:00
|
|
|
pblock => list_data
|
2008-12-09 14:51:33 -06:00
|
|
|
do while (associated(pblock))
|
2008-12-07 18:57:08 -06:00
|
|
|
|
|
|
|
! check if this block is a leaf
|
|
|
|
!
|
2011-04-30 12:28:02 -03:00
|
|
|
#ifdef CONSERVATIVE
|
2011-04-30 12:53:17 -03:00
|
|
|
if (pblock%meta%leaf) &
|
|
|
|
#ifdef EULER
|
|
|
|
call flux_euler(pblock)
|
|
|
|
#endif /* EULER */
|
2011-05-01 08:57:14 -03:00
|
|
|
#ifdef RK2
|
|
|
|
call flux_rk2(pblock)
|
|
|
|
#endif /* RK2 */
|
2011-05-01 10:31:27 -03:00
|
|
|
#ifdef RK3
|
|
|
|
call flux_rk3(pblock)
|
|
|
|
#endif /* RK3 */
|
2011-04-30 12:28:02 -03:00
|
|
|
#else /* CONSERVATIVE */
|
2009-09-14 18:28:17 -03:00
|
|
|
if (pblock%meta%leaf) &
|
2008-12-09 21:06:21 -06:00
|
|
|
#ifdef EULER
|
|
|
|
call evolve_euler(pblock)
|
|
|
|
#endif /* EULER */
|
2008-12-08 16:21:59 -06:00
|
|
|
#ifdef RK2
|
2008-12-09 14:51:33 -06:00
|
|
|
call evolve_rk2(pblock)
|
2008-12-08 16:21:59 -06:00
|
|
|
#endif /* RK2 */
|
2010-12-03 15:38:48 -02:00
|
|
|
#ifdef RK3
|
|
|
|
call evolve_rk3(pblock)
|
|
|
|
#endif /* RK3 */
|
2011-04-30 12:28:02 -03:00
|
|
|
#endif /* CONSERVATIVE */
|
2008-12-07 18:57:08 -06:00
|
|
|
|
|
|
|
! assign pointer to the next block
|
|
|
|
!
|
2008-12-09 14:51:33 -06:00
|
|
|
pblock => pblock%next
|
2008-12-07 18:57:08 -06:00
|
|
|
|
2008-12-09 14:51:33 -06:00
|
|
|
end do
|
2008-12-07 18:57:08 -06:00
|
|
|
|
2011-04-30 13:14:07 -03:00
|
|
|
#ifdef CONSERVATIVE
|
2011-04-30 15:10:02 -03:00
|
|
|
! correct the numerical fluxes between neighboring blocks which are at different
|
|
|
|
! levels
|
|
|
|
!
|
2011-05-01 10:44:31 -03:00
|
|
|
call boundary_correct_fluxes()
|
2011-04-30 15:10:02 -03:00
|
|
|
|
2011-04-30 13:14:07 -03:00
|
|
|
! update solution using numerical fluxes stored in data blocks
|
|
|
|
!
|
|
|
|
pblock => list_data
|
|
|
|
do while (associated(pblock))
|
|
|
|
|
|
|
|
! check if this block is a leaf and update its conserved variables using
|
|
|
|
! corrected numerical fluxes
|
|
|
|
!
|
|
|
|
if (pblock%meta%leaf) call update_solution(pblock)
|
|
|
|
|
|
|
|
! assign pointer to the next block
|
|
|
|
!
|
|
|
|
pblock => pblock%next
|
|
|
|
|
|
|
|
end do
|
|
|
|
|
|
|
|
#endif /* CONSERVATIVE */
|
2008-12-09 20:37:31 -06:00
|
|
|
! update boundaries
|
2008-12-08 12:14:13 -06:00
|
|
|
!
|
2010-12-01 15:14:07 -02:00
|
|
|
call boundary_variables()
|
2008-12-08 12:14:13 -06:00
|
|
|
|
2011-03-10 01:08:00 -03:00
|
|
|
#ifdef REFINE
|
2011-04-26 12:37:25 -03:00
|
|
|
! chec if we need to perform the refinement step
|
|
|
|
!
|
|
|
|
if (maxlev .gt. 1) then
|
|
|
|
|
2010-03-14 15:40:24 -03:00
|
|
|
! check refinement and refine
|
|
|
|
!
|
2011-04-26 12:37:25 -03:00
|
|
|
call update_mesh()
|
2010-03-14 15:40:24 -03:00
|
|
|
|
|
|
|
! update boundaries
|
|
|
|
!
|
2011-04-26 12:37:25 -03:00
|
|
|
call boundary_variables()
|
|
|
|
|
|
|
|
end if ! maxlev > 1
|
2011-03-10 01:08:00 -03:00
|
|
|
#endif /* REFINE */
|
2011-05-03 00:01:00 -03:00
|
|
|
|
2010-12-01 10:39:18 -02:00
|
|
|
! update the maximum speed
|
2008-12-09 14:51:33 -06:00
|
|
|
!
|
2010-12-01 10:39:18 -02:00
|
|
|
call update_maximum_speed()
|
|
|
|
|
|
|
|
! get maximum time step
|
|
|
|
!
|
|
|
|
dtn = dx_min / max(cmax, 1.0d-16)
|
2011-03-18 15:33:24 -03:00
|
|
|
#ifdef VISCOSITY
|
|
|
|
dtn = min(dtn, 0.5d0 * dx_min * dx_min / max(1.0d-16, visc))
|
|
|
|
#endif /* VISCOSITY */
|
2011-03-22 17:24:28 -03:00
|
|
|
#if defined MHD && defined RESISTIVITY
|
2010-12-14 17:29:38 -02:00
|
|
|
dtn = min(dtn, 0.5d0 * dx_min * dx_min / max(1.0d-16, ueta))
|
2011-03-22 17:24:28 -03:00
|
|
|
#endif /* MHD & RESISTIVITY */
|
2011-05-03 00:01:00 -03:00
|
|
|
|
|
|
|
! stop the evolution timer
|
|
|
|
!
|
|
|
|
call stop_timer(2)
|
2010-12-01 10:39:18 -02:00
|
|
|
!
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine evolve
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! update_maximum_speed: subroutine updates module variable cmax with the value
|
|
|
|
! corresponding to the maximum speed in the system
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
subroutine update_maximum_speed()
|
|
|
|
|
2010-12-03 18:02:07 -02:00
|
|
|
use blocks , only : block_data, list_data
|
|
|
|
#ifdef MPI
|
|
|
|
use mpitools, only : mallreducemaxr
|
|
|
|
#endif /* MPI */
|
|
|
|
use scheme , only : maxspeed, cmax
|
2011-05-03 00:01:00 -03:00
|
|
|
use timer , only : start_timer, stop_timer
|
2010-12-01 10:39:18 -02:00
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! local variables
|
|
|
|
!
|
|
|
|
type(block_data), pointer :: pblock
|
|
|
|
real :: cm
|
|
|
|
!
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2011-05-03 00:01:00 -03:00
|
|
|
! start the evolution timer
|
|
|
|
!
|
|
|
|
call start_timer(6)
|
|
|
|
|
2010-12-01 10:39:18 -02:00
|
|
|
! reset the maximum speed
|
|
|
|
!
|
|
|
|
cmax = 1.0d-16
|
2008-12-09 14:51:33 -06:00
|
|
|
|
|
|
|
! iterate over all blocks in order to find the maximum speed
|
|
|
|
!
|
2009-09-14 18:28:17 -03:00
|
|
|
pblock => list_data
|
2008-12-09 14:51:33 -06:00
|
|
|
do while (associated(pblock))
|
|
|
|
|
|
|
|
! check if this block is a leaf
|
|
|
|
!
|
2009-09-14 18:28:17 -03:00
|
|
|
if (pblock%meta%leaf) &
|
2008-12-09 14:51:33 -06:00
|
|
|
cm = maxspeed(pblock%u)
|
|
|
|
|
|
|
|
! compare global and local maximum speeds
|
|
|
|
!
|
|
|
|
cmax = max(cmax, cm)
|
|
|
|
|
|
|
|
! assign pointer to the next block
|
|
|
|
!
|
|
|
|
pblock => pblock%next
|
|
|
|
|
|
|
|
end do
|
2010-12-03 18:02:07 -02:00
|
|
|
|
|
|
|
#ifdef MPI
|
|
|
|
! reduce the maximum speed over all processes
|
|
|
|
!
|
|
|
|
call mallreducemaxr(cmax)
|
|
|
|
#endif /* MPI */
|
2011-05-03 00:01:00 -03:00
|
|
|
|
|
|
|
! stop the evolution timer
|
|
|
|
!
|
|
|
|
call stop_timer(6)
|
2010-02-28 18:35:57 -03:00
|
|
|
!
|
2008-12-08 21:07:10 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
2010-12-01 10:39:18 -02:00
|
|
|
end subroutine update_maximum_speed
|
2011-04-30 12:28:02 -03:00
|
|
|
#ifdef CONSERVATIVE
|
2011-04-30 13:14:07 -03:00
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! update_solution: subroutine performs an one step update of the conserved
|
|
|
|
! variables for the given data block using the integrated
|
|
|
|
! numerical fluxes stored in the same data block
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
subroutine update_solution(pblock)
|
|
|
|
|
|
|
|
use blocks , only : block_data
|
|
|
|
use config , only : im, jm, km
|
|
|
|
use mesh , only : adxi, adyi, adzi
|
2011-05-01 09:44:19 -03:00
|
|
|
#if defined MHD && defined GLM
|
|
|
|
use config , only : alpha_p
|
|
|
|
use mesh , only : dx_min
|
|
|
|
use scheme , only : cmax
|
|
|
|
use variables, only : iph
|
|
|
|
#endif /* MHD & GLM */
|
2011-05-01 09:24:11 -03:00
|
|
|
#ifdef FORCE
|
2011-05-01 09:44:19 -03:00
|
|
|
use forcing , only : real_forcing
|
2011-05-01 09:24:11 -03:00
|
|
|
use variables, only : inx, iny, inz
|
|
|
|
use variables, only : idn, imx, imy, imz
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
use variables, only : ien
|
|
|
|
#endif /* ADI */
|
2011-05-01 09:24:11 -03:00
|
|
|
#endif /* FORCE */
|
2011-04-30 13:14:07 -03:00
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! input arguments
|
|
|
|
!
|
|
|
|
type(block_data), intent(inout) :: pblock
|
|
|
|
|
2011-05-01 08:57:14 -03:00
|
|
|
! local variables
|
|
|
|
!
|
|
|
|
real :: dxi, dyi, dzi
|
2011-05-01 09:44:19 -03:00
|
|
|
#if defined MHD && defined GLM
|
|
|
|
real :: decay
|
|
|
|
#endif /* MHD & GLM */
|
2011-05-01 09:24:11 -03:00
|
|
|
#ifdef FORCE
|
|
|
|
|
|
|
|
! local arrays
|
|
|
|
!
|
|
|
|
real, dimension( 3,im,jm,km) :: f
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
real, dimension( im,jm,km) :: ek, dek
|
|
|
|
#endif /* ADI */
|
2011-05-01 09:24:11 -03:00
|
|
|
#endif /* FORCE */
|
2011-05-01 08:57:14 -03:00
|
|
|
!
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
! prepare dxi, dyi, and dzi
|
|
|
|
!
|
|
|
|
dxi = adxi(pblock%meta%level)
|
|
|
|
dyi = adyi(pblock%meta%level)
|
|
|
|
#if NDIMS == 3
|
|
|
|
dzi = adzi(pblock%meta%level)
|
|
|
|
#endif /* NDIMS == 3 */
|
|
|
|
|
|
|
|
! perform update of conserved variables of the given block using its fluxes
|
|
|
|
!
|
|
|
|
call advance_solution(pblock%u(:,:,:,:), pblock%f(:,:,:,:,:), dxi, dyi, dzi)
|
2011-05-01 09:44:19 -03:00
|
|
|
#if defined MHD && defined GLM
|
|
|
|
|
|
|
|
! evolve Psi due to the source term
|
|
|
|
!
|
|
|
|
decay = exp(- alpha_p * cmax * dt / dx_min)
|
|
|
|
pblock%u(iph,:,:,:) = decay * pblock%u(iph,:,:,:)
|
|
|
|
#endif /* MHD & GLM */
|
2011-05-01 09:24:11 -03:00
|
|
|
#ifdef FORCE
|
|
|
|
|
|
|
|
! obtain the forcing terms in real space
|
|
|
|
!
|
|
|
|
call real_forcing(pblock%meta%level, pblock%meta%xmin, pblock%meta%ymin &
|
|
|
|
, pblock%meta%zmin, f(:,:,:,:))
|
|
|
|
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
! calculate kinetic energy before adding the forcing term
|
|
|
|
!
|
|
|
|
ek(:,:,:) = 0.5d0 * (pblock%u(imx,:,:,:)**2 + pblock%u(imy,:,:,:)**2 &
|
|
|
|
+ pblock%u(imz,:,:,:)**2) / pblock%u(idn,:,:,:)
|
|
|
|
#endif /* ADI */
|
|
|
|
|
2011-05-01 09:24:11 -03:00
|
|
|
! update momenta due to the forcing terms
|
|
|
|
!
|
|
|
|
pblock%u(imx,:,:,:) = pblock%u(imx,:,:,:) &
|
|
|
|
+ pblock%u(idn,:,:,:) * f(inx,:,:,:)
|
|
|
|
pblock%u(imy,:,:,:) = pblock%u(imy,:,:,:) &
|
|
|
|
+ pblock%u(idn,:,:,:) * f(iny,:,:,:)
|
|
|
|
pblock%u(imz,:,:,:) = pblock%u(imz,:,:,:) &
|
|
|
|
+ pblock%u(idn,:,:,:) * f(inz,:,:,:)
|
2011-05-01 19:21:43 -03:00
|
|
|
|
|
|
|
#ifdef ADI
|
|
|
|
! calculate kinetic energy after adding the forcing term
|
|
|
|
!
|
|
|
|
dek(:,:,:) = 0.5d0 * (pblock%u(imx,:,:,:)**2 + pblock%u(imy,:,:,:)**2 &
|
|
|
|
+ pblock%u(imz,:,:,:)**2) / pblock%u(idn,:,:,:) - ek(:,:,:)
|
|
|
|
|
|
|
|
! update total energy with the injected one
|
|
|
|
!
|
|
|
|
pblock%u(ien,:,:,:) = pblock%u(ien,:,:,:) + dek(:,:,:)
|
|
|
|
#endif /* ADI */
|
2011-05-01 09:24:11 -03:00
|
|
|
#endif /* FORCE */
|
2011-05-01 08:57:14 -03:00
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine update_solution
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! advance_solution: subroutine performs an one step update of the conserved
|
|
|
|
! variables array using the numerical fluxes passed as an
|
|
|
|
! argument
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
subroutine advance_solution(u, f, dxi, dyi, dzi)
|
|
|
|
|
|
|
|
use config , only : im, jm, km
|
2011-05-01 09:44:19 -03:00
|
|
|
use variables, only : nqt, nfl
|
|
|
|
use variables, only : inx, iny, inz
|
|
|
|
#ifdef MHD
|
|
|
|
use variables, only : ibx, ibz
|
|
|
|
#ifdef GLM
|
|
|
|
use scheme , only : cmax
|
|
|
|
use variables, only : iph
|
|
|
|
#endif /* GLM */
|
|
|
|
#endif /* MHD */
|
2011-05-01 08:57:14 -03:00
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! input arguments
|
|
|
|
!
|
|
|
|
real, dimension( nqt,im,jm,km), intent(inout) :: u
|
|
|
|
real, dimension(NDIMS,nqt,im,jm,km), intent(in) :: f
|
|
|
|
real :: dxi, dyi, dzi
|
|
|
|
|
2011-04-30 13:14:07 -03:00
|
|
|
! local variables
|
|
|
|
!
|
|
|
|
integer :: i, j, k, im1, jm1, km1
|
|
|
|
real :: dhx, dhy, dhz
|
2011-05-01 09:44:19 -03:00
|
|
|
#if defined MHD && defined GLM
|
|
|
|
real :: ch2
|
|
|
|
#endif /* MHD & GLM */
|
|
|
|
|
|
|
|
! local arrays
|
|
|
|
!
|
|
|
|
real, dimension(nqt,im,jm,km) :: du
|
2011-04-30 13:14:07 -03:00
|
|
|
!
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
! prepare dxi, dyi, and dzi
|
|
|
|
!
|
2011-05-01 08:57:14 -03:00
|
|
|
dhx = dt * dxi
|
|
|
|
dhy = dt * dyi
|
2011-04-30 13:14:07 -03:00
|
|
|
#if NDIMS == 3
|
2011-05-01 08:57:14 -03:00
|
|
|
dhz = dt * dzi
|
2011-04-30 13:14:07 -03:00
|
|
|
#endif /* NDIMS == 3 */
|
|
|
|
|
2011-05-01 09:44:19 -03:00
|
|
|
! reset the increment array du
|
|
|
|
!
|
|
|
|
du(:,:,:,:) = 0.0d0
|
|
|
|
|
2011-04-30 13:14:07 -03:00
|
|
|
! perform update along the X direction
|
|
|
|
!
|
|
|
|
do i = 1, im
|
|
|
|
im1 = max(1, i - 1)
|
|
|
|
|
2011-05-01 09:44:19 -03:00
|
|
|
du(:,i,:,:) = du(:,i,:,:) + dhx * (f(inx,:,im1,:,:) - f(inx,:,i,:,:))
|
2011-04-30 13:14:07 -03:00
|
|
|
end do
|
|
|
|
|
|
|
|
! perform update along the Y direction
|
|
|
|
!
|
|
|
|
do j = 1, jm
|
|
|
|
jm1 = max(1, j - 1)
|
|
|
|
|
2011-05-01 09:44:19 -03:00
|
|
|
du(:,:,j,:) = du(:,:,j,:) + dhy * (f(iny,:,:,jm1,:) - f(iny,:,:,j,:))
|
2011-04-30 13:14:07 -03:00
|
|
|
end do
|
|
|
|
#if NDIMS == 3
|
|
|
|
|
|
|
|
! perform update along the Z direction
|
|
|
|
!
|
|
|
|
do k = 1, km
|
|
|
|
km1 = max(1, k - 1)
|
|
|
|
|
2011-05-01 09:44:19 -03:00
|
|
|
du(:,:,:,k) = du(:,:,:,k) + dhz * (f(inz,:,:,:,km1) - f(inz,:,:,:,k))
|
2011-04-30 13:14:07 -03:00
|
|
|
end do
|
|
|
|
#endif /* NDIMS == 3 */
|
|
|
|
|
2011-05-01 09:44:19 -03:00
|
|
|
! update the solution for the fluid variables
|
|
|
|
!
|
|
|
|
u( 1:nfl,:,:,:) = u( 1:nfl,:,:,:) + du( 1:nfl,:,:,:)
|
|
|
|
|
|
|
|
#ifdef MHD
|
|
|
|
! update the solution for the magnetic variables
|
|
|
|
!
|
|
|
|
u(ibx:ibz,:,:,:) = u(ibx:ibz,:,:,:) + du(ibx:ibz,:,:,:)
|
|
|
|
|
|
|
|
#ifdef GLM
|
|
|
|
! calculate c_h^2
|
|
|
|
!
|
|
|
|
ch2 = cmax * cmax
|
|
|
|
|
|
|
|
! update the solution for the scalar potential Psi
|
|
|
|
!
|
|
|
|
u(iph,:,:,:) = u(iph,:,:,:) + ch2 * du(iph,:,:,:)
|
|
|
|
#endif /* GLM */
|
|
|
|
#endif /* MHD */
|
|
|
|
|
2011-04-30 13:14:07 -03:00
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2011-05-01 08:57:14 -03:00
|
|
|
end subroutine advance_solution
|
2011-04-30 12:53:17 -03:00
|
|
|
#ifdef EULER
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! flux_euler: subroutine performs the first order integration of the numerical
|
|
|
|
! flux
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
subroutine flux_euler(pblock)
|
|
|
|
|
|
|
|
use blocks , only : block_data
|
|
|
|
use mesh , only : adxi, adyi, adzi
|
|
|
|
use scheme , only : update_flux
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! input arguments
|
|
|
|
!
|
|
|
|
type(block_data), intent(inout) :: pblock
|
|
|
|
|
|
|
|
! local variables
|
|
|
|
!
|
|
|
|
real :: dxi, dyi, dzi
|
|
|
|
!
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
! prepare dxi, dyi, and dzi
|
|
|
|
!
|
|
|
|
dxi = adxi(pblock%meta%level)
|
|
|
|
dyi = adyi(pblock%meta%level)
|
|
|
|
dzi = adzi(pblock%meta%level)
|
|
|
|
|
|
|
|
! 1st step of integration
|
|
|
|
!
|
|
|
|
call update_flux(pblock%u(:,:,:,:), pblock%f(:,:,:,:,:), dxi, dyi, dzi)
|
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine flux_euler
|
|
|
|
#endif /* EULER */
|
2011-05-01 08:57:14 -03:00
|
|
|
#ifdef RK2
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! flux_rk2: subroutine performs integration of the numerical flux using
|
|
|
|
! the second order Runge-Kutta method
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
subroutine flux_rk2(pblock)
|
|
|
|
|
|
|
|
use blocks , only : block_data
|
|
|
|
use config , only : im, jm, km
|
|
|
|
use mesh , only : adxi, adyi, adzi
|
|
|
|
use scheme , only : update_flux
|
|
|
|
use variables, only : nqt
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! input arguments
|
|
|
|
!
|
|
|
|
type(block_data), intent(inout) :: pblock
|
|
|
|
|
|
|
|
! local variables
|
|
|
|
!
|
|
|
|
real :: dxi, dyi, dzi
|
|
|
|
|
|
|
|
! local arrays
|
|
|
|
!
|
|
|
|
real, dimension( nqt,im,jm,km) :: u
|
|
|
|
real, dimension(NDIMS,nqt,im,jm,km) :: f0, f1
|
|
|
|
!
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
! prepare dxi, dyi, and dzi
|
|
|
|
!
|
|
|
|
dxi = adxi(pblock%meta%level)
|
|
|
|
dyi = adyi(pblock%meta%level)
|
|
|
|
dzi = adzi(pblock%meta%level)
|
|
|
|
|
|
|
|
! copy the initial state to the local array u
|
|
|
|
!
|
|
|
|
u(:,:,:,:) = pblock%u(:,:,:,:)
|
|
|
|
|
|
|
|
! calculate fluxes at the moment t
|
|
|
|
!
|
|
|
|
call update_flux(u(:,:,:,:), f0(:,:,:,:,:), dxi, dyi, dzi)
|
|
|
|
|
|
|
|
! advance the solution to (t + dt) using computed fluxes in this substep
|
|
|
|
!
|
|
|
|
call advance_solution(u(:,:,:,:), f0(:,:,:,:,:), dxi, dyi, dzi)
|
|
|
|
|
|
|
|
! calculate fluxes at the moment (t + dt)
|
|
|
|
!
|
|
|
|
call update_flux(u(:,:,:,:), f1(:,:,:,:,:), dxi, dyi, dzi)
|
|
|
|
|
|
|
|
! calculate the time averaged flux
|
|
|
|
!
|
|
|
|
pblock%f(:,:,:,:,:) = 0.5d0 * (f0(:,:,:,:,:) + f1(:,:,:,:,:))
|
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine flux_rk2
|
|
|
|
#endif /* RK2 */
|
2011-05-01 10:31:27 -03:00
|
|
|
#ifdef RK3
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! flux_rk3: subroutine performs integration of the numerical flux using
|
|
|
|
! the third order Runge-Kutta method
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
subroutine flux_rk3(pblock)
|
|
|
|
|
|
|
|
use blocks , only : block_data
|
|
|
|
use config , only : im, jm, km
|
|
|
|
use mesh , only : adxi, adyi, adzi
|
|
|
|
use scheme , only : update_flux
|
|
|
|
use variables, only : nqt
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! input arguments
|
|
|
|
!
|
|
|
|
type(block_data), intent(inout) :: pblock
|
|
|
|
|
|
|
|
! local variables
|
|
|
|
!
|
|
|
|
real :: dxi, dyi, dzi
|
|
|
|
|
|
|
|
! local arrays
|
|
|
|
!
|
|
|
|
real, dimension( nqt,im,jm,km) :: u
|
|
|
|
real, dimension(NDIMS,nqt,im,jm,km) :: f0, f1, f2
|
|
|
|
!
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
! prepare dxi, dyi, and dzi
|
|
|
|
!
|
|
|
|
dxi = adxi(pblock%meta%level)
|
|
|
|
dyi = adyi(pblock%meta%level)
|
|
|
|
dzi = adzi(pblock%meta%level)
|
|
|
|
|
|
|
|
! copy the initial state to the local array u
|
|
|
|
!
|
|
|
|
u(:,:,:,:) = pblock%u(:,:,:,:)
|
|
|
|
|
|
|
|
! calculate fluxes at the moment t
|
|
|
|
!
|
|
|
|
call update_flux(u(:,:,:,:), f0(:,:,:,:,:), dxi, dyi, dzi)
|
|
|
|
|
|
|
|
! advance the solution to (t + dt) using computed fluxes in this substep
|
|
|
|
!
|
|
|
|
call advance_solution(u(:,:,:,:), f0(:,:,:,:,:), dxi, dyi, dzi)
|
|
|
|
|
|
|
|
! calculate fluxes at the moment (t + dt)
|
|
|
|
!
|
|
|
|
call update_flux(u(:,:,:,:), f1(:,:,:,:,:), dxi, dyi, dzi)
|
|
|
|
|
|
|
|
! copy the initial state to the local array u
|
|
|
|
!
|
|
|
|
u(:,:,:,:) = pblock%u(:,:,:,:)
|
|
|
|
|
|
|
|
! average fluxes from t and t + dt and prepare for half step update
|
|
|
|
!
|
|
|
|
f2(:,:,:,:,:) = 0.25d0 * (f0(:,:,:,:,:) + f1(:,:,:,:,:))
|
|
|
|
|
|
|
|
! advance the solution to (t + dt/2) using computed flux
|
|
|
|
!
|
|
|
|
call advance_solution(u(:,:,:,:), f2(:,:,:,:,:), dxi, dyi, dzi)
|
|
|
|
|
|
|
|
! calculate fluxes at the moment (t + dt/2)
|
|
|
|
!
|
|
|
|
call update_flux(u(:,:,:,:), f2(:,:,:,:,:), dxi, dyi, dzi)
|
|
|
|
|
|
|
|
! calculate the time averaged flux using Gauss formula
|
|
|
|
!
|
|
|
|
pblock%f(:,:,:,:,:) = (f0(:,:,:,:,:) + f1(:,:,:,:,:) &
|
|
|
|
+ 4.0d0 * f2(:,:,:,:,:)) / 6.0d0
|
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine flux_rk3
|
|
|
|
#endif /* RK3 */
|
2011-04-30 12:28:02 -03:00
|
|
|
#else /* CONSERVATIVE */
|
2008-12-09 21:06:21 -06:00
|
|
|
#ifdef EULER
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! evolve_euler: subroutine evolves the current block using Euler integration
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
subroutine evolve_euler(pblock)
|
|
|
|
|
2010-12-01 09:25:30 -02:00
|
|
|
use blocks , only : block_data
|
|
|
|
use config , only : im, jm, km
|
2010-12-08 21:48:43 -02:00
|
|
|
#ifdef FORCE
|
|
|
|
use forcing , only : real_forcing
|
|
|
|
#endif /* FORCE */
|
2010-12-06 16:20:49 -02:00
|
|
|
use mesh , only : adxi, adyi, adzi
|
2008-12-18 12:18:36 -06:00
|
|
|
#ifdef SHAPE
|
2010-12-01 09:25:30 -02:00
|
|
|
use problem , only : update_shapes
|
2008-12-18 12:18:36 -06:00
|
|
|
#endif /* SHAPE */
|
2010-12-01 13:13:27 -02:00
|
|
|
use scheme , only : update, cmax
|
2010-12-01 09:25:30 -02:00
|
|
|
use variables, only : nqt, nfl
|
2010-12-01 10:53:21 -02:00
|
|
|
#ifdef MHD
|
|
|
|
use variables, only : ibx, ibz
|
|
|
|
#ifdef GLM
|
2010-12-01 11:20:25 -02:00
|
|
|
use config , only : alpha_p
|
|
|
|
use mesh , only : dx_min
|
2010-12-01 10:53:21 -02:00
|
|
|
use variables, only : iph
|
|
|
|
#endif /* GLM */
|
|
|
|
#endif /* MHD */
|
2010-12-08 21:48:43 -02:00
|
|
|
#ifdef FORCE
|
|
|
|
use variables, only : idn, imx, imy, imz
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
use variables, only : ien
|
|
|
|
#endif /* ADI */
|
2010-12-08 21:48:43 -02:00
|
|
|
#endif /* FORCE */
|
2008-12-09 21:06:21 -06:00
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! input arguments
|
|
|
|
!
|
2009-10-28 00:12:18 -02:00
|
|
|
type(block_data), intent(inout) :: pblock
|
2008-12-09 21:06:21 -06:00
|
|
|
|
|
|
|
! local variables
|
|
|
|
!
|
2010-12-06 16:20:49 -02:00
|
|
|
real :: dxi, dyi, dzi, ch2
|
2010-12-01 11:20:25 -02:00
|
|
|
#if defined MHD && defined GLM
|
2010-12-06 16:20:49 -02:00
|
|
|
real :: decay
|
2010-12-01 11:20:25 -02:00
|
|
|
#endif /* MHD & GLM */
|
2008-12-09 21:06:21 -06:00
|
|
|
|
|
|
|
! local arrays
|
|
|
|
!
|
2010-09-19 00:08:20 +02:00
|
|
|
real, dimension(nqt,im,jm,km) :: du
|
2010-12-08 21:48:43 -02:00
|
|
|
#ifdef FORCE
|
|
|
|
real, dimension( 3,im,jm,km) :: f
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
real, dimension( im,jm,km) :: ek, dek
|
|
|
|
#endif /* ADI */
|
2010-12-08 21:48:43 -02:00
|
|
|
#endif /* FORCE */
|
2008-12-09 21:06:21 -06:00
|
|
|
!
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2010-12-06 16:20:49 -02:00
|
|
|
! prepare dxi, dyi, and dzi
|
|
|
|
!
|
|
|
|
dxi = adxi(pblock%meta%level)
|
|
|
|
dyi = adyi(pblock%meta%level)
|
|
|
|
dzi = adzi(pblock%meta%level)
|
|
|
|
|
2011-03-06 23:37:51 -03:00
|
|
|
! 1st step of integration
|
|
|
|
!
|
|
|
|
call update(pblock%u(:,:,:,:), du(:,:,:,:), dxi, dyi, dzi)
|
2008-12-18 12:18:36 -06:00
|
|
|
|
|
|
|
#ifdef SHAPE
|
|
|
|
! restrict update in a defined shape
|
|
|
|
!
|
2010-12-06 16:20:49 -02:00
|
|
|
call update_shapes(pblock, du)
|
2008-12-18 12:18:36 -06:00
|
|
|
#endif /* SHAPE */
|
2008-12-09 21:06:21 -06:00
|
|
|
|
2010-12-01 10:53:21 -02:00
|
|
|
! update the solution for the fluid variables
|
2008-12-09 21:06:21 -06:00
|
|
|
!
|
2010-12-01 10:53:21 -02:00
|
|
|
pblock%u(1:nfl,:,:,:) = pblock%u(1:nfl,:,:,:) + dt * du(1:nfl,:,:,:)
|
|
|
|
|
|
|
|
#ifdef MHD
|
|
|
|
! update the solution for the magnetic variables
|
|
|
|
!
|
|
|
|
pblock%u(ibx:ibz,:,:,:) = pblock%u(ibx:ibz,:,:,:) + dt * du(ibx:ibz,:,:,:)
|
|
|
|
|
|
|
|
#ifdef GLM
|
2010-12-01 10:57:40 -02:00
|
|
|
! calculate c_h^2
|
|
|
|
!
|
|
|
|
ch2 = cmax * cmax
|
|
|
|
|
2010-12-01 10:53:21 -02:00
|
|
|
! update the solution for the scalar potential Psi
|
|
|
|
!
|
2010-12-01 10:57:40 -02:00
|
|
|
pblock%u(iph,:,:,:) = pblock%u(iph,:,:,:) + ch2 * dt * du(iph,:,:,:)
|
2010-12-01 11:20:25 -02:00
|
|
|
|
|
|
|
! evolve Psi due to the source term
|
|
|
|
!
|
|
|
|
decay = exp(- alpha_p * cmax * dt / dx_min)
|
|
|
|
pblock%u(iph,:,:,:) = decay * pblock%u(iph,:,:,:)
|
2010-12-01 10:53:21 -02:00
|
|
|
#endif /* GLM */
|
|
|
|
#endif /* MHD */
|
2011-04-26 10:36:16 -03:00
|
|
|
#ifdef FORCE
|
|
|
|
! obtain the forcing terms in real space
|
|
|
|
!
|
|
|
|
call real_forcing(pblock%meta%level, pblock%meta%xmin, pblock%meta%ymin &
|
|
|
|
, pblock%meta%zmin, f(:,:,:,:))
|
|
|
|
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
! calculate kinetic energy before adding the forcing term
|
|
|
|
!
|
|
|
|
ek(:,:,:) = 0.5d0 * (pblock%u(imx,:,:,:)**2 + pblock%u(imy,:,:,:)**2 &
|
|
|
|
+ pblock%u(imz,:,:,:)**2) / pblock%u(idn,:,:,:)
|
|
|
|
#endif /* ADI */
|
|
|
|
|
2011-04-26 10:36:16 -03:00
|
|
|
! update momenta due to the forcing terms
|
|
|
|
!
|
|
|
|
pblock%u(imx,:,:,:) = pblock%u(imx,:,:,:) + pblock%u(idn,:,:,:) * f(1,:,:,:)
|
|
|
|
pblock%u(imy,:,:,:) = pblock%u(imy,:,:,:) + pblock%u(idn,:,:,:) * f(2,:,:,:)
|
|
|
|
pblock%u(imz,:,:,:) = pblock%u(imz,:,:,:) + pblock%u(idn,:,:,:) * f(3,:,:,:)
|
|
|
|
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
! calculate kinetic energy after adding the forcing term
|
|
|
|
!
|
|
|
|
dek(:,:,:) = 0.5d0 * (pblock%u(imx,:,:,:)**2 + pblock%u(imy,:,:,:)**2 &
|
|
|
|
+ pblock%u(imz,:,:,:)**2) / pblock%u(idn,:,:,:) - ek(:,:,:)
|
|
|
|
|
|
|
|
! update total energy with the injected one
|
|
|
|
!
|
|
|
|
pblock%u(ien,:,:,:) = pblock%u(ien,:,:,:) + dek(:,:,:)
|
|
|
|
#endif /* ADI */
|
2011-04-26 10:36:16 -03:00
|
|
|
#endif /* FORCE */
|
2009-10-28 00:12:18 -02:00
|
|
|
!
|
2008-12-09 21:06:21 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine evolve_euler
|
|
|
|
#endif /* EULER */
|
2008-12-08 16:21:59 -06:00
|
|
|
#ifdef RK2
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
2008-12-08 21:07:10 -06:00
|
|
|
!===============================================================================
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
2010-12-03 15:38:48 -02:00
|
|
|
! evolve_rk2: subroutine evolves the current block using the 2nd order
|
|
|
|
! Runge-Kutta method
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
2008-12-08 21:07:10 -06:00
|
|
|
!===============================================================================
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
|
|
|
subroutine evolve_rk2(pblock)
|
|
|
|
|
2010-12-01 09:25:30 -02:00
|
|
|
use blocks , only : block_data
|
|
|
|
use config , only : im, jm, km
|
2010-12-08 21:55:45 -02:00
|
|
|
#ifdef FORCE
|
|
|
|
use forcing , only : real_forcing
|
|
|
|
#endif /* FORCE */
|
2010-12-06 16:20:49 -02:00
|
|
|
use mesh , only : adxi, adyi, adzi
|
2008-12-18 12:18:36 -06:00
|
|
|
#ifdef SHAPE
|
2010-12-01 09:25:30 -02:00
|
|
|
use problem , only : update_shapes
|
2008-12-18 12:18:36 -06:00
|
|
|
#endif /* SHAPE */
|
2010-12-01 13:13:27 -02:00
|
|
|
use scheme , only : update, cmax
|
2010-12-01 09:25:30 -02:00
|
|
|
use variables, only : nqt, nfl
|
2010-12-01 10:53:21 -02:00
|
|
|
#ifdef MHD
|
|
|
|
use variables, only : ibx, ibz
|
|
|
|
#ifdef GLM
|
2010-12-01 11:20:25 -02:00
|
|
|
use config , only : alpha_p
|
|
|
|
use mesh , only : dx_min
|
2010-12-01 10:53:21 -02:00
|
|
|
use variables, only : iph
|
|
|
|
#endif /* GLM */
|
|
|
|
#endif /* MHD */
|
2010-12-08 21:55:45 -02:00
|
|
|
#ifdef FORCE
|
|
|
|
use variables, only : idn, imx, imy, imz
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
use variables, only : ien
|
|
|
|
#endif /* ADI */
|
2010-12-08 21:55:45 -02:00
|
|
|
#endif /* FORCE */
|
2008-12-07 18:57:08 -06:00
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! input arguments
|
|
|
|
!
|
2009-10-28 00:12:18 -02:00
|
|
|
type(block_data), intent(inout) :: pblock
|
2008-12-07 18:57:08 -06:00
|
|
|
|
|
|
|
! local variables
|
|
|
|
!
|
2010-12-06 16:20:49 -02:00
|
|
|
real :: dxi, dyi, dzi, ch2
|
2010-12-01 11:20:25 -02:00
|
|
|
#if defined MHD && defined GLM
|
2010-12-06 16:20:49 -02:00
|
|
|
real :: decay
|
2010-12-01 11:20:25 -02:00
|
|
|
#endif /* MHD & GLM */
|
2008-12-08 16:21:59 -06:00
|
|
|
|
|
|
|
! local arrays
|
|
|
|
!
|
2010-09-19 00:08:20 +02:00
|
|
|
real, dimension(nqt,im,jm,km) :: u1, du
|
2010-12-08 21:55:45 -02:00
|
|
|
#ifdef FORCE
|
|
|
|
real, dimension( 3,im,jm,km) :: f
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
real, dimension( im,jm,km) :: ek, dek
|
|
|
|
#endif /* ADI */
|
2010-12-08 21:55:45 -02:00
|
|
|
#endif /* FORCE */
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
2008-12-08 21:07:10 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
2010-12-06 16:20:49 -02:00
|
|
|
! prepare dxi, dyi, and dzi
|
|
|
|
!
|
|
|
|
dxi = adxi(pblock%meta%level)
|
|
|
|
dyi = adyi(pblock%meta%level)
|
|
|
|
dzi = adzi(pblock%meta%level)
|
|
|
|
|
2010-12-03 15:38:48 -02:00
|
|
|
!! 1st step of integration
|
|
|
|
!!
|
2010-12-06 16:20:49 -02:00
|
|
|
call update(pblock%u(:,:,:,:), du(:,:,:,:), dxi, dyi, dzi)
|
2008-12-18 12:18:36 -06:00
|
|
|
|
|
|
|
#ifdef SHAPE
|
|
|
|
! restrict update in a defined shape
|
|
|
|
!
|
2010-12-03 15:38:48 -02:00
|
|
|
call update_shapes(pblock, du(:,:,:,:))
|
2008-12-08 16:21:59 -06:00
|
|
|
|
2011-04-26 11:50:57 -03:00
|
|
|
#endif /* SHAPE */
|
2010-12-01 10:53:21 -02:00
|
|
|
! update the solution for the fluid variables
|
|
|
|
!
|
|
|
|
u1(1:nfl,:,:,:) = pblock%u(1:nfl,:,:,:) + dt * du(1:nfl,:,:,:)
|
|
|
|
|
|
|
|
#ifdef MHD
|
|
|
|
! update the solution for the magnetic variables
|
2008-12-08 16:21:59 -06:00
|
|
|
!
|
2010-12-01 10:53:21 -02:00
|
|
|
u1(ibx:ibz,:,:,:) = pblock%u(ibx:ibz,:,:,:) + dt * du(ibx:ibz,:,:,:)
|
|
|
|
|
|
|
|
#ifdef GLM
|
2011-03-06 23:37:51 -03:00
|
|
|
! calculate c_h^2
|
|
|
|
!
|
|
|
|
ch2 = cmax * cmax
|
|
|
|
|
2010-12-01 10:53:21 -02:00
|
|
|
! update the solution for the scalar potential Psi
|
|
|
|
!
|
2010-12-01 10:57:40 -02:00
|
|
|
u1(iph,:,:,:) = pblock%u(iph,:,:,:) + ch2 * dt * du(iph,:,:,:)
|
2011-04-26 11:50:57 -03:00
|
|
|
|
2010-12-01 10:53:21 -02:00
|
|
|
#endif /* GLM */
|
|
|
|
#endif /* MHD */
|
2008-12-08 16:21:59 -06:00
|
|
|
! 2nd step of integration
|
|
|
|
!
|
2010-12-06 16:20:49 -02:00
|
|
|
call update(u1(:,:,:,:), du(:,:,:,:), dxi, dyi, dzi)
|
2008-12-08 16:21:59 -06:00
|
|
|
|
2008-12-18 12:18:36 -06:00
|
|
|
#ifdef SHAPE
|
|
|
|
! restrict update in a defined shape
|
|
|
|
!
|
2010-12-03 15:38:48 -02:00
|
|
|
call update_shapes(pblock, du(:,:,:,:))
|
2008-12-18 12:18:36 -06:00
|
|
|
|
2011-04-26 11:50:57 -03:00
|
|
|
#endif /* SHAPE */
|
2010-12-01 10:53:21 -02:00
|
|
|
! update the solution for the fluid variables
|
|
|
|
!
|
|
|
|
pblock%u(1:nfl,:,:,:) = 0.5d0 * (pblock%u(1:nfl,:,:,:) &
|
2010-12-03 15:38:48 -02:00
|
|
|
+ u1(1:nfl,:,:,:) + dt * du(1:nfl,:,:,:))
|
2010-12-01 10:53:21 -02:00
|
|
|
|
|
|
|
#ifdef MHD
|
|
|
|
! update the solution for the magnetic variables
|
|
|
|
!
|
|
|
|
pblock%u(ibx:ibz,:,:,:) = 0.5d0 * (pblock%u(ibx:ibz,:,:,:) &
|
2010-12-03 15:38:48 -02:00
|
|
|
+ u1(ibx:ibz,:,:,:) + dt * du(ibx:ibz,:,:,:))
|
2010-12-01 10:53:21 -02:00
|
|
|
|
|
|
|
#ifdef GLM
|
|
|
|
! update the solution for the scalar potential Psi
|
2008-12-08 16:21:59 -06:00
|
|
|
!
|
2010-12-01 10:53:21 -02:00
|
|
|
pblock%u(iph,:,:,:) = 0.5d0 * (pblock%u(iph,:,:,:) &
|
2010-12-03 15:38:48 -02:00
|
|
|
+ u1(iph,:,:,:) + ch2 * dt * du(iph,:,:,:))
|
2010-12-01 11:20:25 -02:00
|
|
|
|
|
|
|
! evolve Psi due to the source term
|
|
|
|
!
|
|
|
|
decay = exp(- alpha_p * cmax * dt / dx_min)
|
|
|
|
pblock%u(iph,:,:,:) = decay * pblock%u(iph,:,:,:)
|
2011-04-26 11:50:57 -03:00
|
|
|
|
2010-12-01 10:53:21 -02:00
|
|
|
#endif /* GLM */
|
|
|
|
#endif /* MHD */
|
2011-04-26 10:36:16 -03:00
|
|
|
#ifdef FORCE
|
|
|
|
! obtain the forcing terms in real space
|
|
|
|
!
|
|
|
|
call real_forcing(pblock%meta%level, pblock%meta%xmin, pblock%meta%ymin &
|
|
|
|
, pblock%meta%zmin, f(:,:,:,:))
|
|
|
|
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
! calculate kinetic energy before adding the forcing term
|
|
|
|
!
|
|
|
|
ek(:,:,:) = 0.5d0 * (pblock%u(imx,:,:,:)**2 + pblock%u(imy,:,:,:)**2 &
|
|
|
|
+ pblock%u(imz,:,:,:)**2) / pblock%u(idn,:,:,:)
|
|
|
|
#endif /* ADI */
|
|
|
|
|
2011-04-26 10:36:16 -03:00
|
|
|
! update momenta due to the forcing terms
|
|
|
|
!
|
|
|
|
pblock%u(imx,:,:,:) = pblock%u(imx,:,:,:) + pblock%u(idn,:,:,:) * f(1,:,:,:)
|
|
|
|
pblock%u(imy,:,:,:) = pblock%u(imy,:,:,:) + pblock%u(idn,:,:,:) * f(2,:,:,:)
|
|
|
|
pblock%u(imz,:,:,:) = pblock%u(imz,:,:,:) + pblock%u(idn,:,:,:) * f(3,:,:,:)
|
|
|
|
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
! calculate kinetic energy after adding the forcing term
|
|
|
|
!
|
|
|
|
dek(:,:,:) = 0.5d0 * (pblock%u(imx,:,:,:)**2 + pblock%u(imy,:,:,:)**2 &
|
|
|
|
+ pblock%u(imz,:,:,:)**2) / pblock%u(idn,:,:,:) - ek(:,:,:)
|
|
|
|
|
|
|
|
! update total energy with the injected one
|
|
|
|
!
|
|
|
|
pblock%u(ien,:,:,:) = pblock%u(ien,:,:,:) + dek(:,:,:)
|
|
|
|
#endif /* ADI */
|
2011-04-26 10:36:16 -03:00
|
|
|
#endif /* FORCE */
|
2009-10-28 00:12:18 -02:00
|
|
|
!
|
2008-12-08 21:07:10 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
|
|
|
end subroutine evolve_rk2
|
2008-12-08 16:21:59 -06:00
|
|
|
#endif /* RK2 */
|
2010-12-03 15:38:48 -02:00
|
|
|
#ifdef RK3
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! evolve_rk3: subroutine evolves the current block using the 3rd order
|
|
|
|
! Runge-Kutta method
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
subroutine evolve_rk3(pblock)
|
|
|
|
|
|
|
|
use blocks , only : block_data
|
|
|
|
use config , only : im, jm, km
|
2010-12-09 17:54:59 -02:00
|
|
|
#ifdef FORCE
|
|
|
|
use forcing , only : real_forcing
|
|
|
|
#endif /* FORCE */
|
2010-12-06 16:20:49 -02:00
|
|
|
use mesh , only : adxi, adyi, adzi
|
2010-12-03 15:38:48 -02:00
|
|
|
#ifdef SHAPE
|
|
|
|
use problem , only : update_shapes
|
|
|
|
#endif /* SHAPE */
|
|
|
|
use scheme , only : update, cmax
|
|
|
|
use variables, only : nqt, nfl
|
|
|
|
#ifdef MHD
|
|
|
|
use variables, only : ibx, ibz
|
|
|
|
#ifdef GLM
|
|
|
|
use config , only : alpha_p
|
|
|
|
use mesh , only : dx_min
|
|
|
|
use variables, only : iph
|
|
|
|
#endif /* GLM */
|
|
|
|
#endif /* MHD */
|
2010-12-09 17:54:59 -02:00
|
|
|
#ifdef FORCE
|
|
|
|
use variables, only : idn, imx, imy, imz
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
use variables, only : ien
|
|
|
|
#endif /* ADI */
|
2010-12-09 17:54:59 -02:00
|
|
|
#endif /* FORCE */
|
2010-12-03 15:38:48 -02:00
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! input arguments
|
|
|
|
!
|
|
|
|
type(block_data), intent(inout) :: pblock
|
|
|
|
|
|
|
|
! local variables
|
|
|
|
!
|
2011-05-01 09:44:19 -03:00
|
|
|
real :: dxi, dyi, dzi
|
2010-12-03 15:38:48 -02:00
|
|
|
#if defined MHD && defined GLM
|
2011-05-01 09:44:19 -03:00
|
|
|
real :: decay, ch2
|
2010-12-03 15:38:48 -02:00
|
|
|
#endif /* MHD & GLM */
|
|
|
|
|
|
|
|
! local arrays
|
|
|
|
!
|
|
|
|
real, dimension(nqt,im,jm,km) :: u1, du
|
2010-12-09 17:54:59 -02:00
|
|
|
#ifdef FORCE
|
|
|
|
real, dimension( 3,im,jm,km) :: f
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
real, dimension( im,jm,km) :: ek, dek
|
|
|
|
#endif /* ADI */
|
2010-12-09 17:54:59 -02:00
|
|
|
#endif /* FORCE */
|
2010-12-03 15:38:48 -02:00
|
|
|
|
|
|
|
! parameters
|
|
|
|
!
|
|
|
|
real, parameter :: f4 = 1.0d0 / 4.0d0, f3 = 1.0d0 / 3.0d0
|
|
|
|
!
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2010-12-06 16:20:49 -02:00
|
|
|
! prepare dxi, dyi, and dzi
|
|
|
|
!
|
|
|
|
dxi = adxi(pblock%meta%level)
|
|
|
|
dyi = adyi(pblock%meta%level)
|
|
|
|
dzi = adzi(pblock%meta%level)
|
|
|
|
|
2010-12-03 15:38:48 -02:00
|
|
|
!! 1st step of integration
|
|
|
|
!!
|
2010-12-06 16:20:49 -02:00
|
|
|
call update(pblock%u(:,:,:,:), du(:,:,:,:), dxi, dyi, dzi)
|
2010-12-03 15:38:48 -02:00
|
|
|
|
|
|
|
#ifdef SHAPE
|
|
|
|
! restrict update in a defined shape
|
|
|
|
!
|
|
|
|
call update_shapes(pblock, du(:,:,:,:))
|
|
|
|
#endif /* SHAPE */
|
|
|
|
|
|
|
|
! update the solution for the fluid variables
|
|
|
|
!
|
|
|
|
u1(1:nfl,:,:,:) = pblock%u(1:nfl,:,:,:) + dt * du(1:nfl,:,:,:)
|
|
|
|
|
|
|
|
#ifdef MHD
|
|
|
|
! update the solution for the magnetic variables
|
|
|
|
!
|
|
|
|
u1(ibx:ibz,:,:,:) = pblock%u(ibx:ibz,:,:,:) + dt * du(ibx:ibz,:,:,:)
|
|
|
|
|
|
|
|
#ifdef GLM
|
2011-03-06 23:37:51 -03:00
|
|
|
! calculate c_h^2
|
|
|
|
!
|
|
|
|
ch2 = cmax * cmax
|
|
|
|
|
2010-12-03 15:38:48 -02:00
|
|
|
! update the solution for the scalar potential Psi
|
|
|
|
!
|
|
|
|
u1(iph,:,:,:) = pblock%u(iph,:,:,:) + ch2 * dt * du(iph,:,:,:)
|
|
|
|
#endif /* GLM */
|
|
|
|
#endif /* MHD */
|
|
|
|
|
|
|
|
!! 2nd step of integration
|
|
|
|
!!
|
2010-12-06 16:20:49 -02:00
|
|
|
call update(u1(:,:,:,:), du(:,:,:,:), dxi, dyi, dzi)
|
2010-12-03 15:38:48 -02:00
|
|
|
|
|
|
|
#ifdef SHAPE
|
|
|
|
! restrict update in a defined shape
|
|
|
|
!
|
|
|
|
call update_shapes(pblock, du(:,:,:,:))
|
|
|
|
#endif /* SHAPE */
|
|
|
|
|
|
|
|
! update the solution for the fluid variables
|
|
|
|
!
|
|
|
|
u1(1:nfl,:,:,:) = f4 * (3.0d0 * pblock%u(1:nfl,:,:,:) &
|
|
|
|
+ u1(1:nfl,:,:,:) + dt * du(1:nfl,:,:,:))
|
|
|
|
|
|
|
|
#ifdef MHD
|
|
|
|
! update the solution for the magnetic variables
|
|
|
|
!
|
|
|
|
u1(ibx:ibz,:,:,:) = f4 * (3.0d0 * pblock%u(ibx:ibz,:,:,:) &
|
|
|
|
+ u1(ibx:ibz,:,:,:) + dt * du(ibx:ibz,:,:,:))
|
|
|
|
|
|
|
|
#ifdef GLM
|
|
|
|
! update the solution for the scalar potential Psi
|
|
|
|
!
|
|
|
|
u1(iph,:,:,:) = f4 * (3.0d0 * pblock%u(iph,:,:,:) &
|
|
|
|
+ u1(iph,:,:,:) + ch2 * dt * du(iph,:,:,:))
|
|
|
|
#endif /* GLM */
|
|
|
|
#endif /* MHD */
|
|
|
|
|
|
|
|
!! 3rd step of integration
|
|
|
|
!!
|
2010-12-06 16:20:49 -02:00
|
|
|
call update(u1(:,:,:,:), du(:,:,:,:), dxi, dyi, dzi)
|
2010-12-03 15:38:48 -02:00
|
|
|
|
|
|
|
#ifdef SHAPE
|
|
|
|
! restrict update in a defined shape
|
|
|
|
!
|
|
|
|
call update_shapes(pblock, du(:,:,:,:))
|
|
|
|
#endif /* SHAPE */
|
|
|
|
|
|
|
|
! update the solution for the fluid variables
|
|
|
|
!
|
|
|
|
pblock%u(1:nfl,:,:,:) = f3 * (pblock%u(1:nfl,:,:,:) &
|
|
|
|
+ 2.0d0 * (u1(1:nfl,:,:,:) + dt * du(1:nfl,:,:,:)))
|
|
|
|
|
|
|
|
#ifdef MHD
|
|
|
|
! update the solution for the magnetic variables
|
|
|
|
!
|
|
|
|
pblock%u(ibx:ibz,:,:,:) = f3 * (pblock%u(ibx:ibz,:,:,:) &
|
|
|
|
+ 2.0d0 * (u1(ibx:ibz,:,:,:) + dt * du(ibx:ibz,:,:,:)))
|
|
|
|
|
|
|
|
#ifdef GLM
|
|
|
|
! update the solution for the scalar potential Psi
|
|
|
|
!
|
|
|
|
pblock%u(iph,:,:,:) = f3 * (pblock%u(iph,:,:,:) &
|
|
|
|
+ 2.0d0 * (u1(iph,:,:,:) + ch2 * dt * du(iph,:,:,:)))
|
|
|
|
|
|
|
|
! evolve analytically Psi due to the source term
|
|
|
|
!
|
|
|
|
decay = exp(- alpha_p * cmax * dt / dx_min)
|
|
|
|
pblock%u(iph,:,:,:) = decay * pblock%u(iph,:,:,:)
|
|
|
|
#endif /* GLM */
|
|
|
|
#endif /* MHD */
|
2011-05-01 19:21:43 -03:00
|
|
|
|
2011-04-26 10:36:16 -03:00
|
|
|
#ifdef FORCE
|
|
|
|
! obtain the forcing terms in real space
|
|
|
|
!
|
|
|
|
call real_forcing(pblock%meta%level, pblock%meta%xmin, pblock%meta%ymin &
|
|
|
|
, pblock%meta%zmin, f(:,:,:,:))
|
|
|
|
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
! calculate kinetic energy before adding the forcing term
|
|
|
|
!
|
|
|
|
ek(:,:,:) = 0.5d0 * (pblock%u(imx,:,:,:)**2 + pblock%u(imy,:,:,:)**2 &
|
|
|
|
+ pblock%u(imz,:,:,:)**2) / pblock%u(idn,:,:,:)
|
|
|
|
#endif /* ADI */
|
|
|
|
|
2011-04-26 10:36:16 -03:00
|
|
|
! update momenta due to the forcing terms
|
|
|
|
!
|
|
|
|
pblock%u(imx,:,:,:) = pblock%u(imx,:,:,:) + pblock%u(idn,:,:,:) * f(1,:,:,:)
|
|
|
|
pblock%u(imy,:,:,:) = pblock%u(imy,:,:,:) + pblock%u(idn,:,:,:) * f(2,:,:,:)
|
|
|
|
pblock%u(imz,:,:,:) = pblock%u(imz,:,:,:) + pblock%u(idn,:,:,:) * f(3,:,:,:)
|
|
|
|
|
2011-05-01 19:21:43 -03:00
|
|
|
#ifdef ADI
|
|
|
|
! calculate kinetic energy after adding the forcing term
|
|
|
|
!
|
|
|
|
dek(:,:,:) = 0.5d0 * (pblock%u(imx,:,:,:)**2 + pblock%u(imy,:,:,:)**2 &
|
|
|
|
+ pblock%u(imz,:,:,:)**2) / pblock%u(idn,:,:,:) - ek(:,:,:)
|
|
|
|
|
|
|
|
! update total energy with the injected one
|
|
|
|
!
|
|
|
|
pblock%u(ien,:,:,:) = pblock%u(ien,:,:,:) + dek(:,:,:)
|
|
|
|
#endif /* ADI */
|
2011-04-26 10:36:16 -03:00
|
|
|
#endif /* FORCE */
|
2010-12-03 15:38:48 -02:00
|
|
|
!
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end subroutine evolve_rk3
|
|
|
|
#endif /* RK3 */
|
2011-04-30 12:28:02 -03:00
|
|
|
#endif /* CONSERVATIVE */
|
2010-02-28 18:35:57 -03:00
|
|
|
!
|
2008-12-08 21:07:10 -06:00
|
|
|
!===============================================================================
|
2008-12-07 18:57:08 -06:00
|
|
|
!
|
|
|
|
end module
|