40template<
class WeightType>
42Foam::functionObjects::fieldValues::surfaceFieldValue::weightingFactor
44 const Field<WeightType>& weightField,
50 return mag(weightField);
56template<
class WeightType>
57inline bool Foam::functionObjects::fieldValues::surfaceFieldValue::canWeight
59 const Field<WeightType>&
fld
68bool Foam::functionObjects::fieldValues::surfaceFieldValue::validField
73 typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
74 typedef GeometricField<Type, fvPatchField, volMesh> vf;
75 typedef DimensionedField<Type, polySurfaceGeoMesh> smt;
79 foundObject<smt>(fieldName)
80 || foundObject<vf>(fieldName)
81 || (withSurfaceFields() && foundObject<sf>(fieldName))
88Foam::functionObjects::fieldValues::surfaceFieldValue::getFieldValues
90 const word& fieldName,
94 typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
95 typedef GeometricField<Type, fvPatchField, volMesh> vf;
96 typedef DimensionedField<Type, polySurfaceGeoMesh> smt;
98 if (foundObject<smt>(fieldName))
100 return lookupObject<smt>(fieldName);
102 else if (withSurfaceFields() && foundObject<sf>(fieldName))
104 return filterField(lookupObject<sf>(fieldName));
106 else if (foundObject<vf>(fieldName))
108 const vf&
fld = lookupObject<vf>(fieldName);
116 const interpolationCell<Type> interp(
fld);
118 return sampledPtr_->sample(interp);
122 return filterField(
fld);
129 <<
"Field " << fieldName <<
" not found in database" <<
nl
130 <<
abort(FatalError);
133 return tmp<Field<Type>>::New();
137template<
class Type,
class WeightType>
138Type Foam::functionObjects::fieldValues::surfaceFieldValue::
141 const Field<Type>& values,
142 const vectorField& Sf,
143 const Field<WeightType>& weightField
158 result =
gMin(values);
163 result =
gMax(values);
173 case opAbsWeightedSum:
175 if (is_weightedOp() && canWeight(weightField))
177 tmp<scalarField> weight
179 weightingFactor(weightField, Sf, is_magOp())
182 result =
gSum(weight*values);
187 result =
gSum(values);
192 case opSumDirectionBalance:
195 <<
"Operation " << operationTypeNames_[operation_]
196 <<
" not available for values of type "
197 << pTraits<Type>::typeName
203 case opWeightedAverage:
204 case opAbsWeightedAverage:
206 if (is_weightedOp() && canWeight(weightField))
210 weightingFactor(weightField, Sf, is_magOp())
213 result =
gSum(factor*values)/(
gSum(factor) + ROOTVSMALL);
220 result =
gSum(values)/(scalar(
n) + ROOTVSMALL);
225 case opWeightedAreaAverage:
226 case opAbsWeightedAreaAverage:
228 if (is_weightedOp() && canWeight(weightField))
232 areaWeightingFactor(weightField, Sf, is_magOp())
235 result =
gSum(factor*values)/
gSum(factor + ROOTVSMALL);
242 result =
gSum(factor*values)/
gSum(factor + ROOTVSMALL);
246 case opAreaIntegrate:
247 case opWeightedAreaIntegrate:
248 case opAbsWeightedAreaIntegrate:
250 if (is_weightedOp() && canWeight(weightField))
252 tmp<scalarField> factor
254 areaWeightingFactor(weightField, Sf, is_magOp())
257 result =
gSum(factor*values);
262 tmp<scalarField> factor(
mag(Sf));
264 result =
gSum(factor*values);
271 const scalar gSumMagSf =
gSum(magSf);
273 Type meanValue =
gSum(values*magSf)/gSumMagSf;
275 for (direction d=0; d < pTraits<Type>::nComponents; ++d)
277 tmp<scalarField> vals(
values.component(d));
278 const scalar mean =
component(meanValue, d);
283 /(mean + ROOTVSMALL);
289 case opAreaNormalAverage:
290 case opAreaNormalIntegrate:
297 case opWeightedUniformity:
298 case opAbsWeightedUniformity:
300 if (is_weightedOp() && canWeight(weightField))
303 return processValues<Type, scalar>
307 weightingFactor(weightField, is_magOp())
319template<
class Type,
class WeightType>
320Type Foam::functionObjects::fieldValues::surfaceFieldValue::processValues
322 const Field<Type>& values,
323 const vectorField& Sf,
324 const Field<WeightType>& weightField
327 return processSameTypeValues(values, Sf, weightField);
331template<
class WeightType>
332Foam::label Foam::functionObjects::fieldValues::surfaceFieldValue::writeAll
334 const vectorField& Sf,
335 const Field<WeightType>& weightField,
337 const faceList& faces
340 label nProcessed = 0;
348 if (Pstream::master() && surfaceWriterPtr_ && surfaceWriterPtr_->enabled())
350 auto&
writer = *surfaceWriterPtr_;
358 / regionTypeNames_[regionType_] + (
"_" + regionName_)
366 for (
const word& fieldName : fields_)
370 writeValues<scalar>(fieldName, Sf, weightField,
points, faces)
371 || writeValues<vector>(fieldName, Sf, weightField,
points, faces)
372 || writeValues<sphericalTensor>
374 fieldName, Sf, weightField,
points, faces
376 || writeValues<symmTensor>(fieldName, Sf, weightField,
points, faces)
377 || writeValues<tensor>(fieldName, Sf, weightField,
points, faces)
385 <<
"Requested field " << fieldName
386 <<
" not found in database and not processed"
392 if (Pstream::master() && surfaceWriterPtr_ && surfaceWriterPtr_->enabled())
394 auto&
writer = *surfaceWriterPtr_;
412template<
class Type,
class WeightType>
413bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues
415 const word& fieldName,
416 const vectorField& Sf,
417 const Field<WeightType>& weightField,
419 const faceList& faces
422 const bool ok = validField<Type>(fieldName);
426 Field<Type>
values(getFieldValues<Type>(fieldName,
true));
429 if (surfaceWriterPtr_ && surfaceWriterPtr_->enabled())
431 Field<Type> allValues(values);
432 combineFields(allValues);
434 if (Pstream::master())
437 surfaceWriterPtr_->write(fieldName, allValues);
446 if (operation_ != opNone)
451 Type result = processValues(values, Sf, weightField);
453 switch (postOperation_)
458 for (direction d=0; d < pTraits<Type>::nComponents; ++d)
474 if (postOperation_ != postOpNone)
477 prefix += postOperationTypeNames_[postOperation_];
482 prefix += operationTypeNames_[operation_];
487 word resultName = prefix + regionName_ +
',' + fieldName + suffix;
491 Log <<
" " << prefix << regionName_ << suffix
492 <<
" of " << fieldName <<
" = ";
499 bool alwaysScalar(operation_ & typeScalar);
505 if (postOperation_ == postOpMag)
507 sresult =
mag(sresult);
510 else if (postOperation_ == postOpMag)
512 sresult =
mag(result);
519 file()<<
tab << sresult;
523 this->setResult(resultName, sresult);
527 file()<<
tab << result;
531 this->setResult(resultName, result);
542Foam::functionObjects::fieldValues::surfaceFieldValue::filterField
544 const GeometricField<Type, fvPatchField, volMesh>&
field
550 auto tvalues = tmp<Field<Type>>::New(faceId_.size());
551 auto&
values = tvalues.ref();
555 const label facei = faceId_[i];
556 const label patchi = facePatchId_[i];
578Foam::functionObjects::fieldValues::surfaceFieldValue::filterField
580 const GeometricField<Type, fvsPatchField, surfaceMesh>&
field
583 auto tvalues = tmp<Field<Type>>::New(faceId_.size());
584 auto&
values = tvalues.ref();
588 const label facei = faceId_[i];
589 const label patchi = facePatchId_[i];
603 Pout<<
"field " <<
field.name() <<
" oriented: "
607 if (
field.is_oriented())
IOdictionary propsDict(dictIO)
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))
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edgesCentres")))
A class for managing temporary objects.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
word outputName("finiteArea-edges.obj")
return returnReduce(nRefine-oldNRefine, sumOp< label >())
#define WarningInFunction
Report a warning using Foam::Warning.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
Type gSum(const FieldField< Field, Type > &f)
List< label > labelList
A List of labels.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
label & setComponent(label &val, const direction) noexcept
Non-const access to integer-type (has no components).
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
errorManip< error > abort(error &err)
Type gMin(const FieldField< Field, Type > &f)
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Type gMax(const FieldField< Field, Type > &f)
constexpr char nl
The newline '\n' character (0x0a).
constexpr char tab
The tab '\t' character(0x09).
Fields (face and point) for polySurface.
#define forAll(list, i)
Loop across all elements in list.