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 | Copyright (C) 2011-2013 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::blocking
42  || Pstream::defaultCommsType == Pstream::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::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::blocking
82  );
83  }
84  }
85  }
86  else
87  {
88  FatalErrorIn("lduMatrix::initMatrixInterfaces(..)")
89  << "Unsuported 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::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::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::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::scheduled
221  );
222  }
223  else
224  {
225  interfaces[interfaceI].updateInterfaceMatrix
226  (
227  result,
228  psiif,
229  coupleCoeffs[interfaceI],
230  cmpt,
231  Pstream::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::blocking
255  );
256  }
257  }
258  }
259  else
260  {
261  FatalErrorIn("lduMatrix::updateMatrixInterfaces(..)")
262  << "Unsuported communications type "
263  << Pstream::commsTypeNames[Pstream::defaultCommsType]
264  << exit(FatalError);
265  }
266 }
267 
268 
269 // ************************************************************************* //
unsigned char direction
Definition: direction.H:43
Generic field type.
Definition: FieldField.H:51
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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.
#define forAll(list, i)
Definition: UList.H:421
bool set(const label) const
Is element set.
Definition: UPtrListI.H:80
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:31
error FatalError
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.