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/>.
34 \*---------------------------------------------------------------------------*/
39 #include "areaFields.H"
40 #include "edgeFields.H"
41 #include "lduMatrix.H"
44 #include "dimensionedTypes.H"
45 #include "className.H"
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
58 Ostream& operator<<(Ostream&, const faMatrix<Type>&);
61 /*---------------------------------------------------------------------------*\
62 Class faMatrix Declaration
63 \*---------------------------------------------------------------------------*/
73 // Reference to GeometricField<Type, faPatchField, areaMesh>
74 GeometricField<Type, faPatchField, areaMesh>& psi_;
77 dimensionSet dimensions_;
82 //- Boundary scalar field containing pseudo-matrix coeffs
84 FieldField<Field, Type> internalCoeffs_;
86 //- Boundary scalar field containing pseudo-matrix coeffs
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
104 const unallocLabelList& addr,
105 const Field<Type2>& pf,
109 template<class Type2>
110 void addToInternalField
112 const unallocLabelList& addr,
113 const tmp<Field<Type2> >& tpf,
117 //- Subtract patch contribution from internal field
118 template<class Type2>
119 void subtractFromInternalField
121 const unallocLabelList& addr,
122 const Field<Type2>& pf,
126 template<class Type2>
127 void subtractFromInternalField
129 const unallocLabelList& addr,
130 const tmp<Field<Type2> >& tpf,
135 // Matrix completion functionality
143 void addCmptAvBoundaryDiag(scalarField& diag) const;
145 void addBoundarySource
148 const bool couples = true
154 //- Solver class returned by the solver function
157 faMatrix<Type>& faMat_;
159 autoPtr<lduSolver> solver_;
165 faSolver(faMatrix<Type>& faMat, autoPtr<lduSolver> sol)
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();
184 ClassName("faMatrix");
189 //- Construct given a field to solve for
192 GeometricField<Type, faPatchField, areaMesh>&,
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&);
212 const GeometricField<Type, faPatchField, areaMesh>& psi() const
217 GeometricField<Type, faPatchField, areaMesh>& psi()
222 const dimensionSet& dimensions() const
227 Field<Type>& source()
232 const Field<Type>& source() const
237 //- faBoundary scalar field containing pseudo-matrix coeffs
238 // for internal cells
239 FieldField<Field, Type>& internalCoeffs()
241 return internalCoeffs_;
244 //- faBoundary scalar field containing pseudo-matrix coeffs
245 // for boundary cells
246 FieldField<Field, Type>& boundaryCoeffs()
248 return boundaryCoeffs_;
252 //- Declare return type of the faceFluxCorrectionPtr() function
253 typedef GeometricField<Type, faePatchField, edgeMesh>
256 //- Return pointer to face-flux non-orthogonal correction field
257 edgeTypeFieldPtr& faceFluxCorrectionPtr()
259 return faceFluxCorrectionPtr_;
265 //- Set solution in given cells and eliminate corresponding
266 // equations from the matrix
269 const labelList& faces,
270 const Field<Type>& values
273 //- Set reference level for solution
280 //- Set reference level for a component of the solution
281 // on a given patch face
282 void setComponentReference
286 const direction cmpt,
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
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;
334 void operator=(const faMatrix<Type>&);
335 void operator=(const tmp<faMatrix<Type> >&);
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>&);
362 friend Ostream& operator<< <Type>
365 const faMatrix<Type>&
370 // * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * //
375 const faMatrix<Type>&,
376 const faMatrix<Type>&,
383 const faMatrix<Type>&,
384 const GeometricField<Type, faPatchField, areaMesh>&,
391 const faMatrix<Type>&,
392 const dimensioned<Type>&,
397 //- Solve returning the solution statistics given convergence tolerance
398 // Solver controls read Istream
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
407 lduSolverPerformance solve(const tmp<faMatrix<Type> >&, Istream&);
410 //- Solve returning the solution statistics given convergence tolerance
411 // Solver controls read faSolution
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
420 lduSolverPerformance solve(const tmp<faMatrix<Type> >&);
423 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
426 tmp<faMatrix<Type> > operator-
428 const faMatrix<Type>&
432 tmp<faMatrix<Type> > operator-
434 const tmp<faMatrix<Type> >&
438 tmp<faMatrix<Type> > operator+
440 const faMatrix<Type>&,
441 const faMatrix<Type>&
445 tmp<faMatrix<Type> > operator+
447 const tmp<faMatrix<Type> >&,
448 const faMatrix<Type>&
452 tmp<faMatrix<Type> > operator+
454 const faMatrix<Type>&,
455 const tmp<faMatrix<Type> >&
459 tmp<faMatrix<Type> > operator+
461 const tmp<faMatrix<Type> >&,
462 const tmp<faMatrix<Type> >&
466 tmp<faMatrix<Type> > operator-
468 const faMatrix<Type>&,
469 const faMatrix<Type>&
473 tmp<faMatrix<Type> > operator-
475 const tmp<faMatrix<Type> >&,
476 const faMatrix<Type>&
480 tmp<faMatrix<Type> > operator-
482 const faMatrix<Type>&,
483 const tmp<faMatrix<Type> >&
487 tmp<faMatrix<Type> > operator-
489 const tmp<faMatrix<Type> >&,
490 const tmp<faMatrix<Type> >&
494 tmp<faMatrix<Type> > operator==
496 const faMatrix<Type>&,
497 const faMatrix<Type>&
501 tmp<faMatrix<Type> > operator==
503 const tmp<faMatrix<Type> >&,
504 const faMatrix<Type>&
508 tmp<faMatrix<Type> > operator==
510 const faMatrix<Type>&,
511 const tmp<faMatrix<Type> >&
515 tmp<faMatrix<Type> > operator==
517 const tmp<faMatrix<Type> >&,
518 const tmp<faMatrix<Type> >&
522 tmp<faMatrix<Type> > operator+
524 const faMatrix<Type>&,
525 const GeometricField<Type, faPatchField, areaMesh>&
529 tmp<faMatrix<Type> > operator+
531 const tmp<faMatrix<Type> >&,
532 const GeometricField<Type, faPatchField, areaMesh>&
536 tmp<faMatrix<Type> > operator+
538 const faMatrix<Type>&,
539 const tmp<GeometricField<Type, faPatchField, areaMesh> >&
543 tmp<faMatrix<Type> > operator+
545 const tmp<faMatrix<Type> >&,
546 const tmp<GeometricField<Type, faPatchField, areaMesh> >&
550 tmp<faMatrix<Type> > operator+
552 const GeometricField<Type, faPatchField, areaMesh>&,
553 const faMatrix<Type>&
557 tmp<faMatrix<Type> > operator+
559 const GeometricField<Type, faPatchField, areaMesh>&,
560 const tmp<faMatrix<Type> >&
564 tmp<faMatrix<Type> > operator+
566 const tmp<GeometricField<Type, faPatchField, areaMesh> >&,
567 const faMatrix<Type>&
571 tmp<faMatrix<Type> > operator+
573 const tmp<GeometricField<Type, faPatchField, areaMesh> >&,
574 const tmp<faMatrix<Type> >&
578 tmp<faMatrix<Type> > operator-
580 const faMatrix<Type>&,
581 const GeometricField<Type, faPatchField, areaMesh>&
585 tmp<faMatrix<Type> > operator-
587 const tmp<faMatrix<Type> >&,
588 const GeometricField<Type, faPatchField, areaMesh>&
592 tmp<faMatrix<Type> > operator-
594 const faMatrix<Type>&,
595 const tmp<GeometricField<Type, faPatchField, areaMesh> >&
599 tmp<faMatrix<Type> > operator-
601 const tmp<faMatrix<Type> >&,
602 const tmp<GeometricField<Type, faPatchField, areaMesh> >&
606 tmp<faMatrix<Type> > operator-
608 const GeometricField<Type, faPatchField, areaMesh>&,
609 const faMatrix<Type>&
613 tmp<faMatrix<Type> > operator-
615 const GeometricField<Type, faPatchField, areaMesh>&,
616 const tmp<faMatrix<Type> >&
620 tmp<faMatrix<Type> > operator-
622 const tmp<GeometricField<Type, faPatchField, areaMesh> >&,
623 const faMatrix<Type>&
627 tmp<faMatrix<Type> > operator-
629 const tmp<GeometricField<Type, faPatchField, areaMesh> >&,
630 const tmp<faMatrix<Type> >&
634 tmp<faMatrix<Type> > operator+
636 const tmp<faMatrix<Type> >&,
637 const dimensioned<Type>&
641 tmp<faMatrix<Type> > operator+
643 const dimensioned<Type>&,
644 const tmp<faMatrix<Type> >&
648 tmp<faMatrix<Type> > operator-
650 const tmp<faMatrix<Type> >&,
651 const dimensioned<Type>&
655 tmp<faMatrix<Type> > operator-
657 const dimensioned<Type>&,
658 const tmp<faMatrix<Type> >&
662 tmp<faMatrix<Type> > operator==
664 const faMatrix<Type>&,
665 const GeometricField<Type, faPatchField, areaMesh>&
669 tmp<faMatrix<Type> > operator==
671 const tmp<faMatrix<Type> >&,
672 const GeometricField<Type, faPatchField, areaMesh>&
676 tmp<faMatrix<Type> > operator==
678 const faMatrix<Type>&,
679 const tmp<GeometricField<Type, faPatchField, areaMesh> >&
683 tmp<faMatrix<Type> > operator==
685 const tmp<faMatrix<Type> >&,
686 const tmp<GeometricField<Type, faPatchField, areaMesh> >&
690 tmp<faMatrix<Type> > operator==
692 const faMatrix<Type>&,
693 const dimensioned<Type>&
697 tmp<faMatrix<Type> > operator==
699 const tmp<faMatrix<Type> >&,
700 const dimensioned<Type>&
705 tmp<faMatrix<Type> > operator*
707 const areaScalarField&,
708 const faMatrix<Type>&
712 tmp<faMatrix<Type> > operator*
714 const areaScalarField&,
715 const tmp<faMatrix<Type> >&
719 tmp<faMatrix<Type> > operator*
721 const tmp<areaScalarField>&,
722 const faMatrix<Type>&
726 tmp<faMatrix<Type> > operator*
728 const tmp<areaScalarField>&,
729 const tmp<faMatrix<Type> >&
734 tmp<faMatrix<Type> > operator*
736 const dimensioned<scalar>&,
737 const faMatrix<Type>&
741 tmp<faMatrix<Type> > operator*
743 const dimensioned<scalar>&,
744 const tmp<faMatrix<Type> >&
748 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
750 } // End namespace Foam
752 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
755 # include "faMatrix.C"
758 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
762 // ************************************************************************* //