coupledPolyPatch.H
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) 2011-2019 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 Class
25  Foam::coupledPolyPatch
26 
27 Description
28  The coupledPolyPatch is an abstract base class for patches that couple
29  regions of the computational domain e.g. cyclic and processor-processor
30  links.
31 
32 SourceFiles
33  coupledPolyPatch.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef coupledPolyPatch_H
38 #define coupledPolyPatch_H
39 
40 #include "polyPatch.H"
41 #include "diagTensorField.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class coupledPolyPatch Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class coupledPolyPatch
53 :
54  public polyPatch
55 {
56 public:
57 
58  enum transformType
59  {
60  UNKNOWN, // unspecified; automatic ordering
61  ROTATIONAL, // rotation along coordinate axis
62  TRANSLATIONAL, // translation
63  COINCIDENTFULLMATCH,// assume no transforms
64  // and check the points in faces match
65  NOORDERING // unspecified, no automatic ordering
66  };
67 
69 
70 
71 private:
72 
73  // Private Data
74 
75  //- Default matching tolerance
76  static const scalar defaultMatchTol_;
77 
78  //- Local matching tolerance
79  const scalar matchTolerance_;
80 
81  //- Type of transformation
82  transformType transform_;
83 
84  //- Offset (distance) vector from one side of the couple to the other
85  mutable vectorField separation_;
86 
87  //- Face transformation tensor
88  mutable tensorField forwardT_;
89 
90  //- Neighbour-cell transformation tensor
91  mutable tensorField reverseT_;
92 
93  //- Are faces collocated. Either size 0,1 or length of patch.
94  mutable boolList collocated_;
95 
96 
97 protected:
98 
99  // Protected Member Functions
100 
101  //- Calculate the transformation tensors
102  // smallDist : matching distance per face
103  // absTol : absolute error in normal
104  // if transformType = unknown it first tries rotational, then
105  // translational transform
107  (
108  const vectorField& Cf,
109  const vectorField& Cr,
110  const vectorField& nf,
111  const vectorField& nr,
112  const scalarField& smallDist,
113  const scalar absTol,
114  const transformType = UNKNOWN
115  ) const;
116 
117  //- Initialise the calculation of the patch geometry
118  virtual void initGeometry(PstreamBuffers&) = 0;
119 
120  //- Calculate the patch geometry
121  virtual void calcGeometry(PstreamBuffers&) = 0;
122 
123  //- Initialise the patches for moving points
124  virtual void initMovePoints(PstreamBuffers&, const pointField&) = 0;
125 
126  //- Correct patches after moving points
127  virtual void movePoints(PstreamBuffers&, const pointField&) = 0;
128 
129  //- Initialise the update of the patch topology
130  virtual void initUpdateMesh(PstreamBuffers&) = 0;
131 
132  //- Update of the patch topology
133  virtual void updateMesh(PstreamBuffers&) = 0;
134 
135 
136  //- Write point in OBJ format
137  static void writeOBJ(Ostream& os, const point& pt);
138 
139  //- Write selected points in OBJ format
140  static void writeOBJ(Ostream&, const pointField&, const labelList&);
141 
142  //- Write patch
143  static void writeOBJ
144  (
145  const fileName&,
146  const UList<face>&,
147  const pointField&
148  );
149 
150  //- Write edge in OBJ format
151  static void writeOBJ
152  (
153  Ostream& os,
154  const point& p0,
155  const point& p1,
156  label& vertI
157  );
158 
159  //- Get a unique anchor point for all faces
161  (
162  const UList<face>&,
163  const pointField&,
164  const transformType
165  );
166 
167  //- Get the number of vertices face f needs to be rotated such that
168  // its f[0] point aligns with given anchor (within tol).
169  static label getRotation
170  (
171  const pointField& points,
172  const face& f,
173  const point& anchor,
174  const scalar tol
175  );
176 
177 
178 public:
179 
180  //- Runtime type information
181  TypeName("coupled");
182 
183 
184  // Constructors
185 
186  //- Construct from components
188  (
189  const word& name,
190  const label size,
191  const label start,
192  const label index,
193  const polyBoundaryMesh& bm,
194  const word& patchType,
196  );
197 
198  //- Construct from dictionary
200  (
201  const word& name,
202  const dictionary& dict,
203  const label index,
204  const polyBoundaryMesh& bm,
205  const word& patchType,
206  const transformType defaultTransform = UNKNOWN
207  );
208 
209  //- Construct as copy, resetting the boundary mesh
211 
212  //- Construct given the original patch and resetting the
213  // face list and boundary mesh information
215  (
216  const coupledPolyPatch& pp,
217  const polyBoundaryMesh& bm,
218  const label index,
219  const label newSize,
220  const label newStart
221  );
222 
223  //- Construct given the original patch and a map
225  (
226  const coupledPolyPatch& pp,
227  const polyBoundaryMesh& bm,
228  const label index,
229  const labelUList& mapAddressing,
230  const label newStart
231  );
232 
233 
234  //- Destructor
235  virtual ~coupledPolyPatch();
236 
237 
238  // Member Functions
239 
240  // Access
241 
242  //- Return true because this patch is coupled
243  virtual bool coupled() const
244  {
245  return true;
246  }
247 
248  //- Does this side own the patch ?
249  virtual bool owner() const = 0;
250 
251  //- Does the coupled side own the patch ?
252  virtual bool neighbour() const
253  {
254  return !owner();
255  }
256 
257  //- Type of transform
258  virtual transformType transform() const
259  {
260  return transform_;
261  }
262 
263  //- Type of transform
264  // This is currently only for use when collapsing generated
265  // meshes that can have zero area faces.
266  virtual transformType& transform()
267  {
268  return transform_;
269  }
270 
271  //- Transform a patch-based position from other side to this side
272  virtual void transformPosition(pointField&) const = 0;
273 
274  //- Transform a patch-based position from other side to this side
275  virtual void transformPosition(point&, const label facei) const = 0;
276 
277  //- Are the planes separated.
278  virtual bool separated() const
279  {
280  return separation_.size();
281  }
282 
283  //- If the planes are separated the separation vector.
284  virtual const vectorField& separation() const
285  {
286  return separation_;
287  }
288 
289  //- Are the cyclic planes parallel.
290  virtual bool parallel() const
291  {
292  return forwardT_.empty();
293  }
294 
295  //- Return face transformation tensor.
296  virtual const tensorField& forwardT() const
297  {
298  return forwardT_;
299  }
300 
301  //- Return neighbour-cell transformation tensor.
302  virtual const tensorField& reverseT() const
303  {
304  return reverseT_;
305  }
306 
307  //- Are faces collocated. Either size 0,1 or length of patch
308  virtual const boolList& collocated() const
309  {
310  return collocated_;
311  }
313  scalar matchTolerance() const
314  {
315  return matchTolerance_;
316  }
317 
318 
319  //- Calculate the patch geometry
320  virtual void calcGeometry
321  (
322  const primitivePatch& referPatch,
323  const pointField& thisCtrs,
324  const vectorField& thisAreas,
325  const pointField& thisCc,
326  const pointField& nbrCtrs,
327  const vectorField& nbrAreas,
328  const pointField& nbrCc
329  ) = 0;
330 
331  //- Initialize ordering for primitivePatch. Does not
332  // refer to *this (except for name() and type() etc.)
333  virtual void initOrder
334  (
336  const primitivePatch&
337  ) const = 0;
338 
339  //- Return new ordering for primitivePatch.
340  // Ordering is -faceMap: for every face
341  // index of the new face -rotation:for every new face the clockwise
342  // shift of the original face. Return false if nothing changes
343  // (faceMap is identity, rotation is 0), true otherwise.
344  virtual bool order
345  (
347  const primitivePatch&,
349  labelList& rotation
350  ) const = 0;
351 
352  //- Calculate typical tolerance per face. Is currently max distance
353  // from face centre to any of the face vertices.
354  static scalarField calcFaceTol
355  (
356  const UList<face>& faces,
357  const pointField& points,
358  const pointField& faceCentres
359  );
360 
361  //- Write the polyPatch data as a dictionary
362  virtual void write(Ostream&) const;
363 };
364 
365 
366 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
367 
368 } // End namespace Foam
369 
370 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
371 
372 #endif
373 
374 // ************************************************************************* //
virtual void initMovePoints(PstreamBuffers &, const pointField &)=0
Initialise the patches for moving points.
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const =0
Initialize ordering for primitivePatch. Does not.
dictionary dict
virtual bool coupled() const
Return true because this patch is coupled.
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:313
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.
A class for handling file names.
Definition: fileName.H:79
virtual void initGeometry(PstreamBuffers &)=0
Initialise the calculation of the patch geometry.
virtual bool separated() const
Are the planes separated.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
coupledPolyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType, const transformType transform)
Construct from components.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
scalar matchTolerance() const
virtual const vectorField & separation() const
If the planes are separated the separation vector.
virtual const tensorField & forwardT() const
Return face transformation tensor.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
virtual void movePoints(PstreamBuffers &, const pointField &)=0
Correct patches after moving points.
static pointField getAnchorPoints(const UList< face > &, const pointField &, const transformType)
Get a unique anchor point for all faces.
virtual bool parallel() const
Are the cyclic planes parallel.
A list of faces which address into the list of points.
virtual void calcGeometry(PstreamBuffers &)=0
Calculate the patch geometry.
static const NamedEnum< transformType, 5 > transformTypeNames
A class for handling words, derived from string.
Definition: word.H:59
virtual bool owner() const =0
Does this side own the patch ?
static void writeOBJ(Ostream &os, const point &pt)
Write point in OBJ format.
const Field< PointType > & points() const
Return reference to global points.
virtual void initUpdateMesh(PstreamBuffers &)=0
Initialise the update of the patch topology.
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const =0
Return new ordering for primitivePatch.
Foam::polyBoundaryMesh.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
labelList f(nPoints)
virtual const boolList & collocated() const
Are faces collocated. Either size 0,1 or length of patch.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
static label getRotation(const pointField &points, const face &f, const point &anchor, const scalar tol)
Get the number of vertices face f needs to be rotated such that.
static scalarField calcFaceTol(const UList< face > &faces, const pointField &points, const pointField &faceCentres)
Calculate typical tolerance per face. Is currently max distance.
void calcTransformTensors(const vectorField &Cf, const vectorField &Cr, const vectorField &nf, const vectorField &nr, const scalarField &smallDist, const scalar absTol, const transformType=UNKNOWN) const
Calculate the transformation tensors.
virtual ~coupledPolyPatch()
Destructor.
virtual const tensorField & reverseT() const
Return neighbour-cell transformation tensor.
virtual void transformPosition(pointField &) const =0
Transform a patch-based position from other side to this side.
TypeName("coupled")
Runtime type information.
label index() const
Return the index of this patch in the boundaryMesh.
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:303
virtual bool neighbour() const
Does the coupled side own the patch ?
virtual transformType transform() const
Type of transform.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
virtual void updateMesh(PstreamBuffers &)=0
Update of the patch topology.
Namespace for OpenFOAM.
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:284