Block-Structured AMR Software Framework
AMReX_extrapolater_2D_K.H
Go to the documentation of this file.
1 #ifndef AMReX_extrapolater_2D_K_H_
2 #define AMReX_extrapolater_2D_K_H_
3 #include <AMReX_Config.H>
4 
5 namespace amrex {
6 
9 void
11  int nComp,
13  amrex::Array4<amrex::Real> const& data) noexcept
14 {
15  using namespace amrex::literals;
16 
17  constexpr int finecell = 1;
18  constexpr int crsecell = 0;
19 
20  const auto lo = amrex::lbound(bx);
21  const auto hi = amrex::ubound(bx);
22 
23  int k = lo.z;
24 
25  for (int n = 0; n < nComp; n++) {
26 
27  // set the crse cells in the current layer to zero
28  { // y-dir edges
29  int j = lo.y-1;
30  for (int i = lo.x-1; i <= hi.x+1; ++i) {
31  if (mask(i,j,k) == crsecell) { data(i,j,k,n) = Real(0.0); }
32  }
33  j = hi.y+1;
34  for (int i = lo.x-1; i <= hi.x+1; ++i) {
35  if (mask(i,j,k) == crsecell) { data(i,j,k,n) = Real(0.0); }
36  }
37  }
38  { // x-dir edges
39  int i = lo.x-1;
40  for (int j = lo.y-1; j <= hi.y+1; ++j) {
41  if (mask(i,j,k) == crsecell) { data(i,j,k,n) = Real(0.0); }
42  }
43  i = hi.x+1;
44  for (int j = lo.y-1; j <= hi.y+1; ++j) {
45  if (mask(i,j,k) == crsecell) { data(i,j,k,n) = Real(0.0); }
46  }
47  }
48 
49  // Corners
50  // xlo, ylo
51  {
52  int i = lo.x-1;
53  int j = lo.y-1;
54  if ( mask(i,j,k) == crsecell ) {
55  if ( ( mask(i+1,j,k) == finecell ) ||
56  ( mask(i,j+1,k) == finecell ) ) {
57  data(i,j,k,n) = ( Real(mask(i+1,j,k)) * data(i+1,j,k,n) + Real(mask(i,j+1,k)) * data(i,j+1,k,n) )
58  / Real( mask(i+1,j,k) + mask(i,j+1,k) );
59  } else {
60  data(i,j,k,n) = data(i+1,j+1,k,n);
61  }
62  }
63  }
64  // xlo, yhi
65  {
66  int i = lo.x-1;
67  int j = hi.y+1;
68  if ( mask(i,j,k) == crsecell ) {
69  if ( ( mask(i+1,j,k) == finecell ) ||
70  ( mask(i,j-1,k) == finecell ) ) {
71  data(i,j,k,n) = ( Real(mask(i+1,j,k)) * data(i+1,j,k,n) + Real(mask(i,j-1,k)) * data(i,j-1,k,n) )
72  / Real( mask(i+1,j,k) + mask(i,j-1,k) );
73  } else {
74  data(i,j,k,n) = data(i+1,j-1,k,n);
75  }
76  }
77  }
78  // xhi, ylo
79  {
80  int i = hi.x+1;
81  int j = lo.y-1;
82  if ( mask(i,j,k) == crsecell ) {
83  if ( ( mask(i-1,j,k) == finecell ) ||
84  ( mask(i,j+1,k) == finecell ) ) {
85  data(i,j,k,n) = ( Real(mask(i-1,j,k)) * data(i-1,j,k,n) + Real(mask(i,j+1,k)) * data(i,j+1,k,n) )
86  / Real( mask(i-1,j,k) + mask(i,j+1,k) );
87  } else {
88  data(i,j,k,n) = data(i-1,j+1,k,n);
89  }
90  }
91  }
92  // xhi, yhi
93  {
94  int i = hi.x+1;
95  int j = hi.y+1;
96  if ( mask(i,j,k) == crsecell ) {
97  if ( ( mask(i-1,j,k) == finecell ) ||
98  ( mask(i,j-1,k) == finecell ) ) {
99  data(i,j,k,n) = ( Real(mask(i-1,j,k)) * data(i-1,j,k,n) + Real(mask(i,j-1,k)) * data(i,j-1,k,n) )
100  / Real( mask(i-1,j,k) + mask(i,j-1,k) );
101  } else {
102  data(i,j,k,n) = data(i-1,j-1,k,n);
103  }
104  }
105  }
106  // Edges
107  // xlo, y-valid
108  {
109  int i = lo.x-1;
110  for (int j = lo.y; j <= hi.y; ++j) {
111  if ( mask(i,j,k) == crsecell ) {
112  data(i,j,k,n) = ( Real(mask(i,j-1,k)) * data(i,j-1,k,n) + data(i+1,j,k,n) + Real(mask(i,j+1,k)) * data(i,j+1,k,n) )
113  / Real( mask(i,j-1,k) + 1 + mask(i,j+1,k) );
114  }
115  }
116  }
117  // xhi, y-valid
118  {
119  int i = hi.x+1;
120  for (int j = lo.y; j <= hi.y; ++j) {
121  if ( mask(i,j,k) == crsecell ) {
122  data(i,j,k,n) = ( Real(mask(i,j-1,k)) * data(i,j-1,k,n) + data(i-1,j,k,n) + Real(mask(i,j+1,k)) * data(i,j+1,k,n) )
123  / Real( mask(i,j-1,k) + 1 + mask(i,j+1,k) );
124  }
125  }
126  }
127  // x-valid, ylo
128  {
129  int j = lo.y-1;
130  for (int i = lo.x; i <= hi.x; ++i) {
131  if ( mask(i,j,k) == crsecell ) {
132  data(i,j,k,n) = ( Real(mask(i-1,j,k)) * data(i-1,j,k,n) + Real(mask(i+1,j,k)) * data(i+1,j,k,n) + data(i,j+1,k,n) )
133  / Real( mask(i-1,j,k) + mask(i+1,j,k) + 1 );
134  }
135  }
136  }
137  // x-valid, yhi
138  {
139  int j = hi.y+1;
140  for (int i = lo.x; i <= hi.x; ++i) {
141  if ( mask(i,j,k) == crsecell ) {
142  data(i,j,k,n) = ( Real(mask(i-1,j,k)) * data(i-1,j,k,n) + Real(mask(i+1,j,k)) * data(i+1,j,k,n) + data(i,j-1,k,n) )
143  / Real( mask(i-1,j,k) + mask(i+1,j,k) + 1 );
144  }
145  }
146  }
147  }
148 }
149 
152 void
153 amrex_first_order_extrap_gpu(int i, int j, int k, int n,
154  amrex::Box const& bx,
156  amrex::Array4<amrex::Real> const& data) noexcept
157 {
158  using namespace amrex::literals;
159 
160  constexpr int finecell = 1;
161  constexpr int crsecell = 0;
162 
163  const auto lo = amrex::lbound(bx);
164  const auto hi = amrex::ubound(bx);
165 
166  if ( mask(i,j,k) == crsecell ) {
167  // Corners
168  // xlo, ylo
169  if ( (i == lo.x-1) && (j == lo.y-1) ) {
170  if ( ( mask(i+1,j,k) == finecell ) ||
171  ( mask(i,j+1,k) == finecell ) ) {
172  data(i,j,k,n) = ( Real(mask(i+1,j,k)) * data(i+1,j,k,n) + Real(mask(i,j+1,k)) * data(i,j+1,k,n) )
173  / Real( mask(i+1,j,k) + mask(i,j+1,k) );
174  } else {
175  data(i,j,k,n) = data(i+1,j+1,k,n);
176  }
177  // xlo, yhi
178  } else if ( (i == lo.x-1) && (j == hi.y+1) ) {
179  if ( ( mask(i+1,j,k) == finecell ) ||
180  ( mask(i,j-1,k) == finecell ) ) {
181  data(i,j,k,n) = ( Real(mask(i+1,j,k)) * data(i+1,j,k,n) + Real(mask(i,j-1,k)) * data(i,j-1,k,n) )
182  / Real( mask(i+1,j,k) + mask(i,j-1,k) );
183  } else {
184  data(i,j,k,n) = data(i+1,j-1,k,n);
185  }
186  // xhi, ylo
187  } else if ( (i == hi.x+1) && (j == lo.y-1) ) {
188  if ( ( mask(i-1,j,k) == finecell ) ||
189  ( mask(i,j+1,k) == finecell ) ) {
190  data(i,j,k,n) = ( Real(mask(i-1,j,k)) * data(i-1,j,k,n) + Real(mask(i,j+1,k)) * data(i,j+1,k,n) )
191  / Real( mask(i-1,j,k) + mask(i,j+1,k) );
192  } else {
193  data(i,j,k,n) = data(i-1,j+1,k,n);
194  }
195  // xhi, yhi
196  } else if ( (i == hi.x+1) && (j == hi.y+1) ) {
197  if ( ( mask(i-1,j,k) == finecell ) ||
198  ( mask(i,j-1,k) == finecell ) ) {
199  data(i,j,k,n) = ( Real(mask(i-1,j,k)) * data(i-1,j,k,n) + Real(mask(i,j-1,k)) * data(i,j-1,k,n) )
200  / Real( mask(i-1,j,k) + mask(i,j-1,k) );
201  } else {
202  data(i,j,k,n) = data(i-1,j-1,k,n);
203  }
204  // Edges
205  // xlo, y-valid
206  } else if ( (i == lo.x-1) && (j >= lo.y) && (j <= hi.y) ) {
207  data(i,j,k,n) = ( Real(mask(i,j-1,k)) * data(i,j-1,k,n) + data(i+1,j,k,n) + Real(mask(i,j+1,k)) * data(i,j+1,k,n) )
208  / Real( mask(i,j-1,k) + 1 + mask(i,j+1,k) );
209  // xhi, y-valid
210  } else if ( (i == hi.x+1) && (j >= lo.y) && (j <= hi.y) ) {
211  data(i,j,k,n) = ( Real(mask(i,j-1,k)) * data(i,j-1,k,n) + data(i-1,j,k,n) + Real(mask(i,j+1,k)) * data(i,j+1,k,n) )
212  / Real( mask(i,j-1,k) + 1 + mask(i,j+1,k) );
213  // x-valid, ylo
214  } else if ( (i >= lo.x) && (i <= hi.x) && (j == lo.y-1) ) {
215  data(i,j,k,n) = ( Real(mask(i-1,j,k)) * data(i-1,j,k,n) + Real(mask(i+1,j,k)) * data(i+1,j,k,n) + data(i,j+1,k,n) )
216  / Real( mask(i-1,j,k) + mask(i+1,j,k) + 1 );
217  // x-valid, yhi
218  } else if ( (i >= lo.x) && (i <= hi.x) && (j == hi.y+1) ) {
219  data(i,j,k,n) = ( Real(mask(i-1,j,k)) * data(i-1,j,k,n) + Real(mask(i+1,j,k)) * data(i+1,j,k,n) + data(i,j-1,k,n) )
220  / Real( mask(i-1,j,k) + mask(i+1,j,k) + 1 );
221  }
222  }
223 }
224 
225 }
226 #endif
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
#define AMREX_GPU_HOST
Definition: AMReX_GpuQualifiers.H:17
Array4< int const > mask
Definition: AMReX_InterpFaceRegister.cpp:93
Definition: AMReX_Amr.cpp:49
int nComp(FabArrayBase const &fa)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 ubound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:315
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 lbound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:308
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_first_order_extrap_gpu(int i, int j, int k, int n, amrex::Box const &bx, amrex::Array4< const int > const &mask, amrex::Array4< amrex::Real > const &data) noexcept
Definition: AMReX_extrapolater_1D_K.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_first_order_extrap_cpu(amrex::Box const &bx, int nComp, amrex::Array4< const int > const &mask, amrex::Array4< amrex::Real > const &data) noexcept
Definition: AMReX_extrapolater_1D_K.H:10
Definition: AMReX_Array4.H:61