1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Finite-Area matrix basic solvers.
27 \*---------------------------------------------------------------------------*/
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 // Set reference level for a component of the solution
35 // on a given patch face
37 void faMatrix<Type>::setComponentReference
45 internalCoeffs_[patchi][facei].component(cmpt) +=
46 diag()[psi_.mesh().boundary()[patchi].faceCells()[facei]];
48 boundaryCoeffs_[patchi][facei].component(cmpt) +=
49 diag()[psi_.mesh().boundary()[patchi].faceCells()[facei]]*value;
54 lduSolverPerformance faMatrix<Type>::solve(const dictionary& solverControls)
58 Info<< "faMatrix<Type>::solve(const dictionary&) : "
59 "solving faMatrix<Type>"
63 lduSolverPerformance solverPerfVec
65 "faMatrix<Type>::solve",
69 scalarField saveDiag = diag();
71 Field<Type> source = source_;
72 addBoundarySource(source);
74 // Make a copy of interfaces: no longer a reference
76 lduInterfaceFieldPtrsList interfaces = psi_.boundaryField().interfaces();
78 for (direction cmpt = 0; cmpt < Type::nComponents; cmpt++)
80 // copy field and source
82 scalarField psiCmpt = psi_.internalField().component(cmpt);
83 addBoundaryDiag(diag(), solvingComponent);
85 scalarField sourceCmpt = source.component(cmpt);
87 FieldField<Field, scalar> bouCoeffsCmpt
89 boundaryCoeffs_.component(cmpt)
92 FieldField<Field, scalar> intCoeffsCmpt
94 internalCoeffs_.component(cmpt)
97 // Use the initMatrixInterfaces and updateMatrixInterfaces to correct
98 // bouCoeffsCmpt for the explicit part of the coupled boundary
109 updateMatrixInterfaces
118 lduSolverPerformance solverPerf;
121 solverPerf = lduSolver::New
123 psi_.name() + pTraits<Type>::componentNames[cmpt],
129 )->solve(psiCmpt, sourceCmpt, cmpt);
135 solverPerf.initialResidual() > solverPerfVec.initialResidual()
136 && !solverPerf.singular()
139 solverPerfVec = solverPerf;
142 psi_.internalField().replace(cmpt, psiCmpt);
146 psi_.correctBoundaryConditions();
148 return solverPerfVec;
153 autoPtr<typename faMatrix<Type>::faSolver> faMatrix<Type>::solver()
155 return solver(psi_.mesh().solutionDict().solverDict(psi_.name()));
159 lduSolverPerformance faMatrix<Type>::faSolver::solve()
163 faMat_.psi().mesh().solutionDict().solverDict
172 lduSolverPerformance faMatrix<Type>::solve()
176 this->psi().mesh().solutionDict().solverDict
184 // Return the matrix residual
186 tmp<Field<Type> > faMatrix<Type>::residual() const
188 tmp<Field<Type> > tres(source_);
189 Field<Type>& res = tres();
191 addBoundarySource(res);
193 // Make a copy of interfaces: no longer a reference
195 lduInterfaceFieldPtrsList interfaces = psi_.boundaryField().interfaces();
197 // Loop over field components
198 for (direction cmpt = 0; cmpt < Type::nComponents; cmpt++)
200 scalarField psiCmpt = psi_.internalField().component(cmpt);
202 scalarField boundaryDiagCmpt(psi_.size(), 0.0);
203 addBoundaryDiag(boundaryDiagCmpt, cmpt);
205 FieldField<Field, scalar> bouCoeffsCmpt
207 boundaryCoeffs_.component(cmpt)
216 res.component(cmpt) - boundaryDiagCmpt*psiCmpt,
228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 } // End namespace Foam
232 // ************************************************************************* //