mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Updated fvm field sources - added correct() function and updated grad(p) source
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -45,7 +45,7 @@ namespace Foam
|
|||||||
{
|
{
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class IObasicSourceList Declaration
|
Class IObasicSourceList Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class IObasicSourceList
|
class IObasicSourceList
|
||||||
@ -80,6 +80,8 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
//- Read dictionary
|
//- Read dictionary
|
||||||
virtual bool read();
|
virtual bool read();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -26,6 +26,7 @@ License
|
|||||||
#include "basicSource.H"
|
#include "basicSource.H"
|
||||||
#include "fvMesh.H"
|
#include "fvMesh.H"
|
||||||
#include "fvMatrices.H"
|
#include "fvMatrices.H"
|
||||||
|
#include "volFields.H"
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
@ -161,7 +162,7 @@ void Foam::basicSource::setCellSet()
|
|||||||
}
|
}
|
||||||
case smMapRegion:
|
case smMapRegion:
|
||||||
{
|
{
|
||||||
if(active_)
|
if (active_)
|
||||||
{
|
{
|
||||||
Info<< indent << "- selecting inter region mapping" << endl;
|
Info<< indent << "- selecting inter region mapping" << endl;
|
||||||
const fvMesh& secondaryMesh =
|
const fvMesh& secondaryMesh =
|
||||||
@ -170,7 +171,6 @@ void Foam::basicSource::setCellSet()
|
|||||||
const boundBox secondaryBB = secondaryMesh.bounds();
|
const boundBox secondaryBB = secondaryMesh.bounds();
|
||||||
if (secondaryBB.overlaps(primaryBB))
|
if (secondaryBB.overlaps(primaryBB))
|
||||||
{
|
{
|
||||||
|
|
||||||
// Dummy patches
|
// Dummy patches
|
||||||
wordList cuttingPatches;
|
wordList cuttingPatches;
|
||||||
HashTable<word> patchMap;
|
HashTable<word> patchMap;
|
||||||
@ -218,7 +218,7 @@ void Foam::basicSource::setCellSet()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set volume information
|
// Set volume information
|
||||||
if(selectionMode_ != smMapRegion)
|
if (selectionMode_ != smMapRegion)
|
||||||
{
|
{
|
||||||
V_ = 0.0;
|
V_ = 0.0;
|
||||||
forAll(cells_, i)
|
forAll(cells_, i)
|
||||||
@ -303,6 +303,7 @@ Foam::autoPtr<Foam::basicSource> Foam::basicSource::New
|
|||||||
return autoPtr<basicSource>(cstrIter()(name, modelType, coeffs, mesh));
|
return autoPtr<basicSource>(cstrIter()(name, modelType, coeffs, mesh));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::basicSource::~basicSource()
|
Foam::basicSource::~basicSource()
|
||||||
{
|
{
|
||||||
if (!secondaryToPrimaryInterpPtr_.empty())
|
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)
|
void Foam::basicSource::addSup(fvMatrix<scalar>& eqn, const label fieldI)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -47,6 +47,7 @@ SourceFiles
|
|||||||
#define basicSource_H
|
#define basicSource_H
|
||||||
|
|
||||||
#include "fvMatricesFwd.H"
|
#include "fvMatricesFwd.H"
|
||||||
|
#include "volFieldsFwd.H"
|
||||||
#include "cellSet.H"
|
#include "cellSet.H"
|
||||||
#include "autoPtr.H"
|
#include "autoPtr.H"
|
||||||
#include "meshToMesh.H"
|
#include "meshToMesh.H"
|
||||||
@ -60,7 +61,6 @@ namespace Foam
|
|||||||
|
|
||||||
class fvMesh;
|
class fvMesh;
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class basicSource Declaration
|
Class basicSource Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -330,6 +330,24 @@ public:
|
|||||||
|
|
||||||
// Evaluation
|
// 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
|
// Add explicit and implicit contributions
|
||||||
|
|
||||||
//- Scalar
|
//- Scalar
|
||||||
|
|||||||
@ -135,4 +135,5 @@ inline const Foam::word Foam::basicSource::mapRegionName() const
|
|||||||
return mapRegionName_;
|
return mapRegionName_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -95,6 +95,11 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
|
//- Correct
|
||||||
|
template<class Type>
|
||||||
|
void correct(GeometricField<Type, fvPatchField, volMesh>& fld);
|
||||||
|
|
||||||
|
|
||||||
// Sources
|
// Sources
|
||||||
|
|
||||||
//- Return source for equation
|
//- Return source for equation
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -25,6 +25,39 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * 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>
|
template<class Type>
|
||||||
Foam::tmp<Foam::fvMatrix<Type> > Foam::basicSourceList::operator()
|
Foam::tmp<Foam::fvMatrix<Type> > Foam::basicSourceList::operator()
|
||||||
(
|
(
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
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 * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
|
Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
|
||||||
@ -123,7 +76,7 @@ Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
|
|||||||
const word& sourceName,
|
const word& sourceName,
|
||||||
const word& modelType,
|
const word& modelType,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
const fvMesh& mesh
|
const fvMesh& mesh
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
basicSource(sourceName, modelType, dict, mesh),
|
basicSource(sourceName, modelType, dict, mesh),
|
||||||
@ -133,6 +86,23 @@ Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
|
|||||||
flowDir_(Ubar_/mag(Ubar_))
|
flowDir_(Ubar_/mag(Ubar_))
|
||||||
{
|
{
|
||||||
coeffs_.lookup("fieldNames") >> fieldNames_;
|
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);
|
applied_.setSize(fieldNames_.size(), false);
|
||||||
|
|
||||||
// Read the initial pressure gradient from file if it exists
|
// Read the initial pressure gradient from file if it exists
|
||||||
@ -160,8 +130,6 @@ void Foam::pressureGradientExplicitSource::addSup
|
|||||||
const label fieldI
|
const label fieldI
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
update(eqn);
|
|
||||||
|
|
||||||
DimensionedField<vector, volMesh> Su
|
DimensionedField<vector, volMesh> Su
|
||||||
(
|
(
|
||||||
IOobject
|
IOobject
|
||||||
@ -178,7 +146,53 @@ void Foam::pressureGradientExplicitSource::addSup
|
|||||||
|
|
||||||
UIndirectList<vector>(Su, cells_) = flowDir_*gradP_.value();
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -118,7 +118,10 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
// Access
|
// Evaluate
|
||||||
|
|
||||||
|
//- Correct the pressure gradient
|
||||||
|
virtual void correct(volVectorField& U);
|
||||||
|
|
||||||
//- Add explicit contribution to equation
|
//- Add explicit contribution to equation
|
||||||
virtual void addSup(fvMatrix<vector>& eqn, const label fieldI);
|
virtual void addSup(fvMatrix<vector>& eqn, const label fieldI);
|
||||||
|
|||||||
Reference in New Issue
Block a user