mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
GIT: Resolved conflicts arising from merge with develop branch
This commit is contained in:
@ -72,4 +72,7 @@ externalCoupled/externalCoupled.C
|
||||
externalCoupled/externalCoupledMixed/externalCoupledMixedFvPatchFields.C
|
||||
externalCoupled/externalCoupledTemperatureMixed/externalCoupledTemperatureMixedFvPatchScalarField.C
|
||||
|
||||
ddt2/ddt2.C
|
||||
zeroGradient/zeroGradient.C
|
||||
|
||||
LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects
|
||||
|
||||
269
src/functionObjects/field/ddt2/ddt2.C
Normal file
269
src/functionObjects/field/ddt2/ddt2.C
Normal file
@ -0,0 +1,269 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ 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 "ddt2.H"
|
||||
|
||||
#include "volFields.H"
|
||||
#include "dictionary.H"
|
||||
#include "FieldFunctions.H"
|
||||
#include "steadyStateDdtScheme.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(ddt2, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
ddt2,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::ddt2::checkFormatName(const word& str)
|
||||
{
|
||||
if (str.find("@@") == string::npos)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Bad result naming "
|
||||
<< "(no '@@' token found), deactivating."
|
||||
<< nl << endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
else if (str == "@@")
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Bad result naming "
|
||||
<< "(only a '@@' token found), deactivating."
|
||||
<< nl
|
||||
<< endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::ddt2::uniqWords(wordReList& lst)
|
||||
{
|
||||
boolList retain(lst.size());
|
||||
wordHashSet uniq;
|
||||
forAll(lst, i)
|
||||
{
|
||||
const wordRe& select = lst[i];
|
||||
|
||||
retain[i] =
|
||||
(
|
||||
select.isPattern()
|
||||
|| uniq.insert(static_cast<const word&>(select))
|
||||
);
|
||||
}
|
||||
|
||||
inplaceSubset(retain, lst);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::ddt2::accept(const word& fieldName) const
|
||||
{
|
||||
// check input vs possible result names
|
||||
// to avoid circular calculations
|
||||
return !blacklist_.match(fieldName);
|
||||
}
|
||||
|
||||
|
||||
int Foam::functionObjects::ddt2::process(const word& fieldName)
|
||||
{
|
||||
if (!accept(fieldName))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int state = 0;
|
||||
|
||||
apply<volScalarField>(fieldName, state);
|
||||
apply<volVectorField>(fieldName, state);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::ddt2::process()
|
||||
{
|
||||
results_.clear();
|
||||
|
||||
wordHashSet candidates = subsetStrings(selectFields_, mesh_.names());
|
||||
DynamicList<word> missing(selectFields_.size());
|
||||
DynamicList<word> ignored(selectFields_.size());
|
||||
|
||||
// check exact matches first
|
||||
forAll(selectFields_, i)
|
||||
{
|
||||
const wordRe& select = selectFields_[i];
|
||||
if (!select.isPattern())
|
||||
{
|
||||
const word& fieldName = static_cast<const word&>(select);
|
||||
|
||||
if (!candidates.erase(fieldName))
|
||||
{
|
||||
missing.append(fieldName);
|
||||
}
|
||||
else if (process(fieldName) < 1)
|
||||
{
|
||||
ignored.append(fieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
forAllConstIter(wordHashSet, candidates, iter)
|
||||
{
|
||||
process(iter.key());
|
||||
}
|
||||
|
||||
if (missing.size())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Missing field " << missing << endl;
|
||||
}
|
||||
if (ignored.size())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Unprocessed field " << ignored << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::ddt2::ddt2
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict),
|
||||
selectFields_(),
|
||||
resultName_(word::null),
|
||||
blacklist_(),
|
||||
results_(),
|
||||
mag_(dict.lookupOrDefault<Switch>("mag", false))
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::ddt2::~ddt2()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::ddt2::read(const dictionary& dict)
|
||||
{
|
||||
if (word(mesh_.ddtScheme("default")) == "steadyState")
|
||||
{
|
||||
WarningInFunction
|
||||
<< typeName << " function object not appropriate for steady-state"
|
||||
<< endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
dict.lookup("fields") >> selectFields_;
|
||||
uniqWords(selectFields_);
|
||||
|
||||
resultName_ = dict.lookupOrDefault<word>
|
||||
(
|
||||
"result",
|
||||
( mag_ ? "mag(ddt(@@))" : "magSqr(ddt(@@))" )
|
||||
);
|
||||
|
||||
if (checkFormatName(resultName_))
|
||||
{
|
||||
blacklist_.set
|
||||
(
|
||||
string::quotemeta<regExp>
|
||||
(
|
||||
resultName_
|
||||
).replace("@@", "(.+)")
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
blacklist_.clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::ddt2::execute()
|
||||
{
|
||||
results_.clear();
|
||||
process();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::ddt2::write()
|
||||
{
|
||||
// Consistent output order
|
||||
const wordList outputList = results_.sortedToc();
|
||||
|
||||
forAll(outputList, i)
|
||||
{
|
||||
const word& fieldName = outputList[i];
|
||||
|
||||
if (foundObject<regIOobject>(fieldName))
|
||||
{
|
||||
const regIOobject& io = lookupObject<regIOobject>(fieldName);
|
||||
|
||||
Log << type() << " " << name()
|
||||
<< " write: writing field " << fieldName << endl;
|
||||
|
||||
io.write();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
200
src/functionObjects/field/ddt2/ddt2.H
Normal file
200
src/functionObjects/field/ddt2/ddt2.H
Normal file
@ -0,0 +1,200 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ 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::ddt2
|
||||
|
||||
Group
|
||||
grpFVFunctionObjects
|
||||
|
||||
Description
|
||||
This function object calculates the magnitude squared
|
||||
of d(scalarField)/dt.
|
||||
|
||||
The result can be used further for determining variance or RMS values
|
||||
(for example).
|
||||
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
dpdt2
|
||||
{
|
||||
type ddt2;
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
fields (p);
|
||||
result d@@dt2;
|
||||
...
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
\heading Function object usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | type name: ddt2 | yes |
|
||||
fields | Name of fields to process | yes |
|
||||
result | Name of results | no | magSqr(ddt(@@))
|
||||
log | Log to standard output | no | yes
|
||||
mag | Use 'mag' instead of 'magSqr' | no | false
|
||||
\endtable
|
||||
|
||||
Note that the optional 'mag' entry cannot be changed during the simulation
|
||||
since it alters the dimensions of the output field.
|
||||
|
||||
A list of fields can contain exact names or regular expressions.
|
||||
The token '\@\@' in the result name is replaced by the name of the source
|
||||
field.
|
||||
|
||||
The function object will skip over fields that appear to have
|
||||
already been processed (ie, their names are similar to the output names).
|
||||
|
||||
SourceFiles
|
||||
ddt2.C
|
||||
IOddt2.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_ddt2_H
|
||||
#define functionObjects_ddt2_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "volFieldsFwd.H"
|
||||
#include "OFstream.H"
|
||||
#include "wordReList.H"
|
||||
#include "regExp.H"
|
||||
#include "HashSet.H"
|
||||
#include "Switch.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class ddt2 Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class ddt2
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Name of fields to process
|
||||
wordReList selectFields_;
|
||||
|
||||
//- Formatting for the result fields.
|
||||
word resultName_;
|
||||
|
||||
//- Avoid processing the same field twice.
|
||||
mutable regExp blacklist_;
|
||||
|
||||
//- Hashed names of result fields.
|
||||
wordHashSet results_;
|
||||
|
||||
//- Use 'mag' instead of 'magSqr'.
|
||||
// Cannot be adjusted during the simulation since it alters the
|
||||
// dimensions of the output field.
|
||||
const Switch mag_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Check that the word contains the appropriate substitution token(s).
|
||||
static bool checkFormatName(const word&);
|
||||
|
||||
//- Eliminate duplicate 'word' entries
|
||||
static void uniqWords(wordReList&);
|
||||
|
||||
|
||||
//- Accept unless field name appears to have already been processed
|
||||
bool accept(const word& fieldName) const;
|
||||
|
||||
//- Apply for the volume field type
|
||||
template<class FieldType>
|
||||
int apply(const word& inputName, int& state);
|
||||
|
||||
//- Process by trying to apply for various volume field types.
|
||||
int process(const word& inputName);
|
||||
|
||||
//- Calculate the ddt2 fields
|
||||
void process();
|
||||
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
ddt2(const ddt2&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const ddt2&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("ddt2");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
ddt2
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~ddt2();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return name of the ddt2 function object
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Calculate the ddt2 fields
|
||||
virtual bool execute();
|
||||
|
||||
//- Write the ddt fields
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "ddt2Templates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
103
src/functionObjects/field/ddt2/ddt2Templates.C
Normal file
103
src/functionObjects/field/ddt2/ddt2Templates.C
Normal file
@ -0,0 +1,103 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ 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 "Time.H"
|
||||
#include "dimensionedType.H"
|
||||
#include "fvcDdt.H"
|
||||
|
||||
template<class FieldType>
|
||||
int Foam::functionObjects::ddt2::apply(const word& inputName, int& state)
|
||||
{
|
||||
// State: return 0 (not-processed), -1 (skip), +1 ok
|
||||
|
||||
// Already done, or not available
|
||||
if (state || !foundObject<FieldType>(inputName))
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
const FieldType& input = lookupObject<FieldType>(inputName);
|
||||
|
||||
word outputName(resultName_);
|
||||
outputName.replace("@@", inputName);
|
||||
|
||||
results_.set(outputName);
|
||||
|
||||
if (!foundObject<volScalarField>(outputName))
|
||||
{
|
||||
tmp<volScalarField> tddt2
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
outputName,
|
||||
time_.timeName(),
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar
|
||||
(
|
||||
"0",
|
||||
(
|
||||
mag_
|
||||
? mag(input.dimensions()/dimTime)
|
||||
: magSqr(input.dimensions()/dimTime)
|
||||
),
|
||||
Zero
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
store(outputName, tddt2);
|
||||
}
|
||||
|
||||
volScalarField& output = const_cast<volScalarField&>
|
||||
(
|
||||
lookupObject<volScalarField>(outputName)
|
||||
);
|
||||
|
||||
if (mag_)
|
||||
{
|
||||
output = mag(fvc::ddt(input));
|
||||
}
|
||||
else
|
||||
{
|
||||
output = magSqr(fvc::ddt(input));
|
||||
}
|
||||
|
||||
// Could add additional statistics here
|
||||
Log << type() << " " << name()
|
||||
<< " field " << outputName
|
||||
<< " average: " << gAverage(output) << endl;
|
||||
|
||||
state = +1;
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
223
src/functionObjects/field/zeroGradient/zeroGradient.C
Normal file
223
src/functionObjects/field/zeroGradient/zeroGradient.C
Normal file
@ -0,0 +1,223 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ 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 "zeroGradient.H"
|
||||
|
||||
#include "volFields.H"
|
||||
#include "dictionary.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(zeroGradient, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
zeroGradient,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::zeroGradient::checkFormatName(const word& str)
|
||||
{
|
||||
if (str.find("@@") == string::npos)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Bad result naming "
|
||||
<< "(no '@@' token found), deactivating."
|
||||
<< nl << endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
else if (str == "@@")
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Bad result naming "
|
||||
<< "(only a '@@' token found), deactivating."
|
||||
<< nl
|
||||
<< endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::zeroGradient::uniqWords(wordReList& lst)
|
||||
{
|
||||
boolList retain(lst.size());
|
||||
wordHashSet uniq;
|
||||
forAll(lst, i)
|
||||
{
|
||||
const wordRe& select = lst[i];
|
||||
|
||||
retain[i] =
|
||||
(
|
||||
select.isPattern()
|
||||
|| uniq.insert(static_cast<const word&>(select))
|
||||
);
|
||||
}
|
||||
|
||||
inplaceSubset(retain, lst);
|
||||
}
|
||||
|
||||
|
||||
int Foam::functionObjects::zeroGradient::process(const word& fieldName)
|
||||
{
|
||||
int state = 0;
|
||||
apply<scalar>(fieldName, state);
|
||||
apply<vector>(fieldName, state);
|
||||
apply<sphericalTensor>(fieldName, state);
|
||||
apply<symmTensor>(fieldName, state);
|
||||
apply<tensor>(fieldName, state);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::zeroGradient::process()
|
||||
{
|
||||
results_.clear();
|
||||
|
||||
wordHashSet candidates = subsetStrings(selectFields_, mesh_.names());
|
||||
DynamicList<word> missing(selectFields_.size());
|
||||
DynamicList<word> ignored(selectFields_.size());
|
||||
|
||||
// check exact matches first
|
||||
forAll(selectFields_, i)
|
||||
{
|
||||
const wordRe& select = selectFields_[i];
|
||||
if (!select.isPattern())
|
||||
{
|
||||
const word& fieldName = static_cast<const word&>(select);
|
||||
|
||||
if (!candidates.erase(fieldName))
|
||||
{
|
||||
missing.append(fieldName);
|
||||
}
|
||||
else if (process(fieldName) < 1)
|
||||
{
|
||||
ignored.append(fieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
forAllConstIter(wordHashSet, candidates, iter)
|
||||
{
|
||||
process(iter.key());
|
||||
}
|
||||
|
||||
if (missing.size())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Missing field " << missing << endl;
|
||||
}
|
||||
if (ignored.size())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Unprocessed field " << ignored << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::zeroGradient::zeroGradient
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict),
|
||||
selectFields_(),
|
||||
resultName_(string::null),
|
||||
results_()
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::zeroGradient::~zeroGradient()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::zeroGradient::read(const dictionary& dict)
|
||||
{
|
||||
dict.lookup("fields") >> selectFields_;
|
||||
uniqWords(selectFields_);
|
||||
|
||||
resultName_ = dict.lookupOrDefault<word>("result", type() + "(@@)");
|
||||
return checkFormatName(resultName_);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::zeroGradient::execute()
|
||||
{
|
||||
results_.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::zeroGradient::write()
|
||||
{
|
||||
// Consistent output order
|
||||
const wordList outputList = results_.sortedToc();
|
||||
|
||||
forAll(outputList, i)
|
||||
{
|
||||
const word& fieldName = outputList[i];
|
||||
|
||||
if (foundObject<regIOobject>(fieldName))
|
||||
{
|
||||
const regIOobject& io = lookupObject<regIOobject>(fieldName);
|
||||
|
||||
Log << type() << " " << name()
|
||||
<< " write: writing field " << fieldName << endl;
|
||||
|
||||
io.write();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
188
src/functionObjects/field/zeroGradient/zeroGradient.H
Normal file
188
src/functionObjects/field/zeroGradient/zeroGradient.H
Normal file
@ -0,0 +1,188 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ 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::zeroGradient
|
||||
|
||||
Group
|
||||
grpFVFunctionObjects
|
||||
|
||||
Description
|
||||
This function object creates a volume field with zero-gradient
|
||||
boundary conditions from another volume field.
|
||||
|
||||
The result can be used, for example, to post-process near-wall
|
||||
field values.
|
||||
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
zeroGrad
|
||||
{
|
||||
type zeroGradient;
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
fields (U "(T|k|epsilon|omega)");
|
||||
result @@nearWall;
|
||||
...
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
\heading Function object usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | type name: zeroGradient | yes |
|
||||
fields | Name of fields to process | yes |
|
||||
result | Name of results | no | zeroGradient(@@)
|
||||
log | Log to standard output | no | no
|
||||
\endtable
|
||||
|
||||
A list of fields can contain exact names or regular expressions.
|
||||
The token '\@\@' in the result name is replaced by the name of the source
|
||||
field.
|
||||
|
||||
The function object will skip over fields that would not benefit
|
||||
- ie, only processor, empty, zeroGradient, symmetry patches.
|
||||
This check should also prevent processing fields multiple times.
|
||||
|
||||
SourceFiles
|
||||
zeroGradient.C
|
||||
zeroGradientFunctionObject.C
|
||||
IOzeroGradient.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_zeroGradient_H
|
||||
#define functionObjects_zeroGradient_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "volFieldsFwd.H"
|
||||
#include "OFstream.H"
|
||||
#include "wordReList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class zeroGradient Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class zeroGradient
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Name of fields to process
|
||||
wordReList selectFields_;
|
||||
|
||||
//- Formatting for the result fields.
|
||||
word resultName_;
|
||||
|
||||
//- Hashed names of result fields, and their type
|
||||
HashTable<word> results_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Check that the word contains the appropriate substitution token(s).
|
||||
static bool checkFormatName(const word&);
|
||||
|
||||
//- Eliminate duplicate 'word' entries
|
||||
static void uniqWords(wordReList&);
|
||||
|
||||
|
||||
//- Accept unless field only has empty/zero-gradient/processor patches
|
||||
template<class Type>
|
||||
static bool accept(const GeometricField<Type, fvPatchField, volMesh>&);
|
||||
|
||||
//- Apply for the volume field type
|
||||
template<class Type>
|
||||
int apply(const word& inputName, int& state);
|
||||
|
||||
//- Process by trying to apply for various volume field types.
|
||||
int process(const word& inputName);
|
||||
|
||||
//- Calculate the zeroGradient fields
|
||||
void process();
|
||||
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
zeroGradient(const zeroGradient&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const zeroGradient&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("zeroGradient");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
zeroGradient
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~zeroGradient();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the zeroGradient specification
|
||||
virtual bool read(const dictionary& dict);
|
||||
|
||||
//- Calculate the zeroGradient fields
|
||||
virtual bool execute();
|
||||
|
||||
//- Write the zeroGradient fields
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "zeroGradientTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
115
src/functionObjects/field/zeroGradient/zeroGradientTemplates.C
Normal file
115
src/functionObjects/field/zeroGradient/zeroGradientTemplates.C
Normal file
@ -0,0 +1,115 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ 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 "polyPatch.H"
|
||||
#include "Time.H"
|
||||
#include "zeroGradientFvPatchField.H"
|
||||
|
||||
template<class Type>
|
||||
bool Foam::functionObjects::zeroGradient::accept
|
||||
(
|
||||
const GeometricField<Type, fvPatchField, volMesh>& input
|
||||
)
|
||||
{
|
||||
const typename GeometricField<Type, fvPatchField, volMesh>::Boundary&
|
||||
patches = input.boundaryField();
|
||||
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
const fvPatchField<Type>& p = patches[patchi];
|
||||
const polyPatch& pp = p.patch().patch();
|
||||
|
||||
return !polyPatch::constraintType(pp.type());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
int Foam::functionObjects::zeroGradient::apply
|
||||
(
|
||||
const word& inputName,
|
||||
int& state
|
||||
)
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
|
||||
|
||||
// State: return 0 (not-processed), -1 (skip), +1 ok
|
||||
|
||||
// Already done, or not available
|
||||
if (state || !foundObject<VolFieldType>(inputName))
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
const VolFieldType& input = lookupObject<VolFieldType>(inputName);
|
||||
|
||||
if (!returnReduce(accept(input), orOp<bool>()))
|
||||
{
|
||||
state = -1;
|
||||
return state;
|
||||
}
|
||||
|
||||
word outputName(resultName_);
|
||||
outputName.replace("@@", inputName);
|
||||
|
||||
// Also save the field-type, just in case we want it later
|
||||
results_.set(outputName, VolFieldType::typeName);
|
||||
|
||||
if (!foundObject<VolFieldType>(outputName))
|
||||
{
|
||||
tmp<VolFieldType> tzg
|
||||
(
|
||||
new VolFieldType
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
outputName,
|
||||
time_.timeName(),
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensioned<Type>("0", input.dimensions(), Zero),
|
||||
zeroGradientFvPatchField<Type>::typeName
|
||||
)
|
||||
);
|
||||
|
||||
store(outputName, tzg);
|
||||
}
|
||||
|
||||
VolFieldType& output =
|
||||
const_cast<VolFieldType&>(lookupObject<VolFieldType>(outputName));
|
||||
output = input;
|
||||
output.correctBoundaryConditions();
|
||||
|
||||
state = +1;
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user