FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/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  register const label nFaces = upper().size();
56 
57  for (register 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 unallocLabelList& l = lduAddr().lowerAddr();
87  const unallocLabelList& u = lduAddr().upperAddr();
88 
89  tmp<Field<Type> > tfaceHpsi(new Field<Type> (Lower.size()));
90  Field<Type> & faceHpsi = tfaceHpsi();
91 
92  for (register label face=0; face<l.size(); face++)
93  {
94  faceHpsi[face] = Upper[face]*psi[u[face]] - Lower[face]*psi[l[face]];
95  }
96 
97  return tfaceHpsi;
98  }
99  else
100  {
101  FatalErrorIn("lduMatrix::faceH(const Field<Type>& psi) const")
102  << "Cannot calculate faceH"
103  " the matrix does not have any off-diagonal coefficients."
104  << exit(FatalError);
105 
106  return tmp<Field<Type> >(NULL);
107  }
108 }
109 
110 
111 template<class Type>
114 {
115  tmp<Field<Type> > tfaceHpsi(faceH(tpsi()));
116  tpsi.clear();
117  return tfaceHpsi;
118 }
119 
120 
121 // ************************ vim: set sw=4 sts=4 et: ************************ //