forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move helper traits classes out of Quantity.hh
- Loading branch information
Showing
5 changed files
with
143 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file corecel/math/UnitUtils.hh | ||
//! \brief Helpers for unit trait classes | ||
//---------------------------------------------------------------------------// | ||
#pragma once | ||
|
||
#include "corecel/Macros.hh" | ||
|
||
namespace celeritas | ||
{ | ||
//---------------------------------------------------------------------------// | ||
//! Value is 1 / C1::value() | ||
template<class C1> | ||
struct UnitInverse | ||
{ | ||
//! Get the conversion factor of the resulting unit | ||
static CELER_CONSTEXPR_FUNCTION auto value() noexcept -> decltype(auto) | ||
{ | ||
return 1 / C1::value(); | ||
} | ||
}; | ||
|
||
//---------------------------------------------------------------------------// | ||
//! Value is C1::value() / C2::value() | ||
template<class C1, class C2> | ||
struct UnitDivide | ||
{ | ||
//! Get the conversion factor of the resulting unit | ||
static CELER_CONSTEXPR_FUNCTION auto value() noexcept -> decltype(auto) | ||
{ | ||
return C1::value() / C2::value(); | ||
} | ||
}; | ||
|
||
//! Value is C1::value() * C2::value() | ||
template<class C1, class C2> | ||
struct UnitProduct | ||
{ | ||
//! Get the conversion factor of the resulting unit | ||
static CELER_CONSTEXPR_FUNCTION auto value() noexcept -> decltype(auto) | ||
{ | ||
return C1::value() * C2::value(); | ||
} | ||
}; | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace celeritas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file corecel/math/detail/QuantityImpl.hh | ||
//---------------------------------------------------------------------------// | ||
#pragma once | ||
|
||
#include "corecel/Macros.hh" | ||
|
||
#include "NumericLimits.hh" | ||
|
||
namespace celeritas | ||
{ | ||
namespace detail | ||
{ | ||
//---------------------------------------------------------------------------// | ||
//! Helper tag for special unitless values | ||
enum class QConstant | ||
{ | ||
neg_max = -1, | ||
zero = 0, | ||
max = 1 | ||
}; | ||
|
||
//! Convert unitless values into a particular type | ||
template<class T> | ||
CELER_CONSTEXPR_FUNCTION T get_constant(QConstant qc) | ||
{ | ||
if constexpr (std::is_floating_point_v<T>) | ||
{ | ||
// Return +/- infinity | ||
return qc == QConstant::neg_max ? -numeric_limits<T>::infinity() | ||
: qc == QConstant::max ? numeric_limits<T>::infinity() | ||
: 0; | ||
} | ||
else | ||
{ | ||
// Return lowest and highest values | ||
return qc == QConstant::neg_max ? numeric_limits<T>::lowest() | ||
: qc == QConstant::max ? numeric_limits<T>::max() | ||
: 0; | ||
} | ||
} | ||
|
||
//! Tag class for creating a nonnumeric value comparable to Quantity. | ||
template<QConstant QC> | ||
struct UnitlessQuantity | ||
{ | ||
}; | ||
|
||
//! Helper class for getting attributes about a member function | ||
template<class T> | ||
struct AccessorTraits; | ||
|
||
//! \cond | ||
//! Access the return type using AccessorTraits<decltype(&Foo::bar)> | ||
template<class ResultType, class ClassType> | ||
struct AccessorTraits<ResultType (ClassType::*)() const> | ||
{ | ||
using type = ClassType; | ||
using result_type = ResultType; | ||
}; | ||
//! \endcond | ||
|
||
//! Get the result type of a class accessor | ||
template<class T> | ||
using AccessorResultType = typename AccessorTraits<T>::result_type; | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace detail | ||
} // namespace celeritas |