mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
postProcessing: Replaced 'foamCalc' and the 'postCalc' utilities
with the more general and flexible 'postProcess' utility and '-postProcess' solver option
Rationale
---------
Both the 'postProcess' utility and '-postProcess' solver option use the
same extensive set of functionObjects available for data-processing
during the run avoiding the substantial code duplication necessary for
the 'foamCalc' and 'postCalc' utilities and simplifying maintenance.
Additionally consistency is guaranteed between solver data processing
and post-processing.
The functionObjects have been substantially re-written and generalized
to simplify development and encourage contribution.
Configuration
-------------
An extensive set of simple functionObject configuration files are
provided in
OpenFOAM-dev/etc/caseDicts/postProcessing
and more will be added in the future. These can either be copied into
'<case>/system' directory and included into the 'controlDict.functions'
sub-dictionary or included directly from 'etc/caseDicts/postProcessing'
using the '#includeEtc' directive or the new and more convenient
'#includeFunc' directive which searches the
'<etc>/caseDicts/postProcessing' directories for the selected
functionObject, e.g.
functions
{
#includeFunc Q
#includeFunc Lambda2
}
'#includeFunc' first searches the '<case>/system' directory in case
there is a local configuration.
Description of #includeFunc
---------------------------
Specify a functionObject dictionary file to include, expects the
functionObject name to follow (without quotes).
Search for functionObject dictionary file in
user/group/shipped directories.
The search scheme allows for version-specific and
version-independent files using the following hierarchy:
- \b user settings:
- ~/.OpenFOAM/\<VERSION\>/caseDicts/postProcessing
- ~/.OpenFOAM/caseDicts/postProcessing
- \b group (site) settings (when $WM_PROJECT_SITE is set):
- $WM_PROJECT_SITE/\<VERSION\>/caseDicts/postProcessing
- $WM_PROJECT_SITE/caseDicts/postProcessing
- \b group (site) settings (when $WM_PROJECT_SITE is not set):
- $WM_PROJECT_INST_DIR/site/\<VERSION\>/caseDicts/postProcessing
- $WM_PROJECT_INST_DIR/site/caseDicts/postProcessing
- \b other (shipped) settings:
- $WM_PROJECT_DIR/etc/caseDicts/postProcessing
An example of the \c \#includeFunc directive:
\verbatim
#includeFunc <funcName>
\endverbatim
postProcess
-----------
The 'postProcess' utility and '-postProcess' solver option provide the
same set of controls to execute functionObjects after the run either by
reading a specified set of fields to process in the case of
'postProcess' or by reading all fields and models required to start the
run in the case of '-postProcess' for each selected time:
postProcess -help
Usage: postProcess [OPTIONS]
options:
-case <dir> specify alternate case directory, default is the cwd
-constant include the 'constant/' dir in the times list
-dict <file> read control dictionary from specified location
-field <name> specify the name of the field to be processed, e.g. U
-fields <list> specify a list of fields to be processed, e.g. '(U T p)' -
regular expressions not currently supported
-func <name> specify the name of the functionObject to execute, e.g. Q
-funcs <list> specify the names of the functionObjects to execute, e.g.
'(Q div(U))'
-latestTime select the latest time
-newTimes select the new times
-noFunctionObjects
do not execute functionObjects
-noZero exclude the '0/' dir from the times list, has precedence
over the -withZero option
-parallel run in parallel
-region <name> specify alternative mesh region
-roots <(dir1 .. dirN)>
slave root directories for distributed running
-time <ranges> comma-separated time ranges - eg, ':10,20,40:70,1000:'
-srcDoc display source code in browser
-doc display application documentation in browser
-help print the usage
pimpleFoam -postProcess -help
Usage: pimpleFoam [OPTIONS]
options:
-case <dir> specify alternate case directory, default is the cwd
-constant include the 'constant/' dir in the times list
-dict <file> read control dictionary from specified location
-field <name> specify the name of the field to be processed, e.g. U
-fields <list> specify a list of fields to be processed, e.g. '(U T p)' -
regular expressions not currently supported
-func <name> specify the name of the functionObject to execute, e.g. Q
-funcs <list> specify the names of the functionObjects to execute, e.g.
'(Q div(U))'
-latestTime select the latest time
-newTimes select the new times
-noFunctionObjects
do not execute functionObjects
-noZero exclude the '0/' dir from the times list, has precedence
over the -withZero option
-parallel run in parallel
-postProcess Execute functionObjects only
-region <name> specify alternative mesh region
-roots <(dir1 .. dirN)>
slave root directories for distributed running
-time <ranges> comma-separated time ranges - eg, ':10,20,40:70,1000:'
-srcDoc display source code in browser
-doc display application documentation in browser
-help print the usage
The functionObjects to execute may be specified on the command-line
using the '-func' option for a single functionObject or '-funcs' for a
list, e.g.
postProcess -func Q
postProcess -funcs '(div(U) div(phi))'
In the case of 'Q' the default field to process is 'U' which is
specified in and read from the configuration file but this may be
overridden thus:
postProcess -func 'Q(Ua)'
as is done in the example above to calculate the two forms of the divergence of
the velocity field. Additional fields which the functionObjects may depend on
can be specified using the '-field' or '-fields' options.
The 'postProcess' utility can only be used to execute functionObjects which
process fields present in the time directories. However, functionObjects which
depend on fields obtained from models, e.g. properties derived from turbulence
models can be executed using the '-postProcess' of the appropriate solver, e.g.
pisoFoam -postProcess -func PecletNo
or
sonicFoam -postProcess -func MachNo
In this case all required fields will have already been read so the '-field' or
'-fields' options are not be needed.
Henry G. Weller
CFD Direct Ltd.
This commit is contained in:
331
src/functionObjects/field/fieldValues/cellSource/cellSource.C
Normal file
331
src/functionObjects/field/fieldValues/cellSource/cellSource.C
Normal file
@ -0,0 +1,331 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "cellSource.H"
|
||||
#include "fvMesh.H"
|
||||
#include "volFields.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace fieldValues
|
||||
{
|
||||
defineTypeNameAndDebug(cellSource, 0);
|
||||
addToRunTimeSelectionTable(fieldValue, cellSource, dictionary);
|
||||
addToRunTimeSelectionTable(functionObject, cellSource, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
const char*
|
||||
Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldValues::cellSource::sourceType,
|
||||
2
|
||||
>::names[] = {"cellZone", "all"};
|
||||
|
||||
template<>
|
||||
const char*
|
||||
Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldValues::cellSource::operationType,
|
||||
11
|
||||
>::names[] =
|
||||
{
|
||||
"none",
|
||||
"sum",
|
||||
"sumMag",
|
||||
"average",
|
||||
"weightedAverage",
|
||||
"volAverage",
|
||||
"weightedVolAverage",
|
||||
"volIntegrate",
|
||||
"min",
|
||||
"max",
|
||||
"CoV"
|
||||
};
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldValues::cellSource::sourceType,
|
||||
2
|
||||
> Foam::functionObjects::fieldValues::cellSource::sourceTypeNames_;
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldValues::cellSource::operationType,
|
||||
11
|
||||
> Foam::functionObjects::fieldValues::cellSource::operationTypeNames_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::fieldValues::cellSource::setCellZoneCells()
|
||||
{
|
||||
switch (source_)
|
||||
{
|
||||
case stCellZone:
|
||||
{
|
||||
dict().lookup("sourceName") >> sourceName_;
|
||||
|
||||
label zoneId = mesh().cellZones().findZoneID(sourceName_);
|
||||
|
||||
if (zoneId < 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown cell zone name: " << sourceName_
|
||||
<< ". Valid cell zones are: " << mesh().cellZones().names()
|
||||
<< nl << exit(FatalError);
|
||||
}
|
||||
|
||||
cellId_ = mesh().cellZones()[zoneId];
|
||||
nCells_ = returnReduce(cellId_.size(), sumOp<label>());
|
||||
break;
|
||||
}
|
||||
|
||||
case stAll:
|
||||
{
|
||||
cellId_ = identity(mesh().nCells());
|
||||
nCells_ = returnReduce(cellId_.size(), sumOp<label>());
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown source type. Valid source types are:"
|
||||
<< sourceTypeNames_ << nl << exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Pout<< "Selected source size = " << cellId_.size() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::functionObjects::fieldValues::cellSource::volume() const
|
||||
{
|
||||
return gSum(filterField(mesh().V()));
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::fieldValues::cellSource::initialise
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
setCellZoneCells();
|
||||
|
||||
if (nCells_ == 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< type() << " " << name() << ": "
|
||||
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
|
||||
<< " Source has no cells" << exit(FatalError);
|
||||
}
|
||||
|
||||
volume_ = volume();
|
||||
|
||||
Info<< type() << " " << name() << ":"
|
||||
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
|
||||
<< " total cells = " << nCells_ << nl
|
||||
<< " total volume = " << volume_
|
||||
<< nl << endl;
|
||||
|
||||
if (dict.readIfPresent("weightField", weightFieldName_))
|
||||
{
|
||||
Info<< " weight field = " << weightFieldName_;
|
||||
}
|
||||
|
||||
Info<< nl << endl;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fieldValues::cellSource::writeFileHeader
|
||||
(
|
||||
const label i
|
||||
)
|
||||
{
|
||||
writeCommented(file(), "Source : ");
|
||||
file() << sourceTypeNames_[source_] << " " << sourceName_ << endl;
|
||||
writeCommented(file(), "Cells : ");
|
||||
file() << nCells_ << endl;
|
||||
writeCommented(file(), "Volume : ");
|
||||
file() << volume_ << endl;
|
||||
|
||||
writeCommented(file(), "Time");
|
||||
if (writeVolume_)
|
||||
{
|
||||
file() << tab << "Volume";
|
||||
}
|
||||
|
||||
forAll(fields_, i)
|
||||
{
|
||||
file()
|
||||
<< tab << operationTypeNames_[operation_]
|
||||
<< "(" << fields_[i] << ")";
|
||||
}
|
||||
|
||||
file() << endl;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldValues::cellSource::cellSource
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fieldValue(name, runTime, dict, typeName),
|
||||
source_(sourceTypeNames_.read(dict.lookup("source"))),
|
||||
operation_(operationTypeNames_.read(dict.lookup("operation"))),
|
||||
nCells_(0),
|
||||
cellId_(),
|
||||
weightFieldName_("none"),
|
||||
writeVolume_(dict.lookupOrDefault("writeVolume", false))
|
||||
{
|
||||
if (!isA<fvMesh>(obr_))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "objectRegistry is not an fvMesh" << exit(FatalError);
|
||||
}
|
||||
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
Foam::functionObjects::fieldValues::cellSource::cellSource
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fieldValue(name, obr, dict, typeName),
|
||||
source_(sourceTypeNames_.read(dict.lookup("source"))),
|
||||
operation_(operationTypeNames_.read(dict.lookup("operation"))),
|
||||
nCells_(0),
|
||||
cellId_(),
|
||||
weightFieldName_("none"),
|
||||
writeVolume_(dict.lookupOrDefault("writeVolume", false))
|
||||
{
|
||||
if (!isA<fvMesh>(obr_))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "objectRegistry is not an fvMesh" << exit(FatalError);
|
||||
}
|
||||
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldValues::cellSource::~cellSource()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::fieldValues::cellSource::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
fieldValue::read(dict);
|
||||
|
||||
// No additional info to read
|
||||
initialise(dict);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldValues::cellSource::write
|
||||
(
|
||||
const bool postProcess
|
||||
)
|
||||
{
|
||||
fieldValue::write();
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
writeTime(file());
|
||||
}
|
||||
|
||||
if (writeVolume_)
|
||||
{
|
||||
volume_ = volume();
|
||||
if (Pstream::master())
|
||||
{
|
||||
file() << tab << volume_;
|
||||
}
|
||||
Log << " total volume = " << volume_ << endl;
|
||||
}
|
||||
|
||||
forAll(fields_, i)
|
||||
{
|
||||
const word& fieldName = fields_[i];
|
||||
bool processed = false;
|
||||
|
||||
processed = processed || writeValues<scalar>(fieldName);
|
||||
processed = processed || writeValues<vector>(fieldName);
|
||||
processed = processed || writeValues<sphericalTensor>(fieldName);
|
||||
processed = processed || writeValues<symmTensor>(fieldName);
|
||||
processed = processed || writeValues<tensor>(fieldName);
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Requested field " << fieldName
|
||||
<< " not found in database and not processed"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
file()<< endl;
|
||||
}
|
||||
|
||||
Log << endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
306
src/functionObjects/field/fieldValues/cellSource/cellSource.H
Normal file
306
src/functionObjects/field/fieldValues/cellSource/cellSource.H
Normal file
@ -0,0 +1,306 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::fieldValues::cellSource
|
||||
|
||||
Group
|
||||
grpFieldFunctionObjects
|
||||
|
||||
Description
|
||||
This function object provides a 'cell source' variant of the fieldValues
|
||||
function object. Given a list of user-specified fields and a selection
|
||||
of mesh cells, a number of operations can be performed, such as sums,
|
||||
averages and integrations.
|
||||
|
||||
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
cellSource1
|
||||
{
|
||||
type cellSource;
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
...
|
||||
log true;
|
||||
valueOutput true;
|
||||
source cellZone;
|
||||
sourceName c0;
|
||||
operation volAverage;
|
||||
weightField alpha1;
|
||||
fields
|
||||
(
|
||||
p
|
||||
U
|
||||
);
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
\heading Function object usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | Type name: cellSource | yes |
|
||||
log | Write data to standard output | no | no
|
||||
valueOutput | Write the raw output values | yes |
|
||||
writeVolume | Write the volume of the cellSource | no |
|
||||
source | cell source: see below | yes |
|
||||
sourceName | name of cell source 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
|
||||
|
||||
\linebreak
|
||||
Where \c source is defined by
|
||||
\plaintable
|
||||
cellZone | requires a 'sourceName' entry to specify the cellZone
|
||||
all | all cells
|
||||
\endplaintable
|
||||
|
||||
\linebreak
|
||||
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
|
||||
|
||||
SeeAlso
|
||||
Foam::fieldValues
|
||||
Foam::functionObject
|
||||
|
||||
SourceFiles
|
||||
cellSource.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_cellSource_H
|
||||
#define functionObjects_cellSource_H
|
||||
|
||||
#include "fieldValue.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace fieldValues
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class cellSource Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class cellSource
|
||||
:
|
||||
public fieldValue
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// Public data types
|
||||
|
||||
//- Source type enumeration
|
||||
enum sourceType
|
||||
{
|
||||
stCellZone,
|
||||
stAll
|
||||
};
|
||||
|
||||
//- Source type names
|
||||
static const NamedEnum<sourceType, 2> sourceTypeNames_;
|
||||
|
||||
|
||||
//- 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_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Set cells to evaluate based on a cell zone
|
||||
void setCellZoneCells();
|
||||
|
||||
//- Set cells to evaluate based on a patch
|
||||
void setPatchCells();
|
||||
|
||||
//- Calculate and return volume of the cellSource: sum(V)
|
||||
scalar volume() const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Source type
|
||||
sourceType source_;
|
||||
|
||||
//- Operation to apply to values
|
||||
operationType operation_;
|
||||
|
||||
//- Global number of cells
|
||||
label nCells_;
|
||||
|
||||
//- Local list of cell IDs
|
||||
labelList cellId_;
|
||||
|
||||
//- Weight field name - only used for opWeightedAverage mode
|
||||
word weightFieldName_;
|
||||
|
||||
//- Volume of the cellSource
|
||||
scalar volume_;
|
||||
|
||||
//- Optionally write the volume of the cellSource
|
||||
bool writeVolume_;
|
||||
|
||||
|
||||
// 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("cellSource");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from name, Time and dictionary
|
||||
cellSource
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
//- Construct from name, objectRegistry and dictionary
|
||||
cellSource
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~cellSource();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Return the source type
|
||||
inline const sourceType& source() const;
|
||||
|
||||
//- Return the local list of cell IDs
|
||||
inline const labelList& cellId() const;
|
||||
|
||||
//- Templated helper function to output field values
|
||||
template<class Type>
|
||||
bool writeValues(const word& fieldName);
|
||||
|
||||
//- 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(const bool postProcess = false);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fieldValues
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "cellSourceI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "cellSourceTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,44 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "cellSource.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline const Foam::functionObjects::fieldValues::cellSource::sourceType&
|
||||
Foam::functionObjects::fieldValues::cellSource::source() const
|
||||
{
|
||||
return source_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::labelList&
|
||||
Foam::functionObjects::fieldValues::cellSource::cellId() const
|
||||
{
|
||||
return cellId_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,229 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "cellSource.H"
|
||||
#include "volFields.H"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
bool Foam::functionObjects::fieldValues::cellSource::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::cellSource::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::cellSource::processValues
|
||||
(
|
||||
const Field<Type>& values,
|
||||
const scalarField& V,
|
||||
const scalarField& weightField
|
||||
) const
|
||||
{
|
||||
Type result = Zero;
|
||||
switch (operation_)
|
||||
{
|
||||
case opSum:
|
||||
{
|
||||
result = sum(values);
|
||||
break;
|
||||
}
|
||||
case opSumMag:
|
||||
{
|
||||
result = sum(cmptMag(values));
|
||||
break;
|
||||
}
|
||||
case opAverage:
|
||||
{
|
||||
result = sum(values)/values.size();
|
||||
break;
|
||||
}
|
||||
case opWeightedAverage:
|
||||
{
|
||||
result = sum(weightField*values)/sum(weightField);
|
||||
break;
|
||||
}
|
||||
case opVolAverage:
|
||||
{
|
||||
result = sum(V*values)/sum(V);
|
||||
break;
|
||||
}
|
||||
case opWeightedVolAverage:
|
||||
{
|
||||
result = sum(weightField*V*values)/sum(weightField*V);
|
||||
break;
|
||||
}
|
||||
case opVolIntegrate:
|
||||
{
|
||||
result = sum(V*values);
|
||||
break;
|
||||
}
|
||||
case opMin:
|
||||
{
|
||||
result = min(values);
|
||||
break;
|
||||
}
|
||||
case opMax:
|
||||
{
|
||||
result = max(values);
|
||||
break;
|
||||
}
|
||||
case opCoV:
|
||||
{
|
||||
Type meanValue = sum(values*V)/sum(V);
|
||||
|
||||
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(sum(V*sqr(vals - mean))/sum(V))/mean;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case opNone:
|
||||
{}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
bool Foam::functionObjects::fieldValues::cellSource::writeValues
|
||||
(
|
||||
const word& fieldName
|
||||
)
|
||||
{
|
||||
const bool ok = validField<Type>(fieldName);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
Field<Type> values(setFieldValues<Type>(fieldName));
|
||||
scalarField V(filterField(mesh().V()));
|
||||
scalarField weightField(values.size(), 1.0);
|
||||
|
||||
if (weightFieldName_ != "none")
|
||||
{
|
||||
weightField = setFieldValues<scalar>(weightFieldName_, true);
|
||||
}
|
||||
|
||||
// Combine onto master
|
||||
combineFields(values);
|
||||
combineFields(V);
|
||||
combineFields(weightField);
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
Type result = processValues(values, V, weightField);
|
||||
|
||||
// Add to result dictionary, over-writing any previous entry
|
||||
resultDict_.add(fieldName, result, true);
|
||||
|
||||
if (valueOutput_)
|
||||
{
|
||||
IOField<Type>
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
fieldName + "_" + sourceTypeNames_[source_] + "-"
|
||||
+ sourceName_,
|
||||
obr_.time().timeName(),
|
||||
obr_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
weightField*values
|
||||
).write();
|
||||
}
|
||||
|
||||
|
||||
file()<< tab << result;
|
||||
|
||||
Log << " " << operationTypeNames_[operation_]
|
||||
<< "(" << sourceName_ << ") of " << fieldName
|
||||
<< " = " << result << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::functionObjects::fieldValues::cellSource::filterField
|
||||
(
|
||||
const Field<Type>& field
|
||||
) const
|
||||
{
|
||||
return tmp<Field<Type>>(new Field<Type>(field, cellId_));
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
129
src/functionObjects/field/fieldValues/controlDict
Normal file
129
src/functionObjects/field/fieldValues/controlDict
Normal file
@ -0,0 +1,129 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: dev |
|
||||
| \\ / A nd | Web: www.OpenFOAM.org |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format ascii;
|
||||
class dictionary;
|
||||
object controlDict;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
application icoFoam;
|
||||
|
||||
startFrom startTime;
|
||||
|
||||
startTime 0;
|
||||
|
||||
stopAt endTime;
|
||||
|
||||
endTime 0.5;
|
||||
|
||||
deltaT 0.005;
|
||||
|
||||
writeControl timeStep;
|
||||
|
||||
writeInterval 20;
|
||||
|
||||
purgeWrite 0;
|
||||
|
||||
writeFormat ascii;
|
||||
|
||||
writePrecision 6;
|
||||
|
||||
writeCompression off;
|
||||
|
||||
timeFormat general;
|
||||
|
||||
timePrecision 6;
|
||||
|
||||
runTimeModifiable true;
|
||||
|
||||
functions
|
||||
{
|
||||
faceObj1
|
||||
{
|
||||
type faceSource;
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
|
||||
enabled true;
|
||||
writeControl writeTime;
|
||||
|
||||
// Output to log&file (true) or to file only
|
||||
log true;
|
||||
|
||||
// Output field values as well
|
||||
valueOutput true;
|
||||
|
||||
// Type of source: patch/faceZone/sampledSurface
|
||||
source patch;
|
||||
|
||||
// if patch or faceZone: name of patch or faceZone
|
||||
sourceName movingWall;
|
||||
|
||||
//// if sampledSurface: dictionary with a sampledSurface
|
||||
//// Note: will not sample surface fields.
|
||||
//sampledSurfaceDict
|
||||
//{
|
||||
// // Sampling on triSurface
|
||||
// type sampledTriSurfaceMesh;
|
||||
// surface integrationPlane.stl;
|
||||
// source cells; // sample cells or boundaryFaces
|
||||
// interpolate true;
|
||||
//}
|
||||
|
||||
// Operation: areaAverage/sum/weightedAverage ...
|
||||
operation areaAverage;
|
||||
|
||||
fields
|
||||
(
|
||||
p
|
||||
phi // surface fields not supported for sampledSurface
|
||||
U
|
||||
);
|
||||
}
|
||||
|
||||
faceObj2
|
||||
{
|
||||
type faceSource;
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
enabled true;
|
||||
writeControl writeTime;
|
||||
log true;
|
||||
valueOutput true;
|
||||
source faceZone;
|
||||
sourceName f0;
|
||||
operation sum;
|
||||
|
||||
fields
|
||||
(
|
||||
phi
|
||||
);
|
||||
}
|
||||
|
||||
cellObj1
|
||||
{
|
||||
type cellSource;
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
enabled true;
|
||||
writeControl writeTime;
|
||||
log true;
|
||||
valueOutput true;
|
||||
source cellZone;
|
||||
sourceName c0;
|
||||
operation volAverage;
|
||||
|
||||
fields
|
||||
(
|
||||
p
|
||||
U
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
800
src/functionObjects/field/fieldValues/faceSource/faceSource.C
Normal file
800
src/functionObjects/field/fieldValues/faceSource/faceSource.C
Normal file
@ -0,0 +1,800 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "faceSource.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(faceSource, 0);
|
||||
addToRunTimeSelectionTable(fieldValue, faceSource, dictionary);
|
||||
addToRunTimeSelectionTable(functionObject, faceSource, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldValues::faceSource::sourceType,
|
||||
3
|
||||
>::names[] =
|
||||
{
|
||||
"faceZone",
|
||||
"patch",
|
||||
"sampledSurface"
|
||||
};
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldValues::faceSource::operationType,
|
||||
15
|
||||
>::names[] =
|
||||
{
|
||||
"none",
|
||||
"sum",
|
||||
"sumMag",
|
||||
"sumDirection",
|
||||
"sumDirectionBalance",
|
||||
"average",
|
||||
"weightedAverage",
|
||||
"areaAverage",
|
||||
"weightedAreaAverage",
|
||||
"areaIntegrate",
|
||||
"min",
|
||||
"max",
|
||||
"CoV",
|
||||
"areaNormalAverage",
|
||||
"areaNormalIntegrate"
|
||||
};
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldValues::faceSource::sourceType,
|
||||
3
|
||||
> Foam::functionObjects::fieldValues::faceSource::sourceTypeNames_;
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::fieldValues::faceSource::operationType,
|
||||
15
|
||||
> Foam::functionObjects::fieldValues::faceSource::operationTypeNames_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::fieldValues::faceSource::setFaceZoneFaces()
|
||||
{
|
||||
label zoneId = mesh().faceZones().findZoneID(sourceName_);
|
||||
|
||||
if (zoneId < 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< type() << " " << name() << ": "
|
||||
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
|
||||
<< " Unknown face zone name: " << sourceName_
|
||||
<< ". 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::faceSource::setPatchFaces()
|
||||
{
|
||||
const label patchid = mesh().boundaryMesh().findPatchID(sourceName_);
|
||||
|
||||
if (patchid < 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< type() << " " << name() << ": "
|
||||
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
|
||||
<< " Unknown patch name: " << sourceName_
|
||||
<< ". 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::faceSource::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::faceSource::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::faceSource::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::faceSource::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::faceSource::initialise
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
dict.lookup("sourceName") >> sourceName_;
|
||||
|
||||
switch (source_)
|
||||
{
|
||||
case stFaceZone:
|
||||
{
|
||||
setFaceZoneFaces();
|
||||
break;
|
||||
}
|
||||
case stPatch:
|
||||
{
|
||||
setPatchFaces();
|
||||
break;
|
||||
}
|
||||
case stSampledSurface:
|
||||
{
|
||||
sampledSurfaceFaces(dict);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< type() << " " << name() << ": "
|
||||
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
|
||||
<< nl << " Unknown source type. Valid source types are:"
|
||||
<< sourceTypeNames_.sortedToc() << nl << exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
if (nFaces_ == 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< type() << " " << name() << ": "
|
||||
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
|
||||
<< " Source 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 (source_ == stSampledSurface)
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Cannot use weightField for a sampledSurface"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
if (dict.found("orientedWeightField"))
|
||||
{
|
||||
if (weightFieldName_ == "none")
|
||||
{
|
||||
dict.lookup("orientedWeightField") >> weightFieldName_;
|
||||
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);
|
||||
}
|
||||
|
||||
if (dict.readIfPresent("scaleFactor", scaleFactor_))
|
||||
{
|
||||
Info<< " scale factor = " << scaleFactor_ << nl;
|
||||
}
|
||||
|
||||
Info<< nl << endl;
|
||||
|
||||
if (valueOutput_)
|
||||
{
|
||||
const word surfaceFormat(dict.lookup("surfaceFormat"));
|
||||
|
||||
surfaceWriterPtr_.reset
|
||||
(
|
||||
surfaceWriter::New
|
||||
(
|
||||
surfaceFormat,
|
||||
dict.subOrEmptyDict("formatOptions").
|
||||
subOrEmptyDict(surfaceFormat)
|
||||
).ptr()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fieldValues::faceSource::writeFileHeader
|
||||
(
|
||||
const label i
|
||||
)
|
||||
{
|
||||
writeCommented(file(), "Source : ");
|
||||
file() << sourceTypeNames_[source_] << " " << sourceName_ << endl;
|
||||
writeCommented(file(), "Faces : ");
|
||||
file() << nFaces_ << endl;
|
||||
writeCommented(file(), "Area : ");
|
||||
file() << totalArea_ << endl;
|
||||
|
||||
writeCommented(file(), "Time");
|
||||
if (writeArea_)
|
||||
{
|
||||
file() << tab << "Area";
|
||||
}
|
||||
|
||||
forAll(fields_, i)
|
||||
{
|
||||
file()
|
||||
<< tab << operationTypeNames_[operation_]
|
||||
<< "(" << fields_[i] << ")";
|
||||
}
|
||||
|
||||
file() << endl;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
Foam::scalar Foam::functionObjects::fieldValues::faceSource::processValues
|
||||
(
|
||||
const Field<scalar>& values,
|
||||
const vectorField& Sf,
|
||||
const scalarField& weightField
|
||||
) const
|
||||
{
|
||||
switch (operation_)
|
||||
{
|
||||
case opSumDirection:
|
||||
{
|
||||
vector n(dict_.lookup("direction"));
|
||||
return sum(pos(values*(Sf & n))*mag(values));
|
||||
}
|
||||
case opSumDirectionBalance:
|
||||
{
|
||||
vector n(dict_.lookup("direction"));
|
||||
const scalarField nv(values*(Sf & n));
|
||||
|
||||
return sum(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::faceSource::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 sum(pos(nv)*n*(nv));
|
||||
}
|
||||
case opSumDirectionBalance:
|
||||
{
|
||||
vector n(dict_.lookup("direction"));
|
||||
n /= mag(n) + ROOTVSMALL;
|
||||
const scalarField nv(n & values);
|
||||
|
||||
return sum(pos(nv)*n*(nv));
|
||||
}
|
||||
case opAreaNormalAverage:
|
||||
{
|
||||
scalar result = sum(values & Sf)/sum(mag(Sf));
|
||||
return vector(result, 0.0, 0.0);
|
||||
}
|
||||
case opAreaNormalIntegrate:
|
||||
{
|
||||
scalar result = sum(values & Sf);
|
||||
return vector(result, 0.0, 0.0);
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Fall through to other operations
|
||||
return processSameTypeValues(values, Sf, weightField);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldValues::faceSource::faceSource
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fieldValue(name, runTime, dict, typeName),
|
||||
surfaceWriterPtr_(NULL),
|
||||
source_(sourceTypeNames_.read(dict.lookup("source"))),
|
||||
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_()
|
||||
{
|
||||
if (!isA<fvMesh>(obr_))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "objectRegistry is not an fvMesh" << exit(FatalError);
|
||||
}
|
||||
|
||||
read(dict);
|
||||
}
|
||||
|
||||
Foam::functionObjects::fieldValues::faceSource::faceSource
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fieldValue(name, obr, dict, typeName),
|
||||
surfaceWriterPtr_(NULL),
|
||||
source_(sourceTypeNames_.read(dict.lookup("source"))),
|
||||
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_()
|
||||
{
|
||||
if (!isA<fvMesh>(obr_))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "objectRegistry is not an fvMesh" << exit(FatalError);
|
||||
}
|
||||
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldValues::faceSource::~faceSource()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::fieldValues::faceSource::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
fieldValue::read(dict);
|
||||
initialise(dict);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldValues::faceSource::write
|
||||
(
|
||||
const bool postProcess
|
||||
)
|
||||
{
|
||||
fieldValue::write();
|
||||
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
surfacePtr_().update();
|
||||
}
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
writeTime(file());
|
||||
}
|
||||
|
||||
if (writeArea_)
|
||||
{
|
||||
totalArea_ = totalArea();
|
||||
if (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_
|
||||
);
|
||||
}
|
||||
|
||||
// Combine onto master
|
||||
combineFields(weightField);
|
||||
|
||||
// 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 (Pstream::master())
|
||||
{
|
||||
file()<< endl;
|
||||
}
|
||||
|
||||
Log << endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
449
src/functionObjects/field/fieldValues/faceSource/faceSource.H
Normal file
449
src/functionObjects/field/fieldValues/faceSource/faceSource.H
Normal file
@ -0,0 +1,449 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::fieldValues::faceSource
|
||||
|
||||
Group
|
||||
grpFieldFunctionObjects
|
||||
|
||||
Description
|
||||
This function object provides a 'face source' 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.
|
||||
|
||||
\linebreak
|
||||
For example, to calculate the volumetric or mass flux across a patch,
|
||||
apply the 'sum' operator to the flux field (typically \c phi)
|
||||
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
faceSource1
|
||||
{
|
||||
type faceSource;
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
...
|
||||
log yes;
|
||||
valueOutput true;
|
||||
surfaceFormat none;
|
||||
source faceZone;
|
||||
sourceName f0;
|
||||
operation sum;
|
||||
weightField alpha1;
|
||||
fields
|
||||
(
|
||||
p
|
||||
phi
|
||||
U
|
||||
);
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
\heading Function object usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | type name: faceSource | yes |
|
||||
log | write data to standard output | no | no
|
||||
valueOutput | write the output values | yes |
|
||||
writeArea | Write the area of the faceSource | no |
|
||||
surfaceFormat | output value format | no |
|
||||
source | face source: see below | yes |
|
||||
sourceName | name of face source 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
|
||||
|
||||
\linebreak
|
||||
Where \c source is defined by
|
||||
\plaintable
|
||||
faceZone | requires a 'sourceName' entry to specify the faceZone
|
||||
patch | requires a 'sourceName' entry to specify the patch
|
||||
sampledSurface | requires a 'sampledSurfaceDict' sub-dictionary
|
||||
\endplaintable
|
||||
|
||||
\linebreak
|
||||
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 sampledSurfaces:
|
||||
- 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
|
||||
|
||||
SeeAlso
|
||||
Foam::fieldValues
|
||||
Foam::functionObject
|
||||
|
||||
SourceFiles
|
||||
faceSource.C
|
||||
faceSourceTemplates.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_faceSource_H
|
||||
#define functionObjects_faceSource_H
|
||||
|
||||
#include "fieldValue.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class sampledSurface;
|
||||
class surfaceWriter;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace fieldValues
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class faceSource Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class faceSource
|
||||
:
|
||||
public fieldValue
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// Public data types
|
||||
|
||||
//- Source type enumeration
|
||||
enum sourceType
|
||||
{
|
||||
stFaceZone,
|
||||
stPatch,
|
||||
stSampledSurface
|
||||
};
|
||||
|
||||
//- Source type names
|
||||
static const NamedEnum<sourceType, 3> sourceTypeNames_;
|
||||
|
||||
|
||||
//- 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 faceSource: sum(magSf)
|
||||
scalar totalArea() const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Surface writer
|
||||
autoPtr<surfaceWriter> surfaceWriterPtr_;
|
||||
|
||||
//- Source type
|
||||
sourceType source_;
|
||||
|
||||
//- 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_;
|
||||
|
||||
//- Scale factor - optional
|
||||
scalar scaleFactor_;
|
||||
|
||||
//- Total area of the faceSource
|
||||
scalar totalArea_;
|
||||
|
||||
//- Optionally write the area of the faceSource
|
||||
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>> getFieldValues
|
||||
(
|
||||
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(const label i);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("faceSource");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from name, Time and dictionary
|
||||
faceSource
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
//- Construct from name, objectRegistry and dictionary
|
||||
faceSource
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~faceSource();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Return the source type
|
||||
inline const sourceType& source() 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;
|
||||
|
||||
//- 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(const bool postProcess = false);
|
||||
};
|
||||
|
||||
|
||||
//- Specialisation for scalar
|
||||
template<>
|
||||
scalar faceSource::processValues
|
||||
(
|
||||
const Field<scalar>& values,
|
||||
const vectorField& Sf,
|
||||
const scalarField& weightField
|
||||
) const;
|
||||
|
||||
|
||||
//- Specialisation for vector
|
||||
template<>
|
||||
vector faceSource::processValues
|
||||
(
|
||||
const Field<vector>& values,
|
||||
const vectorField& Sf,
|
||||
const scalarField& weightField
|
||||
) const;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fieldValues
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "faceSourceI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "faceSourceTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,58 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "faceSource.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline const Foam::functionObjects::fieldValues::faceSource::sourceType&
|
||||
Foam::functionObjects::fieldValues::faceSource::source() const
|
||||
{
|
||||
return source_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::labelList&
|
||||
Foam::functionObjects::fieldValues::faceSource::faceId() const
|
||||
{
|
||||
return faceId_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::labelList&
|
||||
Foam::functionObjects::fieldValues::faceSource::facePatch() const
|
||||
{
|
||||
return facePatchId_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::labelList&
|
||||
Foam::functionObjects::fieldValues::faceSource::faceSign() const
|
||||
{
|
||||
return faceSign_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,436 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "faceSource.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::faceSource::validField
|
||||
(
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> vf;
|
||||
|
||||
if (source_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (obr_.foundObject<vf>(fieldName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::functionObjects::fieldValues::faceSource::getFieldValues
|
||||
(
|
||||
const word& fieldName,
|
||||
const bool mustGet,
|
||||
const bool applyOrientation
|
||||
) const
|
||||
{
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> vf;
|
||||
|
||||
if (source_ != 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::faceSource::processSameTypeValues
|
||||
(
|
||||
const Field<Type>& values,
|
||||
const vectorField& Sf,
|
||||
const scalarField& weightField
|
||||
) const
|
||||
{
|
||||
Type result = Zero;
|
||||
switch (operation_)
|
||||
{
|
||||
case opSum:
|
||||
{
|
||||
result = sum(values);
|
||||
break;
|
||||
}
|
||||
case opSumMag:
|
||||
{
|
||||
result = sum(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:
|
||||
{
|
||||
result = sum(values)/values.size();
|
||||
break;
|
||||
}
|
||||
case opWeightedAverage:
|
||||
{
|
||||
if (weightField.size())
|
||||
{
|
||||
result = sum(weightField*values)/sum(weightField);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = sum(values)/values.size();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case opAreaAverage:
|
||||
{
|
||||
const scalarField magSf(mag(Sf));
|
||||
|
||||
result = sum(magSf*values)/sum(magSf);
|
||||
break;
|
||||
}
|
||||
case opWeightedAreaAverage:
|
||||
{
|
||||
const scalarField magSf(mag(Sf));
|
||||
|
||||
if (weightField.size())
|
||||
{
|
||||
result = sum(weightField*magSf*values)/sum(magSf*weightField);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = sum(magSf*values)/sum(magSf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case opAreaIntegrate:
|
||||
{
|
||||
const scalarField magSf(mag(Sf));
|
||||
|
||||
result = sum(magSf*values);
|
||||
break;
|
||||
}
|
||||
case opMin:
|
||||
{
|
||||
result = min(values);
|
||||
break;
|
||||
}
|
||||
case opMax:
|
||||
{
|
||||
result = max(values);
|
||||
break;
|
||||
}
|
||||
case opCoV:
|
||||
{
|
||||
const scalarField magSf(mag(Sf));
|
||||
|
||||
Type meanValue = sum(values*magSf)/sum(magSf);
|
||||
|
||||
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(sum(magSf*sqr(vals - mean))/sum(magSf))/mean;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case opAreaNormalAverage:
|
||||
{}
|
||||
case opAreaNormalIntegrate:
|
||||
{}
|
||||
case opNone:
|
||||
{}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::functionObjects::fieldValues::faceSource::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::faceSource::writeValues
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalarField& weightField,
|
||||
const bool orient
|
||||
)
|
||||
{
|
||||
const bool ok = validField<Type>(fieldName);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
Field<Type> values(getFieldValues<Type>(fieldName, true, orient));
|
||||
|
||||
vectorField Sf;
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
// Get oriented Sf
|
||||
Sf = surfacePtr_().Sf();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get oriented Sf
|
||||
Sf = filterField(mesh().Sf(), true);
|
||||
}
|
||||
|
||||
// Combine onto master
|
||||
combineFields(values);
|
||||
combineFields(Sf);
|
||||
|
||||
// Write raw values on surface if specified
|
||||
if (surfaceWriterPtr_.valid())
|
||||
{
|
||||
faceList faces;
|
||||
pointField points;
|
||||
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
combineSurfaceGeometry(faces, points);
|
||||
}
|
||||
else
|
||||
{
|
||||
combineMeshGeometry(faces, points);
|
||||
}
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
fileName outputDir =
|
||||
baseFileDir()/name()/"surface"/obr_.time().timeName();
|
||||
|
||||
surfaceWriterPtr_->write
|
||||
(
|
||||
outputDir,
|
||||
word(sourceTypeNames_[source_]) + "_" + sourceName_,
|
||||
points,
|
||||
faces,
|
||||
fieldName,
|
||||
values,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Apply scale factor
|
||||
values *= scaleFactor_;
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
Type result = processValues(values, Sf, weightField);
|
||||
|
||||
// Add to result dictionary, over-writing any previous entry
|
||||
resultDict_.add(fieldName, result, true);
|
||||
|
||||
file()<< tab << result;
|
||||
|
||||
Log << " " << operationTypeNames_[operation_]
|
||||
<< "(" << sourceName_ << ") of " << fieldName
|
||||
<< " = " << result << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::functionObjects::fieldValues::faceSource::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() << ": "
|
||||
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
|
||||
<< 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::faceSource::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;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
119
src/functionObjects/field/fieldValues/fieldValue/fieldValue.C
Normal file
119
src/functionObjects/field/fieldValues/fieldValue/fieldValue.C
Normal 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 |
|
||||
-------------------------------------------------------------------------------
|
||||
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
|
||||
)
|
||||
:
|
||||
writeFiles(name, runTime, dict, name),
|
||||
dict_(dict),
|
||||
sourceName_(word::null),
|
||||
fields_(dict.lookup("fields")),
|
||||
valueOutput_(dict.lookup("valueOutput")),
|
||||
resultDict_(fileName("name"), dictionary::null)
|
||||
{
|
||||
read(dict);
|
||||
resetName(valueType);
|
||||
}
|
||||
|
||||
|
||||
Foam::functionObjects::fieldValue::fieldValue
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
const word& valueType
|
||||
)
|
||||
:
|
||||
writeFiles(name, obr, dict, name),
|
||||
dict_(dict),
|
||||
sourceName_(word::null),
|
||||
fields_(dict.lookup("fields")),
|
||||
valueOutput_(dict.lookup("valueOutput")),
|
||||
resultDict_(fileName("name"), dictionary::null)
|
||||
{
|
||||
read(dict);
|
||||
resetName(valueType);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldValue::~fieldValue()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::fieldValue::read(const dictionary& dict)
|
||||
{
|
||||
dict_ = dict;
|
||||
writeFiles::read(dict);
|
||||
dict.lookup("fields") >> fields_;
|
||||
dict.lookup("valueOutput") >> valueOutput_;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldValue::execute(const bool postProcess)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldValue::write(const bool postProcess)
|
||||
{
|
||||
writeFiles::write();
|
||||
|
||||
Log << type() << " " << name() << " output:" << nl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
201
src/functionObjects/field/fieldValues/fieldValue/fieldValue.H
Normal file
201
src/functionObjects/field/fieldValues/fieldValue/fieldValue.H
Normal file
@ -0,0 +1,201 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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/>.
|
||||
|
||||
Class
|
||||
Foam::fieldValue
|
||||
|
||||
Group
|
||||
grpFieldFunctionObjects
|
||||
|
||||
Description
|
||||
Base class for field value -based function objects.
|
||||
|
||||
SourceFiles
|
||||
fieldValue.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_fieldValue_H
|
||||
#define functionObjects_fieldValue_H
|
||||
|
||||
#include "writeFiles.H"
|
||||
#include "Switch.H"
|
||||
#include "Field.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class fvMesh;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fieldValue Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class fieldValue
|
||||
:
|
||||
public writeFiles
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Construction dictionary
|
||||
dictionary dict_;
|
||||
|
||||
//- Name of source object
|
||||
word sourceName_;
|
||||
|
||||
//- List of field names to operate on
|
||||
wordList fields_;
|
||||
|
||||
//- Output field values flag
|
||||
Switch valueOutput_;
|
||||
|
||||
//- Results dictionary for external access of results
|
||||
dictionary resultDict_;
|
||||
|
||||
|
||||
// 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 source name
|
||||
inline const word& sourceName() const;
|
||||
|
||||
//- Return the list of field names
|
||||
inline const wordList& fields() const;
|
||||
|
||||
//- Return the output field values flag
|
||||
inline const Switch& valueOutput() const;
|
||||
|
||||
//- Helper function to return the reference to the mesh
|
||||
inline const fvMesh& mesh() const;
|
||||
|
||||
//- Return access to the latest set of results
|
||||
inline const dictionary& resultDict() const;
|
||||
|
||||
//- Read from dictionary
|
||||
virtual bool read(const dictionary& dict);
|
||||
|
||||
//- Execute
|
||||
virtual bool execute(const bool postProcess = false);
|
||||
|
||||
//- Write to screen/file
|
||||
virtual bool write(const bool postProcess = false);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "fieldValueI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "fieldValueTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,69 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "fieldValue.H"
|
||||
#include "fvMesh.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline const Foam::dictionary& Foam::functionObjects::fieldValue::dict() const
|
||||
{
|
||||
return dict_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::word& Foam::functionObjects::fieldValue::sourceName() const
|
||||
{
|
||||
return sourceName_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::wordList& Foam::functionObjects::fieldValue::fields() const
|
||||
{
|
||||
return fields_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::Switch&
|
||||
Foam::functionObjects::fieldValue::valueOutput() const
|
||||
{
|
||||
return valueOutput_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::fvMesh& Foam::functionObjects::fieldValue::mesh() const
|
||||
{
|
||||
return refCast<const fvMesh>(obr_);
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::dictionary&
|
||||
Foam::functionObjects::fieldValue::resultDict() const
|
||||
{
|
||||
return resultDict_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -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));
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,60 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "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);
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
field =
|
||||
ListListOps::combine<Field<Type>>
|
||||
(
|
||||
allValues,
|
||||
accessOp<Field<Type>>()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::fieldValue::combineFields(tmp<Field<Type>>& field)
|
||||
{
|
||||
combineFields(field());
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,218 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "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::functionObjects::fieldValues::fieldValueDelta::writeFileHeader
|
||||
(
|
||||
const label i
|
||||
)
|
||||
{
|
||||
const wordList& fields1 = source1Ptr_->fields();
|
||||
const wordList& fields2 = source2Ptr_->fields();
|
||||
|
||||
DynamicList<word> commonFields(fields1.size());
|
||||
forAll(fields1, i)
|
||||
{
|
||||
label index = findIndex(fields2, fields1[i]);
|
||||
if (index != -1)
|
||||
{
|
||||
commonFields.append(fields1[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Ostream& os = file();
|
||||
|
||||
writeHeaderValue(os, "Source1", source1Ptr_->name());
|
||||
writeHeaderValue(os, "Source2", source2Ptr_->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
|
||||
)
|
||||
:
|
||||
writeFiles(name, runTime, dict, name),
|
||||
operation_(opSubtract),
|
||||
source1Ptr_(NULL),
|
||||
source2Ptr_(NULL)
|
||||
{
|
||||
if (!isA<fvMesh>(obr_))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "objectRegistry is not an fvMesh" << exit(FatalError);
|
||||
}
|
||||
|
||||
read(dict);
|
||||
resetName(typeName);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldValues::fieldValueDelta::~fieldValueDelta()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::fieldValues::fieldValueDelta::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
writeFiles::read(dict);
|
||||
|
||||
source1Ptr_.reset
|
||||
(
|
||||
fieldValue::New
|
||||
(
|
||||
name() + ".source1",
|
||||
obr_,
|
||||
dict.subDict("source1"),
|
||||
false
|
||||
).ptr()
|
||||
);
|
||||
source2Ptr_.reset
|
||||
(
|
||||
fieldValue::New
|
||||
(
|
||||
name() + ".source2",
|
||||
obr_,
|
||||
dict.subDict("source2"),
|
||||
false
|
||||
).ptr()
|
||||
);
|
||||
|
||||
operation_ = operationTypeNames_.read(dict.lookup("operation"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldValues::fieldValueDelta::write
|
||||
(
|
||||
const bool postProcess
|
||||
)
|
||||
{
|
||||
writeFiles::write();
|
||||
|
||||
source1Ptr_->write();
|
||||
source2Ptr_->write();
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
writeTime(file());
|
||||
}
|
||||
|
||||
Log << type() << " " << name() << " output:" << endl;
|
||||
|
||||
bool found = false;
|
||||
processFields<scalar>(found);
|
||||
processFields<vector>(found);
|
||||
processFields<sphericalTensor>(found);
|
||||
processFields<symmTensor>(found);
|
||||
processFields<tensor>(found);
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
file()<< endl;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
Log << " none" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log << endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldValues::fieldValueDelta::execute
|
||||
(
|
||||
const bool postProcess
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,197 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::fieldValues::fieldValueDelta
|
||||
|
||||
Group
|
||||
grpFieldFunctionObjects
|
||||
|
||||
Description
|
||||
This function object provides a differencing option between two 'field
|
||||
value' function objects.
|
||||
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
fieldValueDelta1
|
||||
{
|
||||
type fieldValueDelta;
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
operation subtract;
|
||||
|
||||
fieldValue1
|
||||
{
|
||||
...
|
||||
}
|
||||
fieldValue2
|
||||
{
|
||||
...
|
||||
}
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
\heading Function object usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | type name: fieldValueDelta | yes |
|
||||
\endtable
|
||||
|
||||
\linebreak
|
||||
The \c operation is one of:
|
||||
\plaintable
|
||||
add | add
|
||||
subtract | subtract
|
||||
min | minimum
|
||||
max | maximum
|
||||
average | average
|
||||
\endplaintable
|
||||
SeeAlso
|
||||
Foam::fieldValue
|
||||
|
||||
SourceFiles
|
||||
fieldValueDelta.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_fieldValueDelta_H
|
||||
#define functionObjects_fieldValueDelta_H
|
||||
|
||||
#include "writeFiles.H"
|
||||
#include "fieldValue.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace fieldValues
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fieldValueDelta Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class fieldValueDelta
|
||||
:
|
||||
public writeFiles
|
||||
{
|
||||
public:
|
||||
//- Operation type enumeration
|
||||
enum operationType
|
||||
{
|
||||
opAdd,
|
||||
opSubtract,
|
||||
opMin,
|
||||
opMax,
|
||||
opAverage
|
||||
};
|
||||
|
||||
//- Operation type names
|
||||
static const NamedEnum<operationType, 5> operationTypeNames_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- Operation to apply to values
|
||||
operationType operation_;
|
||||
|
||||
//- Field value source object 1
|
||||
autoPtr<fieldValue> source1Ptr_;
|
||||
|
||||
//- Field value source object 2
|
||||
autoPtr<fieldValue> source2Ptr_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Templated function to process common fields
|
||||
template<class Type>
|
||||
void processFields(bool& found);
|
||||
|
||||
//- Templated function to apply the operation
|
||||
template<class Type>
|
||||
Type applyOperation(const Type& value1, const Type& value2) const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Output file header information
|
||||
virtual void writeFileHeader(const label i);
|
||||
|
||||
|
||||
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(const bool postProcess = false);
|
||||
|
||||
//- Calculate and write
|
||||
virtual bool write(const bool postProcess = false);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fieldValues
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "fieldValueDeltaTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,128 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "GeometricField.H"
|
||||
#include "volMesh.H"
|
||||
#include "surfaceMesh.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Type Foam::functionObjects::fieldValues::fieldValueDelta::applyOperation
|
||||
(
|
||||
const Type& value1,
|
||||
const Type& value2
|
||||
) const
|
||||
{
|
||||
Type result = Zero;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::fieldValues::fieldValueDelta::processFields
|
||||
(
|
||||
bool& found
|
||||
)
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> vf;
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
|
||||
|
||||
const wordList& fields1 = source1Ptr_->fields();
|
||||
|
||||
const dictionary& results1 = source1Ptr_->resultDict();
|
||||
const dictionary& results2 = source2Ptr_->resultDict();
|
||||
|
||||
Type r1(Zero);
|
||||
Type r2(Zero);
|
||||
|
||||
forAll(fields1, i)
|
||||
{
|
||||
const word& fieldName = fields1[i];
|
||||
|
||||
if
|
||||
(
|
||||
(obr_.foundObject<vf>(fieldName) || obr_.foundObject<sf>(fieldName))
|
||||
&& results2.found(fieldName)
|
||||
)
|
||||
{
|
||||
results1.lookup(fieldName) >> r1;
|
||||
results2.lookup(fieldName) >> r2;
|
||||
|
||||
Type result = applyOperation(r1, r2);
|
||||
|
||||
Log << " " << operationTypeNames_[operation_]
|
||||
<< "(" << fieldName << ") = " << result
|
||||
<< endl;
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
file()<< tab << result;
|
||||
}
|
||||
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user