Block-Structured AMR Software Framework
AMReX_MLTensor_K.H
Go to the documentation of this file.
1 #ifndef AMREX_MLTENSOR_K_H_
2 #define AMREX_MLTENSOR_K_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_FArrayBox.H>
6 #include <AMReX_BndryData.H>
7 
8 namespace amrex {
9 
11 Real mltensor_dy_on_xface (int i, int j, int k, int n, Array4<Real const> const& vel, Real dyi) noexcept
12 {
13  return (vel(i,j+1,k,n)+vel(i-1,j+1,k,n)-vel(i,j-1,k,n)-vel(i-1,j-1,k,n))*(Real(0.25)*dyi);
14 }
15 
17 Real mltensor_dx_on_yface (int i, int j, int k, int n, Array4<Real const> const& vel, Real dxi) noexcept
18 {
19  return (vel(i+1,j,k,n)+vel(i+1,j-1,k,n)-vel(i-1,j,k,n)-vel(i-1,j-1,k,n))*(Real(0.25)*dxi);
20 }
21 
23 Real mltensor_dy_on_xface (int i, int j, int k, int n, Array4<Real const> const& vel, Real dyi,
24  Array4<Real const> const& bvxlo, Array4<Real const> const& bvxhi,
26  0,2*AMREX_SPACEDIM,
27  0,AMREX_SPACEDIM> const& bct,
28  Dim3 const& dlo, Dim3 const& dhi) noexcept
29 {
30  Real ddy;
31  if (i == dlo.x) {
32  if (bct(Orientation::xlo(),n) == AMREX_LO_DIRICHLET && bvxlo) {
33  if (j == dlo.y) {
34  ddy = (bvxlo(i-1,j ,k,n) * Real(-1.5) +
35  bvxlo(i-1,j+1,k,n) * Real(2.) +
36  bvxlo(i-1,j+2,k,n) * Real(-0.5)) * dyi;
37  } else if (j == dhi.y) {
38  ddy = -(bvxlo(i-1,j ,k,n) * Real(-1.5) +
39  bvxlo(i-1,j-1,k,n) * Real(2.) +
40  bvxlo(i-1,j-2,k,n) * Real(-0.5)) * dyi;
41  } else {
42  ddy = (bvxlo(i-1,j+1,k,n)-bvxlo(i-1,j-1,k,n))*(Real(0.5)*dyi);
43  }
44  } else if (bct(Orientation::xlo(),n) == AMREX_LO_NEUMANN) {
45  ddy = (vel(i,j+1,k,n)-vel(i,j-1,k,n))*(Real(0.5)*dyi);
46  } else { // AMREX_LO_REFLECT_ODD or homogeneous Dirichlet
47  ddy = Real(0.);
48  }
49  } else if (i == dhi.x+1) {
50  if (bct(Orientation::xhi(),n) == AMREX_LO_DIRICHLET && bvxhi) {
51  if (j == dlo.y) {
52  ddy = (bvxhi(i,j ,k,n) * Real(-1.5) +
53  bvxhi(i,j+1,k,n) * Real(2.) +
54  bvxhi(i,j+2,k,n) * Real(-0.5)) * dyi;
55  } else if (j == dhi.y) {
56  ddy = -(bvxhi(i,j ,k,n) * Real(-1.5) +
57  bvxhi(i,j-1,k,n) * Real(2.) +
58  bvxhi(i,j-2,k,n) * Real(-0.5)) * dyi;
59  } else {
60  ddy = (bvxhi(i,j+1,k,n)-bvxhi(i,j-1,k,n))*(Real(0.5)*dyi);
61  }
62  } else if (bct(Orientation::xhi(),n) == AMREX_LO_NEUMANN) {
63  ddy = (vel(i-1,j+1,k,n)-vel(i-1,j-1,k,n))*(Real(0.5)*dyi);
64  } else { // AMREX_LO_REFLECT_ODD or homogeneous Dirichlet
65  ddy = Real(0.);
66  }
67  } else {
68  ddy = mltensor_dy_on_xface(i,j,k,n,vel,dyi);
69  }
70  return ddy;
71 }
72 
74 Real mltensor_dx_on_yface (int i, int j, int k, int n, Array4<Real const> const& vel, Real dxi,
75  Array4<Real const> const& bvylo, Array4<Real const> const& bvyhi,
77  0,2*AMREX_SPACEDIM,
78  0,AMREX_SPACEDIM> const& bct,
79  Dim3 const& dlo, Dim3 const& dhi) noexcept
80 {
81  Real ddx;
82  if (j == dlo.y) {
83  if (bct(Orientation::ylo(),n) == AMREX_LO_DIRICHLET && bvylo) {
84  if (i == dlo.x) {
85  ddx = (bvylo(i ,j-1,k,n) * Real(-1.5) +
86  bvylo(i+1,j-1,k,n) * Real(2.) +
87  bvylo(i+2,j-1,k,n) * Real(-0.5)) * dxi;
88  } else if (i == dhi.x) {
89  ddx = -(bvylo(i ,j-1,k,n) * Real(-1.5) +
90  bvylo(i-1,j-1,k,n) * Real(2.) +
91  bvylo(i-2,j-1,k,n) * Real(-0.5)) * dxi;
92  } else {
93  ddx = (bvylo(i+1,j-1,k,n)-bvylo(i-1,j-1,k,n))*(Real(0.5)*dxi);
94  }
95  } else if (bct(Orientation::ylo(),n) == AMREX_LO_NEUMANN) {
96  ddx = (vel(i+1,j,k,n)-vel(i-1,j,k,n))*(Real(0.5)*dxi);
97  } else { // AMREX_LO_REFLECT_ODD or homogeneous Dirichlet
98  ddx = Real(0.);
99  }
100  } else if (j == dhi.y+1) {
101  if (bct(Orientation::yhi(),n) == AMREX_LO_DIRICHLET && bvyhi) {
102  if (i == dlo.x) {
103  ddx = (bvyhi(i ,j,k,n) * Real(-1.5) +
104  bvyhi(i+1,j,k,n) * Real(2.) +
105  bvyhi(i+2,j,k,n) * Real(-0.5)) * dxi;
106  } else if (i == dhi.x) {
107  ddx = -(bvyhi(i ,j,k,n) * Real(-1.5) +
108  bvyhi(i-1,j,k,n) * Real(2.) +
109  bvyhi(i-2,j,k,n) * Real(-0.5)) * dxi;
110  } else {
111  ddx = (bvyhi(i+1,j,k,n)-bvyhi(i-1,j,k,n))*(Real(0.5)*dxi);
112  }
113  } else if (bct(Orientation::yhi(),n) == AMREX_LO_NEUMANN) {
114  ddx = (vel(i+1,j-1,k,n)-vel(i-1,j-1,k,n))*(Real(0.5)*dxi);
115  } else { // AMREX_LO_REFLECT_ODD or homogeneous Dirichlet
116  ddx = Real(0.);
117  }
118  } else {
119  ddx = mltensor_dx_on_yface(i,j,k,n,vel,dxi);
120  }
121  return ddx;
122 }
123 }
124 
125 #if (AMREX_SPACEDIM == 1)
126 #include <AMReX_MLTensor_1D_K.H>
127 #elif (AMREX_SPACEDIM == 2)
128 #include <AMReX_MLTensor_2D_K.H>
129 #else
130 #include <AMReX_MLTensor_3D_K.H>
131 #endif
132 
133 #endif
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
#define AMREX_LO_NEUMANN
Definition: AMReX_LO_BCTYPES.H:6
#define AMREX_LO_DIRICHLET
Definition: AMReX_LO_BCTYPES.H:5
Maintain an identifier for boundary condition types.
Definition: AMReX_BoundCond.H:20
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int yhi() noexcept
Int value of the y-hi-face.
Definition: AMReX_Orientation.H:110
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int ylo() noexcept
Int value of the y-lo-face.
Definition: AMReX_Orientation.H:106
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int xlo() noexcept
Int value of the x-lo-face.
Definition: AMReX_Orientation.H:98
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int xhi() noexcept
Int value of the x-hi-face.
Definition: AMReX_Orientation.H:102
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mltensor_dx_on_yface(int i, int j, int k, int n, Array4< Real const > const &vel, Real dxi) noexcept
Definition: AMReX_MLTensor_K.H:17
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mltensor_dy_on_xface(int i, int j, int k, int n, Array4< Real const > const &vel, Real dyi) noexcept
Definition: AMReX_MLTensor_K.H:11
Definition: AMReX_Array.H:282
Definition: AMReX_Array4.H:61
Definition: AMReX_Dim3.H:12