ENH: support non-worldComm for Dimensioned/Geometric field functions

This commit is contained in:
Mark Olesen 2025-02-17 15:29:29 +01:00
parent 0aecb25024
commit e8e90a8de3
6 changed files with 43 additions and 26 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2023 OpenCFD Ltd.
Copyright (C) 2019-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -275,24 +275,26 @@ cmptAv(const tmp<DimensionedField<Type, GeoMesh>>& tf1)
template<class Type, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
const DimensionedField<Type, GeoMesh>& f1 \
const DimensionedField<Type, GeoMesh>& f1, \
const label comm \
) \
{ \
return dimensioned<ReturnType> \
( \
#Func "(" + f1.name() + ')', \
f1.dimensions(), \
gFunc(f1.field()) \
gFunc(f1.field(), comm) \
); \
} \
\
template<class Type, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
const tmp<DimensionedField<Type, GeoMesh>>& tf1 \
const tmp<DimensionedField<Type, GeoMesh>>& tf1, \
const label comm \
) \
{ \
dimensioned<ReturnType> res = Func(tf1()); \
dimensioned<ReturnType> res = Func(tf1(), comm); \
tf1.clear(); \
return res; \
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2023 OpenCFD Ltd.
Copyright (C) 2019-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -107,12 +107,14 @@ cmptAv(const tmp<DimensionedField<Type, GeoMesh>>& tf1);
template<class Type, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
const DimensionedField<Type, GeoMesh>& f1 \
const DimensionedField<Type, GeoMesh>& f1, \
const label comm = UPstream::worldComm \
); \
template<class Type, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
const tmp<DimensionedField<Type, GeoMesh>>& tf1 \
const tmp<DimensionedField<Type, GeoMesh>>& tf1, \
const label comm = UPstream::worldComm \
);
UNARY_REDUCTION_FUNCTION(Type, max, gMax)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2024 OpenCFD Ltd.
Copyright (C) 2015-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -1132,10 +1132,11 @@ Foam::word Foam::GeometricField<Type, PatchField, GeoMesh>::select
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::writeMinMax
(
Ostream& os
Ostream& os,
label comm
) const
{
MinMax<Type> range = Foam::minMax(*this).value();
MinMax<Type> range = Foam::minMax(*this, comm).value();
os << "min/max(" << this->name() << ") = "
<< range.min() << ", " << range.max() << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2024 OpenCFD Ltd.
Copyright (C) 2015-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -906,8 +906,9 @@ public:
//- otherwise the standard parameters by returning the field name
word select(bool final) const;
//- Helper function to write the min and max to an Ostream
void writeMinMax(Ostream& os) const;
//- Helper function to write the min and max to an Ostream.
// Uses the specified communicator for reductions
void writeMinMax(Ostream& os, label comm = UPstream::worldComm) const;
// Member Function *this Operators

View File

@ -429,7 +429,8 @@ cmptAv(const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1)
template<class Type, template<class> class PatchField, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
const GeometricField<Type, PatchField, GeoMesh>& f1 \
const GeometricField<Type, PatchField, GeoMesh>& f1, \
const label comm \
) \
{ \
return dimensioned<ReturnType> \
@ -443,7 +444,9 @@ dimensioned<ReturnType> Func \
Foam::Func(f1.primitiveField()), \
Foam::Func(f1.boundaryField()) \
), \
BinaryOp<ReturnType>() \
BinaryOp<ReturnType>(), \
UPstream::msgType(), \
comm \
) \
); \
} \
@ -451,14 +454,16 @@ dimensioned<ReturnType> Func \
template<class Type, template<class> class PatchField, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1 \
const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1, \
const label comm \
) \
{ \
dimensioned<ReturnType> res = Func(tf1()); \
dimensioned<ReturnType> res = Func(tf1(), comm); \
tf1.clear(); \
return res; \
}
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, max, maxOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, min, minOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(MinMax<Type>, minMax, plusOp)
@ -473,19 +478,21 @@ UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(scalarMinMax, minMaxMag, plusOp)
template<class Type, template<class> class PatchField, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
const GeometricField<Type, PatchField, GeoMesh>& f1 \
const GeometricField<Type, PatchField, GeoMesh>& f1, \
const label comm \
) \
{ \
return Func(f1.internalField()); \
return Func(f1.internalField(), comm); \
} \
\
template<class Type, template<class> class PatchField, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1 \
const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1, \
const label comm \
) \
{ \
auto result = Func(tf1()); \
auto result = Func(tf1(), comm); \
tf1.clear(); \
return result; \
}

View File

@ -225,13 +225,15 @@ cmptAv(const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1);
template<class Type, template<class> class PatchField, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
const GeometricField<Type, PatchField, GeoMesh>& f1 \
const GeometricField<Type, PatchField, GeoMesh>& f1, \
const label comm = UPstream::worldComm \
); \
\
template<class Type, template<class> class PatchField, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1 \
const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1, \
const label comm = UPstream::worldComm \
);
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, max, maxOp)
@ -248,13 +250,15 @@ UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(scalarMinMax, minMaxMag, plusOp)
template<class Type, template<class> class PatchField, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
const GeometricField<Type, PatchField, GeoMesh>& f1 \
const GeometricField<Type, PatchField, GeoMesh>& f1, \
const label comm = UPstream::worldComm \
); \
\
template<class Type, template<class> class PatchField, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1 \
const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1, \
const label comm = UPstream::worldComm \
);
UNARY_REDUCTION_FUNCTION(Type, sum)