diff --git a/src/fieldSources/basicSource/basicSource/IObasicSourceList.H b/src/fieldSources/basicSource/basicSource/IObasicSourceList.H index 9b915899fb059a8519e94286192cf973d08578cb..69070b18db33a865361fa022a2fb4bf57a94b58e 100644 --- a/src/fieldSources/basicSource/basicSource/IObasicSourceList.H +++ b/src/fieldSources/basicSource/basicSource/IObasicSourceList.H @@ -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(); }; diff --git a/src/fieldSources/basicSource/basicSource/basicSource.C b/src/fieldSources/basicSource/basicSource/basicSource.C index 40f283a78a06f70daac4619bb4361369793900bd..355073b33a2a190399d585d66684596d6096cbec 100644 --- a/src/fieldSources/basicSource/basicSource/basicSource.C +++ b/src/fieldSources/basicSource/basicSource/basicSource.C @@ -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 diff --git a/src/fieldSources/basicSource/basicSource/basicSource.H b/src/fieldSources/basicSource/basicSource/basicSource.H index 1bff3121115e99a8e98eb999b5e3530b9b38ef8c..ca105f90b1883bf444bc9588556e123d3d306101 100644 --- a/src/fieldSources/basicSource/basicSource/basicSource.H +++ b/src/fieldSources/basicSource/basicSource/basicSource.H @@ -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 diff --git a/src/fieldSources/basicSource/basicSource/basicSourceI.H b/src/fieldSources/basicSource/basicSource/basicSourceI.H index 84444144f3071540bd9044cea1c5c86f74b3d2c7..6ffc096defc8473514f2f5f9cf3a48a237ebdb37 100644 --- a/src/fieldSources/basicSource/basicSource/basicSourceI.H +++ b/src/fieldSources/basicSource/basicSource/basicSourceI.H @@ -135,4 +135,5 @@ inline const Foam::word Foam::basicSource::mapRegionName() const return mapRegionName_; } + // ************************************************************************* // diff --git a/src/fieldSources/basicSource/basicSource/basicSourceList.H b/src/fieldSources/basicSource/basicSource/basicSourceList.H index 5e5b5fda141fae6b082dd5e0cff967faf1fbb35b..7d77de55d12b284cf7fde37abbed53b0f8a9fbd3 100644 --- a/src/fieldSources/basicSource/basicSource/basicSourceList.H +++ b/src/fieldSources/basicSource/basicSource/basicSourceList.H @@ -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 diff --git a/src/fieldSources/basicSource/basicSource/basicSourceListTemplates.C b/src/fieldSources/basicSource/basicSource/basicSourceListTemplates.C index aafa91d0983a83a4f3b7cac66847629f2b1e916f..7c83f7f5224906b5bcca627ec70cf3360095689c 100644 --- a/src/fieldSources/basicSource/basicSource/basicSourceListTemplates.C +++ b/src/fieldSources/basicSource/basicSource/basicSourceListTemplates.C @@ -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() ( diff --git a/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.C b/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.C index e3ff7ca50e6c28b25745108e428f86fadc5430d6..c13720b831923e6f251b0885d24948d76b9757fa 100644 --- a/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.C +++ b/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.C @@ -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(); } diff --git a/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.H b/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.H index 287c1701f3f8cdb85ebd3dfd28984ed2edf9ddda..bf760254afb888a6a80fc8039dad9fc1b028f7ff 100644 --- a/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.H +++ b/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.H @@ -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);