mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: missing unit-normal weighting for surfaceFieldValue (fixes #2273)
- when using a vector field for weighting, it either used mag() or mag * area, but did not have a unit-normal projection version
This commit is contained in:
@ -114,7 +114,7 @@ bool Foam::functionObjects::fieldValue::execute()
|
|||||||
|
|
||||||
bool Foam::functionObjects::fieldValue::write()
|
bool Foam::functionObjects::fieldValue::write()
|
||||||
{
|
{
|
||||||
Log << type() << " " << name() << " write:" << nl;
|
Log << type() << ' ' << name() << " write:" << nl;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -186,16 +186,16 @@ public:
|
|||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Return the reference to the construction dictionary
|
//- Return the reference to the construction dictionary
|
||||||
inline const dictionary& dict() const;
|
inline const dictionary& dict() const noexcept;
|
||||||
|
|
||||||
//- Return the region name
|
//- Return the region name
|
||||||
inline const word& regionName() const;
|
inline const word& regionName() const noexcept;
|
||||||
|
|
||||||
//- Return the list of field names
|
//- Return the list of field names
|
||||||
inline const wordList& fields() const;
|
inline const wordList& fields() const noexcept;
|
||||||
|
|
||||||
//- Return the output field values flag
|
//- Return the output field values flag
|
||||||
inline bool writeFields() const;
|
inline bool writeFields() const noexcept;
|
||||||
|
|
||||||
//- Read from dictionary
|
//- Read from dictionary
|
||||||
virtual bool read(const dictionary& dict);
|
virtual bool read(const dictionary& dict);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2020 OpenCFD Ltd.
|
Copyright (C) 2020-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -28,25 +28,28 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline const Foam::dictionary& Foam::functionObjects::fieldValue::dict() const
|
inline const Foam::dictionary& Foam::functionObjects::fieldValue::dict()
|
||||||
|
const noexcept
|
||||||
{
|
{
|
||||||
return dict_;
|
return dict_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::word& Foam::functionObjects::fieldValue::regionName() const
|
inline const Foam::word& Foam::functionObjects::fieldValue::regionName()
|
||||||
|
const noexcept
|
||||||
{
|
{
|
||||||
return regionName_;
|
return regionName_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::wordList& Foam::functionObjects::fieldValue::fields() const
|
inline const Foam::wordList& Foam::functionObjects::fieldValue::fields()
|
||||||
|
const noexcept
|
||||||
{
|
{
|
||||||
return fields_;
|
return fields_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::functionObjects::fieldValue::writeFields() const
|
inline bool Foam::functionObjects::fieldValue::writeFields() const noexcept
|
||||||
{
|
{
|
||||||
return writeFields_;
|
return writeFields_;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -543,9 +543,10 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::totalArea() const
|
|||||||
|
|
||||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::functionObjects::fieldValues::surfaceFieldValue::usesSf() const
|
bool Foam::functionObjects::fieldValues::surfaceFieldValue::usesSf()
|
||||||
|
const noexcept
|
||||||
{
|
{
|
||||||
// Only a few operations do not require the Sf field
|
// Few operations do not require the Sf field
|
||||||
switch (operation_)
|
switch (operation_)
|
||||||
{
|
{
|
||||||
case opNone:
|
case opNone:
|
||||||
@ -554,13 +555,10 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::usesSf() const
|
|||||||
case opSum:
|
case opSum:
|
||||||
case opSumMag:
|
case opSumMag:
|
||||||
case opAverage:
|
case opAverage:
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -703,11 +701,14 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::processValues
|
|||||||
|
|
||||||
scalar mean, numer;
|
scalar mean, numer;
|
||||||
|
|
||||||
if (canWeight(weightField))
|
if (is_weightedOp() && canWeight(weightField))
|
||||||
{
|
{
|
||||||
// Weighted quantity = (Weight * phi * dA)
|
// Weighted quantity = (Weight * phi * dA)
|
||||||
|
|
||||||
tmp<scalarField> weight(weightingFactor(weightField));
|
tmp<scalarField> weight
|
||||||
|
(
|
||||||
|
weightingFactor(weightField, is_magOp())
|
||||||
|
);
|
||||||
|
|
||||||
// Mean weighted value (area-averaged)
|
// Mean weighted value (area-averaged)
|
||||||
mean = gSum(weight()*areaVal()) / areaTotal;
|
mean = gSum(weight()*areaVal()) / areaTotal;
|
||||||
@ -786,11 +787,14 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::processValues
|
|||||||
|
|
||||||
scalar mean, numer;
|
scalar mean, numer;
|
||||||
|
|
||||||
if (canWeight(weightField))
|
if (is_weightedOp() && canWeight(weightField))
|
||||||
{
|
{
|
||||||
// Weighted quantity = (Weight * phi . dA)
|
// Weighted quantity = (Weight * phi . dA)
|
||||||
|
|
||||||
tmp<scalarField> weight(weightingFactor(weightField));
|
tmp<scalarField> weight
|
||||||
|
(
|
||||||
|
weightingFactor(weightField, is_magOp())
|
||||||
|
);
|
||||||
|
|
||||||
// Mean weighted value (area-averaged)
|
// Mean weighted value (area-averaged)
|
||||||
mean = gSum(weight()*areaVal()) / areaTotal;
|
mean = gSum(weight()*areaVal()) / areaTotal;
|
||||||
@ -824,14 +828,17 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::processValues
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
Foam::tmp<Foam::scalarField>
|
Foam::tmp<Foam::scalarField>
|
||||||
Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
|
Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
|
||||||
(
|
(
|
||||||
const Field<scalar>& weightField
|
const Field<scalar>& weightField,
|
||||||
) const
|
const bool useMag
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (usesMag())
|
if (useMag)
|
||||||
{
|
{
|
||||||
return mag(weightField);
|
return mag(weightField);
|
||||||
}
|
}
|
||||||
@ -846,17 +853,48 @@ Foam::tmp<Foam::scalarField>
|
|||||||
Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
|
Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
|
||||||
(
|
(
|
||||||
const Field<scalar>& weightField,
|
const Field<scalar>& weightField,
|
||||||
const vectorField& Sf
|
const vectorField& Sf,
|
||||||
) const
|
const bool useMag
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// scalar * unit-normal
|
||||||
|
|
||||||
|
// Can skip this check - already used canWeight()
|
||||||
|
/// if (returnReduce(weightField.empty(), andOp<bool>()))
|
||||||
|
/// {
|
||||||
|
/// // No weight field - revert to unweighted form?
|
||||||
|
/// return tmp<scalarField>::New(Sf.size(), scalar(1));
|
||||||
|
/// }
|
||||||
|
|
||||||
|
if (useMag)
|
||||||
|
{
|
||||||
|
return mag(weightField);
|
||||||
|
}
|
||||||
|
|
||||||
|
// pass through
|
||||||
|
return weightField;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
|
Foam::tmp<Foam::scalarField>
|
||||||
|
Foam::functionObjects::fieldValues::surfaceFieldValue::areaWeightingFactor
|
||||||
|
(
|
||||||
|
const Field<scalar>& weightField,
|
||||||
|
const vectorField& Sf,
|
||||||
|
const bool useMag
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// scalar * Area
|
// scalar * Area
|
||||||
|
|
||||||
if (returnReduce(weightField.empty(), andOp<bool>()))
|
// Can skip this check - already used canWeight()
|
||||||
{
|
/// if (returnReduce(weightField.empty(), andOp<bool>()))
|
||||||
// No weight field - revert to unweighted form
|
/// {
|
||||||
return mag(Sf);
|
/// // No weight field - revert to unweighted form
|
||||||
}
|
/// return mag(Sf);
|
||||||
else if (usesMag())
|
/// }
|
||||||
|
|
||||||
|
if (useMag)
|
||||||
{
|
{
|
||||||
return mag(weightField * mag(Sf));
|
return mag(weightField * mag(Sf));
|
||||||
}
|
}
|
||||||
@ -870,17 +908,61 @@ Foam::tmp<Foam::scalarField>
|
|||||||
Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
|
Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
|
||||||
(
|
(
|
||||||
const Field<vector>& weightField,
|
const Field<vector>& weightField,
|
||||||
const vectorField& Sf
|
const vectorField& Sf,
|
||||||
) const
|
const bool useMag
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// vector (dot) unit-normal
|
||||||
|
|
||||||
|
// Can skip this check - already used canWeight()
|
||||||
|
/// if (returnReduce(weightField.empty(), andOp<bool>()))
|
||||||
|
/// {
|
||||||
|
/// // No weight field - revert to unweighted form
|
||||||
|
/// return tmp<scalarField>::New(Sf.size(), scalar(1));
|
||||||
|
/// }
|
||||||
|
|
||||||
|
const label len = weightField.size();
|
||||||
|
|
||||||
|
auto tresult = tmp<scalarField>::New(weightField.size());
|
||||||
|
auto& result = tresult.ref();
|
||||||
|
|
||||||
|
for (label facei=0; facei < len; ++facei)
|
||||||
|
{
|
||||||
|
const vector unitNormal(normalised(Sf[facei]));
|
||||||
|
result[facei] = (weightField[facei] & unitNormal);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useMag)
|
||||||
|
{
|
||||||
|
for (scalar& val : result)
|
||||||
|
{
|
||||||
|
val = mag(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tresult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
|
Foam::tmp<Foam::scalarField>
|
||||||
|
Foam::functionObjects::fieldValues::surfaceFieldValue::areaWeightingFactor
|
||||||
|
(
|
||||||
|
const Field<vector>& weightField,
|
||||||
|
const vectorField& Sf,
|
||||||
|
const bool useMag
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// vector (dot) Area
|
// vector (dot) Area
|
||||||
|
|
||||||
if (returnReduce(weightField.empty(), andOp<bool>()))
|
// Can skip this check - already used canWeight()
|
||||||
{
|
/// if (returnReduce(weightField.empty(), andOp<bool>()))
|
||||||
// No weight field - revert to unweighted form
|
/// {
|
||||||
return mag(Sf);
|
/// // No weight field - revert to unweighted form
|
||||||
}
|
/// return mag(Sf);
|
||||||
else if (usesMag())
|
/// }
|
||||||
|
|
||||||
|
if (useMag)
|
||||||
{
|
{
|
||||||
return mag(weightField & Sf);
|
return mag(weightField & Sf);
|
||||||
}
|
}
|
||||||
@ -959,6 +1041,13 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::surfaceFieldValue
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
// Needs completed sampledSurface, surfaceWriter
|
||||||
|
Foam::functionObjects::fieldValues::surfaceFieldValue::~surfaceFieldValue()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::functionObjects::fieldValues::surfaceFieldValue::read
|
bool Foam::functionObjects::fieldValues::surfaceFieldValue::read
|
||||||
@ -1048,7 +1137,7 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::read
|
|||||||
Info<< operationTypeNames_[operation_] << nl;
|
Info<< operationTypeNames_[operation_] << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usesWeight())
|
if (is_weightedOp())
|
||||||
{
|
{
|
||||||
// Can have "weightFields" or "weightField"
|
// Can have "weightFields" or "weightField"
|
||||||
|
|
||||||
|
|||||||
@ -435,6 +435,40 @@ protected:
|
|||||||
autoPtr<surfaceWriter> surfaceWriterPtr_;
|
autoPtr<surfaceWriter> surfaceWriterPtr_;
|
||||||
|
|
||||||
|
|
||||||
|
// Static Member Functions
|
||||||
|
|
||||||
|
//- Weighting factor.
|
||||||
|
// Possibly applies mag() depending on the operation type.
|
||||||
|
template<class WeightType>
|
||||||
|
static tmp<scalarField> weightingFactor
|
||||||
|
(
|
||||||
|
const Field<WeightType>& weightField,
|
||||||
|
const bool useMag
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Weighting factor, weight field projected onto unit-normal.
|
||||||
|
// Possibly applies mag() depending on the operation type.
|
||||||
|
// Reverts to 'one' if the weight field is unavailable.
|
||||||
|
template<class WeightType>
|
||||||
|
static tmp<scalarField> weightingFactor
|
||||||
|
(
|
||||||
|
const Field<WeightType>& weightField,
|
||||||
|
const vectorField& Sf,
|
||||||
|
const bool useMag
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Weighting factor, weight field with area factor.
|
||||||
|
// Possibly applies mag() depending on the operation type.
|
||||||
|
// Reverts to mag(Sf) if the weight field is unavailable.
|
||||||
|
template<class WeightType>
|
||||||
|
static tmp<scalarField> areaWeightingFactor
|
||||||
|
(
|
||||||
|
const Field<WeightType>& weightField,
|
||||||
|
const vectorField& Sf,
|
||||||
|
const bool useMag
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// Protected Member Functions
|
// Protected Member Functions
|
||||||
|
|
||||||
//- The volume mesh or surface registry being used
|
//- The volume mesh or surface registry being used
|
||||||
@ -444,30 +478,29 @@ protected:
|
|||||||
inline bool withSurfaceFields() const;
|
inline bool withSurfaceFields() const;
|
||||||
|
|
||||||
//- Can use mesh topological merge?
|
//- Can use mesh topological merge?
|
||||||
inline bool withTopologicalMerge() const;
|
inline bool withTopologicalMerge() const noexcept;
|
||||||
|
|
||||||
//- Return the local list of face IDs
|
//- Return the local list of face IDs
|
||||||
inline const labelList& faceId() const;
|
inline const labelList& faceId() const noexcept;
|
||||||
|
|
||||||
//- Return the local list of patch ID per face
|
//- Return the local list of patch ID per face
|
||||||
inline const labelList& facePatch() const;
|
inline const labelList& facePatch() const noexcept;
|
||||||
|
|
||||||
//- Return the local true/false list representing the face flip map
|
//- Return the local true/false list representing the face flip map
|
||||||
inline const boolList& faceFlip() const;
|
inline const boolList& faceFlip() const noexcept;
|
||||||
|
|
||||||
//- True if the operation needs a surface Sf
|
//- True if the operation needs a surface Sf
|
||||||
bool usesSf() const;
|
bool usesSf() const noexcept;
|
||||||
|
|
||||||
//- True if the operation variant uses mag
|
//- True if the operation variant uses mag
|
||||||
inline bool usesMag() const;
|
inline bool is_magOp() const noexcept;
|
||||||
|
|
||||||
//- True if the operation variant uses a weight-field
|
//- True if the operation variant uses a weight-field
|
||||||
inline bool usesWeight() const;
|
inline bool is_weightedOp() const noexcept;
|
||||||
|
|
||||||
//- True if operation variant uses a weight-field that is available.
|
//- True if field is non-empty on any processor.
|
||||||
// Checks for availability on any processor.
|
|
||||||
template<class WeightType>
|
template<class WeightType>
|
||||||
inline bool canWeight(const Field<WeightType>& weightField) const;
|
inline bool canWeight(const Field<WeightType>& fld) const;
|
||||||
|
|
||||||
//- Update the surface and surface information as required.
|
//- Update the surface and surface information as required.
|
||||||
// Do nothing (and return false) if no update was required
|
// Do nothing (and return false) if no update was required
|
||||||
@ -519,26 +552,6 @@ protected:
|
|||||||
const GeometricField<Type, fvPatchField, volMesh>& field
|
const GeometricField<Type, fvPatchField, volMesh>& field
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
|
||||||
//- Weighting factor.
|
|
||||||
// Possibly applies mag() depending on the operation type.
|
|
||||||
template<class WeightType>
|
|
||||||
tmp<scalarField> weightingFactor
|
|
||||||
(
|
|
||||||
const Field<WeightType>& weightField
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Weighting factor, weight field with the area.
|
|
||||||
// Possibly applies mag() depending on the operation type.
|
|
||||||
// Reverts to mag(Sf) if the weight field is not available.
|
|
||||||
template<class WeightType>
|
|
||||||
tmp<scalarField> weightingFactor
|
|
||||||
(
|
|
||||||
const Field<WeightType>& weightField,
|
|
||||||
const vectorField& Sf
|
|
||||||
) const;
|
|
||||||
|
|
||||||
|
|
||||||
//- Templated helper function to output field values
|
//- Templated helper function to output field values
|
||||||
template<class WeightType>
|
template<class WeightType>
|
||||||
label writeAll
|
label writeAll
|
||||||
@ -597,13 +610,13 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~surfaceFieldValue() = default;
|
virtual ~surfaceFieldValue();
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Return the region type
|
//- Return the region type
|
||||||
inline regionTypes regionType() const;
|
inline regionTypes regionType() const noexcept;
|
||||||
|
|
||||||
//- Return the output directory
|
//- Return the output directory
|
||||||
inline fileName outputDir() const;
|
inline fileName outputDir() const;
|
||||||
@ -646,26 +659,46 @@ vector surfaceFieldValue::processValues
|
|||||||
template<>
|
template<>
|
||||||
tmp<scalarField> surfaceFieldValue::weightingFactor
|
tmp<scalarField> surfaceFieldValue::weightingFactor
|
||||||
(
|
(
|
||||||
const Field<scalar>& weightField
|
const Field<scalar>& weightField,
|
||||||
) const;
|
const bool useMag
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Specialisation for scalar - pass through
|
||||||
//- Specialisation for scalar - scalar * Area
|
|
||||||
template<>
|
template<>
|
||||||
tmp<scalarField> surfaceFieldValue::weightingFactor
|
tmp<scalarField> surfaceFieldValue::weightingFactor
|
||||||
(
|
(
|
||||||
const Field<scalar>& weightField,
|
const Field<scalar>& weightField,
|
||||||
const vectorField& Sf
|
const vectorField& Sf /* unused */,
|
||||||
) const;
|
const bool useMag
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Specialisation for scalar - scalar * Area
|
||||||
|
template<>
|
||||||
|
tmp<scalarField> surfaceFieldValue::areaWeightingFactor
|
||||||
|
(
|
||||||
|
const Field<scalar>& weightField,
|
||||||
|
const vectorField& Sf,
|
||||||
|
const bool useMag
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
//- Specialisation for vector - vector (dot) Area
|
//- Specialisation for vector - vector (dot) unit-normal
|
||||||
template<>
|
template<>
|
||||||
tmp<scalarField> surfaceFieldValue::weightingFactor
|
tmp<scalarField> surfaceFieldValue::weightingFactor
|
||||||
(
|
(
|
||||||
const Field<vector>& weightField,
|
const Field<vector>& weightField,
|
||||||
const vectorField& Sf
|
const vectorField& Sf,
|
||||||
) const;
|
const bool useMag
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Specialisation for vector - vector (dot) Area
|
||||||
|
template<>
|
||||||
|
tmp<scalarField> surfaceFieldValue::areaWeightingFactor
|
||||||
|
(
|
||||||
|
const Field<vector>& weightField,
|
||||||
|
const vectorField& Sf,
|
||||||
|
const bool useMag
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -44,28 +44,31 @@ withSurfaceFields() const
|
|||||||
|
|
||||||
|
|
||||||
inline bool Foam::functionObjects::fieldValues::surfaceFieldValue::
|
inline bool Foam::functionObjects::fieldValues::surfaceFieldValue::
|
||||||
withTopologicalMerge() const
|
withTopologicalMerge() const noexcept
|
||||||
{
|
{
|
||||||
return (stFaceZone == regionType_ || stPatch == regionType_);
|
return (stFaceZone == regionType_ || stPatch == regionType_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::labelList&
|
inline const Foam::labelList&
|
||||||
Foam::functionObjects::fieldValues::surfaceFieldValue::faceId() const
|
Foam::functionObjects::fieldValues::surfaceFieldValue::faceId()
|
||||||
|
const noexcept
|
||||||
{
|
{
|
||||||
return faceId_;
|
return faceId_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::labelList&
|
inline const Foam::labelList&
|
||||||
Foam::functionObjects::fieldValues::surfaceFieldValue::facePatch() const
|
Foam::functionObjects::fieldValues::surfaceFieldValue::facePatch()
|
||||||
|
const noexcept
|
||||||
{
|
{
|
||||||
return facePatchId_;
|
return facePatchId_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::boolList&
|
inline const Foam::boolList&
|
||||||
Foam::functionObjects::fieldValues::surfaceFieldValue::faceFlip() const
|
Foam::functionObjects::fieldValues::surfaceFieldValue::faceFlip()
|
||||||
|
const noexcept
|
||||||
{
|
{
|
||||||
return faceFlip_;
|
return faceFlip_;
|
||||||
}
|
}
|
||||||
@ -73,16 +76,17 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::faceFlip() const
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline bool
|
inline bool Foam::functionObjects::fieldValues::surfaceFieldValue::
|
||||||
Foam::functionObjects::fieldValues::surfaceFieldValue::usesMag() const
|
is_magOp()
|
||||||
|
const noexcept
|
||||||
{
|
{
|
||||||
// Operation specifically tagged to use mag
|
// Operation specifically tagged to use mag
|
||||||
return (operation_ & typeAbsolute);
|
return (operation_ & typeAbsolute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool
|
inline bool Foam::functionObjects::fieldValues::surfaceFieldValue::
|
||||||
Foam::functionObjects::fieldValues::surfaceFieldValue::usesWeight() const
|
is_weightedOp() const noexcept
|
||||||
{
|
{
|
||||||
// Operation specifically tagged to require a weight field
|
// Operation specifically tagged to require a weight field
|
||||||
return (operation_ & typeWeighted);
|
return (operation_ & typeWeighted);
|
||||||
@ -90,7 +94,8 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::usesWeight() const
|
|||||||
|
|
||||||
|
|
||||||
inline Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes
|
inline Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes
|
||||||
Foam::functionObjects::fieldValues::surfaceFieldValue::regionType() const
|
Foam::functionObjects::fieldValues::surfaceFieldValue::regionType()
|
||||||
|
const noexcept
|
||||||
{
|
{
|
||||||
return regionType_;
|
return regionType_;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,19 +35,32 @@ License
|
|||||||
#include "interpolationCell.H"
|
#include "interpolationCell.H"
|
||||||
#include "interpolationCellPoint.H"
|
#include "interpolationCellPoint.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class WeightType>
|
||||||
|
Foam::tmp<Foam::scalarField>
|
||||||
|
Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
|
||||||
|
(
|
||||||
|
const Field<WeightType>& weightField,
|
||||||
|
const bool useMag /* ignore */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// The scalar form is specialized.
|
||||||
|
// Other types: use mag() to generate a scalar field.
|
||||||
|
return mag(weightField);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class WeightType>
|
template<class WeightType>
|
||||||
inline bool Foam::functionObjects::fieldValues::surfaceFieldValue::canWeight
|
inline bool Foam::functionObjects::fieldValues::surfaceFieldValue::canWeight
|
||||||
(
|
(
|
||||||
const Field<WeightType>& weightField
|
const Field<WeightType>& fld
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return
|
// Non-empty on some processor
|
||||||
(
|
return returnReduce(!fld.empty(), orOp<bool>());
|
||||||
usesWeight()
|
|
||||||
&& returnReduce(!weightField.empty(), orOp<bool>()) // On some processor
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -156,9 +169,13 @@ processSameTypeValues
|
|||||||
case opWeightedSum:
|
case opWeightedSum:
|
||||||
case opAbsWeightedSum:
|
case opAbsWeightedSum:
|
||||||
{
|
{
|
||||||
if (canWeight(weightField))
|
if (is_weightedOp() && canWeight(weightField))
|
||||||
{
|
{
|
||||||
tmp<scalarField> weight(weightingFactor(weightField));
|
tmp<scalarField> weight
|
||||||
|
(
|
||||||
|
weightingFactor(weightField, Sf, is_magOp())
|
||||||
|
);
|
||||||
|
|
||||||
result = gSum(weight*values);
|
result = gSum(weight*values);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -183,9 +200,12 @@ processSameTypeValues
|
|||||||
case opWeightedAverage:
|
case opWeightedAverage:
|
||||||
case opAbsWeightedAverage:
|
case opAbsWeightedAverage:
|
||||||
{
|
{
|
||||||
if (canWeight(weightField))
|
if (is_weightedOp() && canWeight(weightField))
|
||||||
{
|
{
|
||||||
const scalarField factor(weightingFactor(weightField));
|
const scalarField factor
|
||||||
|
(
|
||||||
|
weightingFactor(weightField, Sf, is_magOp())
|
||||||
|
);
|
||||||
|
|
||||||
result = gSum(factor*values)/(gSum(factor) + ROOTVSMALL);
|
result = gSum(factor*values)/(gSum(factor) + ROOTVSMALL);
|
||||||
}
|
}
|
||||||
@ -193,6 +213,7 @@ processSameTypeValues
|
|||||||
{
|
{
|
||||||
// Unweighted form
|
// Unweighted form
|
||||||
const label n = returnReduce(values.size(), sumOp<label>());
|
const label n = returnReduce(values.size(), sumOp<label>());
|
||||||
|
|
||||||
result = gSum(values)/(scalar(n) + ROOTVSMALL);
|
result = gSum(values)/(scalar(n) + ROOTVSMALL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -201,9 +222,12 @@ processSameTypeValues
|
|||||||
case opWeightedAreaAverage:
|
case opWeightedAreaAverage:
|
||||||
case opAbsWeightedAreaAverage:
|
case opAbsWeightedAreaAverage:
|
||||||
{
|
{
|
||||||
if (canWeight(weightField))
|
if (is_weightedOp() && canWeight(weightField))
|
||||||
{
|
{
|
||||||
const scalarField factor(weightingFactor(weightField, Sf));
|
const scalarField factor
|
||||||
|
(
|
||||||
|
areaWeightingFactor(weightField, Sf, is_magOp())
|
||||||
|
);
|
||||||
|
|
||||||
result = gSum(factor*values)/gSum(factor + ROOTVSMALL);
|
result = gSum(factor*values)/gSum(factor + ROOTVSMALL);
|
||||||
}
|
}
|
||||||
@ -211,7 +235,8 @@ processSameTypeValues
|
|||||||
{
|
{
|
||||||
// Unweighted form
|
// Unweighted form
|
||||||
const scalarField factor(mag(Sf));
|
const scalarField factor(mag(Sf));
|
||||||
result = gSum(factor*values)/gSum(factor);
|
|
||||||
|
result = gSum(factor*values)/gSum(factor + ROOTVSMALL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -219,15 +244,20 @@ processSameTypeValues
|
|||||||
case opWeightedAreaIntegrate:
|
case opWeightedAreaIntegrate:
|
||||||
case opAbsWeightedAreaIntegrate:
|
case opAbsWeightedAreaIntegrate:
|
||||||
{
|
{
|
||||||
if (canWeight(weightField))
|
if (is_weightedOp() && canWeight(weightField))
|
||||||
{
|
{
|
||||||
tmp<scalarField> factor(weightingFactor(weightField, Sf));
|
tmp<scalarField> factor
|
||||||
|
(
|
||||||
|
areaWeightingFactor(weightField, Sf, is_magOp())
|
||||||
|
);
|
||||||
|
|
||||||
result = gSum(factor*values);
|
result = gSum(factor*values);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Unweighted form
|
// Unweighted form
|
||||||
tmp<scalarField> factor(mag(Sf));
|
tmp<scalarField> factor(mag(Sf));
|
||||||
|
|
||||||
result = gSum(factor*values);
|
result = gSum(factor*values);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -264,14 +294,14 @@ processSameTypeValues
|
|||||||
case opWeightedUniformity:
|
case opWeightedUniformity:
|
||||||
case opAbsWeightedUniformity:
|
case opAbsWeightedUniformity:
|
||||||
{
|
{
|
||||||
if (canWeight(weightField))
|
if (is_weightedOp() && canWeight(weightField))
|
||||||
{
|
{
|
||||||
// Change weighting from vector -> scalar and dispatch again
|
// Change weighting from vector -> scalar and dispatch again
|
||||||
return processValues<Type, scalar>
|
return processValues<Type, scalar>
|
||||||
(
|
(
|
||||||
values,
|
values,
|
||||||
Sf,
|
Sf,
|
||||||
weightingFactor(weightField)
|
weightingFactor(weightField, is_magOp())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,19 +325,6 @@ Type Foam::functionObjects::fieldValues::surfaceFieldValue::processValues
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class WeightType>
|
|
||||||
Foam::tmp<Foam::scalarField>
|
|
||||||
Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
|
|
||||||
(
|
|
||||||
const Field<WeightType>& weightField
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
// The scalar form is specialized.
|
|
||||||
// For other types always need mag() to generate a scalar field.
|
|
||||||
return mag(weightField);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class WeightType>
|
template<class WeightType>
|
||||||
Foam::label Foam::functionObjects::fieldValues::surfaceFieldValue::writeAll
|
Foam::label Foam::functionObjects::fieldValues::surfaceFieldValue::writeAll
|
||||||
(
|
(
|
||||||
|
|||||||
@ -84,9 +84,10 @@ Foam::functionObjects::fieldValues::volFieldValue::postOperationTypeNames_
|
|||||||
|
|
||||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::functionObjects::fieldValues::volFieldValue::usesVol() const
|
bool Foam::functionObjects::fieldValues::volFieldValue::usesVol()
|
||||||
|
const noexcept
|
||||||
{
|
{
|
||||||
// Only a few operations require the cell volume
|
// Few operations require the cell volume
|
||||||
switch (operation_)
|
switch (operation_)
|
||||||
{
|
{
|
||||||
case opVolAverage:
|
case opVolAverage:
|
||||||
@ -102,33 +103,6 @@ bool Foam::functionObjects::fieldValues::volFieldValue::usesVol() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::functionObjects::fieldValues::volFieldValue::usesMag() const
|
|
||||||
{
|
|
||||||
// Operation specifically tagged to use mag
|
|
||||||
return (operation_ & typeAbsolute);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Foam::functionObjects::fieldValues::volFieldValue::usesWeight() const
|
|
||||||
{
|
|
||||||
// Operation specifically tagged to require a weight field
|
|
||||||
return (operation_ & typeWeighted);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Foam::functionObjects::fieldValues::volFieldValue::canWeight
|
|
||||||
(
|
|
||||||
const scalarField& weightField
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
return
|
|
||||||
(
|
|
||||||
usesWeight()
|
|
||||||
&& returnReduce(!weightField.empty(), orOp<bool>()) // On some processor
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Foam::functionObjects::fieldValues::volFieldValue::writeFileHeader
|
void Foam::functionObjects::fieldValues::volFieldValue::writeFileHeader
|
||||||
(
|
(
|
||||||
Ostream& os
|
Ostream& os
|
||||||
@ -260,7 +234,7 @@ bool Foam::functionObjects::fieldValues::volFieldValue::read
|
|||||||
|
|
||||||
weightFieldNames_.clear();
|
weightFieldNames_.clear();
|
||||||
|
|
||||||
if (usesWeight())
|
if (is_weightedOp())
|
||||||
{
|
{
|
||||||
// Can have "weightFields" or "weightField"
|
// Can have "weightFields" or "weightField"
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -222,17 +222,16 @@ protected:
|
|||||||
// Protected Member Functions
|
// Protected Member Functions
|
||||||
|
|
||||||
//- True if the operation needs the cell-volume
|
//- True if the operation needs the cell-volume
|
||||||
bool usesVol() const;
|
bool usesVol() const noexcept;
|
||||||
|
|
||||||
//- True if the operation variant uses mag
|
//- True if the operation variant uses mag
|
||||||
bool usesMag() const;
|
inline bool is_magOp() const noexcept;
|
||||||
|
|
||||||
//- True if the operation variant uses a weight-field
|
//- True if the operation variant uses a weight-field
|
||||||
bool usesWeight() const;
|
inline bool is_weightedOp() const noexcept;
|
||||||
|
|
||||||
//- True if operation variant uses a weight-field that is available.
|
//- True if field is non-empty on any processor.
|
||||||
// Checks for availability on any processor.
|
inline bool canWeight(const scalarField& fld) const;
|
||||||
inline bool canWeight(const scalarField& weightField) const;
|
|
||||||
|
|
||||||
//- Return true if the field name is valid
|
//- Return true if the field name is valid
|
||||||
template<class Type>
|
template<class Type>
|
||||||
@ -332,6 +331,10 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#include "volFieldValueI.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#ifdef NoRepository
|
#ifdef NoRepository
|
||||||
#include "volFieldValueTemplates.C"
|
#include "volFieldValueTemplates.C"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -0,0 +1,56 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2021 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline bool Foam::functionObjects::fieldValues::volFieldValue::is_magOp()
|
||||||
|
const noexcept
|
||||||
|
{
|
||||||
|
// Operation tagged to use mag
|
||||||
|
return (operation_ & typeAbsolute);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::functionObjects::fieldValues::volFieldValue::is_weightedOp()
|
||||||
|
const noexcept
|
||||||
|
{
|
||||||
|
// Operation tagged to require a weight field
|
||||||
|
return (operation_ & typeWeighted);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::functionObjects::fieldValues::volFieldValue::canWeight
|
||||||
|
(
|
||||||
|
const scalarField& fld
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
// Non-empty on some processor
|
||||||
|
return returnReduce(!fld.empty(), orOp<bool>());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -112,7 +112,7 @@ Type Foam::functionObjects::fieldValues::volFieldValue::processValues
|
|||||||
case opSum:
|
case opSum:
|
||||||
case opWeightedSum:
|
case opWeightedSum:
|
||||||
{
|
{
|
||||||
if (canWeight(weightField))
|
if (is_weightedOp() && canWeight(weightField))
|
||||||
{
|
{
|
||||||
result = gSum(weightField*values);
|
result = gSum(weightField*values);
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ Type Foam::functionObjects::fieldValues::volFieldValue::processValues
|
|||||||
case opAverage:
|
case opAverage:
|
||||||
case opWeightedAverage:
|
case opWeightedAverage:
|
||||||
{
|
{
|
||||||
if (canWeight(weightField))
|
if (is_weightedOp() && canWeight(weightField))
|
||||||
{
|
{
|
||||||
result =
|
result =
|
||||||
gSum(weightField*values)/(gSum(weightField) + ROOTVSMALL);
|
gSum(weightField*values)/(gSum(weightField) + ROOTVSMALL);
|
||||||
@ -142,7 +142,7 @@ Type Foam::functionObjects::fieldValues::volFieldValue::processValues
|
|||||||
case opVolAverage:
|
case opVolAverage:
|
||||||
case opWeightedVolAverage:
|
case opWeightedVolAverage:
|
||||||
{
|
{
|
||||||
if (canWeight(weightField))
|
if (is_weightedOp() && canWeight(weightField))
|
||||||
{
|
{
|
||||||
result = gSum(weightField*V*values)
|
result = gSum(weightField*V*values)
|
||||||
/(gSum(weightField*V) + ROOTVSMALL);
|
/(gSum(weightField*V) + ROOTVSMALL);
|
||||||
@ -157,7 +157,7 @@ Type Foam::functionObjects::fieldValues::volFieldValue::processValues
|
|||||||
case opVolIntegrate:
|
case opVolIntegrate:
|
||||||
case opWeightedVolIntegrate:
|
case opWeightedVolIntegrate:
|
||||||
{
|
{
|
||||||
if (canWeight(weightField))
|
if (is_weightedOp() && canWeight(weightField))
|
||||||
{
|
{
|
||||||
result = gSum(weightField*V*values);
|
result = gSum(weightField*V*values);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user