-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadjust_boundND.f90
69 lines (67 loc) · 1.68 KB
/
adjust_boundND.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
!!-----------------------------------------------------------------
!! This subroutine checks the initial boundary locations and
!! adjusts them if necessary to ensure continuity of the grid
!! setup.
!!
!! THIS SUBROUTINE CURRENTLY ONLY IMPLEMENTED FOR ONE DIMENSION
!!
!!-----------------------------------------------------------------
SUBROUTINE adjust_boundaries(xmin,xmax,x,npart)
USE dimen_mhd
USE debug
USE loguns
!
!--define local variables
!
IMPLICIT NONE
INTEGER, INTENT(IN) :: npart
REAL, DIMENSION(npart), INTENT(IN) :: x
REAL, INTENT(INOUT) :: xmin,xmax
INTEGER :: ipart,i
REAL :: difx(5),tol
LOGICAL :: iuniform
!
!--allow for tracing flow
!
IF (trace) WRITE(iprint,*) ' Entering subroutine adjust_boundaries'
!
!--test to see if grid is uniform near boundaries
!
difx(:) = 0.
tol = 1.e-8 ! tolerance should really change with resolution
!
!--left boundary
!
iuniform = .true.
DO i=1,5
ipart = i
difx(i) = x(ipart+1)-x(ipart)
IF (i.GT.1) THEN
IF (ABS(difx(i)-difx(i-1)).GE.tol) iuniform = .false.
ENDIF
ENDDO
IF (iuniform) THEN
xmin = x(1) - 0.5*(x(2)-x(1))
WRITE(iprint,*) 'uniform grid: xmin adjusted to ',xmin
ELSE
WRITE(iprint,*) 'grid non-uniform: xmin not adjusted'
ENDIF
!
!--right boundary
!
iuniform = .true.
DO i=1,5
ipart = npart-5 + i
difx(i) = x(ipart)-x(ipart-1)
IF (i.GT.1) THEN
IF (ABS(difx(i)-difx(i-1)).GE.tol) iuniform = .false.
ENDIF
ENDDO
IF (iuniform) THEN
xmax = x(npart) + 0.5*(x(npart) - x(npart-1))
WRITE(iprint,*) 'uniform grid: xmax adjusted to ',xmax
ELSE
WRITE(iprint,*) 'grid non-uniform: xmax not adjusted'
ENDIF
RETURN
END SUBROUTINE adjust_boundaries