sources_gravity.f90
Go to the documentation of this file.
1!#############################################################################
2!# #
3!# fosite - 3D hydrodynamical simulation program #
4!# module: sources_gravity.f90 #
5!# #
6!# Copyright (C) 2014-2024 #
7!# Björn Sperling <sperling@astrophysik.uni-kiel.de> #
8!# Tobias Illenseer <tillense@astrophysik.uni-kiel.de> #
9!# Jannes Klee <jklee@astrophysik.uni-kiel.de> #
10!# #
11!# This program is free software; you can redistribute it and/or modify #
12!# it under the terms of the GNU General Public License as published by #
13!# the Free Software Foundation; either version 2 of the License, or (at #
14!# your option) any later version. #
15!# #
16!# This program is distributed in the hope that it will be useful, but #
17!# WITHOUT ANY WARRANTY; without even the implied warranty of #
18!# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or #
19!# NON INFRINGEMENT. See the GNU General Public License for more #
20!# details. #
21!# #
22!# You should have received a copy of the GNU General Public License #
23!# along with this program; if not, write to the Free Software #
24!# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
25!# #
26!#############################################################################
30!----------------------------------------------------------------------------!
40!----------------------------------------------------------------------------!
53 USE common_dict
54 IMPLICIT NONE
55 !--------------------------------------------------------------------------!
56 PRIVATE
57 CHARACTER(LEN=32), PARAMETER :: source_name = "gravity"
59 CLASS(gravity_base), POINTER :: glist => null()
60 TYPE(marray_base) :: pot
61 TYPE(marray_base), ALLOCATABLE :: height
62 TYPE(marray_base), ALLOCATABLE :: invheight2
63 TYPE(marray_base), ALLOCATABLE :: h_ext
66 LOGICAL :: addtoenergy
67 LOGICAL :: update_disk_height
68 CONTAINS
69 PROCEDURE :: initsources
70 PROCEDURE :: updategravity
71 PROCEDURE :: externalsources
72 PROCEDURE :: calcdiskheight
73 final :: finalize
74 END TYPE sources_gravity
75 abstract INTERFACE
76 END INTERFACE
77 !--------------------------------------------------------------------------!
78 PUBLIC :: &
79 ! types
81 !--------------------------------------------------------------------------!
82
83CONTAINS
84
85 SUBROUTINE initsources(this,Mesh,Physics,Fluxes,config,IO)
86 IMPLICIT NONE
87 !------------------------------------------------------------------------!
88 CLASS(sources_gravity), INTENT(INOUT) :: this
89 CLASS(mesh_base), INTENT(IN) :: Mesh
90 CLASS(fluxes_base), INTENT(IN) :: Fluxes
91 CLASS(physics_base), INTENT(IN) :: Physics
92 TYPE(dict_typ), POINTER :: config, IO
93 !------------------------------------------------------------------------!
94 INTEGER :: err, stype,i, valwrite
95 !------------------------------------------------------------------------!
96 CALL getattr(config,"stype",stype)
97 CALL this%InitSources_base(stype,source_name)
98
99 ALLOCATE(this%accel)
100 this%accel = marray_base(physics%VDIM)
101 this%accel%data1d(:) = 0.
102 this%pot = marray_base(4)
103 this%pot%data1d(:) = 0.
104
105 ! Add source terms to energy equation?
106 ! Set this to zero, if a potential is defined in physics_euler2Diamt
107 CALL getattr(config, "energy", i, 1)
108 IF(i.EQ.0) THEN
109 this%addtoenergy = .false.
110 ELSE
111 this%addtoenergy = .true.
112 END IF
113
114 ! initialize gravity
115 CALL new_gravity(this%glist,mesh,fluxes,physics,config,io)
116
117 ! activate output of scale height if requested (default: disabled)
118 CALL getattr(config, "output/height", valwrite, 0)
119
120 ! this parameter is usually set automatically depending on other
121 ! settings (see sources_generic), but if output of height
122 ! is enabled, computation of disk height is activated as well
123 ! (works only 1D/2D accretion disk simulations with flat geometry)
124 IF (valwrite.EQ.1) CALL setattr(config, "update_disk_height", 1)
125 CALL getattr(config, "update_disk_height",valwrite, 0)
126
127 IF (valwrite.EQ.1) THEN
130 IF (physics%VDIM.EQ.2) THEN
131 this%update_disk_height = .true.
132 ALLOCATE(this%height,this%h_ext,this%invheight2)
133 this%height = marray_base()
134 this%h_ext= marray_base()
135 this%invheight2 = marray_base()
136 this%height%data1d = 0.0
137 this%h_ext%data1d = 0.0
138 this%invheight2%data1d = 0.0
139
140 IF (valwrite.EQ.1) THEN
141 CALL setattr(io, "height", &
142 this%height%data3d(mesh%IMIN:mesh%IMAX,mesh%JMIN:mesh%JMAX,mesh%KMIN:mesh%KMAX))
143 END IF
144 ELSE
145 CALL this%Error("sources_gravity::InitSources", "Computation of disk scale height is only supported in 1D/2D flat geometries")
146 END IF
147 ELSE
148 this%update_disk_height = .false.
149 END IF
150
151 ! activate output of gravitational acceleration
152 CALL getattr(config, "output/accel", valwrite, 0)
153 IF (valwrite .EQ. 1) THEN
154 CALL setattr(io, "accel", &
155 this%accel%data4d(mesh%IMIN:mesh%IMAX,mesh%JMIN:mesh%JMAX,mesh%KMIN:mesh%KMAX,1:physics%VDIM))
156 END IF
157
158 END SUBROUTINE initsources
159
164 SUBROUTINE externalsources(this,Mesh,Physics,Fluxes,Sources,time,dt,pvar,cvar,sterm)
167 IMPLICIT NONE
168 !------------------------------------------------------------------------!
169 CLASS(sources_gravity), INTENT(INOUT) :: this
170 CLASS(mesh_base), INTENT(IN) :: Mesh
171 CLASS(physics_base), INTENT(INOUT) :: Physics
172 CLASS(fluxes_base), INTENT(IN) :: Fluxes
173 CLASS(sources_base), INTENT(INOUT) :: Sources
174 REAL, INTENT(IN) :: time, dt
175 CLASS(marray_compound), INTENT(INOUT) :: pvar,cvar,sterm
176 !------------------------------------------------------------------------!
177 ! go through all gravity terms in the list
178 CALL this%UpdateGravity(mesh,physics,fluxes,pvar,time,dt)
179
180 ! update disk scale height if requested
181 IF (this%update_disk_height) THEN
182 SELECT TYPE(phys => physics)
183 CLASS IS (physics_eulerisotherm)
184 CALL this%CalcDiskHeight(mesh,phys,pvar)
185 END SELECT
186 END IF
187
188 ! gravitational source terms
189 CALL physics%ExternalSources(this%accel,pvar,cvar,sterm)
190
193 ! Set src term in energy equation to zero, if it is handeled in the physics
194 ! module
195 SELECT TYPE(s => sterm)
196 TYPE IS (statevector_euler)
197 IF (.NOT.this%addtoenergy) s%energy%data1d(:) = 0.
198 END SELECT
199
200 END SUBROUTINE externalsources
201
203 SUBROUTINE updategravity(this,Mesh,Physics,Fluxes,pvar,time,dt)
204 IMPLICIT NONE
205 !------------------------------------------------------------------------!
206 CLASS(sources_gravity), TARGET, INTENT(INOUT) :: this
207 CLASS(mesh_base), INTENT(IN) :: Mesh
208 CLASS(physics_base), INTENT(INOUT) :: Physics
209 CLASS(fluxes_base), INTENT(IN) :: Fluxes
210 CLASS(marray_compound), INTENT(INOUT) :: pvar
211 REAL, INTENT(IN) :: time, dt
212 !------------------------------------------------------------------------!
213 INTEGER :: i,j,k,l
214 CLASS(gravity_base), POINTER :: gravptr
215 !------------------------------------------------------------------------!
216 ! update acceleration of all gravity sources
217 ! reset gterm
218 this%pot%data1d(:) = 0.
219 this%accel%data1d(:) = 0.
220
221 gravptr => this%glist
222 DO WHILE (ASSOCIATED(gravptr))
223 ! get gravitational acceleration of each gravity module
224 CALL gravptr%UpdateGravity_single(mesh,physics,fluxes,pvar,time,dt)
225
226 ! add contribution to the overall gravitational acceleration
227 this%accel = this%accel + gravptr%accel
228
229 ! add potential if available
230 IF (ALLOCATED(gravptr%pot)) THEN
231 this%pot = this%pot + gravptr%pot
232 END IF
233
234 ! next source term
235 gravptr => gravptr%next
236 END DO
237 END SUBROUTINE
238
239 SUBROUTINE calcdiskheight(this,Mesh,Physics,pvar)
243 IMPLICIT NONE
244 !------------------------------------------------------------------------!
245 CLASS(sources_gravity),TARGET,INTENT(INOUT) :: this
246 CLASS(mesh_base), INTENT(IN) :: Mesh
247 CLASS(physics_eulerisotherm), INTENT(INOUT) :: Physics
248 CLASS(marray_compound), INTENT(INOUT) :: pvar
249 !------------------------------------------------------------------------!
250 CLASS(gravity_base), POINTER :: grav_ptr,selfgrav_ptr => null()
251 LOGICAL :: has_external_potential = .false.
252 !------------------------------------------------------------------------!
253 ! reset inverse scale height^2
254 this%invheight2%data1d(:) = 0.0
255 ! go through all gravity terms in the list
256 grav_ptr => this%glist
257 DO WHILE(ASSOCIATED(grav_ptr))
258 SELECT TYPE (grav => grav_ptr)
259 CLASS IS (gravity_pointmass)
260 CALL grav%CalcDiskHeight_single(mesh,physics,pvar,physics%bccsound,this%h_ext,this%height)
261 this%invheight2%data1d(:) = this%invheight2%data1d(:) + 1./this%height%data1d(:)**2
262 has_external_potential = .true.
263 CLASS IS (gravity_spectral)
264 selfgrav_ptr => grav_ptr
265 END SELECT
266
267 ! next gravity term
268 grav_ptr => grav_ptr%next
269 END DO
270
271 ! self-gravity of the disk needs special treatment
272 IF (ASSOCIATED(selfgrav_ptr)) THEN
273 IF (has_external_potential) THEN
274 ! compute the resultant height due to all external gravitational forces
275 this%h_ext%data1d(:) = 1./sqrt(this%invheight2%data1d(:))
276 END IF
277 CALL selfgrav_ptr%CalcDiskHeight_single(mesh,physics,pvar,physics%bccsound,this%h_ext,this%height)
278 ELSE
279 ! non-selfgravitating disk
280 this%height%data1d(:) = 1./sqrt(this%invheight2%data1d(:))
281 END IF
282
283 END SUBROUTINE calcdiskheight
284
285
286 SUBROUTINE finalize(this)
287 IMPLICIT NONE
288 !------------------------------------------------------------------------!
289 TYPE(sources_gravity), INTENT(INOUT) :: this
290 CLASS(gravity_base), POINTER :: gravptr,tmpptr
291 !------------------------------------------------------------------------!
292 gravptr => this%glist
293 DO WHILE (ASSOCIATED(gravptr))
294 tmpptr => gravptr
295 gravptr => gravptr%next
296 DEALLOCATE(tmpptr)
297 END DO
298 IF (ALLOCATED(this%height)) DEALLOCATE(this%height)
299 IF (ALLOCATED(this%h_ext)) DEALLOCATE(this%h_ext)
300 IF (ALLOCATED(this%invheight2)) DEALLOCATE(this%invheight2)
301 ! deallocation of this%accel is done in inherited destructor
302 ! which is called automatically
303 END SUBROUTINE finalize
304
305END MODULE sources_gravity_mod
Dictionary for generic data types.
Definition: common_dict.f90:61
base module for numerical flux functions
Definition: fluxes_base.f90:39
generic gravity terms module providing functionaly common to all gravity terms
subroutine new_gravity(this, Mesh, Fluxes, Physics, config, IO)
source terms module for gravitational acceleration due to a point mass at the center of the coordinat...
2D poisson solver using spectral methods for direct integration
Basic fosite module.
subroutine finalize(this)
Destructor of logging_base class.
base class for mesh arrays
Definition: marray_base.f90:36
derived class for compound of mesh arrays
basic mesh module
Definition: mesh_base.f90:72
Basic physics module.
physics module for 1D,2D and 3D non-isothermal Euler equations
physics module for 1D,2D and 3D isothermal Euler equations
generic source terms module providing functionaly common to all source terms
source terms module for constant acceleration
character(len=32), parameter source_name
subroutine externalsources(this, Mesh, Physics, Fluxes, Sources, time, dt, pvar, cvar, sterm)
subroutine initsources(this, Mesh, Physics, Fluxes, config, IO)
generic gravity terms module providing functionaly common to all gravity terms
subroutine updategravity(this, Mesh, Physics, Fluxes, pvar, time, dt)
Updates gravity of all gravity source modules.
subroutine calcdiskheight(this, Mesh, Physics, pvar)
basic mesh array class
Definition: marray_base.f90:69
mesh data structure
Definition: mesh_base.f90:122