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 "coneRefinement.H"
27 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(coneRefinement, 0);
36 addToRunTimeSelectionTable(objectRefinement, coneRefinement, dictionary);
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 coneRefinement::coneRefinement()
49 coneRefinement::coneRefinement
52 const scalar cellSize,
66 setCellSize(cellSize);
69 coneRefinement::coneRefinement
72 const dictionary& dict
75 objectRefinement(name, dict)
77 this->operator=(dict);
80 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82 bool coneRefinement::intersectsObject(const boundBox& bb) const
84 //- check if the centre is inside the cone
85 const point c = (bb.max() + bb.min()) / 2.0;
87 const vector v = p1_ - p0_;
88 const scalar d = magSqr(v);
93 const scalar t = ((c - p0_) & v) / d;
94 if( (t > 1.0) || (t < 0.0) )
97 const scalar r = r0_ + (r1_ - r0_) * t;
99 if( mag(p0_ + t * v - c) < r )
105 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
107 dictionary coneRefinement::dict(bool ignoreType) const
111 dict.add("cellSize", cellSize());
112 dict.add("type", type());
115 dict.add("radius0", r0_);
117 dict.add("radius1", r1_);
122 void coneRefinement::write(Ostream& os) const
124 os << " type: " << type()
126 << " radius0: " << r0_
128 << " radius1: " << r1_;
131 void coneRefinement::writeDict(Ostream& os, bool subDict) const
135 os << indent << token::BEGIN_BLOCK << incrIndent << nl;
138 os.writeKeyword("cellSize") << cellSize() << token::END_STATEMENT << nl;
140 // only write type for derived types
141 if( type() != typeName_() )
143 os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
146 os.writeKeyword("p0") << p0_ << token::END_STATEMENT << nl;
147 os.writeKeyword("radius0") << r0_ << token::END_STATEMENT << nl;
148 os.writeKeyword("p1") << p1_ << token::END_STATEMENT << nl;
149 os.writeKeyword("radius1") << r1_ << token::END_STATEMENT << nl;
153 os << decrIndent << indent << token::END_BLOCK << endl;
157 void coneRefinement::operator=(const dictionary& d)
159 // allow as embedded sub-dictionary "coordinateSystem"
160 const dictionary& dict =
163 ? d.subDict(typeName_())
167 // unspecified centre is (0 0 0)
168 if( dict.found("p0") )
170 dict.lookup("p0") >> p0_;
176 "void coneRefinement::operator=(const dictionary& d)"
177 ) << "Entry p0 is not specified!" << exit(FatalError);
182 if( dict.found("radius0") )
184 r0_ = readScalar(dict.lookup("radius0"));
190 "void coneRefinement::operator=(const dictionary& d)"
191 ) << "Entry radius0 is not specified!" << exit(FatalError);
195 // unspecified centre is (0 0 0)
196 if( dict.found("p1") )
198 dict.lookup("p1") >> p1_;
204 "void coneRefinement::operator=(const dictionary& d)"
205 ) << "Entry p1 is not specified!" << exit(FatalError);
210 if( dict.found("radius1") )
212 r1_ = readScalar(dict.lookup("radius1"));
218 "void coneRefinement::operator=(const dictionary& d)"
219 ) << "Entry radius1 is not specified!" << exit(FatalError);
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 Ostream& coneRefinement::operator<<(Ostream& os) const
228 os << "name " << name() << nl;
229 os << "cell size " << cellSize() << nl;
234 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 } // End namespace Foam
238 // ************************************************************************* //