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