Skip to content
Snippets Groups Projects

Feature surface field value operations

Merged Mark OLESEN requested to merge feature-surfacefield-value into develop
9 files
+ 454
290
Compare changes
  • Side-by-side
  • Inline
Files
9
@@ -69,23 +69,32 @@ const Foam::Enum
@@ -69,23 +69,32 @@ const Foam::Enum
>
>
Foam::functionObjects::fieldValues::surfaceFieldValue::operationTypeNames_
Foam::functionObjects::fieldValues::surfaceFieldValue::operationTypeNames_
{
{
 
// Normal operations
{ operationType::opNone, "none" },
{ operationType::opNone, "none" },
 
{ operationType::opMin, "min" },
 
{ operationType::opMax, "max" },
{ operationType::opSum, "sum" },
{ operationType::opSum, "sum" },
{ operationType::opWeightedSum, "weightedSum" },
{ operationType::opSumMag, "sumMag" },
{ operationType::opSumMag, "sumMag" },
{ operationType::opSumDirection, "sumDirection" },
{ operationType::opSumDirection, "sumDirection" },
{ operationType::opSumDirectionBalance, "sumDirectionBalance" },
{ operationType::opSumDirectionBalance, "sumDirectionBalance" },
{ operationType::opAverage, "average" },
{ operationType::opAverage, "average" },
{ operationType::opWeightedAverage, "weightedAverage" },
{ operationType::opAreaAverage, "areaAverage" },
{ operationType::opAreaAverage, "areaAverage" },
{ operationType::opWeightedAreaAverage, "weightedAreaAverage" },
{ operationType::opAreaIntegrate, "areaIntegrate" },
{ operationType::opAreaIntegrate, "areaIntegrate" },
{ operationType::opWeightedAreaIntegrate, "weightedAreaIntegrate" },
{ operationType::opMin, "min" },
{ operationType::opMax, "max" },
{ operationType::opCoV, "CoV" },
{ operationType::opCoV, "CoV" },
{ operationType::opAreaNormalAverage, "areaNormalAverage" },
{ operationType::opAreaNormalAverage, "areaNormalAverage" },
{ operationType::opAreaNormalIntegrate, "areaNormalIntegrate" },
{ operationType::opAreaNormalIntegrate, "areaNormalIntegrate" },
 
 
// Using weighting
 
{ operationType::opWeightedSum, "weightedSum" },
 
{ operationType::opWeightedAverage, "weightedAverage" },
 
{ operationType::opWeightedAreaAverage, "weightedAreaAverage" },
 
{ operationType::opWeightedAreaIntegrate, "weightedAreaIntegrate" },
 
 
// Using absolute weighting
 
{ operationType::opAbsWeightedSum, "absWeightedSum" },
 
{ operationType::opAbsWeightedAverage, "absWeightedAverage" },
 
{ operationType::opAbsWeightedAreaAverage, "absWeightedAreaAverage" },
 
{ operationType::opAbsWeightedAreaIntegrate, "absWeightedAreaIntegrate" },
};
};
const Foam::Enum
const Foam::Enum
@@ -244,7 +253,7 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
@@ -244,7 +253,7 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
{
{
if (facePatchId_[i] != -1)
if (facePatchId_[i] != -1)
{
{
label patchi = facePatchId_[i];
const label patchi = facePatchId_[i];
globalFacesIs[i] += mesh_.boundaryMesh()[patchi].start();
globalFacesIs[i] += mesh_.boundaryMesh()[patchi].start();
}
}
}
}
@@ -279,9 +288,8 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
@@ -279,9 +288,8 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
// My own data first
// My own data first
{
{
const faceList& fcs = allFaces[Pstream::myProcNo()];
const faceList& fcs = allFaces[Pstream::myProcNo()];
forAll(fcs, i)
for (const face& f : fcs)
{
{
const face& f = fcs[i];
face& newF = faces[nFaces++];
face& newF = faces[nFaces++];
newF.setSize(f.size());
newF.setSize(f.size());
forAll(f, fp)
forAll(f, fp)
@@ -291,9 +299,9 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
@@ -291,9 +299,9 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
}
}
const pointField& pts = allPoints[Pstream::myProcNo()];
const pointField& pts = allPoints[Pstream::myProcNo()];
forAll(pts, i)
for (const point& pt : pts)
{
{
points[nPoints++] = pts[i];
points[nPoints++] = pt;
}
}
}
}
@@ -303,9 +311,8 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
@@ -303,9 +311,8 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
if (proci != Pstream::myProcNo())
if (proci != Pstream::myProcNo())
{
{
const faceList& fcs = allFaces[proci];
const faceList& fcs = allFaces[proci];
forAll(fcs, i)
for (const face& f : fcs)
{
{
const face& f = fcs[i];
face& newF = faces[nFaces++];
face& newF = faces[nFaces++];
newF.setSize(f.size());
newF.setSize(f.size());
forAll(f, fp)
forAll(f, fp)
@@ -315,9 +322,9 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
@@ -315,9 +322,9 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
}
}
const pointField& pts = allPoints[proci];
const pointField& pts = allPoints[proci];
forAll(pts, i)
for (const point& pt : pts)
{
{
points[nPoints++] = pts[i];
points[nPoints++] = pt;
}
}
}
}
}
}
@@ -343,9 +350,9 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
@@ -343,9 +350,9 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
}
}
points.transfer(newPoints);
points.transfer(newPoints);
forAll(faces, i)
for (face& f : faces)
{
{
inplaceRenumber(oldToNew, faces[i]);
inplaceRenumber(oldToNew, f);
}
}
}
}
}
}
@@ -447,17 +454,19 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::totalArea() const
@@ -447,17 +454,19 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::totalArea() const
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::fieldValues::surfaceFieldValue::needsSf() const
bool Foam::functionObjects::fieldValues::surfaceFieldValue::usesSf() const
{
{
// Many operations use the Sf field
// Only a few operations do not require the Sf field
switch (operation_)
switch (operation_)
{
{
case opNone:
case opNone:
 
case opMin:
 
case opMax:
case opSum:
case opSum:
case opSumMag:
case opSumMag:
case opAverage:
case opAverage:
case opMin:
case opSumDirection:
case opMax:
case opSumDirectionBalance:
{
{
return false;
return false;
}
}
@@ -469,26 +478,6 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::needsSf() const
@@ -469,26 +478,6 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::needsSf() const
}
}
bool Foam::functionObjects::fieldValues::surfaceFieldValue::needsWeight() const
{
// Only a few operations use weight field
switch (operation_)
{
case opWeightedSum:
case opWeightedAverage:
case opWeightedAreaAverage:
case opWeightedAreaIntegrate:
{
return true;
}
default:
{
return false;
}
}
}
void Foam::functionObjects::fieldValues::surfaceFieldValue::initialise
void Foam::functionObjects::fieldValues::surfaceFieldValue::initialise
(
(
const dictionary& dict
const dictionary& dict
@@ -582,19 +571,32 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::initialise
@@ -582,19 +571,32 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::initialise
weightFieldName_ = "none";
weightFieldName_ = "none";
if (needsWeight())
if (usesWeight())
{
{
if (dict.readIfPresent("weightField", weightFieldName_))
if (regionType_ == stSampledSurface)
{
{
if (regionType_ == stSampledSurface)
FatalIOErrorInFunction(dict)
{
<< "Cannot use weighted operation '"
FatalIOErrorInFunction(dict)
<< operationTypeNames_[operation_]
<< "Cannot use weightField for sampledSurface"
<< "' for sampledSurface"
<< exit(FatalIOError);
<< exit(FatalIOError);
}
}
 
if (dict.readIfPresent("weightField", weightFieldName_))
 
{
Info<< " weight field = " << weightFieldName_ << nl;
Info<< " weight field = " << weightFieldName_ << nl;
}
}
 
else
 
{
 
// Suggest possible alternative unweighted operation?
 
FatalIOErrorInFunction(dict)
 
<< "The '" << operationTypeNames_[operation_]
 
<< "' operation is missing a weightField." << nl
 
<< "Either provide the weightField, "
 
<< "use weightField 'none' to suppress weighting," << nl
 
<< "or use a different operation."
 
<< exit(FatalIOError);
 
}
}
}
// Backwards compatibility for v1612+ and older
// Backwards compatibility for v1612+ and older
@@ -660,10 +662,10 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::writeFileHeader
@@ -660,10 +662,10 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::writeFileHeader
os << tab << "Area";
os << tab << "Area";
}
}
forAll(fields_, i)
for (const word& fieldName : fields_)
{
{
os << tab << operationTypeNames_[operation_]
os << tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
<< "(" << fieldName << ")";
}
}
os << endl;
os << endl;
@@ -684,12 +686,12 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::processValues
@@ -684,12 +686,12 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::processValues
{
{
case opSumDirection:
case opSumDirection:
{
{
vector n(dict_.lookup("direction"));
const vector n(dict_.lookup("direction"));
return gSum(pos(values*(Sf & n))*mag(values));
return gSum(pos(values*(Sf & n))*mag(values));
}
}
case opSumDirectionBalance:
case opSumDirectionBalance:
{
{
vector n(dict_.lookup("direction"));
const vector n(dict_.lookup("direction"));
const scalarField nv(values*(Sf & n));
const scalarField nv(values*(Sf & n));
return gSum(pos(nv)*mag(values) - neg(nv)*mag(values));
return gSum(pos(nv)*mag(values) - neg(nv)*mag(values));
@@ -754,10 +756,17 @@ Foam::tmp<Foam::scalarField>
@@ -754,10 +756,17 @@ Foam::tmp<Foam::scalarField>
Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
(
(
const Field<scalar>& weightField
const Field<scalar>& weightField
)
) const
{
{
// pass through
if (usesMag())
return weightField;
{
 
return mag(weightField);
 
}
 
else
 
{
 
// pass through
 
return weightField;
 
}
}
}
@@ -767,16 +776,21 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
@@ -767,16 +776,21 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
(
(
const Field<scalar>& weightField,
const Field<scalar>& weightField,
const vectorField& Sf
const vectorField& Sf
)
) const
{
{
// scalar * Area
// scalar * Area
if (returnReduce(weightField.empty(), andOp<bool>()))
if (returnReduce(weightField.empty(), andOp<bool>()))
{
{
 
// No weight field - revert to unweighted form
return mag(Sf);
return mag(Sf);
}
}
 
else if (usesMag())
 
{
 
return mag(weightField * mag(Sf));
 
}
else
else
{
{
return weightField * mag(Sf);
return (weightField * mag(Sf));
}
}
}
}
@@ -787,16 +801,21 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
@@ -787,16 +801,21 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
(
(
const Field<vector>& weightField,
const Field<vector>& weightField,
const vectorField& Sf
const vectorField& Sf
)
) const
{
{
// vector (dot) Area
// vector (dot) Area
if (returnReduce(weightField.empty(), andOp<bool>()))
if (returnReduce(weightField.empty(), andOp<bool>()))
{
{
 
// No weight field - revert to unweighted form
return mag(Sf);
return mag(Sf);
}
}
 
else if (usesMag())
 
{
 
return mag(weightField & Sf);
 
}
else
else
{
{
return weightField & Sf;
return (weightField & Sf);
}
}
}
}
@@ -915,7 +934,7 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::write()
@@ -915,7 +934,7 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::write()
// Many operations use the Sf field
// Many operations use the Sf field
vectorField Sf;
vectorField Sf;
if (needsSf())
if (usesSf())
{
{
if (regionType_ == stSurface)
if (regionType_ == stSurface)
{
{
Loading