BUG: collated ensight writer dropping entries (#1451)

- regression as a result of changed time-handling from #1418.
  Now cache the fields information internally.
This commit is contained in:
Mark Olesen 2019-09-29 18:06:59 +02:00 committed by Andrew Heather
parent 4a5569776e
commit a1727f4ba5
3 changed files with 18 additions and 35 deletions

View File

@ -234,6 +234,7 @@ void Foam::surfaceWriters::ensightWriter::close()
{ {
times_.clear(); times_.clear();
meshes_.clear(); meshes_.clear();
cache_.clear();
surfaceWriter::close(); surfaceWriter::close();
} }

View File

@ -89,11 +89,11 @@ class ensightWriter
//- The collated output times //- The collated output times
DynamicList<scalar> times_; DynamicList<scalar> times_;
//- Indices in times_ when a geometry (mesh) has been written //- Indices in times_ when geometry (mesh) has been written (collated)
bitSet meshes_; bitSet meshes_;
// NOTE: Could also maintain fieldsDict here, //- Cached information for times, geometry, fields (collated)
// or as a HashTable of info. dictionary cache_;
// Private Member Functions // Private Member Functions

View File

@ -85,7 +85,7 @@ Foam::label Foam::surfaceWriters::ensightWriter::readPreviousTimes
labelList geomIndices; labelList geomIndices;
scalarList meshTimes; scalarList meshTimes;
dictionary dict; cache_.clear();
const fileName dictFile(baseDir/dictName); const fileName dictFile(baseDir/dictName);
@ -93,19 +93,19 @@ Foam::label Foam::surfaceWriters::ensightWriter::readPreviousTimes
{ {
IFstream is(dictFile); IFstream is(dictFile);
if (is.good() && dict.read(is)) if (is.good() && cache_.read(is))
{ {
meshes_.clear(); meshes_.clear();
dict.readIfPresent("times", times_); cache_.readIfPresent("times", times_);
timeIndex = findTimeIndex(times_, timeValue); timeIndex = findTimeIndex(times_, timeValue);
if (dict.readIfPresent("geometry", geomIndices)) if (cache_.readIfPresent("geometry", geomIndices))
{ {
// Convert indices to bitSet entries // Convert indices to bitSet entries
meshes_.set(geomIndices); meshes_.set(geomIndices);
} }
else if (dict.readIfPresent("meshes", meshTimes)) else if (cache_.readIfPresent("meshes", meshTimes))
{ {
WarningInFunction WarningInFunction
<< nl << nl
@ -273,47 +273,29 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated
// Do case file // Do case file
{ {
dictionary dict;
// Add time information to dictionary // Add time information to dictionary
dict.set("geometry", meshes_.sortedToc()); cache_.set("geometry", meshes_.sortedToc());
dict.set("times", times_); cache_.set("times", times_);
// Debugging, or if needed for older versions: // Debugging, or if needed for older versions:
//// dict.set //// cache_.set
//// ( //// (
//// "meshes", //// "meshes",
//// IndirectList<scalar>(times_, meshes_.sortedToc()) //// IndirectList<scalar>(times_, meshes_.sortedToc())
//// ); //// );
// Add field information to dictionary
dictionary& fieldsDict = cache_.subDictOrAdd("fields");
dictionary& fieldDict = fieldsDict.subDictOrAdd(fieldName);
// Add field information to dictionary? if (fieldDict.empty())
bool hasField = false;
dictionary* fieldsDictPtr = dict.findDict("fields");
if (fieldsDictPtr)
{ {
hasField = fieldsDictPtr->found(fieldName);
}
else
{
// No "fields" dictionary - create first
fieldsDictPtr = dict.set("fields", dictionary())->dictPtr();
}
if (!hasField)
{
dictionary fieldDict;
fieldDict.set("type", ensightPTraits<Type>::typeName); fieldDict.set("type", ensightPTraits<Type>::typeName);
fieldDict.set("name", varName); // ensight variable name fieldDict.set("name", varName); // ensight variable name
fieldsDictPtr->set(fieldName, fieldDict);
stateChanged = true; stateChanged = true;
} }
const dictionary& fieldsDict = *fieldsDictPtr;
if (stateChanged) if (stateChanged)
{ {
if (verbose_) if (verbose_)
@ -323,7 +305,7 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated
{ {
OFstream os(baseDir/"fieldsDict"); OFstream os(baseDir/"fieldsDict");
os << "// Summary of Ensight fields, times" << nl << nl; os << "// Summary of Ensight fields, times" << nl << nl;
dict.write(os, false); cache_.write(os, false);
} }
OFstream osCase(outputFile, IOstream::ASCII); OFstream osCase(outputFile, IOstream::ASCII);
@ -489,7 +471,7 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated
OFstream timeStamp(dataDir/"time"); OFstream timeStamp(dataDir/"time");
timeStamp timeStamp
<< "# timestep time" << nl << "# timestep time" << nl
<< dataDir.name() << " " << timeValue << nl; << dataDir.name() << ' ' << timeValue << nl;
} }
} }