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 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  << "Unsuported 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
111 {
112  if (Pstream::defaultCommsType == Pstream::commsTypes::blocking)
113  {
114  forAll(interfaces, interfacei)
115  {
116  if (interfaces.set(interfacei))
117  {
118  interfaces[interfacei].updateInterfaceMatrix
119  (
120  result,
121  add,
122  psiif,
123  coupleCoeffs[interfacei],
124  cmpt,
125  Pstream::defaultCommsType
126  );
127  }
128  }
129  }
130  else if (Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking)
131  {
132  // Try and consume interfaces as they become available
133  bool allUpdated = false;
134 
135  for (label i=0; i<UPstream::nPollProcInterfaces; i++)
136  {
137  allUpdated = true;
138 
139  forAll(interfaces, interfacei)
140  {
141  if (interfaces.set(interfacei))
142  {
143  if (!interfaces[interfacei].updatedMatrix())
144  {
145  if (interfaces[interfacei].ready())
146  {
147  interfaces[interfacei].updateInterfaceMatrix
148  (
149  result,
150  add,
151  psiif,
152  coupleCoeffs[interfacei],
153  cmpt,
154  Pstream::defaultCommsType
155  );
156  }
157  else
158  {
159  allUpdated = false;
160  }
161  }
162  }
163  }
164 
165  if (allUpdated)
166  {
167  break;
168  }
169  }
170 
171  // Block for everything
172  if (Pstream::parRun())
173  {
174  if (allUpdated)
175  {
176  // All received. Just remove all storage of requests
177  // Note that we don't know what starting number of requests
178  // was before start of sends and receives (since set from
179  // initMatrixInterfaces) so set to 0 and loose any in-flight
180  // requests.
181  UPstream::resetRequests(0);
182  }
183  else
184  {
185  // Block for all requests and remove storage
186  UPstream::waitRequests();
187  }
188  }
189 
190  // Consume
191  forAll(interfaces, interfacei)
192  {
193  if
194  (
195  interfaces.set(interfacei)
196  && !interfaces[interfacei].updatedMatrix()
197  )
198  {
199  interfaces[interfacei].updateInterfaceMatrix
200  (
201  result,
202  add,
203  psiif,
204  coupleCoeffs[interfacei],
205  cmpt,
206  Pstream::defaultCommsType
207  );
208  }
209  }
210  }
211  else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled)
212  {
213  const lduSchedule& patchSchedule = this->patchSchedule();
214 
215  // Loop over all the "normal" interfaces relating to standard patches
216  forAll(patchSchedule, i)
217  {
218  label interfacei = patchSchedule[i].patch;
219 
220  if (interfaces.set(interfacei))
221  {
222  if (patchSchedule[i].init)
223  {
224  interfaces[interfacei].initInterfaceMatrixUpdate
225  (
226  result,
227  add,
228  psiif,
229  coupleCoeffs[interfacei],
230  cmpt,
231  Pstream::commsTypes::scheduled
232  );
233  }
234  else
235  {
236  interfaces[interfacei].updateInterfaceMatrix
237  (
238  result,
239  add,
240  psiif,
241  coupleCoeffs[interfacei],
242  cmpt,
243  Pstream::commsTypes::scheduled
244  );
245  }
246  }
247  }
248 
249  // Loop over the "global" patches are on the list of interfaces but
250  // beyond the end of the schedule which only handles "normal" patches
251  for
252  (
253  label interfacei=patchSchedule.size()/2;
254  interfacei<interfaces.size();
255  interfacei++
256  )
257  {
258  if (interfaces.set(interfacei))
259  {
260  interfaces[interfacei].updateInterfaceMatrix
261  (
262  result,
263  add,
264  psiif,
265  coupleCoeffs[interfacei],
266  cmpt,
267  Pstream::commsTypes::blocking
268  );
269  }
270  }
271  }
272  else
273  {
275  << "Unsuported communications type "
276  << Pstream::commsTypeNames[Pstream::defaultCommsType]
277  << exit(FatalError);
278  }
279 }
280 
281 
282 // ************************************************************************* //
Foam::UPtrList::size
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:90
Foam::FieldField
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:53
Foam::UPtrList::set
const T * set(const label i) const
Return const pointer to element (if set) or nullptr.
Definition: UPtrListI.H:176
lduMatrix.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::label
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:62
Foam::Field< solveScalar >
Foam::UPtrList< const lduInterfaceField >
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
Update interfaced interfaces for matrix operations.
Definition: lduMatrixUpdateMatrixInterfaces.C:103
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:355
Foam::List< lduScheduleEntry >
Foam::direction
uint8_t direction
Definition: direction.H:47