ENH: Particle PatchPostProcessing - enable users to filter particle property output

The optional 'fields' entry can be used to limit which particle fields are
written to file.  If empty/not specified, all properties are written to
maintain backwards compatibility.

    patchPostProcessing1
    {
        type            patchPostProcessing;
        maxStoredParcels 20;
        fields          (position "U.*" d T nParticle);
        patches
        (
            cycLeft_half0
            cycLeft_half1
        );
    }
This commit is contained in:
Andrew Heather
2019-12-09 23:31:01 +00:00
committed by Mark Olesen
parent 6748f10d5d
commit e1a7c0ed1d
3 changed files with 44 additions and 31 deletions

View File

@ -40,15 +40,7 @@ Foam::label Foam::PatchPostProcessing<CloudType>::applyToPatch
const label globalPatchi
) const
{
forAll(patchIDs_, i)
{
if (patchIDs_[i] == globalPatchi)
{
return i;
}
}
return -1;
return patchIDs_.find(globalPatchi);
}
@ -100,7 +92,7 @@ void Foam::PatchPostProcessing<CloudType>::write()
labelList indices(sortedOrder(globalTimes));
string header("# Time currentProc " + parcelType::propertyList_);
string header("# Time currentProc " + header_);
patchOutFile<< header.c_str() << nl;
forAll(globalTimes, i)
@ -132,37 +124,40 @@ Foam::PatchPostProcessing<CloudType>::PatchPostProcessing
:
CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
maxStoredParcels_(this->coeffDict().getScalar("maxStoredParcels")),
fields_(),
patchIDs_(),
times_(),
patchData_()
patchData_(),
header_()
{
const wordList allPatchNames(owner.mesh().boundaryMesh().names());
const wordReList patchNames(this->coeffDict().lookup("patches"));
// The "fields" filter is optional
this->coeffDict().readIfPresent("fields", fields_);
labelHashSet uniqIds;
for (const wordRe& re : patchNames)
// The "patches" are required
const wordRes patchMatcher(this->coeffDict().lookup("patches"));
patchIDs_ = patchMatcher.matching(owner.mesh().boundaryMesh().names());
if (patchIDs_.empty())
{
labelList ids = findStrings(re, allPatchNames);
if (ids.empty())
{
WarningInFunction
<< "Cannot find any patch names matching " << re
<< endl;
}
uniqIds.insert(ids);
WarningInFunction
<< "No matching patches found: "
<< flatOutput(patchMatcher) << nl;
}
patchIDs_ = uniqIds.sortedToc();
if (debug)
{
Info<< "Post-process fields "
<< flatOutput(fields_) << nl;
Info<< "On patches (";
for (const label patchi : patchIDs_)
{
Info<< "Post-process patch "
<< owner.mesh().boundaryMesh()[patchi].name() << endl;
Info<< ' ' << owner.mesh().boundaryMesh()[patchi].name();
}
Info<< " )" << nl;
}
patchData_.setSize(patchIDs_.size());
@ -178,9 +173,11 @@ Foam::PatchPostProcessing<CloudType>::PatchPostProcessing
:
CloudFunctionObject<CloudType>(ppm),
maxStoredParcels_(ppm.maxStoredParcels_),
fields_(ppm.fields_),
patchIDs_(ppm.patchIDs_),
times_(ppm.times_),
patchData_(ppm.patchData_)
patchData_(ppm.patchData_),
header_(ppm.header_)
{}
@ -197,12 +194,20 @@ void Foam::PatchPostProcessing<CloudType>::postPatch
const label patchi = pp.index();
const label localPatchi = applyToPatch(patchi);
if (header_.empty())
{
OStringStream data;
p.writeProperties(data, fields_, " ", true);
header_ = data.str();
}
if (localPatchi != -1 && patchData_[localPatchi].size() < maxStoredParcels_)
{
times_[localPatchi].append(this->owner().time().value());
OStringStream data;
data<< Pstream::myProcNo() << ' ' << p;
data<< Pstream::myProcNo();
p.writeProperties(data, fields_, " ", false);
patchData_[localPatchi].append(data.str());
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -63,6 +64,9 @@ class PatchPostProcessing
//- Maximum number of parcels to store - set as a scalar for I/O
scalar maxStoredParcels_;
//- Field name filters
wordRes fields_;
//- List of patch indices to post-process
labelList patchIDs_;
@ -72,6 +76,9 @@ class PatchPostProcessing
//- List of output data per patch
List<DynamicList<string>> patchData_;
//- Field header
string header_;
// Private Member Functions

View File

@ -164,6 +164,7 @@ cloudFunctions
patchPostProcessing1
{
type patchPostProcessing;
fields (position "U.*" d T nParticle);
maxStoredParcels 20;
patches
(