cyclicACMIFvPatchField.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) 2013-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::cyclicACMIFvPatchField
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 arbitrarily coupled mesh interface (ACMI) interpolation.
37 
38 Usage
39  Example of the boundary condition specification:
40  \verbatim
41  <patchName>
42  {
43  type cyclicACMI;
44  value <initial value>;
45  neighbourValue <initial value of neighbour patch cells>;
46  }
47  \endverbatim
48 
49 See also
50  Foam::AMIInterpolation
51 
52 SourceFiles
53  cyclicACMIFvPatchField.C
54 
55 \*---------------------------------------------------------------------------*/
56 
57 #ifndef Foam_cyclicACMIFvPatchField_H
58 #define Foam_cyclicACMIFvPatchField_H
59 
60 #include "coupledFvPatchField.H"
62 #include "cyclicACMIFvPatch.H"
63 
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 
66 namespace Foam
67 {
68 
69 /*---------------------------------------------------------------------------*\
70  Class cyclicACMIFvPatchField Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 template<class Type>
75 :
76  virtual public cyclicACMILduInterfaceField,
77  public coupledFvPatchField<Type>
78 {
79  // Private data
80 
81  //- Local reference cast into the cyclic patch
82  const cyclicACMIFvPatch& cyclicACMIPatch_;
83 
84 
85  // Sending and receiving (distributed AMI)
86 
87  //- Current range of send requests (non-blocking)
88  mutable labelRange sendRequests_;
89 
90  //- Current range of recv requests (non-blocking)
91  mutable labelRange recvRequests_;
92 
93  //- Send buffers
94  mutable PtrList<List<Type>> sendBufs_;
95 
96  //- Receive buffers_
97  mutable PtrList<List<Type>> recvBufs_;
98 
99  //- Scalar send buffers
100  mutable PtrList<List<solveScalar>> scalarSendBufs_;
101 
102  //- Scalar receive buffers
103  mutable PtrList<List<solveScalar>> scalarRecvBufs_;
104 
105  //- Neighbour coupled internal cell data
106  mutable autoPtr<Field<Type>> patchNeighbourFieldPtr_;
107 
108 
109  // Private Member Functions
110 
111  //- Return the AMI corresponding to the owner side
112  const AMIPatchToPatchInterpolation& ownerAMI() const
113  {
114  return
115  (
116  cyclicACMIPatch_.owner()
117  ? cyclicACMIPatch_.AMI()
118  : cyclicACMIPatch_.neighbPatch().AMI()
119  );
120  }
121 
122  //- All receive/send requests have completed
123  virtual bool all_ready() const;
124 
125  //- Use neighbour field caching
126  static bool cacheNeighbourField();
127 
128  //- Return neighbour coupled internal cell data
129  tmp<Field<Type>> getNeighbourField(const UList<Type>&) const;
130 
131  //- Return neighbour coupled internal cell data (cached or extracted),
132  //- with optional check that AMI.comm() is valid.
133  tmp<Field<Type>> getPatchNeighbourField(bool checkCommunicator) const;
134 
135  //- Return new matrix coeffs
136  tmp<Field<scalar>> coeffs
137  (
138  fvMatrix<Type>& matrix,
139  const Field<scalar>&,
140  const label
141  ) const;
142 
143 
144 public:
145 
146  //- Runtime type information
147  TypeName(cyclicACMIFvPatch::typeName_());
148 
149 
150  // Constructors
151 
152  //- Construct from patch and internal field
154  (
155  const fvPatch&,
157  );
158 
159  //- Construct from patch, internal field and dictionary
161  (
162  const fvPatch&,
164  const dictionary&
165  );
166 
167  //- Construct by mapping given cyclicACMIFvPatchField onto a new patch
169  (
171  const fvPatch&,
173  const fvPatchFieldMapper&
174  );
175 
176  //- Construct as copy
178 
179  //- Construct as copy setting internal field reference
181  (
184  );
185 
186  //- Return a clone
187  virtual tmp<fvPatchField<Type>> clone() const
188  {
189  return fvPatchField<Type>::Clone(*this);
190  }
191 
192  //- Clone with an internal field reference
194  (
196  ) const
197  {
198  return fvPatchField<Type>::Clone(*this, iF);
199  }
200 
201 
202  // Member functions
203 
204  // Access
205 
206  //- Return local reference cast into the cyclic AMI patch
207  const cyclicACMIFvPatch& cyclicACMIPatch() const
208  {
209  return cyclicACMIPatch_;
210  }
211 
212 
213  // Coupling
214 
215  //- Return true if coupled. Note that the underlying patch
216  // is not coupled() - the points don't align
217  virtual bool coupled() const;
218 
219  //- Are all (receive) data available?
220  virtual bool ready() const;
221 
222  //- Return true if this patch field fixes a value
223  // Needed to check if a level has to be specified while solving
224  // Poisson equations
225  virtual bool fixesValue() const
226  {
227  const scalarField& mask =
228  cyclicACMIPatch_.cyclicACMIPatch().mask();
229 
230  if (gMax(mask) > 1e-5)
231  {
232  // regions connected
233  return false;
234  }
235  else
236  {
237  // fully separated
238  return nonOverlapPatchField().fixesValue();
239  }
240  }
241 
242  //- Return neighbour coupled internal cell data
243  virtual tmp<Field<Type>> patchNeighbourField() const;
244 
245  //- Retrieve neighbour coupled internal cell data
246  virtual void patchNeighbourField(UList<Type>& pnf) const;
247 
248  //- Return reference to neighbour patchField
250 
251  //- Return reference to non-overlapping patchField
253 
254 
255  // Evaluation
256 
257  //- Initialise the evaluation of the patch field
258  virtual void initEvaluate(const Pstream::commsTypes commsType);
259 
260  //- Evaluate the patch field
261  virtual void evaluate(const Pstream::commsTypes commsType);
262 
263 
264  // Coupled interface functionality
265 
266  //- Initialise neighbour matrix update
267  virtual void initInterfaceMatrixUpdate
268  (
269  solveScalarField& result,
270  const bool add,
271  const lduAddressing& lduAddr,
272  const label patchId,
273  const solveScalarField& psiInternal,
274  const scalarField& coeffs,
275  const direction cmpt,
276  const Pstream::commsTypes commsType
277  ) const;
278 
279  //- Update result field based on interface functionality
280  virtual void updateInterfaceMatrix
281  (
282  solveScalarField& result,
283  const bool add,
284  const lduAddressing& lduAddr,
285  const label patchId,
286  const solveScalarField& psiInternal,
287  const scalarField& coeffs,
288  const direction cmpt,
289  const Pstream::commsTypes commsType
290  ) const;
291 
292  //- Initialise neighbour matrix update
293  virtual void initInterfaceMatrixUpdate
294  (
295  Field<Type>& result,
296  const bool add,
297  const lduAddressing& lduAddr,
298  const label patchId,
299  const Field<Type>& psiInternal,
300  const scalarField& coeffs,
301  const Pstream::commsTypes commsType
302  ) const;
303 
304  //- Update result field based on interface functionality
305  virtual void updateInterfaceMatrix
306  (
307  Field<Type>&,
308  const bool add,
309  const lduAddressing& lduAddr,
310  const label patchId,
311  const Field<Type>&,
312  const scalarField&,
313  const Pstream::commsTypes commsType
314  ) const;
315 
316  //- Manipulate matrix
317  virtual void manipulateMatrix(fvMatrix<Type>& matrix);
318 
319  //- Manipulate matrix
320  virtual void manipulateMatrix
321  (
322  fvMatrix<Type>& m,
323  const label iMatrix,
324  const direction cmpt
325  );
326 
327  //- Update the coefficients associated with the patch field
328  virtual void updateCoeffs();
329 
330 
331  // Cyclic AMI coupled interface functions
332 
333  //- Does the patch field perform the transformation
334  virtual bool doTransform() const
335  {
336  return (pTraits<Type>::rank && !cyclicACMIPatch_.parallel());
337  }
338 
339  //- Return face transformation tensor
340  virtual const tensorField& forwardT() const
341  {
342  return cyclicACMIPatch_.forwardT();
343  }
344 
345  //- Return neighbour-cell transformation tensor
346  virtual const tensorField& reverseT() const
347  {
348  return cyclicACMIPatch_.reverseT();
349  }
350 
351  //- Return rank of component for transform
352  virtual int rank() const
353  {
354  return pTraits<Type>::rank;
355  }
356 
357 
358  // I-O
359 
360  //- Write
361  virtual void write(Ostream& os) const;
362 };
363 
364 
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 
367 } // End namespace Foam
368 
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
370 
371 #ifdef NoRepository
372  #include "cyclicACMIFvPatchField.C"
373 #endif
374 
375 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376 
377 #endif
378 
379 // ************************************************************************* //
label patchId(-1)
virtual void evaluate(const Pstream::commsTypes commsType)
Evaluate the patch field.
virtual int rank() const
Return rank of component for transform.
uint8_t direction
Definition: direction.H:46
TypeName(cyclicACMIFvPatch::typeName_())
Runtime type information.
const fvPatchField< Type > & nonOverlapPatchField() const
Return reference to non-overlapping patchField.
commsTypes
Communications types.
Definition: UPstream.H:77
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 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.
virtual bool owner() const
virtual tmp< Field< Type > > patchNeighbourField() const
Return neighbour coupled internal cell data.
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:52
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
const cyclicACMIFvPatch & cyclicACMIPatch() const
Return local reference cast into the cyclic AMI patch.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
virtual tmp< fvPatchField< Type > > clone() const
Return a clone.
This boundary condition enforces a cyclic condition between a pair of boundaries, whereby communicati...
virtual bool coupled() const
Return true if coupled. Note that the underlying patch.
virtual bool fixesValue() const
Return true if this patch field fixes a value.
virtual const tensorField & reverseT() const
Return neighbour-cell transformation tensor.
static tmp< fvPatchField< Type > > Clone(const DerivedPatchField &pf, Args &&... args)
Clone a patch field, optionally with internal field reference etc.
Definition: fvPatchField.H:607
virtual bool doTransform() const
Does the patch field perform the transformation.
Cyclic patch for Arbitrarily Coupled Mesh Interface (ACMI)
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
virtual bool ready() const
Are all (receive) data available?
virtual void write(Ostream &os) const
Write.
virtual const cyclicACMIFvPatch & neighbPatch() const
Return neighbour fvPatch.
A FieldMapper for finite-volume patch fields.
virtual const tensorField & forwardT() const
Return face 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
virtual bool parallel() const
Are the cyclic planes parallel.
const cyclicACMIFvPatchField< Type > & neighbourPatchField() const
Return reference to neighbour patchField.
cyclicACMIFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Abstract base class for coupled patches.
Abstract base class for cyclic ACMI coupled interfaces.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Type gMax(const FieldField< Field, Type > &f)
OBJstream os(runTime.globalPath()/outputName)
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.
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
const scalarField & mask() const
Mask field where 1 = overlap(coupled), 0 = no-overlap.
virtual void initEvaluate(const Pstream::commsTypes commsType)
Initialise the evaluation of the patch field.
const cyclicACMIPolyPatch & cyclicACMIPatch() const
Return local reference cast into the cyclic patch.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:54
virtual const tensorField & forwardT() const
Return face transformation tensor.
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...
virtual void manipulateMatrix(fvMatrix< Type > &matrix)
Manipulate matrix.
::Foam::direction rank(const expressions::valueTypeCode) noexcept
The vector-space rank associated with given valueTypeCode.
Definition: exprTraits.C:70
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.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
virtual const tensorField & reverseT() const
Return neighbour-cell transformation tensor.
Namespace for OpenFOAM.