cyclicRepeatAMIPolyPatch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2018-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 #include "SubField.H"
28 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(cyclicRepeatAMIPolyPatch, 0);
36 
37  addToRunTimeSelectionTable(polyPatch, cyclicRepeatAMIPolyPatch, word);
38  addToRunTimeSelectionTable(polyPatch, cyclicRepeatAMIPolyPatch, dictionary);
39 }
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 template <class Type>
48 {
49  public:
50 
51  Tuple2<bool, Type> operator()
52  (
53  const Tuple2<bool, Type>& x,
54  const Tuple2<bool, Type>& y
55  ) const
56  {
57  if (x.first())
58  {
59  return x;
60  }
61  else if (y.first())
62  {
63  return y;
64  }
65  else
66  {
67  return Tuple2<bool, Type>(false, Type());
68  }
69  }
70 };
71 
72 }
73 
74 
75 // * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
76 
78 {
79  if (!owner())
80  {
81  return;
82  }
83 
84  Info<< indent << typeName <<" : Creating addressing and weights between "
85  << returnReduce(this->size(), sumOp<label>()) << " source faces and "
86  << returnReduce(nbrPatch().size(), sumOp<label>()) << " target faces"
87  << endl;
88 
89  // Get the transform associated with the transform patch
90  transformer t;
91  {
92  const coupledPolyPatch& transformPatch = this->transformPatch();
93 
94  if (transformPatch.name() != nbrPatch().transformPatch().name())
95  {
97  << "Transform patch " << transformPatch.name() << " for "
98  << typeName << " patch " << name() << " is not the same as for "
99  << "the neighbour patch " << nbrPatch().name() << ". "
100  << "This is not allowed." << exit(FatalError);
101  }
102 
104  (
105  transformPatch.size(),
106  transformPatch.transform()
107  );
108 
110 
111  if (!bt.first())
112  {
114  << "Transform patch " << transformPatch.name() << " for "
115  << typeName << " patch " << name() << " has zero faces. It may "
116  << "have been converted to a processor cyclic during "
117  << "decomposition. Consider adding " << transformPatch.name()
118  << " and it's neighbour to the list of preserved patches."
119  << exit(FatalError);
120  }
121 
122  t = bt.second();
123  }
124  const transformer tInv(inv(t));
125 
126  // Work out the number of repetitions of the transform that separate this
127  // patch from its neighbour
128  label n = 0;
129  {
130  const scalarField thisMagAreas(this->magFaceAreas());
131  const scalarField nbrMagAreas(nbrPatch().magFaceAreas());
132 
133  vector thisCentre =
134  gSum(this->faceCentres()*thisMagAreas)/gSum(thisMagAreas);
135  vector nbrCentre =
136  gSum(nbrPatch().faceCentres()*nbrMagAreas)/gSum(nbrMagAreas);
137 
138  scalar dLeft = mag(t.transformPosition(thisCentre) - nbrCentre);
139  scalar d = mag(thisCentre - nbrCentre);
140  scalar dRight = mag(tInv.transformPosition(thisCentre) - nbrCentre);
141 
142  while (dLeft < d)
143  {
144  thisCentre = t.transformPosition(thisCentre);
145 
146  dRight = d;
147  d = dLeft;
148  dLeft = mag(t.transformPosition(thisCentre) - nbrCentre);
149 
150  ++ n;
151  }
152 
153  while (dRight < d)
154  {
155  thisCentre = tInv.transformPosition(thisCentre);
156 
157  dLeft = d;
158  d = dRight;
159  dRight = mag(tInv.transformPosition(thisCentre) - nbrCentre);
160 
161  -- n;
162  }
163  }
164 
165  // Generate the full transformations
166  transformer TLeft(t), T(transformer::I), TRight(tInv);
167  if (n > 0)
168  {
169  for (label i = 0; i < n - 1; ++ i)
170  {
171  T = t & T;
172  }
173 
174  TLeft = T;
175  T = t & T;
176  TRight = t & T;
177  }
178  if (n < 0)
179  {
180  for (label i = 0; i > n + 1; -- i)
181  {
182  T = tInv & T;
183  }
184 
185  TRight = T;
186  T = tInv & T;
187  TLeft = tInv & T;
188  }
189 
190  // Create copies of this patch and the neighbour patch's points
191  pointField thisPoints(localPoints());
192  const pointField nbrPoints(nbrPatch().localPoints());
193 
194  // Create primitive patches
195  primitivePatch thisPatch
196  (
197  SubList<face>(localFaces(), size()),
198  thisPoints
199  );
200  primitivePatch nbrPatch
201  (
202  SubList<face>(this->nbrPatch().localFaces(), this->nbrPatch().size()),
203  nbrPoints
204  );
205 
206  // Do the three bounding AMI interpolations
207  thisPoints = TLeft.transformPosition(localPoints());
208  thisPatch.movePoints(thisPoints);
209  autoPtr<AMIInterpolation> AMILeftPtr
210  (
211  new AMIInterpolation
212  (
213  thisPatch,
214  nbrPatch,
216  false,
218  AMILowWeightCorrection_,
219  AMIReverse_,
220  false
221  )
222  );
223  const scalar sLeft =
224  gSum(AMILeftPtr->srcWeightsSum()*AMILeftPtr->srcMagSf())
225  /gSum(AMILeftPtr->srcMagSf());
226 
227  thisPoints = T.transformPosition(localPoints());
228  thisPatch.movePoints(thisPoints);
230  (
231  new AMIInterpolation
232  (
233  thisPatch,
234  nbrPatch,
236  false,
238  AMILowWeightCorrection_,
239  AMIReverse_,
240  false
241  )
242  );
243  const scalar s =
244  gSum(AMIPtr->srcWeightsSum()*AMIPtr->srcMagSf())
245  /gSum(AMIPtr->srcMagSf());
246 
247  thisPoints = TRight.transformPosition(localPoints());
248  thisPatch.movePoints(thisPoints);
249  autoPtr<AMIInterpolation> AMIRightPtr
250  (
251  new AMIInterpolation
252  (
253  thisPatch,
254  nbrPatch,
256  false,
258  AMILowWeightCorrection_,
259  AMIReverse_,
260  false
261  )
262  );
263  const scalar sRight =
264  gSum(AMIRightPtr->srcWeightsSum()*AMIRightPtr->srcMagSf())
265  /gSum(AMIRightPtr->srcMagSf());
266 
267  Info<< typeName << ": number of transforms = " << n << endl
268  << typeName << ": left/centre/right sum(weights) = "
269  << sLeft << ", " << s << ", " << sRight << endl;
270 
271  // Set the AMI interpolators and transforms using the centre and the most
272  // overlapping of the left and right sides
273  AMIs_.resize(2);
274  AMIs_.set(0, sLeft > sRight ? AMILeftPtr.ptr() : AMIPtr.ptr());
275  AMIs_.set(1, sLeft > sRight ? AMIPtr.ptr() : AMIRightPtr.ptr());
276 
277  AMITransforms_.resize(2);
278  AMITransforms_[0] = sLeft > sRight ? TLeft : T;
279  AMITransforms_[1] = sLeft > sRight ? T : TRight;
280 
281  // Sum and normalise the two AMI interpolators
282  AMIInterpolation::sumWeights(AMIs_);
283  AMIInterpolation::reportSumWeights(AMIs_[0]);
284  AMIInterpolation::normaliseWeights(AMIs_);
285 }
286 
287 
289 {
290  static_cast<cyclicTransform&>(*this) =
292  (
293  name(),
294  faceAreas(),
295  *this,
296  nbrPatchName(),
297  nbrPatch(),
298  matchTolerance()
299  );
300 }
301 
302 
303 // * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * //
304 
306 (
307  const word& name,
308  const label size,
309  const label start,
310  const label index,
311  const polyBoundaryMesh& bm,
312  const word& patchType
313 )
314 :
316  (
317  name,
318  size,
319  start,
320  index,
321  bm,
322  patchType,
323  false,
325  ),
326  transformPatchName_(word::null),
327  transformPatchID_(-1)
328 {
329  // Transform patch might not be valid yet so cannot determine
330  // associated patchID
331 }
332 
333 
335 (
336  const word& name,
337  const dictionary& dict,
338  const label index,
339  const polyBoundaryMesh& bm,
340  const word& patchType
341 )
342 :
344  (
345  name,
346  dict,
347  index,
348  bm,
349  patchType,
350  false,
352  ),
353  transformPatchName_(dict.lookup("transformPatch")),
354  transformPatchID_(-1)
355 {
356  // Transform patch might not be valid yet so cannot determine
357  // associated patchID
358 }
359 
360 
362 (
363  const cyclicRepeatAMIPolyPatch& pp,
364  const polyBoundaryMesh& bm
365 )
366 :
367  cyclicAMIPolyPatch(pp, bm),
368  transformPatchName_(pp.transformPatchName_),
369  transformPatchID_(-1)
370 {
371  // Transform patch might not be valid yet so cannot determine
372  // associated patchID
373 }
374 
375 
377 (
378  const cyclicRepeatAMIPolyPatch& pp,
379  const polyBoundaryMesh& bm,
380  const label index,
381  const label newSize,
382  const label newStart,
383  const word& nbrPatchName
384 )
385 :
386  cyclicAMIPolyPatch(pp, bm, index, newSize, newStart, nbrPatchName),
387  transformPatchName_(pp.transformPatchName_),
388  transformPatchID_(-1)
389 {
390  // Transform patch might not be valid yet so cannot determine
391  // associated patchID
392 }
393 
394 
396 (
397  const cyclicRepeatAMIPolyPatch& pp,
398  const polyBoundaryMesh& bm,
399  const label index,
400  const labelUList& mapAddressing,
401  const label newStart
402 )
403 :
404  cyclicAMIPolyPatch(pp, bm, index, mapAddressing, newStart),
405  transformPatchName_(pp.transformPatchName_),
406  transformPatchID_(-1)
407 {
408  // Transform patch might not be valid yet so cannot determine
409  // associated patchID
410 }
411 
412 
413 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
414 
416 {}
417 
418 
419 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
420 
423 {
424  const polyPatch& pp = this->boundaryMesh()[nbrPatchID()];
425 
426  return refCast<const cyclicRepeatAMIPolyPatch>(pp);
427 }
428 
429 
431 {
432  if (transformPatchID_ == -1)
433  {
434  transformPatchID_ =
435  this->boundaryMesh().findPatchID(transformPatchName());
436 
437  if (transformPatchID_ == -1)
438  {
440  << "Illegal transformPatch name " << transformPatchName()
441  << nl << "Valid patch names are "
442  << this->boundaryMesh().names()
443  << exit(FatalError);
444  }
445  }
446 
447  return transformPatchID_;
448 }
449 
450 
453 {
454  const polyPatch& pp = this->boundaryMesh()[transformPatchID()];
455 
456  return refCast<const coupledPolyPatch>(pp);
457 }
458 
459 
461 {
462  // The two AMI-interpolation classes have their weights summed together, so
463  // both should contain the same weights sum field. We can, therefore
464  // delegate to the base class and just return the weights sum of the first.
465 
467 }
468 
469 
470 const Foam::scalarField&
472 {
473  // See above.
474 
476 }
477 
478 
480 {
482  writeEntry(os, "transformPatch", transformPatchName_);
483 }
484 
485 
486 // ************************************************************************* //
virtual void resetAMI() const
Reset the AMI interpolator.
virtual ~cyclicRepeatAMIPolyPatch()
Destructor.
virtual void movePoints(const Field< PointType > &)
Correct patch after moving points.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const word & name() const
Return name.
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
Vector-tensor class used to perform translations and rotations in 3D space.
Definition: transformer.H:83
virtual const scalarField & weightsSum() const
Return the weights sum for this patch.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
A 2-tuple for storing two objects of different types.
Definition: HashTable.H:65
const Type1 & first() const
Return first.
Definition: Tuple2.H:99
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface...
Definition: boundaryMesh.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual const scalarField & nbrWeightsSum() const
Return the weights sum for the neighbour patch.
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
T * ptr()
Return object pointer for reuse.
Definition: autoPtrI.H:90
virtual const transformer & transform() const =0
Return transformation between the coupled patches.
Macros for easy insertion into run-time selection tables.
virtual const scalarField & nbrWeightsSum() const
Return the weights sum for the neighbour patch.
virtual label transformPatchID() const
Neighbour patch ID.
scalar y
A list of faces which address into the list of points.
Repeat patch for Arbitrary Mesh Interface (AMI)
A List obtained as a section of another List.
Definition: SubList.H:53
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Type gSum(const FieldField< Field, Type > &f)
virtual const cyclicRepeatAMIPolyPatch & nbrPatch() const
Return a reference to the neighbour patch.
A class for handling words, derived from string.
Definition: word.H:59
static const word null
An empty word.
Definition: word.H:77
word transformPatchName_
Name of the transform patch.
Cyclic patch for Arbitrary Mesh Interface (AMI)
static const transformer I
Definition: transformer.H:125
virtual const scalarField & weightsSum() const
Return the weights sum for this patch.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
Foam::polyBoundaryMesh.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
static const char nl
Definition: Ostream.H:260
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
defineTypeNameAndDebug(combustionModel, 0)
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
cyclicRepeatAMIPolyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType)
Construct from (base couped patch) components.
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
label n
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
vector transformPosition(const vector &v) const
Transform the given position.
Definition: transformerI.H:153
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Cyclic plane tranformation.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812
virtual const coupledPolyPatch & transformPatch() const
Return a reference to the transform patch.