37 namespace functionObjects
43 regionSizeDistribution,
52 void Foam::functionObjects::regionSizeDistribution::writeGraph
54 const coordSet& coords,
55 const word& valueName,
59 const wordList valNames(1, valueName);
64 OFstream str(outputPath/formatterPtr_().getFileName(coords, valNames));
66 Log <<
" Writing distribution of " << valueName <<
" to " << str.name()
69 List<const scalarField*> valPtrs(1);
71 formatterPtr_().write(coords, valNames, valPtrs, str);
75 void Foam::functionObjects::regionSizeDistribution::writeAlphaFields
77 const regionSplit& regions,
78 const Map<label>& patchRegions,
79 const Map<scalar>& regionVolume,
83 const scalar maxDropletVol = 1.0/6.0*
pow3(maxDiam_);
98 scopedName(alphaName_ +
"_liquidCore"),
99 obr_.time().timeName(),
111 scopedName(alphaName_ +
"_background"),
112 obr_.time().timeName(),
124 const label regioni = regions[celli];
125 if (patchRegions.found(regioni))
127 backgroundAlpha[celli] = 0;
131 liquidCore[celli] = 0;
133 const scalar regionVol = regionVolume[regioni];
134 if (regionVol < maxDropletVol)
136 backgroundAlpha[celli] = 0;
140 liquidCore.correctBoundaryConditions();
141 backgroundAlpha.correctBoundaryConditions();
145 Info<<
" Volume of liquid-core = "
148 <<
" Volume of background = "
153 Log <<
" Writing liquid-core field to " << liquidCore.name() <<
endl;
156 Log<<
" Writing background field to " << backgroundAlpha.name() <<
endl;
157 backgroundAlpha.
write();
162 Foam::functionObjects::regionSizeDistribution::findPatchRegions
164 const regionSplit& regions
171 const labelHashSet patchIDs(mesh_.boundaryMesh().patchSet(patchNames_));
173 label nPatchFaces = 0;
174 for (
const label patchi : patchIDs)
176 nPatchFaces += mesh_.boundaryMesh()[patchi].size();
180 Map<label> patchRegions(nPatchFaces);
181 for (
const label patchi : patchIDs)
183 const polyPatch& pp = mesh_.boundaryMesh()[patchi];
186 const labelList& faceCells = pp.faceCells();
188 for (
const label celli : faceCells)
208 Foam::functionObjects::regionSizeDistribution::divide
215 auto& result = tresult.ref();
221 result[i] = num[i]/denom[i];
232 void Foam::functionObjects::regionSizeDistribution::writeGraphs
234 const word& fieldName,
238 const coordSet& coords
247 binSum[indices[i]] += sortedField[i];
256 binSqrSum[indices[i]] +=
Foam::sqr(sortedField[i]);
264 writeGraph(coords, fieldName +
"_sum", binSum);
266 writeGraph(coords, fieldName +
"_avg", binAvg);
268 writeGraph(coords, fieldName +
"_dev", binDev);
273 void Foam::functionObjects::regionSizeDistribution::writeGraphs
275 const word& fieldName,
277 const regionSplit& regions,
283 const coordSet& coords
287 Map<scalar> regionField(regionSum(regions, cellField));
324 isoPlanes_(
dict.getOrDefault(
"isoPlanes", false))
337 dict.readEntry(
"nBins", nBins_);
338 dict.readEntry(
"field", alphaName_);
339 dict.readEntry(
"threshold", threshold_);
340 dict.readEntry(
"maxDiameter", maxDiam_);
342 dict.readIfPresent(
"minDiameter", minDiam_);
343 dict.readEntry(
"patches", patchNames_);
344 dict.readEntry(
"fields", fields_);
349 if (
dict.found(coordinateSystem::typeName_()))
356 Info<<
"Transforming all vectorFields with coordinate system "
357 << csysPtr_->name() <<
endl;
366 dict.readEntry(
"origin", origin_);
367 dict.readEntry(
"direction", direction_);
368 dict.readEntry(
"maxD", maxDiameter_);
369 dict.readEntry(
"nDownstreamBins", nDownstreamBins_);
370 dict.readEntry(
"maxDownstream", maxDownstream_);
371 direction_.normalise();
391 Log <<
" Looking up field " << alphaName_ <<
endl;
395 Info<<
" Reading field " << alphaName_ <<
endl;
403 mesh_.time().timeName(),
421 Log <<
" Volume of alpha = "
425 const scalar meshVol =
gSum(mesh_.V());
426 const scalar maxDropletVol = 1.0/6.0*
pow3(maxDiam_);
427 const scalar
delta = (maxDiam_-minDiam_)/nBins_;
429 Log <<
" Mesh volume = " << meshVol <<
nl
430 <<
" Maximum droplet diameter = " << maxDiam_ <<
nl
431 <<
" Maximum droplet volume = " << maxDropletVol
436 boolList blockedFace(mesh_.nFaces(),
false);
440 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
442 scalar ownVal =
alpha[mesh_.faceOwner()[facei]];
443 scalar neiVal =
alpha[mesh_.faceNeighbour()[facei]];
447 (ownVal < threshold_ && neiVal > threshold_)
448 || (ownVal > threshold_ && neiVal < threshold_)
451 blockedFace[facei] =
true;
462 tmp<scalarField> townFld(fvp.patchInternalField());
465 tmp<scalarField> tnbrFld(fvp.patchNeighbourField());
468 label start = fvp.patch().patch().start();
472 scalar ownVal = ownFld[i];
473 scalar neiVal = nbrFld[i];
477 (ownVal < threshold_ && neiVal > threshold_)
478 || (ownVal > threshold_ && neiVal < threshold_)
481 blockedFace[start+i] =
true;
490 regionSplit regions(mesh_, blockedFace);
492 Log <<
" Determined " << regions.nRegions()
493 <<
" disconnected regions" <<
endl;
503 mesh_.time().timeName(),
511 Info<<
" Dumping region as volScalarField to " << region.name()
516 region[celli] = regions[celli];
518 region.correctBoundaryConditions();
524 Map<label> patchRegions(findPatchRegions(regions));
529 Map<scalar> allRegionVolume(regionSum(regions, mesh_.V()));
530 Map<scalar> allRegionAlphaVolume(regionSum(regions, alphaVol));
531 Map<label> allRegionNumCells
547 scalar meshSumVol = 0.0;
548 scalar alphaSumVol = 0.0;
551 auto vIter = allRegionVolume.cbegin();
552 auto aIter = allRegionAlphaVolume.cbegin();
553 auto numIter = allRegionNumCells.cbegin();
557 vIter.good() && aIter.good();
558 ++vIter, ++aIter, ++numIter
567 meshSumVol += vIter();
568 alphaSumVol += aIter();
581 Info<<
" Patch connected regions (liquid core):" <<
nl;
589 const label regioni = iter.key();
600 Info<<
" Background regions:" <<
nl;
606 auto vIter = allRegionVolume.cbegin();
607 auto aIter = allRegionAlphaVolume.cbegin();
612 vIter.good() && aIter.good();
618 !patchRegions.found(vIter.key())
619 && vIter() >= maxDropletVol
638 writeAlphaFields(regions, patchRegions, allRegionVolume,
alpha);
649 const label regioni = vIter.key();
652 patchRegions.found(regioni)
653 || vIter() >= maxDropletVol
654 || (allRegionAlphaVolume[regioni]/vIter() < threshold_)
657 allRegionVolume.erase(vIter);
658 allRegionAlphaVolume.erase(regioni);
659 allRegionNumCells.erase(regioni);
663 if (allRegionVolume.size())
675 const coordSet coords(
"diameter",
"x", xBin,
mag(xBin));
681 const labelList sortedRegions = allRegionAlphaVolume.sortedToc();
699 (
alpha.primitiveField()*mesh_.V())
700 *(mesh_.C().primitiveField() - origin_)()
703 Map<vector> allRegionAlphaDistance
718 allRegionAlphaDistance
722 centroids = sortedMoment/sortedVols + origin_;
725 scalarField distToPlane((centroids - origin_) & direction_);
729 (centroids - origin_) - (distToPlane*direction_)
732 const scalar deltaX = maxDownstream_/nDownstreamBins_;
733 labelList downstreamIndices(distToPlane.size(), -1);
738 (
mag(radialDistToOrigin[i]) < maxDiameter_)
739 && (distToPlane[i] < maxDownstream_)
742 downstreamIndices[i] = distToPlane[i]/deltaX;
749 if (downstreamIndices[i] != -1)
751 binDownCount[downstreamIndices[i]] += 1.0;
761 scalar
x = 0.5*deltaX;
768 const coordSet coords(
"distance",
"x", xBin,
mag(xBin));
769 writeGraph(coords,
"isoPlanes", binDownCount);
775 Info<<
" Iso-planes Bins:" <<
nl
782 forAll(binDownCount, bini)
796 forAll(sortedDiameters, i)
806 labelList indices(sortedDiameters.size());
807 forAll(sortedDiameters, i)
809 indices[i] = (sortedDiameters[i]-minDiam_)/
delta;
814 forAll(sortedDiameters, i)
816 binCount[indices[i]] += 1.0;
822 writeGraph(coords,
"count", binCount);
860 wordList scalarNames(obr_.names(volScalarField::typeName));
862 const labelList selected(fields_.matching(scalarNames));
864 for (
const label fieldi : selected)
866 const word& fldName = scalarNames[fieldi];
868 Log <<
" Scalar field " << fldName <<
endl;
873 >(fldName).primitiveField();
891 wordList vectorNames(obr_.names(volVectorField::typeName));
893 const labelList selected(fields_.matching(vectorNames));
895 for (
const label fieldi : selected)
897 const word& fldName = vectorNames[fieldi];
899 Log <<
" Vector field " << fldName <<
endl;
904 >(fldName).primitiveField();
908 Log <<
"Transforming vector field " << fldName
909 <<
" with coordinate system "
913 fld = csysPtr_->localVector(
fld);
924 alphaVol*
fld.component(cmp),