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