hollowConeRefinement.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "hollowConeRefinement.H"
28 #include "boundBox.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 :
43  p0_(),
44  r0Outer_(-1.0),
45  r0Inner_(0.0),
46  p1_(),
47  r1Outer_(-1.0),
48  r1Inner_(0.0)
49 {}
50 
52 (
53  const word& name,
54  const scalar cellSize,
55  const direction additionalRefLevels,
56  const point& p0,
57  const scalar radius0Outer,
58  const scalar radius0Inner,
59  const point& p1,
60  const scalar radius1Outer,
61  const scalar radius1Inner
62 )
63 :
65  p0_(p0),
66  r0Outer_(radius0Outer),
67  r0Inner_(radius0Inner),
68  p1_(p1),
69  r1Outer_(radius1Outer),
70  r1Inner_(radius1Inner)
71 {
72  r0Inner_ = min(r0Inner_, r0Outer_);
73  r1Inner_ = min(r0Inner_, r0Outer_);
74  setName(name);
75  setCellSize(cellSize);
76  setAdditionalRefinementLevels(additionalRefLevels);
77 }
78 
80 (
81  const word& name,
82  const dictionary& dict
83 )
84 :
86 {
87  this->operator=(dict);
88 }
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
93 {
94  //- check if the centre is inside the cone
95  const point c = (bb.max() + bb.min()) / 2.0;
96 
97  const vector v = p1_ - p0_;
98  const scalar d = magSqr(v);
99 
100  if( d < VSMALL )
101  return false;
102 
103  const scalar t = ((c - p0_) & v) / d;
104  if( (t > 1.0) || (t < 0.0) )
105  return false;
106 
107  const scalar rOuter = r0Outer_ + (r1Outer_ - r0Outer_) * t;
108  const scalar rInner = r0Inner_ + (r1Inner_ - r0Inner_) * t;
109 
110  if(( mag(p0_ + t * v - c) < rOuter ) && ( mag(p0_ + t * v - c) > rInner ))
111  return true;
112 
113  return false;
114 }
115 
116 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
117 
118 dictionary hollowConeRefinement::dict(bool /*ignoreType*/) const
119 {
121 
122  if( additionalRefinementLevels() == 0 && cellSize() >= 0.0 )
123  {
124  dict.add("cellSize", cellSize());
125  }
126  else
127  {
128  dict.add("additionalRefinementLevels", additionalRefinementLevels());
129  }
130 
131  dict.add("type", type());
132 
133  dict.add("p0", p0_);
134  dict.add("radius0_Outer", r0Outer_);
135  dict.add("radius0_Inner", r0Inner_);
136  dict.add("p1", p1_);
137  dict.add("radius1_Outer", r1Outer_);
138  dict.add("radius1_Inner", r1Inner_);
139 
140  return dict;
141 }
142 
144 {
145  os << " type: " << type()
146  << " p0: " << p0_
147  << " radius0_Outer: " << r0Outer_
148  << " radius0_Inner: " << r0Inner_
149  << " p1: " << p1_
150  << " radius1_Outer: " << r1Outer_
151  << " radius1_Inner: " << r1Inner_;
152 }
153 
154 void hollowConeRefinement::writeDict(Ostream& os, bool subDict) const
155 {
156  if( subDict )
157  {
158  os << indent << token::BEGIN_BLOCK << incrIndent << nl;
159  }
160 
161  if( additionalRefinementLevels() == 0 && cellSize() >= 0.0 )
162  {
163  os.writeKeyword("cellSize") << cellSize() << token::END_STATEMENT << nl;
164  }
165  else
166  {
167  os.writeKeyword("additionalRefinementLevels")
169  << token::END_STATEMENT << nl;
170  }
171 
172  // only write type for derived types
173  if( type() != typeName_() )
174  {
175  os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
176  }
177 
178  os.writeKeyword("p0") << p0_ << token::END_STATEMENT << nl;
179  os.writeKeyword("radius0_Outer") << r0Outer_ << token::END_STATEMENT << nl;
180  os.writeKeyword("radius0_Inner") << r0Inner_ << token::END_STATEMENT << nl;
181  os.writeKeyword("p1") << p1_ << token::END_STATEMENT << nl;
182  os.writeKeyword("radius1_Outer") << r1Outer_ << token::END_STATEMENT << nl;
183  os.writeKeyword("radius1_Inner") << r1Inner_ << token::END_STATEMENT << nl;
184 
185  if( subDict )
186  {
187  os << decrIndent << indent << token::END_BLOCK << endl;
188  }
189 }
190 
192 {
193  // allow as embedded sub-dictionary "coordinateSystem"
194  const dictionary& dict =
195  (
196  d.found(typeName_())
197  ? d.subDict(typeName_())
198  : d
199  );
200 
201  // unspecified centre is (0 0 0)
202  if( dict.found("p0") )
203  {
204  dict.lookup("p0") >> p0_;
205  }
206  else
207  {
209  (
210  "void hollowConeRefinement::operator=(const dictionary& d)"
211  ) << "Entry p0 is not specified!" << exit(FatalError);
212  p0_ = vector::zero;
213  }
214 
215  // specify radius
216  if( dict.found("radius0_Outer") )
217  {
218  r0Outer_ = readScalar(dict.lookup("radius0_Outer"));
219  }
220  else
221  {
223  (
224  "void hollowConeRefinement::operator=(const dictionary& d)"
225  ) << "Entry radius0_Outer is not specified!" << exit(FatalError);
226  r0Outer_ = -1.0;
227  }
228 
229  // specify radius
230  if( dict.found("radius0_Inner") )
231  {
232  r0Inner_ = readScalar(dict.lookup("radius0_Inner"));
233  }
234  else
235  {
237  (
238  "void hollowConeRefinement::operator=(const dictionary& d)"
239  ) << "Entry radius0_Inner is not specified!" << exit(FatalError);
240  r0Inner_ = -1.0;
241  }
242 
243 
244  // unspecified centre is (0 0 0)
245  if( dict.found("p1") )
246  {
247  dict.lookup("p1") >> p1_;
248  }
249  else
250  {
252  (
253  "void hollowConeRefinement::operator=(const dictionary& d)"
254  ) << "Entry p1 is not specified!" << exit(FatalError);
255  p1_ = vector::zero;
256  }
257 
258  // specify radius
259  if( dict.found("radius1_Outer") )
260  {
261  r1Outer_ = readScalar(dict.lookup("radius1_Outer"));
262  }
263  else
264  {
266  (
267  "void hollowConeRefinement::operator=(const dictionary& d)"
268  ) << "Entry radius1_Outer is not specified!" << exit(FatalError);
269  r1Outer_ = -1.0;
270  }
271 
272  // specify radius
273  if( dict.found("radius1_Inner") )
274  {
275  r1Inner_ = readScalar(dict.lookup("radius1_Inner"));
276  }
277  else
278  {
280  (
281  "void hollowConeRefinement::operator=(const dictionary& d)"
282  ) << "Entry radius1_Inner is not specified!" << exit(FatalError);
283  r1Inner_ = -1.0;
284  }
285 }
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
290 {
291  os << "name " << name() << nl;
292  os << "cell size " << cellSize() << nl;
293  os << "additionalRefinementLevels " << additionalRefinementLevels() << endl;
294 
295  write(os);
296  return os;
297 }
298 
299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
300 
301 } // End namespace Foam
302 
303 // ************************************************************************* //
Foam::hollowConeRefinement::p0_
point p0_
start point and the radii
Definition: hollowConeRefinement.H:56
Foam::hollowConeRefinement::r0Outer_
scalar r0Outer_
Definition: hollowConeRefinement.H:57
Foam::token::END_STATEMENT
@ END_STATEMENT
Definition: token.H:99
Foam::hollowConeRefinement::writeDict
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
Definition: hollowConeRefinement.C:154
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
Foam::hollowConeRefinement::r0Inner_
scalar r0Inner_
Definition: hollowConeRefinement.H:58
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::hollowConeRefinement::dict
dictionary dict(bool ignoreType=false) const
Return as dictionary of entries.
Definition: hollowConeRefinement.C:118
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
Foam::hollowConeRefinement::write
void write(Ostream &) const
Write.
Definition: hollowConeRefinement.C:143
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::objectRefinement::cellSize
scalar cellSize() const
return cell size
Definition: objectRefinement.H:80
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::hollowConeRefinement::intersectsObject
bool intersectsObject(const boundBox &) const
check if a boundBox intersects or is inside the object
Definition: hollowConeRefinement.C:92
Foam::hollowConeRefinement::hollowConeRefinement
hollowConeRefinement()
Null construct.
Definition: hollowConeRefinement.C:40
Foam::hollowConeRefinement::p1_
point p1_
end point and the radii
Definition: hollowConeRefinement.H:61
Foam::objectRefinement
Definition: objectRefinement.H:54
Foam::objectRefinement::additionalRefinementLevels
direction additionalRefinementLevels() const
return the number of additional refinement levels
Definition: objectRefinement.H:157
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
boundBox.H
Foam::hollowConeRefinement::r1Inner_
scalar r1Inner_
Definition: hollowConeRefinement.H:63
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
Foam::token::END_BLOCK
@ END_BLOCK
Definition: token.H:105
Foam::Vector< scalar >
Foam::hollowConeRefinement::r1Outer_
scalar r1Outer_
Definition: hollowConeRefinement.H:62
Foam::Ostream::writeKeyword
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
Foam::direction
unsigned char direction
Definition: direction.H:43
hollowConeRefinement
Refine boxes with centres contained inside the specified hollow cone.
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::hollowConeRefinement::operator=
void operator=(const dictionary &)
assign from dictionary
Definition: hollowConeRefinement.C:191
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::token::BEGIN_BLOCK
@ BEGIN_BLOCK
Definition: token.H:104
hollowConeRefinement.H
Foam::objectRefinement::name
const word & name() const
Return name.
Definition: objectRefinement.H:136
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::hollowConeRefinement::operator<<
Ostream & operator<<(Ostream &) const
Definition: hollowConeRefinement.C:289
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::dictionary::add
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:729
objectRefinement
Base class for coordinate systems. All systems are defined by an origin and a coordinate rotation.