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-2023 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
141 
142  //- Return neighbour side field given internal fields
143  template<class Type2>
144  tmp<Field<Type2>> neighbourSideField
145  (
146  const Field<Type2>&
147  ) const;
148 
149 
150  //- Return new matrix coeffs
151  tmp<Field<scalar>> coeffs
152  (
153  fvMatrix<Type>& matrix,
154  const Field<scalar>&,
155  const label
156  ) const;
157 
158  template<class Type2>
159  void collectStencilData
160  (
161  const refPtr<mapDistribute>& mapPtr,
162  const labelListList& stencil,
163  const Type2& data,
164  List<Type2>& expandedData
165  );
166 
167 
168 public:
169 
170  //- Runtime type information
171  TypeName(cyclicAMIFvPatch::typeName_());
172 
173 
174  // Constructors
175 
176  //- Construct from patch and internal field
178  (
179  const fvPatch&,
181  );
182 
183  //- Construct from patch, internal field and dictionary
185  (
186  const fvPatch&,
188  const dictionary&
189  );
190 
191  //- Construct by mapping given cyclicAMIFvPatchField onto a new patch
193  (
195  const fvPatch&,
197  const fvPatchFieldMapper&
198  );
199 
200  //- Construct as copy
202 
203  //- Construct as copy setting internal field reference
205  (
208  );
209 
210  //- Return a clone
211  virtual tmp<fvPatchField<Type>> clone() const
212  {
213  return fvPatchField<Type>::Clone(*this);
214  }
215 
216  //- Clone with an internal field reference
218  (
220  ) const
221  {
222  return fvPatchField<Type>::Clone(*this, iF);
223  }
224 
225 
226  // Member Functions
227 
228  //- Return local reference cast into the cyclic AMI patch
230  {
231  return cyclicAMIPatch_;
232  }
233 
234 
235  // Coupling
236 
237  //- Return true if coupled. Note that the underlying patch
238  // is not coupled() - the points don't align.
239  virtual bool coupled() const { return cyclicAMIPatch_.coupled(); }
240 
241  //- Are all (receive) data available?
242  virtual bool ready() const;
243 
244  //- Return neighbour coupled internal cell data
245  virtual tmp<Field<Type>> patchNeighbourField() const;
246 
247  //- Return reference to neighbour patchField
249 
250 
251  // Mapping Functions
252 
253  //- Map (and resize as needed) from self given a mapping object
254  virtual void autoMap
255  (
256  const fvPatchFieldMapper&
257  );
258 
259  //- Reverse map the given fvPatchField onto this fvPatchField
260  virtual void rmap
261  (
262  const fvPatchField<Type>&,
263  const labelList&
264  );
265 
266 
267  // Evaluation
268 
269  //- Initialise the evaluation of the patch field
270  virtual void initEvaluate(const Pstream::commsTypes commsType);
271 
272  //- Evaluate the patch field
273  virtual void evaluate(const Pstream::commsTypes commsType);
274 
275 
276  // Coupled interface functionality
277 
278  //- Initialise neighbour matrix update
279  virtual void initInterfaceMatrixUpdate
280  (
281  solveScalarField& result,
282  const bool add,
283  const lduAddressing& lduAddr,
284  const label patchId,
285  const solveScalarField& psiInternal,
286  const scalarField& coeffs,
287  const direction cmpt,
288  const Pstream::commsTypes commsType
289  ) const;
290 
291  //- Update result field based on interface functionality
292  virtual void updateInterfaceMatrix
293  (
294  solveScalarField& result,
295  const bool add,
296  const lduAddressing& lduAddr,
297  const label patchId,
298  const solveScalarField& psiInternal,
299  const scalarField& coeffs,
300  const direction cmpt,
301  const Pstream::commsTypes commsType
302  ) const;
303 
304  //- Initialise neighbour matrix update
305  virtual void initInterfaceMatrixUpdate
306  (
307  Field<Type>& result,
308  const bool add,
309  const lduAddressing& lduAddr,
310  const label patchId,
311  const Field<Type>& psiInternal,
312  const scalarField& coeffs,
313  const Pstream::commsTypes commsType
314  ) const;
315 
316  //- Update result field based on interface functionality
317  virtual void updateInterfaceMatrix
318  (
319  Field<Type>&,
320  const bool add,
321  const lduAddressing& lduAddr,
322  const label patchId,
323  const Field<Type>&,
324  const scalarField&,
325  const Pstream::commsTypes commsType
326  ) const;
327 
328 
329  //- Manipulate matrix
330  virtual void manipulateMatrix
331  (
332  fvMatrix<Type>& m,
333  const label iMatrix,
334  const direction cmpt
335  );
336 
337 
338  // Coupled interface functions
339 
340  //- Does the patch field perform the transformation
341  virtual bool doTransform() const
342  {
343  return (pTraits<Type>::rank && !cyclicAMIPatch_.parallel());
344  }
345 
346  //- Return face transformation tensor
347  virtual const tensorField& forwardT() const
348  {
349  return cyclicAMIPatch_.forwardT();
350  }
351 
352  //- Return neighbour-cell transformation tensor
353  virtual const tensorField& reverseT() const
354  {
355  return cyclicAMIPatch_.reverseT();
356  }
357 
358  //- Return rank of component for transform
359  virtual int rank() const
360  {
361  return pTraits<Type>::rank;
362  }
363 
364 
365  // I-O
366 
367  //- Write
368  virtual void write(Ostream& os) const;
369 
370 
371  // Member Operators
372 
373  virtual void operator=(const fvPatchField<Type>&);
374  virtual void operator==(const fvPatchField<Type>&);
375 };
376 
377 
378 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
379 
380 } // End namespace Foam
381 
382 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
383 
384 #ifdef NoRepository
385  #include "cyclicAMIFvPatchField.C"
386 #endif
387 
388 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
389 
390 #endif
391 
392 // ************************************************************************* //
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
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:75
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:597
Abstract base class for cyclic AMI coupled interfaces.
Generic templated field type.
Definition: Field.H:62
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: Scalar.H:258
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:55
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.