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 and return a clone
204  virtual tmp<fvPatchField<Type>> clone() const
205  {
206  return tmp<fvPatchField<Type>>
207  (
208  new cyclicAMIFvPatchField<Type>(*this)
209  );
210  }
211 
212  //- Construct as copy setting internal field reference
214  (
217  );
218 
219  //- Construct and return a clone setting internal field reference
221  (
223  ) const
224  {
225  return tmp<fvPatchField<Type>>
226  (
227  new cyclicAMIFvPatchField<Type>(*this, iF)
228  );
229  }
230 
231 
232  // Member Functions
233 
234  //- Return local reference cast into the cyclic AMI patch
236  {
237  return cyclicAMIPatch_;
238  }
240 
241  // Coupling
242 
243  //- Return true if coupled. Note that the underlying patch
244  // is not coupled() - the points don't align.
245  virtual bool coupled() const { return cyclicAMIPatch_.coupled(); }
246 
247  //- Are all (receive) data available?
248  virtual bool ready() const;
249 
250  //- Return neighbour coupled internal cell data
251  virtual tmp<Field<Type>> patchNeighbourField() const;
252 
253  //- Return reference to neighbour patchField
255 
256 
257  // Mapping Functions
258 
259  //- Map (and resize as needed) from self given a mapping object
260  virtual void autoMap
261  (
262  const fvPatchFieldMapper&
263  );
264 
265  //- Reverse map the given fvPatchField onto this fvPatchField
266  virtual void rmap
267  (
268  const fvPatchField<Type>&,
269  const labelList&
270  );
271 
272 
273  // Evaluation
274 
275  //- Initialise the evaluation of the patch field
276  virtual void initEvaluate(const Pstream::commsTypes commsType);
277 
278  //- Evaluate the patch field
279  virtual void evaluate(const Pstream::commsTypes commsType);
280 
281 
282  // Coupled interface functionality
283 
284  //- Initialise neighbour matrix update
285  virtual void initInterfaceMatrixUpdate
286  (
287  solveScalarField& result,
288  const bool add,
289  const lduAddressing& lduAddr,
290  const label patchId,
291  const solveScalarField& psiInternal,
292  const scalarField& coeffs,
293  const direction cmpt,
294  const Pstream::commsTypes commsType
295  ) const;
296 
297  //- Update result field based on interface functionality
298  virtual void updateInterfaceMatrix
299  (
300  solveScalarField& result,
301  const bool add,
302  const lduAddressing& lduAddr,
303  const label patchId,
304  const solveScalarField& psiInternal,
305  const scalarField& coeffs,
306  const direction cmpt,
307  const Pstream::commsTypes commsType
308  ) const;
309 
310  //- Initialise neighbour matrix update
311  virtual void initInterfaceMatrixUpdate
312  (
313  Field<Type>& result,
314  const bool add,
315  const lduAddressing& lduAddr,
316  const label patchId,
317  const Field<Type>& psiInternal,
318  const scalarField& coeffs,
319  const Pstream::commsTypes commsType
320  ) const;
321 
322  //- Update result field based on interface functionality
323  virtual void updateInterfaceMatrix
324  (
325  Field<Type>&,
326  const bool add,
327  const lduAddressing& lduAddr,
328  const label patchId,
329  const Field<Type>&,
330  const scalarField&,
331  const Pstream::commsTypes commsType
332  ) const;
333 
334 
335  //- Manipulate matrix
336  virtual void manipulateMatrix
337  (
338  fvMatrix<Type>& m,
339  const label iMatrix,
340  const direction cmpt
341  );
342 
343 
344  // Coupled interface functions
345 
346  //- Does the patch field perform the transformation
347  virtual bool doTransform() const
348  {
349  return (pTraits<Type>::rank && !cyclicAMIPatch_.parallel());
350  }
351 
352  //- Return face transformation tensor
353  virtual const tensorField& forwardT() const
354  {
355  return cyclicAMIPatch_.forwardT();
356  }
357 
358  //- Return neighbour-cell transformation tensor
359  virtual const tensorField& reverseT() const
360  {
361  return cyclicAMIPatch_.reverseT();
362  }
363 
364  //- Return rank of component for transform
365  virtual int rank() const
366  {
367  return pTraits<Type>::rank;
368  }
369 
370 
371  // I-O
372 
373  //- Write
374  virtual void write(Ostream& os) const;
375 
376 
377  // Member Operators
378 
379  virtual void operator=(const fvPatchField<Type>&);
380  virtual void operator==(const fvPatchField<Type>&);
381 };
382 
383 
384 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
385 
386 } // End namespace Foam
387 
388 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
389 
390 #ifdef NoRepository
391  #include "cyclicAMIFvPatchField.C"
392 #endif
393 
394 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
395 
396 #endif
397 
398 // ************************************************************************* //
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:72
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
Construct and return a clone.
Type * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:272
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.
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...
Definition: areaFieldsFwd.H:42
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.