processorFvPatchScalarField.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 
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 
35 template<>
37 (
38  scalarField&,
39  const scalarField& psiInternal,
40  const scalarField&,
41  const direction,
42  const Pstream::commsTypes commsType
43 ) const
44 {
45  this->patch().patchInternalField(psiInternal, scalarSendBuf_);
46 
47  if
48  (
51  )
52  {
53  // Fast path.
54  if (debug && !this->ready())
55  {
57  << "On patch " << procPatch_.name()
58  << " outstanding request."
59  << abort(FatalError);
60  }
61 
62 
63  scalarReceiveBuf_.setSize(scalarSendBuf_.size());
64  outstandingRecvRequest_ = UPstream::nRequests();
66  (
68  procPatch_.neighbProcNo(),
69  reinterpret_cast<char*>(scalarReceiveBuf_.begin()),
70  scalarReceiveBuf_.byteSize(),
71  procPatch_.tag(),
72  procPatch_.comm()
73  );
74 
75  outstandingSendRequest_ = UPstream::nRequests();
77  (
79  procPatch_.neighbProcNo(),
80  reinterpret_cast<const char*>(scalarSendBuf_.begin()),
81  scalarSendBuf_.byteSize(),
82  procPatch_.tag(),
83  procPatch_.comm()
84  );
85  }
86  else
87  {
88  procPatch_.compressedSend(commsType, scalarSendBuf_);
89  }
90 
91  const_cast<processorFvPatchField<scalar>&>(*this).updatedMatrix() = false;
92 }
93 
94 
95 template<>
97 (
98  scalarField& result,
99  const scalarField&,
100  const scalarField& coeffs,
101  const direction,
102  const Pstream::commsTypes commsType
103 ) const
104 {
105  if (this->updatedMatrix())
106  {
107  return;
108  }
109 
110  const labelUList& faceCells = this->patch().faceCells();
111 
112  if
113  (
116  )
117  {
118  // Fast path.
119  if
120  (
121  outstandingRecvRequest_ >= 0
122  && outstandingRecvRequest_ < Pstream::nRequests()
123  )
124  {
125  UPstream::waitRequest(outstandingRecvRequest_);
126  }
127  // Recv finished so assume sending finished as well.
128  outstandingSendRequest_ = -1;
129  outstandingRecvRequest_ = -1;
130 
131 
132  // Consume straight from scalarReceiveBuf_
133  forAll(faceCells, elemI)
134  {
135  result[faceCells[elemI]] -= coeffs[elemI]*scalarReceiveBuf_[elemI];
136  }
137  }
138  else
139  {
140  scalarField pnf
141  (
142  procPatch_.compressedReceive<scalar>(commsType, this->size())()
143  );
144 
145  forAll(faceCells, elemI)
146  {
147  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
148  }
149  }
150 
151  const_cast<processorFvPatchField<scalar>&>(*this).updatedMatrix() = true;
152 }
153 
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 } // End namespace Foam
158 
159 // ************************************************************************* //
static bool floatTransfer
Should compact transfer be used in which floats replace doubles.
Definition: UPstream.H:265
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
bool updatedMatrix() const
Whether matrix has been updated.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
commsTypes
Types of communications.
Definition: UPstream.H:64
uint8_t direction
Definition: direction.H:45
static label nRequests()
Get number of outstanding requests.
Definition: UPstream.C:137
virtual void initInterfaceMatrixUpdate(scalarField &result, const scalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Initialise neighbour matrix update.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
static label read(const commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=0)
Read into given buffer from given processor and return the.
Definition: UIPread.C:79
static bool write(const commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=0)
Write given buffer to given processor.
Definition: UOPwrite.C:34
virtual void updateInterfaceMatrix(scalarField &result, const scalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Update result field based on interface functionality.
This boundary condition enables processor communication across patches.
static void waitRequest(const label i)
Wait until request i has finished.
Definition: UPstream.C:151
Namespace for OpenFOAM.