Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eebasso committed Nov 24, 2023
1 parent 9e35dc1 commit ad9c39f
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 3 deletions.
186 changes: 186 additions & 0 deletions Src/Base/AMReX_Dim3.H
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <AMReX_REAL.H>
#include <AMReX_GpuQualifiers.H>
// #include <AMReX_IntVect.H>

#include <iostream>

Expand All @@ -21,6 +22,191 @@ std::ostream& operator<< (std::ostream& os, const T& d)
return os;
}

// template <class T>
// struct Dim3T
// {
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T () noexcept = default;

// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T (T a_x, T a_y, T a_z) noexcept { define(a_x,a_y,a_z); }

// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// void define (T a_x, T a_y, T a_z) noexcept { x=a_x; y=a_y; z=a_z; }

// // AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// // T& operator[] (int d) noexcept { return d==0 ? x : d==1 ? y : z; }

// // AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// // const T& operator[] (int d) const noexcept { return d==0 ? x : d==1 ? y : z; }

// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// bool operator== (T val) const noexcept { return x == val && y == val && z == val; }

// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// bool operator!= (T val) const noexcept { return x != val || y != val || z != val; }

// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// bool operator== (const Dim3T<T>& rhs) const noexcept { return x == rhs.x && y == rhs.y && z == rhs.z; }

// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// bool operator!= (const Dim3T<T>& rhs) const noexcept { return x != rhs.x || y != rhs.y || z != rhs.z; }

// //! Unary plus -- for completeness.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T> operator+ () const noexcept { return *this; }
// //! Unary Minus -- negates all components.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T> operator- () const noexcept { return {-x, -y, -z}; }
// //! Modifies Dim3 by addition of a scalar to each component.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T>& operator+= (T s) noexcept
// {
// x += s; y += s, z += s; return *this;
// }
// //! Modifies Dim3 by component-wise addition with argument.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T>& operator+= (const Dim3T<T>& rhs) noexcept
// {
// x += rhs.x; y += rhs.y; z += rhs.z; return *this;
// }
// //! Modifies IntVect by multiplication of a scalar to each component.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T>& operator*= (T s) noexcept
// {
// x *= s; y *= s; z *= s; return *this;
// }
// //! Modifies IntVect by component-wise multiplication with argument.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T>& operator*= (const Dim3T<T>& rhs) noexcept
// {
// x *= rhs.x, y *= rhs.y, z *= rhs.z; return *this;
// }
// //! Modifies IntVect by division by a scalar to each component.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T>& operator/= (T s) noexcept
// {
// x /= s, y /= s, z /= s; return *this;
// }
// //! Modifies IntVect by component-wise division with argument.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T>& operator/= (const Dim3T<T>& rhs) noexcept
// {
// x /= rhs.x, y /= rhs.y, z /= rhs.z; return *this;
// }
// //! Modifies IntVect by subtraction of a scalar to each component.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T>& operator-= (T s) noexcept
// {
// x -= s, y -= s, z -= s; return *this;
// }
// //! Modifies IntVect by component-wise subtraction with argument.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T>& operator-= (const Dim3T<T>& rhs) noexcept
// {
// x -= rhs.x, y -= rhs.y, z -= rhs.z; return *this;
// }
// //! Returns component-wise sum of IntVect and argument.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T> operator+ (const Dim3T<T>& rhs) const noexcept
// {
// return Dim3T<T>(x + rhs.x, y + rhs.y, z + rhs.z);
// }
// //! Return an IntVect that is this IntVect + s.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T> operator+ (T s) const noexcept
// {
// return Dim3T<T>(x + s, y + s, z + s);
// }
// //! Returns component-wise difference of IntVect and argument.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T> operator- (const Dim3T<T>& rhs) const noexcept
// {
// return Dim3T<T>(x - rhs.x, y - rhs.y, z - rhs.z);
// }
// //! Return an IntVect that is this IntVect - s.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T> operator- (T s) const noexcept
// {
// return Dim3T<T>(x - s, y - s, z - s);
// }
// //! Returns component-wise product of IntVect and argument.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T> operator* (const Dim3T<T>& rhs) const noexcept
// {
// return Dim3T<T>(x * rhs.x, y * rhs.y, z * rhs.z);
// }
// //! Returns component-wise product of IntVect and s.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T> operator* (T s) const noexcept
// {
// return Dim3T<T>(x * s, y * s, z * s);
// }
// //! Returns component-wise division of IntVect by argument.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T> operator/ (const Dim3T<T>& rhs) const noexcept
// {
// return Dim3T<T>(x / rhs.x, y / rhs.y, z / rhs.z);
// }
// //! Returns component-wise division of IntVect by s.
// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T> operator/ (T s) const noexcept
// {
// return Dim3T<T>(x / s, y / s, z / s);
// }

// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// T dot(const Dim3T<T>& rhs) const noexcept
// {
// return x*rhs.x + y*rhs.y + z*rhs.z;
// }

// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3T<T> cross(const Dim3T<T>& rhs) const noexcept
// {
// return Dim3T<T>(y*rhs.z - z*rhs.y, z*rhs.x - x*rhs.z, x*rhs.y - y*rhs.x);
// }

// T x; T y; T z;

// };

// struct Dim3
// : public Dim3T<int>
// {
// // AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// // Dim3 () { define(0,0,0); }

// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3 (int a_x, int a_y, int a_z) { define(a_x,a_y,a_z); };

// AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
// Dim3 (const IntVect& iv)
// {
// AMREX_D_PICK(define(iv[0],0 ,0 );,
// define(iv[0],iv[1],0 );,
// define(iv[0],iv[1],iv[2]););
// }

// IntVect toIntVect () { return IntVect(*this); }

// bool operator== (const IntVect& iv) { return iv == *this; }

// bool operator!= (const IntVect& iv) { return iv != *this; }
// };

// struct XDim3
// : public Dim3T<Real>
// {

// };
// template <class T>
// std::ostream& operator<< (std::ostream& os, const Dim3T<T>& d)
// {
// os << '(' << d.x << ',' << d.y << ',' << d.z << ')';
// return os;
// }

}

#endif
42 changes: 42 additions & 0 deletions Src/Base/AMReX_Dim3Util.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef AMREX_DIM3_UTIL_H_
#define AMREX_DIM3_UTIL_H_
#include <AMReX_Config.H>

#include <AMReX_Dim3.H>
#include <AMReX_IndexType.H>
#include <AMReX_IntVect.H>

namespace amrex {

template<class D>
D Dim3_plus (const D& a, const D& b) { return {a.x + b.x, a.y + b.y, a.z + b.z}; }

template<class D>
D Dim3_minus (const D& a, const D& b) { return {a.x - b.x, a.y - b.y, a.z - b.z}; }


// template<class D>
// D Dim3_times (const XDim3& a, const XDim3& b) { return {a.x * b.x, a.y * b.y, a.z * b.z}; }
// template<class D>
// D Dim3_divide (const XDim3& num, const XDim3& den) { return {num.x / den.x, num.y / den.y, num.z / den.z}; }


XDim3 Dim3_times (Real s, const XDim3& v) { return {s * v.x, s * v.y, s * v.z}; }

template<class D>
D Dim3_negate (const D& v) { return { -v.x, -v.y, -v.z}; }

int Dim3_dot (const Dim3& a, const Dim3& b) { return a.x*b.x + a.y*b.y + a.z*b.z; }
Real Dim3_dot (const XDim3& a, const XDim3& b) { return a.x*b.x + a.y*b.y + a.z*b.z; }

Dim3 Dim3_cross (const Dim3& a, const Dim3& b) { return {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; }
XDim3 Dim3_cross (const XDim3& a, const XDim3& b) { return {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; }

Real Dim3_norm (const XDim3& a) { return Real(std::sqrt(Real(Dim3_dot(a,a)))); }

template<class D>
void Dim3_plus_equals (D& lhs, const D& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; lhs.z += rhs.z; }

}

#endif /* AMREX_DIM3_UTIL_H_ */
14 changes: 13 additions & 1 deletion Src/Base/AMReX_IntVect.H
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public:
static constexpr unsigned shift1 = sizeof(size_t)>=8 ? 20 : 10;
static constexpr unsigned shift2 = sizeof(size_t)>=8 ? 40 : 20;
public:
std::size_t operator()(const IntVect& vec) const noexcept
std::size_t operator() (const IntVect& vec) const noexcept
{
AMREX_D_DECL(std::size_t ret0 = vec[0], ret1 = vec[1], ret2 = vec[2]);
#if AMREX_SPACEDIM == 1
Expand Down Expand Up @@ -247,6 +247,18 @@ public:
return AMREX_D_TERM(vect[0] != val, || vect[1] != val, || vect[2] != val);
}

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
bool operator== (const Dim3& rhs) const noexcept
{
return AMREX_D_TERM(vect[0] == rhs.x, && vect[1] == rhs.y, && vect[2] == rhs.z);
}

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
bool operator!= (const Dim3& rhs) const noexcept
{
return AMREX_D_TERM(vect[0] != rhs.x, || vect[1] != rhs.y, && vect[2] != rhs.z);
}

//! Returns true if this is equivalent to rhs.
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
bool operator== (const IntVect& rhs) const noexcept
Expand Down
4 changes: 2 additions & 2 deletions Src/Base/AMReX_RealVect.H
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,15 @@ public:
Returns the result of the scalar product with another RealVect
*/
[[nodiscard]] AMREX_GPU_HOST_DEVICE inline
Real dotProduct(const RealVect& a_rhs) const noexcept;
Real dotProduct (const RealVect& a_rhs) const noexcept;

#if (AMREX_SPACEDIM == 3)
///
/**
Returns the result of the cross product with another RealVect
*/
[[nodiscard]] AMREX_GPU_HOST_DEVICE inline
RealVect crossProduct(const RealVect& a_rhs) const noexcept;
RealVect crossProduct (const RealVect& a_rhs) const noexcept;
#endif

///
Expand Down

0 comments on commit ad9c39f

Please sign in to comment.