Commit 2c6f89ef authored by andy's avatar andy
Browse files

ENH: pressureGradientSource - cache 1/A instead of using lookup

parent aab426ec
......@@ -83,7 +83,8 @@ Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
Ubar_(coeffs_.lookup("Ubar")),
gradPini_(coeffs_.lookup("gradPini")),
gradP_(gradPini_),
flowDir_(Ubar_/mag(Ubar_))
flowDir_(Ubar_/mag(Ubar_)),
invAPtr_(NULL)
{
coeffs_.lookup("fieldNames") >> fieldNames_;
......@@ -124,36 +125,9 @@ Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::pressureGradientExplicitSource::addSup
(
fvMatrix<vector>& eqn,
const label fieldI
)
{
DimensionedField<vector, volMesh> Su
(
IOobject
(
name_ + fieldNames_[fieldI] + "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;
}
void Foam::pressureGradientExplicitSource::correct(volVectorField& U)
{
const volScalarField& rAU =
mesh_.lookupObject<volScalarField>("(1|A(" + U.name() + "))");
const scalarField& rAU = invAPtr_().internalField();
// Integrate flow variables over cell set
scalar magUbarAve = 0.0;
......@@ -196,4 +170,61 @@ void Foam::pressureGradientExplicitSource::correct(volVectorField& U)
}
void Foam::pressureGradientExplicitSource::addSup
(
fvMatrix<vector>& eqn,
const label fieldI
)
{
DimensionedField<vector, volMesh> Su
(
IOobject
(
name_ + fieldNames_[fieldI] + "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;
}
void Foam::pressureGradientExplicitSource::setValue
(
fvMatrix<vector>& eqn,
const label
)
{
if (invAPtr_.empty())
{
invAPtr_.reset
(
new volScalarField
(
IOobject
(
name_ + "::invA",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
1.0/eqn.A()
)
);
}
else
{
invAPtr_() = 1.0/eqn.A();
}
}
// ************************************************************************* //
......@@ -33,7 +33,7 @@ Description
pressureGradientExplicitSourceCoeffs
{
UName U; // name of velocity field
fieldNames (U); // name of velocity field
Ubar (10.0 0 0); // desired average velocity
gradPini gradPini [0 2 -2 0 0] 0; // initial pressure gradient
flowDir (1 0 0); // flow direction
......@@ -82,6 +82,9 @@ class pressureGradientExplicitSource
//- Flow direction
vector flowDir_;
//- Matrix 1/A coefficients field pointer
autoPtr<volScalarField> invAPtr_;
// Private Member Functions
......@@ -126,6 +129,13 @@ public:
//- Add explicit contribution to equation
virtual void addSup(fvMatrix<vector>& eqn, const label fieldI);
//- Set 1/A coefficient
virtual void setValue
(
fvMatrix<vector>& eqn,
const label fieldI
);
// I-O
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment