From e65d7201641e8c56fb4bccc022c1286b0aaa95ad Mon Sep 17 00:00:00 2001 From: Mattijs Janssens Date: Tue, 10 Dec 2024 09:31:53 +0000 Subject: [PATCH] ENH: fused: 'fused' variants of explicit discretisation --- src/Allwmake | 1 + src/fused/finiteVolume/Make/files | 7 + src/fused/finiteVolume/Make/options | 7 + .../finiteVolume/fusedGaussConvectionScheme.C | 265 ++++ .../finiteVolume/fusedGaussConvectionScheme.H | 162 ++ .../fusedGaussConvectionSchemes.C | 35 + src/fused/finiteVolume/fusedGaussDivScheme.C | 155 ++ src/fused/finiteVolume/fusedGaussDivScheme.H | 125 ++ src/fused/finiteVolume/fusedGaussDivSchemes.C | 35 + src/fused/finiteVolume/fusedGaussGrad.C | 263 +++ src/fused/finiteVolume/fusedGaussGrad.H | 177 +++ src/fused/finiteVolume/fusedGaussGrads.C | 35 + .../finiteVolume/fusedGaussLaplacianScheme.C | 581 +++++++ .../finiteVolume/fusedGaussLaplacianScheme.H | 264 ++++ .../finiteVolume/fusedGaussLaplacianSchemes.C | 866 ++++++++++ .../finiteVolume/fusedLeastSquaresGrad.C | 115 ++ .../finiteVolume/fusedLeastSquaresGrad.H | 129 ++ .../finiteVolume/fusedLeastSquaresGrads.C | 35 + src/fused/finiteVolume/fvcSurfaceOps.C | 1408 +++++++++++++++++ src/fused/finiteVolume/fvcSurfaceOps.H | 291 ++++ .../simpleFoam/pitzDaily_fused/0/U | 51 + .../simpleFoam/pitzDaily_fused/0/epsilon | 53 + .../simpleFoam/pitzDaily_fused/0/k | 53 + .../simpleFoam/pitzDaily_fused/0/nuTilda | 51 + .../simpleFoam/pitzDaily_fused/0/nut | 54 + .../simpleFoam/pitzDaily_fused/0/omega | 53 + .../simpleFoam/pitzDaily_fused/0/p | 51 + .../simpleFoam/pitzDaily_fused/Allrun | 22 + .../simpleFoam/pitzDaily_fused/README | 4 + .../constant/transportProperties | 22 + .../constant/turbulenceProperties | 31 + .../pitzDaily_fused/system/blockMeshDict | 153 ++ .../pitzDaily_fused/system/controlDict | 49 + .../pitzDaily_fused/system/decomposeParDict | 25 + .../pitzDaily_fused/system/fvSchemes | 63 + .../pitzDaily_fused/system/fvSchemes.template | 63 + .../pitzDaily_fused/system/fvSolution | 59 + 37 files changed, 5813 insertions(+) create mode 100644 src/fused/finiteVolume/Make/files create mode 100644 src/fused/finiteVolume/Make/options create mode 100644 src/fused/finiteVolume/fusedGaussConvectionScheme.C create mode 100644 src/fused/finiteVolume/fusedGaussConvectionScheme.H create mode 100644 src/fused/finiteVolume/fusedGaussConvectionSchemes.C create mode 100644 src/fused/finiteVolume/fusedGaussDivScheme.C create mode 100644 src/fused/finiteVolume/fusedGaussDivScheme.H create mode 100644 src/fused/finiteVolume/fusedGaussDivSchemes.C create mode 100644 src/fused/finiteVolume/fusedGaussGrad.C create mode 100644 src/fused/finiteVolume/fusedGaussGrad.H create mode 100644 src/fused/finiteVolume/fusedGaussGrads.C create mode 100644 src/fused/finiteVolume/fusedGaussLaplacianScheme.C create mode 100644 src/fused/finiteVolume/fusedGaussLaplacianScheme.H create mode 100644 src/fused/finiteVolume/fusedGaussLaplacianSchemes.C create mode 100644 src/fused/finiteVolume/fusedLeastSquaresGrad.C create mode 100644 src/fused/finiteVolume/fusedLeastSquaresGrad.H create mode 100644 src/fused/finiteVolume/fusedLeastSquaresGrads.C create mode 100644 src/fused/finiteVolume/fvcSurfaceOps.C create mode 100644 src/fused/finiteVolume/fvcSurfaceOps.H create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/0/U create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/0/epsilon create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/0/k create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/0/nuTilda create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/0/nut create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/0/omega create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/0/p create mode 100755 tutorials/incompressible/simpleFoam/pitzDaily_fused/Allrun create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/README create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/constant/transportProperties create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/constant/turbulenceProperties create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/system/blockMeshDict create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/system/controlDict create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/system/decomposeParDict create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/system/fvSchemes create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/system/fvSchemes.template create mode 100644 tutorials/incompressible/simpleFoam/pitzDaily_fused/system/fvSolution diff --git a/src/Allwmake b/src/Allwmake index 3d2e2ac222..3700e0b7e0 100755 --- a/src/Allwmake +++ b/src/Allwmake @@ -55,6 +55,7 @@ wmake $targetType meshTools wmake $targetType finiteArea wmake $targetType finiteVolume +wmake $targetType fused/finiteVolume wmake $targetType mesh/blockMesh wmake $targetType mesh/extrudeModel # Requires: blockMesh diff --git a/src/fused/finiteVolume/Make/files b/src/fused/finiteVolume/Make/files new file mode 100644 index 0000000000..fde0488e45 --- /dev/null +++ b/src/fused/finiteVolume/Make/files @@ -0,0 +1,7 @@ +fusedGaussLaplacianSchemes.C +fusedLeastSquaresGrads.C +fusedGaussDivSchemes.C +fusedGaussConvectionSchemes.C +fusedGaussGrads.C + +LIB = $(FOAM_LIBBIN)/libfusedFiniteVolume diff --git a/src/fused/finiteVolume/Make/options b/src/fused/finiteVolume/Make/options new file mode 100644 index 0000000000..f6fbc14a76 --- /dev/null +++ b/src/fused/finiteVolume/Make/options @@ -0,0 +1,7 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(LIB_SRC)/sampling/lnInclude + +LIB_LIBS = \ + -lfiniteVolume diff --git a/src/fused/finiteVolume/fusedGaussConvectionScheme.C b/src/fused/finiteVolume/fusedGaussConvectionScheme.C new file mode 100644 index 0000000000..fb73500875 --- /dev/null +++ b/src/fused/finiteVolume/fusedGaussConvectionScheme.C @@ -0,0 +1,265 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2024 M. Janssens +------------------------------------------------------------------------------- +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 "fvcSurfaceOps.H" +#include "fusedGaussConvectionScheme.H" +#include "fvcSurfaceIntegrate.H" +#include "fvMatrices.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fv +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +const surfaceInterpolationScheme& +fusedGaussConvectionScheme::interpScheme() const +{ + return tinterpScheme_(); +} + + +template +tmp> +fusedGaussConvectionScheme::interpolate +( + const surfaceScalarField&, + const GeometricField& vf +) const +{ + return tinterpScheme_().interpolate(vf); +} + + +template +tmp> +fusedGaussConvectionScheme::flux +( + const surfaceScalarField& faceFlux, + const GeometricField& vf +) const +{ + return faceFlux*interpolate(faceFlux, vf); +} + + +template +tmp> +fusedGaussConvectionScheme::fvmDiv +( + const surfaceScalarField& faceFlux, + const GeometricField& vf +) const +{ + DebugPout<< "fusedGaussConvectionScheme::fvmDiv on " << vf.name() + << " with flux " << faceFlux.name() << endl; + + tmp tweights = tinterpScheme_().weights(vf); + const surfaceScalarField& weights = tweights(); + + tmp> tfvm + ( + new fvMatrix + ( + vf, + faceFlux.dimensions()*vf.dimensions() + ) + ); + fvMatrix& fvm = tfvm.ref(); + + //fvm.lower() = -weights.primitiveField()*faceFlux.primitiveField(); + multiplySubtract + ( + fvm.lower(), + weights.primitiveField(), + faceFlux.primitiveField() + ); + + //fvm.upper() = fvm.lower() + faceFlux.primitiveField(); + add(fvm.upper(), fvm.lower(), faceFlux.primitiveField()); + + fvm.negSumDiag(); + + forAll(vf.boundaryField(), patchi) + { + const fvPatchField& psf = vf.boundaryField()[patchi]; + const fvsPatchScalarField& patchFlux = faceFlux.boundaryField()[patchi]; + const fvsPatchScalarField& pw = weights.boundaryField()[patchi]; + + auto& intCoeffs = fvm.internalCoeffs()[patchi]; + auto& bouCoeffs = fvm.boundaryCoeffs()[patchi]; + + //fvm.internalCoeffs()[patchi] = patchFlux*psf.valueInternalCoeffs(pw); + multiply(intCoeffs, patchFlux, psf.valueInternalCoeffs(pw)()); + + //fvm.boundaryCoeffs()[patchi] = -patchFlux*psf.valueBoundaryCoeffs(pw); + multiply(bouCoeffs, patchFlux, psf.valueBoundaryCoeffs(pw)()); + bouCoeffs.negate(); + } + + if (tinterpScheme_().corrected()) + { + fvm += fvc::surfaceIntegrate(faceFlux*tinterpScheme_().correction(vf)); + } + + return tfvm; +} + + +template +tmp> +fusedGaussConvectionScheme::fvcDiv +( + const surfaceScalarField& faceFlux, + const GeometricField& vf +) const +{ + DebugPout<< "fusedGaussConvectionScheme::fvcDiv on " << vf.name() + << " with flux " << faceFlux.name() << endl; + + typedef GeometricField FieldType; + + const fvMesh& mesh = vf.mesh(); + + tmp tConvection + ( + new FieldType + ( + IOobject + ( + "convection(" + faceFlux.name() + ',' + vf.name() + ')', + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensioned + ( + faceFlux.dimensions() + *vf.dimensions() + /dimVol, + Zero + ), + fvPatchFieldBase::extrapolatedCalculatedType() + ) + ); + + if (this->tinterpScheme_().corrected()) + { + const auto tfaceCorr(this->tinterpScheme_().correction(vf)); + auto& faceCorr = tfaceCorr(); + + const auto interpolator = [&] + ( + const vector& area, + const scalar lambda, + + const Type& ownVal, + const Type& neiVal, + + const scalar& faceVal, + const Type& correction + + ) -> Type + { + return faceVal*((lambda*(ownVal - neiVal) + neiVal) + correction); + }; + + fvc::surfaceSum + ( + // interpolation factors for volume field + this->tinterpScheme_().weights(vf), + + // volume field(s) + vf, + + // surface field(s) + faceFlux, + faceCorr, + + // operation + interpolator, + + tConvection.ref(), + false + ); + } + else + { + const auto interpolator = [&] + ( + const vector& area, + const scalar lambda, + const Type& ownVal, + const Type& neiVal, + + const scalar& faceVal + ) -> Type + { + return faceVal*(lambda*(ownVal - neiVal) + neiVal); + }; + + fvc::surfaceSum + ( + tinterpScheme_().weights(vf), + + vf, + + faceFlux, + + interpolator, + tConvection.ref(), + false + ); + } + + tConvection.ref().primitiveFieldRef() /= mesh.Vsc(); + + tConvection.ref().correctBoundaryConditions(); + + return tConvection; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedGaussConvectionScheme.H b/src/fused/finiteVolume/fusedGaussConvectionScheme.H new file mode 100644 index 0000000000..677a9df827 --- /dev/null +++ b/src/fused/finiteVolume/fusedGaussConvectionScheme.H @@ -0,0 +1,162 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2016 OpenFOAM Foundation +------------------------------------------------------------------------------- +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::fusedGaussConvectionScheme + +Group + grpFvConvectionSchemes + +Description + Basic second-order convection using face-gradients and Gauss' theorem. + +SourceFiles + fusedGaussConvectionScheme.C + +\*---------------------------------------------------------------------------*/ + +#ifndef fusedGaussConvectionScheme_H +#define fusedGaussConvectionScheme_H + +#include "convectionScheme.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fv +{ + +/*---------------------------------------------------------------------------*\ + Class fusedGaussConvectionScheme Declaration +\*---------------------------------------------------------------------------*/ + +template +class fusedGaussConvectionScheme +: + public fv::convectionScheme +{ + // Private data + + tmp> tinterpScheme_; + + + // Private Member Functions + + //- No copy construct + fusedGaussConvectionScheme(const fusedGaussConvectionScheme&) = delete; + + //- No copy assignment + void operator=(const fusedGaussConvectionScheme&) = delete; + + +public: + + //- Runtime type information + TypeName("fusedGauss"); + + + // Constructors + + //- Construct from flux and interpolation scheme + fusedGaussConvectionScheme + ( + const fvMesh& mesh, + const surfaceScalarField& faceFlux, + const tmp>& scheme + ) + : + convectionScheme(mesh, faceFlux), + tinterpScheme_(scheme) + {} + + //- Construct from flux and Istream + fusedGaussConvectionScheme + ( + const fvMesh& mesh, + const surfaceScalarField& faceFlux, + Istream& is + ) + : + convectionScheme(mesh, faceFlux), + tinterpScheme_ + ( + surfaceInterpolationScheme::New(mesh, faceFlux, is) + ) + {} + + + // Member Functions + + const surfaceInterpolationScheme& interpScheme() const; + + tmp> interpolate + ( + const surfaceScalarField&, + const GeometricField& + ) const; + + tmp> flux + ( + const surfaceScalarField&, + const GeometricField& + ) const; + + tmp> fvmDiv + ( + const surfaceScalarField&, + const GeometricField& + ) const; + + tmp> fvcDiv + ( + const surfaceScalarField&, + const GeometricField& + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "fusedGaussConvectionScheme.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedGaussConvectionSchemes.C b/src/fused/finiteVolume/fusedGaussConvectionSchemes.C new file mode 100644 index 0000000000..950406e278 --- /dev/null +++ b/src/fused/finiteVolume/fusedGaussConvectionSchemes.C @@ -0,0 +1,35 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2016 OpenFOAM Foundation +------------------------------------------------------------------------------- +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 "fusedGaussConvectionScheme.H" +#include "fvMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makeFvConvectionScheme(fusedGaussConvectionScheme) + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedGaussDivScheme.C b/src/fused/finiteVolume/fusedGaussDivScheme.C new file mode 100644 index 0000000000..ffb51ac7c1 --- /dev/null +++ b/src/fused/finiteVolume/fusedGaussDivScheme.C @@ -0,0 +1,155 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2024 M. Janssens +------------------------------------------------------------------------------- +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 "fvcSurfaceOps.H" +#include "fusedGaussDivScheme.H" +#include "fvcSurfaceIntegrate.H" +#include "fvMatrices.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fv +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +tmp +< + GeometricField + ::type, fvPatchField, volMesh> +> +fusedGaussDivScheme::fvcDiv +( + const GeometricField& vf +) +{ + typedef typename innerProduct::type DivType; + typedef GeometricField DivFieldType; + + const fvMesh& mesh = vf.mesh(); + + DebugPout<< "fusedGaussDivScheme::fvcDiv on " << vf.name() + << endl; + + tmp tDiv + ( + new DivFieldType + ( + IOobject + ( + "div(" + vf.name() + ')', + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensioned(vf.dimensions()/dimLength, Zero), + fvPatchFieldBase::extrapolatedCalculatedType() + ) + ); + DivFieldType& div = tDiv.ref(); + + //fvcDiv(vf, this->tinterpScheme_().weights(vf), div); + + if (this->tinterpScheme_().corrected()) + { + const auto tfaceCorr(this->tinterpScheme_().correction(vf)); + auto& faceCorr = tfaceCorr(); + + const auto dotInterpolate = [&] + ( + const vector& area, + const scalar lambda, + + const Type& ownVal, + const Type& neiVal, + + const Type& correction + + ) -> DivType + { + return area & ((lambda*(ownVal - neiVal) + neiVal) + correction); + }; + + fvc::surfaceSum + ( + this->tinterpScheme_().weights(vf), + vf, + faceCorr, + dotInterpolate, + div, + false + ); + } + else + { + const auto dotInterpolate = [&] + ( + const vector& area, + const scalar lambda, + const Type& ownVal, + const Type& neiVal + ) -> DivType + { + return area & (lambda*(ownVal - neiVal) + neiVal); + }; + + fvc::surfaceSum + ( + this->tinterpScheme_().weights(vf), + vf, + dotInterpolate, + div, + false + ); + } + + tDiv.ref().primitiveFieldRef() /= mesh.V(); + + tDiv.ref().correctBoundaryConditions(); + + return tDiv; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedGaussDivScheme.H b/src/fused/finiteVolume/fusedGaussDivScheme.H new file mode 100644 index 0000000000..1a02ebadfa --- /dev/null +++ b/src/fused/finiteVolume/fusedGaussDivScheme.H @@ -0,0 +1,125 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2016 OpenFOAM Foundation +------------------------------------------------------------------------------- +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::fusedGaussDivScheme + +Group + grpFvDivSchemes + +Description + Variant of gaussDiv that avoids intermediates + +SourceFiles + fusedGaussDivScheme.C + +\*---------------------------------------------------------------------------*/ + +#ifndef fusedGaussDivScheme_H +#define fusedGaussDivScheme_H + +#include "divScheme.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fv +{ + +/*---------------------------------------------------------------------------*\ + Class fusedGaussDivScheme Declaration +\*---------------------------------------------------------------------------*/ + +template +class fusedGaussDivScheme +: + public fv::divScheme +{ + // Private Member Functions + + //- No copy construct + fusedGaussDivScheme(const fusedGaussDivScheme&) = delete; + + //- No copy assignment + void operator=(const fusedGaussDivScheme&) = delete; + + +public: + + //- Runtime type information + TypeName("fusedGauss"); + + + // Constructors + + //- Construct null + fusedGaussDivScheme(const fvMesh& mesh) + : + divScheme(mesh) + {} + + //- Construct from Istream + fusedGaussDivScheme(const fvMesh& mesh, Istream& is) + : + divScheme(mesh, is) + {} + + + // Member Functions + + tmp + < + GeometricField + ::type, fvPatchField, volMesh> + > fvcDiv + ( + const GeometricField& + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "fusedGaussDivScheme.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedGaussDivSchemes.C b/src/fused/finiteVolume/fusedGaussDivSchemes.C new file mode 100644 index 0000000000..2def82689a --- /dev/null +++ b/src/fused/finiteVolume/fusedGaussDivSchemes.C @@ -0,0 +1,35 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2015 OpenFOAM Foundation +------------------------------------------------------------------------------- +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 "fusedGaussDivScheme.H" +#include "fvMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makeFvDivScheme(fusedGaussDivScheme) + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedGaussGrad.C b/src/fused/finiteVolume/fusedGaussGrad.C new file mode 100644 index 0000000000..5954e5804c --- /dev/null +++ b/src/fused/finiteVolume/fusedGaussGrad.C @@ -0,0 +1,263 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2024 M. Janssens +------------------------------------------------------------------------------- +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 "fusedGaussGrad.H" +#include "extrapolatedCalculatedFvPatchField.H" +#include "fvcSurfaceOps.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +Foam::tmp +< + Foam::GeometricField + < + typename Foam::outerProduct::type, + Foam::fvPatchField, + Foam::volMesh + > +> +Foam::fv::fusedGaussGrad::gradf +( + const GeometricField& ssf, + const word& name +) +{ + typedef typename outerProduct::type GradType; + typedef GeometricField GradFieldType; + + const fvMesh& mesh = ssf.mesh(); + + DebugPout<< "fusedGaussGrad::gradf on " << ssf.name() + << " with name " << name << endl; + + tmp tgGrad + ( + new GradFieldType + ( + IOobject + ( + name, + ssf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensioned(ssf.dimensions()/dimLength, Zero), + fvPatchFieldBase::extrapolatedCalculatedType() + ) + ); + GradFieldType& gGrad = tgGrad.ref(); + + const labelUList& owner = mesh.owner(); + const labelUList& neighbour = mesh.neighbour(); + const vectorField& Sf = mesh.Sf(); + + Field& igGrad = gGrad; + const Field& issf = ssf; + + forAll(owner, facei) + { + const GradType Sfssf = Sf[facei]*issf[facei]; + + igGrad[owner[facei]] += Sfssf; + igGrad[neighbour[facei]] -= Sfssf; + } + + forAll(mesh.boundary(), patchi) + { + const labelUList& pFaceCells = + mesh.boundary()[patchi].faceCells(); + + const vectorField& pSf = mesh.Sf().boundaryField()[patchi]; + + const fvsPatchField& pssf = ssf.boundaryField()[patchi]; + + forAll(mesh.boundary()[patchi], facei) + { + igGrad[pFaceCells[facei]] += pSf[facei]*pssf[facei]; + } + } + + igGrad /= mesh.V(); + + gGrad.correctBoundaryConditions(); + + return tgGrad; +} + + +template +Foam::tmp +< + Foam::GeometricField + < + typename Foam::outerProduct::type, + Foam::fvPatchField, + Foam::volMesh + > +> +Foam::fv::fusedGaussGrad::calcGrad +( + const GeometricField& vf, + const word& name +) const +{ + typedef typename outerProduct::type GradType; + typedef GeometricField GradFieldType; + + const fvMesh& mesh = vf.mesh(); + + DebugPout<< "fusedGaussGrad::calcGrad on " << vf.name() + << " with name " << name << endl; + + tmp tgGrad + ( + new GradFieldType + ( + IOobject + ( + name, + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensioned(vf.dimensions()/dimLength, Zero), + fvPatchFieldBase::extrapolatedCalculatedType() + ) + ); + GradFieldType& gGrad = tgGrad.ref(); + + if (this->tinterpScheme_().corrected()) + { + const auto tfaceCorr(this->tinterpScheme_().correction(vf)); + auto& faceCorr = tfaceCorr(); + + DebugPout<< "fusedGaussGrad::calcGrad corrected interpScheme " + << this->tinterpScheme_().type() << endl; + + const auto interpolate = [&] + ( + const vector& area, + const scalar lambda, + + const Type& ownVal, + const Type& neiVal, + + const Type& correction + + ) -> GradType + { + return area*((lambda*(ownVal - neiVal) + neiVal) + correction); + }; + + fvc::surfaceSum + ( + this->tinterpScheme_().weights(vf), + vf, + faceCorr, + interpolate, + gGrad, + false + ); + } + else + { + DebugPout<< "fusedGaussGrad::calcGrad uncorrected interpScheme " + << this->tinterpScheme_().type() << endl; + + const auto interpolate = [&] + ( + const vector& area, + const scalar lambda, + const Type& ownVal, + const Type& neiVal + ) -> GradType + { + return area*(lambda*(ownVal - neiVal) + neiVal); + }; + + fvc::surfaceSum + ( + tinterpScheme_().weights(vf), + vf, + interpolate, + gGrad, + false + ); + } + + gGrad.primitiveFieldRef() /= mesh.V(); + + gGrad.correctBoundaryConditions(); + + correctBoundaryConditions(vf, gGrad); + + return tgGrad; +} + + +template +template +void Foam::fv::fusedGaussGrad::correctBoundaryConditions +( + const GeometricField& vf, + GeometricField& gGrad +) +{ + DebugPout<< "fusedGaussGrad::correctBoundaryConditions on " + << vf.name() << " with gGrad " << gGrad.name() << endl; + + const fvMesh& mesh = vf.mesh(); + auto& gGradbf = gGrad.boundaryFieldRef(); + + forAll(vf.boundaryField(), patchi) + { + if (!vf.boundaryField()[patchi].coupled()) + { + const auto& pSf = mesh.Sf().boundaryField()[patchi]; + const auto tsnGrad(vf.boundaryField()[patchi].snGrad()); + const auto& snGrad = tsnGrad(); + auto& pgrad = gGradbf[patchi]; + + forAll(pgrad, facei) + { + const vector n(pSf[facei]/mag(pSf[facei])); + const Type uncorrectSnGrad(n & pgrad[facei]); + pgrad[facei] += n*(snGrad[facei] - uncorrectSnGrad); + } + } + } +} + + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedGaussGrad.H b/src/fused/finiteVolume/fusedGaussGrad.H new file mode 100644 index 0000000000..233ecdc577 --- /dev/null +++ b/src/fused/finiteVolume/fusedGaussGrad.H @@ -0,0 +1,177 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2018-2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +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::fusedGaussGrad + +Group + grpFvGradSchemes + +Description + Basic second-order gradient scheme using face-interpolation + and Gauss' theorem. + +SourceFiles + fusedGaussGrad.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_fusedGaussGrad_H +#define Foam_fusedGaussGrad_H + +#include "gradScheme.H" +#include "surfaceInterpolationScheme.H" +#include "linear.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fv +{ + +/*---------------------------------------------------------------------------*\ + Class fusedGaussGrad Declaration +\*---------------------------------------------------------------------------*/ + +template +class fusedGaussGrad +: + public fv::gradScheme +{ + // Private Data + + //- Interpolation scheme + tmp> tinterpScheme_; + + + // Private Member Functions + + //- No copy construct + fusedGaussGrad(const fusedGaussGrad&) = delete; + + //- No copy assignment + void operator=(const fusedGaussGrad&) = delete; + + +public: + + //- Runtime type information + TypeName("fusedGauss"); + + + // Constructors + + //- Construct from mesh + fusedGaussGrad(const fvMesh& mesh) + : + gradScheme(mesh), + tinterpScheme_(new linear(mesh)) + {} + + //- Construct from mesh and Istream + fusedGaussGrad(const fvMesh& mesh, Istream& is) + : + gradScheme(mesh), + tinterpScheme_(nullptr) + { + if (is.eof()) + { + tinterpScheme_.reset + ( + new linear(mesh) + ); + } + else + { + tinterpScheme_.reset + ( + surfaceInterpolationScheme::New(mesh, is) + ); + } + } + + + // Member Functions + + //- Return the gradient of the given field + //- calculated using Gauss' theorem on the given surface field + static + tmp + < + GeometricField + ::type, fvPatchField, volMesh> + > gradf + ( + const GeometricField&, + const word& name + ); + + //- 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; + + //- Correct the boundary values of the gradient using the patchField + //- snGrad functions + template + static void correctBoundaryConditions + ( + const GeometricField&, + GeometricField& + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "fusedGaussGrad.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedGaussGrads.C b/src/fused/finiteVolume/fusedGaussGrads.C new file mode 100644 index 0000000000..86a85a8bee --- /dev/null +++ b/src/fused/finiteVolume/fusedGaussGrads.C @@ -0,0 +1,35 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2015 OpenFOAM Foundation +------------------------------------------------------------------------------- +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 "fvMesh.H" +#include "fusedGaussGrad.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makeFvGradScheme(fusedGaussGrad) + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedGaussLaplacianScheme.C b/src/fused/finiteVolume/fusedGaussLaplacianScheme.C new file mode 100644 index 0000000000..00553d55d9 --- /dev/null +++ b/src/fused/finiteVolume/fusedGaussLaplacianScheme.C @@ -0,0 +1,581 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2024 M. Janssens +------------------------------------------------------------------------------- +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 "fusedGaussLaplacianScheme.H" +#include "fvcSurfaceOps.H" +#include "surfaceInterpolate.H" +#include "fvcDiv.H" +#include "fvcGrad.H" +#include "fvMatrices.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fv +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +tmp> +fusedGaussLaplacianScheme::fvmLaplacianUncorrected +( + const surfaceScalarField& gammaMagSf, + const surfaceScalarField& deltaCoeffs, + const GeometricField& vf +) +{ + DebugPout + << "fusedGaussLaplacianScheme::fvmLaplacianUncorrected on " + << vf.name() + << " with gammaMagSf " << gammaMagSf.name() + << " with deltaCoeffs " << deltaCoeffs.name() + << endl; + + tmp> tfvm + ( + new fvMatrix + ( + vf, + deltaCoeffs.dimensions()*gammaMagSf.dimensions()*vf.dimensions() + ) + ); + fvMatrix& fvm = tfvm.ref(); + + //fvm.upper() = deltaCoeffs.primitiveField()*gammaMagSf.primitiveField(); + multiply + ( + fvm.upper(), + deltaCoeffs.primitiveField(), + gammaMagSf.primitiveField() + ); + fvm.negSumDiag(); + + forAll(vf.boundaryField(), patchi) + { + const fvPatchField& pvf = vf.boundaryField()[patchi]; + const fvsPatchScalarField& pGamma = gammaMagSf.boundaryField()[patchi]; + const fvsPatchScalarField& pDeltaCoeffs = + deltaCoeffs.boundaryField()[patchi]; + + auto& intCoeffs = fvm.internalCoeffs()[patchi]; + auto& bouCoeffs = fvm.boundaryCoeffs()[patchi]; + + if (pvf.coupled()) + { + //intCoeffs = pGamma*pvf.gradientInternalCoeffs(pDeltaCoeffs); + multiply + ( + intCoeffs, + pGamma, + pvf.gradientInternalCoeffs(pDeltaCoeffs)() + ); + //bouCoeffs = -pGamma*pvf.gradientBoundaryCoeffs(pDeltaCoeffs); + multiply + ( + bouCoeffs, + pGamma, + pvf.gradientBoundaryCoeffs(pDeltaCoeffs)() + ); + bouCoeffs.negate(); + } + else + { + //intCoeffs = pGamma*pvf.gradientInternalCoeffs(); + multiply + ( + intCoeffs, + pGamma, + pvf.gradientInternalCoeffs()() + ); + //bouCoeffs = -pGamma*pvf.gradientBoundaryCoeffs(); + multiply + ( + bouCoeffs, + pGamma, + pvf.gradientBoundaryCoeffs()() + ); + bouCoeffs.negate(); + } + } + + return tfvm; +} + + +template +tmp> +fusedGaussLaplacianScheme::gammaSnGradCorr +( + const surfaceVectorField& SfGammaCorr, + const GeometricField& vf +) +{ + const fvMesh& mesh = this->mesh(); + + DebugPout<< "fusedGaussLaplacianScheme::gammaSnGradCorr on " + << vf.name() << " with SfGammCorr " << SfGammaCorr.name() << endl; + + tmp> tgammaSnGradCorr + ( + new GeometricField + ( + IOobject + ( + "gammaSnGradCorr("+vf.name()+')', + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + SfGammaCorr.dimensions() + *vf.dimensions()*mesh.deltaCoeffs().dimensions() + ) + ); + auto& gammaSnGradCorr = tgammaSnGradCorr.ref(); + gammaSnGradCorr.oriented() = SfGammaCorr.oriented(); + + for (direction cmpt = 0; cmpt < pTraits::nComponents; cmpt++) + { + gammaSnGradCorr.replace + ( + cmpt, + fvc::dotInterpolate(SfGammaCorr, fvc::grad(vf.component(cmpt))) + ); + } + + return tgammaSnGradCorr; +} + + +/* +template +void fusedGaussLaplacianScheme::gradComponent +( + const surfaceScalarField& weights, + const GeometricField& vf, + const direction cmpt, + GeometricField& gGrad +) +{ + gGrad = dimensioned(vf.dimensions()/dimLength, Zero); + + // Calculate grad of vf.component(cmpt) + fvc::GaussOp + ( + vf, + weights, + componentInterpolate(cmpt), + gGrad + ); +} +template +tmp> +fusedGaussLaplacianScheme::gammaSnGradCorr +( + const surfaceScalarField& weights, + const GeometricField& gamma, + const GeometricField& vf +) +{ + const fvMesh& mesh = this->mesh(); + + tmp> tgammaSnGradCorr + ( + new GeometricField + ( + IOobject + ( + "gammaSnGradCorr("+vf.name()+')', + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + gamma.dimensions() + *vf.dimensions()*mesh.deltaCoeffs().dimensions() + ) + ); + auto& gammaSnGradCorr = tgammaSnGradCorr.ref(); + + gammaSnGradCorr.oriented() = gamma.oriented(); + + + GeometricField gradCmptFld + ( + IOobject + ( + vf.name() + ".component()", + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + mesh, + vf.dimensions() + ); + + for (direction cmpt = 0; cmpt < pTraits::nComponents; cmpt++) + { + // Calculate fvc::grad(vf.component(cmpt)) into gradCmptFld + gradComponent + ( + weights, + vf, + cmpt, + + gradCmptFld + ); + + //gammaSnGradCorr.replace + //( + // cmpt, + // fvc::dotInterpolate(SfGammaCorr, gradCmptFld) + //); + + + fvc::interpolate + ( + weights, + + gradCmptFld, // fvc::grad(vf.component(cmpt)) + + gamma, // weight field + + tanInterpolate(cmpt), + + gammaSnGradCorr + ); + } + + return tgammaSnGradCorr; +} +*/ + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +tmp> +fusedGaussLaplacianScheme::fvcLaplacian +( + const GeometricField& vf +) +{ + typedef GeometricField FieldType; + //typedef GeometricField SurfaceFieldType; + + tmp tresult + ( + new FieldType + ( + IOobject + ( + "laplacian(" + vf.name() + ')', + vf.instance(), + vf.mesh(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + vf.mesh(), + dimensioned(vf.dimensions()/dimArea, Zero), + fvPatchFieldBase::extrapolatedCalculatedType() + ) + ); + FieldType& result = tresult.ref(); + + DebugPout + << "fusedGaussLaplacianScheme::fvcLaplacian on " + << vf.name() + << " to generate " << result.name() << endl; + + // Note: cannot use fvc::GaussOp since specialised handling on boundary. + // Maybe bypass for processor boundaries? + + const auto tdeltaCoeffs(this->tsnGradScheme_().deltaCoeffs(vf)); + const auto& deltaCoeffs = tdeltaCoeffs(); + + + const fvMesh& mesh = vf.mesh(); + + if (this->tsnGradScheme_().corrected()) + { + // Problem when instantiating for tensors - outerProduct not defined. + // scalar/vector specialisations in *Schemes.C file. + + FatalErrorInFunction<< "Corrected snGrad not supported for field " + << vf.name() << exit(FatalError); + + //typedef typename outerProduct::type GradType; + //typedef GeometricField GradFieldType; + //// Calculate sn gradient + //tmp tfaceGrad + //( + // new SurfaceFieldType + // ( + // IOobject + // ( + // "snGradCorr("+vf.name()+')', + // vf.instance(), + // mesh, + // IOobject::NO_READ, + // IOobject::NO_WRITE + // ), + // mesh, + // vf.dimensions() + // ) + //); + // + //{ + // // Calculate gradient + // tmp tgGrad + // ( + // gradScheme::New + // ( + // mesh, + // mesh.gradScheme("grad(" + vf.name() + ')') + // )().grad(vf, "grad(" + vf.name() + ')') + // ); + // const auto& gGrad = tgGrad(); + // + // // Doing a dotinterpolate with nonOrthCorrectionVectors + // const auto dotInterpolate = [&] + // ( + // const vector& area, + // const scalar lambda, + // + // const GradType& ownVal, + // const GradType& neiVal, + // + // const vector& dotVector, + // + // Type& result + // ) + // { + // result = dotVector&(lambda*(ownVal - neiVal) + neiVal); + // }; + // + // fvc::interpolate + // ( + // mesh.surfaceInterpolation::weights(), // linear interp + // gGrad, // volume field + // mesh.nonOrthCorrectionVectors(),// surface multiplier + // dotInterpolate, + // tfaceGrad.ref() + // ); + //} + //const auto& faceGrad = tfaceGrad(); + // + //const auto snGrad = [&] + //( + // const vector& Sf, + // const scalar dc, + // const Type& ownVal, + // const Type& neiVal, + // const Type& correction + //) -> Type + //{ + // const auto snGrad(dc*(neiVal-ownVal) + correction); + // return mag(Sf)*snGrad; + //}; + // + //fvc::surfaceSnSum + //( + // deltaCoeffs, + // vf, + // faceGrad, // face-based addition + // snGrad, + // result, + // false // avoid boundary evaluation until volume division + //); + } + else + { + const auto snGrad = [&] + ( + const vector& Sf, + const scalar dc, + const Type& ownVal, + const Type& neiVal + ) -> Type + { + const auto snGrad(dc*(neiVal-ownVal)); + return mag(Sf)*snGrad; + }; + + fvc::surfaceSnSum + ( + deltaCoeffs, + vf, + snGrad, + result, + false // avoid boundary evaluation until volume division + ); + } + + result.primitiveFieldRef() /= mesh.V(); + result.correctBoundaryConditions(); + + return tresult; +} + + +template +tmp> +fusedGaussLaplacianScheme::fvcLaplacian +( + const GeometricField& gamma, + const GeometricField& vf +) +{ + DebugPout + << "fusedGaussLaplacianScheme::fvcLaplacian on " + << vf.name() << " with gamma " << gamma.name() << endl; + + return fvcLaplacian(this->tinterpGammaScheme_().interpolate(gamma)(), vf); +} + + +template +tmp> +fusedGaussLaplacianScheme::fvmLaplacian +( + const GeometricField& gamma, + const GeometricField& vf +) +{ + DebugPout<< "fusedGaussLaplacianScheme::fvmLaplacian on " + << vf.name() << " with gamma " << gamma.name() << endl; + + const fvMesh& mesh = this->mesh(); + + const surfaceVectorField Sn(mesh.Sf()/mesh.magSf()); + const surfaceVectorField SfGamma(mesh.Sf() & gamma); + const GeometricField SfGammaSn + ( + SfGamma & Sn + ); + const surfaceVectorField SfGammaCorr(SfGamma - SfGammaSn*Sn); + + tmp> tfvm = fvmLaplacianUncorrected + ( + SfGammaSn, + this->tsnGradScheme_().deltaCoeffs(vf), + vf + ); + fvMatrix& fvm = tfvm.ref(); + + tmp> tfaceFluxCorrection + = gammaSnGradCorr(SfGammaCorr, vf); + + if (this->tsnGradScheme_().corrected()) + { + tfaceFluxCorrection.ref() += + SfGammaSn*this->tsnGradScheme_().correction(vf); + } + + fvm.source() -= mesh.V()*fvc::div(tfaceFluxCorrection())().primitiveField(); + + if (mesh.fluxRequired(vf.name())) + { + fvm.faceFluxCorrectionPtr(tfaceFluxCorrection.ptr()); + } + + return tfvm; +} + + +template +tmp> +fusedGaussLaplacianScheme::fvmLaplacian +( + const GeometricField& gamma, + const GeometricField& vf +) +{ + DebugPout<< "fusedGaussLaplacianScheme::fvmLaplacian on " + << vf.name() << " with gamma " << gamma.name() << endl; + return fvmLaplacian(this->tinterpGammaScheme_().interpolate(gamma)(), vf); +} + + +template +tmp> +fusedGaussLaplacianScheme::fvcLaplacian +( + const GeometricField& gamma, + const GeometricField& vf +) +{ + DebugPout<< "fusedGaussLaplacianScheme::fvcLaplacian on " + << vf.name() << " with gamma " << gamma.name() << endl; + + const fvMesh& mesh = this->mesh(); + + const surfaceVectorField Sn(mesh.Sf()/mesh.magSf()); + const surfaceVectorField SfGamma(mesh.Sf() & gamma); + const GeometricField SfGammaSn + ( + SfGamma & Sn + ); + const surfaceVectorField SfGammaCorr(SfGamma - SfGammaSn*Sn); + + tmp> tLaplacian + ( + fvc::div + ( + SfGammaSn*this->tsnGradScheme_().snGrad(vf) + + gammaSnGradCorr(SfGammaCorr, vf) + ) + ); + + tLaplacian.ref().rename + ( + "laplacian(" + gamma.name() + ',' + vf.name() + ')' + ); + + return tLaplacian; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedGaussLaplacianScheme.H b/src/fused/finiteVolume/fusedGaussLaplacianScheme.H new file mode 100644 index 0000000000..85753bff01 --- /dev/null +++ b/src/fused/finiteVolume/fusedGaussLaplacianScheme.H @@ -0,0 +1,264 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2024 M. Janssens +------------------------------------------------------------------------------- +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::GaussLaplacianScheme + +Group + grpFvLaplacianSchemes + +Description + Variant of GaussLaplacian that avoids intermediate fields + +SourceFiles + fusedGaussLaplacianScheme.C + +\*---------------------------------------------------------------------------*/ + +#ifndef fusedGaussLaplacianScheme_H +#define fusedGaussLaplacianScheme_H + +#include "laplacianScheme.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fv +{ + +/*---------------------------------------------------------------------------*\ + Class fusedGaussLaplacianScheme Declaration +\*---------------------------------------------------------------------------*/ + +template +class fusedGaussLaplacianScheme +: + public fv::laplacianScheme +{ + // Private Member Functions + + //- See gaussLaplacianScheme + tmp> gammaSnGradCorr + ( + const surfaceVectorField& SfGammaCorr, + const GeometricField& + ); + + //- No copy construct + fusedGaussLaplacianScheme(const fusedGaussLaplacianScheme&) + = delete; + + //- No copy assignment + void operator=(const fusedGaussLaplacianScheme&) = delete; + + +public: + + //- Runtime type information + TypeName("fusedGauss"); + + + // Constructors + + //- Construct null + fusedGaussLaplacianScheme(const fvMesh& mesh) + : + laplacianScheme(mesh) + {} + + //- Construct from Istream + fusedGaussLaplacianScheme(const fvMesh& mesh, Istream& is) + : + laplacianScheme(mesh, is) + {} + + //- Construct from mesh, interpolation and snGradScheme schemes + fusedGaussLaplacianScheme + ( + const fvMesh& mesh, + const tmp>& igs, + const tmp>& sngs + ) + : + laplacianScheme(mesh, igs, sngs) + {} + + + //- Destructor + virtual ~fusedGaussLaplacianScheme() = default; + + + // Member Functions + + static tmp> fvmLaplacianUncorrected + ( + const surfaceScalarField& gammaMagSf, + const surfaceScalarField& deltaCoeffs, + const GeometricField& + ); + + ////- Helper: grad on component. Move to GaussGrad? Template on + //// - cell-access operator? + //// - cell-to-face operator? + //// - face-to-cell operator? + //static void gradComponent + //( + // const surfaceScalarField& weights, + // const GeometricField& vf, + // const direction cmpt, + // GeometricField& gGrad + //); + + virtual tmp> fvcLaplacian + ( + const GeometricField& + ); + + virtual tmp> fvmLaplacian + ( + const GeometricField&, + const GeometricField& + ); + + virtual tmp> fvcLaplacian + ( + const GeometricField&, + const GeometricField& + ); + + + // New: override laplacianScheme::fvc/mLaplacian for scalar gamma and + // scalar,vector volField + + virtual tmp> fvmLaplacian + ( + const GeometricField&, + const GeometricField& + ); + + virtual tmp> fvcLaplacian + ( + const GeometricField&, + const GeometricField& + ); +}; + + +// Use macros to emulate partial-specialisation of the Laplacian functions +// for scalar diffusivity gamma + +#define defineFvmLaplacianScalarGamma(Type) \ + \ +template<> \ +tmp> fusedGaussLaplacianScheme::fvmLaplacian \ +( \ + const GeometricField&, \ + const GeometricField& \ +); \ + \ +template<> \ +tmp> \ +fusedGaussLaplacianScheme::fvcLaplacian \ +( \ + const GeometricField&, \ + const GeometricField& \ +); + +defineFvmLaplacianScalarGamma(scalar); +defineFvmLaplacianScalarGamma(vector); +defineFvmLaplacianScalarGamma(sphericalTensor); +defineFvmLaplacianScalarGamma(symmTensor); +defineFvmLaplacianScalarGamma(tensor); + +// Unweighted laplacian +template<> +tmp> +fusedGaussLaplacianScheme::fvcLaplacian +( + const GeometricField& +); +template<> +tmp> +fusedGaussLaplacianScheme::fvcLaplacian +( + const GeometricField& +); + +// Weighted laplacian +template<> +tmp> +fusedGaussLaplacianScheme::fvcLaplacian +( + const GeometricField&, + const GeometricField& +); +template<> +tmp> +fusedGaussLaplacianScheme::fvcLaplacian +( + const GeometricField&, + const GeometricField& +); +template<> +tmp> +fusedGaussLaplacianScheme::fvmLaplacian +( + const GeometricField&, + const GeometricField& +); +template<> +tmp> +fusedGaussLaplacianScheme::fvmLaplacian +( + const GeometricField&, + const GeometricField& +); + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "fusedGaussLaplacianScheme.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedGaussLaplacianSchemes.C b/src/fused/finiteVolume/fusedGaussLaplacianSchemes.C new file mode 100644 index 0000000000..0433c423d3 --- /dev/null +++ b/src/fused/finiteVolume/fusedGaussLaplacianSchemes.C @@ -0,0 +1,866 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2024 M. Janssens +------------------------------------------------------------------------------- +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 "fusedGaussLaplacianScheme.H" +#include "fvMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makeFvLaplacianScheme(fusedGaussLaplacianScheme) + +#define declareFvmLaplacianScalarGamma(Type) \ + \ +template<> \ +Foam::tmp> \ +Foam::fv::fusedGaussLaplacianScheme:: \ +fvmLaplacian \ +( \ + const GeometricField& gamma, \ + const GeometricField& vf \ +) \ +{ \ + DebugPout<< "fusedGaussLaplacianScheme::fvmLaplacian on " << vf.name() \ + << " with scalar gamma " << gamma.name() << endl; \ + \ + const fvMesh& mesh = this->mesh(); \ + \ + GeometricField gammaMagSf \ + ( \ + gamma*mesh.magSf() \ + ); \ + \ + tmp> tfvm = fvmLaplacianUncorrected \ + ( \ + gammaMagSf, \ + this->tsnGradScheme_().deltaCoeffs(vf), \ + vf \ + ); \ + fvMatrix& fvm = tfvm.ref(); \ + \ + if (this->tsnGradScheme_().corrected()) \ + { \ + if (mesh.fluxRequired(vf.name())) \ + { \ + fvm.faceFluxCorrectionPtr() = std::make_unique \ + < \ + GeometricField \ + > \ + ( \ + gammaMagSf*this->tsnGradScheme_().correction(vf) \ + ); \ + \ + fvm.source() -= \ + mesh.V()* \ + fvc::div \ + ( \ + *fvm.faceFluxCorrectionPtr() \ + )().primitiveField(); \ + } \ + else \ + { \ + fvm.source() -= \ + mesh.V()* \ + fvc::div \ + ( \ + gammaMagSf*this->tsnGradScheme_().correction(vf) \ + )().primitiveField(); \ + } \ + } \ + \ + return tfvm; \ +} \ + \ + \ +template<> \ +Foam::tmp> \ +Foam::fv::fusedGaussLaplacianScheme:: \ +fvcLaplacian \ +( \ + const GeometricField& gamma, \ + const GeometricField& vf \ +) \ +{ \ + DebugPout<< "fvcLaplacian on " << vf.name() \ + << " with scalar gamma " << gamma.name() << endl; \ + \ + const fvMesh& mesh = this->mesh(); \ + \ + tmp> tLaplacian \ + ( \ + fvc::div(gamma*this->tsnGradScheme_().snGrad(vf)*mesh.magSf()) \ + ); \ + \ + tLaplacian.ref().rename \ + ( \ + "laplacian(" + gamma.name() + ',' + vf.name() + ')' \ + ); \ + \ + return tLaplacian; \ +} + + +template<> +Foam::tmp +< + Foam::GeometricField +> +Foam::fv::fusedGaussLaplacianScheme::fvcLaplacian +( + const GeometricField& gamma, + const GeometricField& vf +) +{ + typedef scalar Type; + typedef GeometricField FieldType; + typedef GeometricField SurfaceFieldType; + typedef typename outerProduct::type GradType; + typedef GeometricField GradFieldType; + + DebugPout + << "fusedGaussLaplacianScheme::fvcLaplacian" + << " on " << vf.name() << " with gamma " << gamma.name() << endl; + + const fvMesh& mesh = vf.mesh(); + + tmp tresult + ( + new FieldType + ( + IOobject + ( + "laplacian(" + vf.name() + ')', + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensioned + ( + gamma.dimensions()*vf.dimensions()/dimArea, Zero + ), + fvPatchFieldBase::extrapolatedCalculatedType() + ) + ); + FieldType& result = tresult.ref(); + + const auto tweights(this->tinterpGammaScheme_().weights(gamma)); + const auto& weights = tweights(); + const auto tdeltaCoeffs(this->tsnGradScheme_().deltaCoeffs(vf)); + const auto& deltaCoeffs = tdeltaCoeffs(); + + if (this->tsnGradScheme_().corrected()) + { + // Calculate sn gradient + tmp tfaceGrad + ( + new SurfaceFieldType + ( + IOobject + ( + "snGradCorr("+vf.name()+')', + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + vf.dimensions() + ) + ); + + { + // Calculate gradient + tmp tgGrad + ( + gradScheme::New + ( + mesh, + mesh.gradScheme("grad(" + vf.name() + ')') + )().grad(vf, "grad(" + vf.name() + ')') + ); + const auto& gGrad = tgGrad(); + + // Doing a dotinterpolate with nonOrthCorrectionVectors + const auto dotInterpolate = [&] + ( + const vector& area, + const scalar lambda, + + const GradType& ownVal, + const GradType& neiVal, + + const vector& dotVector, + + Type& result + ) + { + result = dotVector&(lambda*(ownVal - neiVal) + neiVal); + }; + + fvc::interpolate + ( + mesh.surfaceInterpolation::weights(), // linear interpolation + gGrad, // volume field + mesh.nonOrthCorrectionVectors(),// surface multiplier + dotInterpolate, + tfaceGrad.ref() + ); + } + const auto& faceGrad = tfaceGrad(); + + const auto snGrad = [&] + ( + const vector& Sf, + + const scalar weight, + const scalar ownGamma, + const scalar neiGamma, + + const scalar dc, + const Type& ownVal, + const Type& neiVal, + + const Type& correction + ) -> Type + { + const auto snGrad(dc*(neiVal-ownVal) + correction); + const scalar faceGamma(weight*(ownGamma-neiGamma)+neiGamma); + return mag(Sf)*faceGamma*snGrad; + }; + + fvc::surfaceSnSum + ( + weights, // gamma weights + gamma, + + deltaCoeffs, + vf, + + faceGrad, // face-based addition + + snGrad, + + result, + false // avoid boundary evaluation until volume division + ); + } + else + { + const auto snGrad = [&] + ( + const vector& Sf, + + const scalar weight, + const scalar ownGamma, + const scalar neiGamma, + + const scalar dc, + const Type& ownVal, + const Type& neiVal + ) -> Type + { + const auto snGrad(dc*(neiVal-ownVal)); + const scalar faceGamma(weight*(ownGamma-neiGamma)+neiGamma); + return mag(Sf)*faceGamma*snGrad; + }; + + fvc::surfaceSnSum + ( + weights, + gamma, + + deltaCoeffs, + vf, + + snGrad, + + result, + false // avoid boundary evaluation until volume division + ); + } + + result.primitiveFieldRef() /= mesh.V(); + result.correctBoundaryConditions(); + + return tresult; +} + + +template<> +Foam::tmp +< + Foam::GeometricField +> +Foam::fv::fusedGaussLaplacianScheme::fvcLaplacian +( + const GeometricField& gamma, + const GeometricField& vf +) +{ + DebugPout + << "fusedGaussLaplacianScheme::fvcLaplacian" + << " on " << vf.name() << " with gamma " << gamma.name() << endl; + + typedef vector Type; + typedef GeometricField FieldType; + typedef GeometricField SurfaceFieldType; + typedef typename outerProduct::type GradType; + typedef GeometricField GradFieldType; + + const fvMesh& mesh = vf.mesh(); + + tmp tresult + ( + new FieldType + ( + IOobject + ( + "laplacian(" + vf.name() + ')', + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensioned + ( + gamma.dimensions()*vf.dimensions()/dimArea, Zero + ), + fvPatchFieldBase::extrapolatedCalculatedType() + ) + ); + FieldType& result = tresult.ref(); + + const auto tweights(this->tinterpGammaScheme_().weights(gamma)); + const auto& weights = tweights(); + const auto tdeltaCoeffs(this->tsnGradScheme_().deltaCoeffs(vf)); + const auto& deltaCoeffs = tdeltaCoeffs(); + + if (this->tsnGradScheme_().corrected()) + { + // Calculate sn gradient + tmp tfaceGrad + ( + new SurfaceFieldType + ( + IOobject + ( + "snGradCorr("+vf.name()+')', + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + vf.dimensions() + ) + ); + + { + // Calculate gradient + tmp tgGrad + ( + gradScheme::New + ( + mesh, + mesh.gradScheme("grad(" + vf.name() + ')') + )().grad(vf, "grad(" + vf.name() + ')') + ); + const auto& gGrad = tgGrad(); + + // Doing a dotinterpolate with nonOrthCorrectionVectors + const auto dotInterpolate = [&] + ( + const vector& area, + const scalar lambda, + + const GradType& ownVal, + const GradType& neiVal, + + const vector& dotVector, + + Type& result + ) + { + result = dotVector&(lambda*(ownVal - neiVal) + neiVal); + }; + + fvc::interpolate + ( + mesh.surfaceInterpolation::weights(), // linear interpolation + gGrad, // volume field + mesh.nonOrthCorrectionVectors(),// surface multiplier + dotInterpolate, + tfaceGrad.ref() + ); + } + const auto& faceGrad = tfaceGrad(); + + const auto snGrad = [&] + ( + const vector& Sf, + + const scalar weight, + const scalar ownGamma, + const scalar neiGamma, + + const scalar dc, + const Type& ownVal, + const Type& neiVal, + + const Type& correction + ) -> Type + { + const auto snGrad(dc*(neiVal-ownVal) + correction); + const scalar faceGamma(weight*(ownGamma-neiGamma)+neiGamma); + return mag(Sf)*faceGamma*snGrad; + }; + + fvc::surfaceSnSum + ( + weights, // gamma weights + gamma, + + deltaCoeffs, + vf, + + faceGrad, // face-based addition + + snGrad, + + result, + false // avoid boundary evaluation until volume division + ); + } + else + { + const auto snGrad = [&] + ( + const vector& Sf, + + const scalar weight, + const scalar ownGamma, + const scalar neiGamma, + + const scalar dc, + const Type& ownVal, + const Type& neiVal + ) -> Type + { + const auto snGrad(dc*(neiVal-ownVal)); + const scalar faceGamma(weight*(ownGamma-neiGamma)+neiGamma); + return mag(Sf)*faceGamma*snGrad; + }; + + fvc::surfaceSnSum + ( + weights, // gamma weights + gamma, + + deltaCoeffs, + vf, + + snGrad, + + result, + false // avoid boundary evaluation until volume division + ); + } + + result.primitiveFieldRef() /= mesh.V(); + result.correctBoundaryConditions(); + + return tresult; +} + + +template<> +Foam::tmp> +Foam::fv::fusedGaussLaplacianScheme::fvmLaplacian +( + const GeometricField& gamma, + const GeometricField& vf +) +{ + // TBD + DebugPout + << "fusedGaussLaplacianScheme::fvmLaplacian" + << " on " << vf.name() << " with gamma " << gamma.name() << endl; + return fvmLaplacian(this->tinterpGammaScheme_().interpolate(gamma)(), vf); +} + + +template<> +Foam::tmp> +Foam::fv::fusedGaussLaplacianScheme::fvmLaplacian +( + const GeometricField& gamma, + const GeometricField& vf +) +{ + // TBD + DebugPout + << "fusedGaussLaplacianScheme::fvmLaplacian" + << " on " << vf.name() << " with gamma " << gamma.name() << endl; + return fvmLaplacian(this->tinterpGammaScheme_().interpolate(gamma)(), vf); +} + + +template<> +Foam::tmp +< + Foam::GeometricField +> +Foam::fv::fusedGaussLaplacianScheme::fvcLaplacian +( + const GeometricField& vf +) +{ + typedef scalar Type; + + typedef GeometricField FieldType; + typedef GeometricField SurfaceFieldType; + typedef typename outerProduct::type GradType; + typedef GeometricField GradFieldType; + + const fvMesh& mesh = vf.mesh(); + + tmp tresult + ( + new FieldType + ( + IOobject + ( + "laplacian(" + vf.name() + ')', + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensioned(vf.dimensions()/dimArea, Zero), + fvPatchFieldBase::extrapolatedCalculatedType() + ) + ); + FieldType& result = tresult.ref(); + + DebugPout + << "fusedGaussLaplacianScheme::fvcLaplacian on " + << vf.name() + << " to generate " << result.name() << endl; + + + const auto tdeltaCoeffs(this->tsnGradScheme_().deltaCoeffs(vf)); + const auto& deltaCoeffs = tdeltaCoeffs(); + + + if (this->tsnGradScheme_().corrected()) + { + // Calculate sn gradient + tmp tfaceGrad + ( + new SurfaceFieldType + ( + IOobject + ( + "snGradCorr("+vf.name()+')', + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + vf.dimensions() + ) + ); + + { + // Calculate gradient + tmp tgGrad + ( + gradScheme::New + ( + mesh, + mesh.gradScheme("grad(" + vf.name() + ')') + )().grad(vf, "grad(" + vf.name() + ')') + ); + const auto& gGrad = tgGrad(); + + // Doing a dotinterpolate with nonOrthCorrectionVectors + const auto dotInterpolate = [&] + ( + const vector& area, + const scalar lambda, + + const GradType& ownVal, + const GradType& neiVal, + + const vector& dotVector, + + Type& result + ) + { + result = dotVector&(lambda*(ownVal - neiVal) + neiVal); + }; + + fvc::interpolate + ( + mesh.surfaceInterpolation::weights(), // linear interpolation + gGrad, // volume field + mesh.nonOrthCorrectionVectors(),// surface multiplier + dotInterpolate, + tfaceGrad.ref() + ); + } + const auto& faceGrad = tfaceGrad(); + + const auto snGrad = [&] + ( + const vector& Sf, + const scalar dc, + const Type& ownVal, + const Type& neiVal, + const Type& correction + ) -> Type + { + const auto snGrad(dc*(neiVal-ownVal) + correction); + return mag(Sf)*snGrad; + }; + + fvc::surfaceSnSum + ( + deltaCoeffs, + vf, + faceGrad, // face-based addition + snGrad, + result, + false // avoid boundary evaluation until volume division + ); + } + else + { + const auto snGrad = [&] + ( + const vector& Sf, + const scalar dc, + const Type& ownVal, + const Type& neiVal + ) -> Type + { + const auto snGrad(dc*(neiVal-ownVal)); + return mag(Sf)*snGrad; + }; + + fvc::surfaceSnSum + ( + deltaCoeffs, + vf, + snGrad, + result, + false // avoid boundary evaluation until volume division + ); + } + + result.primitiveFieldRef() /= mesh.V(); + result.correctBoundaryConditions(); + + return tresult; +} + + +template<> +Foam::tmp +< + Foam::GeometricField +> +Foam::fv::fusedGaussLaplacianScheme::fvcLaplacian +( + const GeometricField& vf +) +{ + typedef vector Type; + + typedef GeometricField FieldType; + typedef GeometricField SurfaceFieldType; + typedef typename outerProduct::type GradType; + typedef GeometricField GradFieldType; + + const fvMesh& mesh = vf.mesh(); + + tmp tresult + ( + new FieldType + ( + IOobject + ( + "laplacian(" + vf.name() + ')', + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensioned(vf.dimensions()/dimArea, Zero), + fvPatchFieldBase::extrapolatedCalculatedType() + ) + ); + FieldType& result = tresult.ref(); + + DebugPout + << "fusedGaussLaplacianScheme::fvcLaplacian on " + << vf.name() + << " to generate " << result.name() << endl; + + + const auto tdeltaCoeffs(this->tsnGradScheme_().deltaCoeffs(vf)); + const auto& deltaCoeffs = tdeltaCoeffs(); + + + if (this->tsnGradScheme_().corrected()) + { + // Calculate sn gradient + tmp tfaceGrad + ( + new SurfaceFieldType + ( + IOobject + ( + "snGradCorr("+vf.name()+')', + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + vf.dimensions() + ) + ); + + { + // Calculate gradient + tmp tgGrad + ( + gradScheme::New + ( + mesh, + mesh.gradScheme("grad(" + vf.name() + ')') + )().grad(vf, "grad(" + vf.name() + ')') + ); + const auto& gGrad = tgGrad(); + + // Doing a dotinterpolate with nonOrthCorrectionVectors + const auto dotInterpolate = [&] + ( + const vector& area, + const scalar lambda, + + const GradType& ownVal, + const GradType& neiVal, + + const vector& dotVector, + + Type& result + ) + { + result = dotVector&(lambda*(ownVal - neiVal) + neiVal); + }; + + fvc::interpolate + ( + mesh.surfaceInterpolation::weights(), // linear interpolation + gGrad, // volume field + mesh.nonOrthCorrectionVectors(),// surface multiplier + dotInterpolate, + tfaceGrad.ref() + ); + } + const auto& faceGrad = tfaceGrad(); + + const auto snGrad = [&] + ( + const vector& Sf, + const scalar dc, + const Type& ownVal, + const Type& neiVal, + const Type& correction + ) -> Type + { + const auto snGrad(dc*(neiVal-ownVal) + correction); + return mag(Sf)*snGrad; + }; + + fvc::surfaceSnSum + ( + deltaCoeffs, + vf, + faceGrad, // face-based addition + snGrad, + result, + false // avoid boundary evaluation until volume division + ); + } + else + { + const auto snGrad = [&] + ( + const vector& Sf, + const scalar dc, + const Type& ownVal, + const Type& neiVal + ) -> Type + { + const auto snGrad(dc*(neiVal-ownVal)); + return mag(Sf)*snGrad; + }; + + fvc::surfaceSnSum + ( + deltaCoeffs, + vf, + snGrad, + result, + false // avoid boundary evaluation until volume division + ); + } + + result.primitiveFieldRef() /= mesh.V(); + result.correctBoundaryConditions(); + + return tresult; +} + + +declareFvmLaplacianScalarGamma(scalar); +declareFvmLaplacianScalarGamma(vector); +declareFvmLaplacianScalarGamma(sphericalTensor); +declareFvmLaplacianScalarGamma(symmTensor); +declareFvmLaplacianScalarGamma(tensor); + + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedLeastSquaresGrad.C b/src/fused/finiteVolume/fusedLeastSquaresGrad.C new file mode 100644 index 0000000000..6479983019 --- /dev/null +++ b/src/fused/finiteVolume/fusedLeastSquaresGrad.C @@ -0,0 +1,115 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2024 M. Janssens +------------------------------------------------------------------------------- +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 "fusedLeastSquaresGrad.H" +#include "leastSquaresVectors.H" +#include "gaussGrad.H" +#include "fvMesh.H" +#include "volMesh.H" +#include "surfaceMesh.H" +#include "GeometricField.H" +#include "extrapolatedCalculatedFvPatchField.H" +#include "fvcSurfaceOps.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +Foam::tmp +< + Foam::GeometricField + < + typename Foam::outerProduct::type, + Foam::fvPatchField, + Foam::volMesh + > +> +Foam::fv::fusedLeastSquaresGrad::calcGrad +( + const GeometricField& vf, + const word& name +) const +{ + typedef typename outerProduct::type GradType; + typedef GeometricField GradFieldType; + + const fvMesh& mesh = vf.mesh(); + + DebugPout<< "fusedLeastSquaresGrad::calcGrad on " << vf.name() + << " with name " << name << endl; + + tmp tlsGrad + ( + new GradFieldType + ( + IOobject + ( + name, + vf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensioned(vf.dimensions()/dimLength, Zero), + fvPatchFieldBase::extrapolatedCalculatedType() + ) + ); + GradFieldType& lsGrad = tlsGrad.ref(); + + // Get reference to least square vectors + const leastSquaresVectors& lsv = leastSquaresVectors::New(mesh); + const surfaceVectorField& ownLs = lsv.pVectors(); + const surfaceVectorField& neiLs = lsv.nVectors(); + + const auto differenceOp = [&] + ( + const vector& area, + const Type& ownVal, + const Type& neiVal + ) -> Type + { + return neiVal - ownVal; + }; + + fvc::surfaceOp + ( + vf, + ownLs, + neiLs, + differenceOp, + lsGrad + ); + + gaussGrad::correctBoundaryConditions(vf, lsGrad); + + return tlsGrad; +} + + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedLeastSquaresGrad.H b/src/fused/finiteVolume/fusedLeastSquaresGrad.H new file mode 100644 index 0000000000..78dc13c31b --- /dev/null +++ b/src/fused/finiteVolume/fusedLeastSquaresGrad.H @@ -0,0 +1,129 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2018-2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +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::fusedLeastSquaresGrad + +Group + grpFvGradSchemes + +Description + Second-order gradient scheme using least-squares. + +SourceFiles + leastSquaresGrad.C + +\*---------------------------------------------------------------------------*/ + +#ifndef fusedLeastSquaresGrad_H +#define fusedLeastSquaresGrad_H + +#include "gradScheme.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fv +{ + +/*---------------------------------------------------------------------------*\ + Class fusedLeastSquaresGrad Declaration +\*---------------------------------------------------------------------------*/ + +template +class fusedLeastSquaresGrad +: + public fv::gradScheme +{ + // Private Member Functions + + //- No copy construct + fusedLeastSquaresGrad(const fusedLeastSquaresGrad&) = delete; + + //- No copy assignment + void operator=(const fusedLeastSquaresGrad&) = delete; + + +public: + + //- Runtime type information + TypeName("fusedLeastSquares"); + + + // Constructors + + //- Construct from mesh + fusedLeastSquaresGrad(const fvMesh& mesh) + : + gradScheme(mesh) + {} + + //- Construct from Istream + fusedLeastSquaresGrad(const fvMesh& mesh, Istream&) + : + 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 + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "fusedLeastSquaresGrad.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fusedLeastSquaresGrads.C b/src/fused/finiteVolume/fusedLeastSquaresGrads.C new file mode 100644 index 0000000000..93b2735299 --- /dev/null +++ b/src/fused/finiteVolume/fusedLeastSquaresGrads.C @@ -0,0 +1,35 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2015 OpenFOAM Foundation +------------------------------------------------------------------------------- +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 "fvMesh.H" +#include "fusedLeastSquaresGrad.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makeFvGradScheme(fusedLeastSquaresGrad) + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fvcSurfaceOps.C b/src/fused/finiteVolume/fvcSurfaceOps.C new file mode 100644 index 0000000000..11d9b93d3c --- /dev/null +++ b/src/fused/finiteVolume/fvcSurfaceOps.C @@ -0,0 +1,1408 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2024 M.Janssens +------------------------------------------------------------------------------- +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 "fvcSurfaceOps.H" +#include "fvMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fvc +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +void surfaceSum +( + const surfaceScalarField& lambdas, + const GeometricField& vf, + const CellToFaceOp& cop, + GeometricField& result, + const bool doCorrectBoundaryConditions +) +{ + const fvMesh& mesh = vf.mesh(); + const auto& Sf = mesh.Sf(); + const auto& P = mesh.owner(); + const auto& N = mesh.neighbour(); + + const auto& vfi = vf.primitiveField(); + auto& sfi = result.primitiveFieldRef(); + + // See e.g. surfaceInterpolationScheme::dotInterpolate + + // Internal field + { + const auto& Sfi = Sf.primitiveField(); + const auto& lambda = lambdas.primitiveField(); + + for (label facei=0; facei::zero // not used + ) + ); + sfi[pFaceCells[facei]] += faceVal; + } + } + } + } + + if (doCorrectBoundaryConditions) + { + result.correctBoundaryConditions(); + } +} + + +template +void surfaceSum +( + const surfaceScalarField& lambdas, + const GeometricField& vf, + const GeometricField& sadd, + const CellToFaceOp& cop, + GeometricField& result, + const bool doCorrectBoundaryConditions +) +{ + const fvMesh& mesh = vf.mesh(); + const auto& Sf = mesh.Sf(); + const auto& P = mesh.owner(); + const auto& N = mesh.neighbour(); + + const auto& vfi = vf.primitiveField(); + auto& sfi = result.primitiveFieldRef(); + + // See e.g. surfaceInterpolationScheme::dotInterpolate + + // Internal field + { + const auto& Sfi = Sf.primitiveField(); + const auto& lambda = lambdas.primitiveField(); + const auto& saddi = sadd.primitiveField(); + + for (label facei=0; facei::zero, // not used + + psadd[facei] + ) + ); + sfi[pFaceCells[facei]] += faceVal; + } + } + } + } + + if (doCorrectBoundaryConditions) + { + result.correctBoundaryConditions(); + } +} + + +template +< + class Type, + class FType0, + class FType1, + class ResultType, + class CellToFaceOp +> +void surfaceSum +( + const surfaceScalarField& lambdas, + const GeometricField& vf, + + const GeometricField& sf0, + const GeometricField& sf1, + + const CellToFaceOp& cop, + GeometricField& result, + const bool doCorrectBoundaryConditions +) +{ + const fvMesh& mesh = vf.mesh(); + const auto& Sf = mesh.Sf(); + const auto& P = mesh.owner(); + const auto& N = mesh.neighbour(); + + const auto& vfi = vf.primitiveField(); + auto& resulti = result.primitiveFieldRef(); + + // See e.g. surfaceInterpolationScheme::dotInterpolate + + // Internal field + { + const auto& Sfi = Sf.primitiveField(); + const auto& lambda = lambdas.primitiveField(); + const auto& sf0i = sf0.primitiveField(); + const auto& sf1i = sf1.primitiveField(); + + for (label facei=0; facei::zero, // not used + + psf0[facei], + psf1[facei] + ) + ); + resulti[pFaceCells[facei]] += faceVal; + } + } + } + } + + if (doCorrectBoundaryConditions) + { + result.correctBoundaryConditions(); + } +} + + +template +void GaussOp +( + const surfaceScalarField& lambdas, + const GeometricField& vf, + const CombineOp& cop, + GeometricField& result +) +{ + const fvMesh& mesh = vf.mesh(); + + // Sum contributions + surfaceSum(lambdas, vf, cop, result, false); + + auto& sfi = result.primitiveFieldRef(); + sfi /= mesh.V(); + + result.correctBoundaryConditions(); +} + + +template +void surfaceOp +( + const GeometricField& vf, + const surfaceVectorField& ownLs, + const surfaceVectorField& neiLs, + const CombineOp& cop, + GeometricField& result +) +{ + const fvMesh& mesh = vf.mesh(); + const auto& Sf = mesh.Sf(); + const auto& P = mesh.owner(); + const auto& N = mesh.neighbour(); + + const auto& vfi = vf.primitiveField(); + auto& sfi = result.primitiveFieldRef(); + + // Internal field + { + const auto& Sfi = Sf.primitiveField(); + + for (label facei=0; facei +void surfaceSnSum +( + const surfaceScalarField& deltaCoeffs, + const GeometricField& vf, + + const CellToFaceOp& cop, + + GeometricField& result, + const bool doCorrectBoundaryConditions +) +{ + const fvMesh& mesh = vf.mesh(); + const auto& Sf = mesh.Sf(); + const auto& P = mesh.owner(); + const auto& N = mesh.neighbour(); + + const auto& vfi = vf.primitiveField(); + auto& sfi = result.primitiveFieldRef(); + + // Internal field + { + const auto& Sfi = Sf.primitiveField(); + const auto& dc = deltaCoeffs.primitiveField(); + + for (label facei=0; facei::zero, + pnf[facei] + ) + ); + sfi[ownCelli] += faceVal; + } + } + } + } + + if (doCorrectBoundaryConditions) + { + result.correctBoundaryConditions(); + } +} + + +template +void surfaceSnSum +( + const surfaceScalarField& deltaCoeffs, + const GeometricField& vf, + const GeometricField& sadd, + + const CellToFaceOp& cop, + + GeometricField& result, + const bool doCorrectBoundaryConditions +) +{ + const fvMesh& mesh = vf.mesh(); + const auto& Sf = mesh.Sf(); + const auto& P = mesh.owner(); + const auto& N = mesh.neighbour(); + + const auto& vfi = vf.primitiveField(); + auto& sfi = result.primitiveFieldRef(); + + // Internal field + { + const auto& Sfi = Sf.primitiveField(); + const auto& dc = deltaCoeffs.primitiveField(); + const auto& saddi = sadd.primitiveField(); + + for (label facei=0; facei::zero, + pnf[facei], + psadd[facei] + ) + ); + sfi[ownCelli] += faceVal; + } + } + } + } + + if (doCorrectBoundaryConditions) + { + result.correctBoundaryConditions(); + } +} + + +template +void surfaceSnSum +( + const surfaceScalarField& gammaWeights, + const GeometricField& gamma, + + const surfaceScalarField& deltaCoeffs, + const GeometricField& vf, + + const CellToFaceOp& cop, + + GeometricField& result, + const bool doCorrectBoundaryConditions +) +{ + const fvMesh& mesh = vf.mesh(); + const auto& Sf = mesh.Sf(); + const auto& P = mesh.owner(); + const auto& N = mesh.neighbour(); + + const auto& gammai = gamma.primitiveField(); + const auto& vfi = vf.primitiveField(); + auto& sfi = result.primitiveFieldRef(); + + // Internal field + { + const auto& Sfi = Sf.primitiveField(); + const auto& weights = gammaWeights.primitiveField(); + const auto& dc = deltaCoeffs.primitiveField(); + + for (label facei=0; facei::zero, // not used + + + scalar(1.0), // use 100% of pnf + pTraits::zero, + pnf[facei] + ) + ); + sfi[ownCelli] += faceVal; + } + } + } + } + + if (doCorrectBoundaryConditions) + { + result.correctBoundaryConditions(); + } +} + + +template +void surfaceSnSum +( + const surfaceScalarField& gammaWeights, + const GeometricField& gamma, + + const surfaceScalarField& deltaCoeffs, + const GeometricField& vf, + + const GeometricField& sadd, + + const CellToFaceOp& cop, + + GeometricField& result, + const bool doCorrectBoundaryConditions +) +{ + const fvMesh& mesh = vf.mesh(); + const auto& Sf = mesh.Sf(); + const auto& P = mesh.owner(); + const auto& N = mesh.neighbour(); + + const auto& gammai = gamma.primitiveField(); + const auto& vfi = vf.primitiveField(); + auto& sfi = result.primitiveFieldRef(); + + // Internal field + { + const auto& Sfi = Sf.primitiveField(); + const auto& weights = gammaWeights.primitiveField(); + const auto& dc = deltaCoeffs.primitiveField(); + const auto& saddi = sadd.primitiveField(); + + for (label facei=0; facei::zero, // not used + + + scalar(1.0), // use 100% of pnf + pTraits::zero, + pnf[facei], + + psadd[facei] + ) + ); + sfi[ownCelli] += faceVal; + } + } + } + } + + if (doCorrectBoundaryConditions) + { + result.correctBoundaryConditions(); + } +} + + +template +< + class Type, + class GType0, + class GType1, + class ResultType, + class CellToFaceOp +> +void surfaceSnSum +( + const surfaceScalarField& gammaWeights, + const GeometricField& gamma0, + const GeometricField& gamma1, + + const surfaceScalarField& deltaCoeffs, + const GeometricField& vf, + + const CellToFaceOp& cop, + + GeometricField& result, + const bool doCorrectBoundaryConditions +) +{ + const fvMesh& mesh = vf.mesh(); + const auto& Sf = mesh.Sf(); + const auto& P = mesh.owner(); + const auto& N = mesh.neighbour(); + + const auto& gamma0i = gamma0.primitiveField(); + const auto& gamma1i = gamma1.primitiveField(); + const auto& vfi = vf.primitiveField(); + auto& sfi = result.primitiveFieldRef(); + + // Internal field + { + const auto& Sfi = Sf.primitiveField(); + const auto& weights = gammaWeights.primitiveField(); + const auto& dc = deltaCoeffs.primitiveField(); + + for (label facei=0; facei::zero, // not used + + pgamma1[facei], + pTraits::zero, // not used + + scalar(1.0), // use 100% of pnf + pTraits::zero, + pnf[facei] + ) + ); + sfi[ownCelli] += faceVal; + } + } + } + } + + if (doCorrectBoundaryConditions) + { + result.correctBoundaryConditions(); + } +} + + +template +void interpolate +( + const surfaceScalarField& weights, + const GeometricField& vf, + const GeometricField& sf, + const CellToFaceOp& cop, + GeometricField& result +) +{ + const fvMesh& mesh = vf.mesh(); + const auto& Sf = mesh.Sf(); + const auto& P = mesh.owner(); + const auto& N = mesh.neighbour(); + + const auto& vfi = vf.primitiveField(); + + // Internal field + { + const auto& Sfi = Sf.primitiveField(); + const auto& weight = weights.primitiveField(); + const auto& sfi = sf.primitiveField(); + + auto& resulti = result.primitiveFieldRef(); + + for (label facei=0; facei::zero, // not used + + psf[facei], + + presult[facei] + ); + } + } + } + } +} +template +< + class Type0, + class Type1, + class ResultType, + class CellToFaceOp +> +void interpolate +( + const surfaceScalarField& weights, + const GeometricField& vf0, + const GeometricField& vf1, + const CellToFaceOp& cop, + GeometricField& result +) +{ + const fvMesh& mesh = vf0.mesh(); + const auto& Sf = mesh.Sf(); + const auto& P = mesh.owner(); + const auto& N = mesh.neighbour(); + + const auto& vf0i = vf0.primitiveField(); + const auto& vf1i = vf1.primitiveField(); + + // Internal field + { + const auto& Sfi = Sf.primitiveField(); + const auto& weight = weights.primitiveField(); + + auto& resulti = result.primitiveFieldRef(); + + for (label facei=0; facei::zero, // not used + + pvf1[facei], + pTraits::zero, // not used + + presult[facei] + ); + } + } + } + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fvc + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/fused/finiteVolume/fvcSurfaceOps.H b/src/fused/finiteVolume/fvcSurfaceOps.H new file mode 100644 index 0000000000..a5a602fc62 --- /dev/null +++ b/src/fused/finiteVolume/fvcSurfaceOps.H @@ -0,0 +1,291 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2024 M.Janssens +------------------------------------------------------------------------------- +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 . + +InNamespace + Foam::fvc + +Description + Surface integrate surfaceField creating a volField. + Surface sum a surfaceField creating a volField. + +SourceFiles + fvcSurfaceOps.C + +\*---------------------------------------------------------------------------*/ + + +#ifndef fvcSurfaceOps_H +#define fvcSurfaceOps_H + +#include "primitiveFieldsFwd.H" +#include "volFieldsFwd.H" +#include "surfaceFieldsFwd.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +//- In-place operations on Fields. Add to FieldFunctions.C ? +#define INPLACE_PRODUCT_OPERATOR(product, CombineOp, Op, OpFunc) \ + \ +template \ +void OpFunc \ +( \ + Field::type>& result, \ + const UList& f1, \ + const UList& f2 \ +) \ +{ \ + typedef typename product::type resultType; \ + TFOR_ALL_F_OP_F_OP_F \ + (resultType, result, CombineOp, Type1, f1, Op, Type2, f2) \ +} + + +INPLACE_PRODUCT_OPERATOR(outerProduct, +=, *, multiplyAdd) +INPLACE_PRODUCT_OPERATOR(outerProduct, -=, *, multiplySubtract) + +#undef INPLACE_PRODUCT_OPERATOR + + + +/*---------------------------------------------------------------------------*\ + Namespace fvc functions Declaration +\*---------------------------------------------------------------------------*/ + +namespace fvc +{ + // Interpolation + + //- Interpolate to face (using cop) and additional face field + template + void interpolate + ( + const surfaceScalarField& lambdas, + const GeometricField& vf, + const GeometricField& sf, + const CellToFaceOp& cop, + GeometricField& result + ); + + //- Interpolate to face (using cop) + template + < + class Type0, + class Type1, + class ResultType, + class CellToFaceOp + > + void interpolate + ( + const surfaceScalarField& weights, + const GeometricField& vf0, + const GeometricField& vf1, + const CellToFaceOp& cop, + GeometricField& result + ); + + + // Interpolation and accumulation + + //- Interpolate to face (using cop) and accumulate. + template + void surfaceSum + ( + const surfaceScalarField& lambdas, + const GeometricField& vf, + const CellToFaceOp& cop, + GeometricField& result, + const bool doCorrectBoundaryConditions = true + ); + + //- Interpolate to face (using cop) and accumulate. Additional + //- face field + template + void surfaceSum + ( + const surfaceScalarField& lambdas, + const GeometricField& vf, + const GeometricField& sf, + const CellToFaceOp& cop, + GeometricField& result, + const bool doCorrectBoundaryConditions = true + ); + + //- Interpolate to face (using cop) and accumulate. Additional + //- face fields + template + < + class Type, + class FType0, + class FType1, + class ResultType, + class CellToFaceOp + > + void surfaceSum + ( + const surfaceScalarField& lambdas, + const GeometricField& vf, + + const GeometricField& sf0, + const GeometricField& sf1, + + const CellToFaceOp& cop, + + GeometricField& result, + const bool doCorrectBoundaryConditions = true + ); + + //- Interpolate to face (using cop) and apply Gauss. Note: uses V(), + // not Vsc() + template + void GaussOp + ( + const surfaceScalarField& lambdas, + const GeometricField& vf, + const CellToFaceOp& cop, + GeometricField& result + ); + + + // Difference and accumulation + + //- sum of snGrad + template + void surfaceSnSum + ( + const surfaceScalarField& deltaCoeffs, + const GeometricField& vf, + + const CellToFaceOp& cop, + + GeometricField& result, + const bool doCorrectBoundaryConditions + ); + //- sum of snGrad with additional surface field + template + void surfaceSnSum + ( + const surfaceScalarField& deltaCoeffs, + const GeometricField& vf, + const GeometricField& sadd, + + const CellToFaceOp& cop, + + GeometricField& result, + const bool doCorrectBoundaryConditions + ); + + //- sum of snGrad with additional (interpolated) volField + template + void surfaceSnSum + ( + const surfaceScalarField& gammaWeights, + const GeometricField& gamma, + + const surfaceScalarField& deltaCoeffs, + const GeometricField& vf, + + const CellToFaceOp& cop, + + GeometricField& result, + const bool doCorrectBoundaryConditions + ); + + //- sum of snGrad with additional (interpolated) volfields + template + < + class Type, + class GType0, + class GType1, + class ResultType, + class CellToFaceOp + > + void surfaceSnSum + ( + const surfaceScalarField& weights, + + const GeometricField& gamma0, + const GeometricField& gamma1, + + const surfaceScalarField& deltaCoeffs, + const GeometricField& vf, + + const CellToFaceOp& cop, + + GeometricField& result, + const bool doCorrectBoundaryConditions + ); + + //- sum of snGrad with additional surface field + template + void surfaceSnSum + ( + const surfaceScalarField& gammaWeights, + const GeometricField& gamma, + + const surfaceScalarField& deltaCoeffs, + const GeometricField& vf, + + const GeometricField& sadd, + + const CellToFaceOp& cop, + + GeometricField& result, + const bool doCorrectBoundaryConditions + ); + + + // Other + + //- Interpolate to face (using cop) and apply distribution vectors + template + void surfaceOp + ( + const GeometricField& vf, + const surfaceVectorField& ownLs, + const surfaceVectorField& neiLs, + const CellToFaceOp& cop, + GeometricField& result + ); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "fvcSurfaceOps.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/U b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/U new file mode 100644 index 0000000000..1b79fa7275 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/U @@ -0,0 +1,51 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volVectorField; + object U; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 1 -1 0 0 0 0]; + +internalField uniform (0 0 0); + +boundaryField +{ + inlet + { + type fixedValue; + value uniform (10 0 0); + } + + outlet + { + type zeroGradient; + } + + upperWall + { + type noSlip; + } + + lowerWall + { + type noSlip; + } + + frontAndBack + { + type empty; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/epsilon b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/epsilon new file mode 100644 index 0000000000..ded25cfa70 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/epsilon @@ -0,0 +1,53 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object epsilon; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 2 -3 0 0 0 0]; + +internalField uniform 14.855; + +boundaryField +{ + inlet + { + type fixedValue; + value uniform 14.855; + } + + outlet + { + type zeroGradient; + } + + upperWall + { + type epsilonWallFunction; + value uniform 14.855; + } + + lowerWall + { + type epsilonWallFunction; + value uniform 14.855; + } + + frontAndBack + { + type empty; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/k b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/k new file mode 100644 index 0000000000..59ed527364 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/k @@ -0,0 +1,53 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object k; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 2 -2 0 0 0 0]; + +internalField uniform 0.375; + +boundaryField +{ + inlet + { + type fixedValue; + value uniform 0.375; + } + + outlet + { + type zeroGradient; + } + + upperWall + { + type kqRWallFunction; + value uniform 0.375; + } + + lowerWall + { + type kqRWallFunction; + value uniform 0.375; + } + + frontAndBack + { + type empty; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/nuTilda b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/nuTilda new file mode 100644 index 0000000000..dbeea21dea --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/nuTilda @@ -0,0 +1,51 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object nuTilda; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 2 -1 0 0 0 0]; + +internalField uniform 0; + +boundaryField +{ + inlet + { + type fixedValue; + value uniform 0; + } + + outlet + { + type zeroGradient; + } + + upperWall + { + type zeroGradient; + } + + lowerWall + { + type zeroGradient; + } + + frontAndBack + { + type empty; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/nut b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/nut new file mode 100644 index 0000000000..558a25b05f --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/nut @@ -0,0 +1,54 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object nut; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 2 -1 0 0 0 0]; + +internalField uniform 0; + +boundaryField +{ + inlet + { + type calculated; + value uniform 0; + } + + outlet + { + type calculated; + value uniform 0; + } + + upperWall + { + type nutkWallFunction; + value uniform 0; + } + + lowerWall + { + type nutkWallFunction; + value uniform 0; + } + + frontAndBack + { + type empty; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/omega b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/omega new file mode 100644 index 0000000000..c1b5a6b433 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/omega @@ -0,0 +1,53 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object omega; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 0 -1 0 0 0 0]; + +internalField uniform 440.15; + +boundaryField +{ + inlet + { + type fixedValue; + value $internalField; + } + + outlet + { + type zeroGradient; + } + + upperWall + { + type omegaWallFunction; + value $internalField; + } + + lowerWall + { + type omegaWallFunction; + value $internalField; + } + + frontAndBack + { + type empty; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/p b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/p new file mode 100644 index 0000000000..eca7aa93a8 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/0/p @@ -0,0 +1,51 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object p; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 2 -2 0 0 0 0]; + +internalField uniform 0; + +boundaryField +{ + inlet + { + type zeroGradient; + } + + outlet + { + type fixedValue; + value uniform 0; + } + + upperWall + { + type zeroGradient; + } + + lowerWall + { + type zeroGradient; + } + + frontAndBack + { + type empty; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/Allrun b/tutorials/incompressible/simpleFoam/pitzDaily_fused/Allrun new file mode 100755 index 0000000000..d9527fe9de --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/Allrun @@ -0,0 +1,22 @@ +#!/bin/sh +cd "${0%/*}" || exit # Run from this directory +. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions +#------------------------------------------------------------------------------ + +runApplication blockMesh + +runApplication decomposePar + +echo "Updating fvSchemes to use Gauss" +sed "s/GAUSS/Gauss/g" system/fvSchemes.template > system/fvSchemes + +runParallel -s Gauss $(getApplication) + + +echo "Updating fvSchemes to use fusedGauss" +sed "s/GAUSS/fusedGauss/g" system/fvSchemes.template > system/fvSchemes + +runParallel -s fusedGauss $(getApplication) + + +#------------------------------------------------------------------------------ diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/README b/tutorials/incompressible/simpleFoam/pitzDaily_fused/README new file mode 100644 index 0000000000..7b902e8b78 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/README @@ -0,0 +1,4 @@ +Testing fused discretisation +============================ + +Runs both standard Gauss and 'fused' Gauss diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/constant/transportProperties b/tutorials/incompressible/simpleFoam/pitzDaily_fused/constant/transportProperties new file mode 100644 index 0000000000..5818777c87 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/constant/transportProperties @@ -0,0 +1,22 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object transportProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +transportModel Newtonian; + +nu 1e-05; + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/constant/turbulenceProperties b/tutorials/incompressible/simpleFoam/pitzDaily_fused/constant/turbulenceProperties new file mode 100644 index 0000000000..f4d56f742f --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/constant/turbulenceProperties @@ -0,0 +1,31 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object turbulenceProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +simulationType RAS; + +RAS +{ + // Tested with kEpsilon, realizableKE, kOmega, kOmegaSST, + // ShihQuadraticKE, LienCubicKE. + RASModel kEpsilon; + + turbulence on; + + printCoeffs on; +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/blockMeshDict b/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/blockMeshDict new file mode 100644 index 0000000000..7709136f71 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/blockMeshDict @@ -0,0 +1,153 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object blockMeshDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +scale 0.001; + +vertices +( + (-20.6 0 -0.5) + (-20.6 25.4 -0.5) + (0 -25.4 -0.5) + (0 0 -0.5) + (0 25.4 -0.5) + (206 -25.4 -0.5) + (206 0 -0.5) + (206 25.4 -0.5) + (290 -16.6 -0.5) + (290 0 -0.5) + (290 16.6 -0.5) + + (-20.6 0 0.5) + (-20.6 25.4 0.5) + (0 -25.4 0.5) + (0 0 0.5) + (0 25.4 0.5) + (206 -25.4 0.5) + (206 0 0.5) + (206 25.4 0.5) + (290 -16.6 0.5) + (290 0 0.5) + (290 16.6 0.5) +); + +negY +( + (2 4 1) + (1 3 0.3) +); + +posY +( + (1 4 2) + (2 3 4) + (2 4 0.25) +); + +posYR +( + (2 1 1) + (1 1 0.25) +); + + +blocks +( + hex (0 3 4 1 11 14 15 12) + (18 30 1) + simpleGrading (0.5 $posY 1) + + hex (2 5 6 3 13 16 17 14) + (180 27 1) + edgeGrading (4 4 4 4 $negY 1 1 $negY 1 1 1 1) + + hex (3 6 7 4 14 17 18 15) + (180 30 1) + edgeGrading (4 4 4 4 $posY $posYR $posYR $posY 1 1 1 1) + + hex (5 8 9 6 16 19 20 17) + (25 27 1) + simpleGrading (2.5 1 1) + + hex (6 9 10 7 17 20 21 18) + (25 30 1) + simpleGrading (2.5 $posYR 1) +); + +edges +( +); + +boundary +( + inlet + { + type patch; + faces + ( + (0 1 12 11) + ); + } + outlet + { + type patch; + faces + ( + (8 9 20 19) + (9 10 21 20) + ); + } + upperWall + { + type wall; + faces + ( + (1 4 15 12) + (4 7 18 15) + (7 10 21 18) + ); + } + lowerWall + { + type wall; + faces + ( + (0 3 14 11) + (3 2 13 14) + (2 5 16 13) + (5 8 19 16) + ); + } + frontAndBack + { + type empty; + faces + ( + (0 3 4 1) + (2 5 6 3) + (3 6 7 4) + (5 8 9 6) + (6 9 10 7) + (11 14 15 12) + (13 16 17 14) + (14 17 18 15) + (16 19 20 17) + (17 20 21 18) + ); + } +); + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/controlDict b/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/controlDict new file mode 100644 index 0000000000..b5a4be57ca --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/controlDict @@ -0,0 +1,49 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object controlDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +libs (fusedFiniteVolume); + +application simpleFoam; + +startFrom startTime; + +startTime 0; + +stopAt endTime; + +endTime 200; + +deltaT 1; + +writeControl timeStep; + +writeInterval 100000; + +purgeWrite 0; + +writeFormat binary; + +writePrecision 16; + +writeCompression off; + +timeFormat general; + +timePrecision 6; + +runTimeModifiable true; + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/decomposeParDict b/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/decomposeParDict new file mode 100644 index 0000000000..6bf14cb563 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/decomposeParDict @@ -0,0 +1,25 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + note "mesh decomposition control dictionary"; + object decomposeParDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- The total number of domains (mandatory) +numberOfSubdomains 5; + +//- The decomposition method (mandatory) +method hierarchical; +n (5 1 1); + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/fvSchemes b/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/fvSchemes new file mode 100644 index 0000000000..0bf667bfe7 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/fvSchemes @@ -0,0 +1,63 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object fvSchemes; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +ddtSchemes +{ + default steadyState; +} + +gradSchemes +{ + default fusedGauss linear; +} + +divSchemes +{ + default none; + + div(phi,U) bounded fusedGauss linearUpwind grad(U); + + turbulence bounded fusedGauss limitedLinear 1; + div(phi,k) $turbulence; + div(phi,epsilon) $turbulence; + div(phi,omega) $turbulence; + + div(nonlinearStress) fusedGauss linear; + div((nuEff*dev2(T(grad(U))))) fusedGauss linear; +} + +laplacianSchemes +{ + default fusedGauss linear corrected; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default corrected; +} + +wallDist +{ + method meshWave; +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/fvSchemes.template b/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/fvSchemes.template new file mode 100644 index 0000000000..fd4bfa0f45 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/fvSchemes.template @@ -0,0 +1,63 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object fvSchemes; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +ddtSchemes +{ + default steadyState; +} + +gradSchemes +{ + default GAUSS linear; +} + +divSchemes +{ + default none; + + div(phi,U) bounded GAUSS linearUpwind grad(U); + + turbulence bounded GAUSS limitedLinear 1; + div(phi,k) $turbulence; + div(phi,epsilon) $turbulence; + div(phi,omega) $turbulence; + + div(nonlinearStress) GAUSS linear; + div((nuEff*dev2(T(grad(U))))) GAUSS linear; +} + +laplacianSchemes +{ + default GAUSS linear corrected; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default corrected; +} + +wallDist +{ + method meshWave; +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/fvSolution b/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/fvSolution new file mode 100644 index 0000000000..008818739a --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pitzDaily_fused/system/fvSolution @@ -0,0 +1,59 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2406 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object fvSolution; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solvers +{ + p + { + solver GAMG; + tolerance 1e-06; + relTol 0.1; + smoother GaussSeidel; + } + + "(U|k|epsilon|omega|f|v2)" + { + solver smoothSolver; + smoother symGaussSeidel; + tolerance 1e-05; + relTol 0.1; + } +} + +SIMPLE +{ + nNonOrthogonalCorrectors 0; + consistent yes; + + residualControl + { + p 1e-2; + U 1e-3; + "(k|epsilon|omega|f|v2)" 1e-3; + } +} + +relaxationFactors +{ + equations + { + U 0.9; // 0.9 is more stable but 0.95 more convergent + ".*" 0.9; // 0.9 is more stable but 0.95 more convergent + } +} + + +// ************************************************************************* //