1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "planeScaling.H"
27 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(planeScaling, 0);
37 addToRunTimeSelectionTable
39 coordinateModification,
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 planeScaling::planeScaling()
48 coordinateModification(),
49 origin_(vector::zero),
51 scalingDistance_(0.0),
55 planeScaling::planeScaling
60 const scalar scalingDistance,
61 const scalar scalingFactor
64 coordinateModification(),
66 normal_(normal/mag(normal)),
67 scalingDistance_(scalingDistance),
68 scalingFactor_(scalingFactor)
70 if( scalingFactor_ < SMALL )
72 Warning << "Scaling factor for plane " << name << " is less than 0.0 "
81 planeScaling::planeScaling
84 const dictionary& dict
87 coordinateModification(name, dict)
89 this->operator=(dict);
92 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 point planeScaling::origin() const
99 void planeScaling::translateAndModifyObject(const vector& disp)
103 scalingDistance_ /= scalingFactor_;
106 vector planeScaling::displacement(const point& p) const
108 const scalar dist = (p - origin_) & normal_;
110 const vector translationVec =
111 normal_ * scalingDistance_ * ((1.0/scalingFactor_) - 1.0);
113 const scalar t = dist / scalingDistance_;
115 const scalar tBnd = Foam::max(0.0, Foam::min(1.0, t));
117 return tBnd * translationVec;
120 vector planeScaling::backwardDisplacement(const point& p) const
122 const scalar dist = (p - origin_) & normal_;
124 const vector translationVec =
125 normal_ * scalingDistance_ * (scalingFactor_ - 1.0);
127 const scalar t = dist / scalingDistance_;
129 const scalar tBnd = Foam::max(0.0, Foam::min(1.0, t));
131 return tBnd * translationVec;
134 bool planeScaling::combiningPossible() const
139 void planeScaling::boundingPlanes(PtrList<plane>& pl) const
141 if( Foam::mag(scalingFactor_ - 1.0) > VSMALL )
145 pl.set(0, new plane(origin_, normal_));
146 pl.set(1, new plane(origin_ + scalingDistance_ * normal_, normal_));
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 dictionary planeScaling::dict(bool ignoreType) const
160 dict.add("type", type());
162 dict.add("origin", origin_);
163 dict.add("normal", normal_);
164 dict.add("scalingDistance", scalingDistance_);
165 dict.add("scalingFactor", scalingFactor_);
170 void planeScaling::write(Ostream& os) const
172 os << " type: " << type()
173 << " origin: " << origin_
174 << " normal: " << normal_
175 << " scalingDistance: " << scalingDistance_
176 << " scalingFactor: " << scalingFactor_;
179 void planeScaling::writeDict(Ostream& os, bool subDict) const
183 os << indent << token::BEGIN_BLOCK << incrIndent << nl;
186 // only write type for derived types
187 if( type() != typeName_() )
189 os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
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;
201 os << decrIndent << indent << token::END_BLOCK << endl;
205 void planeScaling::operator=(const dictionary& d)
207 // allow as embedded sub-dictionary "coordinateSystem"
208 const dictionary& dict =
211 ? d.subDict(typeName_())
215 // unspecified centre is (0 0 0)
216 if( dict.found("origin") )
218 dict.lookup("origin") >> origin_;
224 "void planeScaling::operator=(const dictionary& d)"
225 ) << "Entry origin is not specified!" << exit(FatalError);
227 origin_ = vector::zero;
231 if( dict.found("normal") )
233 dict.lookup("normal") >> normal_;
239 "void planeScaling::operator=(const dictionary& d)"
240 ) << "Entry lengthX is not specified!" << exit(FatalError);
242 normal_ = vector(1, 1, 1);
245 // specify translation distance
246 if( dict.found("scalingDistance") )
248 scalingDistance_ = readScalar(dict.lookup("scalingDistance"));
254 "void planeScaling::operator=(const dictionary& d)"
255 ) << "Entry scalingDistance is not specified!" << exit(FatalError);
257 scalingDistance_ = 0.0;
260 // specify scaling factor
261 if( dict.found("scalingFactor") )
263 scalingFactor_ = readScalar(dict.lookup("scalingFactor"));
269 "void planeScaling::operator=(const dictionary& d)"
270 ) << "Entry scalingFactor is not specified!" << endl;
272 scalingFactor_ = 1.0;
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278 Ostream& planeScaling::operator<<(Ostream& os) const
280 os << "name " << name() << nl;
285 Ostream& operator<<(Ostream& os, const planeScaling& pt)
287 return pt.operator<<(os);
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 } // End namespace Foam
294 // ************************************************************************* //