coneRefinement.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 "coneRefinement.H"
28 #include "boundBox.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 :
43  p0_(),
44  r0_(-1.0),
45  p1_(),
46  r1_(-1.0)
47 {}
48 
50 (
51  const word& name,
52  const scalar cellSize,
53  const direction additionalRefLevels,
54  const point& p0,
55  const scalar radius0,
56  const point& p1,
57  const scalar radius1
58 )
59 :
61  p0_(p0),
62  r0_(radius0),
63  p1_(p1),
64  r1_(radius1)
65 {
66  setName(name);
67  setCellSize(cellSize);
68  setAdditionalRefinementLevels(additionalRefLevels);
69 }
70 
72 (
73  const word& name,
74  const dictionary& dict
75 )
76 :
78 {
79  this->operator=(dict);
80 }
81 
82 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
83 
85 {
86  //- check if the centre is inside the cone
87  const point c = (bb.max() + bb.min()) / 2.0;
88 
89  const vector v = p1_ - p0_;
90  const scalar d = magSqr(v);
91 
92  if( d < VSMALL )
93  return false;
94 
95  const scalar t = ((c - p0_) & v) / d;
96  if( (t > 1.0) || (t < 0.0) )
97  return false;
98 
99  const scalar r = r0_ + (r1_ - r0_) * t;
100 
101  if( mag(p0_ + t * v - c) < r )
102  return true;
103 
104  return false;
105 }
106 
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109 dictionary coneRefinement::dict(bool /*ignoreType*/) const
110 {
112 
113  if( additionalRefinementLevels() == 0 && cellSize() >= 0.0 )
114  {
115  dict.add("cellSize", cellSize());
116  }
117  else
118  {
119  dict.add("additionalRefinementLevels", additionalRefinementLevels());
120  }
121 
122  dict.add("type", type());
123 
124  dict.add("p0", p0_);
125  dict.add("radius0", r0_);
126  dict.add("p1", p1_);
127  dict.add("radius1", r1_);
128 
129  return dict;
130 }
131 
133 {
134  os << " type: " << type()
135  << " p0: " << p0_
136  << " radius0: " << r0_
137  << " p1: " << p1_
138  << " radius1: " << r1_;
139 }
140 
141 void coneRefinement::writeDict(Ostream& os, bool subDict) const
142 {
143  if( subDict )
144  {
145  os << indent << token::BEGIN_BLOCK << incrIndent << nl;
146  }
147 
148  if( additionalRefinementLevels() == 0 && cellSize() >= 0.0 )
149  {
150  os.writeKeyword("cellSize") << cellSize() << token::END_STATEMENT << nl;
151  }
152  else
153  {
154  os.writeKeyword("additionalRefinementLevels")
156  << token::END_STATEMENT << nl;
157  }
158 
159  // only write type for derived types
160  if( type() != typeName_() )
161  {
162  os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
163  }
164 
165  os.writeKeyword("p0") << p0_ << token::END_STATEMENT << nl;
166  os.writeKeyword("radius0") << r0_ << token::END_STATEMENT << nl;
167  os.writeKeyword("p1") << p1_ << token::END_STATEMENT << nl;
168  os.writeKeyword("radius1") << r1_ << token::END_STATEMENT << nl;
169 
170  if( subDict )
171  {
172  os << decrIndent << indent << token::END_BLOCK << endl;
173  }
174 }
175 
177 {
178  // allow as embedded sub-dictionary "coordinateSystem"
179  const dictionary& dict =
180  (
181  d.found(typeName_())
182  ? d.subDict(typeName_())
183  : d
184  );
185 
186  // unspecified centre is (0 0 0)
187  if( dict.found("p0") )
188  {
189  dict.lookup("p0") >> p0_;
190  }
191  else
192  {
194  (
195  "void coneRefinement::operator=(const dictionary& d)"
196  ) << "Entry p0 is not specified!" << exit(FatalError);
197  p0_ = vector::zero;
198  }
199 
200  // specify radius
201  if( dict.found("radius0") )
202  {
203  r0_ = readScalar(dict.lookup("radius0"));
204  }
205  else
206  {
208  (
209  "void coneRefinement::operator=(const dictionary& d)"
210  ) << "Entry radius0 is not specified!" << exit(FatalError);
211  r0_ = -1.0;
212  }
213 
214  // unspecified centre is (0 0 0)
215  if( dict.found("p1") )
216  {
217  dict.lookup("p1") >> p1_;
218  }
219  else
220  {
222  (
223  "void coneRefinement::operator=(const dictionary& d)"
224  ) << "Entry p1 is not specified!" << exit(FatalError);
225  p1_ = vector::zero;
226  }
227 
228  // specify radius
229  if( dict.found("radius1") )
230  {
231  r1_ = readScalar(dict.lookup("radius1"));
232  }
233  else
234  {
236  (
237  "void coneRefinement::operator=(const dictionary& d)"
238  ) << "Entry radius1 is not specified!" << exit(FatalError);
239  r1_ = -1.0;
240  }
241 }
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
246 {
247  os << "name " << name() << nl;
248  os << "cell size " << cellSize() << nl;
249  os << "additionalRefinementLevels " << additionalRefinementLevels() << endl;
250 
251  write(os);
252  return os;
253 }
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 } // End namespace Foam
258 
259 // ************************************************************************* //
Foam::token::END_STATEMENT
@ END_STATEMENT
Definition: token.H:99
Foam::coneRefinement::write
void write(Ostream &) const
Write.
Definition: coneRefinement.C:132
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::coneRefinement::coneRefinement
coneRefinement()
Null construct.
Definition: coneRefinement.C:40
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::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
coneRefinement
Refine boxes with centres contained inside the cone.
Foam::coneRefinement::r1_
scalar r1_
Definition: coneRefinement.H:61
Foam::coneRefinement::operator=
void operator=(const dictionary &)
assign from dictionary
Definition: coneRefinement.C:176
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::coneRefinement::intersectsObject
bool intersectsObject(const boundBox &) const
check if a boundBox intersects or is inside the object
Definition: coneRefinement.C:84
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::coneRefinement::dict
dictionary dict(bool ignoreType=false) const
Return as dictionary of entries.
Definition: coneRefinement.C:109
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::coneRefinement::p1_
point p1_
end point and the radius
Definition: coneRefinement.H:60
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::coneRefinement::operator<<
Ostream & operator<<(Ostream &) const
Definition: coneRefinement.C:245
boundBox.H
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::coneRefinement::p0_
point p0_
start point and the radius
Definition: coneRefinement.H:56
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
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::token::BEGIN_BLOCK
@ BEGIN_BLOCK
Definition: token.H:104
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
coneRefinement.H
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::coneRefinement::writeDict
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
Definition: coneRefinement.C:141
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.
Foam::coneRefinement::r0_
scalar r0_
Definition: coneRefinement.H:57