diff --git a/.gitlab/jobs/tioga.yml b/.gitlab/jobs/tioga.yml index b949e98a7..6ab6fae37 100644 --- a/.gitlab/jobs/tioga.yml +++ b/.gitlab/jobs/tioga.yml @@ -40,7 +40,7 @@ release_resources: #### # Build and test jobs for specific compilers, extends generic tioga build and # test job -cce_16_0_0_rocm_5_6_0: +amdclang_rocm_6.0.2: variables: - COMPILER: "cce-16.0.0-rocm-5.6.0" + COMPILER: "amdclang-rocm-6.0.2-gfx90a" extends: .job_on_tioga diff --git a/source/SAMRAI/hier/BlockId.cpp b/source/SAMRAI/hier/BlockId.cpp index 7230c4237..7c80920a9 100644 --- a/source/SAMRAI/hier/BlockId.cpp +++ b/source/SAMRAI/hier/BlockId.cpp @@ -16,61 +16,9 @@ namespace SAMRAI { namespace hier { -const BlockId -BlockId::s_invalid_id( - tbox::MathUtilities::getMax()); -const BlockId BlockId::s_zero_id(0); +const BlockId BlockId::s_invalid_id(s_invalid_val); +const BlockId BlockId::s_zero_id(s_zero_val); -/* - ******************************************************************************* - ******************************************************************************* - */ -BlockId::BlockId(): - d_value(invalidId().d_value) -{ -} - -/* - ******************************************************************************* - ******************************************************************************* - */ -BlockId::BlockId( - const BlockId& other): - d_value(other.d_value) -{ -} - -/* - ******************************************************************************* - ******************************************************************************* - */ -BlockId::BlockId( - const unsigned int& value): - d_value(value) -{ -} - -/* - ******************************************************************************* - ******************************************************************************* - */ -BlockId::BlockId( - const int& value): - d_value(static_cast(value)) -{ - TBOX_ASSERT(value >=0); -} - -/* - ******************************************************************************* - ******************************************************************************* - */ -BlockId::~BlockId() -{ -#ifdef DEBUG_CHECK_ASSERTIONS - d_value = s_invalid_id.d_value; -#endif -} } } diff --git a/source/SAMRAI/hier/BlockId.h b/source/SAMRAI/hier/BlockId.h index 0ccdc4fe1..faa9b3b2f 100644 --- a/source/SAMRAI/hier/BlockId.h +++ b/source/SAMRAI/hier/BlockId.h @@ -12,6 +12,7 @@ #define included_hier_BlockId #include "SAMRAI/SAMRAI_config.h" +#include "SAMRAI/tbox/MathUtilities.h" #include "SAMRAI/tbox/Utilities.h" #include @@ -36,21 +37,27 @@ class BlockId /*! * @brief Default constructor sets the value to invalid. */ - BlockId(); + constexpr BlockId() : + d_value(s_invalid_val) + { + } /*! * @brief Copy constructor. */ - BlockId( - const BlockId& other); + constexpr BlockId( + const BlockId& other) = default; /*! * @brief Construct from an unsigned int. * * This method is explicit to prevent automatic conversion. */ - explicit BlockId( - const unsigned int& value); + constexpr explicit BlockId( + const unsigned int& value) : + d_value(value) + { + } /*! * @brief Construct from a signed int. @@ -59,13 +66,17 @@ class BlockId * * @pre value >= 0 */ - explicit BlockId( - const int& value); + constexpr explicit BlockId( + const int& value) : + d_value(static_cast(value)) + { + TBOX_CONSTEXPR_ASSERT(value >=0); + } /*! * @brief Default constructor. */ - ~BlockId(); + ~BlockId() = default; /*! * @brief Assignment operator. @@ -74,28 +85,24 @@ class BlockId * * @return @c *this */ - BlockId& + constexpr BlockId& operator = ( - const BlockId& rhs) - { - d_value = rhs.d_value; - return *this; - } + const BlockId& rhs) = default; /*! * @brief Set to an int value. * * @param[in] rhs */ - void + constexpr void setId( const int& rhs) { - TBOX_ASSERT(rhs >= 0); + TBOX_CONSTEXPR_ASSERT(rhs >= 0); d_value = static_cast(rhs); } - void + constexpr void setId( const unsigned int& rhs) { @@ -105,16 +112,16 @@ class BlockId /*! * @brief Whether the value is valid. */ - bool + constexpr bool isValid() const { - return d_value != s_invalid_id.d_value; + return d_value != s_invalid_val; } /*! * @brief Access the numerical value. */ - const block_t& + constexpr const block_t& getBlockValue() const { return d_value; @@ -149,7 +156,7 @@ class BlockId * * @param[in] rhs */ - bool + constexpr bool operator == ( const BlockId& rhs) const { @@ -163,7 +170,7 @@ class BlockId * * @param[in] rhs */ - bool + constexpr bool operator != ( const BlockId& rhs) const { @@ -177,7 +184,7 @@ class BlockId * * @param[in] rhs */ - bool + constexpr bool operator < ( const BlockId& rhs) const { @@ -191,7 +198,7 @@ class BlockId * * @param[in] rhs */ - bool + constexpr bool operator > ( const BlockId& rhs) const { @@ -205,7 +212,7 @@ class BlockId * * @param[in] rhs */ - bool + constexpr bool operator <= ( const BlockId& rhs) const { @@ -219,7 +226,7 @@ class BlockId * * @param[in] rhs */ - bool + constexpr bool operator >= ( const BlockId& rhs) const { @@ -239,7 +246,7 @@ class BlockId * * @param[in] rhs */ - bool + constexpr bool operator == ( const block_t& rhs) const { @@ -253,7 +260,7 @@ class BlockId * * @param[in] rhs */ - bool + constexpr bool operator != ( const block_t& rhs) const { @@ -267,7 +274,7 @@ class BlockId * * @param[in] rhs */ - bool + constexpr bool operator < ( const block_t& rhs) const { @@ -281,7 +288,7 @@ class BlockId * * @param[in] rhs */ - bool + constexpr bool operator > ( const block_t& rhs) const { @@ -295,7 +302,7 @@ class BlockId * * @param[in] rhs */ - bool + constexpr bool operator <= ( const block_t& rhs) const { @@ -309,7 +316,7 @@ class BlockId * * @param[in] rhs */ - bool + constexpr bool operator >= ( const block_t& rhs) const { @@ -336,6 +343,10 @@ class BlockId */ unsigned int d_value; + static constexpr unsigned int s_zero_val = 0; + static constexpr unsigned int s_invalid_val = + tbox::MathUtilities::getMax(); + /*! * @brief BlockId with a numerical value of zero. */ diff --git a/source/SAMRAI/hier/BoxId.cpp b/source/SAMRAI/hier/BoxId.cpp index 9b9f2af25..22a3a674e 100644 --- a/source/SAMRAI/hier/BoxId.cpp +++ b/source/SAMRAI/hier/BoxId.cpp @@ -14,53 +14,6 @@ namespace SAMRAI { namespace hier { -/* - ************************************************************************ - * Constructors - ************************************************************************ - */ -BoxId::BoxId(): - d_global_id(), - d_periodic_id() -{ -} - -BoxId::BoxId( - const GlobalId& id, - const PeriodicId& periodic_id): - d_global_id(id), - d_periodic_id(periodic_id) -{ - TBOX_ASSERT(periodic_id.isValid()); -} - -BoxId::BoxId( - const LocalId& local_id, - const int owner, - const PeriodicId& periodic_id): - d_global_id(local_id, owner), - d_periodic_id(periodic_id) -{ - TBOX_ASSERT(periodic_id.isValid()); -} - -BoxId::BoxId( - const BoxId& r): - d_global_id(r.d_global_id), - d_periodic_id(r.d_periodic_id) -{ - TBOX_ASSERT(r.d_periodic_id.isValid()); -} - -/* - ************************************************************************ - * Destructor - ************************************************************************ - */ -BoxId::~BoxId() -{ -} - /* ****************************************************************************** * Stream-insert operator. diff --git a/source/SAMRAI/hier/BoxId.h b/source/SAMRAI/hier/BoxId.h index fbdbdcf16..0a2cf5d08 100644 --- a/source/SAMRAI/hier/BoxId.h +++ b/source/SAMRAI/hier/BoxId.h @@ -44,7 +44,7 @@ class BoxId * * The object can be changed using initialize() or by assignment. */ - BoxId(); + BoxId() = default; /*! * @brief Initializing constructor. @@ -57,10 +57,15 @@ class BoxId * * @pre periodic_id.isValid() */ - BoxId( + constexpr BoxId( const LocalId& local_id, const int owner_rank, - const PeriodicId& periodic_id = PeriodicId::zero()); + const PeriodicId& periodic_id = PeriodicId::zero()) : + d_global_id(local_id, owner_rank), + d_periodic_id(periodic_id) + { + TBOX_CONSTEXPR_ASSERT(periodic_id.isValid()); + } /*! * @brief Initializing constructor. @@ -71,9 +76,14 @@ class BoxId * * @pre periodic_id.isValid() */ - explicit BoxId( + constexpr explicit BoxId( const GlobalId& id, - const PeriodicId& periodic_id = PeriodicId::zero()); + const PeriodicId& periodic_id = PeriodicId::zero()) : + d_global_id(id), + d_periodic_id(periodic_id) + { + TBOX_CONSTEXPR_ASSERT(periodic_id.isValid()); + } /*! * @brief Copy constructor. @@ -82,13 +92,20 @@ class BoxId * * @pre other.periodic_id.isValid() */ - BoxId( - const BoxId& other); + constexpr BoxId( + const BoxId& other) = default; + + /*! + * @brief Assignment operator + */ + constexpr BoxId& + operator = ( + const BoxId& r) = default; /*! * @brief Destructor. */ - ~BoxId(); + ~BoxId() = default; /*! * @brief Set all the attributes to given values. @@ -105,7 +122,7 @@ class BoxId const int owner_rank, const PeriodicId& periodic_id = PeriodicId::zero()) { - TBOX_ASSERT(periodic_id.isValid()); + TBOX_CONSTEXPR_ASSERT(periodic_id.isValid()); d_global_id.getLocalId() = local_id; d_global_id.getOwnerRank() = owner_rank; d_periodic_id = periodic_id; @@ -114,7 +131,7 @@ class BoxId /*! * @brief Access the GlobalId. */ - const GlobalId& + constexpr const GlobalId& getGlobalId() const { return d_global_id; @@ -123,7 +140,7 @@ class BoxId /*! * @brief Access the owner rank. */ - int + constexpr int getOwnerRank() const { return d_global_id.getOwnerRank(); @@ -132,7 +149,7 @@ class BoxId /*! * @brief Access the LocalId. */ - const LocalId& + constexpr const LocalId& getLocalId() const { return d_global_id.getLocalId(); @@ -141,7 +158,7 @@ class BoxId /*! * @brief Access the PeriodicId. */ - const PeriodicId& + constexpr const PeriodicId& getPeriodicId() const { return d_periodic_id; @@ -161,7 +178,7 @@ class BoxId * @brief Whether the BoxId is valid--meaning it has a valid * GlobalId and PeriodicId. */ - bool + constexpr bool isValid() const { return d_periodic_id.isValid() && @@ -180,18 +197,13 @@ class BoxId * All comparison operators use the GlobalId and PeriodicId. */ - BoxId& - operator = ( - const BoxId& r) = default; - - - bool + constexpr bool operator == ( const BoxId& r) const { bool rval = d_global_id == r.d_global_id && d_periodic_id == r.d_periodic_id; - TBOX_ASSERT(d_periodic_id.isValid() && r.d_periodic_id.isValid()); + TBOX_CONSTEXPR_ASSERT(d_periodic_id.isValid() && r.d_periodic_id.isValid()); return rval; } @@ -200,11 +212,11 @@ class BoxId * * See note on comparison for operator==(const BoxId&); */ - bool + constexpr bool operator != ( const BoxId& r) const { - TBOX_ASSERT(d_periodic_id.isValid() && r.d_periodic_id.isValid()); + TBOX_CONSTEXPR_ASSERT(d_periodic_id.isValid() && r.d_periodic_id.isValid()); bool rval = d_global_id != r.d_global_id || d_periodic_id != r.d_periodic_id; return rval; @@ -216,11 +228,11 @@ class BoxId * Compare the owner ranks first; if they compare equal, compare the * LocalIds next; if they compare equal, compare the PeriodicIds. */ - bool + constexpr bool operator < ( const BoxId& r) const { - TBOX_ASSERT(d_periodic_id.isValid() && r.d_periodic_id.isValid()); + TBOX_CONSTEXPR_ASSERT(d_periodic_id.isValid() && r.d_periodic_id.isValid()); return d_global_id.getOwnerRank() < r.d_global_id.getOwnerRank() || (d_global_id.getOwnerRank() == r.d_global_id.getOwnerRank() && (d_global_id.getLocalId() < r.d_global_id.getLocalId() || @@ -234,11 +246,11 @@ class BoxId * Compare the owner ranks first; if they compare equal, compare the * LocalIds next; if they compare equal, compare the PeriodicIds. */ - bool + constexpr bool operator > ( const BoxId& r) const { - TBOX_ASSERT(d_periodic_id.isValid() && r.d_periodic_id.isValid()); + TBOX_CONSTEXPR_ASSERT(d_periodic_id.isValid() && r.d_periodic_id.isValid()); return d_global_id.getOwnerRank() > r.d_global_id.getOwnerRank() || (d_global_id.getOwnerRank() == r.d_global_id.getOwnerRank() && (d_global_id.getLocalId() > r.d_global_id.getLocalId() || @@ -249,22 +261,22 @@ class BoxId /*! * @brief Less-than-or-equal-to operator. */ - bool + constexpr bool operator <= ( const BoxId& r) const { - TBOX_ASSERT(d_periodic_id.isValid() && r.d_periodic_id.isValid()); + TBOX_CONSTEXPR_ASSERT(d_periodic_id.isValid() && r.d_periodic_id.isValid()); return *this < r || *this == r; } /*! * @brief Greater-than-or-equal-to operator. */ - bool + constexpr bool operator >= ( const BoxId& r) const { - TBOX_ASSERT(d_periodic_id.isValid() && r.d_periodic_id.isValid()); + TBOX_CONSTEXPR_ASSERT(d_periodic_id.isValid() && r.d_periodic_id.isValid()); return *this > r || *this == r; } @@ -280,7 +292,7 @@ class BoxId * * @see putToIntBuffer(), getFromIntBuffer(). */ - static int + constexpr static int commBufferSize() { return 3; diff --git a/source/SAMRAI/hier/GlobalId.cpp b/source/SAMRAI/hier/GlobalId.cpp index 985afdd82..882d4b48f 100644 --- a/source/SAMRAI/hier/GlobalId.cpp +++ b/source/SAMRAI/hier/GlobalId.cpp @@ -14,47 +14,6 @@ namespace SAMRAI { namespace hier { -/* - ************************************************************************ - ************************************************************************ - */ -GlobalId::GlobalId(): - d_owner_rank(tbox::SAMRAI_MPI::getInvalidRank()), - d_local_id(LocalId::getInvalidId()) -{ -} - -/* - ************************************************************************ - ************************************************************************ - */ -GlobalId::GlobalId( - const LocalId& local_id, - const int owner): - d_owner_rank(owner), - d_local_id(local_id) -{ -} - -/* - ************************************************************************ - ************************************************************************ - */ -GlobalId::GlobalId( - const GlobalId& other): - d_owner_rank(other.d_owner_rank), - d_local_id(other.d_local_id) -{ -} - -/* - ************************************************************************ - ************************************************************************ - */ -GlobalId::~GlobalId() -{ -} - std::ostream& operator << ( std::ostream& co, diff --git a/source/SAMRAI/hier/GlobalId.h b/source/SAMRAI/hier/GlobalId.h index b85f81495..93d49fe3d 100644 --- a/source/SAMRAI/hier/GlobalId.h +++ b/source/SAMRAI/hier/GlobalId.h @@ -49,27 +49,35 @@ class GlobalId * The object can be initialized using the assignment operator or * the non-const versions of the getOwnerRank() and getLocalId() methods. */ - GlobalId(); + GlobalId() : + d_owner_rank(tbox::SAMRAI_MPI::getInvalidRank()), + d_local_id(LocalId::getInvalidId()) + { + } /*! * @brief Initializing constructor. */ - GlobalId( + constexpr GlobalId( const LocalId& local_id, - const int owner_rank); + const int owner_rank) : + d_owner_rank(owner_rank), + d_local_id(local_id) + { + } /*! * @brief Copy constructor. * * @param[in] other */ - GlobalId( - const GlobalId& other); + constexpr GlobalId( + const GlobalId& other) = default; /*! * @brief Destructor. */ - ~GlobalId(); + ~GlobalId() = default; /*! * @brief Access the owner rank. @@ -83,7 +91,7 @@ class GlobalId /*! * @brief Access the owner rank. */ - const int& + constexpr const int& getOwnerRank() const { return d_owner_rank; @@ -101,7 +109,7 @@ class GlobalId /*! * @brief Access the LocalId. */ - const LocalId& + constexpr const LocalId& getLocalId() const { return d_local_id; @@ -118,11 +126,11 @@ class GlobalId * owner values first; if they compare equal, compare the LocalId * next. */ - GlobalId& + constexpr GlobalId& operator = ( const GlobalId& r) = default; - bool + constexpr bool operator == ( const GlobalId& r) const { @@ -136,7 +144,7 @@ class GlobalId * * See note on comparison for operator==(const GlobalId&); */ - bool + constexpr bool operator != ( const GlobalId& r) const { @@ -150,7 +158,7 @@ class GlobalId * * See note on comparison for operator==(const GlobalId&); */ - bool + constexpr bool operator < ( const GlobalId& r) const { @@ -163,7 +171,7 @@ class GlobalId * * See note on comparison for operator==(const GlobalId&); */ - bool + constexpr bool operator > ( const GlobalId& r) const { @@ -176,7 +184,7 @@ class GlobalId * * See note on comparison for operator==(const GlobalId&); */ - bool + constexpr bool operator <= ( const GlobalId& r) const { @@ -190,7 +198,7 @@ class GlobalId * * See note on comparison for operator==(const GlobalId&); */ - bool + constexpr bool operator >= ( const GlobalId& r) const { diff --git a/source/SAMRAI/hier/LocalId.cpp b/source/SAMRAI/hier/LocalId.cpp index c4a3f3010..2e4be691a 100644 --- a/source/SAMRAI/hier/LocalId.cpp +++ b/source/SAMRAI/hier/LocalId.cpp @@ -15,47 +15,8 @@ namespace SAMRAI { namespace hier { -const LocalId -LocalId::s_invalid_id( - tbox::MathUtilities::getMax()); -const LocalId LocalId::s_zero_id(0); - -/* - ******************************************************************************* - ******************************************************************************* - */ -LocalId::LocalId(): - d_value(getInvalidId().d_value) { -} - -/* - ******************************************************************************* - ******************************************************************************* - */ -LocalId::LocalId( - const LocalId& other): - d_value(other.d_value) { -} - -/* - ******************************************************************************* - ******************************************************************************* - */ -LocalId::LocalId( - const int& value): - d_value(value) { -} - -/* - ******************************************************************************* - ******************************************************************************* - */ -LocalId::~LocalId() -{ -#ifdef DEBUG_CHECK_ASSERTIONS - d_value = s_invalid_id.d_value; -#endif -} +const LocalId LocalId::s_invalid_id(s_invalid_val); +const LocalId LocalId::s_zero_id(s_zero_val); /* ******************************************************************************* diff --git a/source/SAMRAI/hier/LocalId.h b/source/SAMRAI/hier/LocalId.h index e1225e97d..48846d979 100644 --- a/source/SAMRAI/hier/LocalId.h +++ b/source/SAMRAI/hier/LocalId.h @@ -12,6 +12,7 @@ #define included_hier_LocalId #include "SAMRAI/SAMRAI_config.h" +#include "SAMRAI/tbox/MathUtilities.h" #include @@ -35,26 +36,29 @@ class LocalId /*! * @brief Default constructor. */ - LocalId(); + constexpr LocalId() : d_value(s_invalid_val) + { + } /*! * @brief Copy constructor. */ - LocalId( - const LocalId& other); + constexpr LocalId(const LocalId& other) = default; /*! * @brief Construct from a numerical value. * * This method is explicit to prevent automatic conversion. */ - explicit LocalId( - const int& value); + constexpr explicit LocalId( + const int& value) : d_value(value) + { + } /*! - * @brief Default constructor. + * @brief Default destructor. */ - ~LocalId(); + ~LocalId() = default; /*! * @brief Assignment operator. @@ -63,7 +67,7 @@ class LocalId * * @return @c *this */ - LocalId& + constexpr LocalId& operator = ( const LocalId& rhs) { @@ -78,7 +82,7 @@ class LocalId * * @return @c *this */ - LocalId& + constexpr LocalId& operator = ( const int& rhs) { @@ -98,7 +102,7 @@ class LocalId /*! * @brief Access the numerical value. */ - const int& + constexpr const int& getValue() const { return d_value; @@ -107,10 +111,10 @@ class LocalId /*! * @brief Whether value is a valid one (not equal to getInvalidId()). */ - bool + constexpr bool isValid() const { - return d_value != s_invalid_id.getValue(); + return d_value != s_invalid_val; } /*! @@ -141,7 +145,7 @@ class LocalId * Pre-increment increments the value and returns the incremented * state. */ - LocalId + constexpr LocalId operator ++ () { ++d_value; @@ -154,7 +158,7 @@ class LocalId * Post-increment saves the value, increment it and returns an * object with the saved value. */ - LocalId + constexpr LocalId operator ++ ( int) { @@ -168,7 +172,7 @@ class LocalId * * @param[in] rhs */ - LocalId + constexpr LocalId operator + ( const LocalId& rhs) const { @@ -180,7 +184,7 @@ class LocalId * * @param[in] rhs */ - LocalId + constexpr LocalId operator - ( const LocalId& rhs) const { @@ -192,7 +196,7 @@ class LocalId * * @param[in] rhs */ - LocalId + constexpr LocalId operator * ( const LocalId& rhs) const { @@ -204,7 +208,7 @@ class LocalId * * @param[in] rhs */ - LocalId + constexpr LocalId operator / ( const LocalId& rhs) const { @@ -216,7 +220,7 @@ class LocalId * * @param[in] rhs */ - LocalId + constexpr LocalId operator % ( const LocalId& rhs) const { @@ -228,7 +232,7 @@ class LocalId * * @param[in] rhs */ - LocalId& + constexpr LocalId& operator += ( const LocalId& rhs) { @@ -241,7 +245,7 @@ class LocalId * * @param[in] rhs */ - LocalId& + constexpr LocalId& operator -= ( const LocalId& rhs) { @@ -254,7 +258,7 @@ class LocalId * * @param[in] rhs */ - LocalId + constexpr LocalId operator + ( const int& rhs) const { @@ -266,7 +270,7 @@ class LocalId * * @param[in] rhs */ - LocalId + constexpr LocalId operator - ( const int& rhs) const { @@ -278,7 +282,7 @@ class LocalId * * @param[in] rhs */ - LocalId + constexpr LocalId operator * ( const int& rhs) const { @@ -290,7 +294,7 @@ class LocalId * * @param[in] rhs */ - LocalId + constexpr LocalId operator / ( const int& rhs) const { @@ -302,7 +306,7 @@ class LocalId * * @param[in] rhs */ - LocalId + constexpr LocalId operator % ( const int& rhs) const { @@ -314,7 +318,7 @@ class LocalId * * @param[in] rhs */ - LocalId& + constexpr LocalId& operator += ( const int& rhs) { @@ -327,7 +331,7 @@ class LocalId * * @param[in] rhs */ - LocalId& + constexpr LocalId& operator -= ( const int& rhs) { @@ -348,7 +352,7 @@ class LocalId * * @param[in] rhs */ - bool + constexpr bool operator == ( const LocalId& rhs) const { @@ -362,7 +366,7 @@ class LocalId * * @param[in] rhs */ - bool + constexpr bool operator != ( const LocalId& rhs) const { @@ -376,7 +380,7 @@ class LocalId * * @param[in] rhs */ - bool + constexpr bool operator < ( const LocalId& rhs) const { @@ -390,7 +394,7 @@ class LocalId * * @param[in] rhs */ - bool + constexpr bool operator > ( const LocalId& rhs) const { @@ -404,7 +408,7 @@ class LocalId * * @param[in] rhs */ - bool + constexpr bool operator <= ( const LocalId& rhs) const { @@ -418,7 +422,7 @@ class LocalId * * @param[in] rhs */ - bool + constexpr bool operator >= ( const LocalId& rhs) const { @@ -438,7 +442,7 @@ class LocalId * * @param[in] rhs */ - bool + constexpr bool operator == ( const int& rhs) const { @@ -452,7 +456,7 @@ class LocalId * * @param[in] rhs */ - bool + constexpr bool operator != ( const int& rhs) const { @@ -466,7 +470,7 @@ class LocalId * * @param[in] rhs */ - bool + constexpr bool operator < ( const int& rhs) const { @@ -480,7 +484,7 @@ class LocalId * * @param[in] rhs */ - bool + constexpr bool operator > ( const int& rhs) const { @@ -494,7 +498,7 @@ class LocalId * * @param[in] rhs */ - bool + constexpr bool operator <= ( const int& rhs) const { @@ -508,7 +512,7 @@ class LocalId * * @param[in] rhs */ - bool + constexpr bool operator >= ( const int& rhs) const { @@ -531,6 +535,9 @@ class LocalId */ int d_value; + static constexpr int s_zero_val = 0; + static constexpr int s_invalid_val = tbox::MathUtilities::getMax(); + /*! * @brief LocalId with a numerical value of zero. */ diff --git a/source/SAMRAI/hier/PeriodicId.cpp b/source/SAMRAI/hier/PeriodicId.cpp index 00aab5617..ec07a6fae 100644 --- a/source/SAMRAI/hier/PeriodicId.cpp +++ b/source/SAMRAI/hier/PeriodicId.cpp @@ -14,45 +14,9 @@ namespace SAMRAI { namespace hier { -const PeriodicId PeriodicId::s_invalid_id(-1); -const PeriodicId PeriodicId::s_zero_id(0); +const PeriodicId PeriodicId::s_invalid_id(s_invalid_val); +const PeriodicId PeriodicId::s_zero_id(s_zero_val); -/* - ****************************************************************************** - ****************************************************************************** - */ -PeriodicId::PeriodicId(): - d_value(invalidId().d_value) { -} - -/* - ****************************************************************************** - ****************************************************************************** - */ -PeriodicId::PeriodicId( - const PeriodicId& other): - d_value(other.d_value) { -} - -/* - ****************************************************************************** - ****************************************************************************** - */ -PeriodicId::PeriodicId( - const int& value): - d_value(value) { -} - -/* - ****************************************************************************** - ****************************************************************************** - */ -PeriodicId::~PeriodicId() -{ -#ifdef DEBUG_CHECK_ASSERTIONS - d_value = s_invalid_id.d_value; -#endif -} /* ****************************************************************************** diff --git a/source/SAMRAI/hier/PeriodicId.h b/source/SAMRAI/hier/PeriodicId.h index a656d3924..2d08b5a9c 100644 --- a/source/SAMRAI/hier/PeriodicId.h +++ b/source/SAMRAI/hier/PeriodicId.h @@ -31,26 +31,32 @@ class PeriodicId /*! * @brief Default constructor. */ - PeriodicId(); + constexpr PeriodicId() : + d_value(s_invalid_val) + { + } /*! * @brief Copy constructor. */ - PeriodicId( - const PeriodicId& other); + constexpr PeriodicId( + const PeriodicId& other) = default; /*! * @brief Construct from a numerical value. * * This method is explicit to prevent automatic conversion. */ - explicit PeriodicId( - const int& value); + constexpr explicit PeriodicId( + const int& value) : + d_value(value) + { + } /*! * @brief Default constructor. */ - ~PeriodicId(); + ~PeriodicId() = default; /*! * @brief Assignment operator. @@ -59,13 +65,9 @@ class PeriodicId * * @return @c *this */ - PeriodicId& + constexpr PeriodicId& operator = ( - const PeriodicId& rhs) - { - d_value = rhs.d_value; - return *this; - } + const PeriodicId& rhs) = default; /*! * @brief Assignment operator. @@ -74,7 +76,7 @@ class PeriodicId * * @return @c *this */ - PeriodicId& + constexpr PeriodicId& operator = ( const int& rhs) { @@ -85,7 +87,7 @@ class PeriodicId /*! * @brief Access the numerical value. */ - const int& + constexpr const int& getPeriodicValue() const { return d_value; @@ -112,7 +114,7 @@ class PeriodicId /*! * @brief Returns True if the value is valid. */ - bool + constexpr bool isValid() const { return d_value >= 0; @@ -129,7 +131,7 @@ class PeriodicId * * @param[in] rhs */ - bool + constexpr bool operator == ( const PeriodicId& rhs) const { @@ -143,7 +145,7 @@ class PeriodicId * * @param[in] rhs */ - bool + constexpr bool operator != ( const PeriodicId& rhs) const { @@ -157,7 +159,7 @@ class PeriodicId * * @param[in] rhs */ - bool + constexpr bool operator < ( const PeriodicId& rhs) const { @@ -171,7 +173,7 @@ class PeriodicId * * @param[in] rhs */ - bool + constexpr bool operator > ( const PeriodicId& rhs) const { @@ -185,7 +187,7 @@ class PeriodicId * * @param[in] rhs */ - bool + constexpr bool operator <= ( const PeriodicId& rhs) const { @@ -199,7 +201,7 @@ class PeriodicId * * @param[in] rhs */ - bool + constexpr bool operator >= ( const PeriodicId& rhs) const { @@ -222,6 +224,10 @@ class PeriodicId */ int d_value; + static constexpr int s_zero_val = 0; + + static constexpr int s_invalid_val = -1; + /*! * @brief PeriodicId with a numerical value of zero. */ diff --git a/source/SAMRAI/tbox/Dimension.cpp b/source/SAMRAI/tbox/Dimension.cpp index 8e1b8fc5c..71e552ff7 100644 --- a/source/SAMRAI/tbox/Dimension.cpp +++ b/source/SAMRAI/tbox/Dimension.cpp @@ -12,17 +12,6 @@ namespace SAMRAI { namespace tbox { -Dimension::Dimension( - const unsigned short& dim):d_dim(dim) -{ - TBOX_DIM_ASSERT(dim > 0 && dim <= SAMRAI::MAX_DIM_VAL); -} - -Dimension::Dimension( - const Dimension& dimension):d_dim(dimension.d_dim) -{ -} - std::ostream& operator << ( std::ostream& s, diff --git a/source/SAMRAI/tbox/Dimension.h b/source/SAMRAI/tbox/Dimension.h index 8e39e8fc4..bf3a71611 100644 --- a/source/SAMRAI/tbox/Dimension.h +++ b/source/SAMRAI/tbox/Dimension.h @@ -55,19 +55,24 @@ class Dimension * * @pre (dim > 0) && (dim <= SAMRAI::MAX_DIM_VAL) */ - explicit Dimension( - const unsigned short& dim); + constexpr explicit Dimension( + const unsigned short& dim) : d_dim(dim) + { + TBOX_CONSTEXPR_DIM_ASSERT(dim > 0 && dim <= SAMRAI::MAX_DIM_VAL); + } /** * Construct a dimension equal to the argument. */ - Dimension( - const Dimension& dimension); + constexpr Dimension( + const Dimension& dimension) : d_dim(dimension.d_dim) + { + } /** * Equality operator. */ - bool + constexpr bool operator == ( const Dimension& rhs) const { @@ -77,7 +82,7 @@ class Dimension /** * Inequality operator. */ - bool + constexpr bool operator != ( const Dimension& rhs) const { @@ -87,7 +92,7 @@ class Dimension /** * Greater than operator. */ - bool + constexpr bool operator > ( const Dimension& rhs) const { @@ -97,7 +102,7 @@ class Dimension /** * Greater than or equal operator. */ - bool + constexpr bool operator >= ( const Dimension& rhs) const { @@ -107,7 +112,7 @@ class Dimension /** * Less than operator. */ - bool + constexpr bool operator < ( const Dimension& rhs) const { @@ -117,7 +122,7 @@ class Dimension /** * Less than or equal operator. */ - bool + constexpr bool operator <= ( const Dimension& rhs) const { @@ -132,7 +137,7 @@ class Dimension * used for comparisons, the Dimension comparison operations are * better suited for that purpose. */ - unsigned short + constexpr unsigned short getValue() const { return d_dim; diff --git a/source/SAMRAI/tbox/MathUtilities.cpp b/source/SAMRAI/tbox/MathUtilities.cpp index 599df8d15..789ea19a6 100644 --- a/source/SAMRAI/tbox/MathUtilities.cpp +++ b/source/SAMRAI/tbox/MathUtilities.cpp @@ -153,13 +153,6 @@ MathUtilities::getSignalingNaN() return std::numeric_limits::signaling_NaN(); } -template -TYPE -MathUtilities::getMax() -{ - return std::numeric_limits::max(); -} - template TYPE MathUtilities::getMin() diff --git a/source/SAMRAI/tbox/MathUtilities.h b/source/SAMRAI/tbox/MathUtilities.h index 05813f3e0..7052b4fee 100644 --- a/source/SAMRAI/tbox/MathUtilities.h +++ b/source/SAMRAI/tbox/MathUtilities.h @@ -15,6 +15,7 @@ #include "SAMRAI/tbox/Complex.h" +#include #include namespace SAMRAI { @@ -138,8 +139,11 @@ class MathUtilities * parts set to the POSIX max value for type double. For * other types, will return the POSIX max value for the type. */ - static TYPE - getMax(); + constexpr static TYPE + getMax() + { + return std::numeric_limits::max(); + } /*! * @brief Set vector entries to value given by getMax(). diff --git a/source/SAMRAI/tbox/SAMRAI_MPI.cpp b/source/SAMRAI/tbox/SAMRAI_MPI.cpp index 29c260d98..6e5d49bf4 100644 --- a/source/SAMRAI/tbox/SAMRAI_MPI.cpp +++ b/source/SAMRAI/tbox/SAMRAI_MPI.cpp @@ -55,7 +55,6 @@ SAMRAI_MPI SAMRAI_MPI::s_samrai_world(MPI_COMM_NULL); bool SAMRAI_MPI::s_call_abort_in_serial_instead_of_exit = false; bool SAMRAI_MPI::s_call_abort_in_parallel_instead_of_mpiabort = false; -int SAMRAI_MPI::s_invalid_rank = -1; /* ************************************************************************** diff --git a/source/SAMRAI/tbox/SAMRAI_MPI.h b/source/SAMRAI/tbox/SAMRAI_MPI.h index 360be614c..2cd8a7d6b 100644 --- a/source/SAMRAI/tbox/SAMRAI_MPI.h +++ b/source/SAMRAI/tbox/SAMRAI_MPI.h @@ -176,7 +176,7 @@ class SAMRAI_MPI * This value is intended to be used by other classes as an invalid rank * number rather than using a hard-coded "magic" negative integer value. */ - static int + constexpr static int getInvalidRank() { return s_invalid_rank; @@ -909,7 +909,7 @@ class SAMRAI_MPI /*! * @brief Invalid (negative) rank number for getInvalidRank(). */ - static int s_invalid_rank; + static constexpr int s_invalid_rank = -1; //@{ //@name Structs for passing arguments to MPI diff --git a/source/SAMRAI/tbox/Utilities.h b/source/SAMRAI/tbox/Utilities.h index 5287e5e4a..49aba1711 100644 --- a/source/SAMRAI/tbox/Utilities.h +++ b/source/SAMRAI/tbox/Utilities.h @@ -119,6 +119,26 @@ typedef int mode_t; #endif +#ifdef DEBUG_CHECK_ASSERTIONS + +#define TBOX_CONSTEXPR_ASSERT(EXP) \ + do { \ + if (!(EXP)) { \ + printf("Failed assertion: "); \ + printf( # EXP ); \ + printf("\n"); \ + SAMRAI::tbox::Utilities::abort("", __FILE__, __LINE__); \ + } \ + } while (0) +#else + +/* + * No assertion checking + */ +#define TBOX_CONSTEXPR_ASSERT(EXP) + +#endif + /*! * Throw an error assertion from within any C++ source code if the * given expression is not true. This is a parallel-friendly version @@ -347,6 +367,27 @@ typedef int mode_t; #endif +#ifdef DEBUG_CHECK_DIM_ASSERTIONS + +#define TBOX_CONSTEXPR_DIM_ASSERT(EXP) \ + do { \ + if (!(EXP)) { \ + printf("Failed dimension assertion: "); \ + printf( # EXP ); \ + printf("\n"); \ + SAMRAI::tbox::Utilities::abort("", __FILE__, __LINE__); \ + } \ + } while (0) + +#else + +/* + * No dimensional assertion checking + */ +#define TBOX_CONSTEXPR_DIM_ASSERT(EXP) + +#endif + /** * Throw an error assertion from within any C++ source code. This is * is similar to TBOX_ERROR(), but is designed to be invoked after a