lduMatrixUpdateMatrixInterfaces.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "lduMatrix.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
31 (
32  const FieldField<Field, scalar>& coupleCoeffs,
33  const lduInterfaceFieldPtrsList& interfaces,
34  const scalarField& psiif,
35  scalarField& result,
36  const direction cmpt
37 ) const
38 {
39  if
40  (
41  Pstream::defaultCommsType == Pstream::commsTypes::blocking
42  || Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking
43  )
44  {
45  forAll(interfaces, interfacei)
46  {
47  if (interfaces.set(interfacei))
48  {
49  interfaces[interfacei].initInterfaceMatrixUpdate
50  (
51  result,
52  psiif,
53  coupleCoeffs[interfacei],
54  cmpt,
55  Pstream::defaultCommsType
56  );
57  }
58  }
59  }
60  else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled)
61  {
62  const lduSchedule& patchSchedule = this->patchSchedule();
63 
64  // Loop over the "global" patches are on the list of interfaces but
65  // beyond the end of the schedule which only handles "normal" patches
66  for
67  (
68  label interfacei=patchSchedule.size()/2;
69  interfacei<interfaces.size();
70  interfacei++
71  )
72  {
73  if (interfaces.set(interfacei))
74  {
75  interfaces[interfacei].initInterfaceMatrixUpdate
76  (
77  result,
78  psiif,
79  coupleCoeffs[interfacei],
80  cmpt,
81  Pstream::commsTypes::blocking
82  );
83  }
84  }
85  }
86  else
87  {
89  << "Unsupported communications type "
90  << Pstream::commsTypeNames[Pstream::defaultCommsType]
91  << exit(FatalError);
92  }
93 }
94 
95 
97 (
98  const FieldField<Field, scalar>& coupleCoeffs,
99  const lduInterfaceFieldPtrsList& interfaces,
100  const scalarField& psiif,
101  scalarField& result,
102  const direction cmpt
103 ) const
104 {
105  if (Pstream::defaultCommsType == Pstream::commsTypes::blocking)
106  {
107  forAll(interfaces, interfacei)
108  {
109  if (interfaces.set(interfacei))
110  {
111  interfaces[interfacei].updateInterfaceMatrix
112  (
113  result,
114  psiif,
115  coupleCoeffs[interfacei],
116  cmpt,
117  Pstream::defaultCommsType
118  );
119  }
120  }
121  }
122  else if (Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking)
123  {
124  // Try and consume interfaces as they become available
125  bool allUpdated = false;
126 
127  for (label i=0; i<UPstream::nPollProcInterfaces; i++)
128  {
129  allUpdated = true;
130 
131  forAll(interfaces, interfacei)
132  {
133  if (interfaces.set(interfacei))
134  {
135  if (!interfaces[interfacei].updatedMatrix())
136  {
137  if (interfaces[interfacei].ready())
138  {
139  interfaces[interfacei].updateInterfaceMatrix
140  (
141  result,
142  psiif,
143  coupleCoeffs[interfacei],
144  cmpt,
145  Pstream::defaultCommsType
146  );
147  }
148  else
149  {
150  allUpdated = false;
151  }
152  }
153  }
154  }
155 
156  if (allUpdated)
157  {
158  break;
159  }
160  }
161 
162  // Block for everything
163  if (Pstream::parRun())
164  {
165  if (allUpdated)
166  {
167  // All received. Just remove all storage of requests
168  // Note that we don't know what starting number of requests
169  // was before start of sends and receives (since set from
170  // initMatrixInterfaces) so set to 0 and loose any in-flight
171  // requests.
172  UPstream::resetRequests(0);
173  }
174  else
175  {
176  // Block for all requests and remove storage
177  UPstream::waitRequests();
178  }
179  }
180 
181  // Consume
182  forAll(interfaces, interfacei)
183  {
184  if
185  (
186  interfaces.set(interfacei)
187  && !interfaces[interfacei].updatedMatrix()
188  )
189  {
190  interfaces[interfacei].updateInterfaceMatrix
191  (
192  result,
193  psiif,
194  coupleCoeffs[interfacei],
195  cmpt,
196  Pstream::defaultCommsType
197  );
198  }
199  }
200  }
201  else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled)
202  {
203  const lduSchedule& patchSchedule = this->patchSchedule();
204 
205  // Loop over all the "normal" interfaces relating to standard patches
206  forAll(patchSchedule, i)
207  {
208  label interfacei = patchSchedule[i].patch;
209 
210  if (interfaces.set(interfacei))
211  {
212  if (patchSchedule[i].init)
213  {
214  interfaces[interfacei].initInterfaceMatrixUpdate
215  (
216  result,
217  psiif,
218  coupleCoeffs[interfacei],
219  cmpt,
220  Pstream::commsTypes::scheduled
221  );
222  }
223  else
224  {
225  interfaces[interfacei].updateInterfaceMatrix
226  (
227  result,
228  psiif,
229  coupleCoeffs[interfacei],
230  cmpt,
231  Pstream::commsTypes::scheduled
232  );
233  }
234  }
235  }
236 
237  // Loop over the "global" patches are on the list of interfaces but
238  // beyond the end of the schedule which only handles "normal" patches
239  for
240  (
241  label interfacei=patchSchedule.size()/2;
242  interfacei<interfaces.size();
243  interfacei++
244  )
245  {
246  if (interfaces.set(interfacei))
247  {
248  interfaces[interfacei].updateInterfaceMatrix
249  (
250  result,
251  psiif,
252  coupleCoeffs[interfacei],
253  cmpt,
254  Pstream::commsTypes::blocking
255  );
256  }
257  }
258  }
259  else
260  {
262  << "Unsupported communications type "
263  << Pstream::commsTypeNames[Pstream::defaultCommsType]
264  << exit(FatalError);
265  }
266 }
267 
268 
269 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
uint8_t direction
Definition: direction.H:45
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
void initMatrixInterfaces(const FieldField< Field, scalar > &interfaceCoeffs, const lduInterfaceFieldPtrsList &interfaces, const scalarField &psiif, scalarField &result, const direction cmpt) const
Initialise the update of interfaced interfaces.
Generic field type.
Definition: FieldField.H:51
void updateMatrixInterfaces(const FieldField< Field, scalar > &interfaceCoeffs, const lduInterfaceFieldPtrsList &interfaces, const scalarField &psiif, scalarField &result, const direction cmpt) const
Update interfaced interfaces for matrix operations.
bool set(const label) const
Is element set.
Definition: UPtrListI.H:78
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29