boundary_shearing.f90
Go to the documentation of this file.
1  !#############################################################################
2  !# #
3  !# fosite - 3D hydrodynamical simulation program #
4  !# module: boundary_shearing.f90 #
5  !# #
6  !# Copyright (C) 2006-2018 #
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  !----------------------------------------------------------------------------!
57  !----------------------------------------------------------------------------!
62  USE mesh_base_mod
64  USE common_dict
65 #ifdef PARALLEL
66 #ifdef HAVE_MPI_MOD
67  USE mpi
68 #endif
69 #endif
70  IMPLICIT NONE
71 #ifdef PARALLEL
72 #ifdef HAVE_MPIF_H
73  include 'mpif.h'
74 #endif
75 #endif
76  !--------------------------------------------------------------------------!
77  PRIVATE
78  CHARACTER(LEN=32), PARAMETER :: boundcond_name = "shearing"
79 
81  REAL :: velocity_offset
82  REAL, DIMENSION(:), POINTER :: velocity_shift
83  CONTAINS
84  PROCEDURE :: initboundary_shearing
85  PROCEDURE :: setboundarydata
86  PROCEDURE :: finalize
87  END TYPE
88  !--------------------------------------------------------------------------!
89  PUBLIC :: boundary_shearing
90  !--------------------------------------------------------------------------!
91 
92 CONTAINS
93 
95  SUBROUTINE initboundary_shearing(this,Mesh,Physics,dir,config)
96  IMPLICIT NONE
97  !------------------------------------------------------------------------!
98  CLASS(boundary_shearing), INTENT(INOUT) :: this
99  CLASS(mesh_base), INTENT(IN) :: Mesh
100  CLASS(physics_base), INTENT(IN) :: Physics
101  TYPE(Dict_TYP), POINTER :: config
102  INTEGER, INTENT(IN) :: dir
103  !------------------------------------------------------------------------!
104  INTEGER :: err, l
105  !------------------------------------------------------------------------!
106  CALL this%InitBoundary(mesh,physics,shearing,boundcond_name,dir,config)
107 
108  ALLOCATE( &
109  this%velocity_shift(physics%VNUM+physics%PNUM), &
110  stat = err)
111  IF (err.NE.0) THEN
112  CALL this%Error("InitBoundary_shearing", "Unable to allocate memory.")
113  END IF
114 
115  DO l=1,physics%VNUM + physics%PNUM
116  ! this part for WEST-EAST shear
117  IF (mesh%shear_dir.EQ.2) THEN
118  IF (l.EQ.physics%YVELOCITY) THEN
119  IF (mesh%FARGO.EQ.0) THEN
120  this%velocity_shift(l) = mesh%Q*mesh%OMEGA*(mesh%xmax-mesh%xmin)
121  ELSE IF (mesh%FARGO.EQ.3) THEN
122  this%velocity_shift(l) = 0.0
123  ELSE
124  CALL this%Error("InitTimedisc", &
125  "Shearing boundaries are only compatible without Fargo or Fargo type 3 (shearing box).")
126  END IF
127  ELSE
128  this%velocity_shift(l) = 0.0
129  END IF
130  ! this part for SOUTH-NORTH shear
131  ELSE IF (mesh%shear_dir.EQ.1) THEN
132  IF (l.EQ.physics%XVELOCITY) THEN
133  IF (mesh%FARGO.EQ.0) THEN
134  this%velocity_shift(l) = mesh%Q*mesh%OMEGA*(mesh%ymax-mesh%ymin)
135  ELSE IF (mesh%FARGO.EQ.3) THEN
136  this%velocity_shift(l) = 0.0
137  ELSE
138  CALL this%Error("InitTimedisc", &
139  "Shearing boundaries are only compatible without Fargo or Fargo type 3 (shearing box).")
140  END IF
141  ELSE
142  this%velocity_shift(l) = 0.0
143  END IF
144  ELSE
145  CALL this%Error("InitBoundary", &
146  "Shearing boundaries in top/south direction not allowed, yet.")
147  END IF
148  END DO
149  this%velocity_offset = mesh%Q*mesh%OMEGA*(mesh%xmax-mesh%xmin)/mesh%dy
150 
151  END SUBROUTINE initboundary_shearing
152 
190  PURE SUBROUTINE setboundarydata(this,Mesh,Physics,time,pvar)
191  IMPLICIT NONE
192  !------------------------------------------------------------------------!
193  CLASS(boundary_shearing), INTENT(INOUT) :: this
194  CLASS(mesh_base), INTENT(IN) :: mesh
195  CLASS(physics_base), INTENT(IN) :: physics
196  REAL, INTENT(IN) :: time
197  CLASS(marray_compound), INTENT(INOUT) :: pvar
198  !------------------------------------------------------------------------!
199  INTEGER :: i,j,k,l,intshift
200  REAL :: offremain,offset,offset_tmp
201 #ifdef PARALLEL
202  INTEGER :: status(mpi_status_size)
203  INTEGER :: ierror,req(4)
204  CHARACTER(LEN=80) :: str
205  REAL :: mpi_buf(2*mesh%gnum)
206 #endif
207  !------------------------------------------------------------------------!
208  ! the routine below expect that periodic boundaries are already applied
209 #ifndef PARALLEL
210  CALL this%boundary_periodic%SetBoundaryData(mesh,physics,time,pvar)
211 #endif
212 
213  ! make sure all MPI processes use the same step if domain is decomposed
214  ! along the y-direction (can be different due to round-off errors)
215  offset = -this%velocity_offset*time
216  DO WHILE(offset<0)
217  offset = offset + mesh%JNUM
218  END DO
219 
220  DO l=1,physics%VNUM+physics%PNUM
221  ! chose velocity offset for fargo and considered pvar
222  SELECT CASE(this%GetDirection())
223  CASE(west)
224  offset_tmp = offset
225  intshift = floor(offset_tmp)
226  offremain = offset_tmp - intshift
227  DO i=1,mesh%GNUM
228  !------- integral shift ---------------------------------------------!
229  pvar%data4d(mesh%IMIN-i,mesh%JMIN:mesh%JMAX,mesh%KMIN:mesh%KMAX,l) = &
230  cshift(pvar%data4d(mesh%IMIN-i,mesh%JMIN:mesh%JMAX,mesh%KMIN:mesh%KMAX,l),intshift)
231  !------- residual shift ---------------------------------------------!
232  pvar%data4d(mesh%IMIN-i,mesh%JMAX+1,:,l) = pvar%data4d(mesh%IMIN-i,mesh%JMIN,:,l)
233  DO k=mesh%KMIN,mesh%KMAX
234  DO j=mesh%JMIN,mesh%JMAX
235  pvar%data4d(mesh%IMIN-i,j,k,l) = (1.0 - offremain)*pvar%data4d(mesh%IMIN-i,j,k,l) + &
236  offremain*pvar%data4d(mesh%IMIN-i,j+1,k,l) + this%velocity_shift(l)
237  END DO
238  END DO
239  END DO
240  CASE(east)
241  offset_tmp = -offset
242  intshift = floor(offset_tmp)
243  offremain = offset_tmp - intshift
244  DO i=1,mesh%GNUM
245  !------- integral shift ---------------------------------------------!
246  pvar%data4d(mesh%IMAX+i,mesh%JMIN:mesh%JMAX,mesh%KMIN:mesh%KMAX,l) = &
247  cshift(pvar%data4d(mesh%IMAX+i,mesh%JMIN:mesh%JMAX,mesh%KMIN:mesh%KMAX,l),intshift)
248  !------- residual shift ---------------------------------------------!
249  pvar%data4d(mesh%IMAX+i,mesh%JMAX+1,:,l) = pvar%data4d(mesh%IMAX+i,mesh%JMIN,:,l)
250  DO k=mesh%KMIN,mesh%KMAX
251  DO j=mesh%JMIN,mesh%JMAX
252  pvar%data4d(mesh%IMAX+i,j,k,l) = (1.0 - offremain)*pvar%data4d(mesh%IMAX+i,j,k,l) + &
253  offremain*pvar%data4d(mesh%IMAX+i,j+1,k,l) - this%velocity_shift(l)
254  END DO
255  END DO
256  END DO
257  CASE(south)
258  offset_tmp = -offset
259  intshift = floor(offset_tmp)
260  offremain = offset_tmp - intshift
261  DO j=1,mesh%GNUM
262  !------- integral shift ---------------------------------------------!
263  pvar%data4d(mesh%IMIN:mesh%IMAX,mesh%JMIN-j,mesh%KMIN:mesh%KMAX,l) = &
264  cshift(pvar%data4d(mesh%IMIN:mesh%IMAX,mesh%JMIN-j,mesh%KMIN:mesh%KMAX,l),intshift)
265  !------- residual shift ---------------------------------------------!
266  pvar%data4d(mesh%IMAX+1,mesh%JMIN-j,:,l) = pvar%data4d(mesh%IMIN,mesh%JMIN-j,:,l)
267  DO k=mesh%KMIN,mesh%KMAX
268  DO i=mesh%IMIN,mesh%IMAX
269  pvar%data4d(i,mesh%JMIN-j,k,l) = (1.0 - offremain)*pvar%data4d(i,mesh%JMIN-j,k,l) + &
270  offremain*pvar%data4d(i+1,mesh%JMIN-j,k,l) - this%velocity_shift(l)
271  END DO
272  END DO
273  END DO
274  CASE(north)
275  offset_tmp = offset
276  intshift = floor(offset_tmp)
277  offremain = offset_tmp - intshift
278  DO j=1,mesh%GNUM
279  !------- integral shift ---------------------------------------------!
280  pvar%data4d(mesh%IMIN:mesh%IMAX,mesh%JMAX+j,mesh%KMIN:mesh%KMAX,l) = &
281  cshift(pvar%data4d(mesh%IMIN:mesh%IMAX,mesh%JMAX+j,mesh%KMIN:mesh%KMAX,l),intshift)
282  !------- residual shift ---------------------------------------------!
283  pvar%data4d(mesh%IMAX+1,mesh%JMAX+j,:,l) = pvar%data4d(mesh%IMIN,mesh%JMAX+j,:,l)
284  DO k=mesh%KMIN,mesh%KMAX
285  DO i=mesh%IMIN,mesh%IMAX
286  pvar%data4d(i,mesh%JMAX+j,k,l) = (1.0 - offremain)*pvar%data4d(i,mesh%JMAX+j,k,l) + &
287  offremain*pvar%data4d(i+1,mesh%JMAX+j,k,l) + this%velocity_shift(l)
288  END DO
289  END DO
290  END DO
291  CASE(bottom)
292  !CALL this%Error("SetBoundary", "Shearing not supported in BOTTOM direction.")
293  CASE(top)
294  !CALL this%Error("SetBoundary", "Shearing not supported in TOP direction.")
295  END SELECT
296  END DO
297  END SUBROUTINE setboundarydata
298 
299 
301  SUBROUTINE finalize(this)
302  IMPLICIT NONE
303  !------------------------------------------------------------------------!
304  CLASS(boundary_shearing), INTENT(INOUT) :: this
305  !------------------------------------------------------------------------!
306  DEALLOCATE(this%velocity_shift)
307  CALL this%Finalize_base()
308  END SUBROUTINE finalize
309 
310 
311 
312 END MODULE boundary_shearing_mod
type(logging_base), save this
derived class for compound of mesh arrays
subroutine finalize(this)
Destructor for periodic boundary conditions.
pure subroutine setboundarydata(this, Mesh, Physics, time, pvar)
Applies the periodic boundary condition.
character(len=32), parameter boundcond_name
subroutine initboundary_shearing(this, Mesh, Physics, dir, config)
Constructor for shearing boundary conditions.
named integer constants for flavour of state vectors
Basic physics module.
Dictionary for generic data types.
Definition: common_dict.f90:61
Boundary module for periodic boundary conditions.
Boundary module for a shearingsheet/shearingbox. (see e.g. the standard run )