boxScaling.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 "boxScaling.H"
28 #include "boundBox.H"
29 #include "plane.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
38 
39 // * * * * * * * * * * * * * * Private member functions* * * * * * * * * * * //
40 
42 {
43  pMin_ = centre_ - 0.5 * lengthVec_;
44  pMax_ = centre_ + 0.5 * lengthVec_;
45 }
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 :
52  centre_(),
53  lengthVec_(0.0, 0.0, 0.0),
54  scaleVec_(1.0, 1.0, 1.0),
55  pMin_(),
56  pMax_()
57 {
59 }
60 
62 (
63  const word& name,
64  const point& centre,
65  const scalar lengthX,
66  const scalar lengthY,
67  const scalar lengthZ,
68  const scalar scaleX,
69  const scalar scaleY,
70  const scalar scaleZ
71 )
72 :
74  centre_(centre),
75  lengthVec_(lengthX, lengthY, lengthZ),
76  scaleVec_(scaleX, scaleY, scaleZ),
77  pMin_(),
78  pMax_()
79 {
80  calculateBndBox();
81  setName(name);
82 }
83 
85 (
86  const word& name,
87  const dictionary& dict
88 )
89 :
91 {
92  this->operator=(dict);
93 }
94 
95 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
96 
98 {
99  return centre_;
100 }
101 
103 {
104  centre_ += disp;
105 
106  for(direction i=0;i<vector::nComponents;++i)
107  lengthVec_[i] /= scaleVec_[i];
108 
109  calculateBndBox();
110 }
111 
113 {
114  vector disp;
115 
116  for(direction i=0;i<vector::nComponents;++i)
117  {
118  const scalar dispVec = lengthVec_[i] * ((1.0/scaleVec_[i]) - 1.0);
119  const scalar t = ((p[i] - pMin_[i]) / lengthVec_[i]);
120 
121  const scalar tBnd = Foam::max(0.0, Foam::min(t, 1.0));
122 
123  disp[i] = tBnd * dispVec;
124  }
125 
126  return disp;
127 }
128 
130 {
131  vector disp;
132 
133  for(direction i=0;i<vector::nComponents;++i)
134  {
135  const scalar dispVec = lengthVec_[i] * (scaleVec_[i] - 1.0);
136 
137  const scalar t = ((p[i] - pMin_[i]) / lengthVec_[i]);
138 
139  const scalar tBnd = Foam::max(0.0, Foam::min(t, 1.0));
140 
141  disp[i] = tBnd * dispVec;
142  }
143 
144  return disp;
145 }
146 
148 {
149  return true;
150 }
151 
153 {
154  pl.setSize(6);
155  label counter(0);
156  if( Foam::mag(scaleVec_.x() - 1.0) > VSMALL )
157  {
158  pl.set(counter++, new plane(pMin_, vector(1, 0, 0)));
159  pl.set(counter++, new plane(pMax_, vector(1, 0, 1)));
160  }
161 
162  if( Foam::mag(scaleVec_.y() - 1.0) > VSMALL )
163  {
164  pl.set(counter++, new plane(pMin_, vector(0, 1, 0)));
165  pl.set(counter++, new plane(pMax_, vector(0, 1, 0)));
166  }
167 
168  if( Foam::mag(scaleVec_.z() - 1.0) > VSMALL )
169  {
170  pl.set(counter++, new plane(pMin_, vector(0, 0, 1)));
171  pl.set(counter++, new plane(pMax_, vector(0, 0, 1)));
172  }
173 
174  pl.setSize(counter);
175 }
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 dictionary boxScaling::dict(bool /*ignoreType*/) const
180 {
182 
183  dict.add("type", type());
184 
185  dict.add("centre", centre_);
186  dict.add("lengthX", lengthVec_.x());
187  dict.add("lengthY", lengthVec_.y());
188  dict.add("lengthZ", lengthVec_.z());
189 
190  dict.add("scaleX", scaleVec_.x());
191  dict.add("scaleY", scaleVec_.y());
192  dict.add("scaleZ", scaleVec_.z());
193 
194  return dict;
195 }
196 
197 void boxScaling::write(Ostream& os) const
198 {
199  os << " type: " << type()
200  << " centre: " << centre_
201  << " lengthX: " << lengthVec_.x()
202  << " lengthY: " << lengthVec_.y()
203  << " lengthZ: " << lengthVec_.z()
204  << " scaleX: " << scaleVec_.x()
205  << " scaleY: " << scaleVec_.y()
206  << " scaleZ: " << scaleVec_.z()
207  << endl;
208 }
209 
210 void boxScaling::writeDict(Ostream& os, bool subDict) const
211 {
212  if( subDict )
213  {
214  os << indent << token::BEGIN_BLOCK << incrIndent << nl;
215  }
216 
217  // only write type for derived types
218  if( type() != typeName_() )
219  {
220  os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
221  }
222 
223  os.writeKeyword("centre") << centre_ << token::END_STATEMENT << nl;
224  os.writeKeyword("lengthX") << lengthVec_.x() << token::END_STATEMENT << nl;
225  os.writeKeyword("lengthY") << lengthVec_.y() << token::END_STATEMENT << nl;
226  os.writeKeyword("lengthZ") << lengthVec_.z() << token::END_STATEMENT << nl;
227  os.writeKeyword("scaleX") << scaleVec_.x() << token::END_STATEMENT << nl;
228  os.writeKeyword("scaleY") << scaleVec_.y() << token::END_STATEMENT << nl;
229  os.writeKeyword("scaleZ") << scaleVec_.z() << token::END_STATEMENT << nl;
230 
231  if( subDict )
232  {
233  os << decrIndent << indent << token::END_BLOCK << endl;
234  }
235 }
236 
238 {
239  // allow as embedded sub-dictionary "coordinateSystem"
240  const dictionary& dict =
241  (
242  d.found(typeName_())
243  ? d.subDict(typeName_())
244  : d
245  );
246 
247  // unspecified centre is (0 0 0)
248  if( dict.found("centre") )
249  {
250  dict.lookup("centre") >> centre_;
251  }
252  else
253  {
255  (
256  "void boxScaling::operator=(const dictionary& d)"
257  ) << "Entry centre is not specified!" << exit(FatalError);
259  }
260 
261  // specify lengthX
262  if( dict.found("lengthX") )
263  {
264  lengthVec_.x() = readScalar(dict.lookup("lengthX"));
265  }
266  else
267  {
269  (
270  "void boxScaling::operator=(const dictionary& d)"
271  ) << "Entry lengthX is not specified!" << exit(FatalError);
272  lengthVec_.x() = 0.0;
273  }
274 
275  // specify lengthY
276  if( dict.found("lengthY") )
277  {
278  lengthVec_.y() = readScalar(dict.lookup("lengthY"));
279  }
280  else
281  {
283  (
284  "void boxScaling::operator=(const dictionary& d)"
285  ) << "Entry lengthY is not specified!" << exit(FatalError);
286  lengthVec_.y() = 0.0;
287  }
288 
289  // specify lengthZ
290  if( dict.found("lengthZ") )
291  {
292  lengthVec_.z() = readScalar(dict.lookup("lengthZ"));
293  }
294  else
295  {
297  (
298  "void boxScaling::operator=(const dictionary& d)"
299  ) << "Entry lengthZ is not specified!" << exit(FatalError);
300  lengthVec_.z() = 0.0;
301  }
302 
303  // specify scaleX
304  if( dict.found("scaleX") )
305  {
306  scaleVec_.x() = readScalar(dict.lookup("scaleX"));
307  }
308  else
309  {
310  scaleVec_.x() = 1.0;
311  }
312 
313  // specify scaleY
314  if( dict.found("scaleY") )
315  {
316  scaleVec_.y() = readScalar(dict.lookup("scaleY"));
317  }
318  else
319  {
320  scaleVec_.y() = 1.0;
321  }
322 
323  // specify scaleX
324  if( dict.found("scaleZ") )
325  {
326  scaleVec_.z() = readScalar(dict.lookup("scaleZ"));
327  }
328  else
329  {
330  scaleVec_.z() = 1.0;
331  }
332 
333  calculateBndBox();
334 }
335 
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
337 
339 {
340  os << "name " << name() << nl;
341  write(os);
342  return os;
343 }
344 
346 {
347  return bs.operator<<(os);
348 }
349 
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351 
352 } // End namespace Foam
353 
354 // ************************************************************************* //
Foam::boxScaling::writeDict
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
Definition: boxScaling.C:210
Foam::boxScaling
Definition: boxScaling.H:50
Foam::boxScaling::calculateBndBox
void calculateBndBox()
calculate bounding box points
Definition: boxScaling.C:41
Foam::token::END_STATEMENT
@ END_STATEMENT
Definition: token.H:99
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::boxScaling::write
void write(Ostream &) const
Write.
Definition: boxScaling.C:197
Foam::boxScaling::origin
virtual point origin() const
return the centre of the box
Definition: boxScaling.C:97
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::boxScaling::operator=
void operator=(const dictionary &)
assign from dictionary
Definition: boxScaling.C:237
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::nComponents
@ nComponents
Number of components in this vector space.
Definition: VectorSpace.H:88
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
Foam::plane
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:60
Foam::boxScaling::backwardDisplacement
virtual vector backwardDisplacement(const point &) const
calculate the displacement vector for box scaling
Definition: boxScaling.C:129
Foam::PtrList::set
bool set(const label) const
Is element set.
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.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
plane.H
Foam::boxScaling::lengthVec_
vector lengthVec_
length of box sides
Definition: boxScaling.H:59
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::boxScaling::boxScaling
boxScaling()
Null construct.
Definition: boxScaling.C:49
Foam::boxScaling::combiningPossible
virtual bool combiningPossible() const
can this modification object be combined with other ones
Definition: boxScaling.C:147
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
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::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
Foam::boxScaling::translateAndModifyObject
virtual void translateAndModifyObject(const vector &)
Definition: boxScaling.C:102
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
boxScaling.H
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
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::boxScaling::scaleVec_
vector scaleVec_
scaling factors in all directions
Definition: boxScaling.H:62
Foam::coordinateModification::name
const word & name() const
Return name.
Definition: coordinateModification.H:130
Foam::boxScaling::operator<<
Ostream & operator<<(Ostream &) const
Definition: boxScaling.C:338
coordinateModification
Base class for modifiers of point coordinates.
Foam::Ostream::writeKeyword
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
Foam::boxScaling::pMin_
point pMin_
min point
Definition: boxScaling.H:65
Foam::boxScaling::boundingPlanes
virtual void boundingPlanes(PtrList< plane > &) const
Definition: boxScaling.C:152
Foam::PtrList::setSize
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:142
Foam::coordinateModification
Definition: coordinateModification.H:55
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::boxScaling::dict
dictionary dict(bool ignoreType=false) const
Return as dictionary of entries.
Definition: boxScaling.C:179
Foam::token::BEGIN_BLOCK
@ BEGIN_BLOCK
Definition: token.H:104
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
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::boxScaling::pMax_
point pMax_
max point
Definition: boxScaling.H:68
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::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
boxScaling
Checks if a box is contained inside the box object.
Foam::dictionary::add
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:729
Foam::boxScaling::centre_
point centre_
centre of the box
Definition: boxScaling.H:56
Foam::boxScaling::displacement
virtual vector displacement(const point &) const
calculate the displacement vector for box scaling
Definition: boxScaling.C:112