lduMatrix.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2016-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::lduMatrix
29 
30 Description
31  lduMatrix is a general matrix class in which the coefficients are
32  stored as three arrays, one for the upper triangle, one for the
33  lower triangle and a third for the diagonal.
34 
35  Addressing arrays must be supplied for the upper and lower triangles.
36 
37  It might be better if this class were organised as a hierarchy starting
38  from an empty matrix, then deriving diagonal, symmetric and asymmetric
39  matrices.
40 
41 SourceFiles
42  lduMatrixATmul.C
43  lduMatrix.C
44  lduMatrixTemplates.C
45  lduMatrixOperations.C
46  lduMatrixSolver.C
47  lduMatrixPreconditioner.C
48  lduMatrixTests.C
49  lduMatrixUpdateMatrixInterfaces.C
50 
51 \*---------------------------------------------------------------------------*/
52 
53 #ifndef Foam_lduMatrix_H
54 #define Foam_lduMatrix_H
55 
56 #include "lduMesh.H"
57 #include "primitiveFieldsFwd.H"
58 #include "FieldField.H"
60 #include "solverPerformance.H"
61 #include "typeInfo.H"
62 #include "autoPtr.H"
63 #include "runTimeSelectionTables.H"
64 #include "InfoProxy.H"
65 #include "Enum.H"
66 #include "profilingTrigger.H"
67 #include <functional> // For reference_wrapper
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 namespace Foam
72 {
73 
74 // Forward Declarations
75 class lduMatrix;
76 
77 Ostream& operator<<(Ostream&, const lduMatrix&);
78 Ostream& operator<<(Ostream&, const InfoProxy<lduMatrix>&);
79 
80 
81 /*---------------------------------------------------------------------------*\
82  Class lduMatrix Declaration
83 \*---------------------------------------------------------------------------*/
84 
85 class lduMatrix
86 {
87  // Private Data
88 
89  //- LDU mesh reference
90  //const lduMesh& lduMesh_;
91  std::reference_wrapper<const lduMesh> lduMesh_;
92 
93  //- Diagonal coefficients
94  std::unique_ptr<scalarField> diagPtr_;
95 
96  //- Off-diagonal coefficients (not including interfaces)
97  std::unique_ptr<scalarField> lowerPtr_;
98 
99  //- Off-diagonal coefficients (not including interfaces)
100  std::unique_ptr<scalarField> upperPtr_;
101 
102  //- Off-diagonal coefficients (not including interfaces) in CSR ordering
103  mutable std::unique_ptr<scalarField> lowerCSRPtr_;
104 
105  //- Work space
106  mutable std::unique_ptr<solveScalarField> workPtr_;
107 
108 
109 public:
110 
111  // Public Types
112 
113  //- Enumerated matrix normalisation types
114  enum class normTypes : char
115  {
116  NO_NORM,
117  DEFAULT_NORM,
119  };
120 
121  //- Names for the normTypes
122  static const Enum<normTypes> normTypesNames_;
123 
124  //- Default maximum number of iterations for solvers (1000)
125  static constexpr const label defaultMaxIter = 1000;
126 
127  //- Default (absolute) tolerance (1e-6)
128  static const scalar defaultTolerance;
129 
130 
131  // -----------------------------------------------------------------------
132  //- Abstract base-class for lduMatrix solvers
133  class solver
134  {
135  protected:
136 
137  // Protected Data
138 
140  const lduMatrix& matrix_;
145  //- Dictionary of solution controls
147 
148  //- Verbosity level for solver output statements
149  int log_;
150 
151  //- Minimum number of iterations in the solver
152  label minIter_;
153 
154  //- Maximum number of iterations in the solver
155  label maxIter_;
156 
157  //- The normalisation type
160  //- Final convergence tolerance
161  scalar tolerance_;
162 
163  //- Convergence tolerance relative to the initial
164  scalar relTol_;
165 
166  //- Profiling instrumentation
168 
169 
170  // Protected Member Functions
172  //- Read the control parameters from controlDict_
173  virtual void readControls();
174 
175 
176  public:
177 
178  //- Runtime type information
179  virtual const word& type() const = 0;
180 
182  // Declare run-time constructor selection tables
183 
185  (
187  solver,
188  symMatrix,
189  (
190  const word& fieldName,
195  const dictionary& solverControls
196  ),
197  (
198  fieldName,
199  matrix,
202  interfaces,
203  solverControls
204  )
205  );
206 
208  (
209  autoPtr,
210  solver,
211  asymMatrix,
212  (
213  const word& fieldName,
214  const lduMatrix& matrix,
218  const dictionary& solverControls
219  ),
220  (
221  fieldName,
222  matrix,
225  interfaces,
226  solverControls
227  )
228  );
229 
230 
231  // Constructors
232 
233  //- Construct solver for given field name, matrix etc
234  solver
235  (
236  const word& fieldName,
237  const lduMatrix& matrix,
241  const dictionary& solverControls
242  );
243 
244  // Selectors
245 
246  //- Return a new solver of given type
247  static autoPtr<solver> New
248  (
249  const word& solverName,
250  const word& fieldName,
251  const lduMatrix& matrix,
255  const dictionary& solverControls
256  );
257 
258  //- Return a new solver given dictionary
259  static autoPtr<solver> New
260  (
261  const word& fieldName,
262  const lduMatrix& matrix,
266  const dictionary& solverControls
267  );
268 
269 
270 
271  //- Destructor
272  virtual ~solver() = default;
273 
274 
275  // Member Functions
276 
277  const word& fieldName() const noexcept
278  {
279  return fieldName_;
280  }
281 
282  const lduMatrix& matrix() const noexcept
283  {
284  return matrix_;
285  }
286 
288  {
289  return interfaceBouCoeffs_;
290  }
291 
292  const FieldField<Field, scalar>& interfaceIntCoeffs() const noexcept
293  {
294  return interfaceIntCoeffs_;
295  }
296 
298  {
299  return interfaces_;
300  }
301 
302 
303  //- Read and reset the solver parameters from the given stream
304  virtual void read(const dictionary&);
305 
306  //- Solve with given field and rhs
307  virtual solverPerformance solve
308  (
309  scalarField& psi,
310  const scalarField& source,
311  const direction cmpt=0
312  ) const = 0;
313 
314  //- Solve with given field and rhs (in solveScalar precision).
315  // Default is to call solve routine
317  (
319  const solveScalarField& source,
320  const direction cmpt=0
321  ) const;
322 
323  //- Return the matrix norm using the specified norm method
325  (
326  const solveScalarField& psi,
327  const solveScalarField& source,
328  const solveScalarField& Apsi,
329  solveScalarField& tmpField,
330  const lduMatrix::normTypes normType
331  ) const;
332 
333  //- Return the matrix norm used to normalise the residual for the
334  //- stopping criterion
336  (
337  const solveScalarField& psi,
338  const solveScalarField& source,
339  const solveScalarField& Apsi,
340  solveScalarField& tmpField
341  ) const
342  {
343  return this->normFactor(psi, source, Apsi, tmpField, normType_);
344  }
345  };
346 
347 
348  // -----------------------------------------------------------------------
349  //- Abstract base-class for lduMatrix smoothers
350  class smoother
351  {
352  protected:
353 
354  // Protected Data
355 
357  const lduMatrix& matrix_;
361 
362 
363  public:
364 
365  //- Find the smoother name (directly or from a sub-dictionary)
366  static word getName(const dictionary&);
367 
368  //- Runtime type information
369  virtual const word& type() const = 0;
370 
371 
372  // Declare run-time constructor selection tables
373 
375  (
376  autoPtr,
377  smoother,
378  symMatrix,
379  (
380  const word& fieldName,
381  const lduMatrix& matrix,
385  ),
386  (
387  fieldName,
388  matrix,
391  interfaces
392  )
393  );
394 
396  (
397  autoPtr,
398  smoother,
399  asymMatrix,
400  (
401  const word& fieldName,
402  const lduMatrix& matrix,
406  ),
407  (
408  fieldName,
412  interfaces
413  )
414  );
417  // Constructors
419  //- Construct for given field name, matrix etc
420  smoother
421  (
422  const word& fieldName,
423  const lduMatrix& matrix,
427  );
428 
429 
430  // Selectors
431 
432  //- Return a new smoother
433  static autoPtr<smoother> New
434  (
435  const word& fieldName,
436  const lduMatrix& matrix,
440  const dictionary& solverControls
441  );
442 
443 
444  //- Destructor
445  virtual ~smoother() = default;
446 
447 
448  // Member Functions
449 
450  const word& fieldName() const noexcept
451  {
452  return fieldName_;
453  }
454 
455  const lduMatrix& matrix() const noexcept
456  {
457  return matrix_;
458  }
459 
461  {
462  return interfaceBouCoeffs_;
463  }
464 
465  const FieldField<Field, scalar>& interfaceIntCoeffs() const noexcept
466  {
467  return interfaceIntCoeffs_;
468  }
469 
471  {
472  return interfaces_;
473  }
474 
475 
476  //- Smooth the solution for a given number of sweeps
477  virtual void smooth
478  (
480  const scalarField& source,
481  const direction cmpt,
482  const label nSweeps
483  ) const = 0;
484 
485  //- Smooth the solution for a given number of sweeps
486  virtual void scalarSmooth
487  (
489  const solveScalarField& source,
490  const direction cmpt,
491  const label nSweeps
492  ) const = 0;
493  };
494 
495 
496  // -----------------------------------------------------------------------
497  //- Abstract base-class for lduMatrix preconditioners
498  class preconditioner
499  {
500  protected:
501 
502  // Protected Data
503 
504  //- Reference to the base-solver this preconditioner is used with
505  const solver& solver_;
506 
507 
508  public:
509 
510  //- Find the preconditioner name (directly or from a sub-dictionary)
511  static word getName(const dictionary&);
512 
513  //- Runtime type information
514  virtual const word& type() const = 0;
515 
516 
517  // Declare run-time constructor selection tables
518 
520  (
521  autoPtr,
523  symMatrix,
524  (
525  const solver& sol,
526  const dictionary& solverControls
527  ),
528  (sol, solverControls)
529  );
530 
532  (
533  autoPtr,
535  asymMatrix,
536  (
537  const solver& sol,
538  const dictionary& solverControls
539  ),
540  (sol, solverControls)
541  );
542 
543 
544  // Constructors
545 
546  //- Construct for given solver
547  explicit preconditioner(const solver& sol)
548  :
549  solver_(sol)
550  {}
551 
552 
553  // Selectors
554 
555  //- Return a new preconditioner
557  (
558  const solver& sol,
559  const dictionary& solverControls
560  );
561 
562 
563  //- Destructor
564  virtual ~preconditioner() = default;
565 
566 
567  // Member Functions
568 
569  //- Read and reset the preconditioner parameters
570  //- from the given stream
571  virtual void read(const dictionary&)
572  {}
574  //- Return wA the preconditioned form of residual rA
575  virtual void precondition
576  (
577  solveScalarField& wA,
578  const solveScalarField& rA,
579  const direction cmpt=0
580  ) const = 0;
581 
582  //- Return wT the transpose-matrix preconditioned form of
583  //- residual rT.
584  // This is only required for preconditioning asymmetric matrices.
585  virtual void preconditionT
586  (
587  solveScalarField& wT,
588  const solveScalarField& rT,
589  const direction cmpt=0
590  ) const
591  {
593  }
594 
595  //- Signal end of solver
596  virtual void setFinished(const solverPerformance& perf) const
597  {}
598  };
599 
600 
601  // -----------------------------------------------------------------------
602 
603  // Static Data
604 
605  // Declare name of the class and its debug switch
606  ClassName("lduMatrix");
607 
608 
609  // Constructors
610 
611  //- Construct (without coefficients) for an LDU addressed mesh.
612  // Not yet 'explicit' (legacy code may rely on implicit construct)
613  lduMatrix(const lduMesh& mesh);
614 
615  //- Copy construct
616  lduMatrix(const lduMatrix&);
617 
618  //- Move construct
619  lduMatrix(lduMatrix&&);
620 
621  //- Construct as copy or re-use as specified.
622  lduMatrix(lduMatrix&, bool reuse);
623 
624  //- Construct given an LDU addressed mesh and an Istream
625  //- from which the coefficients are read
626  lduMatrix(const lduMesh& mesh, Istream& is);
627 
628 
629  //- Destructor
630  ~lduMatrix() = default;
631 
632 
633  // Member Functions
634 
635  // Addressing
636 
637  //- Return the LDU mesh from which the addressing is obtained
638  const lduMesh& mesh() const noexcept
639  {
640  return lduMesh_;
641  }
642 
643  //- Set the LDU mesh containing the addressing
644  void setLduMesh(const lduMesh& m)
645  {
646  lduMesh_ = m;
647  }
648 
649  //- Return the LDU addressing
650  const lduAddressing& lduAddr() const
651  {
652  return mesh().lduAddr();
653  }
654 
655  //- Return the patch evaluation schedule
656  const lduSchedule& patchSchedule() const
657  {
658  return mesh().lduAddr().patchSchedule();
659  }
661 
662  // Coefficients
663 
664  const scalarField& diag() const;
665  const scalarField& upper() const;
666  const scalarField& lower() const;
667 
668  scalarField& diag();
669  scalarField& upper();
670  scalarField& lower();
671 
672  // Size with externally provided sizes
673  // (for constructing with 'fake' mesh in GAMG)
674 
675  scalarField& diag(label size);
676  scalarField& upper(label nCoeffs);
677  scalarField& lower(label nCoeffs);
678 
679 
680  // CSR
681 
682  bool hasLowerCSR() const noexcept { return bool(lowerCSRPtr_); }
683 
684  const scalarField& lowerCSR() const;
685 
687 
688  //- Work array
689  const solveScalarField& work() const;
690 
691  //- Work array
692  solveScalarField& work(label size) const;
693 
694 
695  // Characteristics
696 
697  //- The matrix type (empty, diagonal, symmetric, ...)
698  word matrixTypeName() const;
699 
700  bool hasDiag() const noexcept { return bool(diagPtr_); }
701  bool hasUpper() const noexcept { return bool(upperPtr_); }
702  bool hasLower() const noexcept { return bool(lowerPtr_); }
703 
704  //- Matrix has diagonal only
705  bool diagonal() const noexcept
706  {
707  return (diagPtr_ && !lowerPtr_ && !lowerCSRPtr_ && !upperPtr_);
708  }
709 
710  //- Matrix is symmetric
711  bool symmetric() const noexcept
712  {
713  return (diagPtr_ && !(lowerPtr_ || lowerCSRPtr_) && upperPtr_);
714  }
715 
716  //- Matrix is asymmetric (ie, full)
717  bool asymmetric() const noexcept
718  {
719  return (diagPtr_ && (lowerPtr_ || lowerCSRPtr_) && upperPtr_);
720  }
721 
722 
723  // Operations
724 
725  void sumDiag();
726  void negSumDiag();
727 
728  void sumMagOffDiag(scalarField& sumOff) const;
729 
730  //- Matrix multiplication with updated interfaces.
731  void Amul
732  (
734  const tmp<solveScalarField>&,
735  const FieldField<Field, scalar>&,
737  const direction cmpt
738  ) const;
739 
740  //- Matrix transpose multiplication with updated interfaces.
741  void Tmul
742  (
744  const tmp<solveScalarField>&,
745  const FieldField<Field, scalar>&,
747  const direction cmpt
748  ) const;
750 
751  //- Sum the coefficients on each row of the matrix
752  void sumA
753  (
757  ) const;
758 
759 
760  void residual
761  (
762  solveScalarField& rA,
763  const solveScalarField& psi,
764  const scalarField& source,
765  const FieldField<Field, scalar>& interfaceBouCoeffs,
766  const lduInterfaceFieldPtrsList& interfaces,
767  const direction cmpt
768  ) const;
769 
771  (
772  const solveScalarField& psi,
773  const scalarField& source,
774  const FieldField<Field, scalar>& interfaceBouCoeffs,
775  const lduInterfaceFieldPtrsList& interfaces,
776  const direction cmpt
777  ) const;
778 
779 
780  //- Initialise the update of interfaced interfaces
781  //- for matrix operations
783  (
784  const bool add,
785  const FieldField<Field, scalar>& interfaceCoeffs,
786  const lduInterfaceFieldPtrsList& interfaces,
787  const solveScalarField& psiif,
788  solveScalarField& result,
789  const direction cmpt
790  ) const;
791 
792  //- Update interfaced interfaces for matrix operations
794  (
795  const bool add,
796  const FieldField<Field, scalar>& interfaceCoeffs,
797  const lduInterfaceFieldPtrsList& interfaces,
798  const solveScalarField& psiif,
800  const direction cmpt,
801  const label startRequest // starting request (for non-blocking)
802  ) const;
803 
804  //- Set the residual field using an IOField on the object registry
805  //- if it exists
806  void setResidualField
807  (
808  const scalarField& residual,
809  const word& fieldName,
810  const bool initial
811  ) const;
812 
813  template<class Type>
814  tmp<Field<Type>> H(const Field<Type>&) const;
815 
816  template<class Type>
817  tmp<Field<Type>> H(const tmp<Field<Type>>&) const;
818 
819  tmp<scalarField> H1() const;
820 
821  template<class Type>
822  tmp<Field<Type>> faceH(const Field<Type>&) const;
824  template<class Type>
826 
827 
828  // Info
829 
830  //- Return info proxy,
831  //- used to print matrix information to a stream
832  InfoProxy<lduMatrix> info() const noexcept { return *this; }
833 
834 
835  // Member Operators
836 
837  //- Copy assignment
838  void operator=(const lduMatrix&);
839 
840  //- Move assignment
841  void operator=(lduMatrix&&);
842 
843  void negate();
844 
845  void operator+=(const lduMatrix&);
846  void operator-=(const lduMatrix&);
847 
848  void operator*=(const scalarField&);
849  void operator*=(scalar);
850 
851 
852  // Ostream Operators
853 
854  friend Ostream& operator<<(Ostream&, const lduMatrix&);
855  friend Ostream& operator<<(Ostream&, const InfoProxy<lduMatrix>&);
856 };
857 
858 
859 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
860 
861 } // End namespace Foam
862 
863 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
864 
865 #ifdef NoRepository
866  #include "lduMatrixTemplates.C"
867 #endif
868 
869 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
870 
871 #endif
872 
873 // ************************************************************************* //
UPtrList< const lduInterfaceField > lduInterfaceFieldPtrsList
List of coupled interface fields to be used in coupling.
virtual void read(const dictionary &)
Read and reset the preconditioner parameters from the given stream.
Definition: lduMatrix.H:660
virtual void smooth(solveScalarField &psi, const scalarField &source, const direction cmpt, const label nSweeps) const =0
Smooth the solution for a given number of sweeps.
const lduInterfaceFieldPtrsList & interfaces_
Definition: lduMatrix.H:419
const FieldField< Field, scalar > & interfaceBouCoeffs() const noexcept
Definition: lduMatrix.H:333
const scalarField & diag() const
Definition: lduMatrix.C:195
tmp< Field< Type > > faceH(const Field< Type > &) const
const lduInterfaceFieldPtrsList & interfaces() const noexcept
Definition: lduMatrix.H:539
void Tmul(solveScalarField &, const tmp< solveScalarField > &, const FieldField< Field, scalar > &, const lduInterfaceFieldPtrsList &, const direction cmpt) const
Matrix transpose multiplication with updated interfaces.
bool symmetric() const noexcept
Matrix is symmetric.
Definition: lduMatrix.H:838
word matrixTypeName() const
The matrix type (empty, diagonal, symmetric, ...)
Definition: lduMatrix.C:178
virtual void read(const dictionary &)
Read and reset the solver parameters from the given stream.
const FieldField< Field, scalar > & interfaceIntCoeffs() const noexcept
Definition: lduMatrix.H:534
uint8_t direction
Definition: direction.H:46
const FieldField< Field, scalar > & interfaceIntCoeffs_
Definition: lduMatrix.H:160
const lduMatrix & matrix() const noexcept
Definition: lduMatrix.H:524
preconditioner(const solver &sol)
Construct for given solver.
Definition: lduMatrix.H:630
bool hasLowerCSR() const noexcept
Definition: lduMatrix.H:799
~lduMatrix()=default
Destructor.
Field< solveScalar > solveScalarField
virtual const word & type() const =0
Runtime type information.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
declareRunTimeSelectionTable(autoPtr, preconditioner, symMatrix,(const solver &sol, const dictionary &solverControls),(sol, solverControls))
const solver & solver_
Reference to the base-solver this preconditioner is used with.
Definition: lduMatrix.H:582
void residual(solveScalarField &rA, const solveScalarField &psi, const scalarField &source, const FieldField< Field, scalar > &interfaceBouCoeffs, const lduInterfaceFieldPtrsList &interfaces, const direction cmpt) const
void setResidualField(const scalarField &residual, const word &fieldName, const bool initial) const
Set the residual field using an IOField on the object registry if it exists.
Definition: lduMatrix.C:457
declareRunTimeSelectionTable(autoPtr, solver, symMatrix,(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces, const dictionary &solverControls),(fieldName, matrix, interfaceBouCoeffs, interfaceIntCoeffs, interfaces, solverControls))
virtual solverPerformance solve(scalarField &psi, const scalarField &source, const direction cmpt=0) const =0
Solve with given field and rhs.
const solveScalarField & work() const
Work array.
Definition: lduMatrix.C:443
const FieldField< Field, scalar > & interfaceBouCoeffs_
Definition: lduMatrix.H:159
virtual void preconditionT(solveScalarField &wT, const solveScalarField &rT, const direction cmpt=0) const
Return wT the transpose-matrix preconditioned form of residual rT.
Definition: lduMatrix.H:680
pTraits< solveScalar >::cmptType cmptType
Component type.
Definition: Field.H:123
const lduMatrix & matrix() const noexcept
Definition: lduMatrix.H:328
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
Definition: lduMesh.H:53
InfoProxy< lduMatrix > info() const noexcept
Return info proxy, used to print matrix information to a stream.
Definition: lduMatrix.H:975
List< lduScheduleEntry > lduSchedule
A List of lduSchedule entries.
Definition: lduSchedule.H:46
Triggers for starting/stopping code profiling.
ClassName("lduMatrix")
tmp< scalarField > H1() const
void sumMagOffDiag(scalarField &sumOff) const
static constexpr const label defaultMaxIter
Default maximum number of iterations for solvers (1000)
Definition: lduMatrix.H:139
int log_
Verbosity level for solver output statements.
Definition: lduMatrix.H:171
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:51
static const Enum< normTypes > normTypesNames_
Names for the normTypes.
Definition: lduMatrix.H:134
label minIter_
Minimum number of iterations in the solver.
Definition: lduMatrix.H:176
lduMatrix::normTypes normType_
The normalisation type.
Definition: lduMatrix.H:186
virtual ~preconditioner()=default
Destructor.
const lduMatrix & matrix_
Definition: lduMatrix.H:416
static word getName(const dictionary &)
Find the smoother name (directly or from a sub-dictionary)
const lduSchedule & patchSchedule() const
Return the patch evaluation schedule.
Definition: lduMatrix.H:773
Abstract base-class for lduMatrix smoothers.
Definition: lduMatrix.H:409
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
scalar tolerance_
Final convergence tolerance.
Definition: lduMatrix.H:191
void Amul(solveScalarField &, const tmp< solveScalarField > &, const FieldField< Field, scalar > &, const lduInterfaceFieldPtrsList &, const direction cmpt) const
Matrix multiplication with updated interfaces.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics...
label maxIter_
Maximum number of iterations in the solver.
Definition: lduMatrix.H:181
static autoPtr< preconditioner > New(const solver &sol, const dictionary &solverControls)
Return a new preconditioner.
Abstract base-class for lduMatrix solvers.
Definition: lduMatrix.H:151
const word & fieldName() const noexcept
Definition: lduMatrix.H:519
lduMatrix member H operations.
void updateMatrixInterfaces(const bool add, const FieldField< Field, scalar > &interfaceCoeffs, const lduInterfaceFieldPtrsList &interfaces, const solveScalarField &psiif, solveScalarField &result, const direction cmpt, const label startRequest) const
Update interfaced interfaces for matrix operations.
void initMatrixInterfaces(const bool add, const FieldField< Field, scalar > &interfaceCoeffs, const lduInterfaceFieldPtrsList &interfaces, const solveScalarField &psiif, solveScalarField &result, const direction cmpt) const
Initialise the update of interfaced interfaces for matrix operations.
const scalarField & lower() const
Definition: lduMatrix.C:306
friend Ostream & operator<<(Ostream &, const lduMatrix &)
virtual const lduAddressing & lduAddr() const =0
Return ldu addressing.
void sumA(solveScalarField &, const FieldField< Field, scalar > &, const lduInterfaceFieldPtrsList &) const
Sum the coefficients on each row of the matrix.
const lduInterfaceFieldPtrsList & interfaces() const noexcept
Definition: lduMatrix.H:343
const FieldField< Field, scalar > & interfaceBouCoeffs() const noexcept
Definition: lduMatrix.H:529
static const scalar defaultTolerance
Default (absolute) tolerance (1e-6)
Definition: lduMatrix.H:144
solver(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces, const dictionary &solverControls)
Construct solver for given field name, matrix etc.
virtual const word & type() const =0
Runtime type information.
const FieldField< Field, scalar > & interfaceBouCoeffs_
Definition: lduMatrix.H:417
normTypes
Enumerated matrix normalisation types.
Definition: lduMatrix.H:124
void operator=(const lduMatrix &)
Copy assignment.
const lduMatrix & matrix_
Definition: lduMatrix.H:158
bool hasUpper() const noexcept
Definition: lduMatrix.H:824
bool asymmetric() const noexcept
Matrix is asymmetric (ie, full)
Definition: lduMatrix.H:846
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
smoother(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces)
Construct for given field name, matrix etc.
const direction noexcept
Definition: Scalar.H:258
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void operator*=(const scalarField &)
static autoPtr< solver > New(const word &solverName, const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces, const dictionary &solverControls)
Return a new solver of given type.
lduInterfaceFieldPtrsList interfaces_
Definition: lduMatrix.H:161
solveScalarField::cmptType normFactor(const solveScalarField &psi, const solveScalarField &source, const solveScalarField &Apsi, solveScalarField &tmpField, const lduMatrix::normTypes normType) const
Return the matrix norm using the specified norm method.
bool diagonal() const noexcept
Matrix has diagonal only.
Definition: lduMatrix.H:830
virtual ~smoother()=default
Destructor.
virtual const word & type() const =0
Runtime type information.
dictionary controlDict_
Dictionary of solution controls.
Definition: lduMatrix.H:166
"default" norm (== L1_scaled)
Basic run-time type information using word as the type&#39;s name. Used to enhance the standard RTTI to c...
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
lduMatrix is a general matrix class in which the coefficients are stored as three arrays...
Definition: lduMatrix.H:80
"none" norm (returns 1)
const scalarField & upper() const
Definition: lduMatrix.C:235
Abstract base-class for lduMatrix preconditioners.
Definition: lduMatrix.H:573
A helper class for outputting values to Ostream.
Definition: ensightCells.H:44
const lduMesh & mesh() const noexcept
Return the LDU mesh from which the addressing is obtained.
Definition: lduMatrix.H:749
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition: lduMatrix.H:765
static autoPtr< smoother > New(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces, const dictionary &solverControls)
Return a new smoother.
virtual void precondition(solveScalarField &wA, const solveScalarField &rA, const direction cmpt=0) const =0
Return wA the preconditioned form of residual rA.
void setLduMesh(const lduMesh &m)
Set the LDU mesh containing the addressing.
Definition: lduMatrix.H:757
virtual ~solver()=default
Destructor.
const FieldField< Field, scalar > & interfaceIntCoeffs() const noexcept
Definition: lduMatrix.H:338
const FieldField< Field, scalar > & interfaceIntCoeffs_
Definition: lduMatrix.H:418
lduMatrix(const lduMesh &mesh)
Construct (without coefficients) for an LDU addressed mesh.
Definition: lduMatrix.C:54
virtual solverPerformance scalarSolve(solveScalarField &psi, const solveScalarField &source, const direction cmpt=0) const
Solve with given field and rhs (in solveScalar precision).
static word getName(const dictionary &)
Find the preconditioner name (directly or from a sub-dictionary)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
bool hasDiag() const noexcept
Definition: lduMatrix.H:823
const volScalarField & psi
The class contains the addressing required by the lduMatrix: upper, lower and losort.
tmp< Field< Type > > H(const Field< Type > &) const
Macros to ease declaration of run-time selection tables.
void operator-=(const lduMatrix &)
void operator+=(const lduMatrix &)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
profilingTrigger profiling_
Profiling instrumentation.
Definition: lduMatrix.H:201
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:696
bool hasLower() const noexcept
Definition: lduMatrix.H:825
const word & fieldName() const noexcept
Definition: lduMatrix.H:323
virtual void setFinished(const solverPerformance &perf) const
Signal end of solver.
Definition: lduMatrix.H:692
virtual void scalarSmooth(solveScalarField &psi, const solveScalarField &source, const direction cmpt, const label nSweeps) const =0
Smooth the solution for a given number of sweeps.
Namespace for OpenFOAM.
SolverPerformance< scalar > solverPerformance
SolverPerformance instantiated for a scalar.
virtual void readControls()
Read the control parameters from controlDict_.
virtual const lduSchedule & patchSchedule() const =0
Return patch field evaluation schedule.
scalar relTol_
Convergence tolerance relative to the initial.
Definition: lduMatrix.H:196
declareRunTimeSelectionTable(autoPtr, smoother, symMatrix,(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces),(fieldName, matrix, interfaceBouCoeffs, interfaceIntCoeffs, interfaces))
const scalarField & lowerCSR() const
Definition: lduMatrix.C:376