Line data Source code
1 :
2 : #ifndef AMREX_BCREC_H_
3 : #define AMREX_BCREC_H_
4 : #include <AMReX_Config.H>
5 :
6 : #include <AMReX_Box.H>
7 : #include <AMReX_BC_TYPES.H>
8 :
9 : namespace amrex {
10 : /**
11 : * \brief Boundary Condition Records.
12 : * Necessary information and functions for computing boundary conditions.
13 : *
14 : * This class has standard layout. And we should keep it so!
15 : */
16 : class BCRec
17 : {
18 : public:
19 : /**
20 : * \brief The default constructor, which does NOT set valid boundary types.
21 : */
22 : AMREX_GPU_HOST_DEVICE
23 268824 : BCRec () noexcept
24 :
25 : = default;
26 : /**
27 : * \brief The constructor.
28 : */
29 : AMREX_GPU_HOST_DEVICE
30 : BCRec (AMREX_D_DECL(int loX, int loY, int loZ),
31 : AMREX_D_DECL(int hiX, int hiY, int hiZ)) noexcept
32 : : bc {AMREX_D_DECL(loX,loY,loZ),
33 : AMREX_D_DECL(hiX,hiY,hiZ)}
34 : {}
35 : /**
36 : * \brief Another constructor.
37 : */
38 : AMREX_GPU_HOST_DEVICE
39 159270 : BCRec (const int* a_lo, const int* a_hi) noexcept
40 159270 : : bc {AMREX_D_DECL(a_lo[0],a_lo[1],a_lo[2]),
41 159270 : AMREX_D_DECL(a_hi[0],a_hi[1],a_hi[2])}
42 159270 : {}
43 : /*
44 : * \brief Yet another constructor. Inherits bndry types from bc_domain
45 : * when bx lies on edge of domain otherwise gets interior Dirichlet.
46 : */
47 : AMREX_GPU_HOST_DEVICE
48 : BCRec (const Box& bx,
49 : const Box& domain,
50 : const BCRec& bc_domain) noexcept
51 : {
52 : const int* bxlo = bx.loVect();
53 : const int* bxhi = bx.hiVect();
54 : const int* dlo = domain.loVect();
55 : const int* dhi = domain.hiVect();
56 : for (int dir = 0; dir < AMREX_SPACEDIM; dir++)
57 : {
58 : int ilo = dir;
59 : int ihi = dir+AMREX_SPACEDIM;
60 : bc[ilo] = ( bxlo[dir]<=dlo[dir] ? bc_domain.bc[ilo] : BCType::int_dir );
61 : bc[ihi] = ( bxhi[dir]>=dhi[dir] ? bc_domain.bc[ihi] : BCType::int_dir );
62 : }
63 : }
64 : /*
65 : * \brief Explicitly set lo bndry value.
66 : */
67 : AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
68 : void setLo (int dir, int bc_val) noexcept { bc[dir] = bc_val; }
69 : /**
70 : * \brief Explicitly set hi bndry value.
71 : */
72 : AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
73 : void setHi (int dir, int bc_val) noexcept { bc[AMREX_SPACEDIM+dir] = bc_val; }
74 : /**
75 : * \brief Explicitly set bndry value for given face.
76 : */
77 : AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
78 : void set (Orientation face, int bc_val) noexcept {
79 : if (face.isLow()) {
80 : setLo(face.coordDir(), bc_val);
81 : } else {
82 : setHi(face.coordDir(), bc_val);
83 : }
84 : }
85 : /**
86 : * \brief Return bndry values (used in calls to FORTRAN).
87 : */
88 : [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
89 : const int* vect () const& noexcept{ return bc; }
90 : const int* vect () && = delete;
91 :
92 : [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
93 : const int* data () const& noexcept { return bc; }
94 : const int* data () && = delete;
95 :
96 : /**
97 : * \brief Return low-end boundary data.
98 : */
99 : [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
100 : const int* lo () const& noexcept { return bc; }
101 : const int* lo () && = delete;
102 : /**
103 : * \brief Return high-end boundary data.
104 : */
105 : [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
106 : const int* hi () const& noexcept { return bc+AMREX_SPACEDIM; }
107 : const int* hi () && = delete;
108 : /**
109 : * \brief Return low-end boundary data in direction \<dir\>.
110 : */
111 : [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
112 : int lo (int dir) const noexcept { return bc[dir]; }
113 : /**
114 : * \brief Return high-end boundary data in direction \<dir\>.
115 : */
116 : [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
117 : int hi (int dir) const noexcept { return bc[AMREX_SPACEDIM+dir]; }
118 : /**
119 : * \brief Equal test.
120 : */
121 : [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
122 : bool operator== (const BCRec& rhs) const noexcept {
123 : bool retval = true;
124 : for (int i = 0; i < 2*AMREX_SPACEDIM && retval; i++)
125 : {
126 : retval &= bc[i] == rhs.bc[i];
127 : }
128 : return retval;
129 : }
130 : /**
131 : * \brief Not equal test.
132 : */
133 : [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
134 : bool operator!= (const BCRec& rhs) const noexcept { return !(*this == rhs); }
135 : /**
136 : * \brief ASCII write to ostream.
137 : */
138 : friend std::ostream& operator << (std::ostream&, const BCRec&);
139 :
140 : private:
141 : /**
142 : * \brief Array of integer values describing boundary conditions.
143 : */
144 : int bc[2*AMREX_SPACEDIM]{AMREX_D_DECL(BCType::bogus,BCType::bogus,BCType::bogus),
145 : AMREX_D_DECL(BCType::bogus,BCType::bogus,BCType::bogus)};
146 : };
147 :
148 : /**
149 : * \brief Function for setting a BC.
150 : */
151 : AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
152 : void
153 : setBC (const Box& bx, const Box& domain, const BCRec& bc_dom, BCRec& bcr) noexcept
154 : {
155 : const int* bxlo = bx.loVect();
156 : const int* bxhi = bx.hiVect();
157 : const int* dlo = domain.loVect();
158 : const int* dhi = domain.hiVect();
159 : for (int dir = 0; dir < AMREX_SPACEDIM; dir++)
160 : {
161 : bcr.setLo(dir, ( bxlo[dir]<=dlo[dir] ? bc_dom.lo(dir) : BCType::int_dir ));
162 : bcr.setHi(dir, ( bxhi[dir]>=dhi[dir] ? bc_dom.hi(dir) : BCType::int_dir ));
163 : }
164 : }
165 :
166 : /**
167 : * \brief Function for setting array of BCs.
168 : */
169 : void
170 : setBC (const Box& bx,
171 : const Box& domain,
172 : int src_comp,
173 : int dest_comp,
174 : int ncomp,
175 : const Vector<BCRec>& bc_dom,
176 : Vector<BCRec>& bcr) noexcept;
177 : }
178 :
179 : #endif /*_BCREC_H_*/
|