ENH: Aligned finite volume sources - now all derived from basicSource
This commit is contained in:
@ -0,0 +1,198 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 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 "pressureGradientExplicitSource.H"
|
||||
#include "volFields.H"
|
||||
#include "IFstream.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(pressureGradientExplicitSourceNew, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
basicSource,
|
||||
pressureGradientExplicitSourceNew,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::pressureGradientExplicitSourceNew::writeGradP() const
|
||||
{
|
||||
// Only write on output time
|
||||
if (mesh_.time().outputTime())
|
||||
{
|
||||
IOdictionary propsDict
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
name_ + "Properties",
|
||||
mesh_.time().timeName(),
|
||||
"uniform",
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
)
|
||||
);
|
||||
propsDict.add("gradient", gradP_);
|
||||
propsDict.regIOobject::write();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::pressureGradientExplicitSourceNew::update()
|
||||
{
|
||||
volVectorField& U = const_cast<volVectorField&>
|
||||
(
|
||||
mesh_.lookupObject<volVectorField>(UName_)
|
||||
);
|
||||
|
||||
const volScalarField& rAU =
|
||||
mesh_.lookupObject<volScalarField>("(1|A(" + UName_ + "))");
|
||||
|
||||
// Integrate flow variables over cell set
|
||||
scalar magUbarAve = 0.0;
|
||||
scalar rAUave = 0.0;
|
||||
const scalarField& cv = mesh_.V();
|
||||
forAll(cells_, i)
|
||||
{
|
||||
label cellI = cells_[i];
|
||||
scalar volCell = cv[cellI];
|
||||
magUbarAve += (flowDir_ & U[cellI])*volCell;
|
||||
rAUave += rAU[cellI]*volCell;
|
||||
}
|
||||
|
||||
// Collect across all processors
|
||||
reduce(magUbarAve, sumOp<scalar>());
|
||||
|
||||
// Volume averages
|
||||
magUbarAve /= V_;
|
||||
rAUave /= V_;
|
||||
|
||||
// Calculate the pressure gradient increment needed to adjust the average
|
||||
// flow-rate to the desired value
|
||||
scalar gradPplus = (mag(Ubar_) - magUbarAve)/rAUave;
|
||||
|
||||
// Apply correction to velocity field
|
||||
forAll(cells_, i)
|
||||
{
|
||||
label cellI = cells_[i];
|
||||
U[cellI] += flowDir_*rAU[cellI]*gradPplus;
|
||||
}
|
||||
|
||||
// Update pressure gradient
|
||||
gradP_.value() += gradPplus;
|
||||
|
||||
Info<< "Uncorrected Ubar = " << magUbarAve << tab
|
||||
<< "Pressure gradient = " << gradP_.value() << endl;
|
||||
|
||||
writeGradP();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pressureGradientExplicitSourceNew::pressureGradientExplicitSourceNew
|
||||
(
|
||||
const word& sourceName,
|
||||
const word& modelType,
|
||||
const dictionary& dict,
|
||||
const fvMesh& mesh
|
||||
)
|
||||
:
|
||||
basicSource(sourceName, modelType, dict, mesh),
|
||||
UName_(coeffs_.lookupOrDefault<word>("UName", "U")),
|
||||
Ubar_(coeffs_.lookup("Ubar")),
|
||||
gradPini_(coeffs_.lookup("gradPini")),
|
||||
gradP_(gradPini_),
|
||||
flowDir_(Ubar_/mag(Ubar_))
|
||||
{
|
||||
// Read the initial pressure gradient from file if it exists
|
||||
IFstream propsFile
|
||||
(
|
||||
mesh_.time().timeName()/"uniform"/(name_ + "Properties")
|
||||
);
|
||||
|
||||
if (propsFile.good())
|
||||
{
|
||||
Info<< " Reading pressure gradient from file" << endl;
|
||||
dictionary propsDict(dictionary::null, propsFile);
|
||||
propsDict.lookup("gradient") >> gradP_;
|
||||
}
|
||||
|
||||
Info<< " Initial pressure gradient = " << gradP_ << nl << endl;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::pressureGradientExplicitSourceNew::applyToField
|
||||
(
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
if (fieldName == UName_)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::pressureGradientExplicitSourceNew::addSup
|
||||
(
|
||||
fvMatrix<vector>& eqn,
|
||||
const label
|
||||
)
|
||||
{
|
||||
update();
|
||||
|
||||
DimensionedField<vector, volMesh> Su
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
name_ + UName_ + "Sup",
|
||||
mesh_.time().timeName(),
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedVector("zero", gradP_.dimensions(), vector::zero)
|
||||
);
|
||||
|
||||
UIndirectList<vector>(Su, cells_) = flowDir_*gradP_.value();
|
||||
|
||||
eqn -= Su;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,143 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 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::pressureGradientExplicitSourceNew
|
||||
|
||||
Description
|
||||
Creates a cell set pressure gradient source
|
||||
|
||||
Note: Currently only handles kinematic pressure
|
||||
|
||||
SourceFiles
|
||||
pressureGradientExplicitSourceNew.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef pressureGradientExplicitSourceNew_H
|
||||
#define pressureGradientExplicitSourceNew_H
|
||||
|
||||
#include "autoPtr.H"
|
||||
#include "topoSetSource.H"
|
||||
#include "cellSet.H"
|
||||
#include "fvMesh.H"
|
||||
#include "volFields.H"
|
||||
#include "basicSource.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class pressureGradientExplicitSourceNew Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class pressureGradientExplicitSourceNew
|
||||
:
|
||||
public basicSource
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Velocity field name
|
||||
word UName_;
|
||||
|
||||
//- Average velocity
|
||||
vector Ubar_;
|
||||
|
||||
//- Initial pressure gradient
|
||||
dimensionedScalar gradPini_;
|
||||
|
||||
//- Pressure gradient
|
||||
dimensionedScalar gradP_;
|
||||
|
||||
//- Flow direction
|
||||
vector flowDir_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Write the pressure gradient to file (for restarts etc)
|
||||
void writeGradP() const;
|
||||
|
||||
//- Correct driving force for a constant mass flow rate
|
||||
void update();
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
pressureGradientExplicitSourceNew(const pressureGradientExplicitSourceNew&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const pressureGradientExplicitSourceNew&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("pressureGradientExplicitSource");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from explicit source name and mesh
|
||||
pressureGradientExplicitSourceNew
|
||||
(
|
||||
const word& sourceName,
|
||||
const word& modelType,
|
||||
const dictionary& dict,
|
||||
const fvMesh& mesh
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Checks
|
||||
|
||||
//- Return index of field name if found in fieldNames list
|
||||
virtual label applyToField(const word& fieldName) const;
|
||||
|
||||
|
||||
// Access
|
||||
|
||||
//- Add explicit contribution to equation
|
||||
virtual void addSup(fvMatrix<vector>& eqn, const label fieldI);
|
||||
|
||||
|
||||
// I-O
|
||||
|
||||
//- Write the source properties
|
||||
virtual void writeData(Ostream&) const;
|
||||
|
||||
//- Read source dictionary
|
||||
virtual bool read(const dictionary& dict);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,56 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 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 "pressureGradientExplicitSource.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::pressureGradientExplicitSourceNew::writeData(Ostream& os) const
|
||||
{
|
||||
notImplemented
|
||||
(
|
||||
"void Foam::pressureGradientExplicitSourceNew::writeData"
|
||||
"("
|
||||
"Ostream&"
|
||||
") const"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::pressureGradientExplicitSourceNew::read(const dictionary& dict)
|
||||
{
|
||||
notImplemented
|
||||
(
|
||||
"bool Foam::pressureGradientExplicitSourceNew::read"
|
||||
"("
|
||||
"const dictionary&"
|
||||
") const"
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user