1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 BlockLduMatrix is a general matrix class in which the coefficients are
30 stored as three arrays, one for the upper triangle, one for the
31 lower triangle and a third for the diagonal. Addressing object must
32 be supplied for the upper and lower triangles.
35 Hrvoje Jasak, Wikki Ltd. All rights reserved.
39 BlockLduMatrixOperations.C
40 BlockLduMatrixUpdateInterfaces.C
43 BlockLduMatrixDecouple.C
44 BlockLduMatrixDecoupledHOps.C
46 \*---------------------------------------------------------------------------*/
48 #ifndef BlockLduMatrix_H
49 #define BlockLduMatrix_H
51 #include "coeffFields.H"
53 #include "BlockLduInterface.H"
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
67 Ostream& operator<<(Ostream&, const BlockLduMatrix<Type>&);
70 class BlockConstraint;
73 /*---------------------------------------------------------------------------*\
74 Class BlockLduMatrix Declaration
75 \*---------------------------------------------------------------------------*/
86 typedef CoeffField<Type> TypeCoeffField;
87 typedef Field<Type> TypeField;
88 typedef BlockConstraint<Type> ConstraintType;
96 const lduMesh& lduMesh_;
99 // Block matrix elements
101 //- Diagonal coefficients
102 CoeffField<Type>* diagPtr_;
104 //- Upper triangle coefficients. Also used for symmetric matrix
105 CoeffField<Type>* upperPtr_;
107 //- Lower triangle coefficients
108 CoeffField<Type> *lowerPtr_;
113 //- List of coupled interfaces
114 PtrList<BlockLduInterface<Type> > interfaces_;
116 //- Coupled interface coefficients, upper
117 FieldField<CoeffField, Type> coupleUpper_;
119 //- Coupled interface coefficients, lower
120 FieldField<CoeffField, Type> coupleLower_;
125 //- Equation triangle map
126 mutable Map<ConstraintType> fixedEqns_;
129 // Private static data
131 //- Matrix constraint fill-in
132 // Equals to the estimated fraction of fixed nodes in the matrix
133 static const label fixFillIn;
136 // Private member functions
138 // Decoupled versions of nmatrix operations
140 //- Sum off-diagonal coefficients and add to diagonal,
142 void decoupledSumDiag();
144 //- Sum negative off-diagonal coefficients and add to diagonal,
146 void decoupledNegSumDiag();
148 //- Check matrix for diagonal dominance, decoupled version
149 void decoupledCheck() const;
151 //- Relax matrix, decoupled version
159 //- Matrix scaling with scalar field, decoupled version
160 void decoupledMultEqOp(const scalarField& sf);
162 //- Matrix multiplication without coupled interface update,
164 void decoupledAmulCore
170 //- Matrix transpose multiplication without coupled interface update
172 void decoupledTmulCore
178 //- Return L-U vector-matrix multiplication in row-form,
180 tmp<TypeField> decoupledH(const TypeField& x) const;
182 //- Return L-U vector-matrix multiplication in off-diagonal form,
184 tmp<TypeField> decoupledFaceH(const TypeField& x) const;
189 // Access to constraints
191 //- Return constraint map
192 const Map<ConstraintType>& fixedEqns() const
198 //- Return access constraint map
199 Map<ConstraintType>& fixedEqns()
207 //- Runtime type information
208 TypeName("BlockLduMatrix");
213 //- Construct given addressing
214 explicit BlockLduMatrix(const lduMesh&);
216 //- Construct as copy
217 BlockLduMatrix(const BlockLduMatrix<Type>&);
222 virtual ~BlockLduMatrix();
227 // Access to addressing
229 //- Return the LDU mesh from which the addressing is obtained
230 const lduMesh& mesh() const
235 //- Return the LDU addressing
236 const lduAddressing& lduAddr() const
238 return lduMesh_.lduAddr();
241 //- Return the patch evaluation schedule
242 const lduSchedule& patchSchedule() const
244 return lduAddr().patchSchedule();
248 // Access to coefficients
250 //- Return access to diagonal coefficients
251 TypeCoeffField& diag();
253 //- Return diagonal coefficients
254 const TypeCoeffField& diag() const;
256 //- Return access to upper coefficients
257 // Also used for symmetric matrices
258 TypeCoeffField& upper();
260 //- Return upper coefficients
261 // Also used for symmetric matrices
262 const TypeCoeffField& upper() const;
264 //- Return access to lower coefficients
265 TypeCoeffField& lower();
267 //- Return lower coefficients
268 const TypeCoeffField& lower() const;
270 //- Return access to coupled interface coefficients, upper
271 FieldField<CoeffField, Type>& coupleUpper()
276 //- Return coupled interface coefficients, upper
277 const FieldField<CoeffField, Type>& coupleUpper() const
282 //- Return access to coupled interface coefficients, lower
283 FieldField<CoeffField, Type>& coupleLower()
288 //- Return coupled interface coefficients, lower
289 const FieldField<CoeffField, Type>& coupleLower() const
297 //- Return true if there is a diagonal
298 bool thereIsDiag() const
303 //- Return true if upper triangle is allocated
304 bool thereIsUpper() const
309 //- Return true if lower triangle is allocated
310 bool thereIsLower() const
315 //- Return true if matrix is empty
318 //- Return true if matrix is diagonal-only
319 bool diagonal() const;
321 //- Return true if matrix is symmetric
322 bool symmetric() const;
324 //- Return true if matrix is asymmetric
325 bool asymmetric() const;
327 //- Return true if matrix is component-coupled
328 bool componentCoupled() const;
333 //- Sum off-diagonal coefficients and add to diagonal
336 //- Sum negative off-diagonal coefficients and add to diagonal
339 //- Check matrix for diagonal dominance
350 //- Matrix multiplication
357 //- Matrix multiplication without coupled interface update
364 //- Matrix transpose multiplication
371 //- Matrix transpose multiplication without
372 // coupled interface update
380 //- Return decoupled b
388 // Coupled interface functionality
390 //- Initialise the update of coupled interfaces
391 // for Amul operations
398 //- Update coupled interfaces
399 void updateInterfaces
401 const FieldField<CoeffField, Type>& coeffs,
407 // Constraint manipulation
409 //- Set constrained value in a prescribed point
412 const label eqnIndex,
417 // Residual calculation
419 //- Calculate residual
420 tmp<TypeField> residual
425 tmp<TypeField> residual
434 //- Return L-U vector-matrix multiplication in row-form
435 tmp<TypeField> H(const TypeField&) const;
437 //- Return L-U vector-matrix multiplication in off-diagonal form
438 tmp<TypeField> faceH(const TypeField&) const;
443 void operator=(const BlockLduMatrix<Type>&);
447 void operator+=(const BlockLduMatrix<Type>&);
448 void operator-=(const BlockLduMatrix<Type>&);
450 void operator*=(const scalarField&);
451 void operator*=(const scalar);
456 friend Ostream& operator<< <Type>
459 const BlockLduMatrix<Type>&
464 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
466 } // End namespace Foam
468 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
471 # include "BlockLduMatrix.C"
472 # include "BlockLduMatrixOperations.C"
473 # include "BlockLduMatrixUpdateInterfaces.C"
474 # include "BlockLduMatrixATmul.C"
475 # include "BlockLduMatrixHOps.C"
476 # include "BlockLduMatrixDecouple.C"
477 # include "BlockLduMatrixDecoupledHOps.C"
480 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
484 // ************************************************************************* //