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 "lineRefinement.H"
27 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(lineRefinement, 0);
36 addToRunTimeSelectionTable(objectRefinement, lineRefinement, dictionary);
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 lineRefinement::lineRefinement()
47 lineRefinement::lineRefinement
50 const scalar cellSize,
60 setCellSize(cellSize);
63 lineRefinement::lineRefinement
66 const dictionary& dict
69 objectRefinement(name, dict)
71 this->operator=(dict);
74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 bool lineRefinement::intersectsObject(const boundBox& bb) const
78 //- check if the cube contains start point or end point
79 const scalar l = bb.max().x() - bb.min().x();
81 const point min = bb.min() - l * vector(SMALL, SMALL, SMALL);
82 const point max = bb.max() + l * vector(SMALL, SMALL, SMALL);
84 //- check for intersections of line with the cube faces
85 const vector v(p1_ - p0_);
86 if( mag(v.x()) > SMALL )
89 ((p0_.x() < min.x()) && (p1_.x() < min.x())) ||
90 ((p0_.x() > max.x()) && (p1_.x() > max.x()))
96 const vector n(-1, 0, 0);
97 const scalar t = (n & (min - p0_)) / (n & v);
98 const point i = p0_ + t * v;
100 (t > -SMALL) && (t < (1.0+SMALL))
103 (i.y() > min.y()) && (i.y() < max.y()) &&
104 (i.z() > min.z()) && (i.z() < max.z())
110 const vector n(1, 0, 0);
111 const scalar t = (n & (max - p0_)) / (n & v);
112 const point i = p0_ + t * v;
114 (t > -SMALL) && (t < (1.0+SMALL))
117 (i.y() > min.y()) && (i.y() < max.y()) &&
118 (i.z() > min.z()) && (i.z() < max.z())
124 if( mag(v.y()) > SMALL)
127 ((p0_.y() < min.y()) && (p1_.y() < min.y())) ||
128 ((p0_.y() > max.y()) && (p1_.y() > max.y()))
134 const vector n(0, -1, 0);
135 const scalar t = (n & (min - p0_)) / (n & v);
136 const point i = p0_ + t * v;
138 (t > -SMALL) && (t < (1.0+SMALL))
141 (i.x() > min.x()) && (i.x() < max.x()) &&
142 (i.z() > min.z()) && (i.z() < max.z())
148 const vector n(0, 1, 0);
149 const scalar t = (n & (max - p0_)) / (n & v);
150 const point i = p0_ + t * v;
152 (t > -SMALL) && (t < (1.0+SMALL))
155 (i.x() > min.x()) && (i.x() < max.x()) &&
156 (i.z() > min.z()) && (i.z() < max.z())
161 if( mag(v.z()) > SMALL )
164 ((p0_.z() < min.z()) && (p1_.z() < min.z())) ||
165 ((p0_.z() > max.z()) && (p1_.z() > max.z()))
171 const vector n(0, 0, -1);
172 const scalar t = (n & (min - p0_)) / (n & v);
173 const point i = p0_ + t * v;
175 (t > -SMALL) && (t < (1.0+SMALL)) &&
176 (i.x() > min.x()) && (i.x() < max.x()) &&
177 (i.y() > min.y()) && (i.y() < max.y())
183 const vector n(0, 0, 1);
184 const scalar t = (n & (max - p0_)) / (n & v);
185 const point i = p0_ + t * v;
187 (t > -SMALL) && (t < (1.0+SMALL)) &&
188 (i.x() > min.x()) && (i.x() < max.x()) &&
189 (i.y() > min.y()) && (i.y() < max.y())
196 (p0_.x() > min.x()) && (p0_.x() < max.x()) &&
197 (p0_.y() > min.y()) && (p0_.y() < max.y()) &&
198 (p0_.z() > min.z()) && (p0_.z() < max.z())
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 dictionary lineRefinement::dict(bool ignoreType) const
211 dict.add("cellSize", cellSize());
212 dict.add("type", type());
220 void lineRefinement::write(Ostream& os) const
222 os << " type: " << type()
227 void lineRefinement::writeDict(Ostream& os, bool subDict) const
231 os << indent << token::BEGIN_BLOCK << incrIndent << nl;
234 os.writeKeyword("cellSize") << cellSize() << token::END_STATEMENT << nl;
236 // only write type for derived types
237 if( type() != typeName_() )
239 os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
242 os.writeKeyword("p0") << p0_ << token::END_STATEMENT << nl;
243 os.writeKeyword("p1") << p1_ << token::END_STATEMENT << nl;
247 os << decrIndent << indent << token::END_BLOCK << endl;
251 void lineRefinement::operator=(const dictionary& d)
253 // allow as embedded sub-dictionary "coordinateSystem"
254 const dictionary& dict =
257 ? d.subDict(typeName_())
261 // unspecified centre is (0 0 0)
262 if( dict.found("p0") )
264 dict.lookup("p0") >> p0_;
270 "void lineRefinement::operator=(const dictionary& d)"
271 ) << "Entry p0 is not specified!" << exit(FatalError);
276 if( dict.found("p1") )
278 dict.lookup("p1") >> p1_;
284 "void lineRefinement::operator=(const dictionary& d)"
285 ) << "Entry p1 is not specified!" << exit(FatalError);
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 Ostream& lineRefinement::operator<<(Ostream& os) const
294 os << "name " << name() << nl;
295 os << "cell size " << cellSize() << nl;
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
302 } // End namespace Foam
304 // ************************************************************************* //