mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ReadFields: Added functions to read selected fields and store in the objectRegistry
This commit is contained in:
@ -24,9 +24,8 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "ReadFields.H"
|
||||
#include "HashSet.H"
|
||||
#include "Pstream.H"
|
||||
#include "IOobjectList.H"
|
||||
#include "objectRegistry.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
@ -141,8 +140,6 @@ void Foam::ReadFields
|
||||
}
|
||||
}
|
||||
|
||||
//Info<< "Unloading times " << unusedTimes << endl;
|
||||
|
||||
forAll(unusedTimes, i)
|
||||
{
|
||||
objectRegistry& timeCache = const_cast<objectRegistry&>
|
||||
@ -162,8 +159,6 @@ void Foam::ReadFields
|
||||
// Create if not found
|
||||
if (!fieldsCache.found(tm))
|
||||
{
|
||||
//Info<< "Creating registry for time " << tm << endl;
|
||||
|
||||
// Create objectRegistry if not found
|
||||
objectRegistry* timeCachePtr = new objectRegistry
|
||||
(
|
||||
@ -189,9 +184,6 @@ void Foam::ReadFields
|
||||
// Store field if not found
|
||||
if (!timeCache.found(fieldName))
|
||||
{
|
||||
//Info<< "Loading field " << fieldName
|
||||
// << " for time " << tm << endl;
|
||||
|
||||
GeoField loadedFld
|
||||
(
|
||||
IOobject
|
||||
@ -247,4 +239,149 @@ void Foam::ReadFields
|
||||
}
|
||||
|
||||
|
||||
template<class GeoFieldType>
|
||||
void Foam::readFields
|
||||
(
|
||||
const typename GeoFieldType::Mesh& mesh,
|
||||
const IOobjectList& objects,
|
||||
const HashSet<word>& selectedFields,
|
||||
LIFOStack<regIOobject*>& storedObjects
|
||||
)
|
||||
{
|
||||
IOobjectList fields(objects.lookupClass(GeoFieldType::typeName));
|
||||
if (!fields.size()) return;
|
||||
|
||||
bool firstField = true;
|
||||
|
||||
forAllConstIter(IOobjectList, fields, fieldIter)
|
||||
{
|
||||
const IOobject& io = *fieldIter();
|
||||
const word& fieldName = io.name();
|
||||
|
||||
if (selectedFields.found(fieldName))
|
||||
{
|
||||
if (firstField)
|
||||
{
|
||||
Info<< " " << GeoFieldType::typeName << "s:";
|
||||
firstField = false;
|
||||
}
|
||||
|
||||
Info<< " " << fieldName;
|
||||
|
||||
GeoFieldType* fieldPtr = new GeoFieldType
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
fieldName,
|
||||
io.instance(),
|
||||
io.local(),
|
||||
io.db(),
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh
|
||||
);
|
||||
fieldPtr->store();
|
||||
storedObjects.push(fieldPtr);
|
||||
}
|
||||
}
|
||||
|
||||
if (!firstField)
|
||||
{
|
||||
Info<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class UniformFieldType>
|
||||
void Foam::readUniformFields
|
||||
(
|
||||
const IOobjectList& objects,
|
||||
const HashSet<word>& selectedFields,
|
||||
LIFOStack<regIOobject*>& storedObjects,
|
||||
const bool syncPar
|
||||
)
|
||||
{
|
||||
// Search list of objects for wanted type
|
||||
IOobjectList fields(objects.lookupClass(UniformFieldType::typeName));
|
||||
if (!fields.size()) return;
|
||||
|
||||
wordList masterNames(fields.names());
|
||||
|
||||
if (syncPar && Pstream::parRun())
|
||||
{
|
||||
// Check that I have the same fields as the master
|
||||
const wordList localNames(masterNames);
|
||||
Pstream::scatter(masterNames);
|
||||
|
||||
HashSet<word> localNamesSet(localNames);
|
||||
|
||||
forAll(masterNames, i)
|
||||
{
|
||||
const word& masterFld = masterNames[i];
|
||||
|
||||
HashSet<word>::iterator iter = localNamesSet.find(masterFld);
|
||||
|
||||
if (iter == localNamesSet.end())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Fields not synchronised across processors." << endl
|
||||
<< "Master has fields " << masterNames
|
||||
<< " processor " << Pstream::myProcNo()
|
||||
<< " has fields " << localNames << exit(FatalError);
|
||||
}
|
||||
else
|
||||
{
|
||||
localNamesSet.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
forAllConstIter(HashSet<word>, localNamesSet, iter)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Fields not synchronised across processors." << endl
|
||||
<< "Master has fields " << masterNames
|
||||
<< " processor " << Pstream::myProcNo()
|
||||
<< " has fields " << localNames << exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
bool firstField = true;
|
||||
|
||||
forAll(masterNames, i)
|
||||
{
|
||||
const IOobject& io = *fields[masterNames[i]];
|
||||
const word& fieldName = io.name();
|
||||
|
||||
if (selectedFields.found(fieldName))
|
||||
{
|
||||
if (firstField)
|
||||
{
|
||||
Info<< " " << UniformFieldType::typeName << "s:";
|
||||
firstField = false;
|
||||
}
|
||||
|
||||
Info<< " " << fieldName;
|
||||
|
||||
UniformFieldType* fieldPtr = new UniformFieldType
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
fieldName,
|
||||
io.instance(),
|
||||
io.local(),
|
||||
io.db(),
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE
|
||||
)
|
||||
);
|
||||
fieldPtr->store();
|
||||
storedObjects.push(fieldPtr);
|
||||
}
|
||||
}
|
||||
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -25,7 +25,7 @@ Global
|
||||
Foam::ReadFields
|
||||
|
||||
Description
|
||||
Helper routine to read fields
|
||||
Field reading functions for post-processing utilities
|
||||
|
||||
SourceFiles
|
||||
ReadFields.C
|
||||
@ -37,17 +37,20 @@ SourceFiles
|
||||
|
||||
#include "PtrList.H"
|
||||
#include "wordList.H"
|
||||
#include "HashSet.H"
|
||||
#include "LIFOStack.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class regIOobject;
|
||||
class IOobjectList;
|
||||
|
||||
//- Helper routine to read fields
|
||||
// Reads all fields of type. Returns names of fields read. Guarantees all
|
||||
// processors to read fields in same order.
|
||||
//- Read all fields of the specified type.
|
||||
// Returns names of fields read.
|
||||
// Guarantees all processors read fields in same order.
|
||||
template<class GeoField, class Mesh>
|
||||
wordList ReadFields
|
||||
(
|
||||
@ -57,8 +60,8 @@ wordList ReadFields
|
||||
const bool syncPar = true
|
||||
);
|
||||
|
||||
//- Helper routine to read GeometricFields. The fieldsCache is per time
|
||||
// an objectRegistry of all stored fields
|
||||
//- Read all GeometricFields of the specified type.
|
||||
// The fieldsCache is an objectRegistry of all stored fields
|
||||
template<class GeoField>
|
||||
static void ReadFields
|
||||
(
|
||||
@ -68,8 +71,8 @@ static void ReadFields
|
||||
objectRegistry& fieldsCache
|
||||
);
|
||||
|
||||
//- Helper routine to read GeometricFields. The fieldsCache is per time
|
||||
// an objectRegistry of all stored fields
|
||||
//- Read all GeometricFields of the specified type.
|
||||
// The fieldsCache is an objectRegistry of all stored fields
|
||||
template<class GeoField>
|
||||
static void ReadFields
|
||||
(
|
||||
@ -79,6 +82,34 @@ static void ReadFields
|
||||
const word& registryName = "fieldsCache"
|
||||
);
|
||||
|
||||
//- Read the selected GeometricFields of the specified type.
|
||||
// The fields are transferred to the objectRegistry and a list of them is
|
||||
// returned as a stack for later clean-up
|
||||
template<class GeoFieldType>
|
||||
void readFields
|
||||
(
|
||||
const typename GeoFieldType::Mesh& mesh,
|
||||
const IOobjectList& objects,
|
||||
const HashSet<word>& selectedFields,
|
||||
LIFOStack<regIOobject*>& storedObjects
|
||||
);
|
||||
|
||||
|
||||
//- Read the selected UniformDimensionedFields of the specified type.
|
||||
// The fields are transferred to the objectRegistry and a list of them is
|
||||
// returned as a stack for later clean-up
|
||||
template<class GeoFieldType>
|
||||
void readUniformFields
|
||||
(
|
||||
const IOobjectList& objects,
|
||||
const HashSet<word>& selectedFields,
|
||||
LIFOStack<regIOobject*>& storedObjects,
|
||||
const bool syncPar = true
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
Reference in New Issue
Block a user