lduMatrixTemplates.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) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Description
27 lduMatrix member H operations.
28
29\*---------------------------------------------------------------------------*/
30
31#include "lduMatrix.H"
32
33// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34
35template<class Type>
37{
38 tmp<Field<Type>> tHpsi
39 (
40 new Field<Type>(lduAddr().size(), Zero)
41 );
42
43 if (lowerPtr_ || upperPtr_)
44 {
45 Field<Type> & Hpsi = tHpsi.ref();
46
47 Type* __restrict__ HpsiPtr = Hpsi.begin();
48
49 const Type* __restrict__ psiPtr = psi.begin();
50
51 const label* __restrict__ uPtr = lduAddr().upperAddr().begin();
52 const label* __restrict__ lPtr = lduAddr().lowerAddr().begin();
53
54 const scalar* __restrict__ lowerPtr = lower().begin();
55 const scalar* __restrict__ upperPtr = upper().begin();
56
57 const label nFaces = upper().size();
58
59 for (label face=0; face<nFaces; face++)
60 {
61 HpsiPtr[uPtr[face]] -= lowerPtr[face]*psiPtr[lPtr[face]];
62 HpsiPtr[lPtr[face]] -= upperPtr[face]*psiPtr[uPtr[face]];
63 }
64 }
65
66 return tHpsi;
67}
68
69template<class Type>
72{
73 tmp<Field<Type>> tHpsi(H(tpsi()));
74 tpsi.clear();
75 return tHpsi;
76}
77
78
79template<class Type>
82{
83 if (lowerPtr_ || upperPtr_)
84 {
85 const scalarField& Lower = const_cast<const lduMatrix&>(*this).lower();
86 const scalarField& Upper = const_cast<const lduMatrix&>(*this).upper();
87
88 const labelUList& l = lduAddr().lowerAddr();
89 const labelUList& u = lduAddr().upperAddr();
90
91 tmp<Field<Type>> tfaceHpsi(new Field<Type> (Lower.size()));
92 Field<Type> & faceHpsi = tfaceHpsi.ref();
93
94 for (label face=0; face<l.size(); face++)
95 {
96 faceHpsi[face] =
97 Upper[face]*psi[u[face]]
98 - Lower[face]*psi[l[face]];
99 }
100
101 return tfaceHpsi;
102 }
103
105 << "Cannot calculate faceH"
106 " the matrix does not have any off-diagonal coefficients."
107 << exit(FatalError);
108
109 return nullptr;
110}
111
112
113template<class Type>
116{
117 tmp<Field<Type>> tfaceHpsi(faceH(tpsi()));
118 tpsi.clear();
119 return tfaceHpsi;
120}
121
122
123// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:329
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
tmp< GeometricField< Type, faPatchField, areaMesh > > H() const
Return the H operation source.
Definition: faMatrix.C:633
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
virtual const labelUList & upperAddr() const =0
Return upper addressing.
virtual const labelUList & lowerAddr() const =0
Return lower addressing.
lduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition: lduMatrix.H:84
scalarField & upper()
Definition: lduMatrix.C:203
tmp< Field< Type > > faceH(const Field< Type > &) const
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition: lduMatrix.H:578
scalarField & lower()
Definition: lduMatrix.C:174
A class for managing temporary objects.
Definition: tmp.H:65
T & ref() const
Definition: tmpI.H:227
const volScalarField & psi
volScalarField H(IOobject("H", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), mesh, dimensionedScalar(dimLength, Zero))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const labelList nFaces(UPstream::listGatherValues< label >(aMesh.nFaces()))
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130