1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 lduMatrix member H operations.
28 \*---------------------------------------------------------------------------*/
30 #include "lduMatrix.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 Foam::tmp<Foam::Field<Type> > Foam::lduMatrix::H(const Field<Type>& psi) const
37 tmp<Field<Type> > tHpsi
39 new Field<Type>(lduAddr().size(), pTraits<Type>::zero)
42 if (lowerPtr_ || upperPtr_)
44 Field<Type> & Hpsi = tHpsi();
46 Type* __restrict__ HpsiPtr = Hpsi.begin();
48 const Type* __restrict__ psiPtr = psi.begin();
50 const label* __restrict__ uPtr = lduAddr().upperAddr().begin();
51 const label* __restrict__ lPtr = lduAddr().lowerAddr().begin();
53 const scalar* __restrict__ lowerPtr = lower().begin();
54 const scalar* __restrict__ upperPtr = upper().begin();
56 register const label nFaces = upper().size();
58 for (register label face=0; face<nFaces; face++)
60 HpsiPtr[uPtr[face]] -= lowerPtr[face]*psiPtr[lPtr[face]];
61 HpsiPtr[lPtr[face]] -= upperPtr[face]*psiPtr[uPtr[face]];
69 Foam::tmp<Foam::Field<Type> >
70 Foam::lduMatrix::H(const tmp<Field<Type> >& tpsi) const
72 tmp<Field<Type> > tHpsi(H(tpsi()));
79 Foam::tmp<Foam::Field<Type> >
80 Foam::lduMatrix::faceH(const Field<Type>& psi) const
82 if (lowerPtr_ || upperPtr_)
84 const scalarField& Lower = const_cast<const lduMatrix&>(*this).lower();
85 const scalarField& Upper = const_cast<const lduMatrix&>(*this).upper();
87 const unallocLabelList& l = lduAddr().lowerAddr();
88 const unallocLabelList& u = lduAddr().upperAddr();
90 tmp<Field<Type> > tfaceHpsi(new Field<Type> (Lower.size()));
91 Field<Type> & faceHpsi = tfaceHpsi();
93 for (register label face=0; face<l.size(); face++)
95 faceHpsi[face] = Upper[face]*psi[u[face]] - Lower[face]*psi[l[face]];
102 FatalErrorIn("lduMatrix::faceH(const Field<Type>& psi) const")
103 << "Cannot calculate faceH"
104 " the matrix does not have any off-diagonal coefficients."
107 return tmp<Field<Type> >(NULL);
113 Foam::tmp<Foam::Field<Type> >
114 Foam::lduMatrix::faceH(const tmp<Field<Type> >& tpsi) const
116 tmp<Field<Type> > tfaceHpsi(faceH(tpsi()));
122 // ************************************************************************* //