boxRefinement.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 "boxRefinement.H"
28 #include "boundBox.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 :
43  centre_(),
44  lengthX_(-1.0),
45  lengthY_(-1.0),
46  lengthZ_(-1.0)
47 {}
48 
50 (
51  const word& name,
52  const scalar cellSize,
53  const direction additionalRefLevels,
54  const point& centre,
55  const scalar lengthX,
56  const scalar lengthY,
57  const scalar lengthZ
58 )
59 :
61  centre_(centre),
62  lengthX_(lengthX),
63  lengthY_(lengthY),
64  lengthZ_(lengthZ)
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  vector v(0.5*lengthX_, 0.5*lengthY_, 0.5*lengthZ_);
87  boundBox box(centre_ - v, centre_ + v);
88 
89  if( box.overlaps(bb) )
90  return true;
91 
92  return false;
93 }
94 
95 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
96 
97 dictionary boxRefinement::dict(bool /*ignoreType*/) const
98 {
100 
101  if( additionalRefinementLevels() == 0 && cellSize() >= 0.0 )
102  {
103  dict.add("cellSize", cellSize());
104  }
105  else
106  {
107  dict.add("additionalRefinementLevels", additionalRefinementLevels());
108  }
109 
110  dict.add("type", type());
111 
112  dict.add("centre", centre_);
113  dict.add("lengthX", lengthX_);
114  dict.add("lengthY", lengthY_);
115  dict.add("lengthZ", lengthZ_);
116 
117  return dict;
118 }
119 
121 {
122  os << " type: " << type()
123  << " centre: " << centre_
124  << " lengthX: " << lengthX_
125  << " lengthY: " << lengthY_
126  << " lengthZ: " << lengthZ_;
127 }
128 
129 void boxRefinement::writeDict(Ostream& os, bool subDict) const
130 {
131  if( subDict )
132  {
133  os << indent << token::BEGIN_BLOCK << incrIndent << nl;
134  }
135 
136  if( additionalRefinementLevels() == 0 && cellSize() >= 0.0 )
137  {
138  os.writeKeyword("cellSize") << cellSize() << token::END_STATEMENT << nl;
139  }
140  else
141  {
142  os.writeKeyword("additionalRefinementLevels")
144  << token::END_STATEMENT << nl;
145  }
146 
147  // only write type for derived types
148  if( type() != typeName_() )
149  {
150  os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
151  }
152 
153  os.writeKeyword("centre") << centre_ << token::END_STATEMENT << nl;
154  os.writeKeyword("lengthX") << lengthX_ << token::END_STATEMENT << nl;
155  os.writeKeyword("lengthY") << lengthY_ << token::END_STATEMENT << nl;
156  os.writeKeyword("lengthZ") << lengthZ_ << token::END_STATEMENT << nl;
157 
158  if( subDict )
159  {
160  os << decrIndent << indent << token::END_BLOCK << endl;
161  }
162 }
163 
165 {
166  // allow as embedded sub-dictionary "coordinateSystem"
167  const dictionary& dict =
168  (
169  d.found(typeName_())
170  ? d.subDict(typeName_())
171  : d
172  );
173 
174  // unspecified centre is (0 0 0)
175  if( dict.found("centre") )
176  {
177  dict.lookup("centre") >> centre_;
178  }
179  else
180  {
182  (
183  "void boxRefinement::operator=(const dictionary& d)"
184  ) << "Entry centre is not specified!" << exit(FatalError);
186  }
187 
188  // specify lengthX
189  if( dict.found("lengthX") )
190  {
191  lengthX_ = readScalar(dict.lookup("lengthX"));
192  }
193  else
194  {
196  (
197  "void boxRefinement::operator=(const dictionary& d)"
198  ) << "Entry lengthX is not specified!" << exit(FatalError);
199  lengthX_ = -1.0;
200  }
201 
202  // specify lengthY
203  if( dict.found("lengthY") )
204  {
205  lengthY_ = readScalar(dict.lookup("lengthY"));
206  }
207  else
208  {
210  (
211  "void boxRefinement::operator=(const dictionary& d)"
212  ) << "Entry lengthY is not specified!" << exit(FatalError);
213  lengthY_ = -1.0;
214  }
215 
216  // specify lengthZ
217  if( dict.found("lengthZ") )
218  {
219  lengthZ_ = readScalar(dict.lookup("lengthZ"));
220  }
221  else
222  {
224  (
225  "void boxRefinement::operator=(const dictionary& d)"
226  ) << "Entry lengthZ is not specified!" << exit(FatalError);
227  lengthZ_ = -1.0;
228  }
229 }
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
234 {
235  os << "name " << name() << nl;
236  os << "cell size " << cellSize() << nl;
237  os << "additionalRefinementLevels " << additionalRefinementLevels() << endl;
238 
239  write(os);
240  return os;
241 }
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 } // End namespace Foam
246 
247 // ************************************************************************* //
Foam::token::END_STATEMENT
@ END_STATEMENT
Definition: token.H:99
Foam::boxRefinement::centre_
point centre_
centre of the box
Definition: boxRefinement.H:56
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::boxRefinement::lengthY_
scalar lengthY_
Definition: boxRefinement.H:60
Foam::boxRefinement::writeDict
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
Definition: boxRefinement.C:129
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::boxRefinement::dict
dictionary dict(bool ignoreType=false) const
Return as dictionary of entries.
Definition: boxRefinement.C:97
boxRefinement.H
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::boxRefinement::lengthZ_
scalar lengthZ_
Definition: boxRefinement.H:61
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
Foam::boxRefinement::operator=
void operator=(const dictionary &)
assign from dictionary
Definition: boxRefinement.C:164
Foam::boxRefinement::lengthX_
scalar lengthX_
length of box sides
Definition: boxRefinement.H:59
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::boundBox::overlaps
bool overlaps(const boundBox &) const
Overlaps/touches boundingBox?
Definition: boundBoxI.H:120
Foam::boxRefinement::operator<<
Ostream & operator<<(Ostream &) const
Definition: boxRefinement.C:233
Foam::objectRefinement
Definition: objectRefinement.H:54
Foam::objectRefinement::additionalRefinementLevels
direction additionalRefinementLevels() const
return the number of additional refinement levels
Definition: objectRefinement.H:157
Foam::boxRefinement::intersectsObject
bool intersectsObject(const boundBox &) const
check if a boundBox intersects or is inside the object
Definition: boxRefinement.C:84
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
Foam::boxRefinement::boxRefinement
boxRefinement()
Null construct.
Definition: boxRefinement.C:40
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::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
boxRefinement
Checks if a box is contained inside the box object.
Foam::token::END_BLOCK
@ END_BLOCK
Definition: token.H:105
Foam::Vector< scalar >
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::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::boxRefinement::write
void write(Ostream &) const
Write.
Definition: boxRefinement.C:120
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::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.