lduMatrixTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 Description
25  lduMatrix member H operations.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "lduMatrix.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 {
36  tmp<Field<Type>> tHpsi
37  (
38  new Field<Type>(lduAddr().size(), Zero)
39  );
40 
41  if (lowerPtr_ || upperPtr_)
42  {
43  Field<Type> & Hpsi = tHpsi.ref();
44 
45  Type* __restrict__ HpsiPtr = Hpsi.begin();
46 
47  const Type* __restrict__ psiPtr = psi.begin();
48 
49  const label* __restrict__ uPtr = lduAddr().upperAddr().begin();
50  const label* __restrict__ lPtr = lduAddr().lowerAddr().begin();
51 
52  const scalar* __restrict__ lowerPtr = lower().begin();
53  const scalar* __restrict__ upperPtr = upper().begin();
54 
55  const label nFaces = upper().size();
56 
57  for (label face=0; face<nFaces; face++)
58  {
59  HpsiPtr[uPtr[face]] -= lowerPtr[face]*psiPtr[lPtr[face]];
60  HpsiPtr[lPtr[face]] -= upperPtr[face]*psiPtr[uPtr[face]];
61  }
62  }
63 
64  return tHpsi;
65 }
66 
67 template<class Type>
69 Foam::lduMatrix::H(const tmp<Field<Type>>& tpsi) const
70 {
71  tmp<Field<Type>> tHpsi(H(tpsi()));
72  tpsi.clear();
73  return tHpsi;
74 }
75 
76 
77 template<class Type>
80 {
81  if (lowerPtr_ || upperPtr_)
82  {
83  const scalarField& Lower = const_cast<const lduMatrix&>(*this).lower();
84  const scalarField& Upper = const_cast<const lduMatrix&>(*this).upper();
85 
86  const labelUList& l = lduAddr().lowerAddr();
87  const labelUList& u = lduAddr().upperAddr();
88 
89  tmp<Field<Type>> tfaceHpsi(new Field<Type> (Lower.size()));
90  Field<Type> & faceHpsi = tfaceHpsi.ref();
91 
92  for (label face=0; face<l.size(); face++)
93  {
94  faceHpsi[face] =
95  Upper[face]*psi[u[face]]
96  - Lower[face]*psi[l[face]];
97  }
98 
99  return tfaceHpsi;
100  }
101  else
102  {
104  << "Cannot calculate faceH"
105  " the matrix does not have any off-diagonal coefficients."
106  << exit(FatalError);
107 
108  return tmp<Field<Type>>(nullptr);
109  }
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 // ************************************************************************* //
tmp< Field< Type > > faceH(const Field< Type > &) const
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
scalarField & upper()
Definition: lduMatrix.C:197
virtual const labelUList & lowerAddr() const =0
Return lower addressing.
Pre-declare SubField and related Field type.
Definition: Field.H:56
virtual const labelUList & upperAddr() const =0
Return upper addressing.
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
const volScalarField & psi
static const zero Zero
Definition: zero.H:97
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
lduMatrix is a general matrix class in which the coefficients are stored as three arrays...
Definition: lduMatrix.H:79
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition: lduMatrix.H:550
scalarField & lower()
Definition: lduMatrix.C:168
tmp< Field< Type > > H(const Field< Type > &) const
A class for managing temporary objects.
Definition: PtrList.H:53
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311