processorFvPatchScalarField.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-2015 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 (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
48  {
49  // Fast path.
50  if (debug && !this->ready())
51  {
53  << "On patch " << procPatch_.name()
54  << " outstanding request."
55  << abort(FatalError);
56  }
57 
58 
59  scalarReceiveBuf_.setSize(scalarSendBuf_.size());
60  outstandingRecvRequest_ = UPstream::nRequests();
62  (
64  procPatch_.neighbProcNo(),
65  reinterpret_cast<char*>(scalarReceiveBuf_.begin()),
66  scalarReceiveBuf_.byteSize(),
67  procPatch_.tag(),
68  procPatch_.comm()
69  );
70 
71  outstandingSendRequest_ = UPstream::nRequests();
73  (
75  procPatch_.neighbProcNo(),
76  reinterpret_cast<const char*>(scalarSendBuf_.begin()),
77  scalarSendBuf_.byteSize(),
78  procPatch_.tag(),
79  procPatch_.comm()
80  );
81  }
82  else
83  {
84  procPatch_.compressedSend(commsType, scalarSendBuf_);
85  }
86 
87  const_cast<processorFvPatchField<scalar>&>(*this).updatedMatrix() = false;
88 }
89 
90 
91 template<>
93 (
94  scalarField& result,
95  const scalarField&,
96  const scalarField& coeffs,
97  const direction,
98  const Pstream::commsTypes commsType
99 ) const
100 {
101  if (this->updatedMatrix())
102  {
103  return;
104  }
105 
106  const labelUList& faceCells = this->patch().faceCells();
107 
108  if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
109  {
110  // Fast path.
111  if
112  (
113  outstandingRecvRequest_ >= 0
114  && outstandingRecvRequest_ < Pstream::nRequests()
115  )
116  {
117  UPstream::waitRequest(outstandingRecvRequest_);
118  }
119  // Recv finished so assume sending finished as well.
120  outstandingSendRequest_ = -1;
121  outstandingRecvRequest_ = -1;
122 
123 
124  // Consume straight from scalarReceiveBuf_
125  forAll(faceCells, elemI)
126  {
127  result[faceCells[elemI]] -= coeffs[elemI]*scalarReceiveBuf_[elemI];
128  }
129  }
130  else
131  {
132  scalarField pnf
133  (
134  procPatch_.compressedReceive<scalar>(commsType, this->size())()
135  );
136 
137  forAll(faceCells, elemI)
138  {
139  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
140  }
141  }
142 
143  const_cast<processorFvPatchField<scalar>&>(*this).updatedMatrix() = true;
144 }
145 
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 } // End namespace Foam
150 
151 // ************************************************************************* //
static bool floatTransfer
Should compact transfer be used in which floats replace doubles.
Definition: UPstream.H:261
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
uint8_t direction
Definition: direction.H:46
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
commsTypes
Types of communications.
Definition: UPstream.H:64
static label nRequests()
Get number of outstanding requests.
Definition: UPstream.C:107
virtual void initInterfaceMatrixUpdate(scalarField &result, const scalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Initialise neighbour matrix update.
bool updatedMatrix() const
Whether matrix has been updated.
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
This boundary condition enables processor communication across patches.
static void waitRequest(const label i)
Wait until request i has finished.
Definition: UPstream.C:121
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.
Namespace for OpenFOAM.