Commit 4c257552 authored by Andrew Heather's avatar Andrew Heather Committed by Andrew Heather
Browse files

Merge branch 'feature-single-precision' into 'develop'

Feature single precision

See merge request OpenFOAM-plus!234
parents 24371a1d 262faabd
......@@ -614,9 +614,12 @@ Foam::sqr(const dimensioned<Type>& dt)
}
template<class Type>
Foam::dimensioned<Foam::scalar> Foam::magSqr(const dimensioned<Type>& dt)
Foam::dimensioned<typename Foam::typeOfMag<Type>::type>
Foam::magSqr(const dimensioned<Type>& dt)
{
return dimensioned<scalar>
typedef typename typeOfMag<Type>::type magType;
return dimensioned<magType>
(
"magSqr(" + dt.name() + ')',
magSqr(dt.dimensions()),
......@@ -625,9 +628,12 @@ Foam::dimensioned<Foam::scalar> Foam::magSqr(const dimensioned<Type>& dt)
}
template<class Type>
Foam::dimensioned<Foam::scalar> Foam::mag(const dimensioned<Type>& dt)
Foam::dimensioned<typename Foam::typeOfMag<Type>::type>
Foam::mag(const dimensioned<Type>& dt)
{
return dimensioned<scalar>
typedef typename typeOfMag<Type>::type magType;
return dimensioned<magType>
(
"mag(" + dt.name() + ')',
dt.dimensions(),
......
......@@ -437,10 +437,12 @@ dimensioned<typename outerProduct<Type, Type>::type>
sqr(const dimensioned<Type>&);
template<class Type>
dimensioned<scalar> magSqr(const dimensioned<Type>&);
dimensioned<typename typeOfMag<Type>::type>
magSqr(const dimensioned<Type>& dt);
template<class Type>
dimensioned<scalar> mag(const dimensioned<Type>&);
dimensioned<typename typeOfMag<Type>::type>
mag(const dimensioned<Type>& dt);
template<class Type>
dimensioned<Type> cmptMultiply
......
......@@ -141,13 +141,13 @@ sqr(const tmp<DimensionedField<Type, GeoMesh>>& tdf)
template<class Type, class GeoMesh>
tmp<DimensionedField<scalar, GeoMesh>> magSqr
(
const DimensionedField<Type, GeoMesh>& df
)
tmp<DimensionedField<typename typeOfMag<Type>::type, GeoMesh>>
magSqr(const DimensionedField<Type, GeoMesh>& df)
{
typedef typename typeOfMag<Type>::type magType;
auto tres =
tmp<DimensionedField<scalar, GeoMesh>>::New
tmp<DimensionedField<magType, GeoMesh>>::New
(
IOobject
(
......@@ -165,15 +165,15 @@ tmp<DimensionedField<scalar, GeoMesh>> magSqr
}
template<class Type, class GeoMesh>
tmp<DimensionedField<scalar, GeoMesh>> magSqr
(
const tmp<DimensionedField<Type, GeoMesh>>& tdf
)
tmp<DimensionedField<typename typeOfMag<Type>::type, GeoMesh>>
magSqr(const tmp<DimensionedField<Type, GeoMesh>>& tdf)
{
typedef typename typeOfMag<Type>::type magType;
const DimensionedField<Type, GeoMesh>& df = tdf();
auto tres =
reuseTmpDimensionedField<scalar, Type, GeoMesh>::New
reuseTmpDimensionedField<magType, Type, GeoMesh>::New
(
tdf,
"magSqr(" + df.name() + ')',
......@@ -188,13 +188,13 @@ tmp<DimensionedField<scalar, GeoMesh>> magSqr
template<class Type, class GeoMesh>
tmp<DimensionedField<scalar, GeoMesh>> mag
(
const DimensionedField<Type, GeoMesh>& df
)
tmp<DimensionedField<typename typeOfMag<Type>::type, GeoMesh>>
mag(const DimensionedField<Type, GeoMesh>& df)
{
typedef typename typeOfMag<Type>::type magType;
auto tres =
tmp<DimensionedField<scalar, GeoMesh>>::New
tmp<DimensionedField<magType, GeoMesh>>::New
(
IOobject
(
......@@ -212,15 +212,15 @@ tmp<DimensionedField<scalar, GeoMesh>> mag
}
template<class Type, class GeoMesh>
tmp<DimensionedField<scalar, GeoMesh>> mag
(
const tmp<DimensionedField<Type, GeoMesh>>& tdf
)
tmp<DimensionedField<typename typeOfMag<Type>::type, GeoMesh>>
mag(const tmp<DimensionedField<Type, GeoMesh>>& tdf)
{
typedef typename typeOfMag<Type>::type magType;
const DimensionedField<Type, GeoMesh>& df = tdf();
auto tres =
reuseTmpDimensionedField<scalar, Type, GeoMesh>::New
reuseTmpDimensionedField<magType, Type, GeoMesh>::New
(
tdf,
"mag(" + df.name() + ')',
......@@ -325,11 +325,10 @@ UNARY_REDUCTION_FUNCTION(Type, max, gMax)
UNARY_REDUCTION_FUNCTION(Type, min, gMin)
UNARY_REDUCTION_FUNCTION(Type, sum, gSum)
UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
UNARY_REDUCTION_FUNCTION(MinMax<Type>, minMax, gMinMax)
UNARY_REDUCTION_FUNCTION(scalarMinMax, minMaxMag, gMinMaxMag)
UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
UNARY_REDUCTION_FUNCTION(typename typeOfMag<Type>::type, sumMag, gSumMag)
#undef UNARY_REDUCTION_FUNCTION
......
......@@ -62,34 +62,29 @@ tmp<DimensionedField<typename outerProduct<Type, Type>::type, GeoMesh>>
sqr(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
template<class Type, class GeoMesh>
tmp<DimensionedField<scalar, GeoMesh>> magSqr
(
const DimensionedField<Type, GeoMesh>& df
);
tmp<DimensionedField<typename typeOfMag<Type>::type, GeoMesh>>
magSqr(const DimensionedField<Type, GeoMesh>& df);
template<class Type, class GeoMesh>
tmp<DimensionedField<scalar, GeoMesh>> magSqr
(
const tmp<DimensionedField<Type, GeoMesh>>& tdf
);
tmp<DimensionedField<typename typeOfMag<Type>::type, GeoMesh>>
magSqr(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
template<class Type, class GeoMesh>
tmp<DimensionedField<scalar, GeoMesh>> mag
(
const DimensionedField<Type, GeoMesh>& df
);
tmp<DimensionedField<typename typeOfMag<Type>::type, GeoMesh>>
mag(const DimensionedField<Type, GeoMesh>& df);
template<class Type, class GeoMesh>
tmp<DimensionedField<scalar, GeoMesh>> mag
(
const tmp<DimensionedField<Type, GeoMesh>>& tdf
);
tmp<DimensionedField<typename typeOfMag<Type>::type, GeoMesh>>
mag(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
template<class Type, class GeoMesh>
tmp
<
DimensionedField
<typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
<
typename DimensionedField<Type, GeoMesh>::cmptType,
GeoMesh
>
>
cmptAv(const DimensionedField<Type, GeoMesh>& df);
......@@ -97,7 +92,10 @@ template<class Type, class GeoMesh>
tmp
<
DimensionedField
<typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
<
typename DimensionedField<Type, GeoMesh>::cmptType,
GeoMesh
>
>
cmptAv(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
......@@ -123,7 +121,7 @@ UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
UNARY_REDUCTION_FUNCTION(MinMax<Type>, minMax, gMinMax)
UNARY_REDUCTION_FUNCTION(scalarMinMax, minMaxMag, gMinMaxMag)
UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
UNARY_REDUCTION_FUNCTION(typename typeOfMag<Type>::type, sumMag, gSumMag)
#undef UNARY_REDUCTION_FUNCTION
......
......@@ -158,7 +158,11 @@ sqr(const tmp<FieldField<Field, Type>>& tf)
template<template<class> class Field, class Type>
void magSqr(FieldField<Field, scalar>& sf, const FieldField<Field, Type>& f)
void magSqr
(
FieldField<Field, typename typeOfMag<Type>::type>& sf,
const FieldField<Field, Type>& f
)
{
forAll(sf, i)
{
......@@ -167,11 +171,14 @@ void magSqr(FieldField<Field, scalar>& sf, const FieldField<Field, Type>& f)
}
template<template<class> class Field, class Type>
tmp<FieldField<Field, scalar>> magSqr(const FieldField<Field, Type>& f)
tmp<FieldField<Field, typename typeOfMag<Type>::type>>
magSqr(const FieldField<Field, Type>& f)
{
typedef typename typeOfMag<Type>::type magType;
auto tres
(
FieldField<Field, scalar>::NewCalculatedType(f)
FieldField<Field, magType>::NewCalculatedType(f)
);
magSqr(tres.ref(), f);
......@@ -179,11 +186,14 @@ tmp<FieldField<Field, scalar>> magSqr(const FieldField<Field, Type>& f)
}
template<template<class> class Field, class Type>
tmp<FieldField<Field, scalar>> magSqr(const tmp<FieldField<Field, Type>>& tf)
tmp<FieldField<Field, typename typeOfMag<Type>::type>>
magSqr(const tmp<FieldField<Field, Type>>& tf)
{
typedef typename typeOfMag<Type>::type magType;
auto tres
(
reuseTmpFieldField<Field, scalar, Type>::New(tf)
reuseTmpFieldField<Field, magType, Type>::New(tf)
);
magSqr(tres.ref(), tf());
......@@ -193,7 +203,11 @@ tmp<FieldField<Field, scalar>> magSqr(const tmp<FieldField<Field, Type>>& tf)
template<template<class> class Field, class Type>
void mag(FieldField<Field, scalar>& sf, const FieldField<Field, Type>& f)
void mag
(
FieldField<Field, typename typeOfMag<Type>::type>& sf,
const FieldField<Field, Type>& f
)
{
forAll(sf, i)
{
......@@ -202,11 +216,14 @@ void mag(FieldField<Field, scalar>& sf, const FieldField<Field, Type>& f)
}
template<template<class> class Field, class Type>
tmp<FieldField<Field, scalar>> mag(const FieldField<Field, Type>& f)
tmp<FieldField<Field, typename typeOfMag<Type>::type>>
mag(const FieldField<Field, Type>& f)
{
typedef typename typeOfMag<Type>::type magType;
auto tres
(
FieldField<Field, scalar>::NewCalculatedType(f)
FieldField<Field, magType>::NewCalculatedType(f)
);
mag(tres.ref(), f);
......@@ -214,11 +231,14 @@ tmp<FieldField<Field, scalar>> mag(const FieldField<Field, Type>& f)
}
template<template<class> class Field, class Type>
tmp<FieldField<Field, scalar>> mag(const tmp<FieldField<Field, Type>>& tf)
tmp<FieldField<Field, typename typeOfMag<Type>::type>>
mag(const tmp<FieldField<Field, Type>>& tf)
{
typedef typename typeOfMag<Type>::type magType;
auto tres
(
reuseTmpFieldField<Field, scalar, Type>::New(tf)
reuseTmpFieldField<Field, magType, Type>::New(tf)
);
mag(tres.ref(), tf());
......@@ -480,19 +500,21 @@ Type sum(const FieldField<Field, Type>& f)
TMP_UNARY_FUNCTION(Type, sum)
template<template<class> class Field, class Type>
scalar sumMag(const FieldField<Field, Type>& f)
typename typeOfMag<Type>::type sumMag(const FieldField<Field, Type>& f)
{
scalar SumMag = 0.0;
typedef typename typeOfMag<Type>::type magType;
magType result = Zero;
forAll(f, i)
{
SumMag += sumMag(f[i]);
result += sumMag(f[i]);
}
return SumMag;
return result;
}
TMP_UNARY_FUNCTION(scalar, sumMag)
TMP_UNARY_FUNCTION(typename typeOfMag<Type>::type, sumMag)
template<template<class> class Field, class Type>
Type average(const FieldField<Field, Type>& f)
......@@ -555,25 +577,24 @@ TMP_UNARY_FUNCTION(scalarMinMax, minMaxMag)
// With reduction on ReturnType
#define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \
#define G_UNARY_FUNCTION(ReturnType, gFunc, func, rFunc) \
\
template<template<class> class Field, class Type> \
returnType gFunc(const FieldField<Field, Type>& f) \
ReturnType gFunc(const FieldField<Field, Type>& f) \
{ \
returnType res = func(f); \
reduce(res, rFunc##Op<returnType>()); \
ReturnType res = func(f); \
reduce(res, rFunc##Op<ReturnType>()); \
return res; \
} \
TMP_UNARY_FUNCTION(returnType, gFunc)
TMP_UNARY_FUNCTION(ReturnType, gFunc)
G_UNARY_FUNCTION(Type, gMax, max, max)
G_UNARY_FUNCTION(Type, gMin, min, min)
G_UNARY_FUNCTION(Type, gSum, sum, sum)
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, sum)
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, sum)
G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
G_UNARY_FUNCTION(typename typeOfMag<Type>::type, gSumMag, sumMag, sum)
#undef G_UNARY_FUNCTION
......
......@@ -90,23 +90,35 @@ sqr(const tmp<FieldField<Field, Type>>& tf);
template<template<class> class Field, class Type>
void magSqr(FieldField<Field, scalar>& sf, const FieldField<Field, Type>& f);
void magSqr
(
FieldField<Field, typename typeOfMag<Type>::type>& sf,
const FieldField<Field, Type>& f
);
template<template<class> class Field, class Type>
tmp<FieldField<Field, scalar>> magSqr(const FieldField<Field, Type>& f);
tmp<FieldField<Field, typename typeOfMag<Type>::type>>
magSqr(const FieldField<Field, Type>& f);
template<template<class> class Field, class Type>
tmp<FieldField<Field, scalar>> magSqr(const tmp<FieldField<Field, Type>>& tf);
tmp<FieldField<Field, typename typeOfMag<Type>::type>>
magSqr(const tmp<FieldField<Field, Type>>& tf);
template<template<class> class Field, class Type>
void mag(FieldField<Field, scalar>& sf, const FieldField<Field, Type>& f);
void mag
(
FieldField<Field, typename typeOfMag<Type>::type>& res,
const FieldField<Field, Type>& f
);
template<template<class> class Field, class Type>
tmp<FieldField<Field, scalar>> mag(const FieldField<Field, Type>& f);
tmp<FieldField<Field, typename typeOfMag<Type>::type>>
mag(const FieldField<Field, Type>& f);
template<template<class> class Field, class Type>
tmp<FieldField<Field, scalar>> mag(const tmp<FieldField<Field, Type>>& tf);
tmp<FieldField<Field, typename typeOfMag<Type>::type>>
mag(const tmp<FieldField<Field, Type>>& tf);
template<template<class> class Field, class Type>
......@@ -214,9 +226,9 @@ TMP_UNARY_FUNCTION(Type, sum)
template<template<class> class Field, class Type>
scalar sumMag(const FieldField<Field, Type>& f);
typename typeOfMag<Type>::type sumMag(const FieldField<Field, Type>& f);
TMP_UNARY_FUNCTION(scalar, sumMag)
TMP_UNARY_FUNCTION(typename typeOfMag<Type>::type, sumMag)
template<template<class> class Field, class Type>
......@@ -239,20 +251,19 @@ TMP_UNARY_FUNCTION(scalarMinMax, minMaxMag)
// With reduction on ReturnType
#define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \
#define G_UNARY_FUNCTION(ReturnType, gFunc, func, rFunc) \
\
template<template<class> class Field, class Type> \
returnType gFunc(const FieldField<Field, Type>& f); \
TMP_UNARY_FUNCTION(returnType, gFunc)
ReturnType gFunc(const FieldField<Field, Type>& f); \
TMP_UNARY_FUNCTION(ReturnType, gFunc)
G_UNARY_FUNCTION(Type, gMax, max, max)
G_UNARY_FUNCTION(Type, gMin, min, min)
G_UNARY_FUNCTION(Type, gSum, sum, sum)
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, sum)
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, sum)
G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
G_UNARY_FUNCTION(typename typeOfMag<Type>::type, gSumMag, sumMag, sum)
#undef G_UNARY_FUNCTION
......
......@@ -146,23 +146,35 @@ sqr(const tmp<Field<Type>>& tf)
template<class Type>
void magSqr(Field<scalar>& res, const UList<Type>& f)
void magSqr
(
Field<typename typeOfMag<Type>::type>& res,
const UList<Type>& f
)
{
TFOR_ALL_F_OP_FUNC_F(scalar, res, =, magSqr, Type, f)
typedef typename typeOfMag<Type>::type magType;
TFOR_ALL_F_OP_FUNC_F(magType, res, =, magSqr, Type, f)
}
template<class Type>
tmp<Field<scalar>> magSqr(const UList<Type>& f)
tmp<Field<typename typeOfMag<Type>::type>>
magSqr(const UList<Type>& f)
{
auto tres = tmp<Field<scalar>>::New(f.size());
typedef typename typeOfMag<Type>::type magType;
auto tres = tmp<Field<magType>>::New(f.size());
magSqr(tres.ref(), f);
return tres;
}
template<class Type>
tmp<Field<scalar>> magSqr(const tmp<Field<Type>>& tf)
tmp<Field<typename typeOfMag<Type>::type>>
magSqr(const tmp<Field<Type>>& tf)
{
auto tres = reuseTmp<scalar, Type>::New(tf);
typedef typename typeOfMag<Type>::type magType;
auto tres = reuseTmp<magType, Type>::New(tf);
magSqr(tres.ref(), tf());
tf.clear();
return tres;
......@@ -170,23 +182,35 @@ tmp<Field<scalar>> magSqr(const tmp<Field<Type>>& tf)
template<class Type>
void mag(Field<scalar>& res, const UList<Type>& f)
void mag
(
Field<typename typeOfMag<Type>::type>& res,
const UList<Type>& f
)
{
TFOR_ALL_F_OP_FUNC_F(scalar, res, =, mag, Type, f)
typedef typename typeOfMag<Type>::type magType;
TFOR_ALL_F_OP_FUNC_F(magType, res, =, mag, Type, f)
}
template<class Type>
tmp<Field<scalar>> mag(const UList<Type>& f)
tmp<Field<typename typeOfMag<Type>::type>>
mag(const UList<Type>& f)
{
auto tres = tmp<Field<scalar>>::New(f.size());
typedef typename typeOfMag<Type>::type magType;
auto tres = tmp<Field<magType>>::New(f.size());
mag(tres.ref(), f);
return tres;
}
template<class Type>
tmp<Field<scalar>> mag(const tmp<Field<Type>>& tf)
tmp<Field<typename typeOfMag<Type>::type>>
mag(const tmp<Field<Type>>& tf)
{
auto tres = reuseTmp<scalar, Type>::New(tf);
typedef typename typeOfMag<Type>::type magType;
auto tres = reuseTmp<magType, Type>::New(tf);
mag(tres.ref(), tf());
tf.clear();
return tres;
......@@ -341,14 +365,14 @@ TMP_UNARY_FUNCTION(Type, min)
template<class Type>
Type sum(const UList<Type>& f)
{
Type Sum = Zero;
if (f.size())
{
Type Sum = Zero;
TFOR_ALL_S_OP_F(Type, Sum, +=, Type, f)
return Sum;
}
return Zero;
return Sum;
}
TMP_UNARY_FUNCTION(Type, sum)
......@@ -413,15 +437,15 @@ Type minMagSqr(const UList<Type>& f)
TMP_UNARY_FUNCTION(Type, minMagSqr)
template<class Type>
typename pTraits<Type>::cmptType
typename scalarProduct<Type, Type>::type
sumProd(const UList<Type>& f1, const UList<Type>& f2)
{
typedef typename pTraits<Type>::cmptType outType;
typedef typename scalarProduct<Type, Type>::type prodType;
outType result = Zero;
prodType result = Zero;
if (f1.size() && (f1.size() == f2.size()))
{
TFOR_ALL_S_OP_F_OP_F(outType, result, +=, Type, f1, &&, Type, f2)
TFOR_ALL_S_OP_F_OP_F(prodType, result, +=, Type, f1, &&, Type, f2)
}
return result;
}
......@@ -450,41 +474,54 @@ Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2)
template<class Type>
scalar sumSqr(const UList<Type>& f)
typename outerProduct1<Type>::type
sumSqr(const UList<Type>& f)
{
scalar SumSqr = 0;
typedef typename outerProduct1<Type>::type prodType;
prodType result = Zero;
if (f.size())
{
TFOR_ALL_S_OP_FUNC_F(scalar, SumSqr, +=, sqr, Type, f)
TFOR_ALL_S_OP_FUNC_F(prodType, result, +=, sqr, Type, f)
}
return SumSqr;
return result;
}
template<class Type>