Block-Structured AMR Software Framework
AMReX_FilFC_2D_C.H
Go to the documentation of this file.
1 #ifndef AMREX_FILFC_2D_C_H_
2 #define AMREX_FILFC_2D_C_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_FArrayBox.H>
6 #include <AMReX_BCRec.H>
7 #include <AMReX_Geometry.H>
8 
9 namespace amrex {
10 
11 struct FilfcFace
12 {
14  void operator() (const IntVect& iv, Array4<Real> const& q,
15  const int dcomp, const int numcomp,
16  Box const& domain_box, const BCRec* bcr,
17  const int bcomp) const noexcept
18  {
19  const int i = iv[0];
20  const int j = iv[1];
21 
22  // Domain box is indexed according to the face currently treating
23  const IndexType &idxType = domain_box.ixType();
24  const auto& domain_lo = domain_box.loVect();
25  const auto& domain_hi = domain_box.hiVect();
26  const int ilo = domain_lo[0];
27  const int jlo = domain_lo[1];
28  const int ihi = domain_hi[0];
29  const int jhi = domain_hi[1];
30 
31  for (int n = dcomp; n < numcomp+dcomp; ++n)
32  {
33  const BCRec& bc = bcr[bcomp+n-dcomp];
34 
35  if (i == ilo)
36  {
37  // Enforce reflect_odd on the x domain face
38  if ((bc.lo(0) == BCType::reflect_odd) &&
39  (idxType.nodeCentered(0)) ) {
40  q(i,j,0,n) = 0.0;
41  }
42  }
43  else if (i < ilo)
44  {
45  switch (bc.lo(0)) {
46  case (BCType::foextrap):
47  {
48  q(i,j,0,n) = q(ilo,j,0,n);
49  break;
50  }
51  case (BCType::hoextrap):
52  {
53  if (i < ilo - 1)
54  {
55  q(i,j,0,n) = q(ilo,j,0,n);
56  }
57  // i == ilo-1
58  else
59  {
60  q(i,j,0,n) = (idxType.nodeCentered(0)) ? Real(2.0)*q(i+1,j,0,n) - q(i+2,j,0,n)
61  : Real(0.5)*(Real(3.)*q(i+1,j,0,n) - q(i+2,j,0,n));
62  }
63  break;
64  }
65  case (BCType::reflect_even):
66  {
67  q(i,j,0,n) = (idxType.nodeCentered(0)) ? q(2*ilo-i,j,0,n)
68  : q(2*ilo-i-1,j,0,n);
69  break;
70  }
71  case (BCType::reflect_odd):
72  {
73  q(i,j,0,n) = (idxType.nodeCentered(0)) ? -q(2*ilo-i,j,0,n)
74  : -q(2*ilo-i-1,j,0,n);
75  break;
76  }
77  default: { break; }
78  }
79  }
80  else if (i == ihi)
81  {
82  // Enforce reflect_odd on the x domain face
83  if ((bc.hi(0) == BCType::reflect_odd) &&
84  (idxType.nodeCentered(0)) ) {
85  q(i,j,0,n) = 0.0;
86  }
87  }
88  else if (i > ihi)
89  {
90  switch (bc.hi(0)) {
91  case (BCType::foextrap):
92  {
93  q(i,j,0,n) = q(ihi,j,0,n);
94  break;
95  }
96  case (BCType::hoextrap):
97  {
98  if (i > ihi + 1)
99  {
100  q(i,j,0,n) = q(ihi,j,0,n);
101  }
102  // i == ihi+1
103  else
104  {
105  q(i,j,0,n) = (idxType.nodeCentered(0)) ? Real(2.0)*q(i-1,j,0,n) - q(i-2,j,0,n)
106  : Real(0.5)*(Real(3.)*q(i-1,j,0,n) - q(i-2,j,0,n));
107  }
108  break;
109  }
110  case (BCType::reflect_even):
111  {
112  q(i,j,0,n) = (idxType.nodeCentered(0)) ? q(2*ihi-i,j,0,n)
113  : q(2*ihi-i+1,j,0,n);
114  break;
115  }
116  case (BCType::reflect_odd):
117  {
118  q(i,j,0,n) = (idxType.nodeCentered(0)) ? -q(2*ihi-i,j,0,n)
119  : -q(2*ihi-i+1,j,0,n);
120  break;
121  }
122  default: { break; }
123  }
124  }
125 
126  if (j == jlo)
127  {
128  // Enforce reflect_odd on the y domain face
129  if ((bc.lo(1) == BCType::reflect_odd) &&
130  (idxType.nodeCentered(1)) ) {
131  q(i,j,0,n) = 0.0;
132  }
133  }
134  else if (j < jlo)
135  {
136  switch (bc.lo(1)) {
137  case (BCType::foextrap):
138  {
139  q(i,j,0,n) = q(i,jlo,0,n);
140  break;
141  }
142  case (BCType::hoextrap):
143  {
144  if (j < jlo - 1)
145  {
146  q(i,j,0,n) = q(i,jlo,0,n);
147  }
148  // j == jlo-1
149  else
150  {
151  q(i,j,0,n) = (idxType.nodeCentered(1)) ? Real(2.0)*q(i,j+1,0,n) - q(i,j+2,0,n)
152  : Real(0.5)*(Real(3.)*q(i,j+1,0,n) - q(i,j+2,0,n));
153  }
154  break;
155  }
156  case (BCType::reflect_even):
157  {
158  q(i,j,0,n) = (idxType.nodeCentered(1)) ? q(i,2*jlo-j,0,n)
159  : q(i,2*jlo-j-1,0,n);
160  break;
161  }
162  case (BCType::reflect_odd):
163  {
164  q(i,j,0,n) = (idxType.nodeCentered(1)) ? -q(i,2*jlo-j,0,n)
165  : -q(i,2*jlo-j-1,0,n);
166  break;
167  }
168  default: { break; }
169  }
170  }
171  else if (j == jhi)
172  {
173  // Enforce reflect_odd on the y domain face
174  if ((bc.hi(1) == BCType::reflect_odd) &&
175  (idxType.nodeCentered(1)) ) {
176  q(i,j,0,n) = 0.0;
177  }
178  }
179  else if (j > jhi)
180  {
181  switch (bc.hi(1)) {
182  case (BCType::foextrap):
183  {
184  q(i,j,0,n) = q(i,jhi,0,n);
185  break;
186  }
187  case (BCType::hoextrap):
188  {
189  if (j > jhi + 1)
190  {
191  q(i,j,0,n) = q(i,jhi,0,n);
192  }
193  // j == jhi+1
194  else
195  {
196  q(i,j,0,n) = (idxType.nodeCentered(1)) ? Real(2.0)*q(i,j-1,0,n) - q(i,j-2,0,n)
197  : Real(0.5)*(Real(3.)*q(i,j-1,0,n) - q(i,j-2,0,n));
198  }
199  break;
200  }
201  case (BCType::reflect_even):
202  {
203  q(i,j,0,n) = (idxType.nodeCentered(1)) ? q(i,2*jhi-j,0,n)
204  : q(i,2*jhi-j+1,0,n);
205  break;
206  }
207  case (BCType::reflect_odd):
208  {
209  q(i,j,0,n) = (idxType.nodeCentered(1)) ? -q(i,2*jhi-j,0,n)
210  : -q(i,2*jhi-j+1,0,n);
211  break;
212  }
213  default: { break; }
214  }
215  }
216  }
217  }
218 };
219 
220 }
221 
222 #endif
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
Boundary Condition Records. Necessary information and functions for computing boundary conditions.
Definition: AMReX_BCRec.H:17
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const int * hi() const &noexcept
Return high-end boundary data.
Definition: AMReX_BCRec.H:106
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const int * lo() const &noexcept
Return low-end boundary data.
Definition: AMReX_BCRec.H:100
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool nodeCentered() const noexcept
True if the IndexTypeND is NODE based in all directions.
Definition: AMReX_IndexType.H:107
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE CellIndex ixType(int dir) const noexcept
Returns the CellIndex in direction dir.
Definition: AMReX_IndexType.H:116
Definition: AMReX_Amr.cpp:49
Definition: AMReX_Array4.H:61
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(const IntVect &iv, Array4< Real > const &q, const int dcomp, const int numcomp, Box const &domain_box, const BCRec *bcr, const int bcomp) const noexcept
Definition: AMReX_FilFC_1D_C.H:14