aboutsummaryrefslogtreecommitdiff
path: root/src/findboundary.F90
blob: 2eaa1e14182f9bb61d9a56f2c31f6e7769b6f9ee (plain)
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
70
71
72
73
74
! $Header$

! Take a mask that contains only the values 0 and 1.
! Return a mask where the outermost 0s have been replaced by 0.5s.

#include "cctk.h"
#include "cctk_Functions.h"
#include "cctk_Parameters.h"

#include "maskvalues.h"

subroutine excision_findboundary (ierr, mask, ni, nj, nk)
  
  implicit none
  
  DECLARE_CCTK_FUNCTIONS
  DECLARE_CCTK_PARAMETERS
  
  ! Arguments
  
  ! out: zero for success, nonzero for error
  integer      :: ierr

  ! in: array sizes for grid functions
  !     (you can pass in cctk_lsh(:) for these)
  integer      :: ni,nj,nk
  
  ! inout: mask
  CCTK_REAL    :: mask(ni,nj,nk)

! Internal variables.

  integer i,j,k
  integer ii,jj,kk
  logical bnd
  
  if (CCTK_IsThornActive(CCTK_THORNSTRING) == 0) then
     call CCTK_WARN (0, "The routine excision_findboundary was called, but thorn " // CCTK_THORNSTRING // " is not active")
  end if

! Loop over grid points.

  do k=2,nk-1
     do j=2,nj-1
        do i=2,ni-1

!          Check if we are in an excised point.

           if (abs(mask(i,j,k)-MASK_EXCISED)<0.01) then

              bnd = .false.

!             If any neighbour is active, mask the point
!             as a boundary point.

              do kk=k-1,k+1
                 do jj=j-1,j+1
                    do ii=i-1,i+1
                       bnd = bnd.or.abs(mask(ii,jj,kk)-MASK_ACTIVE)<0.01
                    end do
                 end do
              end do

              if (bnd) mask(i,j,k) = MASK_BOUNDARY

           end if

        end do
     end do
  end do
  
  ierr = 0
  
end subroutine excision_findboundary