aboutsummaryrefslogtreecommitdiff
path: root/src/GRHydro_TVDReconstruct.F90
blob: b2528c8ad3614c90507b1c490ba57b4f3624321c (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
 /*@@
   @file      GRHydro_TVDReconstruct.F90
   @date      Sat Jan 26 02:11:44 2002
   @author    Luca Baiotti
   @desc 
   The TVD reconstruction routine.
   @enddesc 
 @@*/

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

#include "SpaceMask.h"

 /*@@
   @routine    tvdreconstruct
   @date       Sat Jan 26 02:12:12 2002
   @author     Luca Baiotti
   @desc 
   Performs slope limited TVD reconstruction on the given input GF
   @enddesc 
   @calls     
   @calledby   
   @history 
   Follows (in philosophy) old code by Ian Hawke
   @endhistory 

@@*/

subroutine tvdreconstruct(nx, ny, nz, xoffset, yoffset, zoffset, &
     orig, bextp, bextm, trivial_rp, hydro_excision_mask)
  
  USE GRHydro_Scalars
  
  implicit none
  
  DECLARE_CCTK_PARAMETERS
  DECLARE_CCTK_FUNCTIONS

  integer :: i, j, k, xoffset, yoffset, zoffset, nx, ny, nz
  CCTK_REAL, dimension(nx, ny, nz) :: orig, bextp, bextm
  CCTK_REAL :: dupw, dloc, delta, ratio, hdelta
  logical, dimension(nx,ny,nz) :: trivial_rp
  CCTK_INT, dimension(nx,ny,nz) :: hydro_excision_mask


  bextp = 0.d0
  bextm = 0.d0

!!$ Initially all Riemann problems are NON-trivial

  trivial_rp = .false.
    ! constraint transport needs to be able to average fluxes in the directions
    ! other that flux_direction, which in turn need the primitives on interfaces
    !$OMP PARALLEL DO PRIVATE(i,j,k,dupw,dloc,delta,ratio,hdelta)
    do k = GRHydro_stencil, nz - GRHydro_stencil + 1 + transport_constraints*(1-zoffset)
      do j = GRHydro_stencil, ny - GRHydro_stencil + 1 + transport_constraints*(1-yoffset)
        do i = GRHydro_stencil, nx - GRHydro_stencil + 1 + transport_constraints*(1-xoffset)
          if (GRHydro_enable_internal_excision /= 0 .and. &
              (hydro_excision_mask(i,j,k) .ne. 0)) then
            trivial_rp(i-xoffset, j-yoffset, k-zoffset) = .true.
            trivial_rp(i, j, k) = .true.
            bextm(i, j, k) = orig(i, j, k)
            bextp(i, j, k) = orig(i, j, k)
            if (GRHydro_enable_internal_excision /= 0 .and. &
                (hydro_excision_mask(i+xoffset,j+yoffset,k+zoffset) .eq. 0)) then
              bextm(i, j, k) = orig(i+xoffset, j+yoffset, k+zoffset)
              bextp(i, j, k) = orig(i+xoffset, j+yoffset, k+zoffset)
            end if
          else if (GRHydro_enable_internal_excision /= 0 .and. &
                   ((hydro_excision_mask(i-xoffset,j-yoffset,k-zoffset) .ne. 0) .or. &
                    (hydro_excision_mask(i+xoffset,j+yoffset,k+zoffset) .ne. 0))) then
            bextm(i, j, k) = orig(i, j, k)
            bextp(i, j, k) = orig(i, j, k)
          else
            dupw = orig(i, j, k) - orig(i-xoffset, j-yoffset, k-zoffset)
            dloc = orig(i+xoffset, j+yoffset, k+zoffset) - orig(i, j, k)

            if (MINMOD) then
               delta = minmod_func(dupw,dloc)
            else if (MC2) then
!!$            This is the van Leer MC slope limiter
               if (dupw*dloc < 0.d0) then
                  delta=0.d0
               else 
                  delta=sign(min(2.d0*abs(dupw),2.d0*abs(dloc),&
                       0.5d0*(abs(dupw)+abs(dloc))),dupw+dloc)
               end if
            else if (SUPERBEE) then
               if (dupw*dloc < 0.d0) then
                  delta=0.d0
               else 
                  delta=sign(max(min(2.d0*abs(dupw),abs(dloc)),&
                       min(2.d0*abs(dloc),abs(dupw))),dupw+dloc)
               end if
            else
               call CCTK_WARN(0, "Type of limiter not recognized")
               ! NOTREACHED
               delta = 0d0 
            end if
            hdelta = 0.5d0 * delta 
            bextm(i, j, k) = orig(i, j, k) - hdelta
            bextp(i, j, k) = orig(i, j, k) + hdelta
          end if
        end do
      end do
    end do
    !$OMP END PARALLEL DO

contains
  function minmod_func(a_in,b_in) result(minmod_result)
    implicit none
    CCTK_REAL,intent(IN)::a_in,b_in
    CCTK_REAL::minmod_result
    
    minmod_result=0.5D0*(sign(1.0d0,a_in)+sign(1.0d0,b_in))*min(abs(a_in),abs(b_in))
  end function minmod_func

end subroutine tvdreconstruct