shearingsheet.f90
Go to the documentation of this file.
1!#############################################################################
2!# #
3!# fosite - 3D hydrodynamical simulation program #
4!# module: shearingsheet.f90 #
5!# #
6!# Copyright (C) 2015-2022 #
7!# Jannes Klee <jklee@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
27!----------------------------------------------------------------------------!
78!----------------------------------------------------------------------------!
80 USE fosite_mod
81#ifdef NECSXAURORA
82 USE asl_unified
83#endif
84#ifdef PARALLEL
85#ifdef HAVE_MPI_MOD
86 USE mpi
87#endif
88#endif
89 IMPLICIT NONE
90#ifdef PARALLEL
91#ifdef HAVE_MPI_H
92 include 'mpif.h'
93#endif
94#endif
95 !--------------------------------------------------------------------------!
96 ! general constants
97 REAL, PARAMETER :: gn = 1.0 ! grav. constant [GEOM] !
98 INTEGER, PARAMETER :: units = geometrical ! needs to be consistent !
99 ! simulation parameter
100 REAL, PARAMETER :: omega = 1.0 ! rotation at fid. point !
101 REAL, PARAMETER :: sigma0 = 1.0 ! mean surf.dens. !
102 REAL, PARAMETER :: tsim = 20./omega ! simulation time !
103 REAL, PARAMETER :: gamma = 2.0 ! dep. on vert. struct. !
104 REAL, PARAMETER :: beta_c = 10.0 ! cooling parameter !
105! REAL, PARAMETER :: BETA_C = 2.0 ! 2 -> collapse !
106 REAL, PARAMETER :: q = 1.5 ! shearing parameter !
107 ! mesh settings
108 INTEGER, PARAMETER :: mgeo = cartesian
109 INTEGER, PARAMETER :: shear_direction = 1 ! enables shearingsheet with direcion !
110 INTEGER, PARAMETER :: xres = 256 ! cells in x-direction !
111 INTEGER, PARAMETER :: yres = 256 ! cells in x-direction !
112 INTEGER, PARAMETER :: zres = 1 ! cells in z-direction !
113 REAL :: domainx = 200.0 ! domain size [GEOM] !
114 REAL :: domainy = 200.0 ! domain size [GEOM] !
115 ! number of output time steps
116 INTEGER, PARAMETER :: onum = 20
117 ! output directory and output name
118 CHARACTER(LEN=256), PARAMETER :: odir = "./"
119 CHARACTER(LEN=256), PARAMETER :: ofname = "shearingsheet"
120 !--------------------------------------------------------------------------!
121 CLASS(fosite), ALLOCATABLE :: sim
122 !--------------------------------------------------------------------------!
123
124ALLOCATE(sim)
125
126#ifdef NECSXAURORA
127CALL asl_library_initialize()
128#endif
129
130CALL sim%InitFosite()
131CALL makeconfig(sim, sim%config)
132CALL sim%Setup()
133CALL initdata(sim%Mesh, sim%Physics, sim%Timedisc%pvar, sim%Timedisc%cvar)
134CALL sim%Run()
135CALL sim%Finalize()
136
137
138#ifdef NECSXAURORA
139CALL asl_library_finalize()
140#endif
141
142DEALLOCATE(sim)
143
144CONTAINS
145 SUBROUTINE makeconfig(Sim,config)
146 IMPLICIT NONE
147 !--------------------------------------------------------------------------!
148 CLASS(fosite) :: Sim
149 TYPE(dict_typ), POINTER :: config
150 !--------------------------------------------------------------------------!
151 ! local variable declaration
152 TYPE(dict_typ), POINTER :: mesh,physics,fluxes,grav,cooling, &
153 sources,timedisc,datafile
154 REAL :: XMIN,XMAX,YMIN,YMAX,ZMIN,ZMAX, SOUNDSPEED
155 !--------------------------------------------------------------------------!
156 domainx = domainx*gn*sigma0/(omega*omega)
157 domainy = domainy*gn*sigma0/(omega*omega)
158 xmin = -0.5*domainx
159 xmax = +0.5*domainx
160 ymin = -0.5*domainy
161 ymax = +0.5*domainy
162 zmin = 0.0
163 zmax = 0.0
164 soundspeed = pi*gn*sigma0/omega ! Toomre-criterion
165
166 ! physics settings
167 physics => dict(&
168 "problem" / euler, &
169 "gamma" / gamma, &
170 "units" / geometrical &
171 )
172
173 ! mesh settings
174 mesh => dict(&
175 "meshtype" / midpoint, &
176 "geometry" / mgeo, &
177 "omega" / omega, &
178 "shearingbox" / shear_direction, &
179 "decomposition" / (/ 1, -1, 1/), &
180 "inum" / xres, &
181 "jnum" / yres, &
182 "knum" / zres, &
183 "xmin" / xmin, &
184 "xmax" / xmax, &
185 "ymin" / ymin, &
186 "ymax" / ymax, &
187 "zmin" / zmin, &
188 "zmax" / zmax, &
189 "Qshear" / q &
190 )
191
192 ! fluxes settings
193 fluxes => dict(&
194 "order" / linear, &
195 "fluxtype" / kt, &
196 "variables" / primitive, &
197 "limiter" / vanleer &
198 )
199
200 ! gravity settings (source term)
201 grav => dict(&
202 "stype" / gravity, &
203 "self/gtype" / sboxspectral, &
204 "self/output/phi" / 0, &
205 "self/output/accel_x" / 0, &
206 "self/output/Fmass2D" / 0, &
207 "self/output/accel_y" / 0 &
208 )
209
210 ! parametrized cooling from Gammie (2001)
211 cooling => dict(&
212 "stype" / disk_cooling, &
213 "method" / gammie_sb, &
214 "output/Qcool" / 1, &
215 "b_cool" / beta_c &
216 )
217
218 ! sources settings (contains source terms)
219 sources => dict(&
220 "cooling" / cooling, &
221 "grav" / grav &
222 )
223
224 ! time discretization settings
225 timedisc => dict(&
226 "method" / dormand_prince, &
227 "cfl" / 0.4, &
228 "stoptime" / tsim, &
229 "dtlimit" / 1e-40, &
230 "output/external_sources" / 0, &
231 "output/density_cvar" / 0, &
232 "output/energy" / 0, &
233 "output/xmomentum" / 0, &
234 "output/ymomentum" / 0, &
235 "output/rhs" / 0, &
236 "output/geometrical_sources" / 0, &
237 "maxiter" / 100000000, &
238 "tol_rel" / 1.0e-3 &
239 )
240
241 ! data i/o settings
242 datafile => dict(&
243 "fileformat" / vtk, &
244 "filepath" / trim(odir), &
245 "filename" / trim(ofname), &
246 "count" / onum &
247 )
248
249 ! overall config settings
250 config => dict(&
251 "mesh" / mesh, &
252 "physics" / physics, &
253 "fluxes" / fluxes, &
254 "sources" / sources, &
255 "timedisc" / timedisc, &
256 "datafile" / datafile &
257 )
258 END SUBROUTINE makeconfig
259
260 SUBROUTINE initdata(Mesh,Physics, pvar, cvar)
261 IMPLICIT NONE
262 !------------------------------------------------------------------------!
263 CLASS(mesh_base), INTENT(IN) :: Mesh
264 CLASS(physics_base), INTENT(IN) :: Physics
265 CLASS(marray_compound), POINTER, INTENT(INOUT) :: pvar,cvar
266 !------------------------------------------------------------------------!
267 INTEGER :: i,j,k,err
268 REAL :: SOUNDSPEED
269 REAL, ALLOCATABLE :: rands(:,:,:)
270#ifdef NECSXAURORA
271 INTEGER :: rng, n
272#endif
273 !------------------------ standard run ----------------------------------!
274 SELECT TYPE(p => pvar)
275 TYPE IS(statevector_euler)
276 ! constant initial pressure determined by Q = 1
277 soundspeed = pi*physics%Constants%GN*sigma0/omega ! Toomre-criterion
278 ! constant initial density
279 DO concurrent(i=1:SIZE(p%density%data1d))
280 p%density%data1d(i) = sigma0
281 p%pressure%data1d(i) = 2.5**2*pi*pi* &
282 physics%Constants%GN**2.*sigma0**3./(gamma*omega**2)
283 END DO
284
285
286 ! create random numbers for setup of initial velocities
287#ifndef NECSXAURORA
288 CALL initrandseed(physics)
289#else
290 CALL asl_random_create(rng, asl_randommethod_mt19937_64)
291 CALL asl_random_distribute_uniform(rng)
292 n = (mesh%IGMAX-mesh%IGMIN+1)*(mesh%JGMAX-mesh%JGMIN+1)*(mesh%KGMAX-mesh%KGMIN+1)
293#endif
294 ALLOCATE(rands(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX),stat=err)
295 IF (err.NE.0) CALL physics%Error("shearingsheet::InitData","Memory allocation failed")
296
297 IF (mesh%shear_dir.EQ.2) THEN
298#ifndef NECSXAURORA
299 CALL random_number(rands)
300#else
301 CALL asl_random_generate_d(rng, n, rands)
302#endif
303 DO concurrent(i=mesh%IGMIN:mesh%IGMAX,j=mesh%JGMIN:mesh%JGMAX,k=mesh%KGMIN:mesh%KGMAX)
304 p%velocity%data4d(i,j,k,1) = (rands(i,j,k)-0.5)*0.1*soundspeed
305 END DO
306
307#ifndef NECSXAURORA
308 CALL random_number(rands)
309#else
310 CALL asl_random_generate_d(rng, n, rands)
311#endif
312 DO concurrent(i=mesh%IGMIN:mesh%IGMAX,j=mesh%JGMIN:mesh%JGMAX,k=mesh%KGMIN:mesh%KGMAX)
313 p%velocity%data4d(i,j,k,2) = -q*omega*mesh%bcenter(i,j,k,1) &
314 + (rands(i,j,k)-0.5)*0.1*soundspeed
315 END DO
316 ELSE IF (mesh%shear_dir.EQ.1) THEN
317#ifndef NECSXAURORA
318 CALL random_number(rands)
319#else
320 CALL asl_random_generate_d(rng, n, rands)
321#endif
322 DO concurrent(i=mesh%IGMIN:mesh%IGMAX,j=mesh%JGMIN:mesh%JGMAX,k=mesh%KGMIN:mesh%KGMAX)
323 p%velocity%data4d(i,j,k,1) = q*omega*mesh%bcenter(i,j,k,2) &
324 + (rands(i,j,k)-0.5)*0.1*soundspeed
325 END DO
326
327#ifndef NECSXAURORA
328 CALL random_number(rands)
329#else
330 CALL asl_random_generate_d(rng, n, rands)
331#endif
332 DO concurrent(i=mesh%IGMIN:mesh%IGMAX,j=mesh%JGMIN:mesh%JGMAX,k=mesh%KGMIN:mesh%KGMAX)
333 p%velocity%data4d(i,j,k,2) = (rands(i,j,k)-0.5)*0.1*soundspeed
334 END DO
335 END IF
336 DEALLOCATE(rands)
337 CLASS DEFAULT
338 CALL physics%Error("shear::InitData","only non-isothermal HD supported")
339 END SELECT
340#ifdef NECSXAURORA
341 CALL asl_random_destroy(rng)
342#endif
343 !------------------------------------------------------------------------!
344 CALL physics%Convert2Conservative(pvar,cvar)
345 CALL mesh%Info(" DATA-----> initial condition: " // &
346 "Standard run shearingsheet")
347 END SUBROUTINE initdata
348
350 SUBROUTINE initrandseed(Physics)
351 IMPLICIT NONE
352 !------------------------------------------------------------------------!
353 CLASS(physics_base),INTENT(IN) :: Physics
354 INTEGER :: i, n, clock
355 INTEGER, DIMENSION(:), ALLOCATABLE :: seed
356 !------------------------------------------------------------------------!
357 ! Initialize random number generator with a seed based on the systems time
358 ! source: http://gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html
359 CALL random_seed(size = n)
360 ALLOCATE(seed(n))
361 CALL system_clock(count=clock)
362 seed = clock + 37 * (/ (i - 1, i = 1, n) /)
363#ifdef PARALLEL
364 seed = seed + physics%GetRank()
365#endif
366 CALL random_seed(put = seed)
367 DEALLOCATE(seed)
368 END SUBROUTINE initrandseed
369END PROGRAM shearingsheet
subroutine initdata(Mesh, Physics, Fluxes, Timedisc)
Definition: bondi2d.f90:274
subroutine makeconfig(Sim, config)
Definition: bondi2d.f90:165
subroutine initrandseed(Physics)
Definition: mestel.f90:371
program shearingsheet
pure real function, dimension(size(ephir%data2d, dim=1)) omega(ephir, velocity)
main fosite class
Definition: fosite.f90:71