Block-Structured AMR Software Framework
AMReX_MLALap_1D_K.H
Go to the documentation of this file.
1 #ifndef AMREX_MLALAP_1D_K_H_
2 #define AMREX_MLALAP_1D_K_H_
3 #include <AMReX_Config.H>
4 
5 namespace amrex {
6 
7 template <typename RT>
9 void mlalap_adotx (Box const& box, Array4<RT> const& y,
10  Array4<RT const> const& x,
11  Array4<RT const> const& a,
12  GpuArray<RT,AMREX_SPACEDIM> const& dxinv,
13  RT alpha, RT beta, int ncomp) noexcept
14 {
15  const RT dhx = beta*dxinv[0]*dxinv[0];
16 
17  const auto lo = amrex::lbound(box);
18  const auto hi = amrex::ubound(box);
19 
20  for (int n = 0; n < ncomp; ++n) {
22  for (int i = lo.x; i <= hi.x; ++i) {
23  y(i,0,0,n) = alpha*a(i,0,0,n)*x(i,0,0,n)
24  - dhx * (x(i+1,0,0,n) - RT(2.)*x(i,0,0,n) + x(i-1,0,0,n));
25  }
26  }
27 }
28 
29 template <typename RT>
31 void mlalap_adotx_m (Box const& box, Array4<RT> const& y,
32  Array4<RT const> const& x,
33  Array4<RT const> const& a,
34  GpuArray<RT,AMREX_SPACEDIM> const& dxinv,
35  RT alpha, RT beta,
36  RT dx, RT probxlo, int ncomp) noexcept
37 {
38  const RT dhx = beta*dxinv[0]*dxinv[0];
39 
40  const auto lo = amrex::lbound(box);
41  const auto hi = amrex::ubound(box);
42 
43  for (int n = 0; n < ncomp; ++n) {
45  for (int i = lo.x; i <= hi.x; ++i) {
46  RT rel = (probxlo + i *dx) * (probxlo + i *dx);
47  RT rer = (probxlo +(i+1)*dx) * (probxlo +(i+1)*dx);
48  RT rc = (probxlo +(i+RT(.5))*dx) * (probxlo +(i+RT(.5))*dx);
49  y(i,0,0,n) = alpha*a(i,0,0,n)*x(i,0,0,n)*rc
50  - dhx * (rer*(x(i+1,0,0,n) - x(i ,0,0,n))
51  - rel*(x(i ,0,0,n) - x(i-1,0,0,n)));
52  }
53  }
54 }
55 
56 template <typename RT>
58 void mlalap_normalize (Box const& box, Array4<RT> const& x,
59  Array4<RT const> const& a,
60  GpuArray<RT,AMREX_SPACEDIM> const& dxinv,
61  RT alpha, RT beta, int ncomp) noexcept
62 {
63  const RT dhx = beta*dxinv[0]*dxinv[0];
64 
65  const auto lo = amrex::lbound(box);
66  const auto hi = amrex::ubound(box);
67 
68  for (int n = 0; n < ncomp; ++n) {
70  for (int i = lo.x; i <= hi.x; ++i) {
71  x(i,0,0,n) /= alpha*a(i,0,0,n) + dhx*RT(2.0);
72  }
73  }
74 }
75 
76 template <typename RT>
78 void mlalap_normalize_m (Box const& box, Array4<RT> const& x,
79  Array4<RT const> const& a,
80  GpuArray<RT,AMREX_SPACEDIM> const& dxinv,
81  RT alpha, RT beta, RT dx, RT probxlo, int ncomp) noexcept
82 {
83  const RT dhx = beta*dxinv[0]*dxinv[0];
84 
85  const auto lo = amrex::lbound(box);
86  const auto hi = amrex::ubound(box);
87 
88  for (int n = 0; n < ncomp; ++n) {
90  for (int i = lo.x; i <= hi.x; ++i) {
91  RT rel = (probxlo + i *dx) * (probxlo + i *dx);
92  RT rer = (probxlo +(i+1)*dx) * (probxlo +(i+1)*dx);
93  RT rc = (probxlo +(i+RT(.5))*dx) * (probxlo +(i+RT(.5))*dx);
94  x(i,0,0,n) /= alpha*a(i,0,0,n)*rc + dhx*(rel+rer);
95  }
96  }
97 }
98 
99 template <typename RT>
101 void mlalap_flux_x (Box const& box, Array4<RT> const& fx,
102  Array4<RT const> const& sol, RT fac, int ncomp) noexcept
103 {
104  const auto lo = amrex::lbound(box);
105  const auto hi = amrex::ubound(box);
106 
107  for (int n = 0; n < ncomp; ++n) {
109  for (int i = lo.x; i <= hi.x; ++i) {
110  fx(i,0,0,n) = -fac*(sol(i,0,0,n)-sol(i-1,0,0,n));
111  }
112  }
113 }
114 
115 template <typename RT>
117 void mlalap_flux_x_m (Box const& box, Array4<RT> const& fx,
118  Array4<RT const> const& sol, RT fac,
119  RT dx, RT probxlo, int ncomp) noexcept
120 {
121  const auto lo = amrex::lbound(box);
122  const auto hi = amrex::ubound(box);
123 
124  for (int n = 0; n < ncomp; ++n) {
126  for (int i = lo.x; i <= hi.x; ++i) {
127  RT re = (probxlo + i*dx) * (probxlo + i*dx);
128  fx(i,0,0,n) = -fac*re*(sol(i,0,0,n)-sol(i-1,0,0,n));
129  }
130  }
131 }
132 
133 template <typename RT>
135 void mlalap_flux_xface (Box const& box, Array4<RT> const& fx,
136  Array4<RT const> const& sol, RT fac, int xlen, int ncomp) noexcept
137 {
138  const auto lo = amrex::lbound(box);
139 
140  for (int n = 0; n < ncomp; ++n) {
141  int i = lo.x;
142  fx(i,0,0,n) = -fac*(sol(i,0,0,n)-sol(i-1,0,0,n));
143  i += xlen;
144  fx(i,0,0,n) = -fac*(sol(i,0,0,n)-sol(i-1,0,0,n));
145  }
146 }
147 
148 template <typename RT>
150 void mlalap_flux_xface_m (Box const& box, Array4<RT> const& fx,
151  Array4<RT const> const& sol, RT fac, int xlen,
152  RT dx, RT probxlo, int ncomp) noexcept
153 {
154  const auto lo = amrex::lbound(box);
155 
156  for (int n = 0; n < ncomp; ++n) {
157  int i = lo.x;
158  RT re = (probxlo + i*dx) * (probxlo + i*dx);
159  fx(i,0,0,n) = -fac*re*(sol(i,0,0,n)-sol(i-1,0,0,n));
160  i += xlen;
161  re = (probxlo + i*dx) * (probxlo + i*dx);
162  fx(i,0,0,n) = -fac*re*(sol(i,0,0,n)-sol(i-1,0,0,n));
163  }
164 }
165 
166 template <typename RT>
168 void mlalap_gsrb (Box const& box, Array4<RT> const& phi,
169  Array4<RT const> const& rhs, RT alpha,
170  RT dhx, Array4<RT const> const& a,
171  Array4<RT const> const& f0, Array4<int const> const& m0,
172  Array4<RT const> const& f1, Array4<int const> const& m1,
173  Box const& vbox, int redblack, int ncomp) noexcept
174 {
175  const auto lo = amrex::lbound(box);
176  const auto hi = amrex::ubound(box);
177  const auto vlo = amrex::lbound(vbox);
178  const auto vhi = amrex::ubound(vbox);
179 
180  for (int n = 0; n < ncomp; ++n) {
182  for (int i = lo.x; i <= hi.x; ++i) {
183  if ((i+redblack)%2 == 0) {
184  RT cf0 = (i == vlo.x && m0(vlo.x-1,0,0) > 0)
185  ? f0(vlo.x,0,0,n) : RT(0.0);
186  RT cf1 = (i == vhi.x && m1(vhi.x+1,0,0) > 0)
187  ? f1(vhi.x,0,0,n) : RT(0.0);
188 
189  RT delta = dhx*(cf0+cf1);
190 
191  RT gamma = alpha*a(i,0,0,n) + dhx*RT(2.0);
192 
193  RT rho = dhx*(phi(i-1,0,0,n) + phi(i+1,0,0,n));
194 
195  phi(i,0,0,n) = (rhs(i,0,0,n) + rho - phi(i,0,0,n)*delta)
196  / (gamma - delta);
197  }
198  }
199  }
200 }
201 
202 template <typename RT>
204 void mlalap_gsrb_m (Box const& box, Array4<RT> const& phi,
205  Array4<RT const> const& rhs, RT alpha,
206  RT dhx, Array4<RT const> const& a,
207  Array4<RT const> const& f0, Array4<int const> const& m0,
208  Array4<RT const> const& f1, Array4<int const> const& m1,
209  Box const& vbox, int redblack,
210  RT dx, RT probxlo, int ncomp)
211 {
212  const auto lo = amrex::lbound(box);
213  const auto hi = amrex::ubound(box);
214  const auto vlo = amrex::lbound(vbox);
215  const auto vhi = amrex::ubound(vbox);
216 
217  for (int n = 0; n < ncomp; ++n) {
219  for (int i = lo.x; i <= hi.x; ++i) {
220  if ((i+redblack)%2 == 0) {
221  RT cf0 = (i == vlo.x && m0(vlo.x-1,0,0) > 0)
222  ? f0(vlo.x,0,0,n) : RT(0.0);
223  RT cf1 = (i == vhi.x && m1(vhi.x+1,0,0) > 0)
224  ? f1(vhi.x,0,0,n) : RT(0.0);
225 
226  RT rel = (probxlo + i *dx) * (probxlo + i *dx);
227  RT rer = (probxlo +(i+1)*dx) * (probxlo +(i+1)*dx);
228  RT rc = (probxlo +(i+RT(.5))*dx) * (probxlo +(i+RT(.5))*dx);
229 
230  RT delta = dhx*(rel*cf0 + rer*cf1);
231 
232  RT gamma = alpha*a(i,0,0,n)*rc + dhx*(rel+rer);
233 
234  RT rho = dhx*(rel*phi(i-1,0,0,n) + rer*phi(i+1,0,0,n));
235 
236  phi(i,0,0,n) = (rhs(i,0,0,n) + rho - phi(i,0,0,n)*delta)
237  / (gamma - delta);
238  }
239  }
240  }
241 }
242 
243 }
244 #endif
#define AMREX_PRAGMA_SIMD
Definition: AMReX_Extension.H:80
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlalap_flux_x(Box const &box, Array4< RT > const &fx, Array4< RT const > const &sol, RT fac, int ncomp) noexcept
Definition: AMReX_MLALap_1D_K.H:101
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlalap_normalize(Box const &box, Array4< RT > const &x, Array4< RT const > const &a, GpuArray< RT, AMREX_SPACEDIM > const &dxinv, RT alpha, RT beta, int ncomp) noexcept
Definition: AMReX_MLALap_1D_K.H:58
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlalap_gsrb(Box const &box, Array4< RT > const &phi, Array4< RT const > const &rhs, RT alpha, RT dhx, Array4< RT const > const &a, Array4< RT const > const &f0, Array4< int const > const &m0, Array4< RT const > const &f1, Array4< int const > const &m1, Box const &vbox, int redblack, int ncomp) noexcept
Definition: AMReX_MLALap_1D_K.H:168
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlalap_adotx_m(Box const &box, Array4< RT > const &y, Array4< RT const > const &x, Array4< RT const > const &a, GpuArray< RT, AMREX_SPACEDIM > const &dxinv, RT alpha, RT beta, RT dx, RT probxlo, int ncomp) noexcept
Definition: AMReX_MLALap_1D_K.H:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlalap_adotx(Box const &box, Array4< RT > const &y, Array4< RT const > const &x, Array4< RT const > const &a, GpuArray< RT, AMREX_SPACEDIM > const &dxinv, RT alpha, RT beta, int ncomp) noexcept
Definition: AMReX_MLALap_1D_K.H:9
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 mlalap_flux_xface_m(Box const &box, Array4< RT > const &fx, Array4< RT const > const &sol, RT fac, int xlen, RT dx, RT probxlo, int ncomp) noexcept
Definition: AMReX_MLALap_1D_K.H:150
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlalap_flux_x_m(Box const &box, Array4< RT > const &fx, Array4< RT const > const &sol, RT fac, RT dx, RT probxlo, int ncomp) noexcept
Definition: AMReX_MLALap_1D_K.H:117
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlalap_flux_xface(Box const &box, Array4< RT > const &fx, Array4< RT const > const &sol, RT fac, int xlen, int ncomp) noexcept
Definition: AMReX_MLALap_1D_K.H:135
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlalap_gsrb_m(Box const &box, Array4< RT > const &phi, Array4< RT const > const &rhs, RT alpha, RT dhx, Array4< RT const > const &a, Array4< RT const > const &f0, Array4< int const > const &m0, Array4< RT const > const &f1, Array4< int const > const &m1, Box const &vbox, int redblack, RT dx, RT probxlo, int ncomp)
Definition: AMReX_MLALap_1D_K.H:204
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlalap_normalize_m(Box const &box, Array4< RT > const &x, Array4< RT const > const &a, GpuArray< RT, AMREX_SPACEDIM > const &dxinv, RT alpha, RT beta, RT dx, RT probxlo, int ncomp) noexcept
Definition: AMReX_MLALap_1D_K.H:78
Definition: AMReX_Array4.H:61
Definition: AMReX_Array.H:34