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 "boxScaling.H"
27 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(boxScaling, 0);
37 addToRunTimeSelectionTable(coordinateModification, boxScaling, dictionary);
39 // * * * * * * * * * * * * * * Private member functions* * * * * * * * * * * //
41 void boxScaling::calculateBndBox()
43 pMin_ = centre_ - 0.5 * lengthVec_;
44 pMax_ = centre_ + 0.5 * lengthVec_;
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 boxScaling::boxScaling()
51 coordinateModification(),
53 lengthVec_(0.0, 0.0, 0.0),
54 scaleVec_(1.0, 1.0, 1.0),
61 boxScaling::boxScaling
73 coordinateModification(),
75 lengthVec_(lengthX, lengthY, lengthZ),
76 scaleVec_(scaleX, scaleY, scaleZ),
84 boxScaling::boxScaling
87 const dictionary& dict
90 coordinateModification(name, dict)
92 this->operator=(dict);
95 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97 point boxScaling::origin() const
102 void boxScaling::translateAndModifyObject(const vector& disp)
106 for(direction i=0;i<vector::nComponents;++i)
107 lengthVec_[i] /= scaleVec_[i];
112 vector boxScaling::displacement(const point& p) const
116 for(direction i=0;i<vector::nComponents;++i)
118 const scalar dispVec = lengthVec_[i] * ((1.0/scaleVec_[i]) - 1.0);
119 const scalar t = ((p[i] - pMin_[i]) / lengthVec_[i]);
121 const scalar tBnd = Foam::max(0.0, Foam::min(t, 1.0));
123 disp[i] = tBnd * dispVec;
129 vector boxScaling::backwardDisplacement(const point& p) const
133 for(direction i=0;i<vector::nComponents;++i)
135 const scalar dispVec = lengthVec_[i] * (scaleVec_[i] - 1.0);
137 const scalar t = ((p[i] - pMin_[i]) / lengthVec_[i]);
139 const scalar tBnd = Foam::max(0.0, Foam::min(t, 1.0));
141 disp[i] = tBnd * dispVec;
147 bool boxScaling::combiningPossible() const
152 void boxScaling::boundingPlanes(PtrList<plane>&pl) const
156 if( Foam::mag(scaleVec_.x() - 1.0) > VSMALL )
158 pl.set(counter++, new plane(pMin_, vector(1, 0, 0)));
159 pl.set(counter++, new plane(pMax_, vector(1, 0, 1)));
162 if( Foam::mag(scaleVec_.y() - 1.0) > VSMALL )
164 pl.set(counter++, new plane(pMin_, vector(0, 1, 0)));
165 pl.set(counter++, new plane(pMax_, vector(0, 1, 0)));
168 if( Foam::mag(scaleVec_.z() - 1.0) > VSMALL )
170 pl.set(counter++, new plane(pMin_, vector(0, 0, 1)));
171 pl.set(counter++, new plane(pMax_, vector(0, 0, 1)));
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 dictionary boxScaling::dict(bool ignoreType) const
183 dict.add("type", type());
185 dict.add("centre", centre_);
186 dict.add("lengthX", lengthVec_.x());
187 dict.add("lengthY", lengthVec_.y());
188 dict.add("lengthZ", lengthVec_.z());
190 dict.add("scaleX", scaleVec_.x());
191 dict.add("scaleY", scaleVec_.y());
192 dict.add("scaleZ", scaleVec_.z());
197 void boxScaling::write(Ostream& os) const
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()
210 void boxScaling::writeDict(Ostream& os, bool subDict) const
214 os << indent << token::BEGIN_BLOCK << incrIndent << nl;
217 // only write type for derived types
218 if( type() != typeName_() )
220 os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
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;
233 os << decrIndent << indent << token::END_BLOCK << endl;
237 void boxScaling::operator=(const dictionary& d)
239 // allow as embedded sub-dictionary "coordinateSystem"
240 const dictionary& dict =
243 ? d.subDict(typeName_())
247 // unspecified centre is (0 0 0)
248 if( dict.found("centre") )
250 dict.lookup("centre") >> centre_;
256 "void boxScaling::operator=(const dictionary& d)"
257 ) << "Entry centre is not specified!" << exit(FatalError);
258 centre_ = vector::zero;
262 if( dict.found("lengthX") )
264 lengthVec_.x() = readScalar(dict.lookup("lengthX"));
270 "void boxScaling::operator=(const dictionary& d)"
271 ) << "Entry lengthX is not specified!" << exit(FatalError);
272 lengthVec_.x() = 0.0;
276 if( dict.found("lengthY") )
278 lengthVec_.y() = readScalar(dict.lookup("lengthY"));
284 "void boxScaling::operator=(const dictionary& d)"
285 ) << "Entry lengthY is not specified!" << exit(FatalError);
286 lengthVec_.y() = 0.0;
290 if( dict.found("lengthZ") )
292 lengthVec_.z() = readScalar(dict.lookup("lengthZ"));
298 "void boxScaling::operator=(const dictionary& d)"
299 ) << "Entry lengthZ is not specified!" << exit(FatalError);
300 lengthVec_.z() = 0.0;
304 if( dict.found("scaleX") )
306 scaleVec_.x() = readScalar(dict.lookup("scaleX"));
314 if( dict.found("scaleY") )
316 scaleVec_.y() = readScalar(dict.lookup("scaleY"));
324 if( dict.found("scaleZ") )
326 scaleVec_.z() = readScalar(dict.lookup("scaleZ"));
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 Ostream& boxScaling::operator<<(Ostream& os) const
340 os << "name " << name() << nl;
345 Ostream& operator<<(Ostream& os, const boxScaling& bs)
347 return bs.operator<<(os);
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
352 } // End namespace Foam
354 // ************************************************************************* //