1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | 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"
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
68 Ostream& operator<<(Ostream&, const BlockLduMatrix<Type>&);
71 class BlockConstraint;
74 /*---------------------------------------------------------------------------*\
75 Class BlockLduMatrix Declaration
76 \*---------------------------------------------------------------------------*/
87 typedef CoeffField<Type> TypeCoeffField;
88 typedef Field<Type> TypeField;
89 typedef BlockConstraint<Type> ConstraintType;
97 const lduMesh& lduMesh_;
99 //- Eliminated equations
100 // Consider adding solo cells on construction. HJ, 26/Oct/2012
101 labelHashSet eliminatedEqns_;
104 // Block matrix elements
106 //- Diagonal coefficients
107 CoeffField<Type>* diagPtr_;
109 //- Upper triangle coefficients. Also used for symmetric matrix
110 CoeffField<Type>* upperPtr_;
112 //- Lower triangle coefficients
113 CoeffField<Type> *lowerPtr_;
118 //- List of coupled interfaces
119 typename BlockLduInterfaceFieldPtrsList<Type>::Type interfaces_;
121 //- Coupled interface coefficients, upper
122 FieldField<CoeffField, Type> coupleUpper_;
124 //- Coupled interface coefficients, lower
125 FieldField<CoeffField, Type> coupleLower_;
130 //- Equation triangle map
131 mutable Map<ConstraintType> fixedEqns_;
134 // Private static data
136 //- Matrix constraint fill-in
137 // Equals to the estimated fraction of fixed nodes in the matrix
138 static const label fixFillIn;
141 // Private member functions
143 // Decoupled versions of nmatrix operations
145 //- Sum off-diagonal coefficients and add to diagonal,
147 void decoupledSumDiag();
149 //- Sum negative off-diagonal coefficients and add to diagonal,
151 void decoupledNegSumDiag();
153 //- Check matrix for diagonal dominance, decoupled version
154 void decoupledCheck() const;
156 //- Relax matrix, decoupled version
164 //- Matrix scaling with scalar field, decoupled version
165 void decoupledMultEqOp(const scalarField& sf);
167 //- Matrix multiplication without coupled interface update,
169 void decoupledAmulCore
175 //- Matrix transpose multiplication without coupled
178 void decoupledTmulCore
184 //- Return L-U vector-matrix multiplication in row-form,
186 tmp<TypeField> decoupledH(const TypeField& x) const;
188 //- Return L-U vector-matrix multiplication in off-diagonal form,
190 tmp<TypeField> decoupledFaceH(const TypeField& x) const;
195 // Access to constraints
197 //- Return constraint map
198 const Map<ConstraintType>& fixedEqns() const
204 //- Return access constraint map
205 Map<ConstraintType>& fixedEqns()
213 //- Runtime type information
214 TypeName("BlockLduMatrix");
219 //- Construct given addressing
220 explicit BlockLduMatrix(const lduMesh&);
222 //- Construct as copy
223 BlockLduMatrix(const BlockLduMatrix<Type>&);
225 //- Construct as copy or re-use as specified.
226 BlockLduMatrix(BlockLduMatrix<Type>&, bool reUse);
231 virtual ~BlockLduMatrix();
236 // Access to addressing
238 //- Return the LDU mesh from which the addressing is obtained
239 const lduMesh& mesh() const
244 //- Return eliminated equations
245 const labelHashSet& eliminatedEqns() const
247 return eliminatedEqns_;
250 //- Return access to eliminated equations
251 labelHashSet& eliminatedEqns()
253 return eliminatedEqns_;
256 //- Return the LDU addressing
257 const lduAddressing& lduAddr() const
259 return lduMesh_.lduAddr();
262 //- Return the patch evaluation schedule
263 const lduSchedule& patchSchedule() const
265 return lduAddr().patchSchedule();
269 // Access to coefficients
271 //- Return access to diagonal coefficients
272 TypeCoeffField& diag();
274 //- Return diagonal coefficients
275 const TypeCoeffField& diag() const;
277 //- Return access to upper coefficients
278 // Also used for symmetric matrices
279 TypeCoeffField& upper();
281 //- Return upper coefficients
282 // Also used for symmetric matrices
283 const TypeCoeffField& upper() const;
285 //- Return access to lower coefficients
286 TypeCoeffField& lower();
288 //- Return lower coefficients
289 const TypeCoeffField& lower() const;
291 //- Return access to coupled interface coefficients, upper
292 FieldField<CoeffField, Type>& coupleUpper()
297 //- Return coupled interface coefficients, upper
298 const FieldField<CoeffField, Type>& coupleUpper() const
303 //- Return access to coupled interface coefficients, lower
304 FieldField<CoeffField, Type>& coupleLower()
309 //- Return coupled interface coefficients, lower
310 const FieldField<CoeffField, Type>& coupleLower() const
315 //- Access to coupled interfaces
316 typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces()
324 //- Return true if there is a diagonal
325 bool thereIsDiag() const
330 //- Return true if upper triangle is allocated
331 bool thereIsUpper() const
336 //- Return true if lower triangle is allocated
337 bool thereIsLower() const
342 //- Return true if matrix is empty
345 //- Return true if matrix is diagonal-only
346 bool diagonal() const;
348 //- Return true if matrix is symmetric
349 bool symmetric() const;
351 //- Return true if matrix is asymmetric
352 bool asymmetric() const;
354 //- Return true if matrix is component-coupled
355 bool componentCoupled() const;
360 //- Sum off-diagonal coefficients and add to diagonal
363 //- Sum negative off-diagonal coefficients and add to diagonal
366 //- Check matrix for diagonal dominance
377 //- Matrix multiplication
384 //- Matrix multiplication without coupled interface update
391 //- Matrix transpose multiplication
398 //- Matrix transpose multiplication without coupled
407 //- Return decoupled b
415 // Coupled interface functionality
417 //- Initialise the update of coupled interfaces
418 // for Amul operations
421 const FieldField<CoeffField, Type>& interfaceCoeffs,
423 const TypeField& psi,
424 const bool switchToLhs = false
427 //- Update coupled interfaces
428 void updateInterfaces
430 const FieldField<CoeffField, Type>& interfaceCoeffs,
432 const TypeField& psi,
433 const bool switchToLhs = false
437 // Constraint manipulation
439 //- Set constrained value in a prescribed point
442 const label eqnIndex,
447 // Residual calculation
449 //- Calculate residual
450 tmp<TypeField> residual
455 tmp<TypeField> residual
464 //- Return L-U vector-matrix multiplication in row-form
465 tmp<TypeField> H(const TypeField&) const;
467 //- Return L-U vector-matrix multiplication in off-diagonal form
468 tmp<TypeField> faceH(const TypeField&) const;
473 void operator=(const BlockLduMatrix<Type>&);
477 void operator+=(const BlockLduMatrix<Type>&);
478 void operator-=(const BlockLduMatrix<Type>&);
480 void operator*=(const scalarField&);
481 void operator*=(const scalar);
486 friend Ostream& operator<< <Type>
489 const BlockLduMatrix<Type>&
494 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
496 } // End namespace Foam
498 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
501 # include "BlockLduMatrix.C"
502 # include "BlockLduMatrixOperations.C"
503 # include "BlockLduMatrixUpdateInterfaces.C"
504 # include "BlockLduMatrixATmul.C"
505 # include "BlockLduMatrixHOps.C"
506 # include "BlockLduMatrixDecouple.C"
507 # include "BlockLduMatrixDecoupledHOps.C"
510 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
514 // ************************************************************************* //