mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
functionObjects: New abstract base-class 'fieldExpression' for simple field expression evaluation functionObjects
Updated and simplified 'div', 'grad' and 'mag' functionObjects by deriving from 'fieldExpression'. Corrected the handling of cached gradients in 'grad'.
This commit is contained in:
@ -38,6 +38,28 @@ namespace functionObjects
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::fvMeshFunctionObject::write(const word& fieldName)
|
||||
{
|
||||
if (mesh_.foundObject<regIOobject>(fieldName))
|
||||
{
|
||||
const regIOobject& field = mesh_.lookupObject<regIOobject>(fieldName);
|
||||
|
||||
Info<< type() << " " << name() << " writing:" << nl
|
||||
<< " field " << field.name() << nl << endl;
|
||||
|
||||
field.write();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fvMeshFunctionObject::fvMeshFunctionObject
|
||||
|
||||
@ -73,6 +73,29 @@ protected:
|
||||
const fvMesh& mesh_;
|
||||
|
||||
|
||||
// Protected member functions
|
||||
|
||||
//- Find field in the objectRegistry
|
||||
template<class FieldType>
|
||||
bool foundField(const word& fieldName) const;
|
||||
|
||||
//- Lookup field from the objectRegistry
|
||||
template<class FieldType>
|
||||
const FieldType& lookupField(const word& fieldName) const;
|
||||
|
||||
//- Store the given field in the objectRegistry under the given name
|
||||
template<class FieldType>
|
||||
bool store
|
||||
(
|
||||
word& fieldName,
|
||||
tmp<FieldType> tfield,
|
||||
bool cacheable = false
|
||||
);
|
||||
|
||||
//- Write field if present in objectRegistry
|
||||
virtual bool write(const word& fieldName);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
@ -113,6 +136,12 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "fvMeshFunctionObjectTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -0,0 +1,100 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 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 "fvMeshFunctionObject.H"
|
||||
#include "volFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<class FieldType>
|
||||
bool Foam::functionObjects::fvMeshFunctionObject::foundField
|
||||
(
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return mesh_.foundObject<FieldType>(fieldName);
|
||||
}
|
||||
|
||||
|
||||
template<class FieldType>
|
||||
const FieldType& Foam::functionObjects::fvMeshFunctionObject::lookupField
|
||||
(
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return mesh_.lookupObject<FieldType>(fieldName);
|
||||
}
|
||||
|
||||
|
||||
template<class FieldType>
|
||||
bool Foam::functionObjects::fvMeshFunctionObject::store
|
||||
(
|
||||
word& fieldName,
|
||||
tmp<FieldType> tfield,
|
||||
bool cacheable
|
||||
)
|
||||
{
|
||||
if (cacheable && fieldName == tfield().name())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Cannot store cache-able field with the named used in the cache."
|
||||
<< nl
|
||||
<< " Either choose a different name or cache the field"
|
||||
<< " and use the 'writeRegisteredObject' functionObject."
|
||||
<< endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if
|
||||
(
|
||||
fieldName.size()
|
||||
&& mesh_.foundObject<FieldType>(fieldName)
|
||||
)
|
||||
{
|
||||
const_cast<FieldType&>
|
||||
(
|
||||
mesh_.lookupObject<FieldType>(fieldName)
|
||||
) = tfield;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fieldName.size() && fieldName != tfield().name())
|
||||
{
|
||||
tfield.ref().rename(fieldName);
|
||||
}
|
||||
else
|
||||
{
|
||||
fieldName = tfield().name();
|
||||
}
|
||||
|
||||
mesh_.objectRegistry::store(tfield.ptr());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -32,6 +32,7 @@ surfaceInterpolateFields/surfaceInterpolateFields.C
|
||||
regionSizeDistribution/regionSizeDistribution.C
|
||||
histogram/histogram.C
|
||||
|
||||
fieldExpression/fieldExpression.C
|
||||
div/div.C
|
||||
grad/grad.C
|
||||
mag/mag.C
|
||||
|
||||
@ -25,6 +25,7 @@ License
|
||||
|
||||
#include "div.H"
|
||||
#include "volFields.H"
|
||||
#include "surfaceFields.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
@ -39,42 +40,6 @@ namespace functionObjects
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::volScalarField& Foam::functionObjects::div::divField
|
||||
(
|
||||
const word& divName,
|
||||
const dimensionSet& dims
|
||||
)
|
||||
{
|
||||
if (!mesh_.foundObject<volScalarField>(divName))
|
||||
{
|
||||
volScalarField* divFieldPtr
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
divName,
|
||||
mesh_.time().timeName(),
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar("zero", dims/dimLength, 0.0)
|
||||
)
|
||||
);
|
||||
|
||||
mesh_.objectRegistry::store(divFieldPtr);
|
||||
}
|
||||
|
||||
const volScalarField& field = mesh_.lookupObject<volScalarField>(divName);
|
||||
|
||||
return const_cast<volScalarField&>(field);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::div::div
|
||||
@ -84,10 +49,8 @@ Foam::functionObjects::div::div
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
fieldExpression(name, runTime, dict)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
@ -98,26 +61,12 @@ Foam::functionObjects::div::~div()
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::div::read(const dictionary& dict)
|
||||
{
|
||||
dict.lookup("fieldName") >> fieldName_;
|
||||
dict.lookup("resultName") >> resultName_;
|
||||
|
||||
if (resultName_ == "none")
|
||||
{
|
||||
resultName_ = "fvc::div(" + fieldName_ + ")";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::div::execute(const bool postProcess)
|
||||
{
|
||||
bool processed = false;
|
||||
|
||||
calcDiv<surfaceScalarField>(fieldName_, resultName_, processed);
|
||||
calcDiv<volVectorField>(fieldName_, resultName_, processed);
|
||||
processed = processed || calc<surfaceScalarField>();
|
||||
processed = processed || calc<volVectorField>();
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
@ -125,24 +74,7 @@ bool Foam::functionObjects::div::execute(const bool postProcess)
|
||||
<< "Unprocessed field " << fieldName_ << endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::div::write(const bool postProcess)
|
||||
{
|
||||
if (mesh_.foundObject<regIOobject>(resultName_))
|
||||
{
|
||||
const regIOobject& field =
|
||||
mesh_.lookupObject<regIOobject>(resultName_);
|
||||
|
||||
Info<< type() << " " << name() << " output:" << nl
|
||||
<< " writing field " << field.name() << nl << endl;
|
||||
|
||||
field.write();
|
||||
}
|
||||
|
||||
return true;
|
||||
return processed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -43,17 +43,12 @@ SourceFiles
|
||||
#ifndef functionObjects_div_H
|
||||
#define functionObjects_div_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "volFieldsFwd.H"
|
||||
#include "fieldExpression.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class dimensionSet;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
@ -63,40 +58,14 @@ namespace functionObjects
|
||||
|
||||
class div
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
public fieldExpression
|
||||
{
|
||||
// Private member data
|
||||
|
||||
//- Name of field to process
|
||||
word fieldName_;
|
||||
|
||||
//- Name of result field
|
||||
word resultName_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Helper function to create/store/return the divergence field
|
||||
volScalarField& divField
|
||||
(
|
||||
const word& gradName,
|
||||
const dimensionSet& dims
|
||||
);
|
||||
|
||||
//- Helper function to calculate the divergence of different field types
|
||||
//- Calculate the divergence of either a
|
||||
// volScalarField or a surfaceScalarField and register the result
|
||||
template<class FieldType>
|
||||
void calcDiv
|
||||
(
|
||||
const word& fieldName,
|
||||
const word& resultName,
|
||||
bool& processed
|
||||
);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
div(const div&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const div&);
|
||||
bool calc();
|
||||
|
||||
|
||||
public:
|
||||
@ -122,14 +91,8 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the div data
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Calculate the divergence field
|
||||
virtual bool execute(const bool postProcess = false);
|
||||
|
||||
//- Write the divergence field
|
||||
virtual bool write(const bool postProcess = false);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -23,28 +23,24 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fvMesh.H"
|
||||
#include "fvcDiv.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class FieldType>
|
||||
void Foam::functionObjects::div::calcDiv
|
||||
(
|
||||
const word& fieldName,
|
||||
const word& resultName,
|
||||
bool& processed
|
||||
)
|
||||
bool Foam::functionObjects::div::calc()
|
||||
{
|
||||
if (mesh_.foundObject<FieldType>(fieldName))
|
||||
if (foundField<FieldType>(fieldName_))
|
||||
{
|
||||
const FieldType& vf = mesh_.lookupObject<FieldType>(fieldName);
|
||||
|
||||
volScalarField& field = divField(resultName, vf.dimensions());
|
||||
|
||||
field = fvc::div(vf);
|
||||
|
||||
processed = true;
|
||||
return store
|
||||
(
|
||||
resultName_,
|
||||
fvc::div(lookupField<FieldType>(fieldName_))
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,81 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 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 "fieldExpression.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(fieldExpression, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldExpression::fieldExpression
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldExpression::~fieldExpression()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::fieldExpression::read(const dictionary& dict)
|
||||
{
|
||||
dict.lookup("field") >> fieldName_;
|
||||
|
||||
if (dict.found("result"))
|
||||
{
|
||||
dict.lookup("result") >> resultName_;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldExpression::write(const bool postProcess)
|
||||
{
|
||||
return fvMeshFunctionObject::write(resultName_);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,126 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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::fieldExpression
|
||||
|
||||
Group
|
||||
grpFieldFunctionObjects
|
||||
|
||||
Description
|
||||
|
||||
SeeAlso
|
||||
Foam::functionObjects::fvMeshFunctionObject
|
||||
|
||||
SourceFiles
|
||||
fieldExpression.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_fieldExpression_H
|
||||
#define functionObjects_fieldExpression_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "volFieldsFwd.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fieldExpression Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class fieldExpression
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected member data
|
||||
|
||||
//- Name of field to process
|
||||
word fieldName_;
|
||||
|
||||
//- Name of result field
|
||||
word resultName_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
fieldExpression(const fieldExpression&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const fieldExpression&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("fieldExpression");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
fieldExpression
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~fieldExpression();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the fieldExpression data
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Calculate the fieldExpressionergence field
|
||||
virtual bool execute(const bool postProcess = false) = 0;
|
||||
|
||||
//- Write the fieldExpressionergence field
|
||||
virtual bool write(const bool postProcess = false);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,7 +24,6 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "grad.H"
|
||||
#include "volFields.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
@ -48,7 +47,7 @@ Foam::functionObjects::grad::grad
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict)
|
||||
fieldExpression(name, runTime, dict)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
@ -62,26 +61,12 @@ Foam::functionObjects::grad::~grad()
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::grad::read(const dictionary& dict)
|
||||
{
|
||||
dict.lookup("fieldName") >> fieldName_;
|
||||
dict.lookup("resultName") >> resultName_;
|
||||
|
||||
if (resultName_ == "none")
|
||||
{
|
||||
resultName_ = "fvc::grad(" + fieldName_ + ")";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::grad::execute(const bool postProcess)
|
||||
{
|
||||
bool processed = false;
|
||||
|
||||
calcGrad<scalar>(fieldName_, resultName_, processed);
|
||||
calcGrad<vector>(fieldName_, resultName_, processed);
|
||||
processed = processed || calc<scalar>();
|
||||
processed = processed || calc<vector>();
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
@ -93,21 +78,4 @@ bool Foam::functionObjects::grad::execute(const bool postProcess)
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::grad::write(const bool postProcess)
|
||||
{
|
||||
if (obr_.foundObject<regIOobject>(resultName_))
|
||||
{
|
||||
const regIOobject& field =
|
||||
obr_.lookupObject<regIOobject>(resultName_);
|
||||
|
||||
Info<< type() << " " << name() << " output:" << nl
|
||||
<< " writing field " << field.name() << nl << endl;
|
||||
|
||||
field.write();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -43,17 +43,12 @@ SourceFiles
|
||||
#ifndef functionObjects_grad_H
|
||||
#define functionObjects_grad_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "volFieldsFwd.H"
|
||||
#include "fieldExpression.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class dimensionSet;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
@ -63,43 +58,13 @@ namespace functionObjects
|
||||
|
||||
class grad
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
public fieldExpression
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Name of field to process
|
||||
word fieldName_;
|
||||
|
||||
//- Name of result field
|
||||
word resultName_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Helper function to create/store/return the gradient field
|
||||
//- Calculate the magnitude of the field and register the result
|
||||
template<class Type>
|
||||
GeometricField
|
||||
<
|
||||
typename outerProduct<vector, Type>::type,
|
||||
fvPatchField,
|
||||
volMesh
|
||||
>&
|
||||
gradField(const word& gradName, const dimensionSet& dims);
|
||||
|
||||
//- Helper function to calculate the gradient of different field types
|
||||
template<class Type>
|
||||
void calcGrad
|
||||
(
|
||||
const word& fieldName,
|
||||
const word& resultName,
|
||||
bool& processed
|
||||
);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
grad(const grad&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const grad&);
|
||||
bool calc();
|
||||
|
||||
|
||||
public:
|
||||
@ -125,14 +90,8 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the grad data
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Calculate the gradient field
|
||||
virtual bool execute(const bool postProcess = false);
|
||||
|
||||
//- Write the gradient field
|
||||
virtual bool write(const bool postProcess = false);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -23,97 +23,37 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fvMesh.H"
|
||||
#include "fvcGrad.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::GeometricField
|
||||
<
|
||||
typename Foam::outerProduct<Foam::vector, Type>::type,
|
||||
Foam::fvPatchField,
|
||||
Foam::volMesh
|
||||
>&
|
||||
Foam::functionObjects::grad::gradField
|
||||
(
|
||||
const word& gradName,
|
||||
const dimensionSet& dims
|
||||
)
|
||||
bool Foam::functionObjects::grad::calc()
|
||||
{
|
||||
Info<< "gradField" << endl;
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
|
||||
|
||||
typedef typename outerProduct<vector, Type>::type gradType;
|
||||
typedef GeometricField<gradType, fvPatchField, volMesh> vfGradType;
|
||||
|
||||
if (!mesh_.foundObject<vfGradType>(gradName))
|
||||
if (foundField<VolFieldType>(fieldName_))
|
||||
{
|
||||
vfGradType* gradFieldPtr
|
||||
return store
|
||||
(
|
||||
new vfGradType
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
gradName,
|
||||
mesh_.time().timeName(),
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensioned<gradType>
|
||||
(
|
||||
"zero",
|
||||
dims/dimLength,
|
||||
Zero
|
||||
)
|
||||
)
|
||||
resultName_,
|
||||
fvc::grad(lookupField<VolFieldType>(fieldName_)),
|
||||
true
|
||||
);
|
||||
|
||||
mesh_.objectRegistry::store(gradFieldPtr);
|
||||
}
|
||||
|
||||
const vfGradType& field = mesh_.lookupObject<vfGradType>(gradName);
|
||||
|
||||
return const_cast<vfGradType&>(field);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::grad::calcGrad
|
||||
(
|
||||
const word& fieldName,
|
||||
const word& resultName,
|
||||
bool& processed
|
||||
)
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> vfType;
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sfType;
|
||||
|
||||
typedef typename outerProduct<vector, Type>::type gradType;
|
||||
typedef GeometricField<gradType, fvPatchField, volMesh> vfGradType;
|
||||
|
||||
if (mesh_.foundObject<vfType>(fieldName))
|
||||
else if (foundField<SurfaceFieldType>(fieldName_))
|
||||
{
|
||||
const vfType& vf = mesh_.lookupObject<vfType>(fieldName);
|
||||
|
||||
vfGradType& field = gradField<Type>(resultName, vf.dimensions());
|
||||
|
||||
// De-reference the tmp to avoid a clash with the cached grad field
|
||||
field = fvc::grad(vf)();
|
||||
|
||||
processed = true;
|
||||
return store
|
||||
(
|
||||
resultName_,
|
||||
fvc::grad(lookupField<SurfaceFieldType>(fieldName_)),
|
||||
true
|
||||
);
|
||||
}
|
||||
else if (mesh_.foundObject<sfType>(fieldName))
|
||||
else
|
||||
{
|
||||
const sfType& sf = mesh_.lookupObject<sfType>(fieldName);
|
||||
|
||||
vfGradType& field = gradField<Type>(resultName, sf.dimensions());
|
||||
|
||||
// De-reference the tmp to avoid a clash with the cached grad field
|
||||
field = fvc::grad(sf)();
|
||||
|
||||
processed = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -24,7 +24,6 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "mag.H"
|
||||
#include "volFields.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
@ -48,7 +47,7 @@ Foam::functionObjects::mag::mag
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict)
|
||||
fieldExpression(name, runTime, dict)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
@ -62,29 +61,15 @@ Foam::functionObjects::mag::~mag()
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::mag::read(const dictionary& dict)
|
||||
{
|
||||
dict.lookup("fieldName") >> fieldName_;
|
||||
dict.lookup("resultName") >> resultName_;
|
||||
|
||||
if (resultName_ == "none")
|
||||
{
|
||||
resultName_ = "mag(" + fieldName_ + ")";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::mag::execute(const bool postProcess)
|
||||
{
|
||||
bool processed = false;
|
||||
|
||||
calc<scalar>(fieldName_, resultName_, processed);
|
||||
calc<vector>(fieldName_, resultName_, processed);
|
||||
calc<sphericalTensor>(fieldName_, resultName_, processed);
|
||||
calc<symmTensor>(fieldName_, resultName_, processed);
|
||||
calc<tensor>(fieldName_, resultName_, processed);
|
||||
processed = processed || calc<scalar>();
|
||||
processed = processed || calc<vector>();
|
||||
processed = processed || calc<sphericalTensor>();
|
||||
processed = processed || calc<symmTensor>();
|
||||
processed = processed || calc<tensor>();
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
@ -92,24 +77,7 @@ bool Foam::functionObjects::mag::execute(const bool postProcess)
|
||||
<< "Unprocessed field " << fieldName_ << endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::mag::write(const bool postProcess)
|
||||
{
|
||||
if (obr_.foundObject<regIOobject>(resultName_))
|
||||
{
|
||||
const regIOobject& field =
|
||||
obr_.lookupObject<regIOobject>(resultName_);
|
||||
|
||||
Info<< type() << " " << name() << " output:" << nl
|
||||
<< " writing field " << field.name() << nl << endl;
|
||||
|
||||
field.write();
|
||||
}
|
||||
|
||||
return true;
|
||||
return processed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -43,17 +43,12 @@ SourceFiles
|
||||
#ifndef functionObjects_mag_H
|
||||
#define functionObjects_mag_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "volFieldsFwd.H"
|
||||
#include "fieldExpression.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class dimensionSet;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
@ -63,37 +58,13 @@ namespace functionObjects
|
||||
|
||||
class mag
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
public fieldExpression
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Name of field to process
|
||||
word fieldName_;
|
||||
|
||||
//- Name of result field
|
||||
word resultName_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Helper function to create/store/return the mag field
|
||||
template<class FieldType>
|
||||
FieldType& magField(const word& magName, const dimensionSet& dims);
|
||||
|
||||
//- Helper function to calculate the magnitude of different field types
|
||||
//- Calculate the magnitude of the field and register the result
|
||||
template<class Type>
|
||||
void calc
|
||||
(
|
||||
const word& fieldName,
|
||||
const word& resultName,
|
||||
bool& processed
|
||||
);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
mag(const mag&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const mag&);
|
||||
bool calc();
|
||||
|
||||
|
||||
public:
|
||||
@ -119,14 +90,8 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the mag data
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Calculate the magnitude field
|
||||
virtual bool execute(const bool postProcess = false);
|
||||
|
||||
//- Write the magnitude field
|
||||
virtual bool write(const bool postProcess = false);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -23,80 +23,36 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
#include "volFields.H"
|
||||
#include "surfaceFields.H"
|
||||
|
||||
template<class FieldType>
|
||||
FieldType& Foam::functionObjects::mag::magField
|
||||
(
|
||||
const word& magName,
|
||||
const dimensionSet& dims
|
||||
)
|
||||
{
|
||||
if (!mesh_.foundObject<FieldType>(magName))
|
||||
{
|
||||
FieldType* magFieldPtr
|
||||
(
|
||||
new FieldType
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
magName,
|
||||
mesh_.time().timeName(),
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar("zero", dims, 0.0)
|
||||
)
|
||||
);
|
||||
|
||||
mesh_.objectRegistry::store(magFieldPtr);
|
||||
}
|
||||
|
||||
const FieldType& f = mesh_.lookupObject<FieldType>(magName);
|
||||
|
||||
return const_cast<FieldType&>(f);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::mag::calc
|
||||
(
|
||||
const word& fieldName,
|
||||
const word& resultName,
|
||||
bool& processed
|
||||
)
|
||||
bool Foam::functionObjects::mag::calc()
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> vfType;
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sfType;
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
|
||||
|
||||
if (mesh_.foundObject<vfType>(fieldName))
|
||||
if (foundField<VolFieldType>(fieldName_))
|
||||
{
|
||||
const vfType& vf = mesh_.lookupObject<vfType>(fieldName);
|
||||
|
||||
volScalarField& field =
|
||||
magField<volScalarField>(resultName_, vf.dimensions());
|
||||
|
||||
field = Foam::mag(vf);
|
||||
|
||||
processed = true;
|
||||
return store
|
||||
(
|
||||
resultName_,
|
||||
Foam::mag(lookupField<VolFieldType>(fieldName_))
|
||||
);
|
||||
}
|
||||
else if (mesh_.foundObject<sfType>(fieldName))
|
||||
else if (foundField<SurfaceFieldType>(fieldName_))
|
||||
{
|
||||
const sfType& sf = mesh_.lookupObject<sfType>(fieldName);
|
||||
|
||||
surfaceScalarField& field =
|
||||
magField<surfaceScalarField>(resultName_, sf.dimensions());
|
||||
|
||||
field = Foam::mag(sf);
|
||||
|
||||
processed = true;
|
||||
return store
|
||||
(
|
||||
resultName_,
|
||||
Foam::mag(lookupField<SurfaceFieldType>(fieldName_))
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user