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(),
458 const auto&
alpha = talpha();
460 Log <<
" Volume of alpha = " 464 const scalar meshVol =
gSum(mesh_.V());
466 const scalar
delta = (maxDiam_-minDiam_)/nBins_;
468 Log <<
" Mesh volume = " << meshVol <<
nl 469 <<
" Maximum droplet diameter = " << maxDiam_ <<
nl 470 <<
" Maximum droplet volume = " << maxDropletVol
475 boolList blockedFace(mesh_.nFaces(),
false);
479 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
481 scalar ownVal =
alpha[mesh_.faceOwner()[facei]];
482 scalar neiVal =
alpha[mesh_.faceNeighbour()[facei]];
486 (ownVal < threshold_ && neiVal > threshold_)
487 || (ownVal > threshold_ && neiVal < threshold_)
490 blockedFace[facei] =
true;
501 tmp<scalarField> townFld(fvp.patchInternalField());
502 tmp<scalarField> tnbrFld(fvp.patchNeighbourField());
503 const auto& ownFld = townFld();
504 const auto& nbrFld = tnbrFld();
506 label start = fvp.patch().patch().start();
510 scalar ownVal = ownFld[i];
511 scalar neiVal = nbrFld[i];
515 (ownVal < threshold_ && neiVal > threshold_)
516 || (ownVal > threshold_ && neiVal < threshold_)
519 blockedFace[start+i] =
true;
528 regionSplit regions(mesh_, blockedFace);
530 Log <<
" Determined " << regions.nRegions()
531 <<
" disconnected regions" <<
endl;
541 mesh_.time().timeName(),
550 Info<<
" Dumping region as volScalarField to " 551 << region.name() <<
endl;
555 region[celli] = regions[celli];
557 region.correctBoundaryConditions();
563 const labelHashSet patchRegions(findPatchRegions(regions));
567 Map<scalar> allRegionVolume(
regionSum(regions, mesh_.V()));
568 Map<scalar> allRegionAlphaVolume(
regionSum(regions, alphaVol));
569 Map<label> allRegionNumCells(
regionSum(regions, mesh_.nCells()));
578 scalar meshSumVol = 0.0;
579 scalar alphaSumVol = 0.0;
582 auto vIter = allRegionVolume.cbegin();
583 auto aIter = allRegionAlphaVolume.cbegin();
584 auto numIter = allRegionNumCells.cbegin();
588 vIter.good() && aIter.good();
589 ++vIter, ++aIter, ++numIter
598 meshSumVol += vIter();
599 alphaSumVol += aIter();
612 Info<<
" Patch connected regions (liquid core):" <<
nl;
618 for (
const label regioni : patchRegions.sortedToc())
630 Info<<
" Background regions:" <<
nl;
636 auto vIter = allRegionVolume.cbegin();
637 auto aIter = allRegionAlphaVolume.cbegin();
642 vIter.good() && aIter.good();
648 !patchRegions.found(vIter.key())
649 && vIter() >= maxDropletVol
668 writeAlphaFields(regions, patchRegions, allRegionVolume,
alpha);
679 const label regioni = vIter.key();
682 patchRegions.found(regioni)
683 || vIter() >= maxDropletVol
684 || (allRegionAlphaVolume[regioni]/vIter() < threshold_)
687 allRegionVolume.erase(vIter);
688 allRegionAlphaVolume.erase(regioni);
689 allRegionNumCells.erase(regioni);
693 if (allRegionVolume.size())
707 const coordSet coords(
"diameter",
"x", xBin,
mag(xBin));
713 const labelList sortedRegions = allRegionAlphaVolume.sortedToc();
727 (
alpha.primitiveField()*mesh_.V())
728 *(mesh_.C().primitiveField() - origin_)()
731 Map<vector> allRegionAlphaDistance
746 centroids = sortedMoment/sortedVols + origin_;
749 scalarField distToPlane((centroids - origin_) & direction_);
753 (centroids - origin_) - (distToPlane*direction_)
756 const scalar deltaX = maxDownstream_/nDownstreamBins_;
757 labelList downstreamIndices(distToPlane.size(), -1);
762 (
mag(radialDistToOrigin[i]) < maxDiameter_)
763 && (distToPlane[i] < maxDownstream_)
766 downstreamIndices[i] = distToPlane[i]/deltaX;
773 if (downstreamIndices[i] != -1)
775 binDownCount[downstreamIndices[i]] += 1.0;
786 scalar
x = 0.5*deltaX;
794 const coordSet coords(
"distance",
"x", xBin,
mag(xBin));
796 auto&
writer = formatterPtr_();
802 writeFile::baseTimeDir() / (coords.name() +
"_isoPlanes")
805 writer.write(
"isoPlanes", binDownCount);
812 Info<<
" Iso-planes Bins:" <<
nl 819 forAll(binDownCount, bini)
833 forAll(sortedDiameters, i)
843 labelList indices(sortedDiameters.size());
844 forAll(sortedDiameters, i)
846 indices[i] = (sortedDiameters[i]-minDiam_)/
delta;
851 forAll(sortedDiameters, i)
853 binCount[indices[i]] += 1.0;
859 auto&
writer = formatterPtr_();
865 writeFile::baseTimeDir() / (coords.name() +
"_count")
868 writer.write(
"count", binCount);
914 const word& fldName = vfield.name();
916 Log <<
" Scalar field " << fldName <<
endl;
918 tmp<Field<scalar>> tfld(vfield.primitiveField());
919 const auto&
fld = tfld();
944 const word& fldName = vfield.name();
946 Log <<
" Vector field " << fldName <<
endl;
948 tmp<Field<vector>> tfld(vfield.primitiveField());
952 Log <<
"Transforming vector field " << fldName
953 <<
" with coordinate system " 954 << csysPtr_->name() <<
endl;
956 tfld = csysPtr_->localVector(tfld());
958 const auto&
fld = tfld();
966 fldName + vector::componentNames[cmpt],
967 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)
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.
static void combineReduce(const List< commsStruct > &comms, 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...
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)