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 -------------------------------------------------------------------------------
10 License
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 
26 Description
27  lduMatrix member H operations.
28 
29 \*---------------------------------------------------------------------------*/
30 
31 #include "lduMatrix.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 template<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 
69 template<class Type>
71 Foam::lduMatrix::H(const tmp<Field<Type>>& tpsi) const
72 {
73  tmp<Field<Type>> tHpsi(H(tpsi()));
74  tpsi.clear();
75  return tHpsi;
76 }
77 
78 
79 template<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 
113 template<class Type>
116 {
117  tmp<Field<Type>> tfaceHpsi(faceH(tpsi()));
118  tpsi.clear();
119  return tfaceHpsi;
120 }
121 
122 
123 // ************************************************************************* //
Foam::lduMatrix::lduAddr
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition: lduMatrix.H:578
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::lduMatrix::upper
scalarField & upper()
Definition: lduMatrix.C:203
Foam::lduMatrix
lduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition: lduMatrix.H:83
H
volScalarField H(IOobject("H", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), mesh, dimensionedScalar(dimLength, Zero))
lduMatrix.H
Foam::lduAddressing::upperAddr
virtual const labelUList & upperAddr() const =0
Return upper addressing.
Foam::UList::begin
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:329
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:227
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::FatalError
error FatalError
Foam::lduMatrix::H
tmp< Field< Type > > H(const Field< Type > &) const
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::lduAddressing::lowerAddr
virtual const labelUList & lowerAddr() const =0
Return lower addressing.
Foam::lduMatrix::faceH
tmp< Field< Type > > faceH(const Field< Type > &) const
Foam::UList< label >
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
psi
const volScalarField & psi
Definition: createFieldRefs.H:1
Foam::lduMatrix::lower
scalarField & lower()
Definition: lduMatrix.C:174