sampledSets, sampledSurfaces: Provide warning message if field cannot be found

Generate fatal error if iso-surface field cannot be found
This commit is contained in:
Henry
2015-05-03 16:52:37 +01:00
parent e64f0846f0
commit 6e87320af7
4 changed files with 143 additions and 75 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -83,12 +83,16 @@ Foam::label Foam::sampledSets::classifyFields()
if (loadFromFiles_)
{
// check files for a particular time
// Check files for a particular time
IOobjectList objects(mesh_, mesh_.time().timeName());
wordList allFields = objects.sortedNames();
labelList indices = findStrings(fieldSelection_, allFields);
forAll(fieldSelection_, i)
{
labelList indices = findStrings(fieldSelection_[i], allFields);
if (indices.size())
{
forAll(indices, fieldI)
{
const word& fieldName = allFields[indices[fieldI]];
@ -102,10 +106,24 @@ Foam::label Foam::sampledSets::classifyFields()
}
else
{
// check currently available fields
WarningIn("sampledSets::classifyFields()")
<< "Cannot find field file matching "
<< fieldSelection_[i] << endl;
}
}
}
else
{
// Check currently available fields
wordList allFields = mesh_.sortedNames();
labelList indices = findStrings(fieldSelection_, allFields);
forAll(fieldSelection_, i)
{
labelList indices = findStrings(fieldSelection_[i], allFields);
if (indices.size())
{
forAll(indices, fieldI)
{
const word& fieldName = allFields[indices[fieldI]];
@ -117,8 +135,17 @@ Foam::label Foam::sampledSets::classifyFields()
);
}
}
else
{
WarningIn("sampledSets::classifyFields()")
<< "Cannot find registered field matching "
<< fieldSelection_[i] << endl;
}
}
}
return nFields;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -56,7 +56,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
{
if (debug)
{
Info<< "sampledIsoSurface::getIsoField() : lookup volField "
Info<< "sampledIsoSurface::getIsoFields() : lookup volField "
<< isoField_ << endl;
}
storedVolFieldPtr_.clear();
@ -68,7 +68,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
if (debug)
{
Info<< "sampledIsoSurface::getIsoField() : checking "
Info<< "sampledIsoSurface::getIsoFields() : checking "
<< isoField_ << " for same time " << fvm.time().timeName()
<< endl;
}
@ -81,16 +81,12 @@ void Foam::sampledIsoSurface::getIsoFields() const
{
if (debug)
{
Info<< "sampledIsoSurface::getIsoField() : reading volField "
Info<< "sampledIsoSurface::getIsoFields() : reading volField "
<< isoField_ << " from time " << fvm.time().timeName()
<< endl;
}
storedVolFieldPtr_.reset
(
new volScalarField
(
IOobject
IOobject vfHeader
(
isoField_,
fvm.time().timeName(),
@ -98,14 +94,29 @@ void Foam::sampledIsoSurface::getIsoFields() const
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
),
);
if (vfHeader.headerOk())
{
storedVolFieldPtr_.reset
(
new volScalarField
(
vfHeader,
fvm
)
);
volFieldPtr_ = storedVolFieldPtr_.operator->();
}
else
{
FatalErrorIn("sampledIsoSurface::getIsoFields()")
<< "Cannot find isosurface field " << isoField_
<< " in database or directory " << vfHeader.path()
<< exit(FatalError);
}
}
}
// Get pointField
@ -119,7 +130,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
{
if (debug)
{
Info<< "sampledIsoSurface::getIsoField() : lookup pointField "
Info<< "sampledIsoSurface::getIsoFields() : lookup pointField "
<< pointFldName << endl;
}
pointFieldPtr_ = &fvm.lookupObject<pointScalarField>(pointFldName);
@ -130,9 +141,10 @@ void Foam::sampledIsoSurface::getIsoFields() const
if (debug)
{
Info<< "sampledIsoSurface::getIsoField() : checking pointField "
<< pointFldName << " for same time "
<< fvm.time().timeName() << endl;
Info<< "sampledIsoSurface::getIsoFields() : "
<< "checking pointField " << pointFldName
<< " for same time " << fvm.time().timeName()
<< endl;
}
if
@ -143,7 +155,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
{
if (debug)
{
Info<< "sampledIsoSurface::getIsoField() :"
Info<< "sampledIsoSurface::getIsoFields() :"
<< " interpolating volField " << volFieldPtr_->name()
<< " to get pointField " << pointFldName << endl;
}
@ -173,10 +185,10 @@ void Foam::sampledIsoSurface::getIsoFields() const
if (debug)
{
Info<< "sampledIsoSurface::getIsoField() : volField "
Info<< "sampledIsoSurface::getIsoFields() : volField "
<< volFieldPtr_->name() << " min:" << min(*volFieldPtr_).value()
<< " max:" << max(*volFieldPtr_).value() << endl;
Info<< "sampledIsoSurface::getIsoField() : pointField "
Info<< "sampledIsoSurface::getIsoFields() : pointField "
<< pointFieldPtr_->name()
<< " min:" << gMin(pointFieldPtr_->internalField())
<< " max:" << gMax(pointFieldPtr_->internalField()) << endl;
@ -193,7 +205,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
{
if (debug)
{
Info<< "sampledIsoSurface::getIsoField() :"
Info<< "sampledIsoSurface::getIsoFields() :"
<< " submesh lookup volField "
<< isoField_ << endl;
}
@ -204,8 +216,8 @@ void Foam::sampledIsoSurface::getIsoFields() const
{
if (debug)
{
Info<< "sampledIsoSurface::getIsoField() : subsetting volField "
<< isoField_ << endl;
Info<< "sampledIsoSurface::getIsoFields() : "
<< "subsetting volField " << isoField_ << endl;
}
storedVolSubFieldPtr_.reset
(
@ -230,7 +242,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
{
if (debug)
{
Info<< "sampledIsoSurface::getIsoField() :"
Info<< "sampledIsoSurface::getIsoFields() :"
<< " submesh lookup pointField " << pointFldName << endl;
}
storedPointSubFieldPtr_.clear();
@ -243,7 +255,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
{
if (debug)
{
Info<< "sampledIsoSurface::getIsoField() :"
Info<< "sampledIsoSurface::getIsoFields() :"
<< " interpolating submesh volField "
<< volSubFieldPtr_->name()
<< " to get submesh pointField " << pointFldName << endl;
@ -260,7 +272,6 @@ void Foam::sampledIsoSurface::getIsoFields() const
}
// If averaging redo the volField. Can only be done now since needs the
// point field.
if (average_)
@ -275,11 +286,11 @@ void Foam::sampledIsoSurface::getIsoFields() const
if (debug)
{
Info<< "sampledIsoSurface::getIsoField() : volSubField "
Info<< "sampledIsoSurface::getIsoFields() : volSubField "
<< volSubFieldPtr_->name()
<< " min:" << min(*volSubFieldPtr_).value()
<< " max:" << max(*volSubFieldPtr_).value() << endl;
Info<< "sampledIsoSurface::getIsoField() : pointSubField "
Info<< "sampledIsoSurface::getIsoFields() : pointSubField "
<< pointSubFieldPtr_->name()
<< " min:" << gMin(pointSubFieldPtr_->internalField())
<< " max:" << gMax(pointSubFieldPtr_->internalField()) << endl;
@ -292,7 +303,7 @@ bool Foam::sampledIsoSurface::updateGeometry() const
{
const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
// no update needed
// No update needed
if (fvm.time().timeIndex() == prevTimeIndex_)
{
return false;
@ -589,8 +600,6 @@ void Foam::sampledIsoSurface::print(Ostream& os) const
os << "sampledIsoSurface: " << name() << " :"
<< " field :" << isoField_
<< " value :" << isoVal_;
//<< " faces:" << faces().size() // note: possibly no geom yet
//<< " points:" << points().size();
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -35,12 +35,10 @@ License
namespace Foam
{
defineTypeNameAndDebug(sampledSurfaces, 0);
defineTypeNameAndDebug(sampledSurfaces, 0);
}
bool Foam::sampledSurfaces::verbose_ = false;
Foam::scalar Foam::sampledSurfaces::mergeTol_ = 1e-10;
@ -49,7 +47,7 @@ Foam::scalar Foam::sampledSurfaces::mergeTol_ = 1e-10;
void Foam::sampledSurfaces::writeGeometry() const
{
// Write to time directory under outputPath_
// skip surface without faces (eg, a failed cut-plane)
// Skip surface without faces (eg, a failed cut-plane)
const fileName outputDir = outputPath_/mesh_.time().timeName();
@ -153,7 +151,7 @@ void Foam::sampledSurfaces::write()
{
if (size())
{
// finalize surfaces, merge points etc.
// Finalize surfaces, merge points etc.
update();
const label nFields = classifyFields();
@ -170,7 +168,7 @@ void Foam::sampledSurfaces::write()
mkDir(outputPath_/mesh_.time().timeName());
}
// write geometry first if required,
// Write geometry first if required,
// or when no fields would otherwise be written
if (nFields == 0 || formatter_->separateGeometry())
{
@ -205,8 +203,8 @@ void Foam::sampledSurfaces::read(const dictionary& dict)
dict.lookup("interpolationScheme") >> interpolationScheme_;
const word writeType(dict.lookup("surfaceFormat"));
// define the surface formatter
// optionally defined extra controls for the output formats
// Define the surface formatter
// Optionally defined extra controls for the output formats
formatter_ = surfaceWriter::New
(
writeType,
@ -225,7 +223,7 @@ void Foam::sampledSurfaces::read(const dictionary& dict)
mergeList_.setSize(size());
}
// ensure all surfaces and merge information are expired
// Ensure all surfaces and merge information are expired
expire();
if (this->size())
@ -301,7 +299,7 @@ bool Foam::sampledSurfaces::expire()
justExpired = true;
}
// clear merge information
// Clear merge information
if (Pstream::parRun())
{
mergeList_[surfI].clear();
@ -322,7 +320,7 @@ bool Foam::sampledSurfaces::update()
return updated;
}
// serial: quick and easy, no merging required
// Serial: quick and easy, no merging required
if (!Pstream::parRun())
{
forAll(*this, surfI)
@ -336,7 +334,7 @@ bool Foam::sampledSurfaces::update()
return updated;
}
// dimension as fraction of mesh bounding box
// Dimension as fraction of mesh bounding box
scalar mergeDim = mergeTol_ * mesh_.bounds().mag();
if (Pstream::master() && debug)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -32,20 +32,54 @@ License
Foam::label Foam::sampledSurfaces::classifyFields()
{
// check files for a particular time
label nFields = 0;
if (loadFromFiles_)
{
// Check files for a particular time
IOobjectList objects(mesh_, mesh_.time().timeName());
wordList allFields = objects.sortedNames();
labelList indices = findStrings(fieldSelection_, allFields);
return indices.size();
forAll(fieldSelection_, i)
{
labelList indices = findStrings(fieldSelection_[i], allFields);
if (indices.size())
{
nFields += indices.size();
}
else
{
WarningIn("sampledSurfaces::classifyFields()")
<< "Cannot find field file matching "
<< fieldSelection_[i] << endl;
}
}
}
else
{
// Check currently available fields
wordList allFields = mesh_.sortedNames();
labelList indices = findStrings(fieldSelection_, allFields);
return indices.size();
forAll(fieldSelection_, i)
{
labelList indices = findStrings(fieldSelection_[i], allFields);
if (indices.size())
{
nFields += indices.size();
}
else
{
WarningIn("sampledSurfaces::classifyFields()")
<< "Cannot find registered field matching "
<< fieldSelection_[i] << endl;
}
}
}
return nFields;
}