Skip to content

Commit

Permalink
Overloading Array4::operator(), ptr and contains (#3956)
Browse files Browse the repository at this point in the history
For convenience, add versions of `Array4::operator()`, `ptr` and
`contains` that take Dim3.
  • Loading branch information
WeiqunZhang committed May 23, 2024
1 parent e6c93bf commit 523c11e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions .codespell-ignore-words
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ parms
pres
ptd
recuse
rIn
shft
siz
structed
Expand Down
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
identity and expression, level of experience, education, socioeconomic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

Expand Down
36 changes: 36 additions & 0 deletions Src/Base/AMReX_Array4.H
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,30 @@ namespace amrex {
#endif
}

template <class U=T, std::enable_if_t<!std::is_void_v<U>,int> = 0>
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
U& operator() (Dim3 const& cell) const noexcept {
return this->operator()(cell.x,cell.y,cell.z);
}

template <class U=T, std::enable_if_t<!std::is_void_v<U>,int> = 0>
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
U& operator() (Dim3 const& cell, int n) const noexcept {
return this->operator()(cell.x,cell.y,cell.z,n);
}

template <class U=T, std::enable_if_t<!std::is_void_v<U>,int> = 0>
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
T* ptr (Dim3 const& cell) const noexcept {
return this->ptr(cell.x,cell.y,cell.z);
}

template <class U=T, std::enable_if_t<!std::is_void_v<U>,int> = 0>
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
T* ptr (Dim3 const& cell, int n) const noexcept {
return this->ptr(cell.x,cell.y,cell.z,n);
}

[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
T* dataPtr () const noexcept {
return this->p;
Expand All @@ -228,6 +252,18 @@ namespace amrex {
return (i>=begin.x && i<end.x && j>=begin.y && j<end.y && k>=begin.z && k<end.z);
}

[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
bool contains (IntVect const& iv) const noexcept {
return AMREX_D_TERM( iv[0]>=begin.x && iv[0]<end.x,
&& iv[1]>=begin.y && iv[1]<end.y,
&& iv[2]>=begin.z && iv[2]<end.z);
}

[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
bool contains (Dim3 const& cell) const noexcept {
return this->contains(cell.x,cell.y,cell.z);
}

#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
AMREX_GPU_HOST_DEVICE inline
void index_assert (int i, int j, int k, int n) const
Expand Down

0 comments on commit 523c11e

Please sign in to comment.