cyclicAMIFvPatchField.H
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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2025 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::cyclicAMIFvPatchField
29 
30 Group
31  grpCoupledBoundaryConditions
32 
33 Description
34  This boundary condition enforces a cyclic condition between a pair of
35  boundaries, whereby communication between the patches is performed using
36  an arbitrary mesh interface (AMI) interpolation.
37 
38 Usage
39  Example of the boundary condition specification:
40  \verbatim
41  <patchName>
42  {
43  type cyclicAMI;
44  value <initial value>;
45  neighbourValue <initial value of neighbour patch cells>;
46  }
47  \endverbatim
48 
49 Note
50  The outer boundary of the patch pairs must be similar, i.e. if the owner
51  patch is transformed to the neighbour patch, the outer perimeter of each
52  patch should be identical (or very similar).
53 
54  The \c neighbourValue is only needed when running distributed,
55  i.e. the neighbour cells are on a different processor from the owner cells.
56  It guarantees consistent restart e.g. when doing a snGrad and avoids
57  additional communication.
58 
59 See also
60  Foam::AMIInterpolation
61  Foam::processorFvPatchField
62 
63 SourceFiles
64  cyclicAMIFvPatchField.C
65 
66 \*---------------------------------------------------------------------------*/
67 
68 #ifndef Foam_cyclicAMIFvPatchField_H
69 #define Foam_cyclicAMIFvPatchField_H
70 
71 #include "cyclicAMIFvPatch.H"
72 #include "coupledFvPatchField.H"
74 
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 
77 namespace Foam
78 {
79 
80 /*---------------------------------------------------------------------------*\
81  Class cyclicAMIFvPatchField Declaration
82 \*---------------------------------------------------------------------------*/
83 
84 template<class Type>
86 :
87  virtual public cyclicAMILduInterfaceField,
88  public coupledFvPatchField<Type>
89 {
90  // Private Data
91 
92  //- Local reference cast into the cyclic patch
93  const cyclicAMIFvPatch& cyclicAMIPatch_;
94 
95 
96  // Sending and receiving (distributed AMI)
97 
98  //- Current range of send requests (non-blocking)
99  mutable labelRange sendRequests_;
100 
101  //- Current range of recv requests (non-blocking)
102  mutable labelRange recvRequests_;
103 
104  //- Send buffers
105  mutable PtrList<List<Type>> sendBufs_;
106 
107  //- Receive buffers_
108  mutable PtrList<List<Type>> recvBufs_;
109 
110  //- Scalar send buffers
111  mutable PtrList<List<solveScalar>> scalarSendBufs_;
112 
113  //- Scalar receive buffers
114  mutable PtrList<List<solveScalar>> scalarRecvBufs_;
115 
116  //- Neighbour coupled internal cell data
117  mutable autoPtr<Field<Type>> patchNeighbourFieldPtr_;
118 
119 
120  // Private Member Functions
121 
122  //- Return the AMI corresponding to the owner side
123  const AMIPatchToPatchInterpolation& ownerAMI() const
124  {
125  return
126  (
127  cyclicAMIPatch_.owner()
128  ? cyclicAMIPatch_.AMI()
129  : cyclicAMIPatch_.neighbPatch().AMI()
130  );
131  }
132 
133  //- All receive/send requests have completed
134  virtual bool all_ready() const;
135 
136  //- Use neighbour field caching
137  static bool cacheNeighbourField();
138 
139  //- Return neighbour coupled internal cell data
140  tmp<Field<Type>> getNeighbourField(const UList<Type>&) const;
141 
142  //- Return neighbour coupled internal cell data (cached or extracted),
143  //- with optional check that AMI.comm() is valid.
144  tmp<Field<Type>> getPatchNeighbourField(bool checkCommunicator) const;
145 
146  //- Return new matrix coeffs
147  tmp<Field<scalar>> coeffs
148  (
149  fvMatrix<Type>& matrix,
150  const Field<scalar>&,
151  const label
152  ) const;
153 
154  template<class Type2>
155  void collectStencilData
156  (
157  const refPtr<mapDistribute>& mapPtr,
158  const labelListList& stencil,
159  const Type2& data,
160  List<Type2>& expandedData
161  );
162 
163 
164 public:
165 
166  //- Runtime type information
167  TypeName(cyclicAMIFvPatch::typeName_());
168 
169 
170  // Constructors
171 
172  //- Construct from patch and internal field
174  (
175  const fvPatch&,
177  );
178 
179  //- Construct from patch, internal field and dictionary
181  (
182  const fvPatch&,
184  const dictionary&
185  );
186 
187  //- Construct by mapping given cyclicAMIFvPatchField onto a new patch
189  (
191  const fvPatch&,
193  const fvPatchFieldMapper&
194  );
195 
196  //- Construct as copy
198 
199  //- Construct as copy setting internal field reference
201  (
204  );
205 
206  //- Return a clone
207  virtual tmp<fvPatchField<Type>> clone() const
208  {
209  return fvPatchField<Type>::Clone(*this);
210  }
211 
212  //- Clone with an internal field reference
214  (
216  ) const
217  {
218  return fvPatchField<Type>::Clone(*this, iF);
219  }
220 
221 
222  // Member Functions
223 
224  //- Return local reference cast into the cyclic AMI patch
226  {
227  return cyclicAMIPatch_;
228  }
229 
230 
231  // Coupling
232 
233  //- Return true if coupled. Note that the underlying patch
234  // is not coupled() - the points don't align.
235  virtual bool coupled() const { return cyclicAMIPatch_.coupled(); }
236 
237  //- Are all (receive) data available?
238  virtual bool ready() const;
239 
240  //- Return neighbour coupled internal cell data
241  virtual tmp<Field<Type>> patchNeighbourField() const;
242 
243  //- Retrieve neighbour coupled internal cell data
244  virtual void patchNeighbourField(UList<Type>& pnf) const;
245 
246  //- Return reference to neighbour patchField
248 
249 
250  // Mapping Functions
251 
252  //- Map (and resize as needed) from self given a mapping object
253  virtual void autoMap
254  (
255  const fvPatchFieldMapper&
256  );
257 
258  //- Reverse map the given fvPatchField onto this fvPatchField
259  virtual void rmap
260  (
261  const fvPatchField<Type>&,
262  const labelList&
263  );
264 
265 
266  // Evaluation
267 
268  //- Initialise the evaluation of the patch field
269  virtual void initEvaluate(const Pstream::commsTypes commsType);
270 
271  //- Evaluate the patch field
272  virtual void evaluate(const Pstream::commsTypes commsType);
273 
274 
275  // Coupled interface functionality
276 
277  //- Initialise neighbour matrix update
278  virtual void initInterfaceMatrixUpdate
279  (
280  solveScalarField& result,
281  const bool add,
282  const lduAddressing& lduAddr,
283  const label patchId,
284  const solveScalarField& psiInternal,
285  const scalarField& coeffs,
286  const direction cmpt,
287  const Pstream::commsTypes commsType
288  ) const;
289 
290  //- Update result field based on interface functionality
291  virtual void updateInterfaceMatrix
292  (
293  solveScalarField& result,
294  const bool add,
295  const lduAddressing& lduAddr,
296  const label patchId,
297  const solveScalarField& psiInternal,
298  const scalarField& coeffs,
299  const direction cmpt,
300  const Pstream::commsTypes commsType
301  ) const;
302 
303  //- Initialise neighbour matrix update
304  virtual void initInterfaceMatrixUpdate
305  (
306  Field<Type>& result,
307  const bool add,
308  const lduAddressing& lduAddr,
309  const label patchId,
310  const Field<Type>& psiInternal,
311  const scalarField& coeffs,
312  const Pstream::commsTypes commsType
313  ) const;
314 
315  //- Update result field based on interface functionality
316  virtual void updateInterfaceMatrix
317  (
318  Field<Type>&,
319  const bool add,
320  const lduAddressing& lduAddr,
321  const label patchId,
322  const Field<Type>&,
323  const scalarField&,
324  const Pstream::commsTypes commsType
325  ) const;
326 
327 
328  //- Manipulate matrix
329  virtual void manipulateMatrix
330  (
331  fvMatrix<Type>& m,
332  const label iMatrix,
333  const direction cmpt
334  );
335 
336 
337  // Coupled interface functions
338 
339  //- Does the patch field perform the transformation
340  virtual bool doTransform() const
341  {
342  return (pTraits<Type>::rank && !cyclicAMIPatch_.parallel());
343  }
344 
345  //- Return face transformation tensor
346  virtual const tensorField& forwardT() const
347  {
348  return cyclicAMIPatch_.forwardT();
349  }
350 
351  //- Return neighbour-cell transformation tensor
352  virtual const tensorField& reverseT() const
353  {
354  return cyclicAMIPatch_.reverseT();
355  }
356 
357  //- Return rank of component for transform
358  virtual int rank() const
359  {
360  return pTraits<Type>::rank;
361  }
362 
363 
364  // I-O
365 
366  //- Write
367  virtual void write(Ostream& os) const;
368 
369 
370  // Member Operators
371 
372  virtual void operator=(const fvPatchField<Type>&);
373  virtual void operator==(const fvPatchField<Type>&);
374 };
375 
376 
377 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
378 
379 } // End namespace Foam
380 
381 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
382 
383 #ifdef NoRepository
384  #include "cyclicAMIFvPatchField.C"
385 #endif
386 
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 
389 #endif
390 
391 // ************************************************************************* //
label patchId(-1)
virtual bool coupled() const
Return true if coupled. Note that the underlying patch.
virtual void operator==(const fvPatchField< Type > &)
uint8_t direction
Definition: direction.H:46
TypeName(cyclicAMIFvPatch::typeName_())
Runtime type information.
virtual bool ready() const
Are all (receive) data available?
commsTypes
Communications types.
Definition: UPstream.H:77
virtual bool parallel() const
Are the cyclic planes parallel.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
void checkCommunicator(int comm, int rank)
Fatal if communicator is outside the allocated range.
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.
virtual void manipulateMatrix(fvMatrix< Type > &m, const label iMatrix, const direction cmpt)
Manipulate matrix.
Cyclic patch for Arbitrary Mesh Interface (AMI)
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:52
virtual tmp< fvPatchField< Type > > clone() const
Return a clone.
Type * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:265
virtual const tensorField & forwardT() const
Return face transformation tensor.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:61
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
virtual void initEvaluate(const Pstream::commsTypes commsType)
Initialise the evaluation of the patch field.
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
virtual bool doTransform() const
Does the patch field perform the transformation.
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.
static tmp< fvPatchField< Type > > Clone(const DerivedPatchField &pf, Args &&... args)
Clone a patch field, optionally with internal field reference etc.
Definition: fvPatchField.H:607
Abstract base class for cyclic AMI coupled interfaces.
virtual void write(Ostream &os) const
Write.
virtual void evaluate(const Pstream::commsTypes commsType)
Evaluate the patch field.
A FieldMapper for finite-volume patch fields.
virtual const tensorField & reverseT() const
Return neighbour-cell transformation tensor.
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:64
const cyclicAMIFvPatch & cyclicAMIPatch() const noexcept
Return local reference cast into the cyclic AMI patch.
Abstract base class for coupled patches.
virtual tmp< Field< Type > > patchNeighbourField() const
Return neighbour coupled internal cell data.
virtual int rank() const
Return rank of component for transform.
const direction noexcept
Definition: scalarImpl.H:255
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
OBJstream os(runTime.globalPath()/outputName)
virtual void operator=(const fvPatchField< Type > &)
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
virtual bool owner() const
Does this side own the patch?
virtual const cyclicAMIFvPatch & neighbPatch() const
Return a reference to the neighbour patch.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:54
virtual bool coupled() const
Return true if this patch is coupled. This is equivalent to the coupledPolyPatch::coupled() if parall...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
::Foam::direction rank(const expressions::valueTypeCode) noexcept
The vector-space rank associated with given valueTypeCode.
Definition: exprTraits.C:70
const cyclicAMIFvPatchField< Type > & neighbourPatchField() const
Return reference to neighbour patchField.
virtual const AMIPatchToPatchInterpolation & AMI() const
Return a reference to the AMI interpolator.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
The class contains the addressing required by the lduMatrix: upper, lower and losort.
cyclicAMIFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
virtual const tensorField & forwardT() const
Return face transformation tensor.
virtual const tensorField & reverseT() const
Return neighbour-cell transformation tensor.
This boundary condition enforces a cyclic condition between a pair of boundaries, whereby communicati...
Namespace for OpenFOAM.