lduMatrixUpdateMatrixInterfaces.C
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) 2019-2020 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 \*---------------------------------------------------------------------------*/
28 
29 #include "lduMatrix.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
34 (
35  const bool add,
36  const FieldField<Field, scalar>& coupleCoeffs,
37  const lduInterfaceFieldPtrsList& interfaces,
38  const solveScalarField& psiif,
39  solveScalarField& result,
40  const direction cmpt
41 ) const
42 {
43  if
44  (
45  Pstream::defaultCommsType == Pstream::commsTypes::blocking
46  || Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking
47  )
48  {
49  forAll(interfaces, interfacei)
50  {
51  if (interfaces.set(interfacei))
52  {
53  interfaces[interfacei].initInterfaceMatrixUpdate
54  (
55  result,
56  add,
57  mesh().lduAddr(),
58  interfacei,
59  psiif,
60  coupleCoeffs[interfacei],
61  cmpt,
62  Pstream::defaultCommsType
63  );
64  }
65  }
66  }
67  else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled)
68  {
69  const lduSchedule& patchSchedule = this->patchSchedule();
70 
71  // Loop over the "global" patches are on the list of interfaces but
72  // beyond the end of the schedule which only handles "normal" patches
73  for
74  (
75  label interfacei=patchSchedule.size()/2;
76  interfacei<interfaces.size();
77  interfacei++
78  )
79  {
80  if (interfaces.set(interfacei))
81  {
82  interfaces[interfacei].initInterfaceMatrixUpdate
83  (
84  result,
85  add,
86  mesh().lduAddr(),
87  interfacei,
88  psiif,
89  coupleCoeffs[interfacei],
90  cmpt,
91  Pstream::commsTypes::blocking
92  );
93  }
94  }
95  }
96  else
97  {
99  << "Unsupported communications type "
100  << Pstream::commsTypeNames[Pstream::defaultCommsType]
101  << exit(FatalError);
102  }
103 }
104 
105 
107 (
108  const bool add,
109  const FieldField<Field, scalar>& coupleCoeffs,
110  const lduInterfaceFieldPtrsList& interfaces,
111  const solveScalarField& psiif,
112  solveScalarField& result,
113  const direction cmpt,
114  const label startRequest
115 ) const
116 {
117  if (Pstream::defaultCommsType == Pstream::commsTypes::blocking)
118  {
119  forAll(interfaces, interfacei)
120  {
121  if (interfaces.set(interfacei))
122  {
123  interfaces[interfacei].updateInterfaceMatrix
124  (
125  result,
126  add,
127  mesh().lduAddr(),
128  interfacei,
129  psiif,
130  coupleCoeffs[interfacei],
131  cmpt,
132  Pstream::defaultCommsType
133  );
134  }
135  }
136  }
137  else if (Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking)
138  {
139  // Try and consume interfaces as they become available
140  bool allUpdated = false;
141 
142  for (label i=0; i<UPstream::nPollProcInterfaces; i++)
143  {
144  allUpdated = true;
145 
146  forAll(interfaces, interfacei)
147  {
148  if (interfaces.set(interfacei))
149  {
150  if (!interfaces[interfacei].updatedMatrix())
151  {
152  if (interfaces[interfacei].ready())
153  {
154  interfaces[interfacei].updateInterfaceMatrix
155  (
156  result,
157  add,
158  mesh().lduAddr(),
159  interfacei,
160  psiif,
161  coupleCoeffs[interfacei],
162  cmpt,
163  Pstream::defaultCommsType
164  );
165  }
166  else
167  {
168  allUpdated = false;
169  }
170  }
171  }
172  }
173 
174  if (allUpdated)
175  {
176  break;
177  }
178  }
179 
180  // Block for everything
181  if (Pstream::parRun())
182  {
183  if (allUpdated)
184  {
185  // All received. Just remove all outstanding requests
186  UPstream::resetRequests(startRequest);
187  }
188  else
189  {
190  // Block for all requests and remove storage
191  UPstream::waitRequests(startRequest);
192  }
193  }
194 
195  // Consume
196  forAll(interfaces, interfacei)
197  {
198  if
199  (
200  interfaces.set(interfacei)
201  && !interfaces[interfacei].updatedMatrix()
202  )
203  {
204  interfaces[interfacei].updateInterfaceMatrix
205  (
206  result,
207  add,
208  mesh().lduAddr(),
209  interfacei,
210  psiif,
211  coupleCoeffs[interfacei],
212  cmpt,
213  Pstream::defaultCommsType
214  );
215  }
216  }
217  }
218  else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled)
219  {
220  const lduSchedule& patchSchedule = this->patchSchedule();
221 
222  // Loop over all the "normal" interfaces relating to standard patches
223  for (const auto& sched : patchSchedule)
224  {
225  const label interfacei = sched.patch;
226 
227  if (interfaces.set(interfacei))
228  {
229  if (sched.init)
230  {
231  interfaces[interfacei].initInterfaceMatrixUpdate
232  (
233  result,
234  add,
235  mesh().lduAddr(),
236  interfacei,
237  psiif,
238  coupleCoeffs[interfacei],
239  cmpt,
240  Pstream::commsTypes::scheduled
241  );
242  }
243  else
244  {
245  interfaces[interfacei].updateInterfaceMatrix
246  (
247  result,
248  add,
249  mesh().lduAddr(),
250  interfacei,
251  psiif,
252  coupleCoeffs[interfacei],
253  cmpt,
254  Pstream::commsTypes::scheduled
255  );
256  }
257  }
258  }
259 
260  // Loop over the "global" patches are on the list of interfaces but
261  // beyond the end of the schedule which only handles "normal" patches
262  for
263  (
264  label interfacei=patchSchedule.size()/2;
265  interfacei<interfaces.size();
266  interfacei++
267  )
268  {
269  if (interfaces.set(interfacei))
270  {
271  interfaces[interfacei].updateInterfaceMatrix
272  (
273  result,
274  add,
275  mesh().lduAddr(),
276  interfacei,
277  psiif,
278  coupleCoeffs[interfacei],
279  cmpt,
280  Pstream::commsTypes::blocking
281  );
282  }
283  }
284  }
285  else
286  {
288  << "Unsupported communications type "
289  << Pstream::commsTypeNames[Pstream::defaultCommsType]
290  << exit(FatalError);
291  }
292 }
293 
294 
295 // ************************************************************************* //
Foam::UPtrList::size
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
Foam::FieldField
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:53
lduMatrix.H
Foam::lduMatrix::updateMatrixInterfaces
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.
Definition: lduMatrixUpdateMatrixInterfaces.C:107
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Field< solveScalar >
Foam::UPtrList< const lduInterfaceField >
Foam::FatalError
error FatalError
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::lduMatrix::initMatrixInterfaces
void initMatrixInterfaces(const bool add, const FieldField< Field, scalar > &interfaceCoeffs, const lduInterfaceFieldPtrsList &interfaces, const solveScalarField &psiif, solveScalarField &result, const direction cmpt) const
Definition: lduMatrixUpdateMatrixInterfaces.C:34
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::UPtrList::set
const T * set(const label i) const
Definition: UPtrList.H:176
Foam::List< lduScheduleEntry >
Foam::direction
uint8_t direction
Definition: direction.H:52