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,
53 const direction additionalRefLevels,
67 setCellSize(cellSize);
68 setAdditionalRefinementLevels(additionalRefLevels);
71 coneRefinement::coneRefinement
74 const dictionary& dict
77 objectRefinement(name, dict)
79 this->operator=(dict);
82 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84 bool coneRefinement::intersectsObject(const boundBox& bb) const
86 //- check if the centre is inside the cone
87 const point c = (bb.max() + bb.min()) / 2.0;
89 const vector v = p1_ - p0_;
90 const scalar d = magSqr(v);
95 const scalar t = ((c - p0_) & v) / d;
96 if( (t > 1.0) || (t < 0.0) )
99 const scalar r = r0_ + (r1_ - r0_) * t;
101 if( mag(p0_ + t * v - c) < r )
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
109 dictionary coneRefinement::dict(bool ignoreType) const
113 if( additionalRefinementLevels() == 0 && cellSize() >= 0.0 )
115 dict.add("cellSize", cellSize());
119 dict.add("additionalRefinementLevels", additionalRefinementLevels());
122 dict.add("type", type());
125 dict.add("radius0", r0_);
127 dict.add("radius1", r1_);
132 void coneRefinement::write(Ostream& os) const
134 os << " type: " << type()
136 << " radius0: " << r0_
138 << " radius1: " << r1_;
141 void coneRefinement::writeDict(Ostream& os, bool subDict) const
145 os << indent << token::BEGIN_BLOCK << incrIndent << nl;
148 if( additionalRefinementLevels() == 0 && cellSize() >= 0.0 )
150 os.writeKeyword("cellSize") << cellSize() << token::END_STATEMENT << nl;
154 os.writeKeyword("additionalRefinementLevels")
155 << additionalRefinementLevels()
156 << token::END_STATEMENT << nl;
159 // only write type for derived types
160 if( type() != typeName_() )
162 os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
165 os.writeKeyword("p0") << p0_ << token::END_STATEMENT << nl;
166 os.writeKeyword("radius0") << r0_ << token::END_STATEMENT << nl;
167 os.writeKeyword("p1") << p1_ << token::END_STATEMENT << nl;
168 os.writeKeyword("radius1") << r1_ << token::END_STATEMENT << nl;
172 os << decrIndent << indent << token::END_BLOCK << endl;
176 void coneRefinement::operator=(const dictionary& d)
178 // allow as embedded sub-dictionary "coordinateSystem"
179 const dictionary& dict =
182 ? d.subDict(typeName_())
186 // unspecified centre is (0 0 0)
187 if( dict.found("p0") )
189 dict.lookup("p0") >> p0_;
195 "void coneRefinement::operator=(const dictionary& d)"
196 ) << "Entry p0 is not specified!" << exit(FatalError);
201 if( dict.found("radius0") )
203 r0_ = readScalar(dict.lookup("radius0"));
209 "void coneRefinement::operator=(const dictionary& d)"
210 ) << "Entry radius0 is not specified!" << exit(FatalError);
214 // unspecified centre is (0 0 0)
215 if( dict.found("p1") )
217 dict.lookup("p1") >> p1_;
223 "void coneRefinement::operator=(const dictionary& d)"
224 ) << "Entry p1 is not specified!" << exit(FatalError);
229 if( dict.found("radius1") )
231 r1_ = readScalar(dict.lookup("radius1"));
237 "void coneRefinement::operator=(const dictionary& d)"
238 ) << "Entry radius1 is not specified!" << exit(FatalError);
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 Ostream& coneRefinement::operator<<(Ostream& os) const
247 os << "name " << name() << nl;
248 os << "cell size " << cellSize() << nl;
249 os << "additionalRefinementLevels " << additionalRefinementLevels() << endl;
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 } // End namespace Foam
259 // ************************************************************************* //