MPI-AMRVAC 3.2
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
Loading...
Searching...
No Matches
mod_source.t
Go to the documentation of this file.
1!> Module for handling split source terms (split from the fluxes)
3 implicit none
4 public
5
6 !> How to apply dimensional splitting to the source terms, see
7 !> @ref discretization.md
8 integer :: sourcesplit =-1
9 integer, parameter :: sourcesplit_sfs = 0
10 integer, parameter :: sourcesplit_sf = 1
11 integer, parameter :: sourcesplit_ssf = 2
12 integer, parameter :: sourcesplit_ssfss = 3
13
14 double precision, save :: time_sts_total = 0.d0
15 double precision :: tw_sts0
16
17 public :: add_split_source
18 public :: addsource2
19 public :: time_sts_total
20
21contains
22
23 subroutine add_split_source(prior)
29 use mod_comm_lib, only: mpistop
30
31 logical, intent(in) :: prior
32 ! This variable, later allocated on the thread stack, causes segmentation fault
33 ! when openmp is used with intel. That could be solved otherwise, by increasing
34 ! the thread stack size, but not using it at all could speed up.
35 double precision :: w1(ixg^t,1:nw)
36 double precision :: qt
37 integer :: iigrid, igrid
38 logical :: src_active
39
40 ! add stiff source terms via super time stepping
41 if(is_sts_initialized()) then
42 tw_sts0 = mpi_wtime()
43 select case (sourcetype_sts)
45 if(prior) then
46 call sts_add_source(dt)
47 end if
49 if(.not. prior) then
50 call sts_add_source(dt)
51 end if
53 call sts_add_source(0.5d0*dt)
54 end select
55 time_sts_total = time_sts_total + (mpi_wtime() - tw_sts0)
56 end if
57 src_active = .false.
58
59 if ((.not.prior).and.&
61
62 if (prior) then
64 else
66 end if
67
68 if(any_source_split) then
69 ! add normal split source terms
70 select case (sourcesplit)
71 case (sourcesplit_sfs)
72 !$OMP PARALLEL DO PRIVATE(igrid,w1)
73 do iigrid=1,igridstail_active; igrid=igrids_active(iigrid);
74 block=>ps(igrid)
75 ^d&dxlevel(^d)=rnode(rpdx^d_,igrid);
76 w1=ps(igrid)%w
77 call phys_to_primitive(ixg^ll,ixg^ll,w1,ps(igrid)%x)
78 call addsource2(0.5d0*dt,0.5d0,ixg^ll,ixm^ll,1,nw,qt,ps(igrid)%w,w1,qt,ps(igrid)%w,&
79 ps(igrid)%x,.true.,src_active)
80 end do
81 !$OMP END PARALLEL DO
82 case (sourcesplit_sf)
83 !$OMP PARALLEL DO PRIVATE(igrid,w1)
84 do iigrid=1,igridstail_active; igrid=igrids_active(iigrid);
85 block=>ps(igrid)
86 ^d&dxlevel(^d)=rnode(rpdx^d_,igrid);
87 w1=ps(igrid)%w
88 call phys_to_primitive(ixg^ll,ixg^ll,w1,ps(igrid)%x)
89 call addsource2(dt ,1d0,ixg^ll,ixm^ll,1,nw,qt,ps(igrid)%w,w1,qt,ps(igrid)%w,&
90 ps(igrid)%x,.true.,src_active)
91 end do
92 !$OMP END PARALLEL DO
93 case (sourcesplit_ssf)
94 !$OMP PARALLEL DO PRIVATE(igrid,w1)
95 do iigrid=1,igridstail_active; igrid=igrids_active(iigrid);
96 block=>ps(igrid)
97 ^d&dxlevel(^d)=rnode(rpdx^d_,igrid);
98 w1=ps(igrid)%w
99 call phys_to_primitive(ixg^ll,ixg^ll,w1,ps(igrid)%x)
100 call addsource2(0.5d0*dt,0.5d0,ixg^ll,ixg^ll,1,nw,qt,ps(igrid)%w,w1,qt,ps(igrid)%w,&
101 ps(igrid)%x,.true.,src_active)
102 call addsource2(dt ,1d0,ixg^ll,ixm^ll,1,nw,qt,ps(igrid)%w,w1,qt,ps(igrid)%w,&
103 ps(igrid)%x,.true.,src_active)
104 end do
105 !$OMP END PARALLEL DO
106 case (sourcesplit_ssfss)
107 !$OMP PARALLEL DO PRIVATE(igrid,w1)
108 do iigrid=1,igridstail_active; igrid=igrids_active(iigrid);
109 block=>ps(igrid)
110 ^d&dxlevel(^d)=rnode(rpdx^d_,igrid);
111 w1=ps(igrid)%w
112 call phys_to_primitive(ixg^ll,ixg^ll,w1,ps(igrid)%x)
113 call addsource2(0.25d0*dt,0.25d0,ixg^ll,ixg^ll,1,nw,qt,ps(igrid)%w,w1,qt,ps(igrid)%w,&
114 ps(igrid)%x,.true.,src_active)
115 call addsource2(0.5d0*dt,0.5d0,ixg^ll,ixm^ll,1,nw,qt,ps(igrid)%w,w1,qt,ps(igrid)%w,&
116 ps(igrid)%x,.true.,src_active)
117 end do
118 !$OMP END PARALLEL DO
119 case default
120 write(unitterm,*)'No such type of sourcesplit=',sourcesplit
121 call mpistop("Error: Unknown type of sourcesplit!")
122 end select
123 end if
124
125 if (.not. prior .and. associated(phys_global_source_after)) then
126 call phys_global_source_after(dt, qt, src_active)
127 end if
128
129 if (src_active) then
130 call getbc(qt,0.d0,ps,iwstart,nwgc)
131 end if
132
133 end subroutine add_split_source
134
135 !> Add source within ixO for iws: w=w+qdt*S[wCT]
136 subroutine addsource2(qdt,dtfactor,ixI^L,ixO^L,iw^LIM,qtC,wCT,wCTprim,qt,&
137 w,x,qsourcesplit,src_active)
141 ! differences with VAC is in iw^LIM and in declaration of ranges for wCT,w
142
143 integer, intent(in) :: ixi^l, ixo^l, iw^lim
144 double precision, intent(in) :: qdt, dtfactor, qtc, qt
145 double precision, intent(in) :: wct(ixi^s,1:nw), wctprim(ixi^s,1:nw), x(ixi^s,1:ndim)
146 double precision, intent(inout) :: w(ixi^s,1:nw)
147 logical, intent(in) :: qsourcesplit
148 logical, intent(inout), optional :: src_active
149
150 logical :: tmp_active
151
152 tmp_active = .false.
153
154 ! user defined sources, typically explicitly added
155 if ((qsourcesplit .eqv. source_split_usr) .and. associated(usr_source)) then
156 tmp_active = .true.
157 call usr_source(qdt,ixi^l,ixo^l,iw^lim,qtc,wct,qt,w,x)
158 end if
159
160 ! physics defined sources, typically explicitly added,
161 ! along with geometrical source additions
162 call phys_add_source(qdt,dtfactor,ixi^l,ixo^l,wct,wctprim,w,x,qsourcesplit,tmp_active)
163
164 ! user post-physics source (runs after gravity etc.)
165 if ((qsourcesplit .eqv. source_split_usr) .and. associated(usr_source_after)) then
166 call usr_source_after(qdt,ixi^l,ixo^l,iw^lim,qtc,wct,qt,w,x)
167 end if
168
169 if (present(src_active)) src_active = src_active .or. tmp_active
170
171 end subroutine addsource2
172
173end module mod_source
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
update ghost cells of all blocks including physical boundaries
subroutine getbc(time, qdt, psb, nwstart, nwbc)
do update ghost cells of all blocks including physical boundaries
This module contains definitions of global parameters and variables and some generic functions/subrou...
type(state), pointer block
Block pointer for using one block and its previous state.
logical source_split_usr
Use split or unsplit way to add user's source terms, default: unsplit.
logical any_source_split
if any normal source term is added in split fasion
double precision global_time
The global simulation time.
integer, parameter ndim
Number of spatial dimensions for grid variables.
double precision dt
global time step
double precision, dimension(:), allocatable, parameter d
integer, parameter unitterm
Unit for standard output.
double precision, dimension(:,:), allocatable rnode
Corner coordinates.
double precision, dimension(^nd) dxlevel
store unstretched cell size of current level
This module defines the procedures of a physics module. It contains function pointers for the various...
Definition mod_physics.t:4
procedure(sub_convert), pointer phys_to_primitive
Definition mod_physics.t:52
procedure(sub_global_source), pointer phys_global_source_after
Definition mod_physics.t:74
procedure(sub_add_source), pointer phys_add_source
Definition mod_physics.t:73
Module for handling split source terms (split from the fluxes)
Definition mod_source.t:2
integer sourcesplit
How to apply dimensional splitting to the source terms, see Discretization.
Definition mod_source.t:8
integer, parameter sourcesplit_ssf
Definition mod_source.t:11
double precision, save, public time_sts_total
Definition mod_source.t:14
subroutine, public addsource2(qdt, dtfactor, ixil, ixol, iwlim, qtc, wct, wctprim, qt, w, x, qsourcesplit, src_active)
Add source within ixO for iws: w=w+qdt*S[wCT].
Definition mod_source.t:138
integer, parameter sourcesplit_ssfss
Definition mod_source.t:12
double precision tw_sts0
Definition mod_source.t:15
integer, parameter sourcesplit_sfs
Definition mod_source.t:9
integer, parameter sourcesplit_sf
Definition mod_source.t:10
subroutine, public add_split_source(prior)
Definition mod_source.t:24
Generic supertimestepping method which can be used for multiple source terms in the governing equatio...
pure logical function, public is_sts_initialized()
integer, parameter, public sourcetype_sts_prior
integer, parameter, public sourcetype_sts_split
integer, parameter, public sourcetype_sts_after
procedure(subr3), pointer, public sts_add_source
Module with all the methods that users can customize in AMRVAC.
procedure(source), pointer usr_source_after
procedure(source), pointer usr_source