Report patch name instead of index in debug
[foam-extend-3.2.git] / src / foam / matrices / blockLduMatrix / BlockLduMatrix / BlockLduMatrix.H
blobec91d6e892f26683f53ca1630c0f4364e0fdad5a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     BlockLduMatrix
27 Description
28     BlockLduMatrix is a general matrix class in which the coefficients are
29     stored as three arrays, one for the upper triangle, one for the
30     lower triangle and a third for the diagonal.  Addressing object must
31     be supplied for the upper and lower triangles.
33 Author
34     Hrvoje Jasak, Wikki Ltd.  All rights reserved.
36 SourceFiles
37     BlockLduMatrix.C
38     BlockLduMatrixOperations.C
39     BlockLduMatrixUpdateInterfaces.C
40     BlockLduMatrixATmul.C
41     BlockLduMatrixHOps.C
42     BlockLduMatrixDecouple.C
43     BlockLduMatrixDecoupledHOps.C
45 \*---------------------------------------------------------------------------*/
47 #ifndef BlockLduMatrix_H
48 #define BlockLduMatrix_H
50 #include "coeffFields.H"
51 #include "FieldField.H"
52 #include "lduMesh.H"
53 #include "HashSet.H"
54 #include "BlockLduInterfaceFieldPtrsList.H"
55 #include "Map.H"
56 #include "optimisationSwitch.H"
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 namespace Foam
63 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
65 template<class Type>
66 class BlockLduMatrix;
68 template<class Type>
69 Ostream& operator<<(Ostream&, const BlockLduMatrix<Type>&);
71 template<class Type>
72 class BlockConstraint;
75 /*---------------------------------------------------------------------------*\
76                         Class BlockLduMatrix Declaration
77 \*---------------------------------------------------------------------------*/
79 template<class Type>
80 class BlockLduMatrix
82     public refCount
84 public:
86     // Public data types
88         typedef CoeffField<Type> TypeCoeffField;
89         typedef Field<Type> TypeField;
90         typedef BlockConstraint<Type> ConstraintType;
93 private:
95     // Private data
97         // LDU mesh reference
98         const lduMesh& lduMesh_;
100         //- Eliminated equations
101         //  Consider adding solo cells on construction.  HJ, 26/Oct/2012
102         labelHashSet eliminatedEqns_;
105         // Block matrix elements
107             //- Diagonal coefficients
108             CoeffField<Type>* diagPtr_;
110             //- Upper triangle coefficients.  Also used for symmetric matrix
111             CoeffField<Type>* upperPtr_;
113             //- Lower triangle coefficients
114             CoeffField<Type> *lowerPtr_;
117         // Coupling
119             //- List of coupled interfaces
120             typename BlockLduInterfaceFieldPtrsList<Type>::Type interfaces_;
122             //- Coupled interface coefficients, upper
123             FieldField<CoeffField, Type> coupleUpper_;
125             //- Coupled interface coefficients, lower
126             FieldField<CoeffField, Type> coupleLower_;
129         // Constraints
131             //- Equation triangle map
132             mutable Map<ConstraintType> fixedEqns_;
135     // Private static data
137         //- Matrix constraint fill-in
138         //  Equals to the estimated fraction of fixed nodes in the matrix
139         static const debug::optimisationSwitch fixFillIn;
142     // Private member functions
144         // Decoupled versions of nmatrix operations
146             //- Sum off-diagonal coefficients and add to diagonal,
147             //  decoupled version
148             void decoupledSumDiag();
150             //- Sum negative off-diagonal coefficients and add to diagonal,
151             //  decoupled version
152             void decoupledNegSumDiag();
154             //- Check matrix for diagonal dominance, decoupled version
155             void decoupledCheck() const;
157             //- Relax matrix, decoupled version
158             void decoupledRelax
159             (
160                 const TypeField& x,
161                 TypeField& b,
162                 const scalar alpha
163             );
165             //- Matrix scaling with scalar field, decoupled version
166             void decoupledMultEqOp(const scalarField& sf);
168             //- Matrix multiplication without coupled interface update,
169             //  Decoupled version
170             void decoupledAmulCore
171             (
172                 TypeField& Ax,
173                 const TypeField& x
174             ) const;
176             //- Matrix transpose multiplication without coupled
177             //  interface update
178             //  Decoupled version
179             void decoupledTmulCore
180             (
181                 TypeField& Tx,
182                 const TypeField& x
183             ) const;
185             //- Return L-U vector-matrix multiplication in row-form,
186             //  Decoupled version
187             tmp<TypeField> decoupledH(const TypeField& x) const;
189             //- Return L-U  vector-matrix multiplication in off-diagonal form,
190             //  Decoupled version
191             tmp<TypeField> decoupledFaceH(const TypeField& x) const;
194 protected:
196     // Access to constraints
198         //- Return constraint map
199         const Map<ConstraintType>& fixedEqns() const
200         {
201             return fixedEqns_;
202         }
205         //- Return access constraint map
206         Map<ConstraintType>& fixedEqns()
207         {
208             return fixedEqns_;
209         }
212 public:
214     //- Runtime type information
215     TypeName("BlockLduMatrix");
218     // Constructors
220         //- Construct given addressing
221         explicit BlockLduMatrix(const lduMesh&);
223         //- Construct as copy
224         BlockLduMatrix(const BlockLduMatrix<Type>&);
226         //- Construct as copy or re-use as specified.
227         BlockLduMatrix(BlockLduMatrix<Type>&, bool reUse);
230     // Destructor
232         virtual ~BlockLduMatrix();
235     // Member functions
237         // Access to addressing
239             //- Return the LDU mesh from which the addressing is obtained
240             const lduMesh& mesh() const
241             {
242                 return lduMesh_;
243             }
245             //- Return eliminated equations
246             const labelHashSet& eliminatedEqns() const
247             {
248                 return eliminatedEqns_;
249             }
251             //- Return access to eliminated equations
252             labelHashSet& eliminatedEqns()
253             {
254                 return eliminatedEqns_;
255             }
257             //- Return the LDU addressing
258             const lduAddressing& lduAddr() const
259             {
260                 return lduMesh_.lduAddr();
261             }
263             //- Return the patch evaluation schedule
264             const lduSchedule& patchSchedule() const
265             {
266                 return lduAddr().patchSchedule();
267             }
270         // Access to coefficients
272             //- Return access to diagonal coefficients
273             TypeCoeffField& diag();
275             //- Return diagonal coefficients
276             const TypeCoeffField& diag() const;
278             //- Return access to upper coefficients
279             //  Also used for symmetric matrices
280             TypeCoeffField& upper();
282             //- Return upper coefficients
283             //  Also used for symmetric matrices
284             const TypeCoeffField& upper() const;
286             //- Return access to lower coefficients
287             TypeCoeffField& lower();
289             //- Return lower coefficients
290             const TypeCoeffField& lower() const;
292             //- Return access to coupled interface coefficients, upper
293             FieldField<CoeffField, Type>& coupleUpper()
294             {
295                 return coupleUpper_;
296             }
298             //- Return coupled interface coefficients, upper
299             const FieldField<CoeffField, Type>& coupleUpper() const
300             {
301                 return coupleUpper_;
302             }
304             //- Return access to coupled interface coefficients, lower
305             FieldField<CoeffField, Type>& coupleLower()
306             {
307                 return coupleLower_;
308             }
310             //- Return coupled interface coefficients, lower
311             const FieldField<CoeffField, Type>& coupleLower() const
312             {
313                 return coupleLower_;
314             }
316             //- Access to coupled interfaces
317             typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces()
318             {
319                 return interfaces_;
320             }
323         // Matrix structure
325             //- Return true if there is a diagonal
326             bool thereIsDiag() const
327             {
328                 return (diagPtr_);
329             }
331             //- Return true if upper triangle is allocated
332             bool thereIsUpper() const
333             {
334                 return (upperPtr_);
335             }
337             //- Return true if lower triangle is allocated
338             bool thereIsLower() const
339             {
340                 return (lowerPtr_);
341             }
343             //- Return true if matrix is empty
344             bool empty() const;
346             //- Return true if matrix is diagonal-only
347             bool diagonal() const;
349             //- Return true if matrix is symmetric
350             bool symmetric() const;
352             //- Return true if matrix is asymmetric
353             bool asymmetric() const;
355             //- Return true if matrix is component-coupled
356             bool componentCoupled() const;
359         // Operations
361             //- Sum off-diagonal coefficients and add to diagonal
362             void sumDiag();
364             //- Sum negative off-diagonal coefficients and add to diagonal
365             void negSumDiag();
367             //- Check matrix for diagonal dominance
368             void check() const;
370             //- Relax matrix
371             void relax
372             (
373                 const TypeField& x,
374                 TypeField& b,
375                 const scalar alpha
376             );
378             //- Matrix multiplication
379             void Amul
380             (
381                 TypeField& Ax,
382                 const TypeField& x
383             ) const;
385             //- Matrix multiplication without coupled interface update
386             void AmulCore
387             (
388                 TypeField& Ax,
389                 const TypeField& x
390             ) const;
392             //- Matrix transpose multiplication
393             void Tmul
394             (
395                 TypeField& Ax,
396                 const TypeField& x
397             ) const;
399             //- Matrix transpose multiplication without coupled
400            //  interface update
401             void TmulCore
402             (
403                 TypeField& Ax,
404                 const TypeField& x
405             ) const;
408             //- Return decoupled b
409             void segregateB
410             (
411                 TypeField& sMul,
412                 const TypeField& x
413             ) const;
416         // Coupled interface functionality
418             //- Initialise the update of coupled interfaces
419             //  for Amul operations
420             void initInterfaces
421             (
422                 const FieldField<CoeffField, Type>& interfaceCoeffs,
423                 TypeField& result,
424                 const TypeField& psi,
425                 const bool switchToLhs = false
426             ) const;
428             //- Update coupled interfaces
429             void updateInterfaces
430             (
431                 const FieldField<CoeffField, Type>& interfaceCoeffs,
432                 TypeField& result,
433                 const TypeField& psi,
434                 const bool switchToLhs = false
435             ) const;
438         // Constraint manipulation
440             //- Set constrained value in a prescribed point
441             void setValue
442             (
443                 const label eqnIndex,
444                 const Type& value
445             );
448         // Residual calculation
450             //- Calculate residual
451             tmp<TypeField> residual
452             (
453                 const TypeField& x
454             ) const;
456             tmp<TypeField> residual
457             (
458                 const TypeField& x,
459                 const TypeField& b
460             ) const;
463         // H-operations
465             //- Return L-U vector-matrix multiplication in row-form
466             tmp<TypeField> H(const TypeField&) const;
468             //- Return L-U  vector-matrix multiplication in off-diagonal form
469             tmp<TypeField> faceH(const TypeField&) const;
472     // Member operators
474         void operator=(const BlockLduMatrix<Type>&);
476         void negate();
478         void operator+=(const BlockLduMatrix<Type>&);
479         void operator-=(const BlockLduMatrix<Type>&);
481         void operator*=(const scalarField&);
482         void operator*=(const scalar);
485     // Ostream operator
487         friend Ostream& operator<< <Type>
488         (
489             Ostream&,
490             const BlockLduMatrix<Type>&
491         );
495 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
497 } // End namespace Foam
499 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
501 #ifdef NoRepository
502 #   include "BlockLduMatrix.C"
503 #   include "BlockLduMatrixOperations.C"
504 #   include "BlockLduMatrixUpdateInterfaces.C"
505 #   include "BlockLduMatrixATmul.C"
506 #   include "BlockLduMatrixHOps.C"
507 #   include "BlockLduMatrixDecouple.C"
508 #   include "BlockLduMatrixDecoupledHOps.C"
509 #endif
511 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
513 #endif
515 // ************************************************************************* //