Skip to content
Snippets Groups Projects
Commit dd20d908 authored by Henry Weller's avatar Henry Weller
Browse files

includeFuncEntry: Added support for function arguments compatible with the...

includeFuncEntry: Added support for function arguments compatible with the '-func' post-processing option

e.g.

functions
{
    #includeFunc mag(U)
}

executes 'mag' on the field 'U' writing the field 'mag(U)'.

The equivalent post-processing command is

postProcess -func 'mag(U)'
parent c9214717
Branches
Tags
1 merge request!60Merge foundation
...@@ -2,7 +2,7 @@ ...@@ -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-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -119,8 +119,6 @@ public: ...@@ -119,8 +119,6 @@ public:
primitiveEntry&, primitiveEntry&,
Istream& Istream&
); );
}; };
......
...@@ -25,58 +25,26 @@ License ...@@ -25,58 +25,26 @@ License
#include "includeFuncEntry.H" #include "includeFuncEntry.H"
#include "functionObjectList.H" #include "functionObjectList.H"
#include "dictionary.H"
#include "IFstream.H"
#include "addToMemberFunctionSelectionTable.H" #include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::word Foam::functionEntries::includeFuncEntry::typeName
(
Foam::functionEntries::includeFuncEntry::typeName_()
);
// Don't lookup the debug switch here as the debug switch dictionary
// might include includeFuncEntry
int Foam::functionEntries::includeFuncEntry::debug(0);
bool Foam::functionEntries::includeFuncEntry::report(false);
namespace Foam namespace Foam
{ {
namespace functionEntries namespace functionEntries
{ {
addToMemberFunctionSelectionTable defineTypeNameAndDebug(includeFuncEntry, 0);
(
functionEntry,
includeFuncEntry,
execute,
dictionaryIstream
);
addToMemberFunctionSelectionTable addToMemberFunctionSelectionTable
( (
functionEntry, functionEntry,
includeFuncEntry, includeFuncEntry,
execute, execute,
primitiveEntryIstream dictionaryIstream
); );
} }
} }
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
Foam::fileName Foam::functionEntries::includeFuncEntry::funcPath
(
const word& fName,
const dictionary& dict
)
{
// Search the system and etc directories for the file and return the path
return functionObjectList::findDict(fName);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
...@@ -86,66 +54,15 @@ bool Foam::functionEntries::includeFuncEntry::execute ...@@ -86,66 +54,15 @@ bool Foam::functionEntries::includeFuncEntry::execute
Istream& is Istream& is
) )
{ {
const word fName(is); const word fNameArgs(is);
const fileName fPath(funcPath(fName, parentDict)); HashSet<word> selectedFields;
IFstream ifs(fPath);
if (ifs)
{
if (Foam::functionEntries::includeFuncEntry::report)
{
Info<< fPath << endl;
}
parentDict.read(ifs);
return true;
}
else
{
FatalIOErrorInFunction
(
is
) << "Cannot open functionObject file "
<< (ifs.name().size() ? ifs.name() : fileName(fName))
<< " while reading dictionary " << parentDict.name()
<< exit(FatalIOError);
return false;
}
}
bool Foam::functionEntries::includeFuncEntry::execute
(
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
)
{
const word fName(is);
const fileName fPath(funcPath(fName, parentDict));
IFstream ifs(fPath);
if (ifs)
{
if (Foam::functionEntries::includeFuncEntry::report)
{
Info<< fPath << endl;
}
entry.read(parentDict, ifs);
return true;
}
else
{
FatalIOErrorInFunction
(
is
) << "Cannot open functionObject file "
<< (ifs.name().size() ? ifs.name() : fileName(fName))
<< " while reading dictionary " << parentDict.name()
<< exit(FatalIOError);
return false; return functionObjectList::readFunctionObject
} (
fNameArgs,
parentDict,
selectedFields
);
} }
......
...@@ -50,7 +50,7 @@ Description ...@@ -50,7 +50,7 @@ Description
\endverbatim \endverbatim
See Also See Also
functionObjectList::findDict Foam::functionObjectList
SourceFiles SourceFiles
includeFuncEntry.C includeFuncEntry.C
...@@ -77,30 +77,9 @@ class includeFuncEntry ...@@ -77,30 +77,9 @@ class includeFuncEntry
: :
public functionEntry public functionEntry
{ {
// Private Member Functions
//- Disallow default bitwise copy construct
includeFuncEntry(const includeFuncEntry&);
//- Disallow default bitwise assignment
void operator=(const includeFuncEntry&);
//- Return the path to the functionObject dictionary path
static fileName funcPath
(
const word& fName,
const dictionary& dict
);
public: public:
// Static data members
//- Report which file is included to stdout
static bool report;
//- Runtime type information //- Runtime type information
ClassName("includeFunc"); ClassName("includeFunc");
...@@ -109,14 +88,6 @@ public: ...@@ -109,14 +88,6 @@ public:
//- Execute the functionEntry in a sub-dict context //- Execute the functionEntry in a sub-dict context
static bool execute(dictionary& parentDict, Istream&); static bool execute(dictionary& parentDict, Istream&);
//- Execute the functionEntry in a primitiveEntry context
static bool execute
(
const dictionary& parentDict,
primitiveEntry&,
Istream&
);
}; };
......
...@@ -99,11 +99,11 @@ Foam::fileName Foam::functionObjectList::findDict(const word& funcName) ...@@ -99,11 +99,11 @@ Foam::fileName Foam::functionObjectList::findDict(const word& funcName)
} }
void Foam::functionObjectList::readFunctionObject bool Foam::functionObjectList::readFunctionObject
( (
const word& funcNameArgs0, const word& funcNameArgs0,
dictionary& functionsDict, dictionary& functionsDict,
HashSet<word>& selectedFields HashSet<word>& requiredFields
) )
{ {
// Parse the optional functionObject arguments // Parse the optional functionObject arguments
...@@ -153,7 +153,7 @@ void Foam::functionObjectList::readFunctionObject ...@@ -153,7 +153,7 @@ void Foam::functionObjectList::readFunctionObject
{ {
WarningInFunction WarningInFunction
<< "Cannot find functionObject file " << funcName << endl; << "Cannot find functionObject file " << funcName << endl;
return; return false;
} }
// Read the functionObject dictionary // Read the functionObject dictionary
...@@ -163,30 +163,32 @@ void Foam::functionObjectList::readFunctionObject ...@@ -163,30 +163,32 @@ void Foam::functionObjectList::readFunctionObject
// Insert the 'field' or 'fields' entry corresponding to the optional // Insert the 'field' or 'fields' entry corresponding to the optional
// arguments or read the 'field' or 'fields' entry and add the required // arguments or read the 'field' or 'fields' entry and add the required
// fields to selectedFields // fields to requiredFields
if (args.size() == 1) if (args.size() == 1)
{ {
funcDict.set("field", args[0]); funcDict.set("field", args[0]);
selectedFields.insert(args[0]); requiredFields.insert(args[0]);
} }
else if (args.size() > 1) else if (args.size() > 1)
{ {
funcDict.set("fields", args); funcDict.set("fields", args);
selectedFields.insert(args); requiredFields.insert(args);
} }
else if (funcDict.found("field")) else if (funcDict.found("field"))
{ {
selectedFields.insert(word(funcDict.lookup("field"))); requiredFields.insert(word(funcDict.lookup("field")));
} }
else if (funcDict.found("fields")) else if (funcDict.found("fields"))
{ {
selectedFields.insert(wordList(funcDict.lookup("fields"))); requiredFields.insert(wordList(funcDict.lookup("fields")));
} }
// Merge this functionObject dictionary into functionsDict // Merge this functionObject dictionary into functionsDict
dictionary funcArgsDict; dictionary funcArgsDict;
funcArgsDict.add(funcNameArgs, funcDict); funcArgsDict.add(funcNameArgs, funcDict);
functionsDict.subDict("functions").merge(funcArgsDict); functionsDict.merge(funcArgsDict);
return true;
} }
...@@ -229,17 +231,19 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New ...@@ -229,17 +231,19 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
( (
const argList& args, const argList& args,
const Time& runTime, const Time& runTime,
dictionary& functionsDict, dictionary& controlDict,
HashSet<word>& selectedFields HashSet<word>& requiredFields
) )
{ {
autoPtr<functionObjectList> functionsPtr; autoPtr<functionObjectList> functionsPtr;
functionsDict.add controlDict.add
( (
dictionaryEntry("functions", functionsDict, dictionary::null) dictionaryEntry("functions", controlDict, dictionary::null)
); );
dictionary& functionsDict = controlDict.subDict("functions");
if if
( (
args.optionFound("dict") args.optionFound("dict")
...@@ -249,7 +253,7 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New ...@@ -249,7 +253,7 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
{ {
if (args.optionFound("dict")) if (args.optionFound("dict"))
{ {
functionsDict.merge controlDict.merge
( (
IOdictionary IOdictionary
( (
...@@ -265,7 +269,7 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New ...@@ -265,7 +269,7 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
if (args.optionFound("func")) if (args.optionFound("func"))
{ {
readFunctionObject(args["func"], functionsDict, selectedFields); readFunctionObject(args["func"], functionsDict, requiredFields);
} }
if (args.optionFound("funcs")) if (args.optionFound("funcs"))
...@@ -274,11 +278,11 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New ...@@ -274,11 +278,11 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
forAll(funcs, i) forAll(funcs, i)
{ {
readFunctionObject(funcs[i], functionsDict, selectedFields); readFunctionObject(funcs[i], functionsDict, requiredFields);
} }
} }
functionsPtr.reset(new functionObjectList(runTime, functionsDict)); functionsPtr.reset(new functionObjectList(runTime, controlDict));
} }
else else
{ {
......
...@@ -91,13 +91,6 @@ class functionObjectList ...@@ -91,13 +91,6 @@ class functionObjectList
// Returns a NULL pointer (and index -1) if it didn't exist. // Returns a NULL pointer (and index -1) if it didn't exist.
functionObject* remove(const word&, label& oldIndex); functionObject* remove(const word&, label& oldIndex);
static void readFunctionObject
(
const word& funcNameArgs0,
dictionary& functionsDict,
HashSet<word>& selectedFields
);
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
functionObjectList(const functionObjectList&); functionObjectList(const functionObjectList&);
...@@ -142,14 +135,14 @@ public: ...@@ -142,14 +135,14 @@ public:
//- Construct and return a functionObjectList for an application. //- Construct and return a functionObjectList for an application.
// If the "dict" argument is specified the functionObjectList is // If the "dict" argument is specified the functionObjectList is
// constructed from that dictionary which is returned as // constructed from that dictionary which is returned as
// functionObjectsDict otherwise the functionObjectList is constructed // controlDict otherwise the functionObjectList is constructed
// from the "functions" sub-dictionary of "system/controlDict" // from the "functions" sub-dictionary of "system/controlDict"
static autoPtr<functionObjectList> New static autoPtr<functionObjectList> New
( (
const argList& args, const argList& args,
const Time& runTime, const Time& runTime,
dictionary& functionObjectsDict, dictionary& controlDict,
HashSet<word>& selectedFields HashSet<word>& requiredFields
); );
...@@ -194,6 +187,19 @@ public: ...@@ -194,6 +187,19 @@ public:
// otherwise null // otherwise null
static fileName findDict(const word& funcName); static fileName findDict(const word& funcName);
//- Read the specified functionObject configuration dictionary parsing
// the optional arguments included in the name 'funcNameArgs0',
// inserting 'field' or 'fields' entries as required and merging the
// resulting functionObject dictionary into 'functionsDict'. Any
// fields required to execute the functionObject are added to
// 'requiredFields'
static bool readFunctionObject
(
const word& funcNameArgs0,
dictionary& functionsDict,
HashSet<word>& requiredFields
);
//- Read and set the function objects if their data have changed //- Read and set the function objects if their data have changed
bool read(); bool read();
......
...@@ -47,8 +47,7 @@ runTimeModifiable true; ...@@ -47,8 +47,7 @@ runTimeModifiable true;
functions functions
{ {
#includeFunc mag #includeFunc mag(U)
mag{field U;}
} }
// ************************************************************************* // // ************************************************************************* //
...@@ -47,8 +47,7 @@ runTimeModifiable true; ...@@ -47,8 +47,7 @@ runTimeModifiable true;
functions functions
{ {
#includeFunc components #includeFunc components(U)
components{field U;}
} }
// ************************************************************************* // // ************************************************************************* //
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment