distributedDILUPreconditioner.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) 2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::distributedDILUPreconditioner
28 
29 Group
30  grpLduMatrixPreconditioners
31 
32 Description
33  Version of DILUpreconditioner that uses preconditioning across processor
34  (and coupled) boundaries. Based on 'Parallel Preconditioners' chapter from
35  'Iterative Methods for Sparse Linear Systems' by Yousef Saad.
36 
37  Leaves out the handling of boundary nodes after internal nodes since
38  probably not beneficial (so no overlap of comms and internal calculation)
39 
40  By default preconditions across coupled boundaries (currently only
41  tested for cyclicAMI). This can be disabled with the 'coupled' setting
42 
43  solver PCG;
44  preconditioner
45  {
46  preconditioner distributedDILU;
47  coupled false;
48  }
49 
50  The cyclicAMI boundary behaviour will only work if
51  - running non-parallel or
52  - different sides of cyclicAMI run on different processors i.e.
53  there is no processor which has cells on both owner and neighbour
54  of the patch pair.
55 
56 See Also
57  Foam::DILUPreconditioner
58  Foam::distributedDICPreconditioner
59 
60 SourceFiles
61  distributedDILUPreconditioner.C
62 
63 \*---------------------------------------------------------------------------*/
64 
65 #ifndef Foam_distributedDILUPreconditioner_H
66 #define Foam_distributedDILUPreconditioner_H
67 
68 #include "lduMatrix.H"
69 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 
72 namespace Foam
73 {
74 
75 /*---------------------------------------------------------------------------*\
76  Class distributedDILUPreconditioner Declaration
77 \*---------------------------------------------------------------------------*/
78 
80 :
82 {
83 protected:
84 
85  // Protected Data
86 
87  //- Precondition across global coupled bc
88  const bool coupled_;
89 
90 
91  //- Processor interface buffers and colouring
92 
93  //- Previous mesh
94  static const lduMesh* meshPtr_;
95 
96  //- Previous processor colours
98 
99  //- Buffers for sending and receiving data
103 
104  //- Interfaces to lower coloured processors
108 
109  //- Interfaces to higher coloured processors
115  //- Local (cell) colouring from global interfaces
116 
117  //- Colour/zone per cell
120  //- Number of colours (in case of multiple disconnected regions
121  // in single mesh)
122  label nColours_;
123 
124 
125  //- Global interfaces. Per colour the interfaces that (might)
126  //- influence it
127 
129 
130  //- Interfaces to non-processor lower coupled interfaces
132 
133  //- Interfaces to non-processor lower coupled interfaces
135 
136  //- Corresponding destination colour (for lowerGlobal)
139  //- Interfaces to non-processor higher coupled interfaces
141 
142  //- Interfaces to non-processor higher coupled interfaces
144 
145  //- Corresponding destination colour (for higherGlobal)
147 
148 
149  //- The reciprocal preconditioned diagonal
152 
153  // Private Member Functions
154 
155  //- Variant of lduMatrix::updateMatrixInterfaces on selected interfaces
157  (
158  const bool add,
159  const FieldField<Field, scalar>& coupleCoeffs,
160  const labelList& selectedInterfaces,
161  const solveScalarField& psiif,
162  solveScalarField& result,
163  const direction cmpt
164  ) const;
165 
166  //- Send (and store in colourBufs_[colouri]) the effect of
167  // doing selectedInterfaces
168  void sendGlobal
169  (
170  const labelList& selectedInterfaces,
172  const label colouri
173  ) const;
174 
175  //- Start receiving in recvBufs_
176  void receive
177  (
178  const labelList& selectedInterfaces,
180  ) const;
181 
182  //- Start sending sendBufs_
183  void send
184  (
185  const labelList& selectedInterfaces,
186  const solveScalarField& psiInternal,
188  ) const;
189 
190  //- Wait for requests or cancel/free requests
191  void wait
192  (
194  const bool cancel = false
195  ) const;
196 
197  //- Update diagonal for interface
198  virtual void addInterfaceDiag
199  (
200  solveScalarField& rD,
201  const label inti,
202  const Field<solveScalar>& recvBuf
203  ) const;
204 
205  //- Update diagonal for all faces of a certain colour
206  virtual void forwardInternalDiag
207  (
208  solveScalarField& rD,
209  const label colouri
210  ) const;
211 
212  //- Update preconditioned variable from interface
213  virtual void addInterface
214  (
215  solveScalarField& wA,
216  const label inti,
217  const Field<solveScalar>& recvBuf
218  ) const;
219 
220  //- Update preconditioned variable walking forward on internal faces
221  virtual void forwardInternal
222  (
223  solveScalarField& wA,
224  const label colouri
225  ) const;
226 
227  //- Update preconditioned variable walking backward on internal faces
228  virtual void backwardInternal
229  (
230  solveScalarField& wA,
231  const label colouri
232  ) const;
233 
234  //- Calculate reciprocal of diagonal
235  virtual void calcReciprocalD(solveScalarField& rD) const;
236 
237 
238 public:
239 
240  //- Runtime type information
241  TypeName("distributedDILU");
242 
243 
244  // Constructors
245 
246  //- Construct from matrix components and preconditioner solver controls
248  (
249  const lduMatrix::solver&,
250  const dictionary& solverControlsUnused
251  );
252 
253 
254  //- Destructor
256 
257 
258  // Member Functions
259 
260  //- Return wA the preconditioned form of residual rA
261  virtual void precondition
262  (
263  solveScalarField& wA,
264  const solveScalarField& rA,
265  const direction cmpt=0
266  ) const;
267 
268  //- Signal end of solver
269  virtual void setFinished(const solverPerformance& perf) const;
270 };
271 
272 
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 
275 } // End namespace Foam
276 
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278 
279 #endif
280 
281 // ************************************************************************* //
virtual void addInterfaceDiag(solveScalarField &rD, const label inti, const Field< solveScalar > &recvBuf) const
Update diagonal for interface.
FieldField< Field, solveScalar > sendBufs_
Buffers for sending and receiving data.
virtual void precondition(solveScalarField &wA, const solveScalarField &rA, const direction cmpt=0) const
Return wA the preconditioned form of residual rA.
uint8_t direction
Definition: direction.H:46
DynamicList< UPstream::Request > lowerSendRequests_
void send(const labelList &selectedInterfaces, const solveScalarField &psiInternal, DynamicList< UPstream::Request > &requests) const
Start sending sendBufs_.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
distributedDILUPreconditioner(const lduMatrix::solver &, const dictionary &solverControlsUnused)
Construct from matrix components and preconditioner solver controls.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
DynamicList< UPstream::Request > recvRequests_
autoPtr< labelList > cellColourPtr_
Local (cell) colouring from global interfaces.
virtual void forwardInternalDiag(solveScalarField &rD, const label colouri) const
Update diagonal for all faces of a certain colour.
solveScalarField rD_
The reciprocal preconditioned diagonal.
List< DynamicList< label > > lowerGlobalSend_
Interfaces to non-processor lower coupled interfaces.
virtual void setFinished(const solverPerformance &perf) const
Signal end of solver.
static const lduMesh * meshPtr_
Processor interface buffers and colouring.
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
Definition: lduMesh.H:53
List< DynamicList< label > > higherGlobalSend_
Interfaces to non-processor higher coupled interfaces.
FieldField< Field, solveScalar > recvBufs_
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:51
List< label > higherColour_
Corresponding destination colour (for higherGlobal)
static autoPtr< labelList > procColoursPtr_
Previous processor colours.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
virtual void forwardInternal(solveScalarField &wA, const label colouri) const
Update preconditioned variable walking forward on internal faces.
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics...
virtual void addInterface(solveScalarField &wA, const label inti, const Field< solveScalar > &recvBuf) const
Update preconditioned variable from interface.
Abstract base-class for lduMatrix solvers.
Definition: lduMatrix.H:129
Version of DILUpreconditioner that uses preconditioning across processor (and coupled) boundaries...
TypeName("distributedDILU")
Runtime type information.
virtual void backwardInternal(solveScalarField &wA, const label colouri) const
Update preconditioned variable walking backward on internal faces.
virtual void calcReciprocalD(solveScalarField &rD) const
Calculate reciprocal of diagonal.
void receive(const labelList &selectedInterfaces, DynamicList< UPstream::Request > &requests) const
Start receiving in recvBufs_.
const bool coupled_
Precondition across global coupled bc.
void updateMatrixInterfaces(const bool add, const FieldField< Field, scalar > &coupleCoeffs, const labelList &selectedInterfaces, const solveScalarField &psiif, solveScalarField &result, const direction cmpt) const
Variant of lduMatrix::updateMatrixInterfaces on selected interfaces.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
DynamicList< label > lowerNbrs_
Interfaces to lower coloured processors.
PtrList< FieldField< Field, solveScalar > > colourBufs_
Global interfaces. Per colour the interfaces that (might) influence it.
List< DynamicList< label > > lowerGlobalRecv_
Interfaces to non-processor lower coupled interfaces.
DynamicList< UPstream::Request > lowerRecvRequests_
DynamicList< UPstream::Request > higherRecvRequests_
void sendGlobal(const labelList &selectedInterfaces, solveScalarField &psi, const label colouri) const
Send (and store in colourBufs_[colouri]) the effect of.
Abstract base-class for lduMatrix preconditioners.
Definition: lduMatrix.H:549
DynamicList< label > higherNbrs_
Interfaces to higher coloured processors.
label nColours_
Number of colours (in case of multiple disconnected regions.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
void wait(DynamicList< UPstream::Request > &requests, const bool cancel=false) const
Wait for requests or cancel/free requests.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
const volScalarField & psi
List< label > lowerColour_
Corresponding destination colour (for lowerGlobal)
DynamicList< UPstream::Request > higherSendRequests_
List< DynamicList< label > > higherGlobalRecv_
Interfaces to non-processor higher coupled interfaces.
Namespace for OpenFOAM.