sources_generic.f90
Go to the documentation of this file.
1!#############################################################################
2!# #
3!# fosite - 3D hydrodynamical simulation program #
4!# module: mesh_generic.f90 #
5!# #
6!# Copyright (C) 2016-2024 #
7!# Manuel Jung <mjung@astrophysik.uni-kiel.de> #
8!# Tobias Illenseer <tillense@astrophysik.uni-kiel.de> #
9!# #
10!# This program is free software; you can redistribute it and/or modify #
11!# it under the terms of the GNU General Public License as published by #
12!# the Free Software Foundation; either version 2 of the License, or (at #
13!# your option) any later version. #
14!# #
15!# This program is distributed in the hope that it will be useful, but #
16!# WITHOUT ANY WARRANTY; without even the implied warranty of #
17!# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or #
18!# NON INFRINGEMENT. See the GNU General Public License for more #
19!# details. #
20!# #
21!# You should have received a copy of the GNU General Public License #
22!# along with this program; if not, write to the Free Software #
23!# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
24!# #
25!#############################################################################
26!----------------------------------------------------------------------------!
36!----------------------------------------------------------------------------!
53 USE common_dict
54 IMPLICIT NONE
55 !--------------------------------------------------------------------------!
56 PRIVATE
58 TYPE, EXTENDS(sources_base) :: sources_list
60 CLASS(marray_compound), POINTER :: sterm => null()
61
62 CONTAINS
64 PROCEDURE :: initsources
65 PROCEDURE :: externalsources
66 PROCEDURE :: calctimestep
67 final :: finalize
68 END TYPE sources_list
69 !--------------------------------------------------------------------------!
70 ! flags for source terms
71 INTEGER, PARAMETER :: list = 0
72 INTEGER, PARAMETER :: gravity = 1
73! INTEGER, PARAMETER :: DISK_THOMSON = 2
74 INTEGER, PARAMETER :: viscosity = 3
75 INTEGER, PARAMETER :: c_accel = 4
76 INTEGER, PARAMETER :: cooling = 5
77 INTEGER, PARAMETER :: rotating_frame = 20
78! INTEGER, PARAMETER :: SGS = 23
79 INTEGER, PARAMETER :: disk_cooling = 24
80! INTEGER, PARAMETER :: WAVE_DAMPING = 25
81! INTEGER, PARAMETER :: FORCING = 26
82 INTEGER, PARAMETER :: planet_heating = 27
83 INTEGER, PARAMETER :: planet_cooling = 28
84! INTEGER, PARAMETER :: STELLAR_HEATING = 29
85 INTEGER, PARAMETER :: shearbox = 30
86 !--------------------------------------------------------------------------!
87 PUBLIC :: &
88 ! types
90
91 ! constants
96
97
98CONTAINS
99
100 SUBROUTINE initsources(this,Mesh,Physics,Fluxes,config,IO)
101 IMPLICIT NONE
102 !------------------------------------------------------------------------!
103 CLASS(sources_list), INTENT(INOUT) :: this
104 CLASS(mesh_base), INTENT(IN) :: Mesh
105 CLASS(physics_base), INTENT(IN) :: Physics
106 CLASS(fluxes_base), INTENT(IN) :: Fluxes
107 TYPE(dict_typ), POINTER :: config, IO
108 !------------------------------------------------------------------------!
109 CLASS(sources_base), POINTER :: newsrc => null(), tmpsrc => null()
110 TYPE(dict_typ), POINTER :: dir,next,src,IOsrc,gsrc => null(),gdir => null()
111 INTEGER :: update_disk_height = 0
112 INTEGER :: stype
113 !------------------------------------------------------------------------!
114 IF (.NOT.physics%Initialized().OR..NOT.mesh%Initialized()) &
115 CALL this%Error("sources_generic::InitSources","physics and/or mesh module uninitialized")
116 IF (this%Initialized()) &
117 CALL this%Error("sources_generic::InitSources","list of source term already initialized")
118
119 CALL this%InitLogging(list,"sources list")
120
121 ALLOCATE(this%sterm,stat=this%err)
122 IF (this%err.NE.0) &
123 CALL this%Error("sources_generic::InitSources","memory allocation failed")
124
125 CALL physics%new_statevector(this%sterm,conservative)
126
127 dir => config
128 DO WHILE(ASSOCIATED(dir))
129 NULLIFY(iosrc)
130 IF(haschild(dir)) THEN
131 src => getchild(dir)
132 CALL getattr(src, "stype", stype)
133
134 ! object creation
135 SELECT CASE(stype)
136 CASE(gravity)
137 ! skip initialization of gravity modules here and initialize them
138 ! at the end to make sure gravity is the first source term in the list
139 gsrc => src
140 gdir => dir
141 NULLIFY(newsrc)
142 CASE(c_accel)
143 ALLOCATE(sources_c_accel::newsrc)
144 CASE(cooling)
145 ALLOCATE(sources_cooling::newsrc)
146 CASE(disk_cooling)
147 ALLOCATE(sources_diskcooling::newsrc)
148 CASE(planet_heating)
149 ALLOCATE(sources_planetheating::newsrc)
150 CASE(planet_cooling)
151 ALLOCATE(sources_planetcooling::newsrc)
152 CASE(rotating_frame)
153 tmpsrc => this%GetSourcesPointer(rotating_frame)
154 IF (ASSOCIATED(tmpsrc)) &
155 CALL this%Error("sources_generic::InitSources","only one rotating frame source term allowed")
156 ALLOCATE(sources_rotframe::newsrc)
157 CASE(shearbox)
158 tmpsrc => this%GetSourcesPointer(shearbox)
159 IF (ASSOCIATED(tmpsrc)) &
160 CALL this%Error("sources_generic::InitSources","only one shearing box source term allowed")
161 ALLOCATE(sources_shearbox::newsrc)
162 CASE(viscosity)
163 ALLOCATE(sources_viscosity::newsrc)
164 CASE DEFAULT
165 CALL this%Error("sources_generic::InitSources","Unknown source type")
166 END SELECT
167
168 ! basic initialization of all source terms except gravity
169 IF (ASSOCIATED(newsrc)) THEN
170 CALL newsrc%InitSources(mesh,physics,fluxes,src,iosrc)
171 SELECT TYPE(obj => newsrc)
172 TYPE IS (sources_diskcooling)
173 IF (obj%cooling%GetType().EQ.gray) update_disk_height = 1
174 TYPE IS (sources_viscosity)
175 IF (obj%viscosity%GetType().EQ.alpha_alt) update_disk_height = 1
176 END SELECT
177
178 ! prepend new source term to list
179 newsrc%next => this%next
180 this%next => newsrc
181 END IF
182
183 ! process the output dictionary
184 IF(ASSOCIATED(iosrc)) CALL setattr(io, getkey(dir), iosrc)
185
186 END IF
187 dir => getnext(dir)
188 END DO
189
190 ! finally initialize gravity
191 IF(ASSOCIATED(gsrc)) THEN
192 NULLIFY(iosrc)
193
194 ALLOCATE(sources_gravity::newsrc)
195 IF (ASSOCIATED(newsrc)) THEN
196 CALL setattr(gsrc,"update_disk_height", update_disk_height)
197 CALL newsrc%InitSources(mesh,physics,fluxes,gsrc,iosrc)
198 ! prepend new source term to list
199 newsrc%next => this%next
200 this%next => newsrc
201 ! check for disk cooling source term and set pointer to gravity source
202 tmpsrc => this%GetSourcesPointer(disk_cooling)
203 IF (ASSOCIATED(tmpsrc)) THEN
204 SELECT TYPE(sp => tmpsrc)
205 CLASS IS(sources_diskcooling)
206 SELECT TYPE(grav => newsrc)
207 CLASS IS(sources_gravity)
208 sp%grav => grav
209 END SELECT
210 END SELECT
211 END IF
212 END IF
213
214 IF(ASSOCIATED(iosrc)) CALL setattr(io, getkey(gdir), iosrc)
215 END IF
216
217 END SUBROUTINE initsources
218
219
220 SUBROUTINE externalsources(this,Mesh,Physics,Fluxes,Sources,time,dt,pvar,cvar,sterm)
221 IMPLICIT NONE
222 !------------------------------------------------------------------------!
223 CLASS(sources_list), INTENT(INOUT) :: this
224 CLASS(mesh_base), INTENT(IN) :: Mesh
225 CLASS(physics_base), INTENT(INOUT) :: Physics
226 CLASS(fluxes_base), INTENT(IN) :: Fluxes
227 CLASS(sources_base), INTENT(INOUT) :: Sources
228 REAL, INTENT(IN) :: time,dt
229 CLASS(marray_compound), INTENT(INOUT) :: pvar,cvar,sterm
230 !------------------------------------------------------------------------!
231 CLASS(sources_base), POINTER :: srcptr
232 !------------------------------------------------------------------------!
233 ! reset sterm
234 sterm%data1d(:) = 0.0
235 ! go through all source terms in the list
236 srcptr => this%next
237 DO WHILE (ASSOCIATED(srcptr))
238
239 CALL srcptr%ExternalSources(mesh,physics,fluxes,this,time,dt,pvar,cvar,this%sterm)
240
241 ! add to the sources
242 sterm%data1d(:) = sterm%data1d(:) + this%sterm%data1d(:)
243
244 ! next source term
245 srcptr => srcptr%next
246
247 END DO
248 ! reset ghost cell data
249 IF (mesh%GINUM.GT.0) THEN
250 sterm%data4d(mesh%IGMIN:mesh%IMIN-mesh%IP1,:,:,:) = 0.0
251 sterm%data4d(mesh%IMAX+mesh%IP1:mesh%IGMAX,:,:,:) = 0.0
252 END IF
253 IF (mesh%GJNUM.GT.0) THEN
254 sterm%data4d(:,mesh%JGMIN:mesh%JMIN-mesh%JP1,:,:) = 0.0
255 sterm%data4d(:,mesh%JMAX+mesh%JP1:mesh%JGMAX,:,:) = 0.0
256 END IF
257 IF (mesh%GKNUM.GT.0) THEN
258 sterm%data4d(:,:,mesh%KGMIN:mesh%KMIN-mesh%KP1,:) = 0.0
259 sterm%data4d(:,:,mesh%KMAX+mesh%KP1:mesh%KGMAX,:) = 0.0
260 END IF
261 END SUBROUTINE externalsources
262
263
264 SUBROUTINE calctimestep(this,Mesh,Physics,Fluxes,pvar,cvar,time,dt,dtcause)
265 IMPLICIT NONE
266 !------------------------------------------------------------------------!
267 CLASS(sources_list), INTENT(INOUT) :: this
268 CLASS(mesh_base), INTENT(IN) :: Mesh
269 CLASS(physics_base), INTENT(INOUT) :: Physics
270 CLASS(fluxes_base), INTENT(IN) :: Fluxes
271 CLASS(marray_compound), INTENT(INOUT) :: pvar,cvar
272 REAL, INTENT(IN) :: time
273 REAL, INTENT(INOUT) :: dt
274 INTEGER, INTENT(OUT) :: dtcause
275 !------------------------------------------------------------------------!
276 CLASS(sources_base), POINTER :: srcptr
277 REAL :: dt_new
278 !------------------------------------------------------------------------!
279 dt_new = dt
280
281 ! go through all source terms in the list
282 srcptr => this%next
283 DO WHILE(ASSOCIATED(srcptr))
284
285 CALL srcptr%CalcTimestep(mesh,physics,fluxes,pvar,cvar,time,dt_new,dtcause)
286
287
288 IF (dt_new .LT. dt) dtcause=srcptr%GetType()
289 dt = min(dt,dt_new)
290 ! next source term
291 srcptr => srcptr%next
292 END DO
293 END SUBROUTINE calctimestep
294
296 SUBROUTINE finalize(this)
297 IMPLICIT NONE
298 !------------------------------------------------------------------------!
299 TYPE(sources_list) :: this
300 !------------------------------------------------------------------------!
301 CLASS(sources_base), POINTER :: srcptr,next
302 !------------------------------------------------------------------------!
303 ! loop over all source terms and call finalization subroutines
304 srcptr => this%next
305 DO WHILE (ASSOCIATED(srcptr))
306 next => srcptr%next
307 DEALLOCATE(srcptr)
308 srcptr => next
309 END DO
310 IF (ASSOCIATED(this%sterm)) DEALLOCATE(this%sterm)
311 END SUBROUTINE finalize
312
313END MODULE sources_generic_mod
Dictionary for generic data types.
Definition: common_dict.f90:61
logical function, public haschild(root)
Check if the node 'root' has one or more children.
function, public getkey(root)
Get the key of pointer 'root'.
type(dict_typ) function, pointer, public getnext(root)
Get the pointer to the next child.
type(dict_typ) function, pointer, public getchild(root)
Get the pointer to a direct child of the pointer 'root'.
base module for numerical flux functions
Definition: fluxes_base.f90:39
base class for mesh arrays
Definition: marray_base.f90:36
subroutine finalize(this)
derived class for compound of mesh arrays
basic mesh module
Definition: mesh_base.f90:72
Basic physics module.
@, public conservative
generic source terms module providing functionaly common to all source terms
source terms module for constant acceleration
subroutine calctimestep(this, Mesh, Physics, Fluxes, pvar, cvar, time, dt, dtcause)
subroutine externalsources(this, Mesh, Physics, Fluxes, Sources, time, dt, pvar, cvar, sterm)
subroutine initsources(this, Mesh, Physics, Fluxes, config, IO)
source terms module for simple optically thin cooling
source terms module for cooling of geometrically thin accretion disks
integer, parameter, public gray
integer, parameter, public gammie_sb
integer, parameter, public gammie
module to manage list of source terms
integer, parameter, public shearbox
integer, parameter, public planet_cooling
integer, parameter list
integer, parameter, public disk_cooling
integer, parameter, public planet_heating
integer, parameter, public rotating_frame
integer, parameter, public c_accel
integer, parameter, public cooling
integer, parameter, public viscosity
integer, parameter, public gravity
generic gravity terms module providing functionaly common to all gravity terms
gray cooling of planetary atmospheres
heating of a planet by a star
source terms module for inertial forces caused by a rotating grid
Source terms module for fictious forces in a shearingsheet.
computes momentum and energy sources due to shear stresses
integer, parameter, public alpha_alt
integer, parameter, public powerlaw
integer, parameter, public molecular
integer, parameter, public beta
character(len=32), dimension(5), parameter, public viscosity_name
integer, parameter, public alpha
mesh data structure
Definition: mesh_base.f90:122
container class to manage the list of source terms