pointEdgeCollapseI.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) 2012-2016 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 \*---------------------------------------------------------------------------*/
28 
29 #include "polyMesh.H"
30 #include "transform.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 // Update this with w2.
35 template<class TrackingData>
36 inline bool Foam::pointEdgeCollapse::update
37 (
38  const pointEdgeCollapse& w2,
39  const scalar tol,
40  TrackingData& td
41 )
42 {
43  if (!w2.valid(td))
44  {
46  << "problem." << abort(FatalError);
47  }
48 
49  if (!valid(td))
50  {
51  operator=(w2);
52  return true;
53  }
54 
55  if (w2.collapseIndex_ == -1 || collapseIndex_ == -1)
56  {
57  // Not marked for collapse; only happens on edges.
58  return false;
59  }
60 
61  if (w2.collapsePriority_ < collapsePriority_)
62  {
63  return false;
64  }
65  else if (w2.collapsePriority_ > collapsePriority_)
66  {
67  operator=(w2);
68  return true;
69  }
70 
71  // Get overwritten by w2 if it has a higher priority
72  if (w2.collapseIndex_ < collapseIndex_)
73  {
74  operator=(w2);
75  return true;
76  }
77  else if (w2.collapseIndex_ == collapseIndex_)
78  {
79  bool identicalPoint = samePoint(w2.collapsePoint_);
80 
81  bool nearer = (magSqr(w2.collapsePoint_) < magSqr(collapsePoint_));
82 
83  if (nearer)
84  {
85  operator=(w2);
86  }
87 
88  if (identicalPoint)
89  {
90  return false;
91  }
92  else
93  {
94  return nearer;
95  }
96  }
97 
98  return false;
99 }
100 
101 
102 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
103 
104 // Null constructor
106 :
107  collapsePoint_(GREAT, GREAT, GREAT),
108  collapseIndex_(-2),
109  collapsePriority_(-2)
110 {}
111 
112 
113 // Construct from origin, distance
115 (
116  const point& collapsePoint,
117  const label collapseIndex,
118  const label collapsePriority
119 )
120 :
121  collapsePoint_(collapsePoint),
122  collapseIndex_(collapseIndex),
123  collapsePriority_(collapsePriority)
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
128 
130 {
131  return collapsePoint_;
132 }
133 
134 
136 {
137  return collapseIndex_;
138 }
139 
140 
142 {
143  return collapsePriority_;
144 }
145 
146 
147 inline bool Foam::pointEdgeCollapse::samePoint(const point& pt) const
148 {
149  bool isLegal1 = (cmptMin(collapsePoint_) < 0.5*GREAT);
150  bool isLegal2 = (cmptMin(pt) < 0.5*GREAT);
151 
152  if (isLegal1 && isLegal2)
153  {
154  return mag(collapsePoint_ - pt) < 1e-9;//SMALL;
155  }
156  else
157  {
158  return isLegal1 == isLegal2;
159  }
160 }
161 
162 
163 template<class TrackingData>
164 inline bool Foam::pointEdgeCollapse::valid(TrackingData& td) const
165 {
166  return collapseIndex_ != -2;
167 }
168 
169 
170 template<class TrackingData>
172 (
173  const polyPatch& patch,
174  const label patchPointi,
175  const point& coord,
176  TrackingData& td
177 )
178 {
179  collapsePoint_ -= coord;
180 }
181 
182 
183 template<class TrackingData>
185 (
186  const tensor& rotTensor,
187  TrackingData& td
188 )
189 {
190  collapsePoint_ = Foam::transform(rotTensor, collapsePoint_);
191 }
192 
193 
194 // Update absolute geometric quantities. Note that distance (dist_)
195 // is not affected by leaving/entering domain.
196 template<class TrackingData>
198 (
199  const polyPatch& patch,
200  const label patchPointi,
201  const point& coord,
202  TrackingData& td
203 )
204 {
205  // back to absolute form
206  collapsePoint_ += coord;
207 }
208 
209 
210 // Update this with information from connected edge
211 template<class TrackingData>
213 (
214  const polyMesh& mesh,
215  const label pointi,
216  const label edgeI,
217  const pointEdgeCollapse& edgeInfo,
218  const scalar tol,
219  TrackingData& td
220 )
221 {
222  return update(edgeInfo, tol, td);
223 }
224 
225 
226 // Update this with new information on same point
227 template<class TrackingData>
229 (
230  const polyMesh& mesh,
231  const label pointi,
232  const pointEdgeCollapse& newPointInfo,
233  const scalar tol,
234  TrackingData& td
235 )
236 {
237  return update(newPointInfo, tol, td);
238 }
239 
240 
241 // Update this with new information on same point. No extra information.
242 template<class TrackingData>
244 (
245  const pointEdgeCollapse& newPointInfo,
246  const scalar tol,
247  TrackingData& td
248 )
249 {
250  return update(newPointInfo, tol, td);
251 }
252 
253 
254 // Update this with information from connected point
255 template<class TrackingData>
257 (
258  const polyMesh& mesh,
259  const label edgeI,
260  const label pointi,
261  const pointEdgeCollapse& pointInfo,
262  const scalar tol,
263  TrackingData& td
264 )
265 {
266  return update(pointInfo, tol, td);
267 }
268 
269 
270 template<class TrackingData>
272 (
273  const pointEdgeCollapse& rhs,
274  TrackingData& td
275 ) const
276 {
277  return operator==(rhs);
278 }
279 
280 
281 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
282 
283 inline bool Foam::pointEdgeCollapse::operator==
284 (
285  const Foam::pointEdgeCollapse& rhs
286 ) const
287 {
288  return
289  collapseIndex_ == rhs.collapseIndex_
290  && collapsePriority_ == rhs.collapsePriority_
291  && samePoint(rhs.collapsePoint_);
292 }
293 
294 
295 inline bool Foam::pointEdgeCollapse::operator!=
296 (
297  const Foam::pointEdgeCollapse& rhs
298 ) const
299 {
300  return !(*this == rhs);
301 }
302 
303 
304 // ************************************************************************* //
Foam::pointEdgeCollapse::updateEdge
bool updateEdge(const polyMesh &mesh, const label edgeI, const label pointi, const pointEdgeCollapse &pointInfo, const scalar tol, TrackingData &td)
Influence of point on edge.
Definition: pointEdgeCollapseI.H:257
Foam::pointEdgeCollapse::collapseIndex
label collapseIndex() const
Definition: pointEdgeCollapseI.H:135
Foam::Tensor< scalar >
Foam::pointEdgeCollapse::equal
bool equal(const pointEdgeCollapse &, TrackingData &) const
Same (like operator==)
Definition: pointEdgeCollapseI.H:272
Foam::pointEdgeCollapse::transform
void transform(const tensor &rotTensor, TrackingData &td)
Apply rotation matrix to origin.
Definition: pointEdgeCollapseI.H:185
update
mesh update()
Foam::pointEdgeCollapse::collapsePoint
const point & collapsePoint() const
Definition: pointEdgeCollapseI.H:129
Foam::pointEdgeCollapse::enterDomain
void enterDomain(const polyPatch &patch, const label patchPointi, const point &pos, TrackingData &td)
Convert relative origin to absolute by adding entering point.
Definition: pointEdgeCollapseI.H:198
Foam::transform
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:519
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::pointEdgeCollapse
Determines length of string of edges walked to point.
Definition: pointEdgeCollapse.H:62
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::cmptMin
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:302
Foam::pointEdgeCollapse::collapsePriority
label collapsePriority() const
Definition: pointEdgeCollapseI.H:141
Foam::label
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:62
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::FatalError
error FatalError
w2
#define w2
Definition: blockCreate.C:35
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::pointEdgeCollapse::pointEdgeCollapse
pointEdgeCollapse()
Construct null.
Definition: pointEdgeCollapseI.H:105
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::pointEdgeCollapse::valid
bool valid(TrackingData &td) const
Check whether origin has been changed at all or.
Definition: pointEdgeCollapseI.H:164
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::pointEdgeCollapse::leaveDomain
void leaveDomain(const polyPatch &patch, const label patchPointi, const point &pos, TrackingData &td)
Convert origin to relative vector to leaving point.
Definition: pointEdgeCollapseI.H:172
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::Vector< scalar >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
transform.H
3D tensor transformation operations.
Foam::pointEdgeCollapse::updatePoint
bool updatePoint(const polyMesh &mesh, const label pointi, const label edgeI, const pointEdgeCollapse &edgeInfo, const scalar tol, TrackingData &td)
Influence of edge on point.
Definition: pointEdgeCollapseI.H:213