fvScalarMatrix.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "fvScalarMatrix.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<>
33 (
34  const label patchi,
35  const label facei,
36  const direction,
37  const scalar value
38 )
39 {
40  if (psi_.needReference())
41  {
42  if (Pstream::master())
43  {
44  internalCoeffs_[patchi][facei] +=
45  diag()[psi_.mesh().boundary()[patchi].faceCells()[facei]];
46 
47  boundaryCoeffs_[patchi][facei] +=
48  diag()[psi_.mesh().boundary()[patchi].faceCells()[facei]]
49  *value;
50  }
51  }
52 }
53 
54 
55 template<>
58 (
59  const dictionary& solverControls
60 )
61 {
62  if (debug)
63  {
64  Info.masterStream(this->mesh().comm())
65  << "fvMatrix<scalar>::solver(const dictionary& solverControls) : "
66  "solver for fvMatrix<scalar>"
67  << endl;
68  }
69 
70  scalarField saveDiag(diag());
71  addBoundaryDiag(diag(), 0);
72 
74  (
76  (
77  *this,
79  (
80  psi_.name(),
81  *this,
82  boundaryCoeffs_,
83  internalCoeffs_,
84  psi_.boundaryField().scalarInterfaces(),
85  solverControls
86  )
87  )
88  );
89 
90  diag() = saveDiag;
91 
92  return solverPtr;
93 }
94 
95 
96 template<>
98 (
99  const dictionary& solverControls
100 )
101 {
104  (fvMat_.psi());
105 
106  scalarField saveDiag(fvMat_.diag());
107  fvMat_.addBoundaryDiag(fvMat_.diag(), 0);
108 
109  scalarField totalSource(fvMat_.source());
110  fvMat_.addBoundarySource(totalSource, false);
111 
112  // assign new solver controls
113  solver_->read(solverControls);
114 
115  solverPerformance solverPerf = solver_->solve
116  (
117  psi.internalField(),
118  totalSource
119  );
120 
121  if (solverPerformance::debug)
122  {
123  solverPerf.print(Info.masterStream(fvMat_.mesh().comm()));
124  }
125 
126  fvMat_.diag() = saveDiag;
127 
128  psi.correctBoundaryConditions();
129 
130  psi.mesh().setSolverPerformance(psi.name(), solverPerf);
131 
132  return solverPerf;
133 }
134 
135 
136 template<>
138 (
139  const dictionary& solverControls
140 )
141 {
142  if (debug)
143  {
144  Info.masterStream(this->mesh().comm())
145  << "fvMatrix<scalar>::solveSegregated"
146  "(const dictionary& solverControls) : "
147  "solving fvMatrix<scalar>"
148  << endl;
149  }
150 
153 
154  scalarField saveDiag(diag());
155  addBoundaryDiag(diag(), 0);
156 
157  scalarField totalSource(source_);
158  addBoundarySource(totalSource, false);
159 
160  // Solver call
162  (
163  psi.name(),
164  *this,
165  boundaryCoeffs_,
166  internalCoeffs_,
167  psi.boundaryField().scalarInterfaces(),
168  solverControls
169  )->solve(psi.internalField(), totalSource);
170 
171  if (solverPerformance::debug)
172  {
173  solverPerf.print(Info.masterStream(mesh().comm()));
174  }
175 
176  diag() = saveDiag;
177 
178  psi.correctBoundaryConditions();
179 
180  psi.mesh().setSolverPerformance(psi.name(), solverPerf);
181 
182  return solverPerf;
183 }
184 
185 
186 template<>
188 {
189  scalarField boundaryDiag(psi_.size(), 0.0);
190  addBoundaryDiag(boundaryDiag, 0);
191 
192  tmp<scalarField> tres
193  (
194  lduMatrix::residual
195  (
196  psi_.internalField(),
197  source_ - boundaryDiag*psi_.internalField(),
198  boundaryCoeffs_,
199  psi_.boundaryField().scalarInterfaces(),
200  0
201  )
202  );
203 
204  addBoundarySource(tres());
205 
206  return tres;
207 }
208 
209 
210 template<>
212 {
213  tmp<volScalarField> tHphi
214  (
215  new volScalarField
216  (
217  IOobject
218  (
219  "H("+psi_.name()+')',
220  psi_.instance(),
221  psi_.mesh(),
222  IOobject::NO_READ,
223  IOobject::NO_WRITE
224  ),
225  psi_.mesh(),
226  dimensions_/dimVol,
227  zeroGradientFvPatchScalarField::typeName
228  )
229  );
230  volScalarField& Hphi = tHphi();
231 
232  Hphi.internalField() = (lduMatrix::H(psi_.internalField()) + source_);
233  addBoundarySource(Hphi.internalField());
234 
235  Hphi.internalField() /= psi_.mesh().V();
237 
238  return tHphi;
239 }
240 
241 
242 template<>
244 {
246  (
247  new volScalarField
248  (
249  IOobject
250  (
251  "H(1)",
252  psi_.instance(),
253  psi_.mesh(),
254  IOobject::NO_READ,
255  IOobject::NO_WRITE
256  ),
257  psi_.mesh(),
258  dimensions_/(dimVol*psi_.dimensions()),
259  zeroGradientFvPatchScalarField::typeName
260  )
261  );
262  volScalarField& H1_ = tH1();
263 
264  H1_.internalField() = lduMatrix::H1();
265  //addBoundarySource(Hphi.internalField());
266 
267  H1_.internalField() /= psi_.mesh().V();
269 
270  return tH1;
271 }
272 
273 
274 // ************************************************************************* //
Foam::fvMatrix::residual
tmp< Field< Type > > residual() const
Return the matrix residual.
Definition: fvMatrixSolve.C:330
Foam::fvMatrix::H
tmp< GeometricField< Type, fvPatchField, volMesh > > H() const
Return the H operation source.
Definition: fvMatrix.C:763
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::diag
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)
Definition: pointPatchFieldFunctions.H:262
Foam::messageStream::masterStream
OSstream & masterStream(const label communicator)
Convert to OSstream.
Definition: messageStream.C:60
Foam::fvMatrix::fvSolver::solve
SolverPerformance< Type > solve()
Solve returning the solution statistics.
Definition: fvMatrixSolve.C:296
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::SolverPerformance::print
void print(Ostream &os) const
Print summary of solver performance to the given stream.
Definition: SolverPerformance.C:97
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
Foam::fvMatrix::H1
tmp< volScalarField > H1() const
Return H(1)
Definition: fvMatrix.C:825
Foam::GeometricField::internalField
InternalField & internalField()
Return internal field.
Definition: GeometricField.C:724
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
fvScalarMatrix.H
A scalar instance of fvMatrix.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMatrix::solver
autoPtr< fvSolver > solver()
Construct and return the solver.
Definition: fvMatrixSolve.C:279
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:885
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
psi
const volScalarField & psi
Definition: setRegionFluidFields.H:13
patchi
label patchi
Definition: getPatchFieldScalar.H:1
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::fvMatrix::fvSolver
Solver class returned by the solver function.
Definition: fvMatrix.H:220
Foam::dimVol
const dimensionSet dimVol(dimVolume)
Definition: dimensionSets.H:59
Foam::fvMatrix::solveSegregated
SolverPerformance< Type > solveSegregated(const dictionary &)
Solve segregated returning the solution statistics.
Definition: fvMatrixSolve.C:104
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::SolverPerformance
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics.
Definition: SolverPerformance.H:49
zeroGradientFvPatchFields.H
Foam::fvMatrix::setComponentReference
void setComponentReference(const label patchi, const label facei, const direction cmpt, const scalar value)
Set reference level for a component of the solution.
Definition: fvMatrixSolve.C:33