ENH: add cmptMagSqr for scalars, VectorSpace, Fields (#1449)

This commit is contained in:
Mark Olesen
2019-09-29 16:53:42 +02:00
committed by Andrew Heather
parent bc9295ee04
commit 4a5569776e
6 changed files with 54 additions and 0 deletions

View File

@ -45,6 +45,7 @@ void printInfo(const vector& vec)
<< " sum:" << cmptSum(vec) << " sum:" << cmptSum(vec)
<< " prod:" << cmptProduct(vec) << " prod:" << cmptProduct(vec)
<< " mag:" << cmptMag(vec) << " mag:" << cmptMag(vec)
<< " magSqr:" << cmptMagSqr(vec)
<< nl << nl; << nl << nl;
} }

View File

@ -322,6 +322,30 @@ tmp<Field<Type>> cmptMag(const tmp<Field<Type>>& tf)
} }
template<class Type>
void cmptMagSqr(Field<Type>& res, const UList<Type>& f)
{
TFOR_ALL_F_OP_FUNC_F(Type, res, =, cmptMagSqr, Type, f)
}
template<class Type>
tmp<Field<Type>> cmptMagSqr(const UList<Type>& f)
{
auto tres = tmp<Field<Type>>::New(f.size());
cmptMagSqr(tres.ref(), f);
return tres;
}
template<class Type>
tmp<Field<Type>> cmptMagSqr(const tmp<Field<Type>>& tf)
{
auto tres = New(tf);
cmptMagSqr(tres.ref(), tf());
tf.clear();
return tres;
}
#define TMP_UNARY_FUNCTION(ReturnType, Func) \ #define TMP_UNARY_FUNCTION(ReturnType, Func) \
\ \
template<class Type> \ template<class Type> \

View File

@ -167,6 +167,16 @@ template<class Type>
tmp<Field<Type>> cmptMag(const tmp<Field<Type>>& tf); tmp<Field<Type>> cmptMag(const tmp<Field<Type>>& tf);
template<class Type>
void cmptMagSqr(Field<Type>& res, const UList<Type>& f);
template<class Type>
tmp<Field<Type>> cmptMagSqr(const UList<Type>& f);
template<class Type>
tmp<Field<Type>> cmptMagSqr(const tmp<Field<Type>>& tf);
#define TMP_UNARY_FUNCTION(ReturnType, Func) \ #define TMP_UNARY_FUNCTION(ReturnType, Func) \
\ \
/** \brief Apply the \c Func() function on the tmp field */ \ /** \brief Apply the \c Func() function on the tmp field */ \

View File

@ -382,6 +382,12 @@ inline Scalar cmptMag(const Scalar s)
} }
inline Scalar cmptMagSqr(const Scalar s)
{
return magSqr(s);
}
inline Scalar sqrtSumSqr(const Scalar a, const Scalar b) inline Scalar sqrtSumSqr(const Scalar a, const Scalar b)
{ {
const Scalar maga = mag(a); const Scalar maga = mag(a);

View File

@ -635,6 +635,18 @@ inline Form cmptMag
} }
template<class Form, class Cmpt, direction Ncmpts>
inline Form cmptMagSqr
(
const VectorSpace<Form, Cmpt, Ncmpts>& vs
)
{
Form v;
VectorSpaceOps<Ncmpts,0>::eqOp(v, vs, eqMagSqrOp<Cmpt>());
return v;
}
template<class Form, class Cmpt, direction Ncmpts> template<class Form, class Cmpt, direction Ncmpts>
inline Form max inline Form max
( (

View File

@ -74,6 +74,7 @@ EqOp(multiplyEq, x *= y)
EqOp(divideEq, x /= y) EqOp(divideEq, x /= y)
EqOp(eqSqr, x = sqr(y)) EqOp(eqSqr, x = sqr(y))
EqOp(eqMag, x = mag(y)) EqOp(eqMag, x = mag(y))
EqOp(eqMagSqr, x = magSqr(y))
EqOp(plusEqMagSqr, x += magSqr(y)) EqOp(plusEqMagSqr, x += magSqr(y))
EqOp(maxEq, x = max(x, y)) EqOp(maxEq, x = max(x, y))
EqOp(minEq, x = min(x, y)) EqOp(minEq, x = min(x, y))