/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "SmoothSolver.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::SmoothSolver::SmoothSolver ( const word& fieldName, const LduMatrix& matrix, const dictionary& solverDict ) : LduMatrix::solver ( fieldName, matrix, solverDict ), nSweeps_(1) { readControls(); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template void Foam::SmoothSolver::readControls() { LduMatrix::solver::readControls(); this->readControl(this->controlDict_, nSweeps_, "nSweeps"); } template Foam::SolverPerformance Foam::SmoothSolver::solve(Field& psi) const { // --- Setup class containing solver performance data SolverPerformance solverPerf ( typeName, this->fieldName_ ); label nIter = 0; // If the nSweeps_ is negative do a fixed number of sweeps if (nSweeps_ < 0) { autoPtr::smoother> smootherPtr = LduMatrix::smoother::New ( this->fieldName_, this->matrix_, this->controlDict_ ); smootherPtr->smooth(psi, -nSweeps_); nIter -= nSweeps_; } else { Type normFactor = Zero; { Field Apsi(psi.size()); Field temp(psi.size()); // Calculate A.psi this->matrix_.Amul(Apsi, psi); // Calculate normalisation factor normFactor = this->normFactor(psi, Apsi, temp); // Calculate residual magnitude solverPerf.initialResidual() = cmptDivide ( gSum(cmptMag(this->matrix_.source() - Apsi)), normFactor ); solverPerf.finalResidual() = solverPerf.initialResidual(); } if (LduMatrix::debug >= 2) { Info<< " Normalisation factor = " << normFactor << endl; } // Check convergence, solve if not converged if ( this->minIter_ > 0 || !solverPerf.checkConvergence(this->tolerance_, this->relTol_) ) { autoPtr::smoother> smootherPtr = LduMatrix::smoother::New ( this->fieldName_, this->matrix_, this->controlDict_ ); // Smoothing loop do { smootherPtr->smooth ( psi, nSweeps_ ); // Calculate the residual to check convergence solverPerf.finalResidual() = cmptDivide ( gSum(cmptMag(this->matrix_.residual(psi))), normFactor ); } while ( ( (nIter += nSweeps_) < this->maxIter_ && !solverPerf.checkConvergence(this->tolerance_, this->relTol_) ) || nIter < this->minIter_ ); } } solverPerf.nIterations() = pTraits::labelType>::one*nIter; return solverPerf; } // ************************************************************************* //