planeScaling.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 "planeScaling.H"
28 #include "boundBox.H"
29 #include "plane.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
38 (
41  dictionary
42 );
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
47 :
49  origin_(vector::zero),
50  normal_(1, 1, 1),
51  scalingDistance_(0.0),
52  scalingFactor_(1.0)
53 {}
54 
56 (
57  const word& name,
58  const point& origin,
59  const vector& normal,
60  const scalar scalingDistance,
61  const scalar scalingFactor
62 )
63 :
65  origin_(origin),
66  normal_(normal/mag(normal)),
67  scalingDistance_(scalingDistance),
68  scalingFactor_(scalingFactor)
69 {
70  if( scalingFactor_ < SMALL )
71  {
72  Warning << "Scaling factor for plane " << name << " is less than 0.0 "
73  << endl;
74 
75  scalingFactor_= 1.0;
76  }
77 
78  setName(name);
79 }
80 
82 (
83  const word& name,
84  const dictionary& dict
85 )
86 :
88 {
89  this->operator=(dict);
90 }
91 
92 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93 
95 {
96  return origin_;
97 }
98 
100 {
101  origin_ += disp;
102 
104 }
105 
107 {
108  const scalar dist = (p - origin_) & normal_;
109 
110  const vector translationVec =
111  normal_ * scalingDistance_ * ((1.0/scalingFactor_) - 1.0);
112 
113  const scalar t = dist / scalingDistance_;
114 
115  const scalar tBnd = Foam::max(0.0, Foam::min(1.0, t));
116 
117  return tBnd * translationVec;
118 }
119 
121 {
122  const scalar dist = (p - origin_) & normal_;
123 
124  const vector translationVec =
126 
127  const scalar t = dist / scalingDistance_;
128 
129  const scalar tBnd = Foam::max(0.0, Foam::min(1.0, t));
130 
131  return tBnd * translationVec;
132 }
133 
135 {
136  return true;
137 }
138 
140 {
141  if( Foam::mag(scalingFactor_ - 1.0) > VSMALL )
142  {
143  pl.setSize(2);
144 
145  pl.set(0, new plane(origin_, normal_));
146  pl.set(1, new plane(origin_ + scalingDistance_ * normal_, normal_));
147  }
148  else
149  {
150  pl.clear();
151  }
152 }
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 dictionary planeScaling::dict(bool /*ignoreType*/) const
157 {
159 
160  dict.add("type", type());
161 
162  dict.add("origin", origin_);
163  dict.add("normal", normal_);
164  dict.add("scalingDistance", scalingDistance_);
165  dict.add("scalingFactor", scalingFactor_);
166 
167  return dict;
168 }
169 
171 {
172  os << " type: " << type()
173  << " origin: " << origin_
174  << " normal: " << normal_
175  << " scalingDistance: " << scalingDistance_
176  << " scalingFactor: " << scalingFactor_;
177 }
178 
179 void planeScaling::writeDict(Ostream& os, bool subDict) const
180 {
181  if( subDict )
182  {
183  os << indent << token::BEGIN_BLOCK << incrIndent << nl;
184  }
185 
186  // only write type for derived types
187  if( type() != typeName_() )
188  {
189  os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
190  }
191 
192  os.writeKeyword("origin") << origin_ << token::END_STATEMENT << nl;
193  os.writeKeyword("normal") << normal_ << token::END_STATEMENT << nl;
194  os.writeKeyword("scalingDistance") << scalingDistance_
195  << token::END_STATEMENT << nl;
196  os.writeKeyword("scalingFactor") << scalingFactor_
197  << token::END_STATEMENT << nl;
198 
199  if( subDict )
200  {
201  os << decrIndent << indent << token::END_BLOCK << endl;
202  }
203 }
204 
206 {
207  // allow as embedded sub-dictionary "coordinateSystem"
208  const dictionary& dict =
209  (
210  d.found(typeName_())
211  ? d.subDict(typeName_())
212  : d
213  );
214 
215  // unspecified centre is (0 0 0)
216  if( dict.found("origin") )
217  {
218  dict.lookup("origin") >> origin_;
219  }
220  else
221  {
223  (
224  "void planeScaling::operator=(const dictionary& d)"
225  ) << "Entry origin is not specified!" << exit(FatalError);
226 
228  }
229 
230  // specify normal
231  if( dict.found("normal") )
232  {
233  dict.lookup("normal") >> normal_;
234  }
235  else
236  {
238  (
239  "void planeScaling::operator=(const dictionary& d)"
240  ) << "Entry lengthX is not specified!" << exit(FatalError);
241 
242  normal_ = vector(1, 1, 1);
243  }
244 
245  // specify translation distance
246  if( dict.found("scalingDistance") )
247  {
248  scalingDistance_ = readScalar(dict.lookup("scalingDistance"));
249  }
250  else
251  {
253  (
254  "void planeScaling::operator=(const dictionary& d)"
255  ) << "Entry scalingDistance is not specified!" << exit(FatalError);
256 
257  scalingDistance_ = 0.0;
258  }
259 
260  // specify scaling factor
261  if( dict.found("scalingFactor") )
262  {
263  scalingFactor_ = readScalar(dict.lookup("scalingFactor"));
264  }
265  else
266  {
267  WarningIn
268  (
269  "void planeScaling::operator=(const dictionary& d)"
270  ) << "Entry scalingFactor is not specified!" << endl;
271 
272  scalingFactor_ = 1.0;
273  }
274 }
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
279 {
280  os << "name " << name() << nl;
281  write(os);
282  return os;
283 }
284 
286 {
287  return pt.operator<<(os);
288 }
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 } // End namespace Foam
293 
294 // ************************************************************************* //
Foam::planeScaling::writeDict
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
Definition: planeScaling.C:179
Foam::planeScaling::scalingFactor_
scalar scalingFactor_
scaling factor
Definition: planeScaling.H:64
Foam::planeScaling::origin_
point origin_
origin of the plane
Definition: planeScaling.H:55
Foam::planeScaling::backwardDisplacement
virtual vector backwardDisplacement(const point &) const
calculate the displacement vector for plane translation
Definition: planeScaling.C:120
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::planeScaling::boundingPlanes
virtual void boundingPlanes(PtrList< plane > &) const
Definition: planeScaling.C:139
Foam::planeScaling
Definition: planeScaling.H:49
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::Warning
messageStream Warning
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::planeScaling::displacement
virtual vector displacement(const point &) const
calculate the displacement vector for plane translation
Definition: planeScaling.C:106
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::planeScaling::write
void write(Ostream &) const
Write.
Definition: planeScaling.C:170
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::PtrList::set
bool set(const label) const
Is element set.
Foam::planeScaling::translateAndModifyObject
virtual void translateAndModifyObject(const vector &)
Definition: planeScaling.C:99
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::nl
static const char nl
Definition: Ostream.H:260
Foam::planeScaling::planeScaling
planeScaling()
Null construct.
Definition: planeScaling.C:46
Foam::planeScaling::dict
dictionary dict(bool ignoreType=false) const
Return as dictionary of entries.
Definition: planeScaling.C:156
planeScaling
Applies scaling to points on the positive side of the plane within the scaling distance.
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
Foam::planeScaling::combiningPossible
virtual bool combiningPossible() const
can this modification object be combined with other ones
Definition: planeScaling.C:134
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::PtrList::clear
void clear()
Clear the PtrList, i.e. set size to zero deleting all the.
Definition: PtrList.C:185
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::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
Foam::planeScaling::scalingDistance_
scalar scalingDistance_
scaling distance
Definition: planeScaling.H:61
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
boundBox.H
Foam::planeScaling::origin
virtual point origin() const
return the origin of the plane
Definition: planeScaling.C:94
planeScaling.H
Foam::planeScaling::normal_
vector normal_
normal vector
Definition: planeScaling.H:58
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::coordinateModification::name
const word & name() const
Return name.
Definition: coordinateModification.H:130
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::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::planeScaling::operator<<
Ostream & operator<<(Ostream &) const
Definition: planeScaling.C:278
Foam::token::BEGIN_BLOCK
@ BEGIN_BLOCK
Definition: token.H:104
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
WarningIn
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Definition: messageStream.H:254
Foam::planeScaling::operator=
void operator=(const dictionary &)
assign from dictionary
Definition: planeScaling.C:205
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::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
normal
A normal distribution model.
Foam::zero
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:47