1 /*---------------------------------------------------------------------------*\
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 -------------------------------------------------------------------------------
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/>.
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.
34 Hrvoje Jasak, Wikki Ltd. All rights reserved.
38 BlockLduMatrixOperations.C
39 BlockLduMatrixUpdateInterfaces.C
42 BlockLduMatrixDecouple.C
43 BlockLduMatrixDecoupledHOps.C
45 \*---------------------------------------------------------------------------*/
47 #ifndef BlockLduMatrix_H
48 #define BlockLduMatrix_H
50 #include "coeffFields.H"
51 #include "FieldField.H"
54 #include "BlockLduInterfaceFieldPtrsList.H"
56 #include "optimisationSwitch.H"
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
69 Ostream& operator<<(Ostream&, const BlockLduMatrix<Type>&);
72 class BlockConstraint;
75 /*---------------------------------------------------------------------------*\
76 Class BlockLduMatrix Declaration
77 \*---------------------------------------------------------------------------*/
88 typedef CoeffField<Type> TypeCoeffField;
89 typedef Field<Type> TypeField;
90 typedef BlockConstraint<Type> ConstraintType;
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_;
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_;
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,
148 void decoupledSumDiag();
150 //- Sum negative off-diagonal coefficients and add to diagonal,
152 void decoupledNegSumDiag();
154 //- Check matrix for diagonal dominance, decoupled version
155 void decoupledCheck() const;
157 //- Relax matrix, decoupled version
165 //- Matrix scaling with scalar field, decoupled version
166 void decoupledMultEqOp(const scalarField& sf);
168 //- Matrix multiplication without coupled interface update,
170 void decoupledAmulCore
176 //- Matrix transpose multiplication without coupled
179 void decoupledTmulCore
185 //- Return L-U vector-matrix multiplication in row-form,
187 tmp<TypeField> decoupledH(const TypeField& x) const;
189 //- Return L-U vector-matrix multiplication in off-diagonal form,
191 tmp<TypeField> decoupledFaceH(const TypeField& x) const;
196 // Access to constraints
198 //- Return constraint map
199 const Map<ConstraintType>& fixedEqns() const
205 //- Return access constraint map
206 Map<ConstraintType>& fixedEqns()
214 //- Runtime type information
215 TypeName("BlockLduMatrix");
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);
232 virtual ~BlockLduMatrix();
237 // Access to addressing
239 //- Return the LDU mesh from which the addressing is obtained
240 const lduMesh& mesh() const
245 //- Return eliminated equations
246 const labelHashSet& eliminatedEqns() const
248 return eliminatedEqns_;
251 //- Return access to eliminated equations
252 labelHashSet& eliminatedEqns()
254 return eliminatedEqns_;
257 //- Return the LDU addressing
258 const lduAddressing& lduAddr() const
260 return lduMesh_.lduAddr();
263 //- Return the patch evaluation schedule
264 const lduSchedule& patchSchedule() const
266 return lduAddr().patchSchedule();
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()
298 //- Return coupled interface coefficients, upper
299 const FieldField<CoeffField, Type>& coupleUpper() const
304 //- Return access to coupled interface coefficients, lower
305 FieldField<CoeffField, Type>& coupleLower()
310 //- Return coupled interface coefficients, lower
311 const FieldField<CoeffField, Type>& coupleLower() const
316 //- Access to coupled interfaces
317 typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces()
325 //- Return true if there is a diagonal
326 bool thereIsDiag() const
331 //- Return true if upper triangle is allocated
332 bool thereIsUpper() const
337 //- Return true if lower triangle is allocated
338 bool thereIsLower() const
343 //- Return true if matrix is empty
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;
361 //- Sum off-diagonal coefficients and add to diagonal
364 //- Sum negative off-diagonal coefficients and add to diagonal
367 //- Check matrix for diagonal dominance
378 //- Matrix multiplication
385 //- Matrix multiplication without coupled interface update
392 //- Matrix transpose multiplication
399 //- Matrix transpose multiplication without coupled
408 //- Return decoupled b
416 // Coupled interface functionality
418 //- Initialise the update of coupled interfaces
419 // for Amul operations
422 const FieldField<CoeffField, Type>& interfaceCoeffs,
424 const TypeField& psi,
425 const bool switchToLhs = false
428 //- Update coupled interfaces
429 void updateInterfaces
431 const FieldField<CoeffField, Type>& interfaceCoeffs,
433 const TypeField& psi,
434 const bool switchToLhs = false
438 // Constraint manipulation
440 //- Set constrained value in a prescribed point
443 const label eqnIndex,
448 // Residual calculation
450 //- Calculate residual
451 tmp<TypeField> residual
456 tmp<TypeField> residual
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;
474 void operator=(const BlockLduMatrix<Type>&);
478 void operator+=(const BlockLduMatrix<Type>&);
479 void operator-=(const BlockLduMatrix<Type>&);
481 void operator*=(const scalarField&);
482 void operator*=(const scalar);
487 friend Ostream& operator<< <Type>
490 const BlockLduMatrix<Type>&
495 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
497 } // End namespace Foam
499 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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"
511 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
515 // ************************************************************************* //