shear.f90
Go to the documentation of this file.
1!#############################################################################
2!# #
3!# fosite - 3D hydrodynamical simulation program #
4!# module: shear.f90 #
5!# #
6!# Copyright (C) 2008-2018 #
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!----------------------------------------------------------------------------!
29!----------------------------------------------------------------------------!
30PROGRAM shear
31 USE fosite_mod
32#include "tap.h"
33 IMPLICIT NONE
34 !--------------------------------------------------------------------------!
35 ! simulation parameters
36 REAL, PARAMETER :: gn = 1.0 ! grav. constant [GEOM] !
37 INTEGER, PARAMETER :: units = geometrical
38 ! simulation parameter
39 REAL, PARAMETER :: csiso = &
40 0.0 ! non-isothermal simulation
41! 1.0 ! isothermal simulation
42 ! with CSISO as sound speed
43 REAL, PARAMETER :: omega = 1.0
44 REAL, PARAMETER :: sigma0 = 1.0
45 REAL, PARAMETER :: tsim = 10./omega
46 REAL, PARAMETER :: gamma = 2.0
47 REAL, PARAMETER :: q = 1.5 ! shearing parameter !
48 ! mesh settings
49 INTEGER, PARAMETER :: mgeo = cartesian
50 INTEGER, PARAMETER :: res_xy = 128 ! resolution in x/y-direction
51 INTEGER, PARAMETER :: res_z = 1 ! resolution in z-direction
52 REAL, PARAMETER :: box_size = 320*gn*sigma0/(omega*omega)
53 REAL, PARAMETER :: box_height = 0.0
54 ! number of output time steps
55 INTEGER, PARAMETER :: onum = 10
56 ! output directory and output name
57 CHARACTER(LEN=256), PARAMETER :: odir = "./"
58 CHARACTER(LEN=256), PARAMETER :: ofname = "sbox"
59 !--------------------------------------------------------------------------!
60 CLASS(fosite), ALLOCATABLE :: sim
61 CLASS(marray_compound), POINTER :: pvar=>null(),pvar_init=>null()
62 REAL :: sigma
63 LOGICAL :: ok
64 !--------------------------------------------------------------------------!
65 tap_plan(1)
66
67 ! with south-north shear
68 ALLOCATE(sim)
69 CALL sim%InitFosite()
70 CALL makeconfig(sim, sim%config)
71 CALL sim%Setup()
72 CALL initdata(sim%Mesh, sim%Physics, sim%Timedisc%pvar, sim%Timedisc%cvar)
73#ifndef PARALLEL
74 ! store transposed initial data
75 CALL sim%Physics%new_statevector(pvar_init,primitive)
76 CALL rotatedata(sim%Mesh,sim%Timedisc%pvar,pvar_init,"xy")
77#endif
78 CALL sim%Run()
79 ok = .NOT.sim%aborted
80#ifndef PARALLEL
81 ! store transposed result of the first run
82 CALL sim%Physics%new_statevector(pvar,primitive)
83 CALL rotatedata(sim%Mesh,sim%Timedisc%pvar,pvar,"xy")
84
85 ! simulate west-east shear
86 CALL sim%InitFosite()
87 CALL makeconfig(sim, sim%config)
88 CALL setattr(sim%config, "/datafile/filename", (trim(odir) // trim(ofname) // "_rotate"))
89 CALL setattr(sim%config, "mesh/shearingbox", 2)
90 CALL sim%Setup()
91 sim%Timedisc%pvar%data1d(:) = pvar_init%data1d(:)
92 SELECT TYPE(phys => sim%Physics)
93 CLASS IS(physics_eulerisotherm)
94 CALL phys%Convert2Conservative(sim%Timedisc%pvar,sim%Timedisc%cvar)
95 CLASS DEFAULT
96 CALL phys%Error("shear","only (non-)isothermal HD supported")
97 END SELECT
98 CALL sim%Run()
99
100 ! compare results
101 sigma = sqrt(sum((sim%Timedisc%pvar%data4d(:,:,:,:)-pvar%data4d(:,:,:,:))**2)/ &
102 SIZE(pvar%data4d(:,:,:,:)))
103 DEALLOCATE(pvar,pvar_init)
104#endif
105 CALL sim%Finalize()
106 DEALLOCATE(sim)
107
108#ifndef PARALLEL
109 ! x-y symmetry test does not work in parallel, because west-east shearing is not implemented
110 tap_check_small(sigma,1e-13,"Shear x-y symmetry test")
111#else
112 tap_check(ok,"stoptime reached")
113#endif
114 tap_done
115
116 CONTAINS
117
119 SUBROUTINE makeconfig(Sim, config)
120 IMPLICIT NONE
121 !------------------------------------------------------------------------!
122 CLASS(fosite) :: Sim
123 TYPE(dict_typ), POINTER :: config
124 !------------------------------------------------------------------------!
125 TYPE(dict_typ), POINTER :: mesh, physics, datafile, &
126 sources, timedisc, fluxes, shear
127 !------------------------------------------------------------------------!
128 INTENT(INOUT) :: sim
129 REAL :: XMIN,XMAX,YMIN,YMAX,ZMIN,ZMAX
130 !------------------------------------------------------------------------!
131 xmin = -0.5*box_size
132 xmax = +0.5*box_size
133 ymin = -0.5*box_size
134 ymax = +0.5*box_size
135 zmin = -0.5*box_height
136 zmax = +0.5*box_height
137
138 ! mesh settings
139 mesh => dict(&
140 "meshtype" / midpoint, &
141 "geometry" / mgeo, &
142 "shearingbox" / 1, &
143 "decomposition" / (/1,-1,1/), & ! decompose along y-direction
144 "inum" / res_xy, &
145 "jnum" / res_xy, &
146 "knum" / res_z, &
147 "xmin" / xmin, &
148 "xmax" / xmax, &
149 "ymin" / ymin, &
150 "ymax" / ymax, &
151 "zmin" / zmin, &
152 "zmax" / zmax, &
153 "omega" / omega, &
154 "output/rotation" / 0, &
155 "output/volume" / 0, &
156 "output/bh" / 0, &
157 "output/dl" / 0 &
158 )
159
160 ! physics settings
161 IF (csiso.GT.tiny(csiso)) THEN
162 physics => dict("problem" / euler_isotherm, &
163 "units" / units, &
164 "cs" / csiso) ! isothermal speed of sound
165 ELSE
166 physics => dict("problem" / euler, &
167 "units" / units, &
168 "gamma" / gamma) ! ratio of specific heats
169 END IF
170
171 ! flux calculation and reconstruction method
172 fluxes => dict( &
173 "fluxtype" / kt, &
174 "order" / linear, &
175 "variables" / primitive, &
176 "limiter" / vanleer &
177 )
178
179 ! time discretization settings
180 timedisc => dict( &
181 "method" / modified_euler, &
182 "order" / 3, &
183 "cfl" / 0.4, &
184 "stoptime" / tsim, &
185 "dtlimit" / 1.0e-40, &
186 "tol_rel" / 0.1, &
187 "output/external_sources" / 1, &
188 "maxiter" / 100000000)
189
190 ! initialize data input/output
191 datafile => dict( &
192 "fileformat" / vtk, &
193 "filename" / (trim(odir) // trim(ofname)), &
194 "count" / onum)
195
196 ! collect all above dicts in the configuration dict
197 config => dict( &
198 "mesh" / mesh, &
199 "physics" / physics, &
200 "fluxes" / fluxes, &
201 "timedisc" / timedisc, &
202 "datafile" / datafile)
203 END SUBROUTINE makeconfig
204
205
207 SUBROUTINE initdata(Mesh,Physics,pvar,cvar)
208 IMPLICIT NONE
209 !------------------------------------------------------------------------!
210 CLASS(mesh_base), INTENT(IN) :: Mesh
211 CLASS(physics_base), INTENT(IN) :: Physics
212 CLASS(marray_compound), POINTER, INTENT(INOUT) :: pvar,cvar
213 !------------------------------------------------------------------------!
214 ! Test for shearing and boundary module
215 ! initial condition
216 SELECT TYPE(p => pvar)
217 CLASS IS(statevector_eulerisotherm) ! isothermal HD
218 WHERE ((abs(mesh%bcenter(:,:,:,1)).LT.0.15*box_size.AND. &
219 abs(mesh%bcenter(:,:,:,2)).LT.0.15*box_size))
220 p%density%data3d(:,:,:) = sigma0
221 ELSEWHERE
222 p%density%data3d(:,:,:) = sigma0*1e-2
223 END WHERE
224 SELECT CASE(mesh%shear_dir)
225 CASE(1)
226 p%velocity%data2d(:,2) = 0.0
227 p%velocity%data4d(:,:,:,1) = mesh%Q*mesh%bcenter(:,:,:,2)*mesh%Omega
228 CASE(2)
229 p%velocity%data2d(:,1) = 0.0
230 p%velocity%data4d(:,:,:,2) = -mesh%Q*mesh%bcenter(:,:,:,1)*mesh%Omega
231 CASE DEFAULT
232 CALL physics%Error("shear::InitData","shearing disabled or unsupported direction")
233 END SELECT
234 CLASS DEFAULT
235 CALL physics%Error("shear::InitData","only (non-)isothermal HD supported")
236 END SELECT
237
238 SELECT TYPE(p => pvar)
239 CLASS IS(statevector_euler) ! non-isothermal HD
240 p%pressure%data1d(:) = 1e-1
241 END SELECT
242
243 CALL physics%Convert2Conservative(pvar,cvar)
244 CALL mesh%Info(" DATA-----> initial condition: " // &
245 "Shearing patch")
246 END SUBROUTINE initdata
247
248 ! only for symmetric matrix
249 SUBROUTINE rotatedata(Mesh,pvar_in,pvar_out,dir)
250 IMPLICIT NONE
251 !------------------------------------------------------------------------!
252 CLASS(mesh_base), INTENT(IN) :: Mesh
253 CLASS(marray_compound), INTENT(INOUT) :: pvar_in,pvar_out
254 CHARACTER(LEN=2), INTENT(IN) :: dir
255 !------------------------------------------------------------------------!
256 INTEGER :: i,j,k
257 !------------------------------------------------------------------------!
258 SELECT CASE(dir)
259 CASE("xy")
260 SELECT TYPE(pin => pvar_in)
261 CLASS IS(statevector_eulerisotherm) ! (non-)isothermal HD
262 SELECT TYPE(pout => pvar_out)
263 CLASS IS(statevector_eulerisotherm) ! (non-)isothermal HD
264 ! rotate at middle of the field, because x' = -y in shearingsheet.
265 FORALL(i=mesh%IGMIN:mesh%IGMAX,j=mesh%JGMIN:mesh%JGMAX,k=mesh%KGMIN:mesh%KGMAX)
266 pout%density%data3d(i,j,k) = pin%density%data3d(mesh%IGMAX-mesh%IGMIN-j-2,i,k)
267 pout%velocity%data4d(i,j,k,1) = pin%velocity%data4d(mesh%IGMAX-mesh%IGMIN-j-2,i,k,2)
268 pout%velocity%data4d(i,j,k,2) = -pin%velocity%data4d(mesh%IGMAX-mesh%IGMIN-j-2,i,k,1)
269 END FORALL
270 END SELECT
271 END SELECT
272 SELECT TYPE(pin => pvar_in)
273 CLASS IS(statevector_euler) ! non-isothermal HD
274 SELECT TYPE(pout => pvar_out)
275 CLASS IS(statevector_euler) ! non-isothermal HD
276 ! rotate at middle of the field, because x' = -y in shearingsheet.
277 FORALL(i=mesh%IGMIN:mesh%IGMAX,j=mesh%JGMIN:mesh%JGMAX,k=mesh%KGMIN:mesh%KGMAX)
278 pout%pressure%data3d(i,j,k) = pin%pressure%data3d(mesh%IGMAX-mesh%IGMIN-j-2,i,k)
279 END FORALL
280 END SELECT
281 END SELECT
282 CASE DEFAULT
283 CALL mesh%Error("shear::RotateData","only 'xy'-plane is currently supported for rotating data")
284 END SELECT
285 END SUBROUTINE rotatedata
286
287END PROGRAM shear
subroutine initdata(Mesh, Physics, Fluxes, Timedisc)
Definition: bondi2d.f90:274
subroutine makeconfig(Sim, config)
Definition: bondi2d.f90:165
program shear
Definition: shear.f90:30
subroutine rotatedata(Mesh, pvar_in, pvar_out, dir)
Definition: shear.f90:250
pure real function, dimension(size(ephir%data2d, dim=1)) omega(ephir, velocity)
main fosite class
Definition: fosite.f90:71