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  psiif,
58  coupleCoeffs[interfacei],
59  cmpt,
60  Pstream::defaultCommsType
61  );
62  }
63  }
64  }
65  else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled)
66  {
67  const lduSchedule& patchSchedule = this->patchSchedule();
68 
69  // Loop over the "global" patches are on the list of interfaces but
70  // beyond the end of the schedule which only handles "normal" patches
71  for
72  (
73  label interfacei=patchSchedule.size()/2;
74  interfacei<interfaces.size();
75  interfacei++
76  )
77  {
78  if (interfaces.set(interfacei))
79  {
80  interfaces[interfacei].initInterfaceMatrixUpdate
81  (
82  result,
83  add,
84  psiif,
85  coupleCoeffs[interfacei],
86  cmpt,
87  Pstream::commsTypes::blocking
88  );
89  }
90  }
91  }
92  else
93  {
95  << "Unsupported communications type "
96  << Pstream::commsTypeNames[Pstream::defaultCommsType]
97  << exit(FatalError);
98  }
99 }
100 
101 
103 (
104  const bool add,
105  const FieldField<Field, scalar>& coupleCoeffs,
106  const lduInterfaceFieldPtrsList& interfaces,
107  const solveScalarField& psiif,
108  solveScalarField& result,
109  const direction cmpt,
110  const label startRequest
111 ) const
112 {
113  if (Pstream::defaultCommsType == Pstream::commsTypes::blocking)
114  {
115  forAll(interfaces, interfacei)
116  {
117  if (interfaces.set(interfacei))
118  {
119  interfaces[interfacei].updateInterfaceMatrix
120  (
121  result,
122  add,
123  psiif,
124  coupleCoeffs[interfacei],
125  cmpt,
126  Pstream::defaultCommsType
127  );
128  }
129  }
130  }
131  else if (Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking)
132  {
133  // Try and consume interfaces as they become available
134  bool allUpdated = false;
135 
136  for (label i=0; i<UPstream::nPollProcInterfaces; i++)
137  {
138  allUpdated = true;
139 
140  forAll(interfaces, interfacei)
141  {
142  if (interfaces.set(interfacei))
143  {
144  if (!interfaces[interfacei].updatedMatrix())
145  {
146  if (interfaces[interfacei].ready())
147  {
148  interfaces[interfacei].updateInterfaceMatrix
149  (
150  result,
151  add,
152  psiif,
153  coupleCoeffs[interfacei],
154  cmpt,
155  Pstream::defaultCommsType
156  );
157  }
158  else
159  {
160  allUpdated = false;
161  }
162  }
163  }
164  }
165 
166  if (allUpdated)
167  {
168  break;
169  }
170  }
171 
172  // Block for everything
173  if (Pstream::parRun())
174  {
175  if (allUpdated)
176  {
177  // All received. Just remove all outstanding requests
178  UPstream::resetRequests(startRequest);
179  }
180  else
181  {
182  // Block for all requests and remove storage
183  UPstream::waitRequests(startRequest);
184  }
185  }
186 
187  // Consume
188  forAll(interfaces, interfacei)
189  {
190  if
191  (
192  interfaces.set(interfacei)
193  && !interfaces[interfacei].updatedMatrix()
194  )
195  {
196  interfaces[interfacei].updateInterfaceMatrix
197  (
198  result,
199  add,
200  psiif,
201  coupleCoeffs[interfacei],
202  cmpt,
203  Pstream::defaultCommsType
204  );
205  }
206  }
207  }
208  else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled)
209  {
210  const lduSchedule& patchSchedule = this->patchSchedule();
211 
212  // Loop over all the "normal" interfaces relating to standard patches
213  forAll(patchSchedule, i)
214  {
215  label interfacei = patchSchedule[i].patch;
216 
217  if (interfaces.set(interfacei))
218  {
219  if (patchSchedule[i].init)
220  {
221  interfaces[interfacei].initInterfaceMatrixUpdate
222  (
223  result,
224  add,
225  psiif,
226  coupleCoeffs[interfacei],
227  cmpt,
228  Pstream::commsTypes::scheduled
229  );
230  }
231  else
232  {
233  interfaces[interfacei].updateInterfaceMatrix
234  (
235  result,
236  add,
237  psiif,
238  coupleCoeffs[interfacei],
239  cmpt,
240  Pstream::commsTypes::scheduled
241  );
242  }
243  }
244  }
245 
246  // Loop over the "global" patches are on the list of interfaces but
247  // beyond the end of the schedule which only handles "normal" patches
248  for
249  (
250  label interfacei=patchSchedule.size()/2;
251  interfacei<interfaces.size();
252  interfacei++
253  )
254  {
255  if (interfaces.set(interfacei))
256  {
257  interfaces[interfacei].updateInterfaceMatrix
258  (
259  result,
260  add,
261  psiif,
262  coupleCoeffs[interfacei],
263  cmpt,
264  Pstream::commsTypes::blocking
265  );
266  }
267  }
268  }
269  else
270  {
272  << "Unsupported communications type "
273  << Pstream::commsTypeNames[Pstream::defaultCommsType]
274  << exit(FatalError);
275  }
276 }
277 
278 
279 // ************************************************************************* //
Foam::UPtrList::size
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:97
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:103
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Field< solveScalar >
init
mesh init(true)
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
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:381
Foam::UPtrList::set
const T * set(const label i) const
Return const pointer to element (can be nullptr),.
Definition: UPtrList.H:170
Foam::List< lduScheduleEntry >
Foam::direction
uint8_t direction
Definition: direction.H:52