Skip to content

Commit

Permalink
Merge pull request #490 from thelfer/486-tfel-math-introduce-the-st2t…
Browse files Browse the repository at this point in the history
…ot2concept-and-the-t2tost2concept

Introduce the T2toST2Concept and ST2toT2Concept concepts. Remove usag…
  • Loading branch information
thelfer authored Jan 26, 2024
2 parents e090bed + c1f9123 commit edebeb1
Show file tree
Hide file tree
Showing 39 changed files with 879 additions and 1,046 deletions.
37 changes: 13 additions & 24 deletions include/TFEL/Material/FiniteStrainBehaviourTangentOperator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
#include <vector>
#include <string>
#include <utility>

#include "TFEL/Config/TFELConfig.hxx"

#include "TFEL/Metaprogramming/Implements.hxx"
#include "TFEL/TypeTraits/BaseType.hxx"
#include "TFEL/Math/Forward/st2tost2.hxx"
Expand All @@ -28,7 +26,6 @@
#include "TFEL/Math/T2toST2/T2toST2Concept.hxx"
#include "TFEL/Math/Forward/t2tot2.hxx"
#include "TFEL/Math/T2toT2/T2toT2Concept.hxx"

#include "TFEL/Utilities/GenTypeBase.hxx"
#include "TFEL/Material/FiniteStrainBehaviourTangentOperatorBase.hxx"

Expand Down Expand Up @@ -115,28 +112,22 @@ namespace tfel::material {
GenType::operator=(src);
return *this;
} // end of FiniteStrainBehaviourTangentOperator& operator=
/*!
* \param const T1&, the value affected to the GenType.
* \pre T1 must be a type that the GenType can hold.
*/
/*!
* \param const T1&, the value affected to the GenType.
* \pre T1 must be a type that the GenType can hold.
*/
template <typename T1>
TFEL_INLINE
typename std::enable_if<tfel::meta::TLCountNbrOfT<T1, TOTypes>::value ==
1,
void>::type
set_uninitialised() {
TFEL_INLINE void set_uninitialised() requires(
tfel::meta::TLCountNbrOfT<T1, TOTypes>::value == 1) {
GenType::template set_uninitialised<T1>();
}
/*!
* assignement operator
* \brief assignement operator
*/
template <typename T>
std::enable_if_t<
tfel::math::implementsT2toST2Concept<T>() &&
tfel::math::getSpaceDimension<T>() == N &&
std::is_same_v<tfel::math::numeric_type<T>, StressType>,
FiniteStrainBehaviourTangentOperator&>
operator=(const T& e) {
template <tfel::math::T2toST2Concept T>
FiniteStrainBehaviourTangentOperator& operator=(const T& e) requires(
tfel::math::getSpaceDimension<T>() == N &&
std::is_same_v<tfel::math::numeric_type<T>, StressType>) {
using namespace tfel::math;
if (this->template is<t2tost2<N, StressType>*>()) {
*(this->template get<t2tost2<N, StressType>*>()) = e;
Expand All @@ -152,11 +143,9 @@ namespace tfel::material {
* \brief assignement operator
*/
template <tfel::math::ST2toST2Concept T>
std::enable_if_t<
FiniteStrainBehaviourTangentOperator& operator=(const T& e) requires(
tfel::math::getSpaceDimension<T>() == N &&
std::is_same_v<tfel::math::numeric_type<T>, StressType>,
FiniteStrainBehaviourTangentOperator&>
operator=(const T& e) {
std::is_same_v<tfel::math::numeric_type<T>, StressType>) {
using namespace tfel::math;
if (this->template is<st2tost2<N, StressType>*>()) {
*(this->template get<st2tost2<N, StressType>*>()) = e;
Expand Down
70 changes: 29 additions & 41 deletions include/TFEL/Math/ST2toST2/ConvertT2toST2ToST2toST2Expr.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ namespace tfel::math {
template <unsigned short N>
struct ConvertT2toST2ToST2toST2Expr;

/*!
* Partial specialisation for 1D stensor
*/
template <typename ST2toST2ResultType>
//! \brief partial specialisation in 1D
template <ST2toST2Concept ST2toST2ResultType>
struct Expr<ST2toST2ResultType, ConvertT2toST2ToST2toST2Expr<1u>>
: public ST2toST2ConceptBase<
Expr<ST2toST2ResultType, ConvertT2toST2ToST2toST2Expr<1u>>>,
Expand All @@ -42,40 +40,36 @@ namespace tfel::math {
/*!
* \param[in] A : t2tost2 to be converted
*/
template <typename T2toST2Type>
Expr(const T2toST2Type& A) {
template <T2toST2Concept T2toST2Type>
TFEL_HOST_DEVICE constexpr Expr(const T2toST2Type& A) noexcept {
using tfel::fsalgo::copy;
static_assert(implementsT2toST2Concept<T2toST2Type>());
static_assert(getSpaceDimension<ST2toST2ResultType>() ==
getSpaceDimension<T2toST2Type>());
static_assert(isAssignableTo<numeric_type<T2toST2Type>,
numeric_type<ST2toST2ResultType>>());
copy<9u>::exe(&A(0, 0), this->v);
} // end of Expr
/*!
* \brief access operator
* \param[in] i : line index
* \param[in] j : column index
*/
const value_type& operator()(const unsigned short i,
const unsigned short j) const {
/*!
* \brief access operator
* \param[in] i : line index
* \param[in] j : column index
*/
TFEL_HOST_DEVICE constexpr const value_type& operator()(
const unsigned short i, const unsigned short j) const noexcept {
return this->v[i * 3 + j];
} // end of operator()
/*!
* \return the runtime properties of this object
* In this case, the number of lines and columns
* are deduced from the template parameter
*/
RunTimeProperties getRunTimeProperties() const {
TFEL_HOST_DEVICE constexpr auto getRunTimeProperties() const noexcept {
return RunTimeProperties();
}
}; // end of struct Expr<ST2toST2ResultType,ConvertT2toST2ToST2toST2Expr<1u>
// >
}; // end of Expr<ST2toST2ResultType,ConvertT2toST2ToST2toST2Expr<1u>>

/*!
* Partial specialisation for 2D stensor
*/
template <typename ST2toST2ResultType>
//! \brief partial specialisation in 2D
template <ST2toST2Concept ST2toST2ResultType>
struct Expr<ST2toST2ResultType, ConvertT2toST2ToST2toST2Expr<2u>>
: public ST2toST2ConceptBase<
Expr<ST2toST2ResultType, ConvertT2toST2ToST2toST2Expr<2u>>>,
Expand All @@ -89,9 +83,8 @@ namespace tfel::math {
/*!
* \param[in] A : t2tost2 to be converted
*/
template <typename T2toST2Type>
Expr(const T2toST2Type& A) {
static_assert(implementsT2toST2Concept<T2toST2Type>());
template <T2toST2Concept T2toST2Type>
TFEL_HOST_DEVICE constexpr Expr(const T2toST2Type& A) noexcept {
static_assert(getSpaceDimension<ST2toST2ResultType>() ==
getSpaceDimension<T2toST2Type>());
static_assert(isAssignableTo<numeric_type<T2toST2Type>,
Expand Down Expand Up @@ -120,25 +113,22 @@ namespace tfel::math {
* \param[in] i : line index
* \param[in] j : column index
*/
const value_type& operator()(const unsigned short i,
const unsigned short j) const {
TFEL_HOST_DEVICE constexpr const value_type& operator()(
const unsigned short i, const unsigned short j) const noexcept {
return this->v[i * 4 + j];
} // end of operator()
/*!
* \return the runtime properties of this object
* In this case, the number of lines and columns
* are deduced from the template parameter
*/
RunTimeProperties getRunTimeProperties() const {
TFEL_HOST_DEVICE constexpr auto getRunTimeProperties() const noexcept {
return RunTimeProperties();
}
}; // end of struct Expr<ST2toST2ResultType,ConvertT2toST2ToST2toST2Expr<2u>
// >
}; // end of Expr<ST2toST2ResultType,ConvertT2toST2ToST2toST2Expr<2u>>

/*!
* Partial specialisation for 3D stensor
*/
template <typename ST2toST2ResultType>
//! \brief partial specialisation in 3D
template <ST2toST2Concept ST2toST2ResultType>
struct Expr<ST2toST2ResultType, ConvertT2toST2ToST2toST2Expr<3u>>
: public ST2toST2ConceptBase<
Expr<ST2toST2ResultType, ConvertT2toST2ToST2toST2Expr<3u>>>,
Expand All @@ -151,9 +141,8 @@ namespace tfel::math {
/*!
* \param[in] A : t2tost2 to be converted
*/
template <typename T2toST2Type>
Expr(const T2toST2Type& A) {
static_assert(implementsT2toST2Concept<T2toST2Type>());
template <T2toST2Concept T2toST2Type>
TFEL_HOST_DEVICE constexpr Expr(const T2toST2Type& A) noexcept {
static_assert(getSpaceDimension<ST2toST2ResultType>() ==
getSpaceDimension<T2toST2Type>());
static_assert(isAssignableTo<numeric_type<T2toST2Type>,
Expand Down Expand Up @@ -202,20 +191,19 @@ namespace tfel::math {
* \param[in] i : line index
* \param[in] j : column index
*/
const value_type& operator()(const unsigned short i,
const unsigned short j) const {
TFEL_HOST_DEVICE constexpr const value_type& operator()(
const unsigned short i, const unsigned short j) const noexcept {
return this->v[i * 6 + j];
} // end of operator()
/*!
* \return the runtime properties of this object
* In this case, the number of lines and columns
* are deduced from the template parameter
*/
RunTimeProperties getRunTimeProperties() const {
TFEL_HOST_DEVICE constexpr auto getRunTimeProperties() const noexcept {
return RunTimeProperties();
}
}; // end of struct Expr<ST2toST2ResultType,ConvertT2toST2ToST2toST2Expr<3u>
// >
}; // end of Expr<ST2toST2ResultType,ConvertT2toST2ToST2toST2Expr<3u>>

} // end of namespace tfel::math

Expand Down
Loading

0 comments on commit edebeb1

Please sign in to comment.