calculatedProcessorGAMGInterfaceField.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2019-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
30 #include "lduMatrix.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(calculatedProcessorGAMGInterfaceField, 0);
38  (
39  GAMGInterfaceField,
40  calculatedProcessorGAMGInterfaceField,
41  lduInterface
42  );
44  (
45  GAMGInterfaceField,
46  calculatedProcessorGAMGInterfaceField,
47  lduInterfaceField
48  );
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
54 Foam::calculatedProcessorGAMGInterfaceField::
55 calculatedProcessorGAMGInterfaceField
56 (
57  const GAMGInterface& GAMGCp,
58  const lduInterfaceField& fineInterface
59 )
60 :
61  GAMGInterfaceField(GAMGCp, fineInterface),
62  procInterface_(refCast<const calculatedProcessorGAMGInterface>(GAMGCp)),
63  doTransform_(false),
64  rank_(0)
65 {
67  refCast<const processorLduInterfaceField>(fineInterface);
68 
69  doTransform_ = p.doTransform();
70  rank_ = p.rank();
71 }
72 
73 
74 Foam::calculatedProcessorGAMGInterfaceField::
75 calculatedProcessorGAMGInterfaceField
76 (
77  const GAMGInterface& GAMGCp,
78  const bool doTransform,
79  const int rank
80 )
81 :
82  GAMGInterfaceField(GAMGCp, doTransform, rank),
83  procInterface_(refCast<const calculatedProcessorGAMGInterface>(GAMGCp)),
84  doTransform_(doTransform),
85  rank_(rank)
86 {}
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
92 (
94  const bool add,
95  const lduAddressing& lduAddr,
96  const label patchId,
97  const solveScalarField& psiInternal,
98  const scalarField&,
99  const direction,
100  const Pstream::commsTypes commsType
101 ) const
102 {
103  procInterface_.interfaceInternalField(psiInternal, scalarSendBuf_);
104 
105  if
106  (
107  commsType == Pstream::commsTypes::nonBlocking
108  && !Pstream::floatTransfer
109  )
110  {
111  // Fast path.
112  scalarReceiveBuf_.setSize(scalarSendBuf_.size());
113  outstandingRecvRequest_ = UPstream::nRequests();
115  (
116  Pstream::commsTypes::nonBlocking,
117  procInterface_.neighbProcNo(),
118  scalarReceiveBuf_.data_bytes(),
119  scalarReceiveBuf_.size_bytes(),
120  procInterface_.tag(),
121  comm()
122  );
123 
124  outstandingSendRequest_ = UPstream::nRequests();
126  (
127  Pstream::commsTypes::nonBlocking,
128  procInterface_.neighbProcNo(),
129  scalarSendBuf_.cdata_bytes(),
130  scalarSendBuf_.size_bytes(),
131  procInterface_.tag(),
132  comm()
133  );
134  }
135  else
136  {
137  procInterface_.compressedSend(commsType, scalarSendBuf_);
138  }
139 
141  = false;
142 }
143 
144 
146 (
147  solveScalarField& result,
148  const bool add,
149  const lduAddressing& lduAddr,
150  const label patchId,
151  const solveScalarField&,
152  const scalarField& coeffs,
153  const direction cmpt,
154  const Pstream::commsTypes commsType
155 ) const
156 {
157  if (updatedMatrix())
158  {
159  return;
160  }
161 
162  const labelUList& faceCells = lduAddr.patchAddr(patchId);
163 
164  if
165  (
166  commsType == Pstream::commsTypes::nonBlocking
167  && !Pstream::floatTransfer
168  )
169  {
170  // Fast path.
171  if
172  (
173  outstandingRecvRequest_ >= 0
174  && outstandingRecvRequest_ < Pstream::nRequests()
175  )
176  {
177  UPstream::waitRequest(outstandingRecvRequest_);
178  }
179  // Recv finished so assume sending finished as well.
180  outstandingSendRequest_ = -1;
181  outstandingRecvRequest_ = -1;
182 
183  // Consume straight from scalarReceiveBuf_
184 
185  // Transform according to the transformation tensor
186  transformCoupleField(scalarReceiveBuf_, cmpt);
187 
188  // Multiply the field by coefficients and add into the result
189  addToInternalField(result, !add, faceCells, coeffs, scalarReceiveBuf_);
190  }
191  else
192  {
193  solveScalarField pnf
194  (
195  procInterface_.compressedReceive<solveScalar>
196  (
197  commsType,
198  this->size()
199  )()
200  );
201  transformCoupleField(pnf, cmpt);
202 
203  addToInternalField(result, !add, faceCells, coeffs, pnf);
204  }
205 
207  = true;
208 }
209 
210 
211 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::lduAddressing
The class contains the addressing required by the lduMatrix: upper, lower and losort.
Definition: lduAddressing.H:114
Foam::calculatedProcessorGAMGInterfaceField::updateInterfaceMatrix
virtual void updateInterfaceMatrix(solveScalarField &result, const bool add, const lduAddressing &lduAddr, const label patchId, const solveScalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Update result field based on interface functionality.
Definition: calculatedProcessorGAMGInterfaceField.C:146
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::calculatedProcessorGAMGInterfaceField::initInterfaceMatrixUpdate
virtual void initInterfaceMatrixUpdate(solveScalarField &result, const bool add, const lduAddressing &lduAddr, const label patchId, const solveScalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Initialise neighbour matrix update.
Definition: calculatedProcessorGAMGInterfaceField.C:92
lduMatrix.H
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
calculatedProcessorGAMGInterfaceField.H
Foam::Field< solveScalar >
Foam::GAMGInterface
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:54
Foam::GAMGInterfaceField
Abstract base class for GAMG agglomerated interface fields.
Definition: GAMGInterfaceField.H:54
Foam::lduInterfaceField::updatedMatrix
bool updatedMatrix() const
Whether matrix has been updated.
Definition: lduInterfaceField.H:119
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::lduInterfaceField
An abstract base class for implicitly-coupled interface fields e.g. processor and cyclic patch fields...
Definition: lduInterfaceField.H:58
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
Foam::calculatedProcessorGAMGInterfaceField
GAMG agglomerated processor interface field.
Definition: calculatedProcessorGAMGInterfaceField.H:52
Foam::UList< label >
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::lduAddressing::patchAddr
virtual const labelUList & patchAddr(const label patchNo) const =0
Return patch to internal addressing given patch number.
patchId
label patchId(-1)
Foam::processorLduInterfaceField
Abstract base class for processor coupled interfaces.
Definition: processorLduInterfaceField.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56