sources_planetcooling.f90
Go to the documentation of this file.
1!#############################################################################
2!# #
3!# fosite - 3D hydrodynamical simulation program #
4!# module: sources_planetcooling.f90 #
5!# #
6!# Copyright (C) 2011-2024 #
7!# Tobias Illenseer <tillense@astrophysik.uni-kiel.de> #
8!# Jannes Klee <jklee@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!----------------------------------------------------------------------------!
63 USE common_dict
64 IMPLICIT NONE
65 !--------------------------------------------------------------------------!
66 PRIVATE
67 CHARACTER(LEN=32), PARAMETER :: source_name = "cooling of planetary atmosphere"
68 !--------------------------------------------------------------------------!
70 TYPE(marray_base), ALLOCATABLE &
71 :: t_s, & !< temperature at the surface
72 rho_s, & !< density at the surface
73 p_s
74 REAL :: t_0
75 REAL :: radflux
76 REAL :: albedo
77 REAL :: distance
78 REAL :: gacc
79 REAL :: tau_inf
80 REAL :: const1, const2
81 CONTAINS
82 PROCEDURE :: initsources
83 PROCEDURE :: infosources
84 PROCEDURE :: updatecooling
85 final :: finalize
86 END TYPE
87 !--------------------------------------------------------------------------!
88 PUBLIC :: &
89 ! types
91 !--------------------------------------------------------------------------!
92
93CONTAINS
94
96 SUBROUTINE initsources(this,Mesh,Physics,Fluxes,config,IO)
99 IMPLICIT NONE
100 !------------------------------------------------------------------------!
101 CLASS(sources_planetcooling), INTENT(INOUT) :: this
102 CLASS(mesh_base), INTENT(IN) :: Mesh
103 CLASS(physics_base), INTENT(IN) :: Physics
104 CLASS(fluxes_base), INTENT(IN) :: Fluxes
105 TYPE(dict_typ), POINTER :: config,IO
106 INTEGER :: stype
107 !------------------------------------------------------------------------!
108 REAL :: effradflux, q
109 !------------------------------------------------------------------------!
110 CALL getattr(config, "stype", stype)
111 CALL this%InitSources_base(stype,source_name)
112
113 CALL this%Info("############################ ATTENTION ############################")
114 CALL this%Warning("sources_planetcooling::InitSources","Untested module, use with care!")
115
116 ! some sanity checks
117 SELECT TYPE (phys => physics)
118 CLASS IS(physics_euler)
119 ! do nothing
120 CLASS DEFAULT
121 CALL this%Error("sources_planetheating::InitSources","physics not supported")
122 END SELECT
123
124 SELECT TYPE (const => physics%constants)
125 CLASS IS(constants_si)
126 ! do nothing
127 CLASS DEFAULT
128 CALL this%Error("sources_planetheating::InitSources","only SI units supported")
129 END SELECT
130
131 ALLOCATE(this%Q,this%T_s)
132 this%Q = marray_base()
133 this%T_s = marray_base()
134
135 ! Courant number, i.e. safety factor for numerical stability
136 CALL getattr(config, "cvis", this%cvis, 0.9)
137 ! radiant energy flux density of stellar radiation at 1 AU distance
138 ! from the central star [W/m^2]
139 CALL getattr(config, "radflux", this%radflux)
140 ! Bond albedo of the planet
141 CALL getattr(config, "albedo", this%albedo,0.0)
142 ! temporal mean distance between planet and star
143 CALL getattr(config, "mean_distance", this%distance,physics%constants%AU)
144 ! equilibrium temperature
145 CALL getattr(config,"T_0", this%T_0)
146 ! gravitational acceleration
147 CALL getattr(config, "gacc", this%gacc)
148
149 ! set initial time < 0
150 this%time = -1.0
151
152 this%Q%data1d(:) = 0.0
153 this%T_s%data1d(:) = this%T_0
154
155 ! initial calculation of optical thickness
156 SELECT TYPE(phys => physics)
157 CLASS IS(physics_euler)
158 ! effective mean radiant flux density at mean distance
159 effradflux = (1.-this%albedo)*this%radflux*(phys%constants%AU/this%distance)**2
160 ! compute the effective optical depth that leads to the equilibrium
161 ! mean surface temperature T_0 of the planet
162 q = phys%gamma/(phys%gamma-1.0)
163 this%tau_inf= ((4*phys%Constants%SB*gamma(1.+4./q)/effradflux)**(0.25) * this%T_0)**q
164 ! conversion factor cs^2 -> T
165 this%const1 = phys%mu/(phys%gamma*phys%Constants%RG)
166 this%const2 = phys%Constants%SB*this%tau_inf**(-4./q) * gamma(1.0+4./q)
167 END SELECT
168
169 ! register cooling function for output
170 CALL this%SetOutput(mesh,config,io)
171
172 ! call InitSources in base
173 CALL this%InfoSources(mesh)
174 END SUBROUTINE initsources
175
176
177 SUBROUTINE infosources(this,Mesh)
178 IMPLICIT NONE
179 !------------------------------------------------------------------------!
180 CLASS(sources_planetcooling), INTENT(IN) :: this
181 CLASS(mesh_base), INTENT(IN) :: Mesh
182 !------------------------------------------------------------------------!
183 CHARACTER(LEN=32) :: param_str
184 !------------------------------------------------------------------------!
185 WRITE (param_str,'(ES10.2)') this%radflux
186 CALL this%Info(" mean stellar flux: " // trim(param_str) // " W/m^2")
187 WRITE (param_str,'(ES10.2)') this%T_0
188 CALL this%Info(" mean equil. temp.: " // trim(param_str) // " K")
189 WRITE (param_str,'(ES10.2)') this%tau_inf
190 CALL this%Info(" optical depth: " // trim(param_str))
191 END SUBROUTINE infosources
192
193
217 SUBROUTINE updatecooling(this,Mesh,Physics,time,pvar)
219 USE functions, ONLY : lngamma
220 IMPLICIT NONE
221 !------------------------------------------------------------------------!
222 CLASS(sources_planetcooling), INTENT(INOUT) :: this
223 CLASS(mesh_base), INTENT(IN) :: Mesh
224 CLASS(physics_euler), INTENT(IN) :: Physics
225 REAL, INTENT(IN) :: time
226 CLASS(statevector_euler), INTENT(IN) :: pvar
227 !------------------------------------------------------------------------!
228 INTEGER :: i,j,k
229 REAL :: Qcool
230 REAL :: const1,const2 ! needed due to performance issues
231 !------------------------------------------------------------------------!
232 ! calculate the cooling function if time has changed
233 IF (time.NE.this%time) THEN
234 ! calculate planet-surface temperature using integrated
235 ! pressure and density
236 this%T_s%data1d(:) = this%const1 * pvar%pressure%data1d(:)/pvar%density%data1d(:)
237
238 ! calculate surface density and pressure if output is requested
239 ! (irrelevant for cooling function)
240 IF (ALLOCATED(this%P_s)) this%P_s%data1d(:) = pvar%density%data1d(:)*this%gacc
241 IF (ALLOCATED(this%rho_s)) this%rho_s%data1d(:) = physics%mu/(physics%Constants%RG) &
242 *this%P_s%data1d(:)/this%T_s%data1d(:)
243
244 ! cooling source
245 WHERE (mesh%without_ghost_zones%mask1d(:))
246 this%Q%data1d(:) = this%const2*this%T_s%data1d(:)**4
247 ELSEWHERE
248 this%Q%data1d(:) = 0.0
249 END WHERE
250
251 ! update time
252 this%time=time
253 END IF
254 END SUBROUTINE updatecooling
255
256
266 SUBROUTINE setoutput(this,Mesh,config,IO)
267 IMPLICIT NONE
268 !------------------------------------------------------------------------!
269 CLASS(sources_planetcooling), INTENT(INOUT) :: this
270 CLASS(mesh_base), INTENT(IN) :: Mesh
271 TYPE(dict_typ),POINTER :: config,IO
272 !------------------------------------------------------------------------!
273 INTEGER :: valwrite
274 !------------------------------------------------------------------------!
275
276 !cooling source term
277 CALL getattr(config, "output/Qcool", valwrite, 0)
278 IF (valwrite .EQ. 1) &
279 CALL setattr(io, "Qcool", &
280 this%Q%data3d(mesh%IMIN:mesh%IMAX,mesh%JMIN:mesh%JMAX,mesh%KMIN:mesh%KMAX))
281
282 ! temperature
283 CALL getattr(config, "output/T_s", valwrite, 0)
284 IF (valwrite .EQ. 1) &
285 CALL setattr(io, "T_s", &
286 this%T_s%data3d(mesh%IMIN:mesh%IMAX,mesh%JMIN:mesh%JMAX,mesh%KMIN:mesh%KMAX))
287
288 ! surface pressure
289 CALL getattr(config, "output/P_s", valwrite, 0)
290 IF (valwrite .EQ. 1) THEN
291 ALLOCATE(this%P_s)
292 this%P_s = marray_base()
293 this%P_s%data1d(:) = 0.0
294 CALL setattr(io, "P_s", &
295 this%P_s%data3d(mesh%IMIN:mesh%IMAX,mesh%JMIN:mesh%JMAX,mesh%KMIN:mesh%KMAX))
296 END IF
297
298 ! surface density
299 CALL getattr(config, "output/rho_s", valwrite, 0)
300 IF (valwrite .EQ. 1) THEN
301 ALLOCATE(this%rho_s)
302 this%rho_s = marray_base()
303 this%rho_s%data1d(:) = 0.0
304 CALL setattr(io, "rho_s", &
305 this%rho_s%data3d(mesh%IMIN:mesh%IMAX,mesh%JMIN:mesh%JMAX,mesh%KMIN:mesh%KMAX))
306 END IF
307 END SUBROUTINE setoutput
308
309
311 SUBROUTINE finalize(this)
312 IMPLICIT NONE
313 !------------------------------------------------------------------------!
314 TYPE(sources_planetcooling), INTENT(INOUT) :: this
315 !------------------------------------------------------------------------!
316 DEALLOCATE(this%T_s)
317 IF (ALLOCATED(this%P_s)) DEALLOCATE(this%P_s)
318 IF (ALLOCATED(this%rho_s)) DEALLOCATE(this%rho_s)
319 ! this%Q is deallocated in parent class destructor
320 END SUBROUTINE finalize
321
Dictionary for generic data types.
Definition: common_dict.f90:61
module for SI units and physical constants
base module for numerical flux functions
Definition: fluxes_base.f90:39
Mathematical functions.
Definition: functions.f90:48
elemental real function, public lngamma(x)
computes the logarithm of the gammafunction with Lanczos approximation found in Numerical Recipes for...
Definition: functions.f90:1197
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
subroutine setoutput(this, config, IO)
Setup mesh fields for i/o.
Definition: mesh_base.f90:828
Basic physics module.
physics module for 1D,2D and 3D non-isothermal Euler equations
generic source terms module providing functionaly common to all source terms
source terms module for simple optically thin cooling
subroutine initsources(this, Mesh, Physics, Fluxes, config, IO)
subroutine updatecooling(this, Mesh, Physics, time, pvar)
Updates the cooling function at each time step.
character(len=32), parameter source_name
gray cooling of planetary atmospheres
subroutine infosources(this, Mesh)
basic mesh array class
Definition: marray_base.f90:69
mesh data structure
Definition: mesh_base.f90:122