ENH: Updated fvm field sources - added correct() function and updated grad(p) source

This commit is contained in:
andy
2012-01-26 16:06:29 +00:00
parent 6c60ab90ef
commit f2e65c6adc
8 changed files with 171 additions and 64 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -45,7 +45,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class IObasicSourceList Declaration
Class IObasicSourceList Declaration
\*---------------------------------------------------------------------------*/
class IObasicSourceList
@ -80,6 +80,8 @@ public:
{}
// Member Functions
//- Read dictionary
virtual bool read();
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -26,6 +26,7 @@ License
#include "basicSource.H"
#include "fvMesh.H"
#include "fvMatrices.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -161,7 +162,7 @@ void Foam::basicSource::setCellSet()
}
case smMapRegion:
{
if(active_)
if (active_)
{
Info<< indent << "- selecting inter region mapping" << endl;
const fvMesh& secondaryMesh =
@ -170,7 +171,6 @@ void Foam::basicSource::setCellSet()
const boundBox secondaryBB = secondaryMesh.bounds();
if (secondaryBB.overlaps(primaryBB))
{
// Dummy patches
wordList cuttingPatches;
HashTable<word> patchMap;
@ -218,7 +218,7 @@ void Foam::basicSource::setCellSet()
}
// Set volume information
if(selectionMode_ != smMapRegion)
if (selectionMode_ != smMapRegion)
{
V_ = 0.0;
forAll(cells_, i)
@ -303,6 +303,7 @@ Foam::autoPtr<Foam::basicSource> Foam::basicSource::New
return autoPtr<basicSource>(cstrIter()(name, modelType, coeffs, mesh));
}
Foam::basicSource::~basicSource()
{
if (!secondaryToPrimaryInterpPtr_.empty())
@ -364,6 +365,36 @@ void Foam::basicSource::checkApplied() const
}
void Foam::basicSource::correct(volScalarField& fld)
{
// do nothing
}
void Foam::basicSource::correct(volVectorField& fld)
{
// do nothing
}
void Foam::basicSource::correct(volSphericalTensorField& fld)
{
// do nothing
}
void Foam::basicSource::correct(volSymmTensorField& fld)
{
// do nothing
}
void Foam::basicSource::correct(volTensorField& fld)
{
// do nothing
}
void Foam::basicSource::addSup(fvMatrix<scalar>& eqn, const label fieldI)
{
// do nothing

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -47,6 +47,7 @@ SourceFiles
#define basicSource_H
#include "fvMatricesFwd.H"
#include "volFieldsFwd.H"
#include "cellSet.H"
#include "autoPtr.H"
#include "meshToMesh.H"
@ -60,7 +61,6 @@ namespace Foam
class fvMesh;
/*---------------------------------------------------------------------------*\
Class basicSource Declaration
\*---------------------------------------------------------------------------*/
@ -330,6 +330,24 @@ public:
// Evaluation
// Correct
//- Scalar
virtual void correct(volScalarField& fld);
//- Vector
virtual void correct(volVectorField& fld);
//- Spherical tensor
virtual void correct(volSphericalTensorField& fld);
//- Symmetric tensor
virtual void correct(volSymmTensorField& fld);
//- Tensor
virtual void correct(volTensorField& fld);
// Add explicit and implicit contributions
//- Scalar

View File

@ -135,4 +135,5 @@ inline const Foam::word Foam::basicSource::mapRegionName() const
return mapRegionName_;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -95,6 +95,11 @@ public:
// Member Functions
//- Correct
template<class Type>
void correct(GeometricField<Type, fvPatchField, volMesh>& fld);
// Sources
//- Return source for equation

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,6 +25,39 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::basicSourceList::correct
(
GeometricField<Type, fvPatchField, volMesh>& fld
)
{
const word& fieldName = fld.name();
forAll(*this, i)
{
basicSource& source = this->operator[](i);
label fieldI = source.applyToField(fieldName);
if (fieldI != -1)
{
source.setApplied(fieldI);
if (source.isActive())
{
if (debug)
{
Info<< "Correcting source " << source.name()
<< " for field " << fieldName << endl;
}
source.correct(fld);
}
}
}
}
template<class Type>
Foam::tmp<Foam::fvMatrix<Type> > Foam::basicSourceList::operator()
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -69,53 +69,6 @@ void Foam::pressureGradientExplicitSource::writeGradP() const
}
void Foam::pressureGradientExplicitSource::update(fvMatrix<vector>& eqn)
{
volVectorField& U = const_cast<volVectorField&>(eqn.psi());
const volScalarField& rAU =
mesh_.lookupObject<volScalarField>("(1|A(" + U.name() + "))");
// 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::pressureGradientExplicitSource::pressureGradientExplicitSource
@ -123,7 +76,7 @@ Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
const word& sourceName,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
const fvMesh& mesh
)
:
basicSource(sourceName, modelType, dict, mesh),
@ -133,6 +86,23 @@ Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
flowDir_(Ubar_/mag(Ubar_))
{
coeffs_.lookup("fieldNames") >> fieldNames_;
if (fieldNames_.size() != 1)
{
FatalErrorIn
(
"Foam::pressureGradientExplicitSource::"
"pressureGradientExplicitSource"
"("
"onst word&, "
"const word&, "
"const dictionary&, "
"const fvMesh&"
")"
) << "Source can only be applied to a single field. Current "
<< "settings are:" << fieldNames_ << exit(FatalError);
}
applied_.setSize(fieldNames_.size(), false);
// Read the initial pressure gradient from file if it exists
@ -160,8 +130,6 @@ void Foam::pressureGradientExplicitSource::addSup
const label fieldI
)
{
update(eqn);
DimensionedField<vector, volMesh> Su
(
IOobject
@ -178,7 +146,53 @@ void Foam::pressureGradientExplicitSource::addSup
UIndirectList<vector>(Su, cells_) = flowDir_*gradP_.value();
eqn -= Su;
eqn += Su;
}
void Foam::pressureGradientExplicitSource::correct(volVectorField& U)
{
const volScalarField& rAU =
mesh_.lookupObject<volScalarField>("(1|A(" + U.name() + "))");
// 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>());
reduce(rAUave, 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<< "Pressure gradient source: uncorrected Ubar = " << magUbarAve
<< ", pressure gradient = " << gradP_.value() << endl;
writeGradP();
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -118,7 +118,10 @@ public:
// Member Functions
// Access
// Evaluate
//- Correct the pressure gradient
virtual void correct(volVectorField& U);
//- Add explicit contribution to equation
virtual void addSup(fvMatrix<vector>& eqn, const label fieldI);