Skip to content
Snippets Groups Projects
Commit b073c0a1 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: postOperation for surfaceFieldValue

- currently only 'none' or 'sqrt', which can be useful in combination
  with integrate or averaging functions.
parent 001a2e4a
No related branches found
No related tags found
No related merge requests found
...@@ -85,6 +85,18 @@ const char* Foam::NamedEnum ...@@ -85,6 +85,18 @@ const char* Foam::NamedEnum
"areaNormalIntegrate" "areaNormalIntegrate"
}; };
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceFieldValue::postOperationType,
2
>::names[] =
{
"none",
"sqrt"
};
const Foam::NamedEnum const Foam::NamedEnum
< <
Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes, Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes,
...@@ -97,6 +109,13 @@ const Foam::NamedEnum ...@@ -97,6 +109,13 @@ const Foam::NamedEnum
16 16
> Foam::functionObjects::fieldValues::surfaceFieldValue::operationTypeNames_; > Foam::functionObjects::fieldValues::surfaceFieldValue::operationTypeNames_;
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceFieldValue::postOperationType,
2
>
Foam::functionObjects::fieldValues::surfaceFieldValue::postOperationTypeNames_;
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
...@@ -649,6 +668,11 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::surfaceFieldValue ...@@ -649,6 +668,11 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::surfaceFieldValue
surfaceWriterPtr_(nullptr), surfaceWriterPtr_(nullptr),
regionType_(regionTypeNames_.read(dict.lookup("regionType"))), regionType_(regionTypeNames_.read(dict.lookup("regionType"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))), operation_(operationTypeNames_.read(dict.lookup("operation"))),
postOperation_
(
postOperationTypeNames_
[dict.lookupOrDefault<word>("postOperation", "none")]
),
weightFieldName_("none"), weightFieldName_("none"),
orientWeightField_(false), orientWeightField_(false),
orientedFieldsStart_(labelMax), orientedFieldsStart_(labelMax),
...@@ -674,6 +698,11 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::surfaceFieldValue ...@@ -674,6 +698,11 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::surfaceFieldValue
surfaceWriterPtr_(nullptr), surfaceWriterPtr_(nullptr),
regionType_(regionTypeNames_.read(dict.lookup("regionType"))), regionType_(regionTypeNames_.read(dict.lookup("regionType"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))), operation_(operationTypeNames_.read(dict.lookup("operation"))),
postOperation_
(
postOperationTypeNames_
[dict.lookupOrDefault<word>("postOperation", "none")]
),
weightFieldName_("none"), weightFieldName_("none"),
orientWeightField_(false), orientWeightField_(false),
orientedFieldsStart_(labelMax), orientedFieldsStart_(labelMax),
......
...@@ -86,6 +86,7 @@ Usage ...@@ -86,6 +86,7 @@ Usage
regionType | face regionType: see below | yes | regionType | face regionType: see below | yes |
name | name of face regionType if required | no | name | name of face regionType if required | no |
operation | operation to perform | yes | operation | operation to perform | yes |
postOperation | post-operation to perform | no | none |
weightField | name of field to apply weighting | no | weightField | name of field to apply weighting | no |
orientedWeightField | name of oriented field to apply weighting | no | orientedWeightField | name of oriented field to apply weighting | no |
scaleFactor | scale factor | no | 1 scaleFactor | scale factor | no | 1
...@@ -223,6 +224,17 @@ public: ...@@ -223,6 +224,17 @@ public:
static const NamedEnum<operationType, 16> operationTypeNames_; static const NamedEnum<operationType, 16> operationTypeNames_;
//- Post-operation type enumeration
enum postOperationType
{
postOpNone,
postOpSqrt
};
//- Operation type names
static const NamedEnum<postOperationType, 2> postOperationTypeNames_;
private: private:
// Private Member Functions // Private Member Functions
...@@ -267,6 +279,9 @@ protected: ...@@ -267,6 +279,9 @@ protected:
//- Operation to apply to values //- Operation to apply to values
operationType operation_; operationType operation_;
//- Optional post-evaluation operation
postOperationType postOperation_;
//- Weight field name - optional //- Weight field name - optional
word weightFieldName_; word weightFieldName_;
...@@ -394,11 +409,11 @@ public: ...@@ -394,11 +409,11 @@ public:
inline fileName outputDir() const; inline fileName outputDir() const;
//- Templated helper function to output field values //- Templated helper function to output field values
template<class Type> template<class Type, class WeightType>
bool writeValues bool writeValues
( (
const word& fieldName, const word& fieldName,
const scalarField& weightField, const Field<WeightType>& weightField,
const bool orient const bool orient
); );
......
...@@ -286,11 +286,11 @@ Type Foam::functionObjects::fieldValues::surfaceFieldValue::processValues ...@@ -286,11 +286,11 @@ Type Foam::functionObjects::fieldValues::surfaceFieldValue::processValues
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type, class WeightType>
bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues
( (
const word& fieldName, const word& fieldName,
const scalarField& weightField, const Field<WeightType>& weightField,
const bool orient const bool orient
) )
{ {
...@@ -355,6 +355,22 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues ...@@ -355,6 +355,22 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues
Type result = processValues(values, Sf, weightField); Type result = processValues(values, Sf, weightField);
switch (postOperation_)
{
case postOpNone:
break;
case postOpSqrt:
{
// sqrt: component-wise - doesn't change the type
for (direction d=0; d < pTraits<Type>::nComponents; ++d)
{
setComponent(result, d)
= sqrt(mag(component(result, d)));
}
}
break;
}
file()<< tab << result; file()<< tab << result;
Log << " " << operationTypeNames_[operation_] Log << " " << operationTypeNames_[operation_]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment