ENH: Added new pressureTools function object

This commit is contained in:
andy
2012-09-24 15:06:45 +01:00
parent 013515dfdd
commit 3644f064af
6 changed files with 587 additions and 0 deletions

View File

@ -9,6 +9,9 @@ dsmcFields/dsmcFieldsFunctionObject.C
pressureCoefficient/pressureCoefficient.C
pressureCoefficient/pressureCoefficientFunctionObject.C
pressureTools/pressureTools.C
pressureTools/pressureToolsFunctionObject.C
staticPressure/staticPressure.C
staticPressure/staticPressureFunctionObject.C

View File

@ -0,0 +1,49 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 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/>.
Typedef
Foam::IOpressureTools
Description
Instance of the generic IOOutputFilter for pressureTools.
\*---------------------------------------------------------------------------*/
#ifndef IOpressureTools_H
#define IOpressureTools_H
#include "pressureTools.H"
#include "IOOutputFilter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOOutputFilter<pressureTools> IOpressureTools;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,245 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 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 "pressureTools.H"
#include "volFields.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::pressureTools, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::word Foam::pressureTools::pName() const
{
word fieldName = "p";
if (calcTotal_)
{
fieldName = "total(" + fieldName + ")";
}
else
{
fieldName = "static(" + fieldName + ")";
}
if (calcCoeff_)
{
fieldName = fieldName + "_coeff";
}
return fieldName;
}
Foam::dimensionedScalar Foam::pressureTools::rho
(
const volScalarField& p
) const
{
if (p.dimensions() == dimPressure)
{
return dimensionedScalar("1", dimless, 1.0);
}
else
{
return dimensionedScalar("rhoRef", dimDensity, rhoRef_);
}
}
Foam::dimensionedScalar Foam::pressureTools::pRef() const
{
dimensionedScalar value("pRef", dimPressure, 0.0);
if (calcTotal_)
{
value.value() += pRef_;
}
return pRef();
}
Foam::tmp<Foam::volScalarField> Foam::pressureTools::pDyn() const
{
const fvMesh& mesh = refCast<const fvMesh>(obr_);
tmp<volScalarField> tpDyn
(
new volScalarField
(
IOobject
(
"pDyn",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar("zero", dimPressure, 0.0)
)
);
if (calcTotal_)
{
const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);
tpDyn() == 0.5*magSqr(U);
}
return tpDyn;
}
Foam::tmp<Foam::volScalarField> Foam::pressureTools::convertToCoeff
(
const volScalarField& p
) const
{
tmp<volScalarField> tCoeff(p);
if (calcCoeff_)
{
tCoeff() /= pDyn();
}
return tCoeff;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pressureTools::pressureTools
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
)
:
name_(name),
obr_(obr),
active_(true),
calcTotal_(false),
calcCoeff_(false),
pName_("p"),
UName_("U"),
pRef_(0.0),
rhoRef_(1.0)
{
// Check if the available mesh is an fvMesh, otherwise deactivate
if (!isA<fvMesh>(obr_))
{
active_ = false;
WarningIn
(
"pressureTools::pressureTools"
"("
"const word&, "
"const objectRegistry&, "
"const dictionary&, "
"const bool"
")"
) << "No fvMesh available, deactivating." << nl
<< endl;
}
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::pressureTools::~pressureTools()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::pressureTools::read(const dictionary& dict)
{
if (active_)
{
dict.readIfPresent("pName", pName_);
dict.readIfPresent("UName", UName_);
const volScalarField& p = obr_.lookupObject<volScalarField>(pName_);
if (p.dimensions() != p.dimensions())
{
dict.lookup("rhoRef") >> rhoRef_;
}
dict.lookup("calcTotal") >> calcTotal_;
if (calcTotal_)
{
dict.lookup("pRef") >> pRef_;
}
dict.lookup("calcCoeff") >> calcCoeff_;
}
}
void Foam::pressureTools::execute()
{
// Do nothing - only valid on write
}
void Foam::pressureTools::end()
{
// Do nothing - only valid on write
}
void Foam::pressureTools::write()
{
if (active_)
{
const volScalarField& p = obr_.lookupObject<volScalarField>(pName_);
volScalarField pResult
(
IOobject
(
pName(),
obr_.time().timeName(),
obr_,
IOobject::NO_READ
),
convertToCoeff(rho(p)*(p + pDyn()) + pRef())
);
pResult.write();
}
}
// ************************************************************************* //

View File

@ -0,0 +1,194 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 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::pressureTools
Description
This function object includes tools to manipulate the pressure into
different forms. These currently include:
- static pressure
p_s = rho*p_k
- total pressure
p_T = pRef + p_s + 0.5 rho |U|^2
- static pressure coefficient
Cp_s = p_s / (0.5 rho |U|^2)
- total pressure coefficient
Cp_T = p_T / (0.5 rho |U|^2)
The function object will operate on both kinematic (p_k) and static
pressure (p_s) fields, and the result is written as a volScalarField.
SourceFiles
pressureTools.C
IOpressureTools.H
\*---------------------------------------------------------------------------*/
#ifndef pressureTools_H
#define pressureTools_H
#include "volFieldsFwd.H"
#include "pointFieldFwd.H"
#include "dimensionedScalar.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class objectRegistry;
class dictionary;
class mapPolyMesh;
/*---------------------------------------------------------------------------*\
Class pressureTools Declaration
\*---------------------------------------------------------------------------*/
class pressureTools
{
// Private data
//- Name of this set of pressureTools objects
word name_;
//- Reference to the database
const objectRegistry& obr_;
//- On/off switch
bool active_;
//- Flag to calculate total pressure
bool calcTotal_;
//- Flag to calculate pressure coefficient
bool calcCoeff_;
//- Name of pressure field, default is "p"
word pName_;
//- Name of velocity field, default is "U"
word UName_;
//- Reference pressure level (used for total pressure)
scalar pRef_;
//- Reference density value
scalar rhoRef_;
// Private Member Functions
//- Return the name of the derived pressure field
word pName() const;
//- Return the density scaling if supplied with kinematic pressure
dimensionedScalar rho(const volScalarField& p) const;
//- Return the reference pressure
dimensionedScalar pRef() const;
//- Calculate and return the (kinematic) dynamic pressure
tmp<volScalarField> pDyn() const;
//- Convert to coeff data by applying the pDyn scaling
tmp<volScalarField> convertToCoeff(const volScalarField& p) const;
//- Disallow default bitwise copy construct
pressureTools(const pressureTools&);
//- Disallow default bitwise assignment
void operator=(const pressureTools&);
public:
//- Runtime type information
TypeName("pressureTools");
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
pressureTools
(
const word& name,
const objectRegistry&,
const dictionary&,
const bool loadFromFiles = false
);
//- Destructor
virtual ~pressureTools();
// Member Functions
//- Return name of the set of pressureTools
virtual const word& name() const
{
return name_;
}
//- Read the pressureTools data
virtual void read(const dictionary&);
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Calculate the pressureTools and write
virtual void write();
//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh&)
{}
//- Update for changes of mesh
virtual void movePoints(const pointField&)
{}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 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 "pressureToolsFunctionObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineNamedTemplateTypeNameAndDebug(pressureToolsFunctionObject, 0);
addToRunTimeSelectionTable
(
functionObject,
pressureToolsFunctionObject,
dictionary
);
}
// ************************************************************************* //

View File

@ -0,0 +1,54 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 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/>.
Typedef
Foam::pressureToolsFunctionObject
Description
FunctionObject wrapper around pressureTools to allow it to be created via
the functions entry within controlDict.
SourceFiles
pressureToolsFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef pressureToolsFunctionObject_H
#define pressureToolsFunctionObject_H
#include "pressureTools.H"
#include "OutputFilterFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef OutputFilterFunctionObject<pressureTools>
pressureToolsFunctionObject;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //