GIT: Initial state after latest Foundation merge

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

View File

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

View File

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

View File

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