ThirdParty: initial commit of the packages selection mechanism using environment...
[foam-extend-3.2.git] / src / finiteArea / faMatrices / faMatrix / faMatrix.H
blob0cd4c964acc07de33e76d537da2e8a71af4b40a4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
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     faMatrix<Type>
27 Description
28     Finite-Area matrix.
30 SourceFiles
31     faMatrix.C
32     faMatrixSolve.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef faMatrix_H
37 #define faMatrix_H
39 #include "areaFields.H"
40 #include "edgeFields.H"
41 #include "lduMatrix.H"
42 #include "tmp.H"
43 #include "autoPtr.H"
44 #include "dimensionedTypes.H"
45 #include "className.H"
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 namespace Foam
52 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
54 template<class Type>
55 class faMatrix;
57 template<class Type>
58 Ostream& operator<<(Ostream&, const faMatrix<Type>&);
61 /*---------------------------------------------------------------------------*\
62                            Class faMatrix Declaration
63 \*---------------------------------------------------------------------------*/
65 template<class Type>
66 class faMatrix
68     public refCount,
69     public lduMatrix
71     // Private data
73         // Reference to GeometricField<Type, faPatchField, areaMesh>
74         GeometricField<Type, faPatchField, areaMesh>& psi_;
76         //- Dimension set
77         dimensionSet dimensions_;
79         //- Source term
80         Field<Type> source_;
82         //- Boundary scalar field containing pseudo-matrix coeffs
83         //  for internal faces
84         FieldField<Field, Type> internalCoeffs_;
86         //- Boundary scalar field containing pseudo-matrix coeffs
87         //  for boundary faces
88         FieldField<Field, Type> boundaryCoeffs_;
91         //- Face flux field for non-orthogonal correction
92         mutable GeometricField<Type, faePatchField, edgeMesh>
93             *faceFluxCorrectionPtr_;
95         direction solvingComponent;
98     // Private member functions
100         //- Add patch contribution to internal field
101         template<class Type2>
102         void addToInternalField
103         (
104             const unallocLabelList& addr,
105             const Field<Type2>& pf,
106             Field<Type2>& intf
107         ) const;
109         template<class Type2>
110         void addToInternalField
111         (
112             const unallocLabelList& addr,
113             const tmp<Field<Type2> >& tpf,
114             Field<Type2>& intf
115         ) const;
117         //- Subtract patch contribution from internal field
118         template<class Type2>
119         void subtractFromInternalField
120         (
121             const unallocLabelList& addr,
122             const Field<Type2>& pf,
123             Field<Type2>& intf
124         ) const;
126         template<class Type2>
127         void subtractFromInternalField
128         (
129             const unallocLabelList& addr,
130             const tmp<Field<Type2> >& tpf,
131             Field<Type2>& intf
132         ) const;
135         // Matrix completion functionality
137             void addBoundaryDiag
138             (
139                 scalarField& diag,
140                 const direction cmpt
141             ) const;
143             void addCmptAvBoundaryDiag(scalarField& diag) const;
145             void addBoundarySource
146             (
147                 Field<Type>& source,
148                 const bool couples = true
149             ) const;
152 public:
154     //- Solver class returned by the solver function
155     class faSolver
156     {
157         faMatrix<Type>& faMat_;
159         autoPtr<lduSolver> solver_;
161     public:
163         // Constructors
165             faSolver(faMatrix<Type>& faMat, autoPtr<lduSolver> sol)
166             :
167                 faMat_(faMat),
168                 solver_(sol)
169             {}
172         // Member functions
174             //- Solve returning the solution statistics.
175             //  Solver controls read from dictionary
176             lduSolverPerformance solve(const dictionary&);
178             //- Solve returning the solution statistics.
179             //  Solver controls read from faSolution
180             lduSolverPerformance solve();
181     };
184     ClassName("faMatrix");
187     // Constructors
189         //- Construct given a field to solve for
190         faMatrix
191         (
192             GeometricField<Type, faPatchField, areaMesh>&,
193             const dimensionSet&
194         );
196         //- Construct as copy
197         faMatrix(const faMatrix<Type>&);
199         //- Construct from Istream given field to solve for
200         faMatrix(GeometricField<Type, faPatchField, areaMesh>&, Istream&);
203     // Destructor
205         virtual ~faMatrix();
208     // Member functions
210         // Access
212             const GeometricField<Type, faPatchField, areaMesh>& psi() const
213             {
214                 return psi_;
215             }
217             GeometricField<Type, faPatchField, areaMesh>& psi()
218             {
219                 return psi_;
220             }
222             const dimensionSet& dimensions() const
223             {
224                 return dimensions_;
225             }
227             Field<Type>& source()
228             {
229                 return source_;
230             }
232             const Field<Type>& source() const
233             {
234                 return source_;
235             }
237             //- faBoundary scalar field containing pseudo-matrix coeffs
238             //  for internal cells
239             FieldField<Field, Type>& internalCoeffs()
240             {
241                 return internalCoeffs_;
242             }
244             //- faBoundary scalar field containing pseudo-matrix coeffs
245             //  for boundary cells
246             FieldField<Field, Type>& boundaryCoeffs()
247             {
248                 return boundaryCoeffs_;
249             }
252             //- Declare return type of the faceFluxCorrectionPtr() function
253             typedef GeometricField<Type, faePatchField, edgeMesh>
254                 *edgeTypeFieldPtr;
256             //- Return pointer to face-flux non-orthogonal correction field
257             edgeTypeFieldPtr& faceFluxCorrectionPtr()
258             {
259                 return faceFluxCorrectionPtr_;
260             }
263         // Operations
265             //- Set solution in given cells and eliminate corresponding
266             //  equations from the matrix
267             void setValues
268             (
269                 const labelList& faces,
270                 const Field<Type>& values
271             );
273             //- Set reference level for solution
274             void setReference
275             (
276                 const label facei,
277                 const Type& value
278             );
280             //- Set reference level for a component of the solution
281             //  on a given patch face
282             void setComponentReference
283             (
284                 const label patchi,
285                 const label facei,
286                 const direction cmpt,
287                 const scalar value
288             );
290             //- Relax matrix (for steady-state solution).
291             //  alpha = 1 : diagonally equal
292             //  alpha < 1 :    ,,      dominant
293             //  alpha = 0 : do nothing
294             void relax(const scalar alpha);
296             //- Relax matrix (for steadty-state solution).
297             //  alpha is read from controlDict
298             void relax();
300             //- Construct and return the solver
301             //  Solver controls read from Istream
302             autoPtr<faSolver> solver(const dictionary&);
304             //- Construct and return the solver
305             //  Solver controls read from faSolution
306             autoPtr<faSolver> solver();
308             //- Solve returning the solution statistics.
309             //  Solver controls read Istream
310             lduSolverPerformance solve(const dictionary&);
312             //- Solve returning the solution statistics.
313             //  Solver controls read from faSolution
314             lduSolverPerformance solve();
316             //- Return the matrix residual
317             tmp<Field<Type> > residual() const;
319             //- Return the matrix diagonal
320             tmp<scalarField> D() const;
322             //- Return the central coefficient
323             tmp<areaScalarField> A() const;
325             //- Return the H operation source
326             tmp<GeometricField<Type, faPatchField, areaMesh> > H() const;
328             //- Return the face-flux field from the matrix
329             tmp<GeometricField<Type, faePatchField, edgeMesh> > flux() const;
332     // Member operators
334         void operator=(const faMatrix<Type>&);
335         void operator=(const tmp<faMatrix<Type> >&);
337         void negate();
339         void operator+=(const faMatrix<Type>&);
340         void operator+=(const tmp<faMatrix<Type> >&);
342         void operator-=(const faMatrix<Type>&);
343         void operator-=(const tmp<faMatrix<Type> >&);
345         void operator+=(const GeometricField<Type,faPatchField,areaMesh>&);
346         void operator+=(const tmp<GeometricField<Type,faPatchField,areaMesh> >&);
348         void operator-=(const GeometricField<Type,faPatchField,areaMesh>&);
349         void operator-=(const tmp<GeometricField<Type,faPatchField,areaMesh> >&);
351         void operator+=(const dimensioned<Type>&);
352         void operator-=(const dimensioned<Type>&);
354         void operator*=(const areaScalarField&);
355         void operator*=(const tmp<areaScalarField>&);
357         void operator*=(const dimensioned<scalar>&);
360     // Ostream operator
362         friend Ostream& operator<< <Type>
363         (
364             Ostream&,
365             const faMatrix<Type>&
366         );
370 // * * * * * * * * * * * * * * * Global functions  * * * * * * * * * * * * * //
372 template<class Type>
373 void checkMethod
375     const faMatrix<Type>&,
376     const faMatrix<Type>&,
377     const char*
380 template<class Type>
381 void checkMethod
383     const faMatrix<Type>&,
384     const GeometricField<Type, faPatchField, areaMesh>&,
385     const char*
388 template<class Type>
389 void checkMethod
391     const faMatrix<Type>&,
392     const dimensioned<Type>&,
393     const char*
397 //- Solve returning the solution statistics given convergence tolerance
398 //  Solver controls read Istream
399 template<class Type>
400 lduSolverPerformance solve(faMatrix<Type>&, Istream&);
403 //- Solve returning the solution statistics given convergence tolerance,
404 //  deleting temporary matrix after solution.
405 //  Solver controls read Istream
406 template<class Type>
407 lduSolverPerformance solve(const tmp<faMatrix<Type> >&, Istream&);
410 //- Solve returning the solution statistics given convergence tolerance
411 //  Solver controls read faSolution
412 template<class Type>
413 lduSolverPerformance solve(faMatrix<Type>&);
416 //- Solve returning the solution statistics given convergence tolerance,
417 //  deleting temporary matrix after solution.
418 //  Solver controls read faSolution
419 template<class Type>
420 lduSolverPerformance solve(const tmp<faMatrix<Type> >&);
423 // * * * * * * * * * * * * * * * Global operators  * * * * * * * * * * * * * //
425 template<class Type>
426 tmp<faMatrix<Type> > operator-
428     const faMatrix<Type>&
431 template<class Type>
432 tmp<faMatrix<Type> > operator-
434     const tmp<faMatrix<Type> >&
437 template<class Type>
438 tmp<faMatrix<Type> > operator+
440     const faMatrix<Type>&,
441     const faMatrix<Type>&
444 template<class Type>
445 tmp<faMatrix<Type> > operator+
447     const tmp<faMatrix<Type> >&,
448     const faMatrix<Type>&
451 template<class Type>
452 tmp<faMatrix<Type> > operator+
454     const faMatrix<Type>&,
455     const tmp<faMatrix<Type> >&
458 template<class Type>
459 tmp<faMatrix<Type> > operator+
461     const tmp<faMatrix<Type> >&,
462     const tmp<faMatrix<Type> >&
465 template<class Type>
466 tmp<faMatrix<Type> > operator-
468     const faMatrix<Type>&,
469     const faMatrix<Type>&
472 template<class Type>
473 tmp<faMatrix<Type> > operator-
475     const tmp<faMatrix<Type> >&,
476     const faMatrix<Type>&
479 template<class Type>
480 tmp<faMatrix<Type> > operator-
482     const faMatrix<Type>&,
483     const tmp<faMatrix<Type> >&
486 template<class Type>
487 tmp<faMatrix<Type> > operator-
489     const tmp<faMatrix<Type> >&,
490     const tmp<faMatrix<Type> >&
493 template<class Type>
494 tmp<faMatrix<Type> > operator==
496     const faMatrix<Type>&,
497     const faMatrix<Type>&
500 template<class Type>
501 tmp<faMatrix<Type> > operator==
503     const tmp<faMatrix<Type> >&,
504     const faMatrix<Type>&
507 template<class Type>
508 tmp<faMatrix<Type> > operator==
510     const faMatrix<Type>&,
511     const tmp<faMatrix<Type> >&
514 template<class Type>
515 tmp<faMatrix<Type> > operator==
517     const tmp<faMatrix<Type> >&,
518     const tmp<faMatrix<Type> >&
521 template<class Type>
522 tmp<faMatrix<Type> > operator+
524     const faMatrix<Type>&,
525     const GeometricField<Type, faPatchField, areaMesh>&
528 template<class Type>
529 tmp<faMatrix<Type> > operator+
531     const tmp<faMatrix<Type> >&,
532     const GeometricField<Type, faPatchField, areaMesh>&
535 template<class Type>
536 tmp<faMatrix<Type> > operator+
538     const faMatrix<Type>&,
539     const tmp<GeometricField<Type, faPatchField, areaMesh> >&
542 template<class Type>
543 tmp<faMatrix<Type> > operator+
545     const tmp<faMatrix<Type> >&,
546     const tmp<GeometricField<Type, faPatchField, areaMesh> >&
549 template<class Type>
550 tmp<faMatrix<Type> > operator+
552     const GeometricField<Type, faPatchField, areaMesh>&,
553     const faMatrix<Type>&
556 template<class Type>
557 tmp<faMatrix<Type> > operator+
559     const GeometricField<Type, faPatchField, areaMesh>&,
560     const tmp<faMatrix<Type> >&
563 template<class Type>
564 tmp<faMatrix<Type> > operator+
566     const tmp<GeometricField<Type, faPatchField, areaMesh> >&,
567     const faMatrix<Type>&
570 template<class Type>
571 tmp<faMatrix<Type> > operator+
573     const tmp<GeometricField<Type, faPatchField, areaMesh> >&,
574     const tmp<faMatrix<Type> >&
577 template<class Type>
578 tmp<faMatrix<Type> > operator-
580     const faMatrix<Type>&,
581     const GeometricField<Type, faPatchField, areaMesh>&
584 template<class Type>
585 tmp<faMatrix<Type> > operator-
587     const tmp<faMatrix<Type> >&,
588     const GeometricField<Type, faPatchField, areaMesh>&
591 template<class Type>
592 tmp<faMatrix<Type> > operator-
594     const faMatrix<Type>&,
595     const tmp<GeometricField<Type, faPatchField, areaMesh> >&
598 template<class Type>
599 tmp<faMatrix<Type> > operator-
601     const tmp<faMatrix<Type> >&,
602     const tmp<GeometricField<Type, faPatchField, areaMesh> >&
605 template<class Type>
606 tmp<faMatrix<Type> > operator-
608     const GeometricField<Type, faPatchField, areaMesh>&,
609     const faMatrix<Type>&
612 template<class Type>
613 tmp<faMatrix<Type> > operator-
615     const GeometricField<Type, faPatchField, areaMesh>&,
616     const tmp<faMatrix<Type> >&
619 template<class Type>
620 tmp<faMatrix<Type> > operator-
622     const tmp<GeometricField<Type, faPatchField, areaMesh> >&,
623     const faMatrix<Type>&
626 template<class Type>
627 tmp<faMatrix<Type> > operator-
629     const tmp<GeometricField<Type, faPatchField, areaMesh> >&,
630     const tmp<faMatrix<Type> >&
633 template<class Type>
634 tmp<faMatrix<Type> > operator+
636     const tmp<faMatrix<Type> >&,
637     const dimensioned<Type>&
640 template<class Type>
641 tmp<faMatrix<Type> > operator+
643     const dimensioned<Type>&,
644     const tmp<faMatrix<Type> >&
647 template<class Type>
648 tmp<faMatrix<Type> > operator-
650     const tmp<faMatrix<Type> >&,
651     const dimensioned<Type>&
654 template<class Type>
655 tmp<faMatrix<Type> > operator-
657     const dimensioned<Type>&,
658     const tmp<faMatrix<Type> >&
661 template<class Type>
662 tmp<faMatrix<Type> > operator==
664     const faMatrix<Type>&,
665     const GeometricField<Type, faPatchField, areaMesh>&
668 template<class Type>
669 tmp<faMatrix<Type> > operator==
671     const tmp<faMatrix<Type> >&,
672     const GeometricField<Type, faPatchField, areaMesh>&
675 template<class Type>
676 tmp<faMatrix<Type> > operator==
678     const faMatrix<Type>&,
679     const tmp<GeometricField<Type, faPatchField, areaMesh> >&
682 template<class Type>
683 tmp<faMatrix<Type> > operator==
685     const tmp<faMatrix<Type> >&,
686     const tmp<GeometricField<Type, faPatchField, areaMesh> >&
689 template<class Type>
690 tmp<faMatrix<Type> > operator==
692     const faMatrix<Type>&,
693     const dimensioned<Type>&
696 template<class Type>
697 tmp<faMatrix<Type> > operator==
699     const tmp<faMatrix<Type> >&,
700     const dimensioned<Type>&
704 template<class Type>
705 tmp<faMatrix<Type> > operator*
707     const areaScalarField&,
708     const faMatrix<Type>&
711 template<class Type>
712 tmp<faMatrix<Type> > operator*
714     const areaScalarField&,
715     const tmp<faMatrix<Type> >&
718 template<class Type>
719 tmp<faMatrix<Type> > operator*
721     const tmp<areaScalarField>&,
722     const faMatrix<Type>&
725 template<class Type>
726 tmp<faMatrix<Type> > operator*
728     const tmp<areaScalarField>&,
729     const tmp<faMatrix<Type> >&
733 template<class Type>
734 tmp<faMatrix<Type> > operator*
736     const dimensioned<scalar>&,
737     const faMatrix<Type>&
740 template<class Type>
741 tmp<faMatrix<Type> > operator*
743     const dimensioned<scalar>&,
744     const tmp<faMatrix<Type> >&
748 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
750 } // End namespace Foam
752 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
754 #ifdef NoRepository
755 #   include "faMatrix.C"
756 #endif
758 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
760 #endif
762 // ************************************************************************* //