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

View File

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

View File

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