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  auto tHpsi = tmp<Field<Type>>::New(lduAddr().size(), Zero);
39 
40  if (lowerPtr_ || upperPtr_)
41  {
42  Type* __restrict__ HpsiPtr = tHpsi.ref().begin();
43 
44  const Type* __restrict__ psiPtr = psi.begin();
45 
46  const label* __restrict__ uPtr = lduAddr().upperAddr().begin();
47  const label* __restrict__ lPtr = lduAddr().lowerAddr().begin();
48 
49  const scalar* __restrict__ lowerPtr = lower().begin();
50  const scalar* __restrict__ upperPtr = upper().begin();
51 
52  const label nFaces = upper().size();
53 
54  for (label face=0; face<nFaces; face++)
55  {
56  HpsiPtr[uPtr[face]] -= lowerPtr[face]*psiPtr[lPtr[face]];
57  HpsiPtr[lPtr[face]] -= upperPtr[face]*psiPtr[uPtr[face]];
58  }
59  }
60 
61  return tHpsi;
62 }
63 
64 template<class Type>
66 Foam::lduMatrix::H(const tmp<Field<Type>>& tpsi) const
67 {
68  tmp<Field<Type>> tHpsi(H(tpsi()));
69  tpsi.clear();
70  return tHpsi;
71 }
72 
73 
74 template<class Type>
77 {
78  if (lowerPtr_ || upperPtr_)
79  {
80  const scalarField& Lower = const_cast<const lduMatrix&>(*this).lower();
81  const scalarField& Upper = const_cast<const lduMatrix&>(*this).upper();
82 
83  const labelUList& l = lduAddr().lowerAddr();
84  const labelUList& u = lduAddr().upperAddr();
85 
86  auto tfaceHpsi = tmp<Field<Type>>::New(Lower.size());
87  auto& faceHpsi = tfaceHpsi.ref();
88 
89  for (label face=0; face<l.size(); face++)
90  {
91  faceHpsi[face] =
92  Upper[face]*psi[u[face]]
93  - Lower[face]*psi[l[face]];
94  }
95 
96  return tfaceHpsi;
97  }
98 
100  << "Cannot calculate faceH"
101  " the matrix does not have any off-diagonal coefficients."
102  << exit(FatalError);
103 
104  return nullptr;
105 }
106 
107 
108 template<class Type>
110 Foam::lduMatrix::faceH(const tmp<Field<Type>>& tpsi) const
111 {
112  tmp<Field<Type>> tfaceHpsi(faceH(tpsi()));
113  tpsi.clear();
114  return tfaceHpsi;
115 }
116 
117 
118 // ************************************************************************* //
tmp< Field< Type > > faceH(const Field< Type > &) const
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
scalarField & upper()
Definition: lduMatrix.C:208
virtual const labelUList & lowerAddr() const =0
Return lower addressing.
Generic templated field type.
Definition: Field.H:62
virtual const labelUList & upperAddr() const =0
Return upper addressing.
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:391
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:734
scalarField & lower()
Definition: lduMatrix.C:179
const volScalarField & psi
tmp< Field< Type > > H(const Field< Type > &) const
A class for managing temporary objects.
Definition: HashPtrTable.H:50
volScalarField H(IOobject("H", runTime.timeName(), mesh.thisDb(), IOobject::NO_READ, IOobject::AUTO_WRITE), mesh, dimensionedScalar(dimLength, Zero))
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127