Block-Structured AMR Software Framework
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
AMReX_MLNodeLinOp_1D_K.H
Go to the documentation of this file.
1#ifndef AMREX_ML_NODE_LINOP_1D_K_H_
2#define AMREX_ML_NODE_LINOP_1D_K_H_
3#include <AMReX_Config.H>
4
5namespace amrex {
6
7template <typename T>
8void mlndlap_bc_doit (Box const& vbx, Array4<T> const& a, Box const& domain,
10 GpuArray<bool,AMREX_SPACEDIM> const& bfhi) noexcept
11{
12 Box gdomain = domain;
13 int const idim = 0;
14 if (! bflo[idim]) { gdomain.growLo(idim,1); }
15 if (! bfhi[idim]) { gdomain.growHi(idim,1); }
16
17 if (gdomain.strictly_contains(vbx)) { return; }
18
19 const int offset = domain.cellCentered() ? 0 : 1;
20
21 const auto dlo = domain.smallEnd(0);
22 const auto dhi = domain.bigEnd(0);
23
24 Box const& sbox = amrex::grow(vbx,1);
25 AMREX_HOST_DEVICE_FOR_3D(sbox, i, j, k,
26 {
27 if (! gdomain.contains(IntVect(i))) {
28 if (i == dlo-1 && bflo[0])
29 {
30 a(i,0,0) = a(i+1+offset, j, k);
31 }
32 else if (i == dhi+1 && bfhi[0])
33 {
34 a(i,0,0) = a(i-1-offset, j, k);
35 }
36 }
37 });
38}
39
41void mlndlap_restriction (int i, int, int, Array4<Real> const& crse,
42 Array4<Real const> const& fine, Array4<int const> const& msk) noexcept
43{
44 int ii = i*2;
45 if (msk(ii,0,0)) {
46 crse(i,0,0) = Real(0.0);
47 } else {
48 crse(i,0,0) = Real(1./4.) *(fine(ii-1,0,0)
49 + Real(2.)* fine(ii ,0,0)
50 + fine(ii+1,0,0));
51 }
52}
53
54template <int rr>
56void mlndlap_restriction (int i, int, int, Array4<Real> const& crse,
57 Array4<Real const> const& fine, Array4<int const> const& msk,
58 Box const& fdom,
60 GpuArray<LinOpBCType, AMREX_SPACEDIM> const& bchi) noexcept
61
62{
63 const int ii = i*rr;
64 if (msk(ii,0,0)) {
65 crse(i,0,0) = Real(0.0);
66 } else {
67 const auto ndlo = fdom.smallEnd(0);
68 const auto ndhi = fdom.bigEnd(0);
69 Real tmp = Real(0.0);
70 for (int ioff = -rr+1; ioff <= rr-1; ++ioff) {
71 Real wx = rr - std::abs(ioff);
72 int itmp = ii + ioff;
73 if ((itmp < ndlo && (bclo[0] == LinOpBCType::Neumann ||
74 bclo[0] == LinOpBCType::inflow)) ||
75 (itmp > ndhi && (bchi[0] == LinOpBCType::Neumann ||
76 bchi[0] == LinOpBCType::inflow))) {
77 itmp = ii - ioff;
78 }
79 tmp += wx*fine(itmp,0,0);
80 }
81 crse(i,0,0) = tmp*(Real(1.0)/Real(rr*rr));
82 }
83}
84
86void mlndlap_semi_restriction (int /*i*/, int /*j*/, int /*k*/, Array4<Real> const&,
87 Array4<Real const> const&, Array4<int const> const&, int) noexcept
88{
89 amrex::Abort("mlndlap_semi_restriction: not implemented in 1D");
90}
91
93void mlndlap_set_nodal_mask (int i, int, int, Array4<int> const& nmsk,
94 Array4<int const> const& cmsk) noexcept
95{
96 using namespace nodelap_detail;
97
98 int s = cmsk(i-1,0,0) + cmsk(i,0,0);
99 if (s == 2*crse_cell) {
100 nmsk(i,0,0) = crse_node;
101 } else if (s == 2*fine_cell) {
102 nmsk(i,0,0) = fine_node;
103 } else {
104 nmsk(i,0,0) = crse_fine_node;
105 }
106}
107
109void mlndlap_set_dirichlet_mask (Box const& bx, Array4<int> const& dmsk,
110 Array4<int const> const& omsk, Box const& dom,
112 GpuArray<LinOpBCType, AMREX_SPACEDIM> const& bchi) noexcept
113{
114 const auto lo = bx.smallEnd(0);
115 const auto hi = bx.bigEnd(0);
117 for (int i = lo; i <= hi; ++i) {
118 if (!dmsk(i,0,0)) {
119 dmsk(i,0,0) = (omsk(i-1,0,0) == 1 || omsk(i,0,0) == 1);
120 }
121 }
122
123 const auto domlo = dom.smallEnd(0);
124 const auto domhi = dom.bigEnd(0);
125
126 if (bclo[0] == LinOpBCType::Dirichlet && lo == domlo) {
127 dmsk(lo,0,0) = 1;
128 }
129
130 if (bchi[0] == LinOpBCType::Dirichlet && hi == domhi) {
131 dmsk(hi,0,0) = 1;
132 }
133}
134
136void mlndlap_set_dot_mask (Box const& bx, Array4<Real> const& dmsk,
137 Array4<int const> const& omsk, Box const& dom,
139 GpuArray<LinOpBCType, AMREX_SPACEDIM> const& bchi) noexcept
140{
141 const auto lo = bx.smallEnd(0);
142 const auto hi = bx.bigEnd(0);
143
145 for (int i = lo; i <= hi; ++i) {
146 dmsk(i,0,0) = static_cast<Real>(omsk(i,0,0));
147 }
148
149 const auto domlo = dom.smallEnd(0);
150 const auto domhi = dom.bigEnd(0);
151
152 if ((bclo[0] == LinOpBCType::Neumann || bclo[0] == LinOpBCType::inflow)
153 && lo == domlo)
154 {
155 dmsk(lo,0,0) *= Real(0.5);
156 }
157
158 if ((bchi[0] == LinOpBCType::Neumann || bchi[0] == LinOpBCType::inflow)
159 && hi == domhi)
160 {
161 dmsk(hi,0,0) *= Real(0.5);
162 }
163}
164
166void mlndlap_set_dot_mask (Box const& bx, Array4<Real> const& dmsk,
167 Array4<int const> const& omsk,
168 Array4<int const> const& fmsk, Box const& dom,
170 GpuArray<LinOpBCType, AMREX_SPACEDIM> const& bchi) noexcept
171{
172 const auto lo = bx.smallEnd(0);
173 const auto hi = bx.bigEnd(0);
174
176 for (int i = lo; i <= hi; ++i) {
177 if (fmsk(i,0,0) == 0) {
178 dmsk(i,0,0) = static_cast<Real>(omsk(i,0,0));
179 } else {
180 dmsk(i,0,0) = Real(0);
181 }
182 }
183
184 const auto domlo = dom.smallEnd(0);
185 const auto domhi = dom.bigEnd(0);
186
187 if ((bclo[0] == LinOpBCType::Neumann || bclo[0] == LinOpBCType::inflow)
188 && lo == domlo)
189 {
190 dmsk(lo,0,0) *= Real(0.5);
191 }
192
193 if ((bchi[0] == LinOpBCType::Neumann || bchi[0] == LinOpBCType::inflow)
194 && hi == domhi)
195 {
196 dmsk(hi,0,0) *= Real(0.5);
197 }
198}
199
200}
201
202#endif
#define AMREX_PRAGMA_SIMD
Definition AMReX_Extension.H:80
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_HOST_DEVICE_FOR_3D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:106
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1089
Array4< Real > fine
Definition AMReX_InterpFaceRegister.cpp:90
Array4< Real const > crse
Definition AMReX_InterpFaceRegister.cpp:92
AMREX_GPU_HOST_DEVICE bool strictly_contains(const IntVectND< dim > &p) const noexcept
Returns true if argument is strictly contained within BoxND.
Definition AMReX_Box.H:236
AMREX_GPU_HOST_DEVICE BoxND & growLo(int idir, int n_cell=1) noexcept
Grow the BoxND on the low end by n_cell cells in direction idir. NOTE: n_cell negative shrinks the Bo...
Definition AMReX_Box.H:648
AMREX_GPU_HOST_DEVICE BoxND & growHi(int idir, int n_cell=1) noexcept
Grow the BoxND on the high end by n_cell cells in direction idir. NOTE: n_cell negative shrinks the B...
Definition AMReX_Box.H:659
AMREX_GPU_HOST_DEVICE bool cellCentered() const noexcept
Returns true if BoxND is cell-centered in all indexing directions.
Definition AMReX_Box.H:319
AMREX_GPU_HOST_DEVICE bool contains(const IntVectND< dim > &p) const noexcept
Returns true if argument is contained within BoxND.
Definition AMReX_Box.H:204
Definition AMReX_Amr.cpp:49
void mlndlap_bc_doit(Box const &vbx, Array4< T > const &a, Box const &domain, GpuArray< bool, AMREX_SPACEDIM > const &bflo, GpuArray< bool, AMREX_SPACEDIM > const &bfhi) noexcept
Definition AMReX_MLNodeLinOp_1D_K.H:8
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_set_nodal_mask(int i, int, int, Array4< int > const &nmsk, Array4< int const > const &cmsk) noexcept
Definition AMReX_MLNodeLinOp_1D_K.H:93
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_restriction(int i, int, int, Array4< Real > const &crse, Array4< Real const > const &fine, Array4< int const > const &msk) noexcept
Definition AMReX_MLNodeLinOp_1D_K.H:41
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_semi_restriction(int, int, int, Array4< Real > const &, Array4< Real const > const &, Array4< int const > const &, int) noexcept
Definition AMReX_MLNodeLinOp_1D_K.H:86
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Grow BoxND in all directions by given amount.
Definition AMReX_Box.H:1211
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_set_dirichlet_mask(Box const &bx, Array4< int > const &dmsk, Array4< int const > const &omsk, Box const &dom, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &bclo, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &bchi) noexcept
Definition AMReX_MLNodeLinOp_1D_K.H:109
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_set_dot_mask(Box const &bx, Array4< Real > const &dmsk, Array4< int const > const &omsk, Box const &dom, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &bclo, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &bchi) noexcept
Definition AMReX_MLNodeLinOp_1D_K.H:136
Definition AMReX_Array4.H:61
Definition AMReX_Array.H:34