coupledPolyPatch.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 | Copyright (C) 2011-2015 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  );
207 
208  //- Construct as copy, resetting the boundary mesh
210 
211  //- Construct given the original patch and resetting the
212  // face list and boundary mesh information
214  (
215  const coupledPolyPatch& pp,
216  const polyBoundaryMesh& bm,
217  const label index,
218  const label newSize,
219  const label newStart
220  );
221 
222  //- Construct given the original patch and a map
224  (
225  const coupledPolyPatch& pp,
226  const polyBoundaryMesh& bm,
227  const label index,
228  const labelUList& mapAddressing,
229  const label newStart
230  );
231 
232 
233  //- Destructor
234  virtual ~coupledPolyPatch();
235 
236 
237  // Member Functions
238 
239  // Access
240 
241  //- Return true because this patch is coupled
242  virtual bool coupled() const
243  {
244  return true;
245  }
246 
247  //- Does this side own the patch ?
248  virtual bool owner() const = 0;
249 
250  //- Does the coupled side own the patch ?
251  virtual bool neighbour() const
252  {
253  return !owner();
254  }
255 
256  //- Type of transform
257  virtual transformType transform() const
258  {
259  return transform_;
260  }
261 
262  //- Type of transform
263  // This is currently only for use when collapsing generated
264  // meshes that can have zero area faces.
265  virtual transformType& transform()
266  {
267  return transform_;
268  }
269 
270  //- Transform a patch-based position from other side to this side
271  virtual void transformPosition(pointField&) const = 0;
272 
273  //- Transform a patch-based position from other side to this side
274  virtual void transformPosition(point&, const label facei) const = 0;
275 
276  //- Are the planes separated.
277  virtual bool separated() const
278  {
279  return separation_.size();
280  }
281 
282  //- If the planes are separated the separation vector.
283  virtual const vectorField& separation() const
284  {
285  return separation_;
286  }
287 
288  //- Are the cyclic planes parallel.
289  virtual bool parallel() const
290  {
291  return forwardT_.empty();
292  }
293 
294  //- Return face transformation tensor.
295  virtual const tensorField& forwardT() const
296  {
297  return forwardT_;
298  }
299 
300  //- Return neighbour-cell transformation tensor.
301  virtual const tensorField& reverseT() const
302  {
303  return reverseT_;
304  }
305 
306  //- Are faces collocated. Either size 0,1 or length of patch
307  virtual const boolList& collocated() const
308  {
309  return collocated_;
310  }
312  scalar matchTolerance() const
313  {
314  return matchTolerance_;
315  }
316 
317 
318  //- Calculate the patch geometry
319  virtual void calcGeometry
320  (
321  const primitivePatch& referPatch,
322  const pointField& thisCtrs,
323  const vectorField& thisAreas,
324  const pointField& thisCc,
325  const pointField& nbrCtrs,
326  const vectorField& nbrAreas,
327  const pointField& nbrCc
328  ) = 0;
329 
330  //- Initialize ordering for primitivePatch. Does not
331  // refer to *this (except for name() and type() etc.)
332  virtual void initOrder
333  (
335  const primitivePatch&
336  ) const = 0;
337 
338  //- Return new ordering for primitivePatch.
339  // Ordering is -faceMap: for every face
340  // index of the new face -rotation:for every new face the clockwise
341  // shift of the original face. Return false if nothing changes
342  // (faceMap is identity, rotation is 0), true otherwise.
343  virtual bool order
344  (
346  const primitivePatch&,
348  labelList& rotation
349  ) const = 0;
350 
351  //- Calculate typical tolerance per face. Is currently max distance
352  // from face centre to any of the face vertices.
353  static scalarField calcFaceTol
354  (
355  const UList<face>& faces,
356  const pointField& points,
357  const pointField& faceCentres
358  );
359 
360  //- Write the polyPatch data as a dictionary
361  virtual void write(Ostream&) const;
362 };
363 
364 
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 
367 } // End namespace Foam
368 
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
370 
371 #endif
372 
373 // ************************************************************************* //
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:69
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:137
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:300
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