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 operations.
28 \*---------------------------------------------------------------------------*/
30 #include "lduMatrix.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 void Foam::lduMatrix::sumDiag()
36 const scalarField& Lower = const_cast<const lduMatrix&>(*this).lower();
37 const scalarField& Upper = const_cast<const lduMatrix&>(*this).upper();
38 scalarField& Diag = diag();
40 const unallocLabelList& l = lduAddr().lowerAddr();
41 const unallocLabelList& u = lduAddr().upperAddr();
43 for (register label face=0; face<l.size(); face++)
45 Diag[l[face]] += Lower[face];
46 Diag[u[face]] += Upper[face];
51 void Foam::lduMatrix::negSumDiag()
53 const scalarField& Lower = const_cast<const lduMatrix&>(*this).lower();
54 const scalarField& Upper = const_cast<const lduMatrix&>(*this).upper();
55 scalarField& Diag = diag();
57 const unallocLabelList& l = lduAddr().lowerAddr();
58 const unallocLabelList& u = lduAddr().upperAddr();
60 for (register label face=0; face<l.size(); face++)
62 Diag[l[face]] -= Lower[face];
63 Diag[u[face]] -= Upper[face];
68 void Foam::lduMatrix::sumMagOffDiag
73 const scalarField& Lower = const_cast<const lduMatrix&>(*this).lower();
74 const scalarField& Upper = const_cast<const lduMatrix&>(*this).upper();
76 const unallocLabelList& l = lduAddr().lowerAddr();
77 const unallocLabelList& u = lduAddr().upperAddr();
79 for (register label face = 0; face < l.size(); face++)
81 sumOff[u[face]] += mag(Lower[face]);
82 sumOff[l[face]] += mag(Upper[face]);
87 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
89 void Foam::lduMatrix::operator=(const lduMatrix& A)
94 << "lduMatrix::operator=(const lduMatrix&) : "
95 << "attempted assignment to self"
126 void Foam::lduMatrix::negate()
145 void Foam::lduMatrix::operator+=(const lduMatrix& A)
152 if (symmetric() && A.symmetric())
154 upper() += A.upper();
156 else if (symmetric() && A.asymmetric())
167 upper() += A.upper();
168 lower() += A.lower();
170 else if (asymmetric() && A.symmetric())
174 lower() += A.upper();
175 upper() += A.upper();
179 lower() += A.lower();
180 upper() += A.lower();
184 else if (asymmetric() && A.asymmetric())
186 lower() += A.lower();
187 upper() += A.upper();
201 else if (A.diagonal())
206 FatalErrorIn("lduMatrix::operator+=(const lduMatrix& A)")
207 << "Unknown matrix type combination"
208 << abort(FatalError);
213 void Foam::lduMatrix::operator-=(const lduMatrix& A)
220 if (symmetric() && A.symmetric())
222 upper() -= A.upper();
224 else if (symmetric() && A.asymmetric())
235 upper() -= A.upper();
236 lower() -= A.lower();
238 else if (asymmetric() && A.symmetric())
242 lower() -= A.upper();
243 upper() -= A.upper();
247 lower() -= A.lower();
248 upper() -= A.lower();
252 else if (asymmetric() && A.asymmetric())
254 lower() -= A.lower();
255 upper() -= A.upper();
261 upper() = -A.upper();
266 lower() = -A.lower();
269 else if (A.diagonal())
274 FatalErrorIn("lduMatrix::operator-=(const lduMatrix& A)")
275 << "Unknown matrix type combination"
276 << abort(FatalError);
281 void Foam::lduMatrix::operator*=(const scalarField& sf)
290 scalarField& upper = *upperPtr_;
292 const unallocLabelList& l = lduAddr().lowerAddr();
294 for (register label face=0; face<upper.size(); face++)
296 upper[face] *= sf[l[face]];
302 scalarField& lower = *lowerPtr_;
304 const unallocLabelList& u = lduAddr().upperAddr();
306 for (register label face=0; face<lower.size(); face++)
308 lower[face] *= sf[u[face]];
314 void Foam::lduMatrix::operator*=(scalar s)
333 Foam::tmp<Foam::scalarField > Foam::lduMatrix::H1() const
335 tmp<scalarField > tH1
337 new scalarField(lduAddr().size(), 0.0)
340 if (lowerPtr_ || upperPtr_)
342 scalarField& H1_ = tH1();
344 scalar* __restrict__ H1Ptr = H1_.begin();
346 const label* __restrict__ uPtr = lduAddr().upperAddr().begin();
347 const label* __restrict__ lPtr = lduAddr().lowerAddr().begin();
349 const scalar* __restrict__ lowerPtr = lower().begin();
350 const scalar* __restrict__ upperPtr = upper().begin();
352 register const label nFaces = upper().size();
354 for (register label face=0; face<nFaces; face++)
356 H1Ptr[uPtr[face]] -= lowerPtr[face];
357 H1Ptr[lPtr[face]] -= upperPtr[face];
365 // ************************************************************************* //