faScalarMatrix.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2017 Wikki Ltd
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Description
28  Finite-Area scalar matrix member functions and operators
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "faScalarMatrix.H"
34 #include "PrecisionAdaptor.H"
35 
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 
38 template<>
40 (
41  const label patchI,
42  const label edgeI,
43  const direction,
44  const scalar value
45 )
46 {
47  const labelUList& faceLabels = psi_.mesh().boundary()[patchI].edgeFaces();
48 
49  internalCoeffs_[patchI][edgeI] += diag()[faceLabels[edgeI]];
50 
51  boundaryCoeffs_[patchI][edgeI] = value;
52 }
53 
54 
55 template<>
57 (
58  const dictionary& solverControls
59 )
60 {
62  << "solving faMatrix<scalar>"
63  << endl;
64 
67 
68  scalarField saveDiag(diag());
69  addBoundaryDiag(diag(), 0);
70 
71  scalarField totalSource(source_);
72  addBoundarySource(totalSource, 0);
73 
74  // Solver call
76  (
77  psi_.name(),
78  *this,
79  boundaryCoeffs_,
80  internalCoeffs_,
81  psi_.boundaryField().scalarInterfaces(),
82  solverControls
83  )->solve(psi.ref(), totalSource);
84 
86  {
87  solverPerf.print(Info);
88  }
89 
90  diag() = saveDiag;
91 
92  psi.correctBoundaryConditions();
93 
94  psi.mesh().setSolverPerformance(psi.name(), solverPerf);
95 
96  return solverPerf;
97 }
98 
99 
100 template<>
102 {
103  scalarField boundaryDiag(psi_.size(), Zero);
104  addBoundaryDiag(boundaryDiag, 0);
105 
106  const scalarField& psif = psi_.internalField();
108  const solveScalarField& psi = tpsi();
109 
111  (
112  lduMatrix::residual
113  (
114  psi,
115  source_ - boundaryDiag*psif,
116  boundaryCoeffs_,
117  psi_.boundaryField().scalarInterfaces(),
118  0
119  )
120  );
121 
123  addBoundarySource(tres_s.ref());
124 
125  return tres_s;
126 }
127 
128 
129 template<>
131 {
133  (
134  new areaScalarField
135  (
136  IOobject
137  (
138  "H("+psi_.name()+')',
139  psi_.instance(),
140  psi_.db(),
141  IOobject::NO_READ,
142  IOobject::NO_WRITE
143  ),
144  psi_.mesh(),
145  dimensions_/dimArea,
146  zeroGradientFaPatchScalarField::typeName
147  )
148  );
149  areaScalarField& Hphi = tHphi.ref();
150 
151  Hphi.primitiveFieldRef() = (lduMatrix::H(psi_.primitiveField()) + source_);
152  addBoundarySource(Hphi.primitiveFieldRef());
153 
154  Hphi.ref() /= psi_.mesh().S();
156 
157  return tHphi;
158 }
159 
160 
161 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::diag
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)
Definition: pointPatchFieldFunctions.H:287
H
volScalarField H(IOobject("H", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), mesh, dimensionedScalar(dimLength, Zero))
PrecisionAdaptor.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::faMatrix::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: faMatrixSolve.C:38
solve
CEqn solve()
Foam::SolverPerformance::print
void print(Ostream &os) const
Print summary of solver performance to the given stream.
Definition: SolverPerformance.C:99
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:258
Foam::dimArea
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:60
Foam::Field< scalar >
Foam::DimensionedField::mesh
const Mesh & mesh() const
Return mesh.
Definition: DimensionedFieldI.H:41
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:360
Foam::faMatrix::solve
SolverPerformance< Type > solve()
Solve returning the solution statistics.
Definition: faMatrixSolve.C:173
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::faMatrix::H
tmp< GeometricField< Type, faPatchField, areaMesh > > H() const
Return the H operation source.
Definition: faMatrix.C:586
Foam::GeometricField::primitiveFieldRef
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field.
Definition: GeometricField.C:766
zeroGradientFaPatchFields.H
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:940
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::GeometricField::ref
Internal & ref(const bool updateAccessTime=true)
Return a reference to the dimensioned internal field.
Definition: GeometricField.C:749
Foam::UList< label >
Foam::ConstPrecisionAdaptor
A const Field wrapper with possible data conversion.
Definition: PrecisionAdaptor.H:50
Foam::direction
uint8_t direction
Definition: direction.H:47
faScalarMatrix.H
Foam::faMatrix::residual
tmp< Field< Type > > residual() const
Return the matrix residual.
Definition: faMatrixSolve.C:180
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
psi
const volScalarField & psi
Definition: createFieldRefs.H:1
Foam::SolverPerformance
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics.
Definition: SolverPerformance.H:51
Foam::tmpNrc< Container< Type > >::ref
Container< Type > & ref() const
Definition: tmpNrcI.H:222