39 namespace functionObjects
45 regionSizeDistribution,
65 const label regioni = regions[celli];
66 regionToSum(regioni, Type(
Zero)) +=
fld[celli];
78 List<Type> sortedData(keys.size());
82 sortedData[i] = regionData[keys[i]];
92 void Foam::functionObjects::regionSizeDistribution::writeAlphaFields
94 const regionSplit& regions,
95 const Map<label>& patchRegions,
96 const Map<scalar>& regionVolume,
100 const scalar maxDropletVol = 1.0/6.0*
pow3(maxDiam_);
141 const label regioni = regions[celli];
142 if (patchRegions.found(regioni))
144 backgroundAlpha[celli] = 0;
148 liquidCore[celli] = 0;
150 const scalar regionVol = regionVolume[regioni];
151 if (regionVol < maxDropletVol)
153 backgroundAlpha[celli] = 0;
157 liquidCore.correctBoundaryConditions();
158 backgroundAlpha.correctBoundaryConditions();
162 Info<<
" Volume of liquid-core = " 165 <<
" Volume of background = " 170 Log <<
" Writing liquid-core field to " << liquidCore.name() <<
endl;
173 Log<<
" Writing background field to " << backgroundAlpha.name() <<
endl;
174 backgroundAlpha.
write();
179 Foam::functionObjects::regionSizeDistribution::findPatchRegions
181 const regionSplit& regions
188 const labelHashSet patchIDs(mesh_.boundaryMesh().patchSet(patchNames_));
190 label nPatchFaces = 0;
191 for (
const label patchi : patchIDs)
193 nPatchFaces += mesh_.boundaryMesh()[patchi].
size();
197 Map<label> patchRegions(nPatchFaces);
198 for (
const label patchi : patchIDs)
200 const polyPatch& pp = mesh_.boundaryMesh()[patchi];
203 const labelList& faceCells = pp.faceCells();
205 for (
const label celli : faceCells)
224 Foam::functionObjects::regionSizeDistribution::divide
231 auto& result = tresult.ref();
237 result[i] = num[i]/denom[i];
248 void Foam::functionObjects::regionSizeDistribution::writeGraphs
250 const word& fieldName,
255 const coordSet& coords
264 binSum[indices[i]] += sortedField[i];
273 binSqrSum[indices[i]] +=
Foam::sqr(sortedField[i]);
281 auto&
writer = formatterPtr_();
311 Log <<
" Writing distribution of " 312 << fieldName <<
" to " <<
writer.path() <<
endl;
314 writer.write(fieldName +
"_sum", binSum);
315 writer.write(fieldName +
"_avg", binAvg);
316 writer.write(fieldName +
"_dev", binDev);
322 void Foam::functionObjects::regionSizeDistribution::writeGraphs
324 const word& fieldName,
326 const regionSplit& regions,
332 const coordSet& coords
336 Map<scalar> regionField(
regionSum(regions, cellField));
370 isoPlanes_(
dict.getOrDefault(
"isoPlanes", false))
383 dict.readEntry(
"nBins", nBins_);
384 dict.readEntry(
"field", alphaName_);
385 dict.readEntry(
"threshold", threshold_);
386 dict.readEntry(
"maxDiameter", maxDiam_);
388 dict.readIfPresent(
"minDiameter", minDiam_);
389 dict.readEntry(
"patches", patchNames_);
390 dict.readEntry(
"fields", fields_);
396 dict.subOrEmptyDict(
"formatOptions").optionalSubDict(
setFormat)
399 csysPtr_ = coordinateSystem::NewIfPresent(obr_,
dict);
403 Info<<
"Transforming all vectorFields with coordinate system " 404 << csysPtr_->name() <<
endl;
409 dict.readEntry(
"origin", origin_);
410 dict.readEntry(
"direction", direction_);
411 dict.readEntry(
"maxD", maxDiameter_);
412 dict.readEntry(
"nDownstreamBins", nDownstreamBins_);
413 dict.readEntry(
"maxDownstream", maxDownstream_);
414 direction_.normalise();
435 Log <<
" Looking up field " << alphaName_ <<
endl;
439 Info<<
" Reading field " << alphaName_ <<
endl;
447 mesh_.time().timeName(),
456 const auto&
alpha = talpha();
458 Log <<
" Volume of alpha = " 462 const scalar meshVol =
gSum(mesh_.V());
463 const scalar maxDropletVol = 1.0/6.0*
pow3(maxDiam_);
464 const scalar
delta = (maxDiam_-minDiam_)/nBins_;
466 Log <<
" Mesh volume = " << meshVol <<
nl 467 <<
" Maximum droplet diameter = " << maxDiam_ <<
nl 468 <<
" Maximum droplet volume = " << maxDropletVol
473 boolList blockedFace(mesh_.nFaces(),
false);
477 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
479 scalar ownVal =
alpha[mesh_.faceOwner()[facei]];
480 scalar neiVal =
alpha[mesh_.faceNeighbour()[facei]];
484 (ownVal < threshold_ && neiVal > threshold_)
485 || (ownVal > threshold_ && neiVal < threshold_)
488 blockedFace[facei] =
true;
499 tmp<scalarField> townFld(fvp.patchInternalField());
500 tmp<scalarField> tnbrFld(fvp.patchNeighbourField());
501 const auto& ownFld = townFld();
502 const auto& nbrFld = tnbrFld();
504 label start = fvp.patch().patch().start();
508 scalar ownVal = ownFld[i];
509 scalar neiVal = nbrFld[i];
513 (ownVal < threshold_ && neiVal > threshold_)
514 || (ownVal > threshold_ && neiVal < threshold_)
517 blockedFace[start+i] =
true;
526 regionSplit regions(mesh_, blockedFace);
528 Log <<
" Determined " << regions.nRegions()
529 <<
" disconnected regions" <<
endl;
539 mesh_.time().timeName(),
547 Info<<
" Dumping region as volScalarField to " << region.name()
552 region[celli] = regions[celli];
554 region.correctBoundaryConditions();
560 Map<label> patchRegions(findPatchRegions(regions));
565 Map<scalar> allRegionVolume(
regionSum(regions, mesh_.V()));
566 Map<scalar> allRegionAlphaVolume(
regionSum(regions, alphaVol));
567 Map<label> allRegionNumCells
583 scalar meshSumVol = 0.0;
584 scalar alphaSumVol = 0.0;
587 auto vIter = allRegionVolume.cbegin();
588 auto aIter = allRegionAlphaVolume.cbegin();
589 auto numIter = allRegionNumCells.cbegin();
593 vIter.good() && aIter.good();
594 ++vIter, ++aIter, ++numIter
603 meshSumVol += vIter();
604 alphaSumVol += aIter();
617 Info<<
" Patch connected regions (liquid core):" <<
nl;
625 const label regioni = iter.key();
636 Info<<
" Background regions:" <<
nl;
642 auto vIter = allRegionVolume.cbegin();
643 auto aIter = allRegionAlphaVolume.cbegin();
648 vIter.good() && aIter.good();
654 !patchRegions.found(vIter.key())
655 && vIter() >= maxDropletVol
674 writeAlphaFields(regions, patchRegions, allRegionVolume,
alpha);
685 const label regioni = vIter.key();
688 patchRegions.found(regioni)
689 || vIter() >= maxDropletVol
690 || (allRegionAlphaVolume[regioni]/vIter() < threshold_)
693 allRegionVolume.erase(vIter);
694 allRegionAlphaVolume.erase(regioni);
695 allRegionNumCells.erase(regioni);
699 if (allRegionVolume.size())
713 const coordSet coords(
"diameter",
"x", xBin,
mag(xBin));
719 const labelList sortedRegions = allRegionAlphaVolume.sortedToc();
733 (
alpha.primitiveField()*mesh_.V())
734 *(mesh_.C().primitiveField() - origin_)()
737 Map<vector> allRegionAlphaDistance
752 centroids = sortedMoment/sortedVols + origin_;
755 scalarField distToPlane((centroids - origin_) & direction_);
759 (centroids - origin_) - (distToPlane*direction_)
762 const scalar deltaX = maxDownstream_/nDownstreamBins_;
763 labelList downstreamIndices(distToPlane.size(), -1);
768 (
mag(radialDistToOrigin[i]) < maxDiameter_)
769 && (distToPlane[i] < maxDownstream_)
772 downstreamIndices[i] = distToPlane[i]/deltaX;
779 if (downstreamIndices[i] != -1)
781 binDownCount[downstreamIndices[i]] += 1.0;
792 scalar
x = 0.5*deltaX;
800 const coordSet coords(
"distance",
"x", xBin,
mag(xBin));
802 auto&
writer = formatterPtr_();
811 writer.write(
"isoPlanes", binDownCount);
818 Info<<
" Iso-planes Bins:" <<
nl 825 forAll(binDownCount, bini)
839 forAll(sortedDiameters, i)
849 labelList indices(sortedDiameters.size());
850 forAll(sortedDiameters, i)
852 indices[i] = (sortedDiameters[i]-minDiam_)/
delta;
857 forAll(sortedDiameters, i)
859 binCount[indices[i]] += 1.0;
865 auto&
writer = formatterPtr_();
874 writer.write(
"count", binCount);
920 Log <<
" Scalar field " << fldName <<
endl;
922 tmp<Field<scalar>> tfld
926 const auto&
fld = tfld();
951 Log <<
" Vector field " << fldName <<
endl;
953 tmp<Field<vector>> tfld
960 Log <<
"Transforming vector field " << fldName
961 <<
" with coordinate system " 965 tfld = csysPtr_->localVector(tfld());
967 const auto&
fld = tfld();
971 for (
direction cmpt = 0; cmpt < vector::nComponents; ++cmpt)
975 fldName + vector::componentNames[cmpt],
976 alphaVol*
fld.component(cmpt),
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
Field< label > labelField
Specialisation of Field<T> for label.
defineTypeNameAndDebug(ObukhovLength, 0)
virtual bool write()
Calculate the regionSizeDistribution and write.
const Internal::FieldType & primitiveField() const noexcept
Return a const-reference to the internal field values.
dimensionedScalar log(const dimensionedScalar &ds)
virtual bool execute()
Do nothing.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
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)
label size() const noexcept
The number of elements in table.
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
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.
static const word & calculatedType()
The type name for calculated patch fields.
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) 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 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.
const Time & time() const noexcept
Return time registry.
static Map< Type > regionSum(const regionSplit ®ions, const Field< Type > &fld)
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.
bool log
Flag to write log into Info.
fileName baseTimeDir() const
Return the base directory for the current time value.
virtual bool read(const dictionary &)
Read the regionSizeDistribution data.
static word timeName(const scalar t, const int precision=precision_)
Return time name of given scalar time formatted with the given precision.
int debug
Static debugging option.
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
virtual bool read(const dictionary &dict)
Read.
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
A List of words.
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)
Am I the master rank.
const objectRegistry & obr_
Reference to the region objectRegistry.
label nRegions() const
Return total number of regions.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool read(const dictionary &dict)
Read optional controls.
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.
word scopedName(const word &name) const
Return a scoped (prefixed) name.
void reset(tmp< T > &&other) noexcept
Clear existing and transfer ownership.
forAllConstIters(mixture.phases(), phase)
A HashTable to objects of type <T> with a label key.
static constexpr const zero Zero
Global zero (0)