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