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 | Copyright (C) 2011-2015 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  (
39  );
40 
41  if (lowerPtr_ || upperPtr_)
42  {
43  Field<Type> & Hpsi = tHpsi();
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();
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> >(NULL);
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 // ************************************************************************* //
Foam::lduMatrix::lduAddr
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition: lduMatrix.H:545
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::lduMatrix
lduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition: lduMatrix.H:77
lduMatrix.H
Foam::lduMatrix::upper
scalarField & upper()
Definition: lduMatrix.C:194
Foam::lduMatrix::lowerPtr_
scalarField * lowerPtr_
Coefficients (not including interfaces)
Definition: lduMatrix.H:85
Foam::lduAddressing::upperAddr
virtual const labelUList & upperAddr() const =0
Return upper addressing.
Foam::UList::begin
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
Foam::lduMatrix::lower
scalarField & lower()
Definition: lduMatrix.C:165
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< Type >
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:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
psi
const volScalarField & psi
Definition: setRegionFluidFields.H:13
Foam::lduAddressing::lowerAddr
virtual const labelUList & lowerAddr() const =0
Return lower addressing.
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::lduMatrix::faceH
tmp< Field< Type > > faceH(const Field< Type > &) const
Foam::UList
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
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::UList::size
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
Foam::lduMatrix::upperPtr_
scalarField * upperPtr_
Definition: lduMatrix.H:85