MPI-AMRVAC  3.0
The MPI - Adaptive Mesh Refinement - Versatile Advection Code
set_B0.t
Go to the documentation of this file.
1 subroutine set_b0_grid(igrid)
4 
5  integer, intent(in) :: igrid
6 
7  integer :: ixCoG^L
8 
9  ixcogmin^d=1;
10  ixcogmax^d=(ixghi^d-2*nghostcells)/2+2*nghostcells;
11 
12  call set_b0_cell(ps(igrid)%B0(ixg^t,:,0),ps(igrid)%x,ixg^ll,ixg^ll)
13  if(mhd_semirelativistic) call set_b0_cell(psc(igrid)%B0(ixcog^s,:,0),psc(igrid)%x,ixcog^l,ixcog^l)
14  call set_j0_cell(igrid,ps(igrid)%J0,ixg^ll,ixm^ll^ladd1)
15  call set_b0_face(igrid,ps(igrid)%x,ixg^ll,ixm^ll)
16 
17 end subroutine set_b0_grid
18 
19 subroutine set_b0_cell(wB0,x,ixI^L,ix^L)
20  use mod_usr_methods, only: usr_set_b0
22  use mod_geometry
23 
24  integer, intent(in):: ixI^L,ix^L
25  double precision, intent(inout) :: wB0(ixI^S,1:ndir)
26  double precision, intent(in) :: x(ixI^S,1:ndim)
27 
28  wb0(ix^s,1:ndir)=zero
29 
30  ! approximate cell-averaged B0 as cell-centered B0
31  select case (coordinate)
32  case (spherical)
33  {^nooned
34  if (dabs(bdip)>smalldouble) then
35  wb0(ix^s,1)=2.0d0*bdip*dcos(x(ix^s,2))/x(ix^s,1)**3
36  wb0(ix^s,2)=bdip*dsin(x(ix^s,2))/x(ix^s,1)**3
37  end if
38 
39  if (abs(bquad)>smalldouble) then
40  wb0(ix^s,1)=wb0(ix^s,1) &
41  +bquad*0.5d0*(1.0d0+3.0d0*dcos(2.0d0*x(ix^s,2)))/x(ix^s,1)**4
42  wb0(ix^s,2)=wb0(ix^s,2)+bquad*dsin(2.0d0*x(ix^s,2))/x(ix^s,1)**4
43  end if
44  if (abs(boct)>smalldouble) then
45  wb0(ix^s,1)=wb0(ix^s,1) &
46  +boct*(10.0d0*dcos(2.0d0*x(ix^s,2))-2.0d0) &
47  *dcos(x(ix^s,2))/x(ix^s,1)**5
48  wb0(ix^s,2)=wb0(ix^s,2) &
49  +boct*1.5d0*(3.0d0+5.0d0*dcos(2.0d0*x(ix^s,2))) &
50  *dsin(x(ix^s,2))/x(ix^s,1)**5
51  end if
52  }
53  end select
54 
55  if (associated(usr_set_b0)) call usr_set_b0(ixi^l,ix^l,x,wb0)
56 
57 end subroutine set_b0_cell
58 
59 subroutine set_j0_cell(igrid,wJ0,ixI^L,ix^L)
60  use mod_usr_methods, only: usr_set_j0
62  use mod_geometry
63 
64  integer, intent(in):: igrid,ixI^L,ix^L
65  double precision, intent(inout) :: wJ0(ixI^S,7-2*ndir:3)
66  integer :: idirmin0, idirmin
67 
68  if(associated(usr_set_j0)) then
69  call usr_set_j0(ixi^l,ix^l,ps(igrid)%x,wj0)
70  else
71  idirmin0 = 7-2*ndir
72  call curlvector(ps(igrid)%B0(ixi^s,:,0),ixi^l,ix^l,wj0,idirmin,idirmin0,ndir)
73  end if
74 
75 end subroutine set_j0_cell
76 
77 subroutine set_b0_face(igrid,x,ixI^L,ixO^L)
79 
80  integer, intent(in) :: igrid, ixI^L, ixO^L
81  double precision, intent(in) :: x(ixI^S,1:ndim)
82 
83  double precision :: delx(ixI^S,1:ndim)
84  double precision :: xC(ixI^S,1:ndim),xshift^D
85  integer :: idims, ixC^L, hxO^L, ix, idims2
86 
87  if(slab_uniform)then
88  ^d&delx(ixi^s,^d)=rnode(rpdx^d_,igrid)\
89  else
90  ! for all non-cartesian and stretched cartesian coordinates
91  delx(ixi^s,1:ndim)=ps(igrid)%dx(ixi^s,1:ndim)
92  endif
93 
94 
95  do idims=1,ndim
96  hxo^l=ixo^l-kr(idims,^d);
97  if(stagger_grid) then
98  ! ct needs all transverse cells
99  ixcmax^d=ixomax^d+nghostcells-nghostcells*kr(idims,^d); ixcmin^d=hxomin^d-nghostcells+nghostcells*kr(idims,^d);
100  else
101  ! ixC is centered index in the idims direction from ixOmin-1/2 to ixOmax+1/2
102  ixcmax^d=ixomax^d; ixcmin^d=hxomin^d;
103  end if
104  ! always xshift=0 or 1/2
105  xshift^d=half*(one-kr(^d,idims));
106  do idims2=1,ndim
107  select case(idims2)
108  {case(^d)
109  do ix = ixc^lim^d
110  ! xshift=half: this is the cell center coordinate
111  ! xshift=0: this is the cell edge i+1/2 coordinate
112  xc(ix^d%ixC^s,^d)=x(ix^d%ixC^s,^d)+(half-xshift^d)*delx(ix^d%ixC^s,^d)
113  end do\}
114  end select
115  end do
116  call set_b0_cell(ps(igrid)%B0(ixi^s,:,idims),xc,ixi^l,ixc^l)
117  end do
118 
119 end subroutine set_b0_face
Module with geometry-related routines (e.g., divergence, curl)
Definition: mod_geometry.t:2
integer coordinate
Definition: mod_geometry.t:6
integer, parameter spherical
Definition: mod_geometry.t:10
subroutine curlvector(qvec, ixIL, ixOL, curlvec, idirmin, idirmin0, ndir0, fourthorder)
Calculate curl of a vector qvec within ixL Options to employ standard second order CD evaluations use...
Definition: mod_geometry.t:626
This module contains definitions of global parameters and variables and some generic functions/subrou...
integer ixghi
Upper index of grid block arrays.
integer, dimension(3, 3) kr
Kronecker delta tensor.
logical stagger_grid
True for using stagger grid.
double precision bdip
amplitude of background dipolar, quadrupolar, octupolar, user's field
integer, dimension(:), allocatable, parameter d
integer ixm
the mesh range (within a block with ghost cells)
double precision, dimension(:,:), allocatable rnode
Corner coordinates.
integer nghostcells
Number of ghost cells surrounding a grid.
logical slab_uniform
uniform Cartesian geometry or not (stretched Cartesian)
Magneto-hydrodynamics module.
Definition: mod_mhd_phys.t:2
logical, public, protected mhd_semirelativistic
Whether semirelativistic MHD equations (Gombosi 2002 JCP) are solved.
Definition: mod_mhd_phys.t:90
Module with all the methods that users can customize in AMRVAC.
procedure(set_j0), pointer usr_set_j0
procedure(set_b0), pointer usr_set_b0
subroutine set_b0_grid(igrid)
Definition: set_B0.t:2
subroutine set_b0_cell(wB0, x, ixIL, ixL)
Definition: set_B0.t:20
subroutine set_j0_cell(igrid, wJ0, ixIL, ixL)
Definition: set_B0.t:60
subroutine set_b0_face(igrid, x, ixIL, ixOL)
Definition: set_B0.t:78