From 578cb2b67c109d3a220ce2bf1ca2aa1aecf5e7ae Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 30 May 2024 17:19:54 +0100 Subject: [PATCH 1/4] INT: Integration of gmresSolver from foam-extend (http://www.foam-extend.org) --- src/OpenFOAM/Make/files | 1 + .../lduMatrix/solvers/GMRES/gmresSolver.C | 320 ++++++++++++++++++ .../lduMatrix/solvers/GMRES/gmresSolver.H | 140 ++++++++ 3 files changed, 461 insertions(+) create mode 100644 src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.C create mode 100644 src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.H diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 3c99495537..63f621101a 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -445,6 +445,7 @@ $(lduMatrix)/solvers/PBiCGStab/PBiCGStab.C $(lduMatrix)/solvers/FPCG/FPCG.C $(lduMatrix)/solvers/PPCG/PPCG.C $(lduMatrix)/solvers/PPCR/PPCR.C +$(lduMatrix)/solvers/GMRES/gmresSolver.C $(lduMatrix)/smoothers/GaussSeidel/GaussSeidelSmoother.C $(lduMatrix)/smoothers/symGaussSeidel/symGaussSeidelSmoother.C diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.C new file mode 100644 index 0000000000..c0c9f4c622 --- /dev/null +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.C @@ -0,0 +1,320 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2010-2015 Hrvoje Jasak, Wikki 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 . + +Description + Preconditioned Generalised Minimal Residual solver with + run-time selectable preconditioning + +\*---------------------------------------------------------------------------*/ + +#include "gmresSolver.H" +#include "scalarMatrices.H" +#include "PrecisionAdaptor.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(gmresSolver, 0); + + lduMatrix::solver::addsymMatrixConstructorToTable + addgmresSolverSymMatrixConstructorToTable_; + + lduMatrix::solver::addasymMatrixConstructorToTable + addgmresSolverAsymMatrixConstructorToTable_; + +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::gmresSolver::givensRotation +( + const solveScalar& h, + const solveScalar& beta, + solveScalar& c, + solveScalar& s +) const +{ + if (beta == 0) + { + c = 1; + s = 0; + } + else if (mag(beta) > mag(h)) + { + scalar tau = -h/beta; + s = 1.0/Foam::sqrt(1.0 + sqr(tau)); + c = s*tau; + } + else + { + scalar tau = -beta/h; + c = 1.0/Foam::sqrt(1.0 + sqr(tau)); + s = c*tau; + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +//- Construct from matrix and solver data stream +Foam::gmresSolver::gmresSolver +( + const word& fieldName, + const lduMatrix& matrix, + const FieldField& coupleBouCoeffs, + const FieldField& coupleIntCoeffs, + const lduInterfaceFieldPtrsList& interfaces, + const dictionary& dict +) +: + lduMatrix::solver + ( + fieldName, + matrix, + coupleBouCoeffs, + coupleIntCoeffs, + interfaces, + dict + ), + preconPtr_ + ( + lduMatrix::preconditioner::New + ( + *this, + dict + ) + ), + nDirs_(readLabel(dict.lookup("nDirections"))) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::solverPerformance Foam::gmresSolver::scalarSolve +( + solveScalarField& x, + const solveScalarField& b, + const direction cmpt +) const +{ + // Prepare solver performance + solverPerformance solverPerf + ( + preconPtr_->type() + typeName, fieldName() + ); + + solveScalarField wA(x.size()); + solveScalarField rA(x.size()); + + // Calculate initial residual + matrix_.Amul(wA, x, interfaceBouCoeffs_, interfaces_, cmpt); + + // Use rA as scratch space when calculating the normalisation factor + solveScalar normFactor = this->normFactor(x, b, wA, rA); + + if (lduMatrix::debug >= 2) + { + Info<< " Normalisation factor = " << normFactor << endl; + } + + // Calculate residual + forAll (rA, i) + { + rA[i] = b[i] - wA[i]; + } + + solverPerf.initialResidual() = + gSumMag(rA, matrix().mesh().comm()) + /normFactor; + solverPerf.finalResidual() = solverPerf.initialResidual(); + + // Note: GMRES cannot be forced to do minIter sweeps + // if the residual is zero, due to algorithmic reasons + // HJ, 22/Aug/2012 + //if (!converged(solverPerf)) + if (!solverPerf.checkConvergence(tolerance_, relTol_, log_)) +// if (!stop(solverPerf)) + { + typedef SquareMatrix solveScalarSquareMatrix; + + // Create the Hesenberg matrix + solveScalarSquareMatrix H(nDirs_, 0); + + // Create y and b for Hessenberg matrix + solveScalarField yh(nDirs_, 0); + solveScalarField bh(nDirs_ + 1, 0); + + // Givens rotation vectors + solveScalarField c(nDirs_, 0); + solveScalarField s(nDirs_, 0); + + // Allocate Krylov space vectors + FieldField V(nDirs_ + 1); + + forAll (V, i) + { + V.set(i, new solveScalarField(x.size(), 0)); + } + + do + { + // Execute preconditioning + preconPtr_->precondition(wA, rA, cmpt); + + // Calculate beta and scale first vector + solveScalar beta = Foam::sqrt(gSumSqr(wA, matrix().mesh().comm())); + + // Set initial rhs and bh[0] = beta + bh = 0; + bh[0] = beta; + + for (label i = 0; i < nDirs_; i++) + { + // Set search direction + V[i] = wA; + V[i] /= beta; + + // Arnoldi's method + matrix_.Amul(rA, V[i], interfaceBouCoeffs_, interfaces_, cmpt); + + // Execute preconditioning + preconPtr_->precondition(wA, rA, cmpt); + + for (label j = 0; j <= i; j++) + { + beta = gSumProd(wA, V[j], matrix().mesh().comm()); + + H[j][i] = beta; + + forAll (wA, wI) + { + wA[wI] -= beta*V[j][wI]; + } + } + + beta = Foam::sqrt(gSumSqr(wA, matrix().mesh().comm())); + + // Apply previous Givens rotations to new column of H. + for (label j = 0; j < i; j++) + { + const solveScalar Hji = H[j][i]; + H[j][i] = c[j]*Hji - s[j]*H[j + 1][i]; + H[j + 1][i] = s[j]*Hji + c[j]*H[j + 1][i]; + } + + // Apply Givens rotation to current row. + givensRotation(H[i][i], beta, c[i], s[i]); + + const solveScalar bhi = bh[i]; + bh[i] = c[i]*bhi - s[i]*bh[i + 1]; + bh[i + 1] = s[i]*bhi + c[i]*bh[i + 1]; + H[i][i] = c[i]*H[i][i] - s[i]*beta; + } + + // Back substitute to solve Hy = b + for (label i = nDirs_ - 1; i >= 0; i--) + { + solveScalar sum = bh[i]; + + for (label j = i + 1; j < nDirs_; j++) + { + sum -= H[i][j]*yh[j]; + } + + yh[i] = sum/H[i][i]; + } + + // Update solution + + for (label i = 0; i < nDirs_; i++) + { + const solveScalarField& Vi = V[i]; + const solveScalar& yi = yh[i]; + + forAll (x, psiI) + { + x[psiI] += yi*Vi[psiI]; + } + } + + // Re-calculate the residual + matrix_.Amul(wA, x, interfaceBouCoeffs_, interfaces_, cmpt); + + forAll (rA, raI) + { + rA[raI] = b[raI] - wA[raI]; + } + + solverPerf.finalResidual() = + gSumMag(rA, matrix().mesh().comm()) + /normFactor; + solverPerf.nIterations()++; + } while //(!stop(solverPerf)); + ( + ( + ++solverPerf.nIterations() < maxIter_ + && !solverPerf.checkConvergence(tolerance_, relTol_, log_) + ) + || solverPerf.nIterations() < minIter_ + ); + } + + + if (preconPtr_) + { + preconPtr_->setFinished(solverPerf); + } + + matrix().setResidualField + ( + ConstPrecisionAdaptor(rA)(), + fieldName_, + false + ); + + return solverPerf; +} + + +Foam::solverPerformance Foam::gmresSolver::solve +( + scalarField& psi_s, + const scalarField& source, + const direction cmpt +) const +{ + PrecisionAdaptor tpsi(psi_s); + return scalarSolve + ( + tpsi.ref(), + ConstPrecisionAdaptor(source)(), + cmpt + ); +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.H b/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.H new file mode 100644 index 0000000000..714a88ec5a --- /dev/null +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.H @@ -0,0 +1,140 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2010-2015 Hrvoje Jasak, Wikki 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 + gmresSolver + +Group + grpLduMatrixSolvers + +Description + Preconditioned Generalised Minimal Residual solver with + run-time selectable preconditioning + +SourceFiles + gmresSolver.C + +\*---------------------------------------------------------------------------*/ + +#ifndef gmresSolver_H +#define gmresSolver_H + +#include "lduMatrix.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class gmresSolver Declaration +\*---------------------------------------------------------------------------*/ + +class gmresSolver +: + public lduMatrix::solver +{ + // Private Data + + //- Preconditioner + autoPtr preconPtr_; + + //- Krylov space dimension + label nDirs_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + gmresSolver(const gmresSolver&) = delete; + + //- Disallow default bitwise assignment + void operator=(const gmresSolver&) = delete; + + + //- Givens rotation + void givensRotation + ( + const solveScalar& H, + const solveScalar& beta, + solveScalar& c, + solveScalar& s + ) const; + + +public: + + //- Runtime type information + TypeName("GMRES"); + + + // Constructors + + //- Construct from matrix components and solver data stream + gmresSolver + ( + const word& fieldName, + const lduMatrix& matrix, + const FieldField& coupleBouCoeffs, + const FieldField& coupleIntCoeffs, + const lduInterfaceFieldPtrsList& interfaces, + const dictionary& dict + ); + + + // Destructor + + virtual ~gmresSolver() = default; + + + // Member Functions + + //- Solve the matrix with this solver + virtual solverPerformance scalarSolve + ( + solveScalarField& psi, + const solveScalarField& source, + const direction cmpt=0 + ) const; + + //- Solve the matrix with this solver + virtual solverPerformance solve + ( + scalarField& x, + const scalarField& b, + const direction cmpt = 0 + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // From ab1788ae337fd96aa1ec3b404873b1a4d86848c6 Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 3 Jun 2024 12:29:04 +0100 Subject: [PATCH 2/4] ENH: simpleFoam: added gmres-using case. --- .../incompressible/simpleFoam/longPipe/0/U | 51 +++++++++++ .../incompressible/simpleFoam/longPipe/0/p | 51 +++++++++++ .../incompressible/simpleFoam/longPipe/Allrun | 12 +++ .../longPipe/constant/transportProperties | 22 +++++ .../longPipe/constant/turbulenceProperties | 19 ++++ .../simpleFoam/longPipe/system/blockMeshDict | 86 +++++++++++++++++++ .../simpleFoam/longPipe/system/controlDict | 48 +++++++++++ .../longPipe/system/decomposeParDict | 24 ++++++ .../simpleFoam/longPipe/system/fvSchemes | 63 ++++++++++++++ .../simpleFoam/longPipe/system/fvSolution | 76 ++++++++++++++++ 10 files changed, 452 insertions(+) create mode 100644 tutorials/incompressible/simpleFoam/longPipe/0/U create mode 100644 tutorials/incompressible/simpleFoam/longPipe/0/p create mode 100755 tutorials/incompressible/simpleFoam/longPipe/Allrun create mode 100644 tutorials/incompressible/simpleFoam/longPipe/constant/transportProperties create mode 100644 tutorials/incompressible/simpleFoam/longPipe/constant/turbulenceProperties create mode 100644 tutorials/incompressible/simpleFoam/longPipe/system/blockMeshDict create mode 100644 tutorials/incompressible/simpleFoam/longPipe/system/controlDict create mode 100644 tutorials/incompressible/simpleFoam/longPipe/system/decomposeParDict create mode 100644 tutorials/incompressible/simpleFoam/longPipe/system/fvSchemes create mode 100644 tutorials/incompressible/simpleFoam/longPipe/system/fvSolution diff --git a/tutorials/incompressible/simpleFoam/longPipe/0/U b/tutorials/incompressible/simpleFoam/longPipe/0/U new file mode 100644 index 0000000000..e6d9abdf7d --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/0/U @@ -0,0 +1,51 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2312 | +| \\ / 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 (0.1 0 0); + } + + outlet + { + type zeroGradient; + } + + upperWall + { + type noSlip; + } + + lowerWall + { + type noSlip; + } + + frontAndBack + { + type empty; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/longPipe/0/p b/tutorials/incompressible/simpleFoam/longPipe/0/p new file mode 100644 index 0000000000..da1f59277f --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/0/p @@ -0,0 +1,51 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2312 | +| \\ / 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/longPipe/Allrun b/tutorials/incompressible/simpleFoam/longPipe/Allrun new file mode 100755 index 0000000000..91af870cc9 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/Allrun @@ -0,0 +1,12 @@ +#!/bin/sh +cd "${0%/*}" || exit # Run from this directory +. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions +#------------------------------------------------------------------------------ + +runApplication blockMesh + +SOLVER=PCG runApplication -s PCG $(getApplication) -debug-switch SolverPerformance=2 + +SOLVER=GMRES runApplication -s GMRES $(getApplication) -debug-switch SolverPerformance=2 + +#------------------------------------------------------------------------------ diff --git a/tutorials/incompressible/simpleFoam/longPipe/constant/transportProperties b/tutorials/incompressible/simpleFoam/longPipe/constant/transportProperties new file mode 100644 index 0000000000..4908cd4b36 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/constant/transportProperties @@ -0,0 +1,22 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2312 | +| \\ / 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/longPipe/constant/turbulenceProperties b/tutorials/incompressible/simpleFoam/longPipe/constant/turbulenceProperties new file mode 100644 index 0000000000..08d5a78ccd --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/constant/turbulenceProperties @@ -0,0 +1,19 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2312 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object turbulenceProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +simulationType laminar; + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/longPipe/system/blockMeshDict b/tutorials/incompressible/simpleFoam/longPipe/system/blockMeshDict new file mode 100644 index 0000000000..3daae0ec53 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/system/blockMeshDict @@ -0,0 +1,86 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2312 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object blockMeshDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +scale 0.001; + +vertices +( + ( 0 0 0) + ( 300 0 0) + ( 300 3 0) + ( 0 3 0) + ( 0 0 3) + ( 300 0 3) + ( 300 3 3) + ( 0 3 3) +); + +blocks +( + hex (0 1 2 3 4 5 6 7) (300 300 1) simpleGrading (1 1 1) +); + +edges +( +); + +boundary +( + inlet + { + type patch; + faces + ( + (0 4 7 3) + ); + } + outlet + { + type patch; + faces + ( + (2 6 5 1) + ); + } + upperWall + { + type wall; + faces + ( + (3 7 6 2) + ); + } + lowerWall + { + type wall; + faces + ( + (1 5 4 0) + ); + } + frontAndBack + { + type empty; + faces + ( + (0 3 2 1) + (4 5 6 7) + ); + } +); + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/longPipe/system/controlDict b/tutorials/incompressible/simpleFoam/longPipe/system/controlDict new file mode 100644 index 0000000000..c367d40a90 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/system/controlDict @@ -0,0 +1,48 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2312 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object controlDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +application simpleFoam; + +startFrom startTime; + +startTime 0; + +stopAt endTime; + +endTime 500; + +deltaT 1; + +writeControl timeStep; + +writeInterval 10; + +purgeWrite 0; + +writeFormat ascii; + +writePrecision 6; + +writeCompression off; + +timeFormat general; + +timePrecision 6; + +runTimeModifiable true; + + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/longPipe/system/decomposeParDict b/tutorials/incompressible/simpleFoam/longPipe/system/decomposeParDict new file mode 100644 index 0000000000..355ffe5aa1 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/system/decomposeParDict @@ -0,0 +1,24 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2306 | +| \\ / 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 4; + +//- The decomposition method (mandatory) +method scotch; + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/longPipe/system/fvSchemes b/tutorials/incompressible/simpleFoam/longPipe/system/fvSchemes new file mode 100644 index 0000000000..34b7d87bd9 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/system/fvSchemes @@ -0,0 +1,63 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2312 | +| \\ / 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/longPipe/system/fvSolution b/tutorials/incompressible/simpleFoam/longPipe/system/fvSolution new file mode 100644 index 0000000000..b18517edc7 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/system/fvSolution @@ -0,0 +1,76 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2312 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object fvSolution; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solvers +{ + p + { + tolerance 1e-06; + relTol 0.1; + + /* + solver GAMG; + smoother GaussSeidel; + + // Explicit specify solver for coarse-level correction to override + // solution tolerance + coarsestLevelCorr + { + // For limited residual reduction (relTol) PPCR behaves better + // than PCG (or PPCG) + solver PCG; + preconditioner DIC; + //relTol 0.05; + } + */ + solver ${SOLVER}; + nDirections 100; + preconditioner DIC; + } + + "(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 + } +} + + +// ************************************************************************* // From 44f85501857b0c0b583bda924232262f98e6db10 Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Tue, 4 Jun 2024 09:50:50 +0100 Subject: [PATCH 3/4] (Merge) TUT: longPipe: style changes --- .../simpleFoam/longPipe/{0 => 0.orig}/U | 3 +- .../simpleFoam/longPipe/{0 => 0.orig}/p | 3 +- .../simpleFoam/longPipe/Allclean | 8 +++++ .../incompressible/simpleFoam/longPipe/Allrun | 6 ++-- .../simpleFoam/longPipe/Allrun-parallel | 14 ++++++++ .../simpleFoam/longPipe/Allrun.pre | 10 ++++++ .../longPipe/constant/transportProperties | 3 +- .../longPipe/constant/turbulenceProperties | 2 +- .../simpleFoam/longPipe/system/blockMeshDict | 7 +--- .../simpleFoam/longPipe/system/controlDict | 5 ++- .../longPipe/system/decomposeParDict | 14 ++++---- .../simpleFoam/longPipe/system/fvSchemes | 4 +-- .../simpleFoam/longPipe/system/fvSolution | 33 +++++-------------- 13 files changed, 59 insertions(+), 53 deletions(-) rename tutorials/incompressible/simpleFoam/longPipe/{0 => 0.orig}/U (94%) rename tutorials/incompressible/simpleFoam/longPipe/{0 => 0.orig}/p (94%) create mode 100755 tutorials/incompressible/simpleFoam/longPipe/Allclean create mode 100755 tutorials/incompressible/simpleFoam/longPipe/Allrun-parallel create mode 100755 tutorials/incompressible/simpleFoam/longPipe/Allrun.pre diff --git a/tutorials/incompressible/simpleFoam/longPipe/0/U b/tutorials/incompressible/simpleFoam/longPipe/0.orig/U similarity index 94% rename from tutorials/incompressible/simpleFoam/longPipe/0/U rename to tutorials/incompressible/simpleFoam/longPipe/0.orig/U index e6d9abdf7d..62fa184d22 100644 --- a/tutorials/incompressible/simpleFoam/longPipe/0/U +++ b/tutorials/incompressible/simpleFoam/longPipe/0.orig/U @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2312 | +| \\ / O peration | Version: v2403 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -47,5 +47,4 @@ boundaryField } } - // ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/longPipe/0/p b/tutorials/incompressible/simpleFoam/longPipe/0.orig/p similarity index 94% rename from tutorials/incompressible/simpleFoam/longPipe/0/p rename to tutorials/incompressible/simpleFoam/longPipe/0.orig/p index da1f59277f..5fbdf1f0ad 100644 --- a/tutorials/incompressible/simpleFoam/longPipe/0/p +++ b/tutorials/incompressible/simpleFoam/longPipe/0.orig/p @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2312 | +| \\ / O peration | Version: v2403 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -47,5 +47,4 @@ boundaryField } } - // ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/longPipe/Allclean b/tutorials/incompressible/simpleFoam/longPipe/Allclean new file mode 100755 index 0000000000..fb1f384730 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/Allclean @@ -0,0 +1,8 @@ +#!/bin/sh +cd "${0%/*}" || exit # Run from this directory +. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions +#------------------------------------------------------------------------------ + +cleanCase0 + +#------------------------------------------------------------------------------ diff --git a/tutorials/incompressible/simpleFoam/longPipe/Allrun b/tutorials/incompressible/simpleFoam/longPipe/Allrun index 91af870cc9..9a6a746f3d 100755 --- a/tutorials/incompressible/simpleFoam/longPipe/Allrun +++ b/tutorials/incompressible/simpleFoam/longPipe/Allrun @@ -3,10 +3,10 @@ cd "${0%/*}" || exit # Run from this directory . ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions #------------------------------------------------------------------------------ -runApplication blockMesh +./Allrun.pre -SOLVER=PCG runApplication -s PCG $(getApplication) -debug-switch SolverPerformance=2 +SOLVER=PCG runApplication -s PCG $(getApplication) # -debug-switch SolverPerformance=2 -SOLVER=GMRES runApplication -s GMRES $(getApplication) -debug-switch SolverPerformance=2 +SOLVER=GMRES runApplication -s GMRES $(getApplication) # -debug-switch SolverPerformance=2 #------------------------------------------------------------------------------ diff --git a/tutorials/incompressible/simpleFoam/longPipe/Allrun-parallel b/tutorials/incompressible/simpleFoam/longPipe/Allrun-parallel new file mode 100755 index 0000000000..4a85b64ba4 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/Allrun-parallel @@ -0,0 +1,14 @@ +#!/bin/sh +cd "${0%/*}" || exit # Run from this directory +. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions +#------------------------------------------------------------------------------ + +./Allrun.pre + +runApplication decomposePar + +SOLVER=PCG runParallel -s PCG $(getApplication) # -debug-switch SolverPerformance=2 + +SOLVER=GMRES runParallel -s GMRES $(getApplication) # -debug-switch SolverPerformance=2 + +#------------------------------------------------------------------------------ diff --git a/tutorials/incompressible/simpleFoam/longPipe/Allrun.pre b/tutorials/incompressible/simpleFoam/longPipe/Allrun.pre new file mode 100755 index 0000000000..48a84b613a --- /dev/null +++ b/tutorials/incompressible/simpleFoam/longPipe/Allrun.pre @@ -0,0 +1,10 @@ +#!/bin/sh +cd "${0%/*}" || exit # Run from this directory +. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions +#------------------------------------------------------------------------------ + +restore0Dir + +runApplication blockMesh + +#------------------------------------------------------------------------------ diff --git a/tutorials/incompressible/simpleFoam/longPipe/constant/transportProperties b/tutorials/incompressible/simpleFoam/longPipe/constant/transportProperties index 4908cd4b36..301d0b28bf 100644 --- a/tutorials/incompressible/simpleFoam/longPipe/constant/transportProperties +++ b/tutorials/incompressible/simpleFoam/longPipe/constant/transportProperties @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2312 | +| \\ / O peration | Version: v2403 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -18,5 +18,4 @@ transportModel Newtonian; nu 1e-05; - // ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/longPipe/constant/turbulenceProperties b/tutorials/incompressible/simpleFoam/longPipe/constant/turbulenceProperties index 08d5a78ccd..037c28e40b 100644 --- a/tutorials/incompressible/simpleFoam/longPipe/constant/turbulenceProperties +++ b/tutorials/incompressible/simpleFoam/longPipe/constant/turbulenceProperties @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2312 | +| \\ / O peration | Version: v2403 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ diff --git a/tutorials/incompressible/simpleFoam/longPipe/system/blockMeshDict b/tutorials/incompressible/simpleFoam/longPipe/system/blockMeshDict index 3daae0ec53..b06e1abad3 100644 --- a/tutorials/incompressible/simpleFoam/longPipe/system/blockMeshDict +++ b/tutorials/incompressible/simpleFoam/longPipe/system/blockMeshDict @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2312 | +| \\ / O peration | Version: v2403 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -33,10 +33,6 @@ blocks hex (0 1 2 3 4 5 6 7) (300 300 1) simpleGrading (1 1 1) ); -edges -( -); - boundary ( inlet @@ -82,5 +78,4 @@ boundary } ); - // ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/longPipe/system/controlDict b/tutorials/incompressible/simpleFoam/longPipe/system/controlDict index c367d40a90..b1d5786434 100644 --- a/tutorials/incompressible/simpleFoam/longPipe/system/controlDict +++ b/tutorials/incompressible/simpleFoam/longPipe/system/controlDict @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2312 | +| \\ / O peration | Version: v2403 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -42,7 +42,6 @@ timeFormat general; timePrecision 6; -runTimeModifiable true; - +runTimeModifiable false; // ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/longPipe/system/decomposeParDict b/tutorials/incompressible/simpleFoam/longPipe/system/decomposeParDict index 355ffe5aa1..3fa8ef92a4 100644 --- a/tutorials/incompressible/simpleFoam/longPipe/system/decomposeParDict +++ b/tutorials/incompressible/simpleFoam/longPipe/system/decomposeParDict @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2306 | +| \\ / O peration | Version: v2403 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -10,15 +10,17 @@ FoamFile version 2.0; format ascii; class dictionary; - note "mesh decomposition control dictionary"; object decomposeParDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -//- The total number of domains (mandatory) -numberOfSubdomains 4; +numberOfSubdomains 2; -//- The decomposition method (mandatory) -method scotch; +method hierarchical; + +coeffs +{ + n (2 1 1); +} // ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/longPipe/system/fvSchemes b/tutorials/incompressible/simpleFoam/longPipe/system/fvSchemes index 34b7d87bd9..78ff4a473a 100644 --- a/tutorials/incompressible/simpleFoam/longPipe/system/fvSchemes +++ b/tutorials/incompressible/simpleFoam/longPipe/system/fvSchemes @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2312 | +| \\ / O peration | Version: v2403 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -35,7 +35,6 @@ divSchemes div(phi,epsilon) $turbulence; div(phi,omega) $turbulence; - div(nonlinearStress) Gauss linear; div((nuEff*dev2(T(grad(U))))) Gauss linear; } @@ -59,5 +58,4 @@ wallDist method meshWave; } - // ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/longPipe/system/fvSolution b/tutorials/incompressible/simpleFoam/longPipe/system/fvSolution index b18517edc7..eb4fe5b8f8 100644 --- a/tutorials/incompressible/simpleFoam/longPipe/system/fvSolution +++ b/tutorials/incompressible/simpleFoam/longPipe/system/fvSolution @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2312 | +| \\ / O peration | Version: v2403 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -18,30 +18,14 @@ solvers { p { + solver ${SOLVER}; + preconditioner DIC; + nDirections 100; tolerance 1e-06; relTol 0.1; - - /* - solver GAMG; - smoother GaussSeidel; - - // Explicit specify solver for coarse-level correction to override - // solution tolerance - coarsestLevelCorr - { - // For limited residual reduction (relTol) PPCR behaves better - // than PCG (or PPCG) - solver PCG; - preconditioner DIC; - //relTol 0.05; - } - */ - solver ${SOLVER}; - nDirections 100; - preconditioner DIC; } - "(U|k|epsilon|omega|f|v2)" + "(U|k|epsilon|omega)" { solver smoothSolver; smoother symGaussSeidel; @@ -59,7 +43,7 @@ SIMPLE { p 1e-2; U 1e-3; - "(k|epsilon|omega|f|v2)" 1e-3; + "(k|epsilon|omega)" 1e-3; } } @@ -67,10 +51,9 @@ 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 + U 0.9; + ".*" 0.9; } } - // ************************************************************************* // From fc20aa1c4d21cd1434fd55544e92cac5933d9c57 Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Wed, 5 Jun 2024 11:39:03 +0100 Subject: [PATCH 4/4] (Merge): INT: Integration of gmresSolver from foam-extend --- .../lduMatrix/solvers/GMRES/gmresSolver.C | 19 +++++++--------- .../lduMatrix/solvers/GMRES/gmresSolver.H | 22 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.C index c0c9f4c622..362b347af6 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.C @@ -108,7 +108,7 @@ Foam::gmresSolver::gmresSolver dict ) ), - nDirs_(readLabel(dict.lookup("nDirections"))) + nDirs_(dict.getLabel("nDirections")) {} @@ -121,7 +121,7 @@ Foam::solverPerformance Foam::gmresSolver::scalarSolve const direction cmpt ) const { - // Prepare solver performance + // Initialise the solverPerformance object to track solver performance solverPerformance solverPerf ( preconPtr_->type() + typeName, fieldName() @@ -155,9 +155,7 @@ Foam::solverPerformance Foam::gmresSolver::scalarSolve // Note: GMRES cannot be forced to do minIter sweeps // if the residual is zero, due to algorithmic reasons // HJ, 22/Aug/2012 - //if (!converged(solverPerf)) if (!solverPerf.checkConvergence(tolerance_, relTol_, log_)) -// if (!stop(solverPerf)) { typedef SquareMatrix solveScalarSquareMatrix; @@ -192,7 +190,7 @@ Foam::solverPerformance Foam::gmresSolver::scalarSolve bh = 0; bh[0] = beta; - for (label i = 0; i < nDirs_; i++) + for (label i = 0; i < nDirs_; ++i) { // Set search direction V[i] = wA; @@ -204,7 +202,7 @@ Foam::solverPerformance Foam::gmresSolver::scalarSolve // Execute preconditioning preconPtr_->precondition(wA, rA, cmpt); - for (label j = 0; j <= i; j++) + for (label j = 0; j <= i; ++j) { beta = gSumProd(wA, V[j], matrix().mesh().comm()); @@ -219,7 +217,7 @@ Foam::solverPerformance Foam::gmresSolver::scalarSolve beta = Foam::sqrt(gSumSqr(wA, matrix().mesh().comm())); // Apply previous Givens rotations to new column of H. - for (label j = 0; j < i; j++) + for (label j = 0; j < i; ++j) { const solveScalar Hji = H[j][i]; H[j][i] = c[j]*Hji - s[j]*H[j + 1][i]; @@ -240,7 +238,7 @@ Foam::solverPerformance Foam::gmresSolver::scalarSolve { solveScalar sum = bh[i]; - for (label j = i + 1; j < nDirs_; j++) + for (label j = i + 1; j < nDirs_; ++j) { sum -= H[i][j]*yh[j]; } @@ -249,8 +247,7 @@ Foam::solverPerformance Foam::gmresSolver::scalarSolve } // Update solution - - for (label i = 0; i < nDirs_; i++) + for (label i = 0; i < nDirs_; ++i) { const solveScalarField& Vi = V[i]; const solveScalar& yi = yh[i]; @@ -273,7 +270,7 @@ Foam::solverPerformance Foam::gmresSolver::scalarSolve gSumMag(rA, matrix().mesh().comm()) /normFactor; solverPerf.nIterations()++; - } while //(!stop(solverPerf)); + } while ( ( ++solverPerf.nIterations() < maxIter_ diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.H b/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.H index 714a88ec5a..0e069d151a 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.H +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GMRES/gmresSolver.H @@ -38,8 +38,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef gmresSolver_H -#define gmresSolver_H +#ifndef Foam_gmresSolver_H +#define Foam_gmresSolver_H #include "lduMatrix.H" @@ -65,15 +65,6 @@ class gmresSolver label nDirs_; - // Private Member Functions - - //- Disallow default bitwise copy construct - gmresSolver(const gmresSolver&) = delete; - - //- Disallow default bitwise assignment - void operator=(const gmresSolver&) = delete; - - //- Givens rotation void givensRotation ( @@ -90,6 +81,15 @@ public: TypeName("GMRES"); + // Generated Methods + + //- No copy construct + gmresSolver(const gmresSolver&) = delete; + + //- No copy assignment + void operator=(const gmresSolver&) = delete; + + // Constructors //- Construct from matrix components and solver data stream