functionObjects::add: Add list of fields

The operation can be applied to any volume or surface fields generating a
    volume or surface scalar field.

    Example of function object specification:
    \verbatim
    Ttot
    {
        type            add;
        libs            ("libfieldFunctionObjects.so");
        fields          (T Tdelta);
        result          Ttot;
        executeControl  writeTime;
        writeControl    writeTime;
    }
    \endverbatim

Also refactored functionObjects::fieldsExpression to avoid code
duplication between the 'add' and 'subtract' functionObjects.
This commit is contained in:
Henry Weller
2016-11-19 21:48:48 +00:00
parent 21fbad85fb
commit 56919a4442
10 changed files with 377 additions and 64 deletions

View File

@ -52,12 +52,12 @@ void Foam::functionObjects::fieldsExpression::setResultName
if (resultName_.empty())
{
if (fieldNames_ != defaultArgs)
if (!fieldNames_.empty())
{
resultName_ = typeName + '(';
forAll(fieldNames_, i)
resultName_ = typeName + '(' + fieldNames_[0];
for (label i=1; i<fieldNames_.size(); i++)
{
resultName_ += fieldNames_[i];
resultName_ += ',' + fieldNames_[i];
}
resultName_ += ')';
}
@ -85,6 +85,15 @@ Foam::functionObjects::fieldsExpression::fieldsExpression
resultName_(resultName)
{
read(dict);
if (fieldNames_.size() < 2)
{
FatalIOErrorInFunction(dict)
<< "functionObject::" << type() << " " << name
<< " requires at least 2 fields only "
<< fieldNames_.size() << " provided: " << fieldNames_
<< exit(FatalIOError);
}
}