2014-04-29 18:35:58 -03:00
|
|
|
|
!!******************************************************************************
|
|
|
|
|
!!
|
|
|
|
|
!! This file is part of the AMUN source code, a program to perform
|
|
|
|
|
!! Newtonian or relativistic magnetohydrodynamical simulations on uniform or
|
|
|
|
|
!! adaptive mesh.
|
|
|
|
|
!!
|
2024-03-07 09:34:43 -03:00
|
|
|
|
!! Copyright (C) 2008-2024 Grzegorz Kowal <grzegorz@amuncode.org>
|
2014-04-29 18:35:58 -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 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: SOURCES
|
|
|
|
|
!!
|
|
|
|
|
!! This modules adds source terms.
|
|
|
|
|
!!
|
|
|
|
|
!!******************************************************************************
|
|
|
|
|
!
|
|
|
|
|
module sources
|
|
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
2021-11-26 13:37:25 -03:00
|
|
|
|
! interfaces for the extra source terms subroutine
|
|
|
|
|
!
|
|
|
|
|
abstract interface
|
2022-02-09 16:25:07 -03:00
|
|
|
|
subroutine update_extra_sources_iface(t, dt, pdata)
|
2021-11-26 13:37:25 -03:00
|
|
|
|
use blocks, only : block_data
|
|
|
|
|
implicit none
|
|
|
|
|
real(kind=8) , intent(in) :: t, dt
|
2022-02-09 16:25:07 -03:00
|
|
|
|
type(block_data), pointer , intent(inout) :: pdata
|
2021-11-26 13:37:25 -03:00
|
|
|
|
end subroutine
|
|
|
|
|
end interface
|
|
|
|
|
|
|
|
|
|
! pointer to the extra source terms subroutine
|
|
|
|
|
!
|
|
|
|
|
procedure(update_extra_sources_iface), pointer, save :: &
|
|
|
|
|
update_extra_sources => null()
|
|
|
|
|
|
2014-09-19 08:04:48 -03:00
|
|
|
|
! GLM-MHD source terms type (1 - EGLM, 2 - HEGLM)
|
|
|
|
|
!
|
2019-01-30 12:20:18 -02:00
|
|
|
|
integer , save :: glm_type = 0
|
|
|
|
|
character(len=32), save :: glm_name = "none"
|
2014-09-19 08:04:48 -03:00
|
|
|
|
|
2014-05-27 17:53:35 -03:00
|
|
|
|
! viscosity coefficient
|
|
|
|
|
!
|
2019-01-30 12:20:18 -02:00
|
|
|
|
real(kind=8) , save :: viscosity = 0.0d+00
|
2014-05-29 12:04:55 -03:00
|
|
|
|
|
|
|
|
|
! resistivity coefficient
|
|
|
|
|
!
|
2019-01-30 12:20:18 -02:00
|
|
|
|
real(kind=8) , save :: resistivity = 0.0d+00
|
2019-02-25 09:53:05 -03:00
|
|
|
|
real(kind=8) , save :: anomalous = 0.0d+00
|
|
|
|
|
real(kind=8) , save :: jcrit = 1.0d+00
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
2019-01-30 12:20:18 -02:00
|
|
|
|
public :: initialize_sources, finalize_sources, print_sources
|
2021-11-26 13:37:25 -03:00
|
|
|
|
public :: update_sources, update_extra_sources
|
2014-05-29 12:04:55 -03:00
|
|
|
|
public :: viscosity, resistivity
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
|
|
|
|
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
|
!
|
|
|
|
|
contains
|
|
|
|
|
!
|
|
|
|
|
!===============================================================================
|
|
|
|
|
!!
|
|
|
|
|
!!*** PUBLIC SUBROUTINES *****************************************************
|
|
|
|
|
!!
|
|
|
|
|
!===============================================================================
|
|
|
|
|
!
|
|
|
|
|
!===============================================================================
|
|
|
|
|
!
|
|
|
|
|
! subroutine INITIALIZE_SOURCES:
|
|
|
|
|
! -----------------------------
|
|
|
|
|
!
|
|
|
|
|
! Subroutine initializes module SOURCES.
|
|
|
|
|
!
|
|
|
|
|
! Arguments:
|
|
|
|
|
!
|
|
|
|
|
! verbose - a logical flag turning the information printing;
|
2019-02-08 15:37:06 -02:00
|
|
|
|
! status - an integer flag for error return value;
|
2014-04-29 18:35:58 -03:00
|
|
|
|
!
|
|
|
|
|
!===============================================================================
|
|
|
|
|
!
|
2019-02-08 15:37:06 -02:00
|
|
|
|
subroutine initialize_sources(verbose, status)
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
2021-11-16 15:22:15 -03:00
|
|
|
|
use parameters, only : get_parameter
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
2019-02-08 15:37:06 -02:00
|
|
|
|
logical, intent(in) :: verbose
|
|
|
|
|
integer, intent(out) :: status
|
2014-09-19 08:04:48 -03:00
|
|
|
|
|
2019-02-08 15:37:06 -02:00
|
|
|
|
character(len=8) :: tglm = "none"
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
2021-11-16 15:22:15 -03:00
|
|
|
|
!-------------------------------------------------------------------------------
|
2019-02-08 15:37:06 -02:00
|
|
|
|
!
|
|
|
|
|
status = 0
|
|
|
|
|
|
2014-09-19 08:04:48 -03:00
|
|
|
|
! get the type of the GLM source terms
|
|
|
|
|
!
|
2019-01-28 21:32:37 -02:00
|
|
|
|
call get_parameter("glm_source_terms", tglm)
|
2014-09-19 08:04:48 -03:00
|
|
|
|
|
|
|
|
|
! set the glm_type variable to correct value
|
|
|
|
|
!
|
|
|
|
|
select case(trim(tglm))
|
|
|
|
|
case("eglm", "EGLM")
|
|
|
|
|
glm_type = 1
|
2019-01-30 12:20:18 -02:00
|
|
|
|
glm_name = "EGLM"
|
2014-09-19 08:04:48 -03:00
|
|
|
|
case("heglm", "HEGLM")
|
|
|
|
|
glm_type = 2
|
2019-01-30 12:20:18 -02:00
|
|
|
|
glm_name = "HEGLM"
|
2022-01-06 16:46:36 -03:00
|
|
|
|
case("kepes", "KEPES")
|
|
|
|
|
glm_type = 3
|
|
|
|
|
glm_name = "KEPES"
|
2014-09-19 08:04:48 -03:00
|
|
|
|
case default
|
|
|
|
|
glm_type = 0
|
2019-01-30 12:20:18 -02:00
|
|
|
|
glm_name = "none"
|
2014-09-19 08:04:48 -03:00
|
|
|
|
end select
|
|
|
|
|
|
2014-05-27 17:53:35 -03:00
|
|
|
|
! get viscosity coefficient
|
|
|
|
|
!
|
2019-02-08 15:37:06 -02:00
|
|
|
|
call get_parameter("viscosity", viscosity)
|
|
|
|
|
|
|
|
|
|
if (viscosity < 0.0d+00) then
|
|
|
|
|
if (verbose) then
|
|
|
|
|
write(*,*)
|
|
|
|
|
write(*,"(1x,a)") "ERROR!"
|
|
|
|
|
write(*,"(1x,a)") "Negative viscosity coefficient!"
|
|
|
|
|
end if
|
|
|
|
|
status = 1
|
|
|
|
|
end if
|
2014-05-29 12:04:55 -03:00
|
|
|
|
|
2019-02-25 09:53:05 -03:00
|
|
|
|
! get resistivity coefficients
|
2014-05-29 12:04:55 -03:00
|
|
|
|
!
|
2019-01-28 21:32:37 -02:00
|
|
|
|
call get_parameter("resistivity", resistivity)
|
2019-02-08 15:37:06 -02:00
|
|
|
|
|
|
|
|
|
if (resistivity < 0.0d+00) then
|
|
|
|
|
if (verbose) then
|
|
|
|
|
write(*,*)
|
|
|
|
|
write(*,"(1x,a)") "ERROR!"
|
|
|
|
|
write(*,"(1x,a)") "Negative resistivity coefficient!"
|
|
|
|
|
end if
|
|
|
|
|
status = 1
|
|
|
|
|
end if
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
2019-02-25 09:53:05 -03:00
|
|
|
|
call get_parameter("anomalous", anomalous)
|
|
|
|
|
|
|
|
|
|
if (anomalous < 0.0d+00) then
|
|
|
|
|
if (verbose) then
|
|
|
|
|
write(*,*)
|
|
|
|
|
write(*,"(1x,a)") "ERROR!"
|
|
|
|
|
write(*,"(1x,a)") "Negative anomalous resistivity coefficient!"
|
|
|
|
|
end if
|
|
|
|
|
status = 1
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
call get_parameter("jcrit", jcrit)
|
|
|
|
|
|
|
|
|
|
if (jcrit <= 0.0d+00) then
|
|
|
|
|
if (verbose) then
|
|
|
|
|
write(*,*)
|
|
|
|
|
write(*,"(1x,a)") "ERROR!"
|
|
|
|
|
write(*,"(1x,a)") "Non-positive critical current density coefficient!"
|
|
|
|
|
end if
|
|
|
|
|
status = 1
|
|
|
|
|
end if
|
|
|
|
|
|
2014-04-29 18:35:58 -03:00
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
|
!
|
|
|
|
|
end subroutine initialize_sources
|
|
|
|
|
!
|
|
|
|
|
!===============================================================================
|
|
|
|
|
!
|
|
|
|
|
! subroutine FINALIZE_SOURCES:
|
|
|
|
|
! ---------------------------
|
|
|
|
|
!
|
|
|
|
|
! Subroutine releases memory used by the module.
|
|
|
|
|
!
|
|
|
|
|
! Arguments:
|
|
|
|
|
!
|
2019-02-08 15:37:06 -02:00
|
|
|
|
! status - an integer flag for error return value;
|
2014-04-29 18:35:58 -03:00
|
|
|
|
!
|
|
|
|
|
!===============================================================================
|
|
|
|
|
!
|
2019-02-08 15:37:06 -02:00
|
|
|
|
subroutine finalize_sources(status)
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
2019-02-08 15:37:06 -02:00
|
|
|
|
integer, intent(out) :: status
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
2021-11-16 15:22:15 -03:00
|
|
|
|
!-------------------------------------------------------------------------------
|
2019-02-08 15:37:06 -02:00
|
|
|
|
!
|
|
|
|
|
status = 0
|
|
|
|
|
|
2014-04-29 18:35:58 -03:00
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
|
!
|
|
|
|
|
end subroutine finalize_sources
|
|
|
|
|
!
|
|
|
|
|
!===============================================================================
|
|
|
|
|
!
|
2019-01-30 12:20:18 -02:00
|
|
|
|
! subroutine PRINT_SOURCES:
|
|
|
|
|
! ------------------------
|
|
|
|
|
!
|
|
|
|
|
! Subroutine prints module parameters.
|
|
|
|
|
!
|
|
|
|
|
! Arguments:
|
|
|
|
|
!
|
|
|
|
|
! verbose - a logical flag turning the information printing;
|
|
|
|
|
!
|
|
|
|
|
!===============================================================================
|
|
|
|
|
!
|
|
|
|
|
subroutine print_sources(verbose)
|
|
|
|
|
|
|
|
|
|
use equations, only : magnetized
|
2019-01-30 18:55:41 -02:00
|
|
|
|
use helpers , only : print_section, print_parameter
|
2019-01-30 12:20:18 -02:00
|
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
|
|
logical, intent(in) :: verbose
|
2021-11-16 15:22:15 -03:00
|
|
|
|
|
2019-01-30 12:20:18 -02:00
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
|
!
|
|
|
|
|
if (verbose) then
|
|
|
|
|
|
2019-01-30 18:55:41 -02:00
|
|
|
|
call print_section(verbose, "Source terms")
|
|
|
|
|
call print_parameter(verbose, "viscosity" , viscosity )
|
2019-01-30 12:20:18 -02:00
|
|
|
|
if (magnetized) then
|
2019-01-30 18:55:41 -02:00
|
|
|
|
call print_parameter(verbose, "resistivity" , resistivity)
|
2020-08-06 14:33:42 -03:00
|
|
|
|
if (anomalous > 0.0d+00) then
|
2019-02-27 10:07:46 -03:00
|
|
|
|
call print_parameter(verbose, "anomalous" , anomalous )
|
|
|
|
|
call print_parameter(verbose, "jcrit" , jcrit )
|
|
|
|
|
end if
|
2019-01-30 18:55:41 -02:00
|
|
|
|
call print_parameter(verbose, "glm source terms", glm_name )
|
2019-01-30 12:20:18 -02:00
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
|
!
|
|
|
|
|
end subroutine print_sources
|
|
|
|
|
!
|
|
|
|
|
!===============================================================================
|
|
|
|
|
!
|
2014-04-29 18:35:58 -03:00
|
|
|
|
! subroutine UPDATE_SOURCES:
|
|
|
|
|
! -------------------------
|
|
|
|
|
!
|
2021-11-12 11:53:43 -03:00
|
|
|
|
! Subroutine adds source terms to the array of increments dU.
|
2014-04-29 18:35:58 -03:00
|
|
|
|
!
|
|
|
|
|
! Arguments:
|
|
|
|
|
!
|
2017-03-07 16:04:03 -03:00
|
|
|
|
! t, dt - the time and time increment;
|
2022-02-09 16:25:07 -03:00
|
|
|
|
! pdata - the pointer to a data block;
|
2014-04-29 18:35:58 -03:00
|
|
|
|
!
|
|
|
|
|
!===============================================================================
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
subroutine update_sources(t, dt, pdata)
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
2021-11-26 13:37:25 -03:00
|
|
|
|
use blocks , only : block_data
|
|
|
|
|
use coordinates, only : nn => bcells
|
|
|
|
|
use coordinates, only : ax, adx, ay, ady, adz
|
2020-08-15 01:12:41 -03:00
|
|
|
|
#if NDIMS == 3
|
2021-11-26 13:37:25 -03:00
|
|
|
|
use coordinates, only : az
|
2020-08-15 01:12:41 -03:00
|
|
|
|
#endif /* NDIMS == 3 */
|
2021-11-26 13:37:25 -03:00
|
|
|
|
use equations , only : magnetized
|
|
|
|
|
use equations , only : inx, iny, inz
|
|
|
|
|
use equations , only : idn, ivx, ivy, ivz, imx, imy, imz, ien
|
|
|
|
|
use equations , only : ibx, iby, ibz, ibp
|
|
|
|
|
use gravity , only : gravity_enabled, gravitational_acceleration
|
|
|
|
|
use helpers , only : print_message
|
|
|
|
|
use operators , only : divergence, gradient, laplace, curl
|
|
|
|
|
use workspace , only : resize_workspace, work, work_in_use
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
2019-02-05 11:17:59 -02:00
|
|
|
|
real(kind=8) , intent(in) :: t, dt
|
2022-02-09 16:25:07 -03:00
|
|
|
|
type(block_data), pointer , intent(inout) :: pdata
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
2021-11-12 11:53:43 -03:00
|
|
|
|
logical, save :: first = .true.
|
|
|
|
|
|
|
|
|
|
integer :: status
|
2022-01-08 10:52:05 -03:00
|
|
|
|
integer :: i, j, k
|
2014-11-18 19:08:50 -02:00
|
|
|
|
real(kind=8) :: fc, gc
|
2017-03-06 11:12:25 -03:00
|
|
|
|
real(kind=8) :: gx, gy, gz
|
2014-11-18 19:08:50 -02:00
|
|
|
|
real(kind=8) :: dvxdx, dvxdy, dvxdz, divv
|
|
|
|
|
real(kind=8) :: dvydx, dvydy, dvydz
|
|
|
|
|
real(kind=8) :: dvzdx, dvzdy, dvzdz
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
2022-01-08 11:52:16 -03:00
|
|
|
|
integer, save :: nt
|
2021-12-07 10:46:18 -03:00
|
|
|
|
!$ integer :: omp_get_thread_num
|
|
|
|
|
|
2017-03-06 11:12:25 -03:00
|
|
|
|
real(kind=8), dimension(3) :: ga, dh
|
2019-02-13 11:44:51 -02:00
|
|
|
|
real(kind=8), dimension(nn) :: x, y
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#if NDIMS == 3
|
2019-02-13 11:44:51 -02:00
|
|
|
|
real(kind=8), dimension(nn) :: z
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#else /* NDIMS == 3 */
|
|
|
|
|
real(kind=8), dimension( 1) :: z
|
|
|
|
|
#endif /* NDIMS == 3 */
|
2021-11-12 11:53:43 -03:00
|
|
|
|
real(kind=8), dimension(:,:,:) , pointer, save :: db
|
|
|
|
|
real(kind=8), dimension(:,:,:,:,:), pointer, save :: tmp
|
2021-12-07 19:55:30 -03:00
|
|
|
|
!$omp threadprivate(first, nt, db, tmp)
|
2021-11-12 11:53:43 -03:00
|
|
|
|
|
|
|
|
|
character(len=*), parameter :: loc = 'SOURCES:update_sources()'
|
|
|
|
|
|
2014-04-29 18:35:58 -03:00
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
|
!
|
2022-01-08 11:52:16 -03:00
|
|
|
|
nt = 0
|
2021-12-07 19:55:30 -03:00
|
|
|
|
!$ nt = omp_get_thread_num()
|
2021-11-12 11:53:43 -03:00
|
|
|
|
if (first) then
|
2021-11-13 20:38:27 -03:00
|
|
|
|
i = nn**NDIMS
|
|
|
|
|
j = 10 * i
|
|
|
|
|
|
|
|
|
|
call resize_workspace(j, status)
|
|
|
|
|
if (status /= 0) then
|
2021-11-19 12:39:36 -03:00
|
|
|
|
call print_message(loc, "Could not resize the workspace!")
|
2021-11-12 11:53:43 -03:00
|
|
|
|
go to 100
|
2021-11-13 20:38:27 -03:00
|
|
|
|
end if
|
2021-11-12 11:53:43 -03:00
|
|
|
|
|
|
|
|
|
#if NDIMS == 3
|
2021-12-07 10:46:18 -03:00
|
|
|
|
db(1:nn,1:nn,1:nn) => work( 1:i,nt)
|
|
|
|
|
tmp(1:3,1:3,1:nn,1:nn,1:nn) => work(i+1:j,nt)
|
2021-11-12 11:53:43 -03:00
|
|
|
|
#else /* NDIMS == 3 */
|
2021-12-07 10:46:18 -03:00
|
|
|
|
db(1:nn,1:nn,1: 1) => work( 1:i,nt)
|
|
|
|
|
tmp(1:3,1:3,1:nn,1:nn,1: 1) => work(i+1:j,nt)
|
2021-11-12 11:53:43 -03:00
|
|
|
|
#endif /* NDIMS == 3 */
|
|
|
|
|
|
|
|
|
|
first = .false.
|
|
|
|
|
end if
|
|
|
|
|
|
2022-01-08 10:52:05 -03:00
|
|
|
|
#if NDIMS == 2
|
|
|
|
|
k = 1
|
|
|
|
|
#endif /* NDIMS == 2 */
|
|
|
|
|
|
2017-03-06 11:12:25 -03:00
|
|
|
|
! proceed only if the gravitational term is enabled
|
2014-04-29 18:35:58 -03:00
|
|
|
|
!
|
2017-03-06 11:12:25 -03:00
|
|
|
|
if (gravity_enabled) then
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
|
|
|
|
! prepare block coordinates
|
|
|
|
|
!
|
2019-02-05 11:17:59 -02:00
|
|
|
|
x(:) = pdata%meta%xmin + ax(pdata%meta%level,:)
|
|
|
|
|
y(:) = pdata%meta%ymin + ay(pdata%meta%level,:)
|
2014-04-29 18:35:58 -03:00
|
|
|
|
#if NDIMS == 3
|
2019-02-05 11:17:59 -02:00
|
|
|
|
z(:) = pdata%meta%zmin + az(pdata%meta%level,:)
|
2014-04-29 18:35:58 -03:00
|
|
|
|
#endif /* NDIMS == 3 */
|
|
|
|
|
|
|
|
|
|
! iterate over all positions in the YZ plane
|
|
|
|
|
!
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#if NDIMS == 3
|
2019-02-13 11:44:51 -02:00
|
|
|
|
do k = 1, nn
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#endif /* NDIMS == 3 */
|
2019-02-13 11:44:51 -02:00
|
|
|
|
do j = 1, nn
|
|
|
|
|
do i = 1, nn
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
2017-03-06 11:12:25 -03:00
|
|
|
|
! get gravitational acceleration components
|
2014-04-29 18:35:58 -03:00
|
|
|
|
!
|
2017-03-07 15:47:22 -03:00
|
|
|
|
call gravitational_acceleration(t, dt, x(i), y(j), z(k), ga(1:3))
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
2017-03-06 11:12:25 -03:00
|
|
|
|
! calculate the gravitational source terms
|
2014-04-29 18:35:58 -03:00
|
|
|
|
!
|
2017-03-06 11:12:25 -03:00
|
|
|
|
gx = pdata%q(idn,i,j,k) * ga(1)
|
|
|
|
|
gy = pdata%q(idn,i,j,k) * ga(2)
|
2014-04-29 18:35:58 -03:00
|
|
|
|
#if NDIMS == 3
|
2017-03-06 11:12:25 -03:00
|
|
|
|
gz = pdata%q(idn,i,j,k) * ga(3)
|
2014-04-29 18:35:58 -03:00
|
|
|
|
#endif /* NDIMS == 3 */
|
|
|
|
|
|
|
|
|
|
! add source terms to momentum equations
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(imx,i,j,k) = pdata%du(imx,i,j,k) + gx
|
|
|
|
|
pdata%du(imy,i,j,k) = pdata%du(imy,i,j,k) + gy
|
2014-04-29 18:35:58 -03:00
|
|
|
|
#if NDIMS == 3
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(imz,i,j,k) = pdata%du(imz,i,j,k) + gz
|
2014-04-29 18:35:58 -03:00
|
|
|
|
#endif /* NDIMS == 3 */
|
|
|
|
|
|
|
|
|
|
! add source terms to total energy equation
|
|
|
|
|
!
|
2014-05-27 17:53:35 -03:00
|
|
|
|
if (ien > 0) then
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
|
|
|
|
#if NDIMS == 2
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ien,i,j,k) = pdata%du(ien,i,j,k) &
|
|
|
|
|
+ gx * pdata%q(ivx,i,j,k) &
|
|
|
|
|
+ gy * pdata%q(ivy,i,j,k)
|
2014-04-29 18:35:58 -03:00
|
|
|
|
#endif /* NDIMS == 2 */
|
|
|
|
|
#if NDIMS == 3
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ien,i,j,k) = pdata%du(ien,i,j,k) &
|
|
|
|
|
+ gx * pdata%q(ivx,i,j,k) &
|
|
|
|
|
+ gy * pdata%q(ivy,i,j,k) &
|
|
|
|
|
+ gz * pdata%q(ivz,i,j,k)
|
2014-04-29 18:35:58 -03:00
|
|
|
|
#endif /* NDIMS == 3 */
|
|
|
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
2019-02-13 11:44:51 -02:00
|
|
|
|
end do ! i = 1, nn
|
|
|
|
|
end do ! j = 1, nn
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#if NDIMS == 3
|
2019-02-13 11:44:51 -02:00
|
|
|
|
end do ! k = 1, nn
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#endif /* NDIMS == 3 */
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
2017-03-06 11:12:25 -03:00
|
|
|
|
end if ! gravity enabled
|
2014-04-29 18:35:58 -03:00
|
|
|
|
|
2014-05-27 17:53:35 -03:00
|
|
|
|
! proceed only if the viscosity coefficient is not zero
|
|
|
|
|
!
|
|
|
|
|
if (viscosity > 0.0d+00) then
|
|
|
|
|
|
2021-12-07 10:46:18 -03:00
|
|
|
|
if (work_in_use(nt)) &
|
2022-02-09 16:25:07 -03:00
|
|
|
|
call print_message(loc, "Workspace is being used right now! " // &
|
2021-11-19 12:39:36 -03:00
|
|
|
|
"Corruptions can occur!")
|
2021-11-12 11:53:43 -03:00
|
|
|
|
|
2021-12-07 10:46:18 -03:00
|
|
|
|
work_in_use(nt) = .true.
|
2021-11-12 11:53:43 -03:00
|
|
|
|
|
2014-05-27 17:53:35 -03:00
|
|
|
|
! prepare coordinate increments
|
|
|
|
|
!
|
2014-11-18 19:08:50 -02:00
|
|
|
|
dh(1) = adx(pdata%meta%level)
|
|
|
|
|
dh(2) = ady(pdata%meta%level)
|
|
|
|
|
dh(3) = adz(pdata%meta%level)
|
2014-05-27 17:53:35 -03:00
|
|
|
|
|
2014-11-18 19:08:50 -02:00
|
|
|
|
! calculate the velocity Jacobian
|
|
|
|
|
!
|
2019-02-05 11:17:59 -02:00
|
|
|
|
call gradient(dh(:), pdata%q(ivx,:,:,:), tmp(inx,inx:inz,:,:,:))
|
|
|
|
|
call gradient(dh(:), pdata%q(ivy,:,:,:), tmp(iny,inx:inz,:,:,:))
|
|
|
|
|
call gradient(dh(:), pdata%q(ivz,:,:,:), tmp(inz,inx:inz,:,:,:))
|
2014-11-18 19:08:50 -02:00
|
|
|
|
|
|
|
|
|
! iterate over all cells
|
2014-05-27 17:53:35 -03:00
|
|
|
|
!
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#if NDIMS == 3
|
2019-02-13 11:44:51 -02:00
|
|
|
|
do k = 1, nn
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#endif /* NDIMS == 3 */
|
2019-02-13 11:44:51 -02:00
|
|
|
|
do j = 1, nn
|
|
|
|
|
do i = 1, nn
|
2014-05-27 17:53:35 -03:00
|
|
|
|
|
2014-11-18 19:08:50 -02:00
|
|
|
|
! prepare the νρ factor
|
2014-05-27 17:53:35 -03:00
|
|
|
|
!
|
2014-11-18 19:08:50 -02:00
|
|
|
|
gc = viscosity * pdata%q(idn,i,j,k)
|
|
|
|
|
fc = 2.0d+00 * gc
|
2014-05-27 17:53:35 -03:00
|
|
|
|
|
2014-11-18 19:08:50 -02:00
|
|
|
|
! get the velocity Jacobian elements
|
2014-05-27 17:53:35 -03:00
|
|
|
|
!
|
2014-11-18 19:08:50 -02:00
|
|
|
|
dvxdx = tmp(inx,inx,i,j,k)
|
|
|
|
|
dvxdy = tmp(inx,iny,i,j,k)
|
|
|
|
|
dvxdz = tmp(inx,inz,i,j,k)
|
|
|
|
|
dvydx = tmp(iny,inx,i,j,k)
|
|
|
|
|
dvydy = tmp(iny,iny,i,j,k)
|
|
|
|
|
dvydz = tmp(iny,inz,i,j,k)
|
|
|
|
|
dvzdx = tmp(inz,inx,i,j,k)
|
|
|
|
|
dvzdy = tmp(inz,iny,i,j,k)
|
|
|
|
|
dvzdz = tmp(inz,inz,i,j,k)
|
|
|
|
|
divv = (dvxdx + dvydy + dvzdz) / 3.0d+00
|
2014-05-27 17:53:35 -03:00
|
|
|
|
|
2014-11-18 19:08:50 -02:00
|
|
|
|
! calculate elements of the viscous stress tensor
|
2014-05-27 17:53:35 -03:00
|
|
|
|
!
|
2014-11-18 19:08:50 -02:00
|
|
|
|
tmp(inx,inx,i,j,k) = fc * (dvxdx - divv)
|
|
|
|
|
tmp(iny,iny,i,j,k) = fc * (dvydy - divv)
|
|
|
|
|
tmp(inz,inz,i,j,k) = fc * (dvzdz - divv)
|
|
|
|
|
tmp(inx,iny,i,j,k) = gc * (dvxdy + dvydx)
|
|
|
|
|
tmp(inx,inz,i,j,k) = gc * (dvxdz + dvzdx)
|
|
|
|
|
tmp(iny,inz,i,j,k) = gc * (dvydz + dvzdy)
|
|
|
|
|
tmp(iny,inx,i,j,k) = tmp(inx,iny,i,j,k)
|
|
|
|
|
tmp(inz,inx,i,j,k) = tmp(inx,inz,i,j,k)
|
|
|
|
|
tmp(inz,iny,i,j,k) = tmp(iny,inz,i,j,k)
|
2014-05-27 17:53:35 -03:00
|
|
|
|
|
2019-02-13 11:44:51 -02:00
|
|
|
|
end do ! i = 1, nn
|
|
|
|
|
end do ! j = 1, nn
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#if NDIMS == 3
|
2019-02-13 11:44:51 -02:00
|
|
|
|
end do ! k = 1, nn
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#endif /* NDIMS == 3 */
|
2014-11-18 19:08:50 -02:00
|
|
|
|
|
|
|
|
|
! calculate the divergence of the first tensor row
|
2014-05-27 17:53:35 -03:00
|
|
|
|
!
|
2019-02-05 11:17:59 -02:00
|
|
|
|
call divergence(dh(:), tmp(inx,inx:inz,:,:,:), db(:,:,:))
|
2014-05-27 17:53:35 -03:00
|
|
|
|
|
2014-11-18 19:08:50 -02:00
|
|
|
|
! add viscous source terms to the X momentum equation
|
2014-05-27 17:53:35 -03:00
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(imx,:,:,:) = pdata%du(imx,:,:,:) + db(:,:,:)
|
2014-05-27 17:53:35 -03:00
|
|
|
|
|
2014-11-18 19:08:50 -02:00
|
|
|
|
! calculate the divergence of the second tensor row
|
2014-05-27 17:53:35 -03:00
|
|
|
|
!
|
2019-02-05 11:17:59 -02:00
|
|
|
|
call divergence(dh(:), tmp(iny,inx:inz,:,:,:), db(:,:,:))
|
2014-05-27 17:53:35 -03:00
|
|
|
|
|
2014-11-18 19:08:50 -02:00
|
|
|
|
! add viscous source terms to the Y momentum equation
|
2014-05-27 17:53:35 -03:00
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(imy,:,:,:) = pdata%du(imy,:,:,:) + db(:,:,:)
|
2014-05-27 17:53:35 -03:00
|
|
|
|
|
2014-11-18 19:08:50 -02:00
|
|
|
|
! calculate the divergence of the third tensor row
|
2014-05-27 17:53:35 -03:00
|
|
|
|
!
|
2019-02-05 11:17:59 -02:00
|
|
|
|
call divergence(dh(:), tmp(inz,inx:inz,:,:,:), db(:,:,:))
|
2014-05-27 17:53:35 -03:00
|
|
|
|
|
2014-11-18 19:08:50 -02:00
|
|
|
|
! add viscous source terms to the Z momentum equation
|
2014-05-27 17:53:35 -03:00
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(imz,:,:,:) = pdata%du(imz,:,:,:) + db(:,:,:)
|
2014-05-27 17:53:35 -03:00
|
|
|
|
|
|
|
|
|
! add viscous source term to total energy equation
|
|
|
|
|
!
|
2014-11-18 19:08:50 -02:00
|
|
|
|
if (ien > 0) then
|
2014-11-18 20:38:37 -02:00
|
|
|
|
|
|
|
|
|
! iterate over all cells
|
|
|
|
|
!
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#if NDIMS == 3
|
2019-02-13 11:44:51 -02:00
|
|
|
|
do k = 1, nn
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#endif /* NDIMS == 3 */
|
2019-02-13 11:44:51 -02:00
|
|
|
|
do j = 1, nn
|
|
|
|
|
do i = 1, nn
|
2014-11-18 20:38:37 -02:00
|
|
|
|
|
|
|
|
|
! calculate scalar product of v and viscous stress tensor τ
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
gx = pdata%q(ivx,i,j,k) * tmp(inx,inx,i,j,k) &
|
|
|
|
|
+ pdata%q(ivy,i,j,k) * tmp(inx,iny,i,j,k) &
|
2014-11-18 20:38:37 -02:00
|
|
|
|
+ pdata%q(ivz,i,j,k) * tmp(inx,inz,i,j,k)
|
2022-02-09 16:25:07 -03:00
|
|
|
|
gy = pdata%q(ivx,i,j,k) * tmp(iny,inx,i,j,k) &
|
|
|
|
|
+ pdata%q(ivy,i,j,k) * tmp(iny,iny,i,j,k) &
|
2014-11-18 20:38:37 -02:00
|
|
|
|
+ pdata%q(ivz,i,j,k) * tmp(iny,inz,i,j,k)
|
2022-02-09 16:25:07 -03:00
|
|
|
|
gz = pdata%q(ivx,i,j,k) * tmp(inz,inx,i,j,k) &
|
|
|
|
|
+ pdata%q(ivy,i,j,k) * tmp(inz,iny,i,j,k) &
|
2014-11-18 20:38:37 -02:00
|
|
|
|
+ pdata%q(ivz,i,j,k) * tmp(inz,inz,i,j,k)
|
|
|
|
|
|
|
|
|
|
! update (v.τ), use the first row of the tensor tmp
|
|
|
|
|
!
|
|
|
|
|
tmp(inx,inx,i,j,k) = gx
|
|
|
|
|
tmp(inx,iny,i,j,k) = gy
|
|
|
|
|
tmp(inx,inz,i,j,k) = gz
|
|
|
|
|
|
2019-02-13 11:44:51 -02:00
|
|
|
|
end do ! i = 1, nn
|
|
|
|
|
end do ! j = 1, nn
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#if NDIMS == 3
|
2019-02-13 11:44:51 -02:00
|
|
|
|
end do ! k = 1, nn
|
2019-02-05 11:17:59 -02:00
|
|
|
|
#endif /* NDIMS == 3 */
|
2014-11-18 20:38:37 -02:00
|
|
|
|
|
|
|
|
|
! calculate the divergence of (v.τ)
|
|
|
|
|
!
|
2019-02-05 11:17:59 -02:00
|
|
|
|
call divergence(dh(:), tmp(inx,inx:inz,:,:,:), db(:,:,:))
|
2014-11-18 20:38:37 -02:00
|
|
|
|
|
|
|
|
|
! update the energy increment
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ien,:,:,:) = pdata%du(ien,:,:,:) + db(:,:,:)
|
2014-11-18 20:38:37 -02:00
|
|
|
|
|
|
|
|
|
end if ! ien > 0
|
2014-05-27 17:53:35 -03:00
|
|
|
|
|
2021-12-07 10:46:18 -03:00
|
|
|
|
work_in_use(nt) = .false.
|
2021-11-12 11:53:43 -03:00
|
|
|
|
|
2014-05-27 17:53:35 -03:00
|
|
|
|
end if ! viscosity is not zero
|
|
|
|
|
|
2014-09-19 08:04:48 -03:00
|
|
|
|
!=== add magnetic field related source terms ===
|
2014-05-29 12:04:55 -03:00
|
|
|
|
!
|
2021-11-12 11:53:43 -03:00
|
|
|
|
if (magnetized) then
|
|
|
|
|
|
2021-12-07 10:46:18 -03:00
|
|
|
|
if (work_in_use(nt)) &
|
2022-02-09 16:25:07 -03:00
|
|
|
|
call print_message(loc, "Workspace is being used right now! " // &
|
2021-11-19 12:39:36 -03:00
|
|
|
|
"Corruptions can occur!")
|
2021-11-12 11:53:43 -03:00
|
|
|
|
|
2021-12-07 10:46:18 -03:00
|
|
|
|
work_in_use(nt) = .true.
|
2014-05-29 12:04:55 -03:00
|
|
|
|
|
|
|
|
|
! prepare coordinate increments
|
|
|
|
|
!
|
|
|
|
|
dh(1) = adx(pdata%meta%level)
|
|
|
|
|
dh(2) = ady(pdata%meta%level)
|
|
|
|
|
dh(3) = adz(pdata%meta%level)
|
|
|
|
|
|
2022-01-06 16:46:36 -03:00
|
|
|
|
! add the EGLM-MHD and KEPES source terms
|
2014-09-19 08:04:48 -03:00
|
|
|
|
!
|
|
|
|
|
if (glm_type > 0) then
|
|
|
|
|
|
|
|
|
|
! calculate the magnetic field divergence
|
|
|
|
|
!
|
|
|
|
|
call divergence(dh(:), pdata%q(ibx:ibz,:,:,:), db(:,:,:))
|
|
|
|
|
|
2024-07-30 16:46:29 -03:00
|
|
|
|
! update the momentum component increments, i.e.
|
2014-09-19 08:04:48 -03:00
|
|
|
|
! d/dt (ρv) + ∇.F = - (∇.B)B
|
|
|
|
|
!
|
2024-07-30 16:46:29 -03:00
|
|
|
|
pdata%du(imx,:,:,:) = pdata%du(imx,:,:,:) &
|
2022-02-09 16:25:07 -03:00
|
|
|
|
- db(:,:,:) * pdata%q(ibx,:,:,:)
|
2024-07-30 16:46:29 -03:00
|
|
|
|
pdata%du(imy,:,:,:) = pdata%du(imy,:,:,:) &
|
2022-02-09 16:25:07 -03:00
|
|
|
|
- db(:,:,:) * pdata%q(iby,:,:,:)
|
2024-07-30 16:46:29 -03:00
|
|
|
|
pdata%du(imz,:,:,:) = pdata%du(imz,:,:,:) &
|
2022-02-09 16:25:07 -03:00
|
|
|
|
- db(:,:,:) * pdata%q(ibz,:,:,:)
|
2022-01-22 11:57:01 -03:00
|
|
|
|
|
2022-01-06 16:46:36 -03:00
|
|
|
|
! add the HEGLM-MHD and KEPES source terms
|
2014-09-19 08:04:48 -03:00
|
|
|
|
!
|
|
|
|
|
if (glm_type > 1) then
|
|
|
|
|
|
|
|
|
|
! update magnetic field component increments, i.e.
|
|
|
|
|
! d/dt B + ∇.F = - (∇.B)v
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ibx,:,:,:) = pdata%du(ibx,:,:,:) &
|
|
|
|
|
- db(:,:,:) * pdata%q(ivx,:,:,:)
|
|
|
|
|
pdata%du(iby,:,:,:) = pdata%du(iby,:,:,:) &
|
|
|
|
|
- db(:,:,:) * pdata%q(ivy,:,:,:)
|
|
|
|
|
pdata%du(ibz,:,:,:) = pdata%du(ibz,:,:,:) &
|
|
|
|
|
- db(:,:,:) * pdata%q(ivz,:,:,:)
|
2014-09-19 08:04:48 -03:00
|
|
|
|
|
|
|
|
|
! update the energy equation
|
|
|
|
|
!
|
|
|
|
|
if (ien > 0) then
|
|
|
|
|
|
|
|
|
|
! calculate scalar product of velocity and magnetic field
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
tmp(inx,inx,:,:,:) = sum(pdata%q(ivx:ivz,:,:,:) &
|
|
|
|
|
* pdata%q(ibx:ibz,:,:,:), 1)
|
2014-09-19 08:04:48 -03:00
|
|
|
|
|
|
|
|
|
! add the divergence potential source term to the energy equation, i.e.
|
|
|
|
|
! d/dt E + ∇.F = - (∇.B) (v.B)
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ien,:,:,:) = pdata%du(ien,:,:,:) &
|
|
|
|
|
- db(:,:,:) * tmp(inx,inx,:,:,:)
|
2014-09-19 08:04:48 -03:00
|
|
|
|
|
|
|
|
|
end if ! ien > 0
|
|
|
|
|
|
|
|
|
|
end if ! glm_type > 1
|
|
|
|
|
|
2022-01-22 11:57:01 -03:00
|
|
|
|
if (ibp > 0) then
|
|
|
|
|
if (glm_type == 3) then
|
2022-01-06 16:46:36 -03:00
|
|
|
|
|
2022-01-22 11:57:01 -03:00
|
|
|
|
! calculate the divergence of velocity
|
2022-01-06 16:46:36 -03:00
|
|
|
|
!
|
2022-01-22 11:57:01 -03:00
|
|
|
|
call divergence(dh(:), pdata%q(ivx:ivz,:,:,:), db(:,:,:))
|
2022-01-06 16:46:36 -03:00
|
|
|
|
|
2022-01-22 11:57:01 -03:00
|
|
|
|
! add the divergence potential source term to the energy equation, i.e.
|
|
|
|
|
! d/dt ψ + ∇.F = ½ψ(∇.v)
|
2022-01-06 16:46:36 -03:00
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ibp,:,:,:) = pdata%du(ibp,:,:,:) &
|
2022-01-22 11:57:01 -03:00
|
|
|
|
+ 5.0d-01 * pdata%q(ibp,:,:,:) * db(:,:,:)
|
2022-01-06 16:46:36 -03:00
|
|
|
|
|
2022-01-22 11:57:01 -03:00
|
|
|
|
else if (ien > 0) then
|
2022-01-06 16:46:36 -03:00
|
|
|
|
|
2022-01-22 11:57:01 -03:00
|
|
|
|
! calculate the gradient of the divergence correcting field
|
2022-01-06 16:46:36 -03:00
|
|
|
|
!
|
2022-01-22 11:57:01 -03:00
|
|
|
|
call gradient(dh(:), pdata%q(ibp,:,:,:), tmp(inx:inz,inx,:,:,:))
|
2022-01-06 16:46:36 -03:00
|
|
|
|
|
2022-01-22 11:57:01 -03:00
|
|
|
|
db(:,:,:) = sum(pdata%q(ivx:ivz,:,:,:) * tmp(inx:inz,inx,:,:,:), 1)
|
|
|
|
|
|
|
|
|
|
! update the divergence correcting field
|
|
|
|
|
! d/dt ψ + ∇.F = - (v.∇)ψ
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ibp,:,:,:) = pdata%du(ibp,:,:,:) - db(:,:,:)
|
2022-01-06 16:46:36 -03:00
|
|
|
|
|
|
|
|
|
! add the divergence potential source term to the energy equation, i.e.
|
|
|
|
|
! d/dt E + ∇.F = - B.(∇ψ)
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ien,:,:,:) = pdata%du(ien,:,:,:) &
|
2022-01-22 11:57:01 -03:00
|
|
|
|
- sum(pdata%q(ibx:ibz,:,:,:) * tmp(inx:inz,inx,:,:,:), 1)
|
2022-01-06 16:46:36 -03:00
|
|
|
|
|
2022-01-22 11:57:01 -03:00
|
|
|
|
end if ! glm == 3
|
|
|
|
|
end if ! ibp
|
2022-01-06 16:46:36 -03:00
|
|
|
|
end if ! glm_type > 0
|
2014-09-19 08:04:48 -03:00
|
|
|
|
|
2019-02-25 09:53:05 -03:00
|
|
|
|
! if anomalous resistivity is enabled
|
|
|
|
|
!
|
|
|
|
|
if (anomalous > 0.0d+00) then
|
|
|
|
|
|
|
|
|
|
! calculate current density (J = ∇xB)
|
|
|
|
|
!
|
|
|
|
|
call curl(dh(:), pdata%q(ibx:ibz,:,:,:), tmp(inx:inz,inx,:,:,:))
|
|
|
|
|
|
|
|
|
|
! calculate the normalized absolute value of current density (|J|/Jcrit)
|
|
|
|
|
!
|
|
|
|
|
tmp(inx,iny,:,:,:) = sqrt(sum(tmp(inx:inz,inx,:,:,:)**2, 1)) / jcrit
|
|
|
|
|
|
|
|
|
|
! calculate the local resistivity [ηu + ηa (|J|/Jcrit - 1) H(|J|/Jcrit)]
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
tmp(iny,iny,:,:,:) = resistivity + &
|
2019-02-25 09:53:05 -03:00
|
|
|
|
anomalous * max(0.0d+00, (tmp(inx,iny,:,:,:) - 1.0d+00))
|
|
|
|
|
|
|
|
|
|
! multiply the current density vector by the local resistivity (ηJ)
|
2014-09-19 08:04:48 -03:00
|
|
|
|
!
|
2019-02-25 09:53:05 -03:00
|
|
|
|
tmp(inx,inz,:,:,:) = tmp(iny,iny,:,:,:) * tmp(inx,inx,:,:,:)
|
|
|
|
|
tmp(iny,inz,:,:,:) = tmp(iny,iny,:,:,:) * tmp(iny,inx,:,:,:)
|
|
|
|
|
tmp(inz,inz,:,:,:) = tmp(iny,iny,:,:,:) * tmp(inz,inx,:,:,:)
|
|
|
|
|
|
|
|
|
|
! calculate the curl of (ηJ)
|
|
|
|
|
!
|
|
|
|
|
call curl(dh(:), tmp(inx:inz,inz,:,:,:), tmp(inx:inz,iny,:,:,:))
|
|
|
|
|
|
|
|
|
|
! update magnetic field component increments
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ibx,:,:,:) = pdata%du(ibx,:,:,:) - tmp(inx,iny,:,:,:)
|
|
|
|
|
pdata%du(iby,:,:,:) = pdata%du(iby,:,:,:) - tmp(iny,iny,:,:,:)
|
|
|
|
|
pdata%du(ibz,:,:,:) = pdata%du(ibz,:,:,:) - tmp(inz,iny,:,:,:)
|
2019-02-25 09:53:05 -03:00
|
|
|
|
|
|
|
|
|
! update energy equation
|
|
|
|
|
!
|
|
|
|
|
if (ien > 0) then
|
|
|
|
|
|
|
|
|
|
! calculate the vector product Bx(η ∇xB)
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
tmp(inx,iny,:,:,:) = pdata%q(iby,:,:,:) * tmp(inz,inz,:,:,:) &
|
2019-02-25 09:53:05 -03:00
|
|
|
|
- pdata%q(ibz,:,:,:) * tmp(iny,inz,:,:,:)
|
2022-02-09 16:25:07 -03:00
|
|
|
|
tmp(iny,iny,:,:,:) = pdata%q(ibz,:,:,:) * tmp(inx,inz,:,:,:) &
|
2019-02-25 09:53:05 -03:00
|
|
|
|
- pdata%q(ibx,:,:,:) * tmp(inz,inz,:,:,:)
|
2022-02-09 16:25:07 -03:00
|
|
|
|
tmp(inz,iny,:,:,:) = pdata%q(ibx,:,:,:) * tmp(iny,inz,:,:,:) &
|
2019-02-25 09:53:05 -03:00
|
|
|
|
- pdata%q(iby,:,:,:) * tmp(inx,inz,:,:,:)
|
|
|
|
|
|
|
|
|
|
! calculate the divergence ∇.[Bx(η ∇xB)]
|
|
|
|
|
!
|
|
|
|
|
call divergence(dh(:), tmp(inx:inz,iny,:,:,:), db(:,:,:))
|
|
|
|
|
|
|
|
|
|
! add the second resistive source term to the energy equation, i.e.
|
|
|
|
|
! d/dt E + ∇.F = η J²
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ien,:,:,:) = pdata%du(ien,:,:,:) + db(:,:,:)
|
2019-02-25 09:53:05 -03:00
|
|
|
|
|
|
|
|
|
end if ! energy equation present
|
|
|
|
|
|
|
|
|
|
else if (resistivity > 0.0d+00) then
|
2014-09-19 08:04:48 -03:00
|
|
|
|
|
2014-11-19 19:14:24 -02:00
|
|
|
|
! calculate the Laplace operator of B, i.e. Δ(B)
|
2014-05-29 12:04:55 -03:00
|
|
|
|
!
|
2019-02-05 11:17:59 -02:00
|
|
|
|
call laplace(dh(:), pdata%q(ibx,:,:,:), tmp(inx,inx,:,:,:))
|
|
|
|
|
call laplace(dh(:), pdata%q(iby,:,:,:), tmp(inx,iny,:,:,:))
|
|
|
|
|
call laplace(dh(:), pdata%q(ibz,:,:,:), tmp(inx,inz,:,:,:))
|
2014-11-19 20:19:08 -02:00
|
|
|
|
|
|
|
|
|
! multiply by the resistivity coefficient
|
|
|
|
|
!
|
2019-02-05 11:17:59 -02:00
|
|
|
|
tmp(iny,inx:inz,:,:,:) = resistivity * tmp(inx,inx:inz,:,:,:)
|
2014-05-29 12:04:55 -03:00
|
|
|
|
|
|
|
|
|
! update magnetic field component increments
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ibx,:,:,:) = pdata%du(ibx,:,:,:) + tmp(iny,inx,:,:,:)
|
|
|
|
|
pdata%du(iby,:,:,:) = pdata%du(iby,:,:,:) + tmp(iny,iny,:,:,:)
|
|
|
|
|
pdata%du(ibz,:,:,:) = pdata%du(ibz,:,:,:) + tmp(iny,inz,:,:,:)
|
2014-05-29 12:04:55 -03:00
|
|
|
|
|
|
|
|
|
! update energy equation
|
|
|
|
|
!
|
2014-09-19 08:04:48 -03:00
|
|
|
|
if (ien > 0) then
|
2014-05-29 12:04:55 -03:00
|
|
|
|
|
2014-11-19 19:14:24 -02:00
|
|
|
|
! add the first resistive source term to the energy equation, i.e.
|
|
|
|
|
! d/dt E + ∇.F = η B.[Δ(B)]
|
2014-05-29 12:04:55 -03:00
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ien,:,:,:) = pdata%du(ien,:,:,:) &
|
|
|
|
|
+ (pdata%q(ibx,:,:,:) * tmp(iny,inx,:,:,:) &
|
|
|
|
|
+ pdata%q(iby,:,:,:) * tmp(iny,iny,:,:,:) &
|
|
|
|
|
+ pdata%q(ibz,:,:,:) * tmp(iny,inz,:,:,:))
|
2014-05-29 12:04:55 -03:00
|
|
|
|
|
2014-11-19 19:14:24 -02:00
|
|
|
|
! calculate current density J = ∇xB
|
2014-05-29 12:04:55 -03:00
|
|
|
|
!
|
2019-02-05 11:17:59 -02:00
|
|
|
|
call curl(dh(:), pdata%q(ibx:ibz,:,:,:), tmp(inz,inx:inz,:,:,:))
|
2014-05-29 12:04:55 -03:00
|
|
|
|
|
2017-03-29 10:40:31 -03:00
|
|
|
|
! calculate J²
|
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
db(:,:,:) = tmp(inz,inx,:,:,:)**2 &
|
|
|
|
|
+ tmp(inz,iny,:,:,:)**2 &
|
|
|
|
|
+ tmp(inz,inz,:,:,:)**2
|
2017-03-29 10:40:31 -03:00
|
|
|
|
|
2014-11-19 19:14:24 -02:00
|
|
|
|
! add the second resistive source term to the energy equation, i.e.
|
|
|
|
|
! d/dt E + ∇.F = η J²
|
2014-05-29 12:04:55 -03:00
|
|
|
|
!
|
2022-02-09 16:25:07 -03:00
|
|
|
|
pdata%du(ien,:,:,:) = pdata%du(ien,:,:,:) + resistivity * db(:,:,:)
|
2014-05-29 12:04:55 -03:00
|
|
|
|
|
2014-09-19 08:04:48 -03:00
|
|
|
|
end if ! energy equation present
|
|
|
|
|
|
|
|
|
|
end if ! resistivity is not zero
|
2014-05-29 12:04:55 -03:00
|
|
|
|
|
2021-12-07 10:46:18 -03:00
|
|
|
|
work_in_use(nt) = .false.
|
2021-11-12 11:53:43 -03:00
|
|
|
|
|
|
|
|
|
end if ! magnetized
|
2014-05-29 12:04:55 -03:00
|
|
|
|
|
2021-11-26 13:37:25 -03:00
|
|
|
|
! add extra source terms
|
2017-03-08 11:10:22 -03:00
|
|
|
|
!
|
2021-11-26 13:37:25 -03:00
|
|
|
|
if (associated(update_extra_sources)) &
|
2022-02-09 16:25:07 -03:00
|
|
|
|
call update_extra_sources(t, dt, pdata)
|
2017-03-08 11:10:22 -03:00
|
|
|
|
|
2021-11-12 11:53:43 -03:00
|
|
|
|
100 continue
|
|
|
|
|
|
2014-04-29 18:35:58 -03:00
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
|
!
|
|
|
|
|
end subroutine update_sources
|
|
|
|
|
|
|
|
|
|
!===============================================================================
|
|
|
|
|
!
|
|
|
|
|
end module sources
|