ENH: probes: filter out points that cannot be found. Fixes #492.

This commit is contained in:
mattijs
2017-06-07 16:33:06 +01:00
parent f31d5cf217
commit 74cfb1906f
3 changed files with 43 additions and 10 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -58,6 +58,9 @@ void Foam::probes::findElements(const fvMesh& mesh)
faceList_.clear(); faceList_.clear();
faceList_.setSize(size()); faceList_.setSize(size());
processor_.setSize(size());
processor_ = -1;
forAll(*this, probei) forAll(*this, probei)
{ {
const vector& location = operator[](probei); const vector& location = operator[](probei);
@ -105,9 +108,12 @@ void Foam::probes::findElements(const fvMesh& mesh)
label celli = elementList_[probei]; label celli = elementList_[probei];
label facei = faceList_[probei]; label facei = faceList_[probei];
processor_[probei] = (celli != -1 ? Pstream::myProcNo() : -1);
// Check at least one processor with cell. // Check at least one processor with cell.
reduce(celli, maxOp<label>()); reduce(celli, maxOp<label>());
reduce(facei, maxOp<label>()); reduce(facei, maxOp<label>());
reduce(processor_[probei], maxOp<label>());
if (celli == -1) if (celli == -1)
{ {
@ -240,8 +246,13 @@ Foam::label Foam::probes::prepare()
forAll(*this, probei) forAll(*this, probei)
{ {
fout<< "# Probe " << probei << ' ' << operator[](probei) fout<< "# Probe " << probei << ' ' << operator[](probei);
<< endl;
if (processor_[probei] == -1)
{
fout<< " # Not Found";
}
fout<< endl;
} }
fout<< '#' << setw(IOstream::defaultPrecision() + 6) fout<< '#' << setw(IOstream::defaultPrecision() + 6)
@ -249,7 +260,10 @@ Foam::label Foam::probes::prepare()
forAll(*this, probei) forAll(*this, probei)
{ {
fout<< ' ' << setw(w) << probei; if (includeOutOfBounds_ || processor_[probei] != -1)
{
fout<< ' ' << setw(w) << probei;
}
} }
fout<< endl; fout<< endl;
@ -288,7 +302,8 @@ Foam::probes::probes
loadFromFiles_(loadFromFiles), loadFromFiles_(loadFromFiles),
fieldSelection_(), fieldSelection_(),
fixedLocations_(true), fixedLocations_(true),
interpolationScheme_("cell") interpolationScheme_("cell"),
includeOutOfBounds_(true)
{ {
if (readFields) if (readFields)
{ {
@ -320,6 +335,7 @@ bool Foam::probes::read(const dictionary& dict)
<< "entry will be ignored"; << "entry will be ignored";
} }
} }
dict.readIfPresent("includeOutOfBounds", includeOutOfBounds_);
// Initialise cells to sample from supplied locations // Initialise cells to sample from supplied locations
findElements(mesh_); findElements(mesh_);

View File

@ -62,6 +62,10 @@ Description
(0.21 0.20999 0.01) // at outlet2 (0.21 0.20999 0.01) // at outlet2
(0.21 0 0.01) // at central block (0.21 0 0.01) // at central block
); );
// Optional: filter out points that haven't been found. Default
// is to include them (with value -VGREAT)
includeOutOfBounds true;
} }
\endverbatim \endverbatim
@ -148,6 +152,9 @@ protected:
// Note: only possible when fixedLocations_ is true // Note: only possible when fixedLocations_ is true
word interpolationScheme_; word interpolationScheme_;
//- Include probes that were not found
bool includeOutOfBounds_;
// Calculated // Calculated
@ -165,12 +172,16 @@ protected:
fieldGroup<symmTensor> surfaceSymmTensorFields_; fieldGroup<symmTensor> surfaceSymmTensorFields_;
fieldGroup<tensor> surfaceTensorFields_; fieldGroup<tensor> surfaceTensorFields_;
// Cells to be probed (obtained from the locations) //- Cells to be probed (obtained from the locations)
labelList elementList_; labelList elementList_;
// Faces to be probed //- Faces to be probed
labelList faceList_; labelList faceList_;
//- Processor holding the cell or face (-1 if point not found
// on any processor)
labelList processor_;
//- Current open files //- Current open files
HashPtrTable<OFstream> probeFilePtrs_; HashPtrTable<OFstream> probeFilePtrs_;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -80,7 +80,10 @@ void Foam::probes::sampleAndWrite
forAll(values, probei) forAll(values, probei)
{ {
os << ' ' << setw(w) << values[probei]; if (includeOutOfBounds_ || processor_[probei] != -1)
{
os << ' ' << setw(w) << values[probei];
}
} }
os << endl; os << endl;
} }
@ -104,7 +107,10 @@ void Foam::probes::sampleAndWrite
forAll(values, probei) forAll(values, probei)
{ {
os << ' ' << setw(w) << values[probei]; if (includeOutOfBounds_ || processor_[probei] != -1)
{
os << ' ' << setw(w) << values[probei];
}
} }
os << endl; os << endl;
} }