42 namespace functionObjects
48 regionSizeDistribution,
68 const label regioni = regions[celli];
69 regionToSum(regioni, Type(
Zero)) +=
fld[celli];
78 static Map<label>
regionSum(
const regionSplit& regions,
const label nCells)
83 for (label celli = 0; celli < nCells; ++celli)
85 const label regioni = regions[celli];
86 ++regionToSum(regioni);
98 List<Type> sortedData(keys.size());
102 sortedData[i] = regionData[keys[i]];
112 void Foam::functionObjects::regionSizeDistribution::writeAlphaFields
114 const regionSplit& regions,
116 const Map<scalar>& regionVolume,
135 scopedName(alphaName_ +
"_liquidCore"),
136 obr_.time().timeName(),
148 scopedName(alphaName_ +
"_background"),
149 obr_.time().timeName(),
161 const label regioni = regions[celli];
162 if (keepRegions.found(regioni))
164 backgroundAlpha[celli] = 0;
168 liquidCore[celli] = 0;
170 const scalar regionVol = regionVolume[regioni];
171 if (regionVol < maxDropletVol)
173 backgroundAlpha[celli] = 0;
177 liquidCore.correctBoundaryConditions();
178 backgroundAlpha.correctBoundaryConditions();
182 Info<<
" Volume of liquid-core = " 185 <<
" Volume of background = " 190 Log <<
" Writing liquid-core field to " << liquidCore.name() <<
endl;
193 Log<<
" Writing background field to " << backgroundAlpha.name() <<
endl;
194 backgroundAlpha.
write();
199 Foam::functionObjects::regionSizeDistribution::findPatchRegions
201 const regionSplit& regions
209 labelHashSet patchSet(mesh_.boundaryMesh().patchSet(patchNames_));
211 for (
const label patchi : patchSet)
213 const polyPatch&
pp = mesh_.boundaryMesh()[patchi];
216 for (
const label celli :
pp.faceCells())
218 patchRegions.insert(regions[celli]);
230 Foam::functionObjects::regionSizeDistribution::divide
237 auto& result = tresult.ref();
243 result[i] = num[i]/denom[i];
250 void Foam::functionObjects::regionSizeDistribution::writeGraphs
252 const word& fieldName,
257 const coordSet& coords
266 binSum[indices[i]] += sortedField[i];
275 binSqrSum[indices[i]] +=
Foam::sqr(sortedField[i]);
283 auto&
writer = formatterPtr_();
313 Log <<
" Writing distribution of " 314 << fieldName <<
" to " <<
writer.path() <<
endl;
316 writer.write(fieldName +
"_sum", binSum);
317 writer.write(fieldName +
"_avg", binAvg);
318 writer.write(fieldName +
"_dev", binDev);
324 void Foam::functionObjects::regionSizeDistribution::writeGraphs
326 const word& fieldName,
328 const regionSplit& regions,
334 const coordSet& coords
338 Map<scalar> regionField(
regionSum(regions, cellField));
372 isoPlanes_(
dict.getOrDefault(
"isoPlanes", false))
385 dict.readEntry(
"nBins", nBins_);
386 dict.readEntry(
"field", alphaName_);
387 dict.readEntry(
"threshold", threshold_);
388 dict.readEntry(
"maxDiameter", maxDiam_);
390 dict.readIfPresent(
"minDiameter", minDiam_);
391 dict.readEntry(
"patches", patchNames_);
392 dict.readEntry(
"fields", fields_);
398 dict.subOrEmptyDict(
"formatOptions").optionalSubDict(
setFormat)
401 csysPtr_ = coordinateSystem::NewIfPresent(obr_,
dict);
405 Info<<
"Transforming all vectorFields with coordinate system " 406 << csysPtr_->name() <<
endl;
411 dict.readEntry(
"origin", origin_);
412 dict.readEntry(
"direction", direction_);
413 dict.readEntry(
"maxD", maxDiameter_);
414 dict.readEntry(
"nDownstreamBins", nDownstreamBins_);
415 dict.readEntry(
"maxDownstream", maxDownstream_);
416 direction_.normalise();
437 Log <<
" Looking up field " << alphaName_ <<
endl;
441 Info<<
" Reading field " << alphaName_ <<
endl;
449 mesh_.time().timeName(),
459 const auto&
alpha = talpha();
461 Log <<
" Volume of alpha = " 465 const scalar meshVol =
gSum(mesh_.V());
467 const scalar
delta = (maxDiam_-minDiam_)/nBins_;
469 Log <<
" Mesh volume = " << meshVol <<
nl 470 <<
" Maximum droplet diameter = " << maxDiam_ <<
nl 471 <<
" Maximum droplet volume = " << maxDropletVol
476 boolList blockedFace(mesh_.nFaces(),
false);
480 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
482 scalar ownVal =
alpha[mesh_.faceOwner()[facei]];
483 scalar neiVal =
alpha[mesh_.faceNeighbour()[facei]];
487 (ownVal < threshold_ && neiVal > threshold_)
488 || (ownVal > threshold_ && neiVal < threshold_)
491 blockedFace[facei] =
true;
502 tmp<scalarField> townFld(fvp.patchInternalField());
503 tmp<scalarField> tnbrFld(fvp.patchNeighbourField());
504 const auto& ownFld = townFld();
505 const auto& nbrFld = tnbrFld();
507 label start = fvp.patch().patch().start();
511 scalar ownVal = ownFld[i];
512 scalar neiVal = nbrFld[i];
516 (ownVal < threshold_ && neiVal > threshold_)
517 || (ownVal > threshold_ && neiVal < threshold_)
520 blockedFace[start+i] =
true;
529 regionSplit regions(mesh_, blockedFace);
531 Log <<
" Determined " << regions.nRegions()
532 <<
" disconnected regions" <<
endl;
539 mesh_.newIOobject(
"region"),
544 Info<<
" Dumping region as volScalarField to " 545 << region.name() <<
endl;
549 region[celli] = regions[celli];
551 region.correctBoundaryConditions();
557 const labelHashSet patchRegions(findPatchRegions(regions));
561 Map<scalar> allRegionVolume(
regionSum(regions, mesh_.V()));
562 Map<scalar> allRegionAlphaVolume(
regionSum(regions, alphaVol));
563 Map<label> allRegionNumCells(
regionSum(regions, mesh_.nCells()));
572 scalar meshSumVol = 0.0;
573 scalar alphaSumVol = 0.0;
576 auto vIter = allRegionVolume.cbegin();
577 auto aIter = allRegionAlphaVolume.cbegin();
578 auto numIter = allRegionNumCells.cbegin();
582 vIter.good() && aIter.good();
583 ++vIter, ++aIter, ++numIter
592 meshSumVol += vIter();
593 alphaSumVol += aIter();
606 Info<<
" Patch connected regions (liquid core):" <<
nl;
612 for (
const label regioni : patchRegions.sortedToc())
624 Info<<
" Background regions:" <<
nl;
630 auto vIter = allRegionVolume.cbegin();
631 auto aIter = allRegionAlphaVolume.cbegin();
636 vIter.good() && aIter.good();
642 !patchRegions.found(vIter.key())
643 && vIter() >= maxDropletVol
662 writeAlphaFields(regions, patchRegions, allRegionVolume,
alpha);
673 const label regioni = vIter.key();
676 patchRegions.found(regioni)
677 || vIter() >= maxDropletVol
678 || (allRegionAlphaVolume[regioni]/vIter() < threshold_)
681 allRegionVolume.erase(vIter);
682 allRegionAlphaVolume.erase(regioni);
683 allRegionNumCells.erase(regioni);
687 if (allRegionVolume.size())
701 const coordSet coords(
"diameter",
"x", xBin,
mag(xBin));
707 const labelList sortedRegions = allRegionAlphaVolume.sortedToc();
721 (
alpha.primitiveField()*mesh_.V())
722 *(mesh_.C().primitiveField() - origin_)()
725 Map<vector> allRegionAlphaDistance
740 centroids = sortedMoment/sortedVols + origin_;
743 scalarField distToPlane((centroids - origin_) & direction_);
747 (centroids - origin_) - (distToPlane*direction_)
750 const scalar deltaX = maxDownstream_/nDownstreamBins_;
751 labelList downstreamIndices(distToPlane.size(), -1);
756 (
mag(radialDistToOrigin[i]) < maxDiameter_)
757 && (distToPlane[i] < maxDownstream_)
760 downstreamIndices[i] = distToPlane[i]/deltaX;
767 if (downstreamIndices[i] != -1)
769 binDownCount[downstreamIndices[i]] += 1.0;
780 scalar
x = 0.5*deltaX;
788 const coordSet coords(
"distance",
"x", xBin,
mag(xBin));
790 auto&
writer = formatterPtr_();
796 writeFile::baseTimeDir() / (coords.name() +
"_isoPlanes")
799 writer.write(
"isoPlanes", binDownCount);
806 Info<<
" Iso-planes Bins:" <<
nl 813 forAll(binDownCount, bini)
827 forAll(sortedDiameters, i)
837 labelList indices(sortedDiameters.size());
838 forAll(sortedDiameters, i)
840 indices[i] = (sortedDiameters[i]-minDiam_)/
delta;
845 forAll(sortedDiameters, i)
847 binCount[indices[i]] += 1.0;
853 auto&
writer = formatterPtr_();
859 writeFile::baseTimeDir() / (coords.name() +
"_count")
862 writer.write(
"count", binCount);
908 const word& fldName = vfield.name();
910 Log <<
" Scalar field " << fldName <<
endl;
912 tmp<Field<scalar>> tfld(vfield.primitiveField());
913 const auto&
fld = tfld();
938 const word& fldName = vfield.name();
940 Log <<
" Vector field " << fldName <<
endl;
942 tmp<Field<vector>> tfld(vfield.primitiveField());
946 Log <<
"Transforming vector field " << fldName
947 <<
" with coordinate system " 948 << csysPtr_->name() <<
endl;
950 tfld = csysPtr_->localVector(tfld());
952 const auto&
fld = tfld();
960 fldName + vector::componentNames[cmpt],
961 alphaVol*
fld.component(cmpt),
Different types of constants.
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
void divide(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
virtual bool write()
Calculate the regionSizeDistribution and write.
dimensionedScalar log(const dimensionedScalar &ds)
virtual bool execute()
Do nothing.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
A list of keyword definitions, which are a keyword followed by a number of values (eg...
dimensionedSymmTensor sqr(const dimensionedVector &dv)
constexpr char nl
The newline '\n' character (0x0a)
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
dimensioned< Type > domainIntegrate(const GeometricField< Type, fvPatchField, volMesh > &vf)
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
GeometricField< vector, fvPatchField, volMesh > volVectorField
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
regionSizeDistribution(const word &name, const Time &runTime, const dictionary &)
Construct for given objectRegistry and dictionary.
Macros for easy insertion into run-time selection tables.
UList< label > labelUList
A UList of labels.
bool read(const char *buf, int32_t &val)
Same as readInt32.
#define forAll(list, i)
Loop across all elements in list.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
static word suffix(const word &fldName, const word &fileExt=word::null)
Name suffix based on fieldName (underscore separator)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
static autoPtr< coordSetWriter > New(const word &writeFormat)
Return a reference to the selected writer.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
word outputName("finiteArea-edges.obj")
vectorField pointField
pointField is a vectorField.
Type gSum(const FieldField< Field, Type > &f)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Generic templated field type.
fvPatchField< scalar > fvPatchScalarField
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
static Map< Type > regionSum(const regionSplit ®ions, const Field< Type > &fld)
static void combineReduce(T &value, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors...
dimensionedScalar cbrt(const dimensionedScalar &ds)
static List< Type > extractData(const labelUList &keys, const Map< Type > ®ionData)
#define forAllIters(container, iter)
Iterate across all elements in the container object.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
A List of wordRe with additional matching capabilities.
constexpr scalar pi(M_PI)
Volume integrate volField creating a volField.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
virtual bool read(const dictionary &)
Read the regionSizeDistribution data.
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const word & name() const noexcept
Return const reference to name.
List< word > wordList
List of word.
dimensionedScalar pow3(const dimensionedScalar &ds)
vector point
Point is a vector.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static const word & calculatedType() noexcept
The type name for calculated patch fields.
label nRegions() const
Return total number of regions.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Field< vector > vectorField
Specialisation of Field<T> for vector.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
word setFormat(propsDict.getOrDefault< word >("setFormat", "vtk"))
List< label > labelList
A List of labels.
A class for managing temporary objects.
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
static void mapCombineReduce(Container &values, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine map values from different processo...
Base class for writing single files from the function objects.
Defines the attributes of an object for which implicit objectRegistry management is supported...
List< bool > boolList
A List of bools.
Do not request registration (bool: false)
void reset(tmp< T > &&other) noexcept
Clear existing and transfer ownership.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
A HashTable to objects of type <T> with a label key.
static constexpr const zero Zero
Global zero (0)