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<>
36 inline
38 (
39  scalarField&,
40  const scalarField& psiInternal,
41  const scalarField&,
42  const direction,
43  const Pstream::commsTypes commsType
44 ) const
45 {
46  this->patch().patchInternalField(psiInternal, scalarSendBuf_);
47 
48  if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
49  {
50  // Fast path.
51  if (debug && !this->ready())
52  {
54  << "On patch " << procPatch_.name()
55  << " outstanding request."
56  << abort(FatalError);
57  }
58 
59 
60  scalarReceiveBuf_.setSize(scalarSendBuf_.size());
61  outstandingRecvRequest_ = UPstream::nRequests();
63  (
65  procPatch_.neighbProcNo(),
66  reinterpret_cast<char*>(scalarReceiveBuf_.begin()),
67  scalarReceiveBuf_.byteSize(),
68  procPatch_.tag(),
69  procPatch_.comm()
70  );
71 
72  outstandingSendRequest_ = UPstream::nRequests();
74  (
76  procPatch_.neighbProcNo(),
77  reinterpret_cast<const char*>(scalarSendBuf_.begin()),
78  scalarSendBuf_.byteSize(),
79  procPatch_.tag(),
80  procPatch_.comm()
81  );
82  }
83  else
84  {
85  procPatch_.compressedSend(commsType, scalarSendBuf_);
86  }
87 
88  const_cast<processorFvPatchField<scalar>&>(*this).updatedMatrix() = false;
89 }
90 
91 
92 template<>
93 inline
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 // ************************************************************************* //
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::processorFvPatchField
This boundary condition enables processor communication across patches.
Definition: processorFvPatchField.H:64
Foam::UIPstream::read
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
Foam::UOPstream::write
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
Foam::UPstream::nonBlocking
@ nonBlocking
Definition: UPstream.H:68
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::UPstream::floatTransfer
static bool floatTransfer
Should compact transfer be used in which floats replace doubles.
Definition: UPstream.H:245
Foam::UPstream::waitRequest
static void waitRequest(const label i)
Wait until request i has finished.
Definition: UPstream.C:110
Foam::processorFvPatchField::initInterfaceMatrixUpdate
virtual void initInterfaceMatrixUpdate(scalarField &result, const scalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Initialise neighbour matrix update.
Definition: processorFvPatchField.C:306
Foam::FatalError
error FatalError
Foam::lduInterfaceField::updatedMatrix
bool updatedMatrix() const
Whether matrix has been updated.
Definition: lduInterfaceField.H:116
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::processorFvPatchField::updateInterfaceMatrix
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.
Definition: processorFvPatchField.C:362
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:64
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::UPstream::nRequests
static label nRequests()
Get number of outstanding requests.
Definition: UPstream.C:96
Foam::UList
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
Foam::direction
unsigned char direction
Definition: direction.H:43
processorFvPatchScalarField.H