sphereRefinement.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 "sphereRefinement.H"
28 #include "boundBox.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 :
43  centre_(),
44  radius_(-1.0)
45 {}
46 
48 (
49  const word& name,
50  const scalar cellSize,
51  const direction additionalRefLevels,
52  const point& centre,
53  const scalar radius
54 )
55 :
57  centre_(centre),
58  radius_(radius)
59 {
60  setName(name);
61  setCellSize(cellSize);
62  setAdditionalRefinementLevels(additionalRefLevels);
63 }
64 
66 (
67  const word& name,
68  const dictionary& dict
69 )
70 :
72 {
73  this->operator=(dict);
74 }
75 
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
77 
79 {
80  const point& c = (bb.max() + bb.min()) / 2.0;
81 
82  if( magSqr(c - centre_) < sqr(radius_) )
83  return true;
84 
85  return false;
86 }
87 
88 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
89 
90 dictionary sphereRefinement::dict(bool /*ignoreType*/) const
91 {
93 
94  if( additionalRefinementLevels() == 0 && cellSize() >= 0.0 )
95  {
96  dict.add("cellSize", cellSize());
97  }
98  else
99  {
100  dict.add("additionalRefinementLevels", additionalRefinementLevels());
101  }
102 
103  dict.add("type", type());
104 
105  dict.add("centre", centre_);
106  dict.add("radius", radius_);
107 
108  return dict;
109 }
110 
112 {
113  os << " type: " << type()
114  << " centre: " << centre_
115  << " radius: " << radius_;
116 }
117 
118 void sphereRefinement::writeDict(Ostream& os, bool subDict) const
119 {
120  if( subDict )
121  {
122  os << indent << token::BEGIN_BLOCK << incrIndent << nl;
123  }
124 
125  if( additionalRefinementLevels() == 0 && cellSize() >= 0.0 )
126  {
127  os.writeKeyword("cellSize") << cellSize() << token::END_STATEMENT << nl;
128  }
129  else
130  {
131  os.writeKeyword("additionalRefinementLevels")
133  << token::END_STATEMENT << nl;
134  }
135 
136  // only write type for derived types
137  if( type() != typeName_() )
138  {
139  os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
140  }
141 
142  os.writeKeyword("centre") << centre_ << token::END_STATEMENT << nl;
143  os.writeKeyword("radius") << radius_ << token::END_STATEMENT << nl;
144 
145  if( subDict )
146  {
147  os << decrIndent << indent << token::END_BLOCK << endl;
148  }
149 }
150 
152 {
153  // allow as embedded sub-dictionary "coordinateSystem"
154  const dictionary& dict =
155  (
156  d.found(typeName_())
157  ? d.subDict(typeName_())
158  : d
159  );
160 
161  // unspecified centre is (0 0 0)
162  if( dict.found("centre") )
163  {
164  dict.lookup("centre") >> centre_;
165  }
166  else
167  {
169  (
170  "void sphereRefinement::operator=(const dictionary& d)"
171  ) << "Entry centre is not specified!" << exit(FatalError);
173  }
174 
175  // specify radius
176  if( dict.found("radius") )
177  {
178  radius_ = readScalar(dict.lookup("radius"));
179  }
180  else
181  {
183  (
184  "void sphereRefinement::operator=(const dictionary& d)"
185  ) << "Entry radius is not specified!" << exit(FatalError);
186  radius_ = -1.0;
187  }
188 }
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
193 {
194  os << "name " << name() << nl;
195  os << "cell size " << cellSize() << nl;
196  os << "additionalRefinementLevels " << additionalRefinementLevels() << endl;
197 
198  write(os);
199  return os;
200 }
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 } // End namespace Foam
205 
206 // ************************************************************************* //
sphereRefinement.H
Foam::sphereRefinement::writeDict
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
Definition: sphereRefinement.C:118
Foam::token::END_STATEMENT
@ END_STATEMENT
Definition: token.H:99
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::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::sphereRefinement::write
void write(Ostream &) const
Write.
Definition: sphereRefinement.C:111
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::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
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::sphereRefinement::intersectsObject
bool intersectsObject(const boundBox &) const
check if a boundBox intersects or is inside the object
Definition: sphereRefinement.C:78
Foam::nl
static const char nl
Definition: Ostream.H:260
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::sphereRefinement::radius_
scalar radius_
radius of the sphere
Definition: sphereRefinement.H:59
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::sphereRefinement::operator=
void operator=(const dictionary &)
assign from dictionary
Definition: sphereRefinement.C:151
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
boundBox.H
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::sphereRefinement::operator<<
Ostream & operator<<(Ostream &) const
Definition: sphereRefinement.C:192
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::sphereRefinement::sphereRefinement
sphereRefinement()
Null construct.
Definition: sphereRefinement.C:40
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::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::sphereRefinement::centre_
point centre_
centre of the sphere
Definition: sphereRefinement.H:56
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
sphereRefinement
Mark objects contained in a sphere.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::sphereRefinement::dict
dictionary dict(bool ignoreType=false) const
Return as dictionary of entries.
Definition: sphereRefinement.C:90
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::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.