diff --git a/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/UEqns.H b/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/UEqns.H index ce5c622f9a..ae22926c4e 100644 --- a/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/UEqns.H +++ b/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/UEqns.H @@ -1,3 +1,7 @@ +mrfZones.correctBoundaryVelocity(U1); +mrfZones.correctBoundaryVelocity(U2); +mrfZones.correctBoundaryVelocity(U); + fvVectorMatrix U1Eqn(U1, U1.dimensions()*dimVol/dimTime); fvVectorMatrix U2Eqn(U2, U2.dimensions()*dimVol/dimTime); diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/UEqns.H b/applications/solvers/multiphase/multiphaseEulerFoam/UEqns.H index a63ff3c85a..7584d84f27 100644 --- a/applications/solvers/multiphase/multiphaseEulerFoam/UEqns.H +++ b/applications/solvers/multiphase/multiphaseEulerFoam/UEqns.H @@ -1,3 +1,5 @@ +#include "mrfZonesCorrectBCs.H" + PtrList UEqns(fluid.phases().size()); autoPtr dragCoeffs(fluid.dragCoeffs()); diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/mrfZonesCorrectBCs.H b/applications/solvers/multiphase/multiphaseEulerFoam/mrfZonesCorrectBCs.H new file mode 100644 index 0000000000..d670aa4a41 --- /dev/null +++ b/applications/solvers/multiphase/multiphaseEulerFoam/mrfZonesCorrectBCs.H @@ -0,0 +1,6 @@ + forAllIter(PtrDictionary, fluid.phases(), iter) + { + mrfZones.correctBoundaryVelocity(iter().U()); + } + + mrfZones.correctBoundaryVelocity(U); diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 66729d197c..1ce1f78949 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -340,8 +340,7 @@ $(gradSchemes)/gaussGrad/gaussGrads.C $(gradSchemes)/leastSquaresGrad/leastSquaresVectors.C $(gradSchemes)/leastSquaresGrad/leastSquaresGrads.C -$(gradSchemes)/extendedLeastSquaresGrad/extendedLeastSquaresVectors.C -$(gradSchemes)/extendedLeastSquaresGrad/extendedLeastSquaresGrads.C +$(gradSchemes)/LeastSquaresGrad/LeastSquaresGrads.C $(gradSchemes)/fourthGrad/fourthGrads.C limitedGradSchemes = $(gradSchemes)/limitedGradSchemes diff --git a/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet/turbulentInletFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet/turbulentInletFvPatchField.H index 3917d167bd..f99a71cc35 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet/turbulentInletFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet/turbulentInletFvPatchField.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-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -39,7 +39,7 @@ Description \vartable x_p | patch values - x_{ref} | refernce patch values + x_{ref} | reference patch values n | time level \alpha | fraction of new random component added to previous time value C_{RMS} | RMS coefficient diff --git a/src/finiteVolume/finiteVolume/gradSchemes/extendedLeastSquaresGrad/extendedLeastSquaresGrad.C b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.C similarity index 50% rename from src/finiteVolume/finiteVolume/gradSchemes/extendedLeastSquaresGrad/extendedLeastSquaresGrad.C rename to src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.C index 91e2cc50f5..03a6f1c84f 100644 --- a/src/finiteVolume/finiteVolume/gradSchemes/extendedLeastSquaresGrad/extendedLeastSquaresGrad.C +++ b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.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) 2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,18 +23,16 @@ License \*---------------------------------------------------------------------------*/ -#include "extendedLeastSquaresGrad.H" -#include "extendedLeastSquaresVectors.H" +#include "LeastSquaresGrad.H" +#include "LeastSquaresVectors.H" #include "gaussGrad.H" #include "fvMesh.H" #include "volMesh.H" -#include "surfaceMesh.H" -#include "GeometricField.H" #include "zeroGradientFvPatchField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -template +template Foam::tmp < Foam::GeometricField @@ -44,15 +42,21 @@ Foam::tmp Foam::volMesh > > -Foam::fv::extendedLeastSquaresGrad::calcGrad +Foam::fv::LeastSquaresGrad::calcGrad ( - const GeometricField& vsf, + const GeometricField& vtf, const word& name ) const { typedef typename outerProduct::type GradType; - const fvMesh& mesh = vsf.mesh(); + const fvMesh& mesh = vtf.mesh(); + + // Get reference to least square vectors + const LeastSquaresVectors& lsv = LeastSquaresVectors::New + ( + mesh + ); tmp > tlsGrad ( @@ -61,7 +65,7 @@ Foam::fv::extendedLeastSquaresGrad::calcGrad IOobject ( name, - vsf.instance(), + vtf.instance(), mesh, IOobject::NO_READ, IOobject::NO_WRITE @@ -70,87 +74,64 @@ Foam::fv::extendedLeastSquaresGrad::calcGrad dimensioned ( "zero", - vsf.dimensions()/dimLength, + vtf.dimensions()/dimLength, pTraits::zero ), zeroGradientFvPatchField::typeName ) ); GeometricField& lsGrad = tlsGrad(); + Field& lsGradIf = lsGrad; - // Get reference to least square vectors - const extendedLeastSquaresVectors& lsv = extendedLeastSquaresVectors::New - ( - mesh, - minDet_ - ); + const extendedCentredCellToCellStencil& stencil = lsv.stencil(); + const List >& stencilAddr = stencil.stencil(); + const List >& lsvs = lsv.vectors(); - const surfaceVectorField& ownLs = lsv.pVectors(); - const surfaceVectorField& neiLs = lsv.nVectors(); + // Construct flat version of vtf + // including all values referred to by the stencil + List flatVtf(stencil.map().constructSize(), pTraits::zero); - const labelUList& owner = mesh.owner(); - const labelUList& neighbour = mesh.neighbour(); - - forAll(owner, facei) + // Insert internal values + forAll(vtf, celli) { - label own = owner[facei]; - label nei = neighbour[facei]; - - Type deltaVsf = vsf[nei] - vsf[own]; - - lsGrad[own] += ownLs[facei]*deltaVsf; - lsGrad[nei] -= neiLs[facei]*deltaVsf; + flatVtf[celli] = vtf[celli]; } - // Boundary faces - forAll(vsf.boundaryField(), patchi) + // Insert boundary values + forAll(vtf.boundaryField(), patchi) { - const fvsPatchVectorField& patchOwnLs = ownLs.boundaryField()[patchi]; + const fvPatchField& ptf = vtf.boundaryField()[patchi]; - const labelUList& faceCells = - lsGrad.boundaryField()[patchi].patch().faceCells(); + label nCompact = + ptf.patch().start() + - mesh.nInternalFaces() + + mesh.nCells(); - if (vsf.boundaryField()[patchi].coupled()) + forAll(ptf, i) { - const Field neiVsf - ( - vsf.boundaryField()[patchi].patchNeighbourField() - ); - - forAll(neiVsf, patchFaceI) - { - lsGrad[faceCells[patchFaceI]] += - patchOwnLs[patchFaceI] - *(neiVsf[patchFaceI] - vsf[faceCells[patchFaceI]]); - } - } - else - { - const fvPatchField& patchVsf = vsf.boundaryField()[patchi]; - - forAll(patchVsf, patchFaceI) - { - lsGrad[faceCells[patchFaceI]] += - patchOwnLs[patchFaceI] - *(patchVsf[patchFaceI] - vsf[faceCells[patchFaceI]]); - } + flatVtf[nCompact++] = ptf[i]; } } + // Do all swapping to complete flatVtf + stencil.map().distribute(flatVtf); - const List& additionalCells = lsv.additionalCells(); - const vectorField& additionalVectors = lsv.additionalVectors(); - - forAll(additionalCells, i) + // Accumulate the cell-centred gradient from the + // weighted least-squares vectors and the flattened field values + forAll(stencilAddr, celli) { - lsGrad[additionalCells[i][0]] += - additionalVectors[i] - *(vsf[additionalCells[i][1]] - vsf[additionalCells[i][0]]); + const labelList& compactCells = stencilAddr[celli]; + const List& lsvc = lsvs[celli]; + + forAll(compactCells, i) + { + lsGradIf[celli] += lsvc[i]*flatVtf[compactCells[i]]; + } } - + // Correct the boundary conditions lsGrad.correctBoundaryConditions(); - gaussGrad::correctBoundaryConditions(vsf, lsGrad); + gaussGrad::correctBoundaryConditions(vtf, lsGrad); return tlsGrad; } diff --git a/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.H b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.H new file mode 100644 index 0000000000..edc9418465 --- /dev/null +++ b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.H @@ -0,0 +1,174 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 . + +Class + Foam::fv::LeastSquaresGrad + +Description + Gradient calculated using weighted least-squares on an arbitrary stencil. + The stencil type is provided via a template argument and any cell-based + stencil is supported: + + \table + Stencil | Connections | Scheme name + centredCFCCellToCellStencil | cell-face-cell | Not Instantiated + centredCPCCellToCellStencil | cell-point-cell | pointCellsLeastSquares + centredCECCellToCellStencil | cell-edge-cell | edgeCellsLeastSquares + \endtable + + The first of these is not instantiated by default as the standard + leastSquaresGrad is equivalent and more efficient. + + \heading Usage + + Example of the gradient specification: + \verbatim + gradSchemes + { + default pointCellsLeastSquares; + } + \endverbatim + +See Also + Foam::fv::LeastSquaresVectors + Foam::fv::leastSquaresGrad + +SourceFiles + LeastSquaresGrad.C + LeastSquaresVectors.H + LeastSquaresVectors.C + +\*---------------------------------------------------------------------------*/ + +#ifndef LeastSquaresGrad_H +#define LeastSquaresGrad_H + +#include "gradScheme.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fv +{ + +/*---------------------------------------------------------------------------*\ + Class LeastSquaresGrad Declaration +\*---------------------------------------------------------------------------*/ + +template +class LeastSquaresGrad +: + public fv::gradScheme +{ + // Private Data + + //- Minimum determinant criterion to choose extra cells + scalar minDet_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + LeastSquaresGrad(const LeastSquaresGrad&); + + //- Disallow default bitwise assignment + void operator=(const LeastSquaresGrad&); + + +public: + + //- Runtime type information + TypeName("LeastSquares"); + + + // Constructors + + //- Construct from Istream + LeastSquaresGrad(const fvMesh& mesh, Istream& schemeData) + : + gradScheme(mesh) + {} + + + // Member Functions + + //- Return the gradient of the given field to the gradScheme::grad + // for optional caching + virtual tmp + < + GeometricField + ::type, fvPatchField, volMesh> + > calcGrad + ( + const GeometricField& vsf, + const word& name + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Add the patch constructor functions to the hash tables + +#define makeLeastSquaresGradTypeScheme(SS, STENCIL, TYPE) \ + \ +typedef LeastSquaresGrad LeastSquaresGrad##TYPE##STENCIL##_; \ +defineTemplateTypeNameAndDebugWithName \ + (LeastSquaresGrad##TYPE##STENCIL##_, #SS, 0); \ + \ +gradScheme::addIstreamConstructorToTable \ + > \ + add##SS##STENCIL##TYPE##IstreamConstructorToTable_; + +#define makeLeastSquaresGradScheme(SS, STENCIL) \ + \ +typedef LeastSquaresVectors LeastSquaresVectors##STENCIL##_; \ +defineTemplateTypeNameAndDebugWithName \ + (LeastSquaresVectors##STENCIL##_, #SS, 0); \ + \ +makeLeastSquaresGradTypeScheme(SS,STENCIL,scalar) \ +makeLeastSquaresGradTypeScheme(SS,STENCIL,vector) + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "LeastSquaresGrad.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrads.C b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrads.C new file mode 100644 index 0000000000..021e2da28e --- /dev/null +++ b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrads.C @@ -0,0 +1,57 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 . + +\*---------------------------------------------------------------------------*/ + +#include "LeastSquaresGrad.H" +//#include "centredCFCCellToCellStencilObject.H" +#include "centredCPCCellToCellStencilObject.H" +#include "centredCECCellToCellStencilObject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace fv +{ + // makeLeastSquaresGradScheme + // ( + // faceCellsLeastSquares, + // centredCFCCellToCellStencilObject + // ) + + makeLeastSquaresGradScheme + ( + pointCellsLeastSquares, + centredCPCCellToCellStencilObject + ) + + makeLeastSquaresGradScheme + ( + edgeCellsLeastSquares, + centredCECCellToCellStencilObject + ) +} +} + +// ************************************************************************* // diff --git a/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresVectors.C b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresVectors.C new file mode 100644 index 0000000000..c575b23c28 --- /dev/null +++ b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresVectors.C @@ -0,0 +1,118 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 . + +\*---------------------------------------------------------------------------*/ + +#include "LeastSquaresVectors.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::fv::LeastSquaresVectors::LeastSquaresVectors +( + const fvMesh& mesh +) +: + MeshObject(mesh), + vectors_(mesh.nCells()) +{ + calcLeastSquaresVectors(); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::fv::LeastSquaresVectors::~LeastSquaresVectors() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::fv::LeastSquaresVectors::calcLeastSquaresVectors() +{ + if (debug) + { + Info<< "LeastSquaresVectors::calcLeastSquaresVectors() :" + << "Calculating least square gradient vectors" + << endl; + } + + const fvMesh& mesh = this->mesh_; + const extendedCentredCellToCellStencil& stencil = this->stencil(); + + stencil.collectData(mesh.C(), vectors_); + + // Create the base form of the dd-tensor + // including components for the "empty" directions + symmTensor dd0(sqr((Vector