geomCellLooper.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-2016 OpenFOAM Foundation
9  Copyright (C) 2020 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::geomCellLooper
29 
30 Description
31  Implementation of cellLooper. Does pure geometric cut through cell.
32 
33  Handles all cell shapes in the same way: cut edges with plane through
34  cell centre and normal in direction of provided direction. Snaps cuts
35  close to edge endpoints (close = snapTol * minEdgeLen) to vertices.
36 
37  Currently determines cuts through edges (and edge endpoints close to plane)
38  in random order and then sorts them acc. to angle. Could be converted to
39  use walk but problem is that face can be cut multiple times (since does
40  not need to be convex). Another problem is that edges parallel to plane
41  might not be cut. So these are handled by looking at the distance from
42  edge endpoints to the plane.
43 
44 SourceFiles
45  geomCellLooper.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef geomCellLooper_H
50 #define geomCellLooper_H
51 
52 #include "cellLooper.H"
53 #include "typeInfo.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 // Forward Declarations
61 class plane;
62 
63 /*---------------------------------------------------------------------------*\
64  Class geomCellLooper Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class geomCellLooper
68 :
69  public cellLooper
70 {
71  // Static
72 
73  //- Tolerance for point equal test. Fraction of edge length.
74  static const scalar pointEqualTol_;
75 
76  //- Tolerance for cut through edges to get snapped to edge end point.
77  // Fraction of length of minimum connected edge length.
78  static scalar snapTol_;
79 
80 
81  // Private Member Functions
82 
83  //- Min length of attached edges
84  scalar minEdgeLen(const label vertI) const;
85 
86  //- Return true and set weight if edge is cut
87  bool cutEdge
88  (
89  const plane& cutPlane,
90  const label edgeI,
91  scalar& weight
92  ) const;
93 
94  //- Snaps cut through edge by cut through vertex (if weight closer than
95  // tol to 0 or 1). Returns vertex label snapped to or -1.
96  label snapToVert
97  (
98  const scalar tol,
99  const label edgeI,
100  const scalar weight
101  ) const;
102 
103  //- Gets two (random) vectors perpendicular to n and each other to be
104  // used as base.
105  void getBase
106  (
107  const vector& n,
108  vector& e0,
109  vector& e1
110  ) const;
111 
112  //- Return true if the cut edge at loop[index] is inbetween the cuts
113  // through the edge end points.
114  bool edgeEndsCut(const labelList&, const label index) const;
115 
116 
117  //- No copy construct
118  geomCellLooper(const geomCellLooper&) = delete;
119 
120  //- No copy assignment
121  void operator=(const geomCellLooper&) = delete;
122 
123 
124 public:
125 
126  //- Runtime type information
127  TypeName("geomCellLooper");
128 
129 
130  // Static Functions
131 
132  static scalar snapTol()
133  {
134  return snapTol_;
135  }
136 
137  static void setSnapTol(const scalar tol)
138  {
139  snapTol_ = tol;
140  }
141 
142 
143  // Constructors
144 
145  //- Construct from mesh
146  explicit geomCellLooper(const polyMesh& mesh);
147 
148 
149  //- Destructor
150  virtual ~geomCellLooper() = default;
151 
152 
153  // Member Functions
154 
155  //- Create cut along circumference of celli. Gets current mesh cuts.
156  // Cut along circumference is expressed as loop of cuts plus weights
157  // for cuts along edges (only valid for edge cuts).
158  // Return true if successful cut.
159  virtual bool cut
160  (
161  const vector& refDir,
162  const label celli,
163  const boolList& vertIsCut,
164  const boolList& edgeIsCut,
165  const scalarField& edgeWeight,
166 
167  labelList& loop,
168  scalarField& loopWeights
169  ) const;
170 
171  //- Same but now also base point of cut provided (instead of always
172  // cell centre)
173  virtual bool cut
174  (
175  const plane& cutPlane,
176  const label celli,
177  const boolList& vertIsCut,
178  const boolList& edgeIsCut,
179  const scalarField& edgeWeight,
180 
181  labelList& loop,
182  scalarField& loopWeights
183  ) const;
184 };
185 
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 } // End namespace Foam
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 #endif
194 
195 // ************************************************************************* //
typeInfo.H
Foam::geomCellLooper::cut
virtual bool cut(const vector &refDir, const label celli, const boolList &vertIsCut, const boolList &edgeIsCut, const scalarField &edgeWeight, labelList &loop, scalarField &loopWeights) const
Create cut along circumference of celli. Gets current mesh cuts.
Definition: geomCellLooper.C:217
cellLooper.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::plane
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Definition: plane.H:89
Foam::geomCellLooper::snapTol
static scalar snapTol()
Definition: geomCellLooper.H:131
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::Field< scalar >
Foam::geomCellLooper::~geomCellLooper
virtual ~geomCellLooper()=default
Destructor.
Foam::cellLooper
Abstract base class. Concrete implementations know how to cut a cell (i.e. determine a loop around th...
Definition: cellLooper.H:72
Foam::geomCellLooper
Implementation of cellLooper. Does pure geometric cut through cell.
Definition: geomCellLooper.H:66
Foam::geomCellLooper::TypeName
TypeName("geomCellLooper")
Runtime type information.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::geomCellLooper::setSnapTol
static void setSnapTol(const scalar tol)
Definition: geomCellLooper.H:136
Foam::Vector< scalar >
Foam::List< label >
Foam::edgeVertex::mesh
const polyMesh & mesh() const
Definition: edgeVertex.H:101