Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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
26Description
27 lduMatrix member H operations.
28
29\*---------------------------------------------------------------------------*/
31#include "lduMatrix.H"
32
33// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34
35template<class Type>
37{
38 auto tHpsi = tmp<Field<Type>>::New(lduAddr().size(), Foam::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 }
61 return tHpsi;
62}
63
64template<class Type>
66Foam::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
74template<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
108template<class Type>
110Foam::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// ************************************************************************* //
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition UListI.H:410
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A face is a list of labels corresponding to mesh vertices.
Definition face.H:71
virtual const labelUList & upperAddr() const =0
Return upper addressing.
virtual const labelUList & lowerAddr() const =0
Return lower addressing.
lduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition lduMatrix.H:81
lduMatrix(const lduMesh &mesh)
Construct (without coefficients) for an LDU addressed mesh.
Definition lduMatrix.C:54
tmp< Field< Type > > faceH(const Field< Type > &) const
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition lduMatrix.H:769
const scalarField & upper() const
Definition lduMatrix.C:235
tmp< Field< Type > > H(const Field< Type > &) const
const scalarField & lower() const
Definition lduMatrix.C:306
A class for managing temporary objects.
Definition tmp.H:75
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
const volScalarField & psi
volScalarField H(IOobject("H", runTime.timeName(), mesh.thisDb(), IOobject::NO_READ, IOobject::AUTO_WRITE), mesh, dimensionedScalar(dimLength, Zero))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
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.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
UList< label > labelUList
A UList of labels.
Definition UList.H:75