GIT: Initial state after latest Foundation merge

This commit is contained in:
Andrew Heather
2016-09-20 14:49:08 +01:00
4571 changed files with 115696 additions and 74609 deletions

View File

@ -0,0 +1,119 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fieldValue.H"
#include "Time.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(fieldValue, 0);
defineRunTimeSelectionTable(fieldValue, dictionary);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValue::fieldValue
(
const word& name,
const Time& runTime,
const dictionary& dict,
const word& valueType
)
:
fvMeshFunctionObject(name, runTime, dict),
writeFile(obr_, name, valueType, dict),
scaleFactor_(1.0),
dict_(dict),
regionName_(word::null)
{
read(dict);
}
Foam::functionObjects::fieldValue::fieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const word& valueType
)
:
fvMeshFunctionObject(name, obr, dict),
writeFile(obr_, name, valueType, dict),
scaleFactor_(1.0),
dict_(dict),
regionName_(word::null)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValue::~fieldValue()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldValue::read(const dictionary& dict)
{
if (dict != dict_)
{
dict_ = dict;
}
fvMeshFunctionObject::read(dict);
dict.lookup("fields") >> fields_;
dict.lookup("writeFields") >> writeFields_;
dict.readIfPresent("scaleFactor", scaleFactor_);
return true;
}
bool Foam::functionObjects::fieldValue::execute()
{
return true;
}
bool Foam::functionObjects::fieldValue::write()
{
Log << type() << " " << name() << " write:" << nl;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,199 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::fieldValue
Group
grpFieldFunctionObjects
Description
Base class for field value-based function objects.
See also
Foam::functionObject
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::writeFile
SourceFiles
fieldValue.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldValue_H
#define functionObjects_fieldValue_H
#include "fvMeshFunctionObject.H"
#include "writeFile.H"
#include "Switch.H"
#include "Field.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class fvMesh;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fieldValue Declaration
\*---------------------------------------------------------------------------*/
class fieldValue
:
public fvMeshFunctionObject,
public writeFile
{
protected:
// Protected data
//- Construction dictionary
dictionary dict_;
//- Name of region (patch, zone, etc.)
word regionName_;
//- List of field names to operate on
wordList fields_;
//- Output field values flag
Switch writeFields_;
// Protected Member Functions
//- Combine fields from all processor domains into single field
template<class Type>
void combineFields(Field<Type>& field);
//- Combine fields from all processor domains into single field
template<class Type>
void combineFields(tmp<Field<Type>>&);
public:
//- Run-time type information
TypeName("fieldValue");
// Declare runtime constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
fieldValue,
dictionary,
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
),
(name, obr, dict)
);
// Constructors
//- Construct from Time and dictionary
fieldValue
(
const word& name,
const Time& runTime,
const dictionary& dict,
const word& valueType
);
//- Construct from objectRegistry and dictionary
fieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const word& valueType
);
//- Return a reference to the selected fieldValue
static autoPtr<fieldValue> New
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool output = true
);
//- Destructor
virtual ~fieldValue();
// Member Functions
//- Return the reference to the construction dictionary
inline const dictionary& dict() const;
//- Return the region name
inline const word& regionName() const;
//- Return the list of field names
inline const wordList& fields() const;
//- Return the output field values flag
inline const Switch& writeFields() const;
//- Read from dictionary
virtual bool read(const dictionary& dict);
//- Execute
virtual bool execute();
//- Write
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "fieldValueI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldValueTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,53 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::dictionary& Foam::functionObjects::fieldValue::dict() const
{
return dict_;
}
inline const Foam::word& Foam::functionObjects::fieldValue::regionName() const
{
return regionName_;
}
inline const Foam::wordList& Foam::functionObjects::fieldValue::fields() const
{
return fields_;
}
inline const Foam::Switch&
Foam::functionObjects::fieldValue::writeFields() const
{
return writeFields_;
}
// ************************************************************************* //

View File

@ -0,0 +1,63 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fieldValue.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::functionObjects::fieldValue>
Foam::functionObjects::fieldValue::New
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool output
)
{
const word modelType(dict.lookup("type"));
if (output)
{
Info<< "Selecting " << typeName << " " << modelType << endl;
}
dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(modelType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown " << typeName << " type "
<< modelType << nl << nl
<< "Valid " << typeName << " types are:" << nl
<< dictionaryConstructorTablePtr_->sortedToc()
<< exit(FatalError);
}
return autoPtr<fieldValue>(cstrIter()(name, obr, dict));
}
// ************************************************************************* //

View File

@ -0,0 +1,58 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fieldValue.H"
#include "ListListOps.H"
#include "Pstream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::functionObjects::fieldValue::combineFields(Field<Type>& field)
{
List<Field<Type>> allValues(Pstream::nProcs());
allValues[Pstream::myProcNo()] = field;
Pstream::gatherList(allValues);
Pstream::scatterList(allValues);
field =
ListListOps::combine<Field<Type>>
(
allValues,
accessOp<Field<Type>>()
);
}
template<class Type>
void Foam::functionObjects::fieldValue::combineFields(tmp<Field<Type>>& field)
{
combineFields(field());
}
// ************************************************************************* //

View File

@ -0,0 +1,233 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fieldValueDelta.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
defineTypeNameAndDebug(fieldValueDelta, 0);
addToRunTimeSelectionTable(functionObject, fieldValueDelta, dictionary);
}
}
}
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldValues::fieldValueDelta::operationType,
5
>::names[] =
{
"add",
"subtract",
"min",
"max",
"average"
};
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::fieldValueDelta::operationType,
5
> Foam::functionObjects::fieldValues::fieldValueDelta::operationTypeNames_;
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
void Foam::fieldValues::fieldValueDelta::writeFileHeader(Ostream& os) const
{
const wordList& fields1 = region1Ptr_->fields();
const wordList& fields2 = region2Ptr_->fields();
DynamicList<word> commonFields(fields1.size());
forAll(fields1, fieldi)
{
label index = findIndex(fields2, fields1[fieldi]);
if (index != -1)
{
commonFields.append(fields1[fieldi]);
}
}
writeHeaderValue(os, "Source1", region1Ptr_->name());
writeHeaderValue(os, "Source2", region2Ptr_->name());
writeHeaderValue(os, "Operation", operationTypeNames_[operation_]);
writeCommented(os, "Time");
forAll(commonFields, i)
{
os << tab << commonFields[i];
}
os << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::fieldValueDelta::fieldValueDelta
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
regionFunctionObject(name, runTime, dict),
writeFile(obr_, name, typeName, dict),
operation_(opSubtract),
region1Ptr_(nullptr),
region2Ptr_(nullptr)
{
read(dict);
writeFileHeader(file());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::fieldValueDelta::~fieldValueDelta()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldValues::fieldValueDelta::read
(
const dictionary& dict
)
{
regionFunctionObject::read(dict);
writeFile::read(dict);
region1Ptr_.reset
(
fieldValue::New
(
name() + ".region1",
obr_,
dict.subDict("region1"),
false
).ptr()
);
region2Ptr_.reset
(
fieldValue::New
(
name() + ".region2",
obr_,
dict.subDict("region2"),
false
).ptr()
);
operation_ = operationTypeNames_.read(dict.lookup("operation"));
return true;
}
bool Foam::functionObjects::fieldValues::fieldValueDelta::write()
{
region1Ptr_->write();
region2Ptr_->write();
writeTime(file());
Log << type() << " " << name() << " write:" << endl;
const word& name1 = source1Ptr_->name();
const word& name2 = source2Ptr_->name();
const wordList entries1 = objectResultEntries(name1);
const wordList entries2 = objectResultEntries(name2);
if (entries1.size() != entries2.size())
{
FatalErrorInFunction
<< name_ << ": objects must generate the same number of results"
<< nl
<< " " << name1 << " objects: " << entries1 << nl
<< " " << name2 << " objects: " << entries2 << nl
<< exit(FatalError);
}
forAll(entries1, i)
{
const word& entry1(entries1[i]);
const word& entry2(entries2[i]);
const word type1 = objectResultType(name1, entry1);
const word type2 = objectResultType(name2, entry2);
if (type1 != type2)
{
FatalErrorInFunction
<< name_
<< ": input values for operation must be of the same type"
<< nl
<< " " << entry1 << ": " << type1 << nl
<< " " << entry2 << ": " << type2 << nl
<< exit(FatalError);
}
bool found = false;
applyOperation<scalar>(type1, name1, name2, entry1, entry2, found);
applyOperation<vector>(type1, name1, name2, entry1, entry2, found);
applyOperation<sphericalTensor>
(type1, name1, name2, entry1, entry2, found);
applyOperation<symmTensor>(type1, name1, name2, entry1, entry2, found);
applyOperation<tensor>(type1, name1, name2, entry1, entry2, found);
if (log && !found)
{
Info<< "Operation between "
<< name1 << " with result " << entry1 << " and "
<< name2 << " with result " << entry2 << " not applied"
<< endl;
}
}
Log << (entries1.empty() ? " none" : "") << endl;
file()<< endl;
return true;
}
bool Foam::functionObjects::fieldValues::fieldValueDelta::execute()
{
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,245 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
<<<<<<< HEAD:src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
=======
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation |
>>>>>>> foundation-github:src/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::fieldValues::fieldValueDelta
Group
grpFieldFunctionObjects
Description
<<<<<<< HEAD:src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H
This function object provides applies an operation to the output of two
fieldValue function objects.
The operation is applied to all results of each fieldValue object.
Accordingly, each object must generate the same number and type of results.
=======
Provides a differencing option between two 'field value' function objects.
>>>>>>> foundation-github:src/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H
Example of function object specification:
\verbatim
fieldValueDelta1
{
type fieldValueDelta;
libs ("libfieldFunctionObjects.so");
operation subtract;
source1
{
...
}
source2
{
...
}
}
\endverbatim
Usage
\table
Property | Description | Required | Default value
type | type name: fieldValueDelta | yes |
\endtable
The \c operation is one of:
\plaintable
add | add
subtract | subtract
min | minimum
max | maximum
average | average
\endplaintable
<<<<<<< HEAD:src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H
SeeAlso
Foam::fieldValue
=======
See also
Foam::functionObject
Foam::functionObject::fieldValue
Foam::functionObjects::regionFunctionObject
Foam::functionObjects::logFiles
>>>>>>> foundation-github:src/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H
SourceFiles
fieldValueDelta.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldValueDelta_H
#define functionObjects_fieldValueDelta_H
<<<<<<< HEAD:src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H
#include "functionObjectState.H"
#include "functionObjectFile.H"
=======
#include "regionFunctionObject.H"
#include "logFiles.H"
>>>>>>> foundation-github:src/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H
#include "fieldValue.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
/*---------------------------------------------------------------------------*\
Class fieldValueDelta Declaration
\*---------------------------------------------------------------------------*/
class fieldValueDelta
:
<<<<<<< HEAD:src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H
public functionObjectState,
public functionObjectFile
=======
public regionFunctionObject,
public logFiles
>>>>>>> foundation-github:src/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H
{
public:
//- Operation type enumeration
enum operationType
{
opAdd,
opSubtract,
opMin,
opMax,
opAverage
};
//- Operation type names
static const NamedEnum<operationType, 5> operationTypeNames_;
private:
// Private data
<<<<<<< HEAD:src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H
//- Database this class is registered to
const objectRegistry& obr_;
//- Flag to indicate to load from files
bool loadFromFiles_;
//- Switch to send output to Info as well as to file
Switch log_;
=======
>>>>>>> foundation-github:src/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H
//- Operation to apply to values
operationType operation_;
//- Field value region object 1
autoPtr<fieldValue> region1Ptr_;
//- Field value region object 2
autoPtr<fieldValue> region2Ptr_;
// Private Member Functions
//- Templated function to apply the operation
template<class Type>
void apply
(
const word& resultType,
const word& name1,
const word& name2,
const word& entryName1,
const word& entryName2,
bool& found
);
protected:
// Protected Member Functions
//- Output file header information
virtual void writeFileHeader(Ostream& os) const;
public:
//- Run-time type information
TypeName("fieldValueDelta");
// Constructors
//- Construct from Time and dictionary
fieldValueDelta
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~fieldValueDelta();
// Public Member Functions
//- Read from dictionary
virtual bool read(const dictionary&);
//- Do nothing
virtual bool execute();
//- Calculate and write
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fieldValues
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldValueDeltaTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,100 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Type Foam::functionObjects::fieldValues::fieldValueDelta::applyOperation
(
const word& resultType,
const word& name1,
const word& name2,
const word& entryName1,
const word& entryName2,
bool& found
)
{
if (pTraits<Type>::typeName != resultType)
{
return;
}
Type result = Zero;
Type value1 = this->getObjectResult<Type>(name1, entryName1);
Type value2 = this->getObjectResult<Type>(name2, entryName2);
const word& opName = operationTypeNames_[operation_];
switch (operation_)
{
case opAdd:
{
result = value1 + value2;
break;
}
case opSubtract:
{
result = value1 - value2;
break;
}
case opMin:
{
result = min(value1, value2);
break;
}
case opMax:
{
result = max(value1, value2);
break;
}
case opAverage:
{
result = 0.5*(value1 + value2);
break;
}
default:
{
FatalErrorInFunction
<< "Unable to process operation "
<< operationTypeNames_[operation_]
<< abort(FatalError);
}
}
const word resultName(opName + '(' + entryName1 + ',' + entryName2 + ')');
Log << " " << resultName << " = " << result << endl;
this->file()<< tab << result;
// Write state/results information
this->setResult(resultName, result);
found = true;
}
// ************************************************************************* //

View File

@ -0,0 +1,785 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "surfaceFieldValue.H"
#include "fvMesh.H"
#include "cyclicPolyPatch.H"
#include "emptyPolyPatch.H"
#include "coupledPolyPatch.H"
#include "sampledSurface.H"
#include "mergePoints.H"
#include "indirectPrimitivePatch.H"
#include "PatchTools.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
defineTypeNameAndDebug(surfaceFieldValue, 0);
addToRunTimeSelectionTable(fieldValue, surfaceFieldValue, dictionary);
addToRunTimeSelectionTable(functionObject, surfaceFieldValue, dictionary);
}
}
}
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes,
3
>::names[] =
{
"faceZone",
"patch",
"sampledSurface"
};
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceFieldValue::operationType,
15
>::names[] =
{
"none",
"sum",
"sumMag",
"sumDirection",
"sumDirectionBalance",
"average",
"weightedAverage",
"areaAverage",
"weightedAreaAverage",
"areaIntegrate",
"min",
"max",
"CoV",
"areaNormalAverage",
"areaNormalIntegrate"
};
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes,
3
> Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypeNames_;
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceFieldValue::operationType,
15
> Foam::functionObjects::fieldValues::surfaceFieldValue::operationTypeNames_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldValues::surfaceFieldValue::setFaceZoneFaces()
{
label zoneId = mesh_.faceZones().findZoneID(regionName_);
if (zoneId < 0)
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
<< " Unknown face zone name: " << regionName_
<< ". Valid face zones are: " << mesh_.faceZones().names()
<< nl << exit(FatalError);
}
const faceZone& fZone = mesh_.faceZones()[zoneId];
DynamicList<label> faceIds(fZone.size());
DynamicList<label> facePatchIds(fZone.size());
DynamicList<label> faceSigns(fZone.size());
forAll(fZone, i)
{
label facei = fZone[i];
label faceId = -1;
label facePatchId = -1;
if (mesh_.isInternalFace(facei))
{
faceId = facei;
facePatchId = -1;
}
else
{
facePatchId = mesh_.boundaryMesh().whichPatch(facei);
const polyPatch& pp = mesh_.boundaryMesh()[facePatchId];
if (isA<coupledPolyPatch>(pp))
{
if (refCast<const coupledPolyPatch>(pp).owner())
{
faceId = pp.whichFace(facei);
}
else
{
faceId = -1;
}
}
else if (!isA<emptyPolyPatch>(pp))
{
faceId = facei - pp.start();
}
else
{
faceId = -1;
facePatchId = -1;
}
}
if (faceId >= 0)
{
if (fZone.flipMap()[i])
{
faceSigns.append(-1);
}
else
{
faceSigns.append(1);
}
faceIds.append(faceId);
facePatchIds.append(facePatchId);
}
}
faceId_.transfer(faceIds);
facePatchId_.transfer(facePatchIds);
faceSign_.transfer(faceSigns);
nFaces_ = returnReduce(faceId_.size(), sumOp<label>());
if (debug)
{
Pout<< "Original face zone size = " << fZone.size()
<< ", new size = " << faceId_.size() << endl;
}
}
void Foam::functionObjects::fieldValues::surfaceFieldValue::setPatchFaces()
{
const label patchid = mesh_.boundaryMesh().findPatchID(regionName_);
if (patchid < 0)
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
<< " Unknown patch name: " << regionName_
<< ". Valid patch names are: "
<< mesh_.boundaryMesh().names() << nl
<< exit(FatalError);
}
const polyPatch& pp = mesh_.boundaryMesh()[patchid];
label nFaces = pp.size();
if (isA<emptyPolyPatch>(pp))
{
nFaces = 0;
}
faceId_.setSize(nFaces);
facePatchId_.setSize(nFaces);
faceSign_.setSize(nFaces);
nFaces_ = returnReduce(faceId_.size(), sumOp<label>());
forAll(faceId_, facei)
{
faceId_[facei] = facei;
facePatchId_[facei] = patchid;
faceSign_[facei] = 1;
}
}
void Foam::functionObjects::fieldValues::surfaceFieldValue::sampledSurfaceFaces
(
const dictionary& dict
)
{
surfacePtr_ = sampledSurface::New
(
name(),
mesh_,
dict.subDict("sampledSurfaceDict")
);
surfacePtr_().update();
nFaces_ = returnReduce(surfacePtr_().faces().size(), sumOp<label>());
}
void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
(
faceList& faces,
pointField& points
) const
{
List<faceList> allFaces(Pstream::nProcs());
List<pointField> allPoints(Pstream::nProcs());
labelList globalFacesIs(faceId_);
forAll(globalFacesIs, i)
{
if (facePatchId_[i] != -1)
{
label patchi = facePatchId_[i];
globalFacesIs[i] += mesh_.boundaryMesh()[patchi].start();
}
}
// Add local faces and points to the all* lists
indirectPrimitivePatch pp
(
IndirectList<face>(mesh_.faces(), globalFacesIs),
mesh_.points()
);
allFaces[Pstream::myProcNo()] = pp.localFaces();
allPoints[Pstream::myProcNo()] = pp.localPoints();
Pstream::gatherList(allFaces);
Pstream::gatherList(allPoints);
// Renumber and flatten
label nFaces = 0;
label nPoints = 0;
forAll(allFaces, proci)
{
nFaces += allFaces[proci].size();
nPoints += allPoints[proci].size();
}
faces.setSize(nFaces);
points.setSize(nPoints);
nFaces = 0;
nPoints = 0;
// My own data first
{
const faceList& fcs = allFaces[Pstream::myProcNo()];
forAll(fcs, i)
{
const face& f = fcs[i];
face& newF = faces[nFaces++];
newF.setSize(f.size());
forAll(f, fp)
{
newF[fp] = f[fp] + nPoints;
}
}
const pointField& pts = allPoints[Pstream::myProcNo()];
forAll(pts, i)
{
points[nPoints++] = pts[i];
}
}
// Other proc data follows
forAll(allFaces, proci)
{
if (proci != Pstream::myProcNo())
{
const faceList& fcs = allFaces[proci];
forAll(fcs, i)
{
const face& f = fcs[i];
face& newF = faces[nFaces++];
newF.setSize(f.size());
forAll(f, fp)
{
newF[fp] = f[fp] + nPoints;
}
}
const pointField& pts = allPoints[proci];
forAll(pts, i)
{
points[nPoints++] = pts[i];
}
}
}
// Merge
labelList oldToNew;
pointField newPoints;
bool hasMerged = mergePoints
(
points,
SMALL,
false,
oldToNew,
newPoints
);
if (hasMerged)
{
if (debug)
{
Pout<< "Merged from " << points.size()
<< " down to " << newPoints.size() << " points" << endl;
}
points.transfer(newPoints);
forAll(faces, i)
{
inplaceRenumber(oldToNew, faces[i]);
}
}
}
void Foam::functionObjects::fieldValues::surfaceFieldValue::
combineSurfaceGeometry
(
faceList& faces,
pointField& points
) const
{
if (surfacePtr_.valid())
{
const sampledSurface& s = surfacePtr_();
if (Pstream::parRun())
{
// Dimension as fraction of mesh bounding box
scalar mergeDim = 1e-10*mesh_.bounds().mag();
labelList pointsMap;
PatchTools::gatherAndMerge
(
mergeDim,
primitivePatch
(
SubList<face>(s.faces(), s.faces().size()),
s.points()
),
points,
faces,
pointsMap
);
}
else
{
faces = s.faces();
points = s.points();
}
}
}
Foam::scalar
Foam::functionObjects::fieldValues::surfaceFieldValue::totalArea() const
{
scalar totalArea;
if (surfacePtr_.valid())
{
totalArea = gSum(surfacePtr_().magSf());
}
else
{
totalArea = gSum(filterField(mesh_.magSf(), false));
}
return totalArea;
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldValues::surfaceFieldValue::initialise
(
const dictionary& dict
)
{
dict.lookup("name") >> regionName_;
switch (regionType_)
{
case stFaceZone:
{
setFaceZoneFaces();
break;
}
case stPatch:
{
setPatchFaces();
break;
}
case stSampledSurface:
{
sampledSurfaceFaces(dict);
break;
}
default:
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):"
<< nl << " Unknown region type. Valid region types are:"
<< regionTypeNames_.sortedToc() << nl << exit(FatalError);
}
}
if (nFaces_ == 0)
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
<< " Region has no faces" << exit(FatalError);
}
if (surfacePtr_.valid())
{
surfacePtr_().update();
}
totalArea_ = totalArea();
Info<< type() << " " << name() << ":" << nl
<< " total faces = " << nFaces_ << nl
<< " total area = " << totalArea_ << nl;
if (dict.readIfPresent("weightField", weightFieldName_))
{
Info<< " weight field = " << weightFieldName_ << nl;
if (regionType_ == stSampledSurface)
{
FatalIOErrorInFunction(dict)
<< "Cannot use weightField for a sampledSurface"
<< exit(FatalIOError);
}
}
if (dict.found("orientedWeightField"))
{
if (weightFieldName_ == "none")
{
dict.lookup("orientedWeightField") >> weightFieldName_;
if (log_) Info << " weight field = " << weightFieldName_ << nl;
orientWeightField_ = true;
}
else
{
FatalIOErrorInFunction(dict)
<< "Either weightField or orientedWeightField can be supplied, "
<< "but not both"
<< exit(FatalIOError);
}
}
List<word> orientedFields;
if (dict.readIfPresent("orientedFields", orientedFields))
{
orientedFieldsStart_ = fields_.size();
fields_.append(orientedFields);
}
Info<< nl << endl;
if (writeFields_)
{
const word surfaceFormat(dict.lookup("surfaceFormat"));
surfaceWriterPtr_.reset
(
surfaceWriter::New
(
surfaceFormat,
dict.subOrEmptyDict("formatOptions").
subOrEmptyDict(surfaceFormat)
).ptr()
);
}
}
void Foam::fieldValues::faceSource::writeFileHeader(Ostream& os) const
{
if (operation_ != opNone)
{
writeCommented(os, "Region type : ");
os << regionTypeNames_[regionType_] << " " << regionName_ << endl;
writeHeaderValue(os, "Faces", nFaces_);
writeHeaderValue(os, "Area", totalArea_);
writeHeaderValue(os, "Scale factor", scaleFactor_);
writeCommented(os, "Time");
if (writeArea_)
{
os << tab << "Area";
}
forAll(fields_, i)
{
os << tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
}
os << endl;
}
}
template<>
Foam::scalar Foam::functionObjects::fieldValues::surfaceFieldValue::
processValues
(
const Field<scalar>& values,
const vectorField& Sf,
const scalarField& weightField
) const
{
switch (operation_)
{
case opSumDirection:
{
vector n(dict_.lookup("direction"));
return gSum(pos(values*(Sf & n))*mag(values));
}
case opSumDirectionBalance:
{
vector n(dict_.lookup("direction"));
const scalarField nv(values*(Sf & n));
return gSum(pos(nv)*mag(values) - neg(nv)*mag(values));
}
default:
{
// Fall through to other operations
return processSameTypeValues(values, Sf, weightField);
}
}
}
template<>
Foam::vector Foam::functionObjects::fieldValues::surfaceFieldValue::
processValues
(
const Field<vector>& values,
const vectorField& Sf,
const scalarField& weightField
) const
{
switch (operation_)
{
case opSumDirection:
{
vector n(dict_.lookup("direction"));
n /= mag(n) + ROOTVSMALL;
const scalarField nv(n & values);
return gSum(pos(nv)*n*(nv));
}
case opSumDirectionBalance:
{
vector n(dict_.lookup("direction"));
n /= mag(n) + ROOTVSMALL;
const scalarField nv(n & values);
return gSum(pos(nv)*n*(nv));
}
case opAreaNormalAverage:
{
scalar result = gSum(values & Sf)/gSum(mag(Sf));
return vector(result, 0.0, 0.0);
}
case opAreaNormalIntegrate:
{
scalar result = gSum(values & Sf);
return vector(result, 0.0, 0.0);
}
default:
{
// Fall through to other operations
return processSameTypeValues(values, Sf, weightField);
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::surfaceFieldValue::surfaceFieldValue
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldValue(name, runTime, dict, typeName),
surfaceWriterPtr_(nullptr),
regionType_(regionTypeNames_.read(dict.lookup("regionType"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("none"),
orientWeightField_(false),
orientedFieldsStart_(labelMax),
scaleFactor_(1.0),
writeArea_(dict.lookupOrDefault("writeArea", false)),
nFaces_(0),
faceId_(),
facePatchId_(),
faceSign_()
{
read(dict);
writeFileHeader(file());
}
Foam::functionObjects::fieldValues::surfaceFieldValue::surfaceFieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
)
:
fieldValue(name, obr, dict, typeName),
surfaceWriterPtr_(nullptr),
regionType_(regionTypeNames_.read(dict.lookup("regionType"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("none"),
orientWeightField_(false),
orientedFieldsStart_(labelMax),
scaleFactor_(1.0),
writeArea_(dict.lookupOrDefault("writeArea", false)),
nFaces_(0),
faceId_(),
facePatchId_(),
faceSign_()
{
read(dict);
writeFileHeader(file());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::surfaceFieldValue::~surfaceFieldValue()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldValues::surfaceFieldValue::read
(
const dictionary& dict
)
{
fieldValue::read(dict);
initialise(dict);
return true;
}
bool Foam::functionObjects::fieldValues::surfaceFieldValue::write()
{
if (operation_ != opNone)
{
fieldValue::write();
}
if (surfacePtr_.valid())
{
surfacePtr_().update();
}
if (operation_ != opNone && Pstream::master())
{
writeTime(file());
}
if (writeArea_)
{
totalArea_ = totalArea();
if (operation_ != opNone && Pstream::master())
{
file() << tab << totalArea_;
}
Log << " total area = " << totalArea_ << endl;
}
// Construct weight field. Note: zero size means weight = 1
scalarField weightField;
if (weightFieldName_ != "none")
{
weightField =
getFieldValues<scalar>
(
weightFieldName_,
true,
orientWeightField_
);
}
// Process the fields
forAll(fields_, i)
{
const word& fieldName = fields_[i];
bool ok = false;
bool orient = i >= orientedFieldsStart_;
ok = ok || writeValues<scalar>(fieldName, weightField, orient);
ok = ok || writeValues<vector>(fieldName, weightField, orient);
ok = ok
|| writeValues<sphericalTensor>(fieldName, weightField, orient);
ok = ok || writeValues<symmTensor>(fieldName, weightField, orient);
ok = ok || writeValues<tensor>(fieldName, weightField, orient);
if (!ok)
{
WarningInFunction
<< "Requested field " << fieldName
<< " not found in database and not processed"
<< endl;
}
}
if (operation_ != opNone && Pstream::master())
{
file() << endl;
}
Log << endl;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,474 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::fieldValues::surfaceFieldValue
Group
grpFieldFunctionObjects
Description
Provides a 'face regionType' variant of the fieldValues function object.
Given a list of user-specified fields and a selection of mesh (or general
surface) faces, a number of operations can be performed, such as sums,
averages and integrations.
For example, to calculate the volumetric or mass flux across a patch,
apply the 'sum' operator to the flux field (typically \c phi)
Examples of function object specification:
\verbatim
movingWallPatch
{
type surfaceFieldValue;
libs ("libfieldFunctionObjects.so");
log true;
writeControl writeTime;
writeFields true;
regionType patch;
name movingWall;
operation areaAverage;
fields
(
p
phi
U
);
}
surfaceFieldValue1
{
type surfaceFieldValue;
libs ("libfieldFunctionObjects.so");
log true;
writeControl writeTime;
writeFields true;
surfaceFormat none;
regionType faceZone;
name f0;
operation sum;
weightField alpha1;
fields
(
p
phi
U
);
}
\endverbatim
Usage
\table
Property | Description | Required | Default value
type | type name: surfaceFieldValue | yes |
log | write data to standard output | no | no
writeFields | Write the region field values | yes |
writeArea | Write the area of the surfaceFieldValue | no |
surfaceFormat | output value format | no |
regionType | face regionType: see below | yes |
name | name of face regionType if required | no |
operation | operation to perform | yes |
weightField | name of field to apply weighting | no |
orientedWeightField | name of oriented field to apply weighting | no |
scaleFactor | scale factor | no | 1
fields | list of fields to operate on | yes |
orientedFields | list of oriented fields to operate on | no |
\endtable
Where \c regionType is defined by
\plaintable
faceZone | requires a 'name' entry to specify the faceZone
patch | requires a 'name' entry to specify the patch
sampledSurface | requires a 'sampledSurfaceDict' sub-dictionary
\endplaintable
The \c operation is one of:
\plaintable
none | no operation
sum | sum
sumMag | sum of component magnitudes
sumDirection | sum values which are positive in given direction
sumDirectionBalance | sum of balance of values in given direction
average | ensemble average
weightedAverage | weighted average
areaAverage | area weighted average
weightedAreaAverage | weighted area average
areaIntegrate | area integral
min | minimum
max | maximum
CoV | coefficient of variation: standard deviation/mean
areaNormalAverage| area weighted average in face normal direction
areaNormalIntegrate | area weighted integral in face normal directon
\endplaintable
Note
- The values reported by the areaNormalAverage and areaNormalIntegrate
operations are written as the first component of a field with the same
rank as the input field.
- faces on empty patches get ignored
- if the field is a volField the \c faceZone can only consist of boundary
faces
- the `oriented' entries relate to mesh-oriented fields, such as the
flux, phi. These fields will be oriented according to the face normals.
- using \c sampledSurface:
- not available for surface fields
- if interpolate=true they use \c interpolationCellPoint
otherwise they use cell values
- each triangle in \c sampledSurface is logically only in one cell
so interpolation will be wrong when triangles are larger than
cells. This can only happen for sampling on a \c triSurfaceMesh
- take care when using isoSurfaces - these might have duplicate
triangles and so integration might be wrong
See also
Foam::fieldValues
Foam::functionObject
SourceFiles
surfaceFieldValue.C
surfaceFieldValueTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_surfaceFieldValue_H
#define functionObjects_surfaceFieldValue_H
#include "fieldValue.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class sampledSurface;
class surfaceWriter;
namespace functionObjects
{
namespace fieldValues
{
/*---------------------------------------------------------------------------*\
Class surfaceFieldValue Declaration
\*---------------------------------------------------------------------------*/
class surfaceFieldValue
:
public fieldValue
{
public:
// Public data types
//- region type enumeration
enum regionTypes
{
stFaceZone,
stPatch,
stSampledSurface
};
//- region type names
static const NamedEnum<regionTypes, 3> regionTypeNames_;
//- Operation type enumeration
enum operationType
{
opNone,
opSum,
opSumMag,
opSumDirection,
opSumDirectionBalance,
opAverage,
opWeightedAverage,
opAreaAverage,
opWeightedAreaAverage,
opAreaIntegrate,
opMin,
opMax,
opCoV,
opAreaNormalAverage,
opAreaNormalIntegrate
};
//- Operation type names
static const NamedEnum<operationType, 15> operationTypeNames_;
private:
// Private Member Functions
//- Set faces to evaluate based on a face zone
void setFaceZoneFaces();
//- Set faces to evaluate based on a patch
void setPatchFaces();
//- Set faces according to sampledSurface
void sampledSurfaceFaces(const dictionary&);
//- Combine mesh faces and points from multiple processors
void combineMeshGeometry
(
faceList& faces,
pointField& points
) const;
//- Combine surface faces and points from multiple processors
void combineSurfaceGeometry
(
faceList& faces,
pointField& points
) const;
//- Calculate and return total area of the surfaceFieldValue: sum(magSf)
scalar totalArea() const;
protected:
// Protected data
//- Surface writer
autoPtr<surfaceWriter> surfaceWriterPtr_;
//- region type
regionTypes regionType_;
//- Operation to apply to values
operationType operation_;
//- Weight field name - optional
word weightFieldName_;
//- Flag to indicate if flipMap should be applied to the weight field
bool orientWeightField_;
//- Start index of fields that require application of flipMap
label orientedFieldsStart_;
//- Total area of the surfaceFieldValue
scalar totalArea_;
//- Optionally write the area of the surfaceFieldValue
bool writeArea_;
//- Global number of faces
label nFaces_;
// If operating on mesh faces (faceZone, patch)
//- Local list of face IDs
labelList faceId_;
//- Local list of patch ID per face
labelList facePatchId_;
//- List of +1/-1 representing face flip map
// (1 use as is, -1 negate)
labelList faceSign_;
// If operating on sampledSurface
//- Underlying sampledSurface
autoPtr<sampledSurface> surfacePtr_;
// Protected Member Functions
//- Initialise, e.g. face addressing
void initialise(const dictionary& dict);
//- Return true if the field name is valid
template<class Type>
bool validField(const word& fieldName) const;
//- Return field values by looking up field name
template<class Type>
tmp<Field<Type>> setFieldValues
(
const word& fieldName,
const bool mustGet = false,
const bool applyOrientation = false
) const;
//- Apply the 'operation' to the values. Operation has to
// preserve Type.
template<class Type>
Type processSameTypeValues
(
const Field<Type>& values,
const vectorField& Sf,
const scalarField& weightField
) const;
//- Apply the 'operation' to the values. Wrapper around
// processSameTypeValues. See also template specialisation below.
template<class Type>
Type processValues
(
const Field<Type>& values,
const vectorField& Sf,
const scalarField& weightField
) const;
//- Output file header information
virtual void writeFileHeader(Ostream& os) const;
public:
//- Run-time type information
TypeName("surfaceFieldValue");
// Constructors
//- Construct from name, Time and dictionary
surfaceFieldValue
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Construct from name, objectRegistry and dictionary
surfaceFieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
);
//- Destructor
virtual ~surfaceFieldValue();
// Public Member Functions
//- Return the region type
inline const regionTypes& regionType() const;
//- Return the local list of face IDs
inline const labelList& faceId() const;
//- Return the local list of patch ID per face
inline const labelList& facePatch() const;
//- Return the list of +1/-1 representing face flip map
inline const labelList& faceSign() const;
//- Return the output directory
inline fileName outputDir() const;
//- Templated helper function to output field values
template<class Type>
bool writeValues
(
const word& fieldName,
const scalarField& weightField,
const bool orient
);
//- Filter a surface field according to faceIds
template<class Type>
tmp<Field<Type>> filterField
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& field,
const bool applyOrientation
) const;
//- Filter a volume field according to faceIds
template<class Type>
tmp<Field<Type>> filterField
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const bool applyOrientation
) const;
//- Read from dictionary
virtual bool read(const dictionary&);
//- Calculate and write
virtual bool write();
};
//- Specialisation for scalar
template<>
scalar surfaceFieldValue::processValues
(
const Field<scalar>& values,
const vectorField& Sf,
const scalarField& weightField
) const;
//- Specialisation for vector
template<>
vector surfaceFieldValue::processValues
(
const Field<vector>& values,
const vectorField& Sf,
const scalarField& weightField
) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fieldValues
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "surfaceFieldValueI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "surfaceFieldValueTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "surfaceFieldValue.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes&
Foam::functionObjects::fieldValues::surfaceFieldValue::regionType() const
{
return regionType_;
}
inline const Foam::labelList&
Foam::functionObjects::fieldValues::surfaceFieldValue::faceId() const
{
return faceId_;
}
inline const Foam::labelList&
Foam::functionObjects::fieldValues::surfaceFieldValue::facePatch() const
{
return facePatchId_;
}
inline const Foam::labelList&
Foam::functionObjects::fieldValues::surfaceFieldValue::faceSign() const
{
return faceSign_;
}
inline Foam::fileName
Foam::functionObjects::fieldValues::surfaceFieldValue::outputDir() const
{
return baseFileDir()/name()/"surface"/obr_.time().timeName();
}
// ************************************************************************* //

View File

@ -0,0 +1,448 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "surfaceFieldValue.H"
#include "surfaceFields.H"
#include "volFields.H"
#include "sampledSurface.H"
#include "surfaceWriter.H"
#include "interpolationCellPoint.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::fieldValues::surfaceFieldValue::validField
(
const word& fieldName
) const
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (regionType_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
{
return true;
}
else if (obr_.foundObject<vf>(fieldName))
{
return true;
}
return false;
}
template<class Type>
<<<<<<< HEAD:src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C
Foam::tmp<Foam::Field<Type>> Foam::fieldValues::faceSource::setFieldValues
=======
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::fieldValues::surfaceFieldValue::getFieldValues
>>>>>>> foundation-github:src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C
(
const word& fieldName,
const bool mustGet,
const bool applyOrientation
) const
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (regionType_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
{
return filterField(obr_.lookupObject<sf>(fieldName), applyOrientation);
}
else if (obr_.foundObject<vf>(fieldName))
{
const vf& fld = obr_.lookupObject<vf>(fieldName);
if (surfacePtr_.valid())
{
if (surfacePtr_().interpolate())
{
const interpolationCellPoint<Type> interp(fld);
tmp<Field<Type>> tintFld(surfacePtr_().interpolate(interp));
const Field<Type>& intFld = tintFld();
// Average
const faceList& faces = surfacePtr_().faces();
tmp<Field<Type>> tavg
(
new Field<Type>(faces.size(), Zero)
);
Field<Type>& avg = tavg.ref();
forAll(faces, facei)
{
const face& f = faces[facei];
forAll(f, fp)
{
avg[facei] += intFld[f[fp]];
}
avg[facei] /= f.size();
}
return tavg;
}
else
{
return surfacePtr_().sample(fld);
}
}
else
{
return filterField(fld, applyOrientation);
}
}
if (mustGet)
{
FatalErrorInFunction
<< "Field " << fieldName << " not found in database"
<< abort(FatalError);
}
return tmp<Field<Type>>(new Field<Type>(0));
}
template<class Type>
Type Foam::functionObjects::fieldValues::surfaceFieldValue::
processSameTypeValues
(
const Field<Type>& values,
const vectorField& Sf,
const scalarField& weightField
) const
{
Type result = Zero;
switch (operation_)
{
case opSum:
{
result = gSum(values);
break;
}
case opSumMag:
{
result = gSum(cmptMag(values));
break;
}
case opSumDirection:
{
FatalErrorInFunction
<< "Operation " << operationTypeNames_[operation_]
<< " not available for values of type "
<< pTraits<Type>::typeName
<< exit(FatalError);
result = Zero;
break;
}
case opSumDirectionBalance:
{
FatalErrorInFunction
<< "Operation " << operationTypeNames_[operation_]
<< " not available for values of type "
<< pTraits<Type>::typeName
<< exit(FatalError);
result = Zero;
break;
}
case opAverage:
{
label n = returnReduce(values.size(), sumOp<label>());
result = gSum(values)/(scalar(n) + ROOTVSMALL);
break;
}
case opWeightedAverage:
{
label wSize = returnReduce(weightField.size(), sumOp<label>());
if (wSize > 0)
{
result =
gSum(weightField*values)/(gSum(weightField) + ROOTVSMALL);
}
else
{
label n = returnReduce(values.size(), sumOp<label>());
result = gSum(values)/(scalar(n) + ROOTVSMALL);
}
break;
}
case opAreaAverage:
{
const scalarField magSf(mag(Sf));
result = gSum(magSf*values)/gSum(magSf);
break;
}
case opWeightedAreaAverage:
{
const scalarField magSf(mag(Sf));
label wSize = returnReduce(weightField.size(), sumOp<label>());
if (wSize > 0)
{
result = gSum(weightField*magSf*values)/gSum(magSf*weightField);
}
else
{
result = gSum(magSf*values)/gSum(magSf);
}
break;
}
case opAreaIntegrate:
{
const scalarField magSf(mag(Sf));
result = gSum(magSf*values);
break;
}
case opMin:
{
result = gMin(values);
break;
}
case opMax:
{
result = gMax(values);
break;
}
case opCoV:
{
const scalarField magSf(mag(Sf));
const scalar gSumMagSf = gSum(magSf);
Type meanValue = gSum(values*magSf)/gSumMagSf;
const label nComp = pTraits<Type>::nComponents;
for (direction d=0; d<nComp; ++d)
{
scalarField vals(values.component(d));
scalar mean = component(meanValue, d);
scalar& res = setComponent(result, d);
res =
sqrt(gSum(magSf*sqr(vals - mean))/gSumMagSf)
/(mean + ROOTVSMALL);
}
break;
}
case opAreaNormalAverage:
{}
case opAreaNormalIntegrate:
{}
case opNone:
{}
}
return result;
}
template<class Type>
Type Foam::functionObjects::fieldValues::surfaceFieldValue::processValues
(
const Field<Type>& values,
const vectorField& Sf,
const scalarField& weightField
) const
{
return processSameTypeValues(values, Sf, weightField);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues
(
const word& fieldName,
const scalarField& weightField,
const bool orient
)
{
const bool ok = validField<Type>(fieldName);
if (ok)
{
Field<Type> values(setFieldValues<Type>(fieldName, true, orient));
vectorField Sf;
if (surfacePtr_.valid())
{
// Get oriented Sf
Sf = surfacePtr_().Sf();
}
else
{
// Get oriented Sf
Sf = filterField(mesh_.Sf(), true);
}
// Write raw values on surface if specified
if (surfaceWriterPtr_.valid())
{
Field<Type> allValues(values);
combineFields(allValues);
faceList faces;
pointField points;
if (surfacePtr_.valid())
{
combineSurfaceGeometry(faces, points);
}
else
{
combineMeshGeometry(faces, points);
}
if (Pstream::master())
{
surfaceWriterPtr_->write
(
outputDir(),
regionTypeNames_[regionType_] + ("_" + regionName_),
points,
faces,
fieldName,
allValues,
false
);
}
}
if (operation_ != opNone)
{
// Apply scale factor
values *= scaleFactor_;
Type result = processValues(values, Sf, weightField);
file()<< tab << result;
Log << " " << operationTypeNames_[operation_]
<< "(" << regionName_ << ") of " << fieldName
<< " = " << result << endl;
// Write state/results information
const word& opName = operationTypeNames_[operation_];
word resultName =
opName + '(' + sourceName_ + ',' + fieldName + ')';
this->setResult(resultName, result);
}
}
return ok;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::fieldValues::surfaceFieldValue::filterField
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const bool applyOrientation
) const
{
tmp<Field<Type>> tvalues(new Field<Type>(faceId_.size()));
Field<Type>& values = tvalues.ref();
forAll(values, i)
{
label facei = faceId_[i];
label patchi = facePatchId_[i];
if (patchi >= 0)
{
values[i] = field.boundaryField()[patchi][facei];
}
else
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):"
<< nl
<< " Unable to process internal faces for volume field "
<< field.name() << nl << abort(FatalError);
}
}
if (applyOrientation)
{
forAll(values, i)
{
values[i] *= faceSign_[i];
}
}
return tvalues;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::fieldValues::surfaceFieldValue::filterField
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& field,
const bool applyOrientation
) const
{
tmp<Field<Type>> tvalues(new Field<Type>(faceId_.size()));
Field<Type>& values = tvalues.ref();
forAll(values, i)
{
label facei = faceId_[i];
label patchi = facePatchId_[i];
if (patchi >= 0)
{
values[i] = field.boundaryField()[patchi][facei];
}
else
{
values[i] = field[facei];
}
}
if (applyOrientation)
{
forAll(values, i)
{
values[i] *= faceSign_[i];
}
}
return tvalues;
}
// ************************************************************************* //

View File

@ -0,0 +1,218 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "volFieldValue.H"
#include "fvMesh.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
defineTypeNameAndDebug(volFieldValue, 0);
addToRunTimeSelectionTable(fieldValue, volFieldValue, dictionary);
addToRunTimeSelectionTable(functionObject, volFieldValue, dictionary);
}
}
}
template<>
const char*
Foam::NamedEnum
<
Foam::functionObjects::fieldValues::volFieldValue::operationType,
11
>::names[] =
{
"none",
"sum",
"sumMag",
"average",
"weightedAverage",
"volAverage",
"weightedVolAverage",
"volIntegrate",
"min",
"max",
"CoV"
};
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::volFieldValue::operationType,
11
> Foam::functionObjects::fieldValues::volFieldValue::operationTypeNames_;
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldValues::volFieldValue::initialise
(
const dictionary& dict
)
{
if (dict.readIfPresent("weightField", weightFieldName_))
{
Info<< " weight field = " << weightFieldName_;
}
Info<< nl << endl;
}
void Foam::functionObjects::fieldValues::volFieldValue::writeFileHeader
(
const label i
)
{
volRegion::writeFileHeader(*this, file());
writeCommented(file(), "Time");
forAll(fields_, fieldi)
{
file()
<< tab << operationTypeNames_[operation_]
<< "(" << fields_[fieldi] << ")";
}
file() << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::volFieldValue::volFieldValue
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldValue(name, runTime, dict, typeName),
volRegion(fieldValue::mesh_, dict),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("none")
{
read(dict);
}
Foam::functionObjects::fieldValues::volFieldValue::volFieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
)
:
fieldValue(name, obr, dict, typeName),
volRegion(fieldValue::mesh_, dict),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("none")
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::volFieldValue::~volFieldValue()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldValues::volFieldValue::read
(
const dictionary& dict
)
{
fieldValue::read(dict);
// No additional info to read
initialise(dict);
return true;
}
bool Foam::functionObjects::fieldValues::volFieldValue::write()
{
fieldValue::write();
if (Pstream::master())
{
writeTime(file());
}
// Construct weight field. Note: zero size means weight = 1
scalarField weightField;
if (weightFieldName_ != "none")
{
weightField =
getFieldValues<scalar>
(
weightFieldName_,
true
);
}
forAll(fields_, i)
{
const word& fieldName = fields_[i];
bool ok = false;
ok = ok || writeValues<scalar>(fieldName, weightField);
ok = ok || writeValues<vector>(fieldName, weightField);
ok = ok || writeValues<sphericalTensor>(fieldName, weightField);
ok = ok || writeValues<symmTensor>(fieldName, weightField);
ok = ok || writeValues<tensor>(fieldName, weightField);
if (!ok)
{
WarningInFunction
<< "Requested field " << fieldName
<< " not found in database and not ok"
<< endl;
}
}
if (Pstream::master())
{
file()<< endl;
}
Log << endl;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,258 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::fieldValues::volFieldValue
Group
grpFieldFunctionObjects
Description
Provides a 'volRegion' specialization of the fieldValue function object.
Given a list of user-specified fields and a 'volRegion', a number of
operations can be performed, such as sums, averages and integrations.
Example of function object specification:
\verbatim
volFieldValue1
{
type volFieldValue;
libs ("libfieldFunctionObjects.so");
log true;
writeControl writeTime;
writeFields true;
regionType cellZone;
name c0;
operation volAverage;
weightField alpha1;
fields
(
p
U
);
}
\endverbatim
Usage
\table
Property | Description | Required | Default value
type | Type name: volFieldValue | yes |
log | Write data to standard output | no | no
writeFields | Write the region field values | yes |
regionType | volRegion type: see below | yes |
name | Name of volRegion if required | no |
operation | Operation to perform | yes |
weightField | Name of field to apply weighting | no |
fields | List of fields to operate on | yes |
\endtable
Where \c regionType is defined by
\plaintable
cellZone | requires a 'name' entry to specify the cellZone
all | all cells
\endplaintable
The \c operation is one of:
\plaintable
none | No operation
sum | Sum
sumMag | Sum of component magnitudes
average | Ensemble average
weightedAverage | Weighted average
volAverage | Volume weighted average
weightedVolAverage | Weighted volume average
volIntegrate | Volume integral
min | Minimum
max | Maximum
CoV | Coefficient of variation: standard deviation/mean
\endplaintable
See also
Foam::functionObjects::fieldValues::fieldValue
Foam::functionObjects::volRegion
Foam::functionObject
SourceFiles
volFieldValue.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_volFieldValue_H
#define functionObjects_volFieldValue_H
#include "fieldValue.H"
#include "volRegion.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
/*---------------------------------------------------------------------------*\
Class volFieldValue Declaration
\*---------------------------------------------------------------------------*/
class volFieldValue
:
public fieldValue,
public volRegion
{
public:
// Public data types
//- Operation type enumeration
enum operationType
{
opNone,
opSum,
opSumMag,
opAverage,
opWeightedAverage,
opVolAverage,
opWeightedVolAverage,
opVolIntegrate,
opMin,
opMax,
opCoV
};
//- Operation type names
static const NamedEnum<operationType, 11> operationTypeNames_;
protected:
// Protected data
//- Operation to apply to values
operationType operation_;
//- Weight field name - only used for opWeightedAverage mode
word weightFieldName_;
// Protected Member Functions
//- Initialise, e.g. cell addressing
void initialise(const dictionary& dict);
//- Return true if the field name is valid
template<class Type>
bool validField(const word& fieldName) const;
//- Insert field values into values list
template<class Type>
tmp<Field<Type>> setFieldValues
(
const word& fieldName,
const bool mustGet = false
) const;
//- Apply the 'operation' to the values
template<class Type>
Type processValues
(
const Field<Type>& values,
const scalarField& V,
const scalarField& weightField
) const;
//- Output file header information
virtual void writeFileHeader(const label i);
public:
//- Run-time type information
TypeName("volFieldValue");
// Constructors
//- Construct from name, Time and dictionary
volFieldValue
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Construct from name, objectRegistry and dictionary
volFieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
);
//- Destructor
virtual ~volFieldValue();
// Public Member Functions
//- Templated helper function to output field values
template<class Type>
bool writeValues(const word& fieldName, const scalarField& weightField);
//- Filter a field according to cellIds
template<class Type>
tmp<Field<Type>> filterField(const Field<Type>& field) const;
//- Read from dictionary
virtual bool read(const dictionary&);
//- Calculate and write
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fieldValues
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "volFieldValueTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,247 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "volFieldValue.H"
#include "volFields.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::fieldValues::volFieldValue::validField
(
const word& fieldName
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (obr_.foundObject<vf>(fieldName))
{
return true;
}
return false;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::fieldValues::volFieldValue::setFieldValues
(
const word& fieldName,
const bool mustGet
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (obr_.foundObject<vf>(fieldName))
{
return filterField(obr_.lookupObject<vf>(fieldName));
}
if (mustGet)
{
FatalErrorInFunction
<< "Field " << fieldName << " not found in database"
<< abort(FatalError);
}
return tmp<Field<Type>>(new Field<Type>(0.0));
}
template<class Type>
Type Foam::functionObjects::fieldValues::volFieldValue::processValues
(
const Field<Type>& values,
const scalarField& V,
const scalarField& weightField
) const
{
Type result = Zero;
switch (operation_)
{
case opSum:
{
result = gSum(values);
break;
}
case opSumMag:
{
result = gSum(cmptMag(values));
break;
}
case opAverage:
{
label n = returnReduce(values.size(), sumOp<label>());
result = gSum(values)/(scalar(n) + ROOTVSMALL);
break;
}
case opWeightedAverage:
{
label wSize = returnReduce(weightField.size(), sumOp<label>());
if (wSize > 0)
{
result =
gSum(weightField*values)/(gSum(weightField) + ROOTVSMALL);
}
else
{
label n = returnReduce(values.size(), sumOp<label>());
result = gSum(values)/(scalar(n) + ROOTVSMALL);
}
break;
}
case opVolAverage:
{
result = gSum(values*V)/(gSum(V) + ROOTVSMALL);
break;
}
case opWeightedVolAverage:
{
result = gSum(weightField*V*values)/gSum(weightField*V);
break;
}
case opVolIntegrate:
{
result = gSum(V*values);
break;
}
case opMin:
{
result = gMin(values);
break;
}
case opMax:
{
result = gMax(values);
break;
}
case opCoV:
{
const scalar sumV = gSum(V);
Type meanValue = gSum(V*values)/sumV;
const label nComp = pTraits<Type>::nComponents;
for (direction d=0; d<nComp; ++d)
{
scalarField vals(values.component(d));
scalar mean = component(meanValue, d);
scalar& res = setComponent(result, d);
res = sqrt(gSum(V*sqr(vals - mean))/sumV)/(mean + ROOTVSMALL);
}
break;
}
case opNone:
{}
}
return result;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::fieldValues::volFieldValue::writeValues
(
const word& fieldName
const scalarField& weightField
)
{
const bool ok = validField<Type>(fieldName);
if (ok)
{
Field<Type> values(setFieldValues<Type>(fieldName));
scalarField V(filterField(fieldValue::mesh_.V()));
if (writeFields_)
{
Field<Type> allValues(values);
combineFields(allValues);
if (Pstream::master())
{
IOField<Type>
(
IOobject
(
fieldName + '_' + regionTypeNames_[regionType_]
+ '-' + volRegion::regionName_,
obr_.time().timeName(),
obr_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
scaleFactor_*weightField*allValues
).write();
}
}
// Apply scale factor
values *= scaleFactor_;
Type result = processValues(values, V, weightField);
file()<< tab << result;
Log << " " << operationTypeNames_[operation_]
<< "(" << volRegion::regionName_ << ") of " << fieldName
<< " = " << result << endl;
// Write state/results information
const word& opName = operationTypeNames_[operation_];
word resultName = opName + '(' + sourceName_ + ',' + fieldName + ')';
this->setResult(resultName, result);
}
return ok;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::fieldValues::volFieldValue::filterField
(
const Field<Type>& field
) const
{
if (isNull(cellIDs()))
{
return field;
}
else
{
return tmp<Field<Type>>(new Field<Type>(field, cellIDs()));
}
}
// ************************************************************************* //