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
35 \*---------------------------------------------------------------------------*/
40 #include "areaFields.H"
41 #include "edgeFields.H"
42 #include "lduMatrix.H"
45 #include "dimensionedTypes.H"
46 #include "className.H"
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
59 Ostream& operator<<(Ostream&, const faMatrix<Type>&);
62 /*---------------------------------------------------------------------------*\
63 Class faMatrix Declaration
64 \*---------------------------------------------------------------------------*/
74 // Reference to GeometricField<Type, faPatchField, areaMesh>
75 GeometricField<Type, faPatchField, areaMesh>& psi_;
78 dimensionSet dimensions_;
83 //- Boundary scalar field containing pseudo-matrix coeffs
85 FieldField<Field, Type> internalCoeffs_;
87 //- Boundary scalar field containing pseudo-matrix coeffs
89 FieldField<Field, Type> boundaryCoeffs_;
92 //- Face flux field for non-orthogonal correction
93 mutable GeometricField<Type, faePatchField, edgeMesh>
94 *faceFluxCorrectionPtr_;
96 direction solvingComponent;
99 // Private member functions
101 //- Add patch contribution to internal field
102 template<class Type2>
103 void addToInternalField
105 const unallocLabelList& addr,
106 const Field<Type2>& pf,
110 template<class Type2>
111 void addToInternalField
113 const unallocLabelList& addr,
114 const tmp<Field<Type2> >& tpf,
118 //- Subtract patch contribution from internal field
119 template<class Type2>
120 void subtractFromInternalField
122 const unallocLabelList& addr,
123 const Field<Type2>& pf,
127 template<class Type2>
128 void subtractFromInternalField
130 const unallocLabelList& addr,
131 const tmp<Field<Type2> >& tpf,
136 // Matrix completion functionality
144 void addCmptAvBoundaryDiag(scalarField& diag) const;
146 void addBoundarySource
149 const bool couples = true
155 //- Solver class returned by the solver function
158 faMatrix<Type>& faMat_;
160 autoPtr<lduSolver> solver_;
166 faSolver(faMatrix<Type>& faMat, autoPtr<lduSolver> sol)
175 //- Solve returning the solution statistics.
176 // Solver controls read from dictionary
177 lduSolverPerformance solve(const dictionary&);
179 //- Solve returning the solution statistics.
180 // Solver controls read from faSolution
181 lduSolverPerformance solve();
185 ClassName("faMatrix");
190 //- Construct given a field to solve for
193 GeometricField<Type, faPatchField, areaMesh>&,
197 //- Construct as copy
198 faMatrix(const faMatrix<Type>&);
200 //- Construct from Istream given field to solve for
201 faMatrix(GeometricField<Type, faPatchField, areaMesh>&, Istream&);
213 const GeometricField<Type, faPatchField, areaMesh>& psi() const
218 GeometricField<Type, faPatchField, areaMesh>& psi()
223 const dimensionSet& dimensions() const
228 Field<Type>& source()
233 const Field<Type>& source() const
238 //- faBoundary scalar field containing pseudo-matrix coeffs
239 // for internal cells
240 FieldField<Field, Type>& internalCoeffs()
242 return internalCoeffs_;
245 //- faBoundary scalar field containing pseudo-matrix coeffs
246 // for boundary cells
247 FieldField<Field, Type>& boundaryCoeffs()
249 return boundaryCoeffs_;
253 //- Declare return type of the faceFluxCorrectionPtr() function
254 typedef GeometricField<Type, faePatchField, edgeMesh>
257 //- Return pointer to face-flux non-orthogonal correction field
258 edgeTypeFieldPtr& faceFluxCorrectionPtr()
260 return faceFluxCorrectionPtr_;
266 //- Set solution in given cells and eliminate corresponding
267 // equations from the matrix
270 const labelList& faces,
271 const Field<Type>& values
274 //- Set reference level for solution
281 //- Set reference level for a component of the solution
282 // on a given patch face
283 void setComponentReference
287 const direction cmpt,
291 //- Relax matrix (for steady-state solution).
292 // alpha = 1 : diagonally equal
293 // alpha < 1 : ,, dominant
294 // alpha = 0 : do nothing
295 void relax(const scalar alpha);
297 //- Relax matrix (for steadty-state solution).
298 // alpha is read from controlDict
301 //- Construct and return the solver
302 // Solver controls read from Istream
303 autoPtr<faSolver> solver(const dictionary&);
305 //- Construct and return the solver
306 // Solver controls read from faSolution
307 autoPtr<faSolver> solver();
309 //- Solve returning the solution statistics.
310 // Solver controls read Istream
311 lduSolverPerformance solve(const dictionary&);
313 //- Solve returning the solution statistics.
314 // Solver controls read from faSolution
315 lduSolverPerformance solve();
317 //- Return the matrix residual
318 tmp<Field<Type> > residual() const;
320 //- Return the matrix diagonal
321 tmp<scalarField> D() const;
323 //- Return the central coefficient
324 tmp<areaScalarField> A() const;
326 //- Return the H operation source
327 tmp<GeometricField<Type, faPatchField, areaMesh> > H() const;
329 //- Return the face-flux field from the matrix
330 tmp<GeometricField<Type, faePatchField, edgeMesh> > flux() const;
335 void operator=(const faMatrix<Type>&);
336 void operator=(const tmp<faMatrix<Type> >&);
340 void operator+=(const faMatrix<Type>&);
341 void operator+=(const tmp<faMatrix<Type> >&);
343 void operator-=(const faMatrix<Type>&);
344 void operator-=(const tmp<faMatrix<Type> >&);
346 void operator+=(const GeometricField<Type,faPatchField,areaMesh>&);
347 void operator+=(const tmp<GeometricField<Type,faPatchField,areaMesh> >&);
349 void operator-=(const GeometricField<Type,faPatchField,areaMesh>&);
350 void operator-=(const tmp<GeometricField<Type,faPatchField,areaMesh> >&);
352 void operator+=(const dimensioned<Type>&);
353 void operator-=(const dimensioned<Type>&);
355 void operator*=(const areaScalarField&);
356 void operator*=(const tmp<areaScalarField>&);
358 void operator*=(const dimensioned<scalar>&);
363 friend Ostream& operator<< <Type>
366 const faMatrix<Type>&
371 // * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * //
376 const faMatrix<Type>&,
377 const faMatrix<Type>&,
384 const faMatrix<Type>&,
385 const GeometricField<Type, faPatchField, areaMesh>&,
392 const faMatrix<Type>&,
393 const dimensioned<Type>&,
398 //- Solve returning the solution statistics given convergence tolerance
399 // Solver controls read Istream
401 lduSolverPerformance solve(faMatrix<Type>&, Istream&);
404 //- Solve returning the solution statistics given convergence tolerance,
405 // deleting temporary matrix after solution.
406 // Solver controls read Istream
408 lduSolverPerformance solve(const tmp<faMatrix<Type> >&, Istream&);
411 //- Solve returning the solution statistics given convergence tolerance
412 // Solver controls read faSolution
414 lduSolverPerformance solve(faMatrix<Type>&);
417 //- Solve returning the solution statistics given convergence tolerance,
418 // deleting temporary matrix after solution.
419 // Solver controls read faSolution
421 lduSolverPerformance solve(const tmp<faMatrix<Type> >&);
424 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
427 tmp<faMatrix<Type> > operator-
429 const faMatrix<Type>&
433 tmp<faMatrix<Type> > operator-
435 const tmp<faMatrix<Type> >&
439 tmp<faMatrix<Type> > operator+
441 const faMatrix<Type>&,
442 const faMatrix<Type>&
446 tmp<faMatrix<Type> > operator+
448 const tmp<faMatrix<Type> >&,
449 const faMatrix<Type>&
453 tmp<faMatrix<Type> > operator+
455 const faMatrix<Type>&,
456 const tmp<faMatrix<Type> >&
460 tmp<faMatrix<Type> > operator+
462 const tmp<faMatrix<Type> >&,
463 const tmp<faMatrix<Type> >&
467 tmp<faMatrix<Type> > operator-
469 const faMatrix<Type>&,
470 const faMatrix<Type>&
474 tmp<faMatrix<Type> > operator-
476 const tmp<faMatrix<Type> >&,
477 const faMatrix<Type>&
481 tmp<faMatrix<Type> > operator-
483 const faMatrix<Type>&,
484 const tmp<faMatrix<Type> >&
488 tmp<faMatrix<Type> > operator-
490 const tmp<faMatrix<Type> >&,
491 const tmp<faMatrix<Type> >&
495 tmp<faMatrix<Type> > operator==
497 const faMatrix<Type>&,
498 const faMatrix<Type>&
502 tmp<faMatrix<Type> > operator==
504 const tmp<faMatrix<Type> >&,
505 const faMatrix<Type>&
509 tmp<faMatrix<Type> > operator==
511 const faMatrix<Type>&,
512 const tmp<faMatrix<Type> >&
516 tmp<faMatrix<Type> > operator==
518 const tmp<faMatrix<Type> >&,
519 const tmp<faMatrix<Type> >&
523 tmp<faMatrix<Type> > operator+
525 const faMatrix<Type>&,
526 const GeometricField<Type, faPatchField, areaMesh>&
530 tmp<faMatrix<Type> > operator+
532 const tmp<faMatrix<Type> >&,
533 const GeometricField<Type, faPatchField, areaMesh>&
537 tmp<faMatrix<Type> > operator+
539 const faMatrix<Type>&,
540 const tmp<GeometricField<Type, faPatchField, areaMesh> >&
544 tmp<faMatrix<Type> > operator+
546 const tmp<faMatrix<Type> >&,
547 const tmp<GeometricField<Type, faPatchField, areaMesh> >&
551 tmp<faMatrix<Type> > operator+
553 const GeometricField<Type, faPatchField, areaMesh>&,
554 const faMatrix<Type>&
558 tmp<faMatrix<Type> > operator+
560 const GeometricField<Type, faPatchField, areaMesh>&,
561 const tmp<faMatrix<Type> >&
565 tmp<faMatrix<Type> > operator+
567 const tmp<GeometricField<Type, faPatchField, areaMesh> >&,
568 const faMatrix<Type>&
572 tmp<faMatrix<Type> > operator+
574 const tmp<GeometricField<Type, faPatchField, areaMesh> >&,
575 const tmp<faMatrix<Type> >&
579 tmp<faMatrix<Type> > operator-
581 const faMatrix<Type>&,
582 const GeometricField<Type, faPatchField, areaMesh>&
586 tmp<faMatrix<Type> > operator-
588 const tmp<faMatrix<Type> >&,
589 const GeometricField<Type, faPatchField, areaMesh>&
593 tmp<faMatrix<Type> > operator-
595 const faMatrix<Type>&,
596 const tmp<GeometricField<Type, faPatchField, areaMesh> >&
600 tmp<faMatrix<Type> > operator-
602 const tmp<faMatrix<Type> >&,
603 const tmp<GeometricField<Type, faPatchField, areaMesh> >&
607 tmp<faMatrix<Type> > operator-
609 const GeometricField<Type, faPatchField, areaMesh>&,
610 const faMatrix<Type>&
614 tmp<faMatrix<Type> > operator-
616 const GeometricField<Type, faPatchField, areaMesh>&,
617 const tmp<faMatrix<Type> >&
621 tmp<faMatrix<Type> > operator-
623 const tmp<GeometricField<Type, faPatchField, areaMesh> >&,
624 const faMatrix<Type>&
628 tmp<faMatrix<Type> > operator-
630 const tmp<GeometricField<Type, faPatchField, areaMesh> >&,
631 const tmp<faMatrix<Type> >&
635 tmp<faMatrix<Type> > operator+
637 const tmp<faMatrix<Type> >&,
638 const dimensioned<Type>&
642 tmp<faMatrix<Type> > operator+
644 const dimensioned<Type>&,
645 const tmp<faMatrix<Type> >&
649 tmp<faMatrix<Type> > operator-
651 const tmp<faMatrix<Type> >&,
652 const dimensioned<Type>&
656 tmp<faMatrix<Type> > operator-
658 const dimensioned<Type>&,
659 const tmp<faMatrix<Type> >&
663 tmp<faMatrix<Type> > operator==
665 const faMatrix<Type>&,
666 const GeometricField<Type, faPatchField, areaMesh>&
670 tmp<faMatrix<Type> > operator==
672 const tmp<faMatrix<Type> >&,
673 const GeometricField<Type, faPatchField, areaMesh>&
677 tmp<faMatrix<Type> > operator==
679 const faMatrix<Type>&,
680 const tmp<GeometricField<Type, faPatchField, areaMesh> >&
684 tmp<faMatrix<Type> > operator==
686 const tmp<faMatrix<Type> >&,
687 const tmp<GeometricField<Type, faPatchField, areaMesh> >&
691 tmp<faMatrix<Type> > operator==
693 const faMatrix<Type>&,
694 const dimensioned<Type>&
698 tmp<faMatrix<Type> > operator==
700 const tmp<faMatrix<Type> >&,
701 const dimensioned<Type>&
706 tmp<faMatrix<Type> > operator*
708 const areaScalarField&,
709 const faMatrix<Type>&
713 tmp<faMatrix<Type> > operator*
715 const areaScalarField&,
716 const tmp<faMatrix<Type> >&
720 tmp<faMatrix<Type> > operator*
722 const tmp<areaScalarField>&,
723 const faMatrix<Type>&
727 tmp<faMatrix<Type> > operator*
729 const tmp<areaScalarField>&,
730 const tmp<faMatrix<Type> >&
735 tmp<faMatrix<Type> > operator*
737 const dimensioned<scalar>&,
738 const faMatrix<Type>&
742 tmp<faMatrix<Type> > operator*
744 const dimensioned<scalar>&,
745 const tmp<faMatrix<Type> >&
749 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
751 } // End namespace Foam
753 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
756 # include "faMatrix.C"
759 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
763 // ************************************************************************* //