32#define TEMPLATE template<class Type>
66template<
class Type, direction r>
77 resultType, result, =,
pow, Type, f1, resultType,
82template<
class Type, direction r>
83tmp<Field<typename powProduct<Type, r>::type>>
86 const UList<Type>& f1,
96template<
class Type, direction r>
97tmp<Field<typename powProduct<Type, r>::type>>
100 const tmp<Field<Type>>& tf1,
116 const UList<Type>& f1
125tmp<Field<typename outerProduct<Type, Type>::type>>
126sqr(
const UList<Type>& f1)
135tmp<Field<typename outerProduct<Type, Type>::type>>
136sqr(
const tmp<Field<Type>>& tf1)
150 const UList<Type>& f1
159tmp<Field<typename typeOfMag<Type>::type>>
160magSqr(
const UList<Type>& f1)
170tmp<Field<typename typeOfMag<Type>::type>>
171magSqr(
const tmp<Field<Type>>& tf1)
186 const UList<Type>& f1
195tmp<Field<typename typeOfMag<Type>::type>>
196mag(
const UList<Type>& f1)
206tmp<Field<typename typeOfMag<Type>::type>>
207mag(
const tmp<Field<Type>>& tf1)
222 const UList<Type>& f1
231tmp<Field<typename Field<Type>::cmptType>>
cmptMax(
const UList<Type>& f1)
240tmp<Field<typename Field<Type>::cmptType>>
cmptMax(
const tmp<Field<Type>>& tf1)
254 const UList<Type>& f1
263tmp<Field<typename Field<Type>::cmptType>>
cmptMin(
const UList<Type>& f1)
272tmp<Field<typename Field<Type>::cmptType>>
cmptMin(
const tmp<Field<Type>>& tf1)
286 const UList<Type>& f1
295tmp<Field<typename Field<Type>::cmptType>>
cmptAv(
const UList<Type>& f1)
304tmp<Field<typename Field<Type>::cmptType>>
cmptAv(
const tmp<Field<Type>>& tf1)
321tmp<Field<Type>>
cmptMag(
const UList<Type>& f1)
329tmp<Field<Type>>
cmptMag(
const tmp<Field<Type>>& tf1)
331 auto tres =
New(tf1);
345tmp<Field<Type>>
cmptMagSqr(
const UList<Type>& f1)
353tmp<Field<Type>>
cmptMagSqr(
const tmp<Field<Type>>& tf1)
362#define TMP_UNARY_FUNCTION(ReturnType, Func) \
364template<class Type> \
365ReturnType Func(const tmp<Field<Type>>& tf1) \
367 ReturnType res = Func(tf1()); \
388Type
min(
const UList<Type>& f1)
403Type
sum(
const UList<Type>& f1)
407 resultType result =
Zero;
435 TFOR_ALL_S_OP_FUNC_F_S
485 resultType result =
Zero;
486 if (f1.size() && (f1.size() == f2.size()))
488 TFOR_ALL_S_OP_F_OP_F(resultType, result, +=, Type, f1, &&, Type, f2)
495Type
sumCmptProd(
const UList<Type>& f1,
const UList<Type>& f2)
498 if (f1.size() && (f1.size() == f2.size()))
522 resultType result =
Zero;
535 resultType result =
sumSqr(tf1());
543sumMag(
const UList<Type>& f1)
547 resultType result =
Zero;
576 Type result =
sum(f1)/f1.size();
582 <<
"empty field, returning zero" <<
endl;
591#define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \
593template<class Type> \
594ReturnType gFunc(const UList<Type>& f, const label comm) \
596 ReturnType res = Func(f); \
597 Foam::reduce(res, rFunc##Op<ReturnType>(), UPstream::msgType(), comm); \
600TMP_UNARY_FUNCTION(ReturnType, gFunc)
615#undef G_UNARY_FUNCTION
628 resultType result =
sumProd(f1, f2);
636 const UList<Type>& f1,
637 const UList<Type>& f2,
649 const UList<Type>& f1,
653 label count = f1.size();
654 Type result =
sum(f1);
668 <<
"empty field, returning zero." <<
endl;
679 const UList<scalar>& weights,
680 const UList<Type>&
fld,
687 const label loopLen =
fld.size();
690 for (label i = 0; i < loopLen; ++i)
703 if (weight > ROOTVSMALL)
706 return result/(weight + ROOTVSMALL);
725 const label loopLen =
fld.size();
728 for (label i = 0; i < loopLen; ++i)
743#undef TMP_UNARY_FUNCTION
779 const Foam::zero_one&
782 if (result.cdata() == f1.cdata())
785 result.clamp_range(Foam::zero_one{});
792 f1.cbegin(result.size()),
835#define PRODUCT_OPERATOR(product, Op, OpFunc) \
837template<class Type1, class Type2> \
840 Field<typename product<Type1, Type2>::type>& result, \
841 const UList<Type1>& f1, \
842 const UList<Type2>& f2 \
845 typedef typename product<Type1, Type2>::type resultType; \
846 TFOR_ALL_F_OP_F_OP_F(resultType, result, =, Type1, f1, Op, Type2, f2) \
849template<class Type1, class Type2> \
850tmp<Field<typename product<Type1, Type2>::type>> \
851operator Op(const UList<Type1>& f1, const UList<Type2>& f2) \
853 typedef typename product<Type1, Type2>::type resultType; \
854 auto tres = tmp<Field<resultType>>::New(f1.size()); \
855 OpFunc(tres.ref(), f1, f2); \
859template<class Type1, class Type2> \
860tmp<Field<typename product<Type1, Type2>::type>> \
861operator Op(const UList<Type1>& f1, const tmp<Field<Type2>>& tf2) \
863 typedef typename product<Type1, Type2>::type resultType; \
864 auto tres = reuseTmp<resultType, Type2>::New(tf2); \
865 OpFunc(tres.ref(), f1, tf2()); \
870template<class Type1, class Type2> \
871tmp<Field<typename product<Type1, Type2>::type>> \
872operator Op(const tmp<Field<Type1>>& tf1, const UList<Type2>& f2) \
874 typedef typename product<Type1, Type2>::type resultType; \
875 auto tres = reuseTmp<resultType, Type1>::New(tf1); \
876 OpFunc(tres.ref(), tf1(), f2); \
881template<class Type1, class Type2> \
882tmp<Field<typename product<Type1, Type2>::type>> \
883operator Op(const tmp<Field<Type1>>& tf1, const tmp<Field<Type2>>& tf2) \
885 typedef typename product<Type1, Type2>::type resultType; \
886 auto tres = reuseTmpTmp<resultType, Type1, Type1, Type2>::New(tf1, tf2); \
887 OpFunc(tres.ref(), tf1(), tf2()); \
893template<class Type, class Form, class Cmpt, direction nCmpt> \
896 Field<typename product<Type, Form>::type>& result, \
897 const UList<Type>& f1, \
898 const VectorSpace<Form,Cmpt,nCmpt>& vs \
901 typedef typename product<Type, Form>::type resultType; \
902 TFOR_ALL_F_OP_F_OP_S \
903 (resultType, result, =,Type, f1, Op, Form, static_cast<const Form&>(vs))\
906template<class Type, class Form, class Cmpt, direction nCmpt> \
907tmp<Field<typename product<Type, Form>::type>> \
908operator Op(const UList<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs) \
910 typedef typename product<Type, Form>::type resultType; \
911 auto tres = tmp<Field<resultType>>::New(f1.size()); \
912 OpFunc(tres.ref(), f1, static_cast<const Form&>(vs)); \
916template<class Type, class Form, class Cmpt, direction nCmpt> \
917tmp<Field<typename product<Type, Form>::type>> \
920 const tmp<Field<Type>>& tf1, \
921 const VectorSpace<Form,Cmpt,nCmpt>& vs \
924 typedef typename product<Type, Form>::type resultType; \
925 auto tres = reuseTmp<resultType, Type>::New(tf1); \
926 OpFunc(tres.ref(), tf1(), static_cast<const Form&>(vs)); \
931template<class Form, class Cmpt, direction nCmpt, class Type> \
934 Field<typename product<Form, Type>::type>& result, \
935 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
936 const UList<Type>& f1 \
939 typedef typename product<Form, Type>::type resultType; \
940 TFOR_ALL_F_OP_S_OP_F \
941 (resultType, result, =,Form,static_cast<const Form&>(vs), Op, Type, f1)\
944template<class Form, class Cmpt, direction nCmpt, class Type> \
945tmp<Field<typename product<Form, Type>::type>> \
946operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const UList<Type>& f1) \
948 typedef typename product<Form, Type>::type resultType; \
949 auto tres = tmp<Field<resultType>>::New(f1.size()); \
950 OpFunc(tres.ref(), static_cast<const Form&>(vs), f1); \
954template<class Form, class Cmpt, direction nCmpt, class Type> \
955tmp<Field<typename product<Form, Type>::type>> \
958 const VectorSpace<Form,Cmpt,nCmpt>& vs, const tmp<Field<Type>>& tf1 \
961 typedef typename product<Form, Type>::type resultType; \
962 auto tres = reuseTmp<resultType, Type>::New(tf1); \
963 OpFunc(tres.ref(), static_cast<const Form&>(vs), tf1()); \
976#undef PRODUCT_OPERATOR
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func)
#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func)
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
#define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc)
#define TMP_UNARY_FUNCTION(ReturnType, Func)
#define BINARY_FUNCTION_INTERFACE_FS(ReturnType, Type1, Type2, Func)
#define TFOR_ALL_S_OP_F_OP_F(typeS, s, OP1, typeF1, f1, OP2, typeF2, f2)
#define TFOR_ALL_F_OP_FUNC_F_S(typeF1, f1, OP, FUNC, typeF2, f2, typeS, s)
#define TFOR_ALL_F_OP_F_FUNC(typeF1, f1, OP, typeF2, f2, FUNC)
#define TFOR_ALL_F_OP_F_FUNC_S(typeF1, f1, OP, typeF2, f2, FUNC, typeS, s)
#define TFOR_ALL_S_OP_FUNC_F(typeS, s, OP, FUNC, typeF, f)
#define TFOR_ALL_S_OP_FUNC_F_S(typeS1, s1, OP, FUNC, typeF, f, typeS2, s2)
#define TFOR_ALL_F_OP_FUNC_F(typeF1, f1, OP, FUNC, typeF2, f2)
#define TFOR_ALL_S_OP_FUNC_F_F(typeS, s, OP, FUNC, typeF1, f1, typeF2, f2)
Inter-processor communication reduction functions.
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
void clamp_range(const Type &lower, const Type &upper)
Clamp field values (in-place) to the specified range.
pTraits< Type >::cmptType cmptType
Component type.
A min/max value pair with additional methods. In addition to conveniently storing values,...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
iterator begin() noexcept
Return an iterator to begin traversing the UList.
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant UList.
void size(const label n)
Older name for setAddressableSize.
static int & msgType() noexcept
Message tag of standard messages.
Outer-product of identical types.
typeOfRank< typenamepTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank)>::type type
A traits class, which is primarily used for primitives and vector-space.
symmTypeOfRank< typenamepTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank)>::type type
pTraits< arg1 >::cmptType type
A class for managing temporary objects.
The magnitude type for given argument.
pTraits< typenamepTraits< arg1 >::cmptType >::magType type
Represents 0/1 range or concept. Used for tagged dispatch or clamping.
#define PRODUCT_OPERATOR(product, op, opFunc)
#define WarningInFunction
Report a warning using Foam::Warning.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Type gAverage(const FieldField< Field, Type > &f, const label comm)
The global arithmetic average of a FieldField.
dimensioned< scalarMinMax > minMaxMag(const DimensionedField< Type, GeoMesh > &f1, const label comm)
scalarProduct< Type, Type >::type gSumProd(const UList< Type > &f1, const UList< Type > &f2, const label comm)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Type gSum(const FieldField< Field, Type > &f)
Type gWeightedAverage(const UList< scalar > &weights, const UList< Type > &fld, const label comm)
The global weighted average of a field, using the mag() of the weights.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void subtract(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Type sumCmptMag(const UList< Type > &f1)
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
Type sumCmptProd(const UList< Type > &f1, const UList< Type > &f2)
dimensionSet clamp(const dimensionSet &a, const dimensionSet &range)
void divide(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
Type minMagSqr(const UList< Type > &f1)
MinMax< scalar > scalarMinMax
A scalar min/max range.
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Type gWeightedSum(const UList< scalar > &weights, const UList< Type > &fld, const label comm)
The global weighted sum (integral) of a field, using the mag() of the weights.
scalarMinMax gMinMaxMag(const FieldField< Field, Type > &f)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Type gMaxMagSqr(const UList< Type > &f, const label comm)
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh > > cmptAv(const DimensionedField< Type, GeoMesh > &f1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
outerProduct1< Type >::type sumSqr(const UList< Type > &f1)
complex sumProd(const UList< complex > &f1, const UList< complex > &f2)
Sum product.
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
void cmptMagSqr(Field< Type > &result, const UList< Type > &f1)
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1, const label comm)
static constexpr const zero Zero
Global zero (0).
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
typeOfMag< Type >::type gSumMag(const FieldField< Field, Type > &f)
void dotdot(FieldField< Field1, typename scalarProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void sumReduce(T &value, CountType &count, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) the sum of value and counter (eg, for averaging).
Type gMin(const FieldField< Field, Type > &f)
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
outerProduct1< Type >::type gSumSqr(const UList< Type > &f, const label comm)
void negate(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1)
Type gMinMagSqr(const UList< Type > &f, const label comm)
Type maxMagSqr(const UList< Type > &f1)
void multiply(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &f1, const label comm)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Type gSumCmptMag(const UList< Type > &f, const label comm)
Type gMax(const FieldField< Field, Type > &f)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
void outer(FieldField< Field1, typename outerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
Type gSumCmptProd(const UList< Type > &f1, const UList< Type > &f2, const label comm)
dimensioned< typename typeOfMag< Type >::type > sumMag(const DimensionedField< Type, GeoMesh > &f1, const label comm)
Unary function for applying component-wise clamping.
static tmp< Field< TypeR > > New(const Field< Type1 > &f1)
Pass-through to tmp New.