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
......@@ -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-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -119,8 +119,6 @@ public:
primitiveEntry&,
Istream&
);
};
......
......@@ -25,58 +25,26 @@ License
#include "includeFuncEntry.H"
#include "functionObjectList.H"
#include "dictionary.H"
#include "IFstream.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * 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 functionEntries
{
addToMemberFunctionSelectionTable
(
functionEntry,
includeFuncEntry,
execute,
dictionaryIstream
);
defineTypeNameAndDebug(includeFuncEntry, 0);
addToMemberFunctionSelectionTable
(
functionEntry,
includeFuncEntry,
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 * * * * * * * * * * * * * //
......@@ -86,66 +54,15 @@ bool Foam::functionEntries::includeFuncEntry::execute
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;
}
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);
const word fNameArgs(is);
HashSet<word> selectedFields;
return false;
}
return functionObjectList::readFunctionObject
(
fNameArgs,
parentDict,
selectedFields
);
}
......
......@@ -50,7 +50,7 @@ Description
\endverbatim
See Also
functionObjectList::findDict
Foam::functionObjectList
SourceFiles
includeFuncEntry.C
......@@ -77,30 +77,9 @@ class includeFuncEntry
:
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:
// Static data members
//- Report which file is included to stdout
static bool report;
//- Runtime type information
ClassName("includeFunc");
......@@ -109,14 +88,6 @@ public:
//- Execute the functionEntry in a sub-dict context
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)
}
void Foam::functionObjectList::readFunctionObject
bool Foam::functionObjectList::readFunctionObject
(
const word& funcNameArgs0,
dictionary& functionsDict,
HashSet<word>& selectedFields
HashSet<word>& requiredFields
)
{
// Parse the optional functionObject arguments
......@@ -153,7 +153,7 @@ void Foam::functionObjectList::readFunctionObject
{
WarningInFunction
<< "Cannot find functionObject file " << funcName << endl;
return;
return false;
}
// Read the functionObject dictionary
......@@ -163,30 +163,32 @@ void Foam::functionObjectList::readFunctionObject
// Insert the 'field' or 'fields' entry corresponding to the optional
// arguments or read the 'field' or 'fields' entry and add the required
// fields to selectedFields
// fields to requiredFields
if (args.size() == 1)
{
funcDict.set("field", args[0]);
selectedFields.insert(args[0]);
requiredFields.insert(args[0]);
}
else if (args.size() > 1)
{
funcDict.set("fields", args);
selectedFields.insert(args);
requiredFields.insert(args);
}
else if (funcDict.found("field"))
{
selectedFields.insert(word(funcDict.lookup("field")));
requiredFields.insert(word(funcDict.lookup("field")));
}
else if (funcDict.found("fields"))
{
selectedFields.insert(wordList(funcDict.lookup("fields")));
requiredFields.insert(wordList(funcDict.lookup("fields")));
}
// Merge this functionObject dictionary into functionsDict
dictionary funcArgsDict;
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
(
const argList& args,
const Time& runTime,
dictionary& functionsDict,
HashSet<word>& selectedFields
dictionary& controlDict,
HashSet<word>& requiredFields
)
{
autoPtr<functionObjectList> functionsPtr;
functionsDict.add
controlDict.add
(
dictionaryEntry("functions", functionsDict, dictionary::null)
dictionaryEntry("functions", controlDict, dictionary::null)
);
dictionary& functionsDict = controlDict.subDict("functions");
if
(
args.optionFound("dict")
......@@ -249,7 +253,7 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
{
if (args.optionFound("dict"))
{
functionsDict.merge
controlDict.merge
(
IOdictionary
(
......@@ -265,7 +269,7 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
if (args.optionFound("func"))
{
readFunctionObject(args["func"], functionsDict, selectedFields);
readFunctionObject(args["func"], functionsDict, requiredFields);
}
if (args.optionFound("funcs"))
......@@ -274,11 +278,11 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
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
{
......
......@@ -91,13 +91,6 @@ class functionObjectList
// Returns a NULL pointer (and index -1) if it didn't exist.
functionObject* remove(const word&, label& oldIndex);
static void readFunctionObject
(
const word& funcNameArgs0,
dictionary& functionsDict,
HashSet<word>& selectedFields
);
//- Disallow default bitwise copy construct
functionObjectList(const functionObjectList&);
......@@ -142,14 +135,14 @@ public:
//- Construct and return a functionObjectList for an application.
// If the "dict" argument is specified the functionObjectList is
// 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"
static autoPtr<functionObjectList> New
(
const argList& args,
const Time& runTime,
dictionary& functionObjectsDict,
HashSet<word>& selectedFields
dictionary& controlDict,
HashSet<word>& requiredFields
);
......@@ -194,6 +187,19 @@ public:
// otherwise null
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
bool read();
......
......@@ -47,8 +47,7 @@ runTimeModifiable true;
functions
{
#includeFunc mag
mag{field U;}
#includeFunc mag(U)
}
// ************************************************************************* //
......@@ -47,8 +47,7 @@ runTimeModifiable true;
functions
{
#includeFunc components
components{field U;}
#includeFunc components(U)
}
// ************************************************************************* //
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment