43 namespace functionObjects
61 { regionTypes::stFaceZone,
"faceZone" },
62 { regionTypes::stPatch,
"patch" },
63 { regionTypes::stObject,
"functionObjectSurface" },
64 { regionTypes::stSampled,
"sampledSurface" },
75 { operationType::opNone,
"none" },
76 { operationType::opMin,
"min" },
77 { operationType::opMax,
"max" },
78 { operationType::opSum,
"sum" },
79 { operationType::opSumMag,
"sumMag" },
80 { operationType::opSumDirection,
"sumDirection" },
81 { operationType::opSumDirectionBalance,
"sumDirectionBalance" },
82 { operationType::opAverage,
"average" },
83 { operationType::opAreaAverage,
"areaAverage" },
84 { operationType::opAreaIntegrate,
"areaIntegrate" },
85 { operationType::opCoV,
"CoV" },
86 { operationType::opAreaNormalAverage,
"areaNormalAverage" },
87 { operationType::opAreaNormalIntegrate,
"areaNormalIntegrate" },
88 { operationType::opUniformity,
"uniformity" },
91 { operationType::opWeightedSum,
"weightedSum" },
92 { operationType::opWeightedAverage,
"weightedAverage" },
93 { operationType::opWeightedAreaAverage,
"weightedAreaAverage" },
94 { operationType::opWeightedAreaIntegrate,
"weightedAreaIntegrate" },
95 { operationType::opWeightedUniformity,
"weightedUniformity" },
98 { operationType::opAbsWeightedSum,
"absWeightedSum" },
99 { operationType::opAbsWeightedAverage,
"absWeightedAverage" },
100 { operationType::opAbsWeightedAreaAverage,
"absWeightedAreaAverage" },
101 { operationType::opAbsWeightedAreaIntegrate,
"absWeightedAreaIntegrate" },
102 { operationType::opAbsWeightedUniformity,
"absWeightedUniformity" },
111 { postOperationType::postOpNone,
"none" },
112 { postOperationType::postOpSqrt,
"sqrt" },
130 void Foam::functionObjects::fieldValues::surfaceFieldValue::setFaceZoneFaces()
132 const label zoneId = mesh_.faceZones().findZoneID(regionName_);
138 << regionTypeNames_[regionType_] <<
'(' << regionName_ <<
"):" <<
nl
139 <<
" Unknown face zone name: " << regionName_
140 <<
". Valid face zones are: " << mesh_.faceZones().names()
144 const faceZone& fZone = mesh_.faceZones()[zoneId];
152 const label facei = fZone[i];
155 label facePatchId = -1;
156 if (mesh_.isInternalFace(facei))
163 facePatchId = mesh_.boundaryMesh().whichPatch(facei);
165 if (isA<coupledPolyPatch>(pp))
167 if (refCast<const coupledPolyPatch>(pp).owner())
176 else if (!isA<emptyPolyPatch>(pp))
190 facePatchIds.append(facePatchId);
191 faceFlip.append(fZone.
flipMap()[i] ? true :
false);
195 faceId_.transfer(faceIds);
196 facePatchId_.transfer(facePatchIds);
197 faceFlip_.transfer(faceFlip);
202 Pout<<
"Original face zone size = " << fZone.size()
203 <<
", new size = " << faceId_.size() <<
endl;
208 void Foam::functionObjects::fieldValues::surfaceFieldValue::setPatchFaces()
210 const label patchid = mesh_.boundaryMesh().findPatchID(regionName_);
216 << regionTypeNames_[regionType_] <<
'(' << regionName_ <<
"):" <<
nl
217 <<
" Unknown patch name: " << regionName_
218 <<
". Valid patch names are: "
219 << mesh_.boundaryMesh().names() <<
nl
225 label nFaces = pp.size();
226 if (isA<emptyPolyPatch>(pp))
231 faceId_.setSize(nFaces);
232 facePatchId_.setSize(nFaces);
233 faceFlip_.setSize(nFaces);
238 faceId_[facei] = facei;
239 facePatchId_[facei] = patchid;
240 faceFlip_[facei] =
false;
245 void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
257 if (facePatchId_[i] != -1)
259 const label patchi = facePatchId_[i];
260 globalFacesIs[i] += mesh_.boundaryMesh()[patchi].start();
267 IndirectList<face>(mesh_.faces(), globalFacesIs),
281 nFaces += allFaces[proci].size();
285 faces.setSize(nFaces);
294 for (
const face&
f : fcs)
296 face& newF = faces[nFaces++];
305 for (
const point& pt : pts)
316 const faceList& fcs = allFaces[proci];
317 for (
const face&
f : fcs)
319 face& newF = faces[nFaces++];
328 for (
const point& pt : pts)
352 <<
" down to " << newPoints.size() <<
" points" <<
endl;
355 points.transfer(newPoints);
356 for (face&
f : faces)
364 void Foam::functionObjects::fieldValues::surfaceFieldValue::
365 combineSurfaceGeometry
371 if (stObject == regionType_)
373 const polySurface&
s = dynamicCast<const polySurface>(obr());
378 const scalar mergeDim = 1
e-10*boundBox(
s.points(),
true).
mag();
387 SubList<face>(
s.faces(),
s.faces().size()),
401 else if (sampledPtr_.valid())
403 const sampledSurface&
s = sampledPtr_();
408 const scalar mergeDim = 1
e-10*mesh_.bounds().mag();
417 SubList<face>(
s.faces(),
s.faces().size()),
435 Foam::functionObjects::fieldValues::surfaceFieldValue::totalArea()
const
437 scalar totalArea = 0;
439 if (stObject == regionType_)
441 const polySurface&
s = dynamicCast<const polySurface>(obr());
443 totalArea =
gSum(
s.magSf());
445 else if (sampledPtr_.valid())
447 totalArea =
gSum(sampledPtr_().magSf());
451 totalArea =
gSum(filterField(mesh_.magSf()));
484 if (sampledPtr_.valid())
486 sampledPtr_->update();
508 const polySurface&
s = dynamicCast<const polySurface>(obr());
525 << regionTypeNames_[regionType_] <<
'(' << regionName_ <<
"):" <<
nl
529 totalArea_ = totalArea();
531 Log <<
" total faces = " << nFaces_ <<
nl
532 <<
" total area = " << totalArea_ <<
nl
535 writeFileHeader(file());
537 needsUpdate_ =
false;
547 if (operation_ != opNone)
549 writeCommented(os,
"Region type : ");
550 os << regionTypeNames_[regionType_] <<
" " << regionName_ <<
endl;
552 writeHeaderValue(os,
"Faces", nFaces_);
553 writeHeaderValue(os,
"Area", totalArea_);
554 writeHeaderValue(os,
"Scale factor", scaleFactor_);
556 if (weightFieldName_ !=
"none")
558 writeHeaderValue(os,
"Weight field", weightFieldName_);
561 writeCommented(os,
"Time");
567 for (
const word& fieldName : fields_)
569 os <<
tab << operationTypeNames_[operation_]
570 <<
"(" << fieldName <<
")";
594 case opSumDirectionBalance:
603 case opWeightedUniformity:
604 case opAbsWeightedUniformity:
606 const scalar areaTotal =
gSum(
mag(Sf));
611 if (canWeight(weightField))
618 mean =
gSum(weight()*areaVal()) / areaTotal;
621 numer =
gSum(
mag(weight*areaVal - (mean *
mag(Sf))));
628 mean =
gSum(areaVal()) / areaTotal;
631 numer =
gSum(
mag(areaVal - (mean *
mag(Sf))));
635 const scalar ui = 1 - numer/(2*
mag(mean*areaTotal) + ROOTVSMALL);
637 return min(
max(ui, 0), 1);
643 return processSameTypeValues(
values, Sf, weightField);
667 case opSumDirectionBalance:
674 case opAreaNormalAverage:
679 case opAreaNormalIntegrate:
686 case opWeightedUniformity:
687 case opAbsWeightedUniformity:
689 const scalar areaTotal =
gSum(
mag(Sf));
694 if (canWeight(weightField))
701 mean =
gSum(weight()*areaVal()) / areaTotal;
704 numer =
gSum(
mag(weight*areaVal - (mean *
mag(Sf))));
711 mean =
gSum(areaVal()) / areaTotal;
714 numer =
gSum(
mag(areaVal - (mean *
mag(Sf))));
718 const scalar ui = 1 - numer/(2*
mag(mean*areaTotal) + ROOTVSMALL);
726 return processSameTypeValues(
values, Sf, weightField);
741 return mag(weightField);
765 return mag(weightField *
mag(Sf));
768 return (weightField *
mag(Sf));
788 return mag(weightField & Sf);
791 return (weightField & Sf);
805 regionType_(regionTypeNames_.get(
"regionType",
dict)),
806 operation_(operationTypeNames_.get(
"operation",
dict)),
809 postOperationTypeNames_.lookupOrDefault
813 postOperationType::postOpNone,
817 weightFieldName_(
"none"),
838 regionType_(regionTypeNames_.get(
"regionType",
dict)),
839 operation_(operationTypeNames_.get(
"operation",
dict)),
842 postOperationTypeNames_.lookupOrDefault
846 postOperationType::postOpNone,
850 weightFieldName_(
"none"),
872 weightFieldName_ =
"none";
874 writeArea_ =
dict.lookupOrDefault(
"writeArea",
false);
878 facePatchId_.clear();
881 surfaceWriterPtr_.clear();
883 dict.readEntry(
"name", regionName_);
887 if (stSampled == regionType_)
893 dict.subDict(
"sampledSurfaceDict")
900 if (postOperation_ != postOpNone)
902 Info<< postOperationTypeNames_[postOperation_] <<
'('
903 << operationTypeNames_[operation_] <<
')' <<
nl;
907 Info<< operationTypeNames_[operation_] <<
nl;
912 if (stSampled == regionType_)
915 <<
"Cannot use weighted operation '"
916 << operationTypeNames_[operation_]
917 <<
"' for sampledSurface"
921 if (
dict.readIfPresent(
"weightField", weightFieldName_))
923 Info<<
" weight field = " << weightFieldName_ <<
nl;
929 <<
"The '" << operationTypeNames_[operation_]
930 <<
"' operation is missing a weightField." <<
nl
931 <<
"Either provide the weightField, "
932 <<
"use weightField 'none' to suppress weighting," <<
nl
933 <<
"or use a different operation."
940 if (
dict.readIfPresent(
"orientedFields", orientedFields))
942 fields_.
append(orientedFields);
945 <<
"The 'orientedFields' option is deprecated. These fields can "
946 <<
"and have been added to the standard 'fields' list."
954 surfaceWriterPtr_.reset
959 dict.subOrEmptyDict(
"formatOptions").subOrEmptyDict(formatName)
965 surfaceWriterPtr_->verbose() =
true;
968 if (surfaceWriterPtr_->enabled())
970 Info<<
" surfaceFormat = " << formatName <<
nl;
974 surfaceWriterPtr_->clear();
986 if (needsUpdate_ || operation_ != opNone)
993 if (operation_ != opNone)
995 writeCurrentTime(file());
1000 totalArea_ = totalArea();
1001 Log <<
" total area = " << totalArea_ <<
endl;
1005 file() <<
tab << totalArea_;
1013 if (stObject == regionType_)
1015 const polySurface&
s = dynamicCast<const polySurface>(obr());
1018 else if (sampledPtr_.valid())
1020 Sf = sampledPtr_().Sf();
1024 Sf = filterField(mesh_.Sf());
1032 if (surfaceWriterPtr_.valid())
1034 if (withTopologicalMerge())
1036 combineMeshGeometry(faces,
points);
1040 combineSurfaceGeometry(faces,
points);
1045 if (weightFieldName_ !=
"none")
1047 if (validField<scalar>(weightFieldName_))
1051 getFieldValues<scalar>(weightFieldName_,
true)
1055 writeAll(Sf, weightField,
points, faces);
1057 else if (validField<vector>(weightFieldName_))
1061 getFieldValues<vector>(weightFieldName_,
true)
1065 writeAll(Sf, weightField,
points, faces);
1070 <<
"weightField " << weightFieldName_
1071 <<
" not found or an unsupported type"
1081 writeAll(Sf, weightField,
points, faces);
1084 if (operation_ != opNone)
1100 needsUpdate_ =
true;
1109 needsUpdate_ =
true;