mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add cmptMagSqr for scalars, VectorSpace, Fields (#1449)
This commit is contained in:
committed by
Andrew Heather
parent
bc9295ee04
commit
4a5569776e
@ -45,6 +45,7 @@ void printInfo(const vector& vec)
|
||||
<< " sum:" << cmptSum(vec)
|
||||
<< " prod:" << cmptProduct(vec)
|
||||
<< " mag:" << cmptMag(vec)
|
||||
<< " magSqr:" << cmptMagSqr(vec)
|
||||
<< nl << nl;
|
||||
}
|
||||
|
||||
|
||||
@ -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) \
|
||||
\
|
||||
template<class Type> \
|
||||
|
||||
@ -167,6 +167,16 @@ template<class Type>
|
||||
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) \
|
||||
\
|
||||
/** \brief Apply the \c Func() function on the tmp field */ \
|
||||
|
||||
@ -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)
|
||||
{
|
||||
const Scalar maga = mag(a);
|
||||
|
||||
@ -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>
|
||||
inline Form max
|
||||
(
|
||||
|
||||
@ -74,6 +74,7 @@ EqOp(multiplyEq, x *= y)
|
||||
EqOp(divideEq, x /= y)
|
||||
EqOp(eqSqr, x = sqr(y))
|
||||
EqOp(eqMag, x = mag(y))
|
||||
EqOp(eqMagSqr, x = magSqr(y))
|
||||
EqOp(plusEqMagSqr, x += magSqr(y))
|
||||
EqOp(maxEq, x = max(x, y))
|
||||
EqOp(minEq, x = min(x, y))
|
||||
|
||||
Reference in New Issue
Block a user