1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "fvScalarMatrix.H"
27 #include "zeroGradientFvPatchFields.H"
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 void Foam::fvMatrix<Foam::scalar>::setComponentReference
40 if (psi_.needReference())
42 if (Pstream::master())
44 internalCoeffs_[patchi][facei] +=
45 diag()[psi_.mesh().boundary()[patchi].faceCells()[facei]];
47 boundaryCoeffs_[patchi][facei] +=
48 diag()[psi_.mesh().boundary()[patchi].faceCells()[facei]]
56 Foam::autoPtr<Foam::fvMatrix<Foam::scalar>::fvSolver>
57 Foam::fvMatrix<Foam::scalar>::solver
59 const dictionary& solverControls
64 Info<< "fvMatrix<scalar>::solver(const dictionary& solverControls) : "
65 "solver for fvMatrix<scalar>"
69 scalarField saveDiag(diag());
70 addBoundaryDiag(diag(), 0);
72 autoPtr<fvMatrix<scalar>::fvSolver> solverPtr
74 new fvMatrix<scalar>::fvSolver
77 lduMatrix::solver::New
83 psi_.boundaryField().interfaces(),
96 Foam::lduMatrix::solverPerformance Foam::fvMatrix<Foam::scalar>::fvSolver::solve
98 const dictionary& solverControls
101 GeometricField<scalar, fvPatchField, volMesh>& psi =
102 const_cast<GeometricField<scalar, fvPatchField, volMesh>&>
105 scalarField saveDiag(fvMat_.diag());
106 fvMat_.addBoundaryDiag(fvMat_.diag(), 0);
108 scalarField totalSource(fvMat_.source());
109 fvMat_.addBoundarySource(totalSource, false);
111 // assign new solver controls
112 solver_->read(solverControls);
114 lduMatrix::solverPerformance solverPerf = solver_->solve
122 fvMat_.diag() = saveDiag;
124 psi.correctBoundaryConditions();
126 psi.mesh().setSolverPerformance(psi.name(), solverPerf);
133 Foam::lduMatrix::solverPerformance Foam::fvMatrix<Foam::scalar>::solve
135 const dictionary& solverControls
140 Info<< "fvMatrix<scalar>::solve(const dictionary& solverControls) : "
141 "solving fvMatrix<scalar>"
145 GeometricField<scalar, fvPatchField, volMesh>& psi =
146 const_cast<GeometricField<scalar, fvPatchField, volMesh>&>(psi_);
148 scalarField saveDiag(diag());
149 addBoundaryDiag(diag(), 0);
151 scalarField totalSource(source_);
152 addBoundarySource(totalSource, false);
155 lduMatrix::solverPerformance solverPerf = lduMatrix::solver::New
161 psi.boundaryField().interfaces(),
163 )->solve(psi.internalField(), totalSource);
169 psi.correctBoundaryConditions();
171 psi.mesh().setSolverPerformance(psi.name(), solverPerf);
178 Foam::tmp<Foam::scalarField> Foam::fvMatrix<Foam::scalar>::residual() const
180 scalarField boundaryDiag(psi_.size(), 0.0);
181 addBoundaryDiag(boundaryDiag, 0);
183 tmp<scalarField> tres
187 psi_.internalField(),
188 source_ - boundaryDiag*psi_.internalField(),
190 psi_.boundaryField().interfaces(),
195 addBoundarySource(tres());
202 Foam::tmp<Foam::volScalarField> Foam::fvMatrix<Foam::scalar>::H() const
204 tmp<volScalarField> tHphi
210 "H("+psi_.name()+')',
218 zeroGradientFvPatchScalarField::typeName
221 volScalarField& Hphi = tHphi();
223 Hphi.internalField() = (lduMatrix::H(psi_.internalField()) + source_);
224 addBoundarySource(Hphi.internalField());
226 Hphi.internalField() /= psi_.mesh().V();
227 Hphi.correctBoundaryConditions();
234 Foam::tmp<Foam::volScalarField> Foam::fvMatrix<Foam::scalar>::H1() const
236 tmp<volScalarField> tH1
249 dimensions_/(dimVol*psi_.dimensions()),
250 zeroGradientFvPatchScalarField::typeName
253 volScalarField& H1_ = tH1();
255 H1_.internalField() = lduMatrix::H1();
256 //addBoundarySource(Hphi.internalField());
258 H1_.internalField() /= psi_.mesh().V();
259 H1_.correctBoundaryConditions();
265 // ************************************************************************* //