1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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
29 Tetrahedral Finite Element matrix.
35 \*---------------------------------------------------------------------------*/
37 #ifndef tetFemMatrix_H
38 #define tetFemMatrix_H
40 #include "tetPointFields.H"
41 #include "elementFields.H"
42 #include "lduMatrix.H"
45 #include "dimensionedTypes.H"
47 #include "constraints.H"
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
60 Ostream& operator<<(Ostream&, const tetFemMatrix<Type>&);
63 /*---------------------------------------------------------------------------*\
64 Class tetFemMatrix Declaration
65 \*---------------------------------------------------------------------------*/
75 //- Reference to GeometricField
76 GeometricField<Type, tetPolyPatchField, tetPointMesh>& psi_;
79 dimensionSet dimensions_;
84 //- Are boundary conditions set?
85 mutable bool boundaryConditionsSet_;
87 //- Equation triangle map
88 mutable Map<constraint<Type> > fixedEqns_;
90 direction solvingComponent;
93 // Private static data
95 //- Matrix constraint fill-in
96 // Equals to the estimated fraction of fixed nodes in the matrix
97 static const label fixFillIn;
99 // Private Member Functions
101 //- Add boundary source and diagonal for gradient-type conditions
102 void addBoundarySourceDiag();
104 //- Store boundary coefficients
105 void storeBoundaryCoeffs() const;
107 //- Add coupling coefficients
108 // In parallel computations, the consequence of cell-by-cell
109 // matrix assembly is the fact that the "other part" of all the
110 // edge coefficients on the coupled edge and the diagonal
111 // coefficient is assembled on the neighbouring processor. The
112 // matrix assembly is therefore completed only once the matrix is
113 // completed, by adding the contribution from the neighbouring
115 // Note: There will be an additional component of
116 // vector-matrix multiply, for the edges originating on the
117 // parallel patch and protruding into the neighbouring domain.
118 // This is treated by doing a "local" multiplication on the
119 // neighbouring side and then adding the result.
121 void addCouplingCoeffs();
123 void eliminateCouplingCoeffs();
125 void addCouplingSource(scalarField&) const;
127 //- Set component boundary conditions
128 void setComponentBoundaryConditions
131 scalarField& psiCmpt,
132 scalarField& sourceCmpt
135 //- Reconstruct matrix
136 void reconstructMatrix();
138 //- Distribute source. Given an element field construct a source
139 // by distributing the volume integral over the element points
140 tmp<Field<Type> > distributeSource(const Field<Type>&) const;
145 // No tetFemSolver: boundary coefficients are not cached
148 ClassName("tetFemMatrix");
150 typedef constraint<Type> ConstraintType;
155 //- Construct given a field to solve for
158 GeometricField<Type, tetPolyPatchField, tetPointMesh>&,
162 //- Construct as copy
163 tetFemMatrix(const tetFemMatrix<Type>&);
165 //- Construct from Istream given field to solve for
168 GeometricField<Type, tetPolyPatchField, tetPointMesh>&,
175 virtual ~tetFemMatrix();
182 const GeometricField<Type, tetPolyPatchField, tetPointMesh>&
188 GeometricField<Type, tetPolyPatchField, tetPointMesh>& psi()
193 const dimensionSet& dimensions() const
198 Field<Type>& source()
203 const Field<Type>& source() const
208 //- Does the matrix need a reference level for solution
209 //bool needReference();
214 //- Set constrained value in a prescribed point
221 //- Relax matrix (for steady-state solution).
222 // alpha = 1 : diagonally equal
223 // alpha < 1 : ,, dominant
224 // alpha = 0 : do nothing
225 void relax(const scalar alpha);
227 //- Relax matrix (for steady-state solution).
228 // alpha is read from controlDict
231 //- Check matrix for diagonal dominance
234 //- Solve returning the solution statistics.
235 // Convergence tolerance read from dictionary
236 lduSolverPerformance solve(const dictionary&);
238 //- Solve returning the solution statistics.
239 // Solver controls read from tetFemSolution
240 lduSolverPerformance solve();
242 //- Return the matrix residual
243 tmp<Field<Type> > residual();
248 void operator=(const tetFemMatrix<Type>&);
249 void operator=(const tmp<tetFemMatrix<Type> >&);
253 void operator+=(const tetFemMatrix<Type>&);
254 void operator+=(const tmp<tetFemMatrix<Type> >&);
256 void operator-=(const tetFemMatrix<Type>&);
257 void operator-=(const tmp<tetFemMatrix<Type> >&);
261 const GeometricField<Type, elementPatchField, elementMesh>&
265 const tmp<GeometricField<Type, elementPatchField, elementMesh> >&
270 const GeometricField<Type, elementPatchField, elementMesh>&
275 const tmp<GeometricField<Type, elementPatchField, elementMesh> >&
278 void operator+=(const dimensioned<Type>&);
279 void operator-=(const dimensioned<Type>&);
281 void operator*=(const dimensioned<scalar>&);
285 friend Ostream& operator<< <Type>
288 const tetFemMatrix<Type>&
293 // * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * //
298 const tetFemMatrix<Type>&,
299 const tetFemMatrix<Type>&,
307 const tetFemMatrix<Type>&,
308 const GeometricField<Type, elementPatchField, elementMesh>&,
316 const tetFemMatrix<Type>&,
317 const dimensioned<Type>&,
322 //- Solve returning the solution statistics given convergence tolerance
323 // Solver controls read from Istream
325 lduSolverPerformance solve(tetFemMatrix<Type>&, Istream&);
328 //- Solve returning the solution statistics given convergence tolerance,
329 // deleting temporary matrix after solution.
330 // Solver controls read from Istream
332 lduSolverPerformance solve(const tmp<tetFemMatrix<Type> >&, Istream&);
335 //- Solve returning the solution statistics given convergence tolerance
336 // Convergence tolerance read from controlDict
338 lduSolverPerformance solve(tetFemMatrix<Type>&);
340 //- Solve returning the solution statistics given convergence tolerance,
341 // deleting temporary matrix after solution.
342 // Convergence tolerance read from controlDict
344 lduSolverPerformance solve(const tmp<tetFemMatrix<Type> >&);
347 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
350 tmp<tetFemMatrix<Type> > operator-
352 const tetFemMatrix<Type>&
356 tmp<tetFemMatrix<Type> > operator-
358 const tmp<tetFemMatrix<Type> >&
362 tmp<tetFemMatrix<Type> > operator+
364 const tetFemMatrix<Type>&,
365 const tetFemMatrix<Type>&
369 tmp<tetFemMatrix<Type> > operator+
371 const tmp<tetFemMatrix<Type> >&,
372 const tetFemMatrix<Type>&
376 tmp<tetFemMatrix<Type> > operator+
378 const tetFemMatrix<Type>&,
379 const tmp<tetFemMatrix<Type> >&
383 tmp<tetFemMatrix<Type> > operator+
385 const tmp<tetFemMatrix<Type> >&,
386 const tmp<tetFemMatrix<Type> >&
390 tmp<tetFemMatrix<Type> > operator-
392 const tetFemMatrix<Type>&,
393 const tetFemMatrix<Type>&
397 tmp<tetFemMatrix<Type> > operator-
399 const tmp<tetFemMatrix<Type> >&,
400 const tetFemMatrix<Type>&
404 tmp<tetFemMatrix<Type> > operator-
406 const tetFemMatrix<Type>&,
407 const tmp<tetFemMatrix<Type> >&
411 tmp<tetFemMatrix<Type> > operator-
413 const tmp<tetFemMatrix<Type> >&,
414 const tmp<tetFemMatrix<Type> >&
418 tmp<tetFemMatrix<Type> > operator==
420 const tetFemMatrix<Type>&,
421 const tetFemMatrix<Type>&
425 tmp<tetFemMatrix<Type> > operator==
427 const tmp<tetFemMatrix<Type> >&,
428 const tetFemMatrix<Type>&
432 tmp<tetFemMatrix<Type> > operator==
434 const tetFemMatrix<Type>&,
435 const tmp<tetFemMatrix<Type> >&
439 tmp<tetFemMatrix<Type> > operator==
441 const tmp<tetFemMatrix<Type> >&,
442 const tmp<tetFemMatrix<Type> >&
446 tmp<tetFemMatrix<Type> > operator+
448 const tetFemMatrix<Type>&,
449 const GeometricField<Type, elementPatchField, elementMesh>&
453 tmp<tetFemMatrix<Type> > operator+
455 const tmp<tetFemMatrix<Type> >&,
456 const GeometricField<Type, elementPatchField, elementMesh>&
460 tmp<tetFemMatrix<Type> > operator+
462 const tetFemMatrix<Type>&,
463 const tmp<GeometricField<Type, elementPatchField, elementMesh> >&
467 tmp<tetFemMatrix<Type> > operator+
469 const tmp<tetFemMatrix<Type> >&,
470 const tmp<GeometricField<Type, elementPatchField, elementMesh> >&
474 tmp<tetFemMatrix<Type> > operator+
476 const GeometricField<Type, elementPatchField, elementMesh>&,
477 const tetFemMatrix<Type>&
481 tmp<tetFemMatrix<Type> > operator+
483 const GeometricField<Type, elementPatchField, elementMesh>&,
484 const tmp<tetFemMatrix<Type> >&
488 tmp<tetFemMatrix<Type> > operator+
490 const tmp<GeometricField<Type, elementPatchField, elementMesh> >&,
491 const tetFemMatrix<Type>&
495 tmp<tetFemMatrix<Type> > operator+
497 const tmp<GeometricField<Type, elementPatchField, elementMesh> >&,
498 const tmp<tetFemMatrix<Type> >&
502 tmp<tetFemMatrix<Type> > operator-
504 const tetFemMatrix<Type>&,
505 const GeometricField<Type, elementPatchField, elementMesh>&
509 tmp<tetFemMatrix<Type> > operator-
511 const tmp<tetFemMatrix<Type> >&,
512 const GeometricField<Type, elementPatchField, elementMesh>&
516 tmp<tetFemMatrix<Type> > operator-
518 const tetFemMatrix<Type>&,
519 const tmp<GeometricField<Type, elementPatchField, elementMesh> >&
523 tmp<tetFemMatrix<Type> > operator-
525 const tmp<tetFemMatrix<Type> >&,
526 const tmp<GeometricField<Type, elementPatchField, elementMesh> >&
530 tmp<tetFemMatrix<Type> > operator-
532 const GeometricField<Type, elementPatchField, elementMesh>&,
533 const tetFemMatrix<Type>&
537 tmp<tetFemMatrix<Type> > operator-
539 const GeometricField<Type, elementPatchField, elementMesh>&,
540 const tmp<tetFemMatrix<Type> >&
544 tmp<tetFemMatrix<Type> > operator-
546 const tmp<GeometricField<Type, elementPatchField, elementMesh> >&,
547 const tetFemMatrix<Type>&
551 tmp<tetFemMatrix<Type> > operator-
553 const tmp<GeometricField<Type, elementPatchField, elementMesh> >&,
554 const tmp<tetFemMatrix<Type> >&
558 tmp<tetFemMatrix<Type> > operator+
560 const tmp<tetFemMatrix<Type> >&,
561 const dimensioned<Type>&
565 tmp<tetFemMatrix<Type> > operator+
567 const dimensioned<Type>&,
568 const tmp<tetFemMatrix<Type> >&
572 tmp<tetFemMatrix<Type> > operator-
574 const tmp<tetFemMatrix<Type> >&,
575 const dimensioned<Type>&
579 tmp<tetFemMatrix<Type> > operator-
581 const dimensioned<Type>&,
582 const tmp<tetFemMatrix<Type> >&
586 tmp<tetFemMatrix<Type> > operator==
588 const tetFemMatrix<Type>&,
589 const GeometricField<Type, elementPatchField, elementMesh>&
593 tmp<tetFemMatrix<Type> > operator==
595 const tmp<tetFemMatrix<Type> >&,
596 const GeometricField<Type, elementPatchField, elementMesh>&
600 tmp<tetFemMatrix<Type> > operator==
602 const tetFemMatrix<Type>&,
603 const tmp<GeometricField<Type, elementPatchField, elementMesh> >&
607 tmp<tetFemMatrix<Type> > operator==
609 const tmp<tetFemMatrix<Type> >&,
610 const tmp<GeometricField<Type, elementPatchField, elementMesh> >&
614 tmp<tetFemMatrix<Type> > operator==
616 const tetFemMatrix<Type>&,
617 const dimensioned<Type>&
621 tmp<tetFemMatrix<Type> > operator==
623 const tmp<tetFemMatrix<Type> >&,
624 const dimensioned<Type>&
629 tmp<tetFemMatrix<Type> > operator*
631 const dimensioned<scalar>&,
632 const tetFemMatrix<Type>&
636 tmp<tetFemMatrix<Type> > operator*
638 const dimensioned<scalar>&,
639 const tmp<tetFemMatrix<Type> >&
643 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
645 } // End namespace Foam
647 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
650 # include "tetFemMatrix.C"
651 # include "tetFemMatrixSolve.C"
652 # include "tetFemMatrixTools.C"
653 # include "tetFemMatrixCheck.C"
656 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
660 // ************************************************************************* //