1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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
36 \*---------------------------------------------------------------------------*/
41 #include "volFields.H"
42 #include "surfaceFields.H"
43 #include "lduMatrix.H"
46 #include "dimensionedTypes.H"
47 #include "zeroField.H"
48 #include "className.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 // Forward declaration of friend functions and operators
61 tmp<GeometricField<Type, fvPatchField, volMesh> > operator&
63 const fvMatrix<Type>&,
64 const DimensionedField<Type, volMesh>&
68 tmp<GeometricField<Type, fvPatchField, volMesh> > operator&
70 const fvMatrix<Type>&,
71 const tmp<DimensionedField<Type, volMesh> >&
75 tmp<GeometricField<Type, fvPatchField, volMesh> > operator&
77 const fvMatrix<Type>&,
78 const tmp<GeometricField<Type, fvPatchField, volMesh> >&
82 tmp<GeometricField<Type, fvPatchField, volMesh> > operator&
84 const tmp<fvMatrix<Type> >&,
85 const DimensionedField<Type, volMesh>&
89 tmp<GeometricField<Type, fvPatchField, volMesh> > operator&
91 const tmp<fvMatrix<Type> >&,
92 const tmp<DimensionedField<Type, volMesh> >&
96 tmp<GeometricField<Type, fvPatchField, volMesh> > operator&
98 const tmp<fvMatrix<Type> >&,
99 const tmp<GeometricField<Type, fvPatchField, volMesh> >&
103 Ostream& operator<<(Ostream&, const fvMatrix<Type>&);
106 /*---------------------------------------------------------------------------*\
107 Class fvMatrix Declaration
108 \*---------------------------------------------------------------------------*/
120 // Reference to GeometricField<Type, fvPatchField, volMesh>
121 GeometricField<Type, fvPatchField, volMesh>& psi_;
124 dimensionSet dimensions_;
129 //- Boundary scalar field containing pseudo-matrix coeffs
130 // for internal cells
131 FieldField<Field, Type> internalCoeffs_;
133 //- Boundary scalar field containing pseudo-matrix coeffs
134 // for boundary cells
135 FieldField<Field, Type> boundaryCoeffs_;
138 //- Face flux field for non-orthogonal correction
139 mutable GeometricField<Type, fvsPatchField, surfaceMesh>
140 *faceFluxCorrectionPtr_;
143 // Private member functions
145 //- Add patch contribution to internal field
146 template<class Type2>
147 void addToInternalField
149 const unallocLabelList& addr,
150 const Field<Type2>& pf,
154 template<class Type2>
155 void addToInternalField
157 const unallocLabelList& addr,
158 const tmp<Field<Type2> >& tpf,
162 //- Subtract patch contribution from internal field
163 template<class Type2>
164 void subtractFromInternalField
166 const unallocLabelList& addr,
167 const Field<Type2>& pf,
171 template<class Type2>
172 void subtractFromInternalField
174 const unallocLabelList& addr,
175 const tmp<Field<Type2> >& tpf,
180 // Matrix completion functionality
188 void addCmptAvBoundaryDiag(scalarField& diag) const;
190 void addBoundarySource
193 const bool couples=true
199 //- Solver class returned by the solver function
200 // used for systems in which it is useful to cache the solver for reuse
201 // e.g. is the solver is potentialy expensive to construct (AMG) and can
202 // be used several times (PISO)
205 fvMatrix<Type>& fvMat_;
207 autoPtr<lduMatrix::solver> solver_;
213 fvSolver(fvMatrix<Type>& fvMat, autoPtr<lduMatrix::solver> sol)
222 //- Solve returning the solution statistics.
223 // Solver controls read from Istream
224 lduMatrix::solverPerformance solve(Istream&);
226 //- Solve returning the solution statistics.
227 // Solver controls read from fvSolution
228 lduMatrix::solverPerformance solve();
232 ClassName("fvMatrix");
237 //- Construct given a field to solve for
240 GeometricField<Type, fvPatchField, volMesh>&,
244 //- Construct as copy
245 fvMatrix(const fvMatrix<Type>&);
247 //- Construct as copy of tmp<fvMatrix<Type> > deleting argument
248 # ifdef ConstructFromTmp
249 fvMatrix(const tmp<fvMatrix<Type> >&);
252 //- Construct from Istream given field to solve for
253 fvMatrix(GeometricField<Type, fvPatchField, volMesh>&, Istream&);
265 const GeometricField<Type, fvPatchField, volMesh>& psi() const
270 GeometricField<Type, fvPatchField, volMesh>& psi()
275 const dimensionSet& dimensions() const
280 Field<Type>& source()
285 const Field<Type>& source() const
290 //- fvBoundary scalar field containing pseudo-matrix coeffs
291 // for internal cells
292 FieldField<Field, Type>& internalCoeffs()
294 return internalCoeffs_;
297 //- fvBoundary scalar field containing pseudo-matrix coeffs
298 // for boundary cells
299 FieldField<Field, Type>& boundaryCoeffs()
301 return boundaryCoeffs_;
305 //- Declare return type of the faceFluxCorrectionPtr() function
306 typedef GeometricField<Type, fvsPatchField, surfaceMesh>
307 *surfaceTypeFieldPtr;
309 //- Return pointer to face-flux non-orthogonal correction field
310 surfaceTypeFieldPtr& faceFluxCorrectionPtr()
312 return faceFluxCorrectionPtr_;
318 //- Set solution in given cells and eliminate corresponding
319 // equations from the matrix
322 const labelList& cells,
323 const Field<Type>& values
326 //- Set reference level for solution
331 const bool forceReference = false
334 //- Set reference level for a component of the solution
335 // on a given patch face
336 void setComponentReference
340 const direction cmpt,
344 //- Relax matrix (for steady-state solution).
345 // alpha = 1 : diagonally equal
346 // alpha < 1 : diagonally dominant
347 // alpha = 0 : do nothing
348 void relax(const scalar alpha);
350 //- Relax matrix (for steady-state solution).
351 // alpha is read from controlDict
354 //- Construct and return the solver
355 // Solver controls read from Istream
356 autoPtr<fvSolver> solver(Istream&);
358 //- Construct and return the solver
359 // Solver controls read from fvSolution
360 autoPtr<fvSolver> solver();
362 //- Solve returning the solution statistics.
363 // Solver controls read from Istream
364 lduMatrix::solverPerformance solve(Istream&);
366 //- Solve returning the solution statistics.
367 // Solver controls read from fvSolution
368 lduMatrix::solverPerformance solve();
370 //- Return the matrix residual
371 tmp<Field<Type> > residual() const;
373 //- Return the matrix scalar diagonal
374 tmp<scalarField> D() const;
376 //- Return the matrix Type diagonal
377 tmp<Field<Type> > DD() const;
379 //- Return the central coefficient
380 tmp<volScalarField> A() const;
382 //- Return the H operation source
383 tmp<GeometricField<Type, fvPatchField, volMesh> > H() const;
386 tmp<volScalarField> H1() const;
388 //- Return the face-flux field from the matrix
389 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
395 void operator=(const fvMatrix<Type>&);
396 void operator=(const tmp<fvMatrix<Type> >&);
400 void operator+=(const fvMatrix<Type>&);
401 void operator+=(const tmp<fvMatrix<Type> >&);
403 void operator-=(const fvMatrix<Type>&);
404 void operator-=(const tmp<fvMatrix<Type> >&);
408 const DimensionedField<Type, volMesh>&
412 const tmp<DimensionedField<Type, volMesh> >&
416 const tmp<GeometricField<Type, fvPatchField, volMesh> >&
421 const DimensionedField<Type, volMesh>&
425 const tmp<DimensionedField<Type, volMesh> >&
429 const tmp<GeometricField<Type, fvPatchField, volMesh> >&
432 void operator+=(const dimensioned<Type>&);
433 void operator-=(const dimensioned<Type>&);
435 void operator+=(const zeroField&);
436 void operator-=(const zeroField&);
438 void operator*=(const DimensionedField<scalar, volMesh>&);
439 void operator*=(const tmp<DimensionedField<scalar, volMesh> >&);
440 void operator*=(const tmp<volScalarField>&);
442 void operator*=(const dimensioned<scalar>&);
447 friend tmp<GeometricField<Type, fvPatchField, volMesh> >
450 const fvMatrix<Type>&,
451 const DimensionedField<Type, volMesh>&
454 friend tmp<GeometricField<Type, fvPatchField, volMesh> >
457 const fvMatrix<Type>&,
458 const tmp<GeometricField<Type, fvPatchField, volMesh> >&
461 friend tmp<GeometricField<Type, fvPatchField, volMesh> >
464 const tmp<fvMatrix<Type> >&,
465 const DimensionedField<Type, volMesh>&
468 friend tmp<GeometricField<Type, fvPatchField, volMesh> >
471 const tmp<fvMatrix<Type> >&,
472 const tmp<GeometricField<Type, fvPatchField, volMesh> >&
478 friend Ostream& operator<< <Type>
481 const fvMatrix<Type>&
486 // * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * //
491 const fvMatrix<Type>&,
492 const fvMatrix<Type>&,
499 const fvMatrix<Type>&,
500 const DimensionedField<Type, volMesh>&,
507 const fvMatrix<Type>&,
508 const dimensioned<Type>&,
513 //- Solve returning the solution statistics given convergence tolerance
514 // Solver controls read Istream
516 lduMatrix::solverPerformance solve(fvMatrix<Type>&, Istream&);
519 //- Solve returning the solution statistics given convergence tolerance,
520 // deleting temporary matrix after solution.
521 // Solver controls read Istream
523 lduMatrix::solverPerformance solve(const tmp<fvMatrix<Type> >&, Istream&);
526 //- Solve returning the solution statistics given convergence tolerance
527 // Solver controls read fvSolution
529 lduMatrix::solverPerformance solve(fvMatrix<Type>&);
532 //- Solve returning the solution statistics given convergence tolerance,
533 // deleting temporary matrix after solution.
534 // Solver controls read fvSolution
536 lduMatrix::solverPerformance solve(const tmp<fvMatrix<Type> >&);
539 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
542 tmp<fvMatrix<Type> > operator==
544 const fvMatrix<Type>&,
545 const fvMatrix<Type>&
549 tmp<fvMatrix<Type> > operator==
551 const tmp<fvMatrix<Type> >&,
552 const fvMatrix<Type>&
556 tmp<fvMatrix<Type> > operator==
558 const fvMatrix<Type>&,
559 const tmp<fvMatrix<Type> >&
563 tmp<fvMatrix<Type> > operator==
565 const tmp<fvMatrix<Type> >&,
566 const tmp<fvMatrix<Type> >&
571 tmp<fvMatrix<Type> > operator==
573 const fvMatrix<Type>&,
574 const DimensionedField<Type, volMesh>&
578 tmp<fvMatrix<Type> > operator==
580 const fvMatrix<Type>&,
581 const tmp<DimensionedField<Type, volMesh> >&
585 tmp<fvMatrix<Type> > operator==
587 const fvMatrix<Type>&,
588 const tmp<GeometricField<Type, fvPatchField, volMesh> >&
592 tmp<fvMatrix<Type> > operator==
594 const tmp<fvMatrix<Type> >&,
595 const DimensionedField<Type, volMesh>&
599 tmp<fvMatrix<Type> > operator==
601 const tmp<fvMatrix<Type> >&,
602 const tmp<DimensionedField<Type, volMesh> >&
606 tmp<fvMatrix<Type> > operator==
608 const tmp<fvMatrix<Type> >&,
609 const tmp<GeometricField<Type, fvPatchField, volMesh> >&
613 tmp<fvMatrix<Type> > operator==
615 const fvMatrix<Type>&,
616 const dimensioned<Type>&
620 tmp<fvMatrix<Type> > operator==
622 const tmp<fvMatrix<Type> >&,
623 const dimensioned<Type>&
628 tmp<fvMatrix<Type> > operator==
630 const fvMatrix<Type>&,
635 tmp<fvMatrix<Type> > operator==
637 const tmp<fvMatrix<Type> >&,
643 tmp<fvMatrix<Type> > operator-
645 const fvMatrix<Type>&
649 tmp<fvMatrix<Type> > operator-
651 const tmp<fvMatrix<Type> >&
656 tmp<fvMatrix<Type> > operator+
658 const fvMatrix<Type>&,
659 const fvMatrix<Type>&
663 tmp<fvMatrix<Type> > operator+
665 const tmp<fvMatrix<Type> >&,
666 const fvMatrix<Type>&
670 tmp<fvMatrix<Type> > operator+
672 const fvMatrix<Type>&,
673 const tmp<fvMatrix<Type> >&
677 tmp<fvMatrix<Type> > operator+
679 const tmp<fvMatrix<Type> >&,
680 const tmp<fvMatrix<Type> >&
685 tmp<fvMatrix<Type> > operator+
687 const fvMatrix<Type>&,
688 const DimensionedField<Type, volMesh>&
692 tmp<fvMatrix<Type> > operator+
694 const fvMatrix<Type>&,
695 const tmp<DimensionedField<Type, volMesh> >&
699 tmp<fvMatrix<Type> > operator+
701 const fvMatrix<Type>&,
702 const tmp<GeometricField<Type, fvPatchField, volMesh> >&
706 tmp<fvMatrix<Type> > operator+
708 const tmp<fvMatrix<Type> >&,
709 const DimensionedField<Type, volMesh>&
713 tmp<fvMatrix<Type> > operator+
715 const tmp<fvMatrix<Type> >&,
716 const tmp<DimensionedField<Type, volMesh> >&
720 tmp<fvMatrix<Type> > operator+
722 const tmp<fvMatrix<Type> >&,
723 const tmp<GeometricField<Type, fvPatchField, volMesh> >&
727 tmp<fvMatrix<Type> > operator+
729 const DimensionedField<Type, volMesh>&,
730 const fvMatrix<Type>&
734 tmp<fvMatrix<Type> > operator+
736 const tmp<DimensionedField<Type, volMesh> >&,
737 const fvMatrix<Type>&
741 tmp<fvMatrix<Type> > operator+
743 const tmp<GeometricField<Type, fvPatchField, volMesh> >&,
744 const fvMatrix<Type>&
748 tmp<fvMatrix<Type> > operator+
750 const DimensionedField<Type, volMesh>&,
751 const tmp<fvMatrix<Type> >&
755 tmp<fvMatrix<Type> > operator+
757 const tmp<DimensionedField<Type, volMesh> >&,
758 const tmp<fvMatrix<Type> >&
762 tmp<fvMatrix<Type> > operator+
764 const tmp<GeometricField<Type, fvPatchField, volMesh> >&,
765 const tmp<fvMatrix<Type> >&
770 tmp<fvMatrix<Type> > operator+
772 const fvMatrix<Type>&,
773 const dimensioned<Type>&
777 tmp<fvMatrix<Type> > operator+
779 const tmp<fvMatrix<Type> >&,
780 const dimensioned<Type>&
784 tmp<fvMatrix<Type> > operator+
786 const dimensioned<Type>&,
787 const fvMatrix<Type>&
791 tmp<fvMatrix<Type> > operator+
793 const dimensioned<Type>&,
794 const tmp<fvMatrix<Type> >&
799 tmp<fvMatrix<Type> > operator-
801 const fvMatrix<Type>&,
802 const fvMatrix<Type>&
806 tmp<fvMatrix<Type> > operator-
808 const tmp<fvMatrix<Type> >&,
809 const fvMatrix<Type>&
813 tmp<fvMatrix<Type> > operator-
815 const fvMatrix<Type>&,
816 const tmp<fvMatrix<Type> >&
820 tmp<fvMatrix<Type> > operator-
822 const tmp<fvMatrix<Type> >&,
823 const tmp<fvMatrix<Type> >&
828 tmp<fvMatrix<Type> > operator-
830 const fvMatrix<Type>&,
831 const DimensionedField<Type, volMesh>&
835 tmp<fvMatrix<Type> > operator-
837 const fvMatrix<Type>&,
838 const tmp<DimensionedField<Type, volMesh> >&
842 tmp<fvMatrix<Type> > operator-
844 const fvMatrix<Type>&,
845 const tmp<GeometricField<Type, fvPatchField, volMesh> >&
849 tmp<fvMatrix<Type> > operator-
851 const tmp<fvMatrix<Type> >&,
852 const DimensionedField<Type, volMesh>&
856 tmp<fvMatrix<Type> > operator-
858 const tmp<fvMatrix<Type> >&,
859 const tmp<DimensionedField<Type, volMesh> >&
863 tmp<fvMatrix<Type> > operator-
865 const tmp<fvMatrix<Type> >&,
866 const tmp<GeometricField<Type, fvPatchField, volMesh> >&
870 tmp<fvMatrix<Type> > operator-
872 const DimensionedField<Type, volMesh>&,
873 const fvMatrix<Type>&
877 tmp<fvMatrix<Type> > operator-
879 const tmp<DimensionedField<Type, volMesh> >&,
880 const fvMatrix<Type>&
884 tmp<fvMatrix<Type> > operator-
886 const tmp<GeometricField<Type, fvPatchField, volMesh> >&,
887 const fvMatrix<Type>&
891 tmp<fvMatrix<Type> > operator-
893 const DimensionedField<Type, volMesh>&,
894 const tmp<fvMatrix<Type> >&
898 tmp<fvMatrix<Type> > operator-
900 const tmp<DimensionedField<Type, volMesh> >&,
901 const tmp<fvMatrix<Type> >&
905 tmp<fvMatrix<Type> > operator-
907 const tmp<GeometricField<Type, fvPatchField, volMesh> >&,
908 const tmp<fvMatrix<Type> >&
913 tmp<fvMatrix<Type> > operator-
915 const fvMatrix<Type>&,
916 const dimensioned<Type>&
920 tmp<fvMatrix<Type> > operator-
922 const tmp<fvMatrix<Type> >&,
923 const dimensioned<Type>&
927 tmp<fvMatrix<Type> > operator-
929 const dimensioned<Type>&,
930 const fvMatrix<Type>&
934 tmp<fvMatrix<Type> > operator-
936 const dimensioned<Type>&,
937 const tmp<fvMatrix<Type> >&
942 tmp<fvMatrix<Type> > operator*
944 const DimensionedField<scalar, volMesh>&,
945 const fvMatrix<Type>&
949 tmp<fvMatrix<Type> > operator*
951 const tmp<DimensionedField<scalar, volMesh> >&,
952 const fvMatrix<Type>&
956 tmp<fvMatrix<Type> > operator*
958 const tmp<volScalarField>&,
959 const fvMatrix<Type>&
963 tmp<fvMatrix<Type> > operator*
965 const DimensionedField<scalar, volMesh>&,
966 const tmp<fvMatrix<Type> >&
970 tmp<fvMatrix<Type> > operator*
972 const tmp<DimensionedField<scalar, volMesh> >&,
973 const tmp<fvMatrix<Type> >&
977 tmp<fvMatrix<Type> > operator*
979 const tmp<volScalarField>&,
980 const tmp<fvMatrix<Type> >&
985 tmp<fvMatrix<Type> > operator*
987 const dimensioned<scalar>&,
988 const fvMatrix<Type>&
992 tmp<fvMatrix<Type> > operator*
994 const dimensioned<scalar>&,
995 const tmp<fvMatrix<Type> >&
999 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1001 } // End namespace Foam
1003 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1006 # include "fvMatrix.C"
1009 // Specialisation for scalars
1010 #include "fvScalarMatrix.H"
1012 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1016 // ************************************************************************* //