All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PointHit.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-2020 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::PointHit
26 
27 Description
28  This class describes the interaction of a face and a point. It
29  carries the info of a successful hit and (if successful), returns
30  the interaction point.
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #ifndef PointHit_H
35 #define PointHit_H
36 
37 #include "bool.H"
38 #include "token.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 // Forward declaration of classes
46 
47 class Ostream;
48 
49 
50 // Forward declaration of friend functions and operators
51 
52 template<class Point> class PointHit;
53 
54 template<class Point>
55 inline Ostream& operator<<(Ostream&, const PointHit<Point>&);
56 
57 
58 /*---------------------------------------------------------------------------*\
59  Class PointHit Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 template<class Point>
63 class PointHit
64 {
65  // Private Data
66 
67  //- Hit success
68  bool hit_;
69 
70  //- Point of hit; for miss holds best estimate outside the object
71  Point hitPoint_;
72 
73  //- Distance to hit point
74  scalar distance_;
75 
76  //- Eligible miss
77  bool eligibleMiss_;
78 
79 
80 public:
81 
82  // Constructors
83 
84  //- Construct null
85  PointHit()
86  :
87  hit_(false),
88  hitPoint_(Zero),
89  distance_(great),
90  eligibleMiss_(false)
91  {}
92 
93  //- Construct from components
95  (
96  const bool hit,
97  const Point& p,
98  const scalar dist,
99  const bool eligibleMiss
100  )
101  :
102  hit_(hit),
103  hitPoint_(p),
104  distance_(dist),
105  eligibleMiss_(eligibleMiss)
106  {}
107 
108  //- Construct from point. Hit and distance set later
109  PointHit(const Point& p)
110  :
111  hit_(false),
112  hitPoint_(p),
113  distance_(great),
114  eligibleMiss_(false)
115  {}
116 
117 
118  // Member Functions
119 
120  //- Is there a hit
121  bool hit() const
122  {
123  return hit_;
124  }
125 
126  //- Return hit point
127  const Point& hitPoint() const
128  {
129  if (!hit_)
130  {
132  << "requested a hit point for a miss"
133  << abort(FatalError);
134  }
135 
136  return hitPoint_;
137  }
138 
139  //- Return distance to hit
140  scalar distance() const
141  {
142  return distance_;
143  }
144 
145  //- Return miss point
146  const Point& missPoint() const
147  {
148  if (hit_)
149  {
151  << "requested a miss point for a hit"
152  << abort(FatalError);
153  }
154 
155  return hitPoint_;
156  }
157 
158  //- Return point with no checking
159  const Point& rawPoint() const
160  {
161  return hitPoint_;
162  }
163 
164  //- Is this an eligible miss
165  bool eligibleMiss() const
166  {
167  return eligibleMiss_;
168  }
170  void setHit()
171  {
172  hit_ = true;
173  eligibleMiss_ = false;
174  }
176  void setMiss(const bool eligible)
177  {
178  hit_ = false;
179  eligibleMiss_ = eligible;
180  }
182  void setPoint(const Point& p)
183  {
184  hitPoint_ = p;
185  }
187  void setDistance(const scalar d)
188  {
189  distance_ = d;
190  }
191 
192 
193  // Ostream operator
194 
195  friend Ostream& operator<< <Point>
196  (
197  Ostream& os,
198  const PointHit<Point>& b
199  );
200 };
201 
202 
203 template<class Point>
204 inline Ostream& operator<<(Ostream& os, const PointHit<Point>& b)
205 {
206  os << b.hit() << token::SPACE
207  << b.rawPoint() << token::SPACE
208  << b.distance() << token::SPACE
209  << b.eligibleMiss();
210 
211  return os;
212 }
213 
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 } // End namespace Foam
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 #endif
222 
223 // ************************************************************************* //
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
PointHit()
Construct null.
Definition: PointHit.H:84
const dimensionedScalar b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
const Point & missPoint() const
Return miss point.
Definition: PointHit.H:145
void setHit()
Definition: PointHit.H:169
void setDistance(const scalar d)
Definition: PointHit.H:186
const Point & hitPoint() const
Return hit point.
Definition: PointHit.H:126
bool hit() const
Is there a hit.
Definition: PointHit.H:120
static const zero Zero
Definition: zero.H:97
This class describes the interaction of a face and a point. It carries the info of a successful hit a...
Definition: PointHit.H:51
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void setMiss(const bool eligible)
Definition: PointHit.H:175
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
const Point & rawPoint() const
Return point with no checking.
Definition: PointHit.H:158
scalar distance() const
Return distance to hit.
Definition: PointHit.H:139
volScalarField & p
bool eligibleMiss() const
Is this an eligible miss.
Definition: PointHit.H:164
void setPoint(const Point &p)
Definition: PointHit.H:181
System bool.
Namespace for OpenFOAM.