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

View File

@ -2,7 +2,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-2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -56,7 +56,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
{ {
if (debug) if (debug)
{ {
Info<< "sampledIsoSurface::getIsoField() : lookup volField " Info<< "sampledIsoSurface::getIsoFields() : lookup volField "
<< isoField_ << endl; << isoField_ << endl;
} }
storedVolFieldPtr_.clear(); storedVolFieldPtr_.clear();
@ -68,7 +68,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
if (debug) if (debug)
{ {
Info<< "sampledIsoSurface::getIsoField() : checking " Info<< "sampledIsoSurface::getIsoFields() : checking "
<< isoField_ << " for same time " << fvm.time().timeName() << isoField_ << " for same time " << fvm.time().timeName()
<< endl; << endl;
} }
@ -81,33 +81,44 @@ void Foam::sampledIsoSurface::getIsoFields() const
{ {
if (debug) if (debug)
{ {
Info<< "sampledIsoSurface::getIsoField() : reading volField " Info<< "sampledIsoSurface::getIsoFields() : reading volField "
<< isoField_ << " from time " << fvm.time().timeName() << isoField_ << " from time " << fvm.time().timeName()
<< endl; << endl;
} }
storedVolFieldPtr_.reset IOobject vfHeader
( (
new volScalarField isoField_,
( fvm.time().timeName(),
IOobject fvm,
( IOobject::MUST_READ,
isoField_, IOobject::NO_WRITE,
fvm.time().timeName(), false
fvm,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
),
fvm
)
); );
volFieldPtr_ = storedVolFieldPtr_.operator->();
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 // Get pointField
// ~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~
@ -119,7 +130,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
{ {
if (debug) if (debug)
{ {
Info<< "sampledIsoSurface::getIsoField() : lookup pointField " Info<< "sampledIsoSurface::getIsoFields() : lookup pointField "
<< pointFldName << endl; << pointFldName << endl;
} }
pointFieldPtr_ = &fvm.lookupObject<pointScalarField>(pointFldName); pointFieldPtr_ = &fvm.lookupObject<pointScalarField>(pointFldName);
@ -130,9 +141,10 @@ void Foam::sampledIsoSurface::getIsoFields() const
if (debug) if (debug)
{ {
Info<< "sampledIsoSurface::getIsoField() : checking pointField " Info<< "sampledIsoSurface::getIsoFields() : "
<< pointFldName << " for same time " << "checking pointField " << pointFldName
<< fvm.time().timeName() << endl; << " for same time " << fvm.time().timeName()
<< endl;
} }
if if
@ -143,7 +155,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
{ {
if (debug) if (debug)
{ {
Info<< "sampledIsoSurface::getIsoField() :" Info<< "sampledIsoSurface::getIsoFields() :"
<< " interpolating volField " << volFieldPtr_->name() << " interpolating volField " << volFieldPtr_->name()
<< " to get pointField " << pointFldName << endl; << " to get pointField " << pointFldName << endl;
} }
@ -173,10 +185,10 @@ void Foam::sampledIsoSurface::getIsoFields() const
if (debug) if (debug)
{ {
Info<< "sampledIsoSurface::getIsoField() : volField " Info<< "sampledIsoSurface::getIsoFields() : volField "
<< volFieldPtr_->name() << " min:" << min(*volFieldPtr_).value() << volFieldPtr_->name() << " min:" << min(*volFieldPtr_).value()
<< " max:" << max(*volFieldPtr_).value() << endl; << " max:" << max(*volFieldPtr_).value() << endl;
Info<< "sampledIsoSurface::getIsoField() : pointField " Info<< "sampledIsoSurface::getIsoFields() : pointField "
<< pointFieldPtr_->name() << pointFieldPtr_->name()
<< " min:" << gMin(pointFieldPtr_->internalField()) << " min:" << gMin(pointFieldPtr_->internalField())
<< " max:" << gMax(pointFieldPtr_->internalField()) << endl; << " max:" << gMax(pointFieldPtr_->internalField()) << endl;
@ -193,7 +205,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
{ {
if (debug) if (debug)
{ {
Info<< "sampledIsoSurface::getIsoField() :" Info<< "sampledIsoSurface::getIsoFields() :"
<< " submesh lookup volField " << " submesh lookup volField "
<< isoField_ << endl; << isoField_ << endl;
} }
@ -204,8 +216,8 @@ void Foam::sampledIsoSurface::getIsoFields() const
{ {
if (debug) if (debug)
{ {
Info<< "sampledIsoSurface::getIsoField() : subsetting volField " Info<< "sampledIsoSurface::getIsoFields() : "
<< isoField_ << endl; << "subsetting volField " << isoField_ << endl;
} }
storedVolSubFieldPtr_.reset storedVolSubFieldPtr_.reset
( (
@ -230,7 +242,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
{ {
if (debug) if (debug)
{ {
Info<< "sampledIsoSurface::getIsoField() :" Info<< "sampledIsoSurface::getIsoFields() :"
<< " submesh lookup pointField " << pointFldName << endl; << " submesh lookup pointField " << pointFldName << endl;
} }
storedPointSubFieldPtr_.clear(); storedPointSubFieldPtr_.clear();
@ -243,7 +255,7 @@ void Foam::sampledIsoSurface::getIsoFields() const
{ {
if (debug) if (debug)
{ {
Info<< "sampledIsoSurface::getIsoField() :" Info<< "sampledIsoSurface::getIsoFields() :"
<< " interpolating submesh volField " << " interpolating submesh volField "
<< volSubFieldPtr_->name() << volSubFieldPtr_->name()
<< " to get submesh pointField " << pointFldName << endl; << " 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 // If averaging redo the volField. Can only be done now since needs the
// point field. // point field.
if (average_) if (average_)
@ -275,11 +286,11 @@ void Foam::sampledIsoSurface::getIsoFields() const
if (debug) if (debug)
{ {
Info<< "sampledIsoSurface::getIsoField() : volSubField " Info<< "sampledIsoSurface::getIsoFields() : volSubField "
<< volSubFieldPtr_->name() << volSubFieldPtr_->name()
<< " min:" << min(*volSubFieldPtr_).value() << " min:" << min(*volSubFieldPtr_).value()
<< " max:" << max(*volSubFieldPtr_).value() << endl; << " max:" << max(*volSubFieldPtr_).value() << endl;
Info<< "sampledIsoSurface::getIsoField() : pointSubField " Info<< "sampledIsoSurface::getIsoFields() : pointSubField "
<< pointSubFieldPtr_->name() << pointSubFieldPtr_->name()
<< " min:" << gMin(pointSubFieldPtr_->internalField()) << " min:" << gMin(pointSubFieldPtr_->internalField())
<< " max:" << gMax(pointSubFieldPtr_->internalField()) << endl; << " max:" << gMax(pointSubFieldPtr_->internalField()) << endl;
@ -292,7 +303,7 @@ bool Foam::sampledIsoSurface::updateGeometry() const
{ {
const fvMesh& fvm = static_cast<const fvMesh&>(mesh()); const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
// no update needed // No update needed
if (fvm.time().timeIndex() == prevTimeIndex_) if (fvm.time().timeIndex() == prevTimeIndex_)
{ {
return false; return false;
@ -589,8 +600,6 @@ void Foam::sampledIsoSurface::print(Ostream& os) const
os << "sampledIsoSurface: " << name() << " :" os << "sampledIsoSurface: " << name() << " :"
<< " field :" << isoField_ << " field :" << isoField_
<< " value :" << isoVal_; << " 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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -35,12 +35,10 @@ License
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(sampledSurfaces, 0); defineTypeNameAndDebug(sampledSurfaces, 0);
} }
bool Foam::sampledSurfaces::verbose_ = false; bool Foam::sampledSurfaces::verbose_ = false;
Foam::scalar Foam::sampledSurfaces::mergeTol_ = 1e-10; Foam::scalar Foam::sampledSurfaces::mergeTol_ = 1e-10;
@ -49,7 +47,7 @@ Foam::scalar Foam::sampledSurfaces::mergeTol_ = 1e-10;
void Foam::sampledSurfaces::writeGeometry() const void Foam::sampledSurfaces::writeGeometry() const
{ {
// Write to time directory under outputPath_ // 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(); const fileName outputDir = outputPath_/mesh_.time().timeName();
@ -153,7 +151,7 @@ void Foam::sampledSurfaces::write()
{ {
if (size()) if (size())
{ {
// finalize surfaces, merge points etc. // Finalize surfaces, merge points etc.
update(); update();
const label nFields = classifyFields(); const label nFields = classifyFields();
@ -170,7 +168,7 @@ void Foam::sampledSurfaces::write()
mkDir(outputPath_/mesh_.time().timeName()); mkDir(outputPath_/mesh_.time().timeName());
} }
// write geometry first if required, // Write geometry first if required,
// or when no fields would otherwise be written // or when no fields would otherwise be written
if (nFields == 0 || formatter_->separateGeometry()) if (nFields == 0 || formatter_->separateGeometry())
{ {
@ -205,8 +203,8 @@ void Foam::sampledSurfaces::read(const dictionary& dict)
dict.lookup("interpolationScheme") >> interpolationScheme_; dict.lookup("interpolationScheme") >> interpolationScheme_;
const word writeType(dict.lookup("surfaceFormat")); const word writeType(dict.lookup("surfaceFormat"));
// define the surface formatter // Define the surface formatter
// optionally defined extra controls for the output formats // Optionally defined extra controls for the output formats
formatter_ = surfaceWriter::New formatter_ = surfaceWriter::New
( (
writeType, writeType,
@ -225,7 +223,7 @@ void Foam::sampledSurfaces::read(const dictionary& dict)
mergeList_.setSize(size()); mergeList_.setSize(size());
} }
// ensure all surfaces and merge information are expired // Ensure all surfaces and merge information are expired
expire(); expire();
if (this->size()) if (this->size())
@ -301,7 +299,7 @@ bool Foam::sampledSurfaces::expire()
justExpired = true; justExpired = true;
} }
// clear merge information // Clear merge information
if (Pstream::parRun()) if (Pstream::parRun())
{ {
mergeList_[surfI].clear(); mergeList_[surfI].clear();
@ -322,7 +320,7 @@ bool Foam::sampledSurfaces::update()
return updated; return updated;
} }
// serial: quick and easy, no merging required // Serial: quick and easy, no merging required
if (!Pstream::parRun()) if (!Pstream::parRun())
{ {
forAll(*this, surfI) forAll(*this, surfI)
@ -336,7 +334,7 @@ bool Foam::sampledSurfaces::update()
return updated; return updated;
} }
// dimension as fraction of mesh bounding box // Dimension as fraction of mesh bounding box
scalar mergeDim = mergeTol_ * mesh_.bounds().mag(); scalar mergeDim = mergeTol_ * mesh_.bounds().mag();
if (Pstream::master() && debug) if (Pstream::master() && debug)

View File

@ -2,7 +2,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 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -32,20 +32,54 @@ License
Foam::label Foam::sampledSurfaces::classifyFields() Foam::label Foam::sampledSurfaces::classifyFields()
{ {
// check files for a particular time label nFields = 0;
if (loadFromFiles_) if (loadFromFiles_)
{ {
// Check files for a particular time
IOobjectList objects(mesh_, mesh_.time().timeName()); IOobjectList objects(mesh_, mesh_.time().timeName());
wordList allFields = objects.sortedNames(); 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 else
{ {
// Check currently available fields
wordList allFields = mesh_.sortedNames(); wordList allFields = mesh_.sortedNames();
labelList indices = findStrings(fieldSelection_, allFields); 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;
} }