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 public :: add_split_source
15 public :: addsource2
16
17contains
18
19 subroutine add_split_source(prior)
26 use mod_comm_lib, only: mpistop
28
29 logical, intent(in) :: prior
30 ! This variable, later allocated on the thread stack, causes segmentation fault
31 ! when openmp is used with intel. That could be solved otherwise, by increasing
32 ! the thread stack size, but not using it at all could speed up.
33 double precision :: w1(ixg^t,1:nw)
34 double precision :: qt, tsts(3)
35 integer :: iigrid, igrid
36 logical :: src_active
37
38 ! add stiff source terms via super time stepping
39 if(is_sts_initialized()) then
40 call timer_open(tsts)
41 select case (sourcetype_sts)
43 if(prior) then
44 call sts_add_source(dt)
45 end if
47 if(.not. prior) then
48 call sts_add_source(dt)
49 end if
51 call sts_add_source(0.5d0*dt)
52 end select
54 end if
55 src_active = .false.
56
57 if ((.not.prior).and.&
59
60 if (prior) then
62 else
64 end if
65
66 if(any_source_split) then
67 ! add normal split source terms
68 select case (sourcesplit)
69 case (sourcesplit_sfs)
70 !$OMP PARALLEL DO PRIVATE(igrid,w1)
71 do iigrid=1,igridstail_active; igrid=igrids_active(iigrid);
72 block=>ps(igrid)
73 ^d&dxlevel(^d)=rnode(rpdx^d_,igrid);
74 w1=ps(igrid)%w
75 call phys_to_primitive(ixg^ll,ixg^ll,w1,ps(igrid)%x)
76 call addsource2(0.5d0*dt,0.5d0,ixg^ll,ixm^ll,1,nw,qt,ps(igrid)%w,w1,qt,ps(igrid)%w,&
77 ps(igrid)%x,.true.,src_active)
78 end do
79 !$OMP END PARALLEL DO
80 case (sourcesplit_sf)
81 !$OMP PARALLEL DO PRIVATE(igrid,w1)
82 do iigrid=1,igridstail_active; igrid=igrids_active(iigrid);
83 block=>ps(igrid)
84 ^d&dxlevel(^d)=rnode(rpdx^d_,igrid);
85 w1=ps(igrid)%w
86 call phys_to_primitive(ixg^ll,ixg^ll,w1,ps(igrid)%x)
87 call addsource2(dt ,1d0,ixg^ll,ixm^ll,1,nw,qt,ps(igrid)%w,w1,qt,ps(igrid)%w,&
88 ps(igrid)%x,.true.,src_active)
89 end do
90 !$OMP END PARALLEL DO
91 case (sourcesplit_ssf)
92 !$OMP PARALLEL DO PRIVATE(igrid,w1)
93 do iigrid=1,igridstail_active; igrid=igrids_active(iigrid);
94 block=>ps(igrid)
95 ^d&dxlevel(^d)=rnode(rpdx^d_,igrid);
96 w1=ps(igrid)%w
97 call phys_to_primitive(ixg^ll,ixg^ll,w1,ps(igrid)%x)
98 call addsource2(0.5d0*dt,0.5d0,ixg^ll,ixg^ll,1,nw,qt,ps(igrid)%w,w1,qt,ps(igrid)%w,&
99 ps(igrid)%x,.true.,src_active)
100 call addsource2(dt ,1d0,ixg^ll,ixm^ll,1,nw,qt,ps(igrid)%w,w1,qt,ps(igrid)%w,&
101 ps(igrid)%x,.true.,src_active)
102 end do
103 !$OMP END PARALLEL DO
104 case (sourcesplit_ssfss)
105 !$OMP PARALLEL DO PRIVATE(igrid,w1)
106 do iigrid=1,igridstail_active; igrid=igrids_active(iigrid);
107 block=>ps(igrid)
108 ^d&dxlevel(^d)=rnode(rpdx^d_,igrid);
109 w1=ps(igrid)%w
110 call phys_to_primitive(ixg^ll,ixg^ll,w1,ps(igrid)%x)
111 call addsource2(0.25d0*dt,0.25d0,ixg^ll,ixg^ll,1,nw,qt,ps(igrid)%w,w1,qt,ps(igrid)%w,&
112 ps(igrid)%x,.true.,src_active)
113 call addsource2(0.5d0*dt,0.5d0,ixg^ll,ixm^ll,1,nw,qt,ps(igrid)%w,w1,qt,ps(igrid)%w,&
114 ps(igrid)%x,.true.,src_active)
115 end do
116 !$OMP END PARALLEL DO
117 case default
118 write(unitterm,*)'No such type of sourcesplit=',sourcesplit
119 call mpistop("Error: Unknown type of sourcesplit!")
120 end select
121 end if
122
123 if (.not. prior .and. associated(phys_global_source_after)) then
124 call phys_global_source_after(dt, qt, src_active)
125 end if
126
127 if (src_active) then
128 call getbc(qt,0.d0,ps,iwstart,nwgc)
129 ! update eos variables: Te (nH) including ghost cells
130 call prepare_eos_w_fields(ps)
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.
Equation of state for AMRVAC, handled through a single eos_container object.
Definition mod_eos.t:30
subroutine, public prepare_eos_w_fields(psx)
Definition mod_eos.t:404
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
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
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:20
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
double precision time_sts
Definition mod_timing.t:19
subroutine timer_open(t0)
Open a timing window, whose length leaves out the EoS and ghost-cell time spent inside it,...
Definition mod_timing.t:66
double precision function timer_close(t0)
Wall time since timer_open, less the EoS and ghost-cell time spent in between.
Definition mod_timing.t:73
Module with all the methods that users can customize in AMRVAC.
procedure(source), pointer usr_source_after
procedure(source), pointer usr_source