meshOctreeAutomaticRefinement.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
29 #include "demandDrivenData.H"
30 #include "triSurfacePartitioner.H"
32 #include "meshOctreeAddressing.H"
33 #include "IOdictionary.H"
34 #include "triSurf.H"
35 
36 // #define DEBUGSearch
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
44 {
47 }
48 
50 const
51 {
53  {
54  # ifdef USE_OMP
55  if( omp_in_parallel() )
57  (
58  "const meshOctreeAddressing& meshOctreeAutomaticRefinement"
59  "::octreeAddressing() const"
60  ) << "Cannot calculate addressing!" << abort(FatalError);
61  # endif
62 
64  }
65 
66  return *octreeAddressingPtr_;
67 }
68 
70 {
72 }
73 
75 {
76  if( !partitionerPtr_ )
77  {
78  # ifdef USE_OMP
79  if( omp_in_parallel() )
81  (
82  "const triSurfacePartitioner& meshOctreeAutomaticRefinement"
83  "::partitioner() const"
84  ) << "Cannot calculate addressing!" << abort(FatalError);
85  # endif
86 
88  }
89 
90  return *partitionerPtr_;
91 }
92 
94 {
96 }
97 
99 const
100 {
101  if( !curvaturePtr_ )
102  {
103  # ifdef USE_OMP
104  if( omp_in_parallel() )
106  (
107  "const triSurfaceCurvatureEstimator& "
108  "meshOctreeAutomaticRefinement::curvature() const"
109  ) << "Cannot calculate addressing!" << abort(FatalError);
110  # endif
111 
113  }
114 
115  return *curvaturePtr_;
116 }
117 
119 {
120  const boundBox& rootBox = octree_.rootBox();
121  const scalar size = rootBox.max().x() - rootBox.min().x();
122  maxRefLevel_ = 0;
123 
124  if( meshDict_.found("minCellSize") )
125  {
126  const scalar maxSize(readScalar(meshDict_.lookup("maxCellSize")));
127  scalar cs(readScalar(meshDict_.lookup("minCellSize")));
128  cs *= (1.0 + SMALL);
129 
130  if( cs > maxSize )
131  return;
132 
133  bool finished;
134  do
135  {
136  finished = false;
137 
138  const scalar lSize = size / pow(2, label(maxRefLevel_));
139 
140  if( lSize < cs )
141  {
142  finished = true;
143  }
144  else
145  {
146  ++maxRefLevel_;
147  }
148  } while( !finished );
149 
150  useDATABoxes_ = true;
151 
152  Info << "Requested min cell size corresponds to octree level "
153  << label(maxRefLevel_) << endl;
154  }
155 }
156 
157 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
158 
159 // Construct from surface and IOdictionary
161 (
162  meshOctree& mo,
163  const IOdictionary& dict,
164  bool useDATABoxes
165 )
166 :
167  octree_(mo),
168  meshDict_(dict),
169  useDATABoxes_(useDATABoxes),
170  hexRefinement_(false),
171  octreeAddressingPtr_(NULL),
172  partitionerPtr_(NULL),
173  curvaturePtr_(NULL),
174  maxRefLevel_(0)
175 {
176  if( !useDATABoxes_ && dict.found("keepCellsIntersectingBoundary") )
177  {
178  useDATABoxes_ = readBool(dict.lookup("keepCellsIntersectingBoundary"));
179  }
180 
181  //- calculate maximum allowed refinement level from the minimum cell size
182  setMaxRefLevel();
183 }
184 
185 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
186 
188 {
192 }
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 } // End namespace Foam
197 
198 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::meshOctreeAutomaticRefinement::octreeAddressingPtr_
meshOctreeAddressing * octreeAddressingPtr_
meshOctreeAddressing pointer
Definition: meshOctreeAutomaticRefinement.H:73
Foam::triSurfacePartitioner
Definition: triSurfacePartitioner.H:53
triSurf.H
Foam::meshOctreeAutomaticRefinement::meshOctreeAutomaticRefinement
meshOctreeAutomaticRefinement(const meshOctreeAutomaticRefinement &)
Disallow default bitwise copy construct.
Foam::meshOctreeAutomaticRefinement::curvature
const triSurfaceCurvatureEstimator & curvature() const
Definition: meshOctreeAutomaticRefinement.C:98
Foam::meshOctreeAutomaticRefinement::~meshOctreeAutomaticRefinement
~meshOctreeAutomaticRefinement()
Definition: meshOctreeAutomaticRefinement.C:187
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
Foam::meshOctreeAutomaticRefinement::meshDict_
const IOdictionary & meshDict_
const reference to mesh dictionary
Definition: meshOctreeAutomaticRefinement.H:63
triSurfacePartitioner.H
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
triSurfaceCurvatureEstimator.H
Foam::meshOctreeAutomaticRefinement::octree_
meshOctree & octree_
reference to meshOctree
Definition: meshOctreeAutomaticRefinement.H:60
Foam::meshOctreeAutomaticRefinement::octreeAddressing
const meshOctreeAddressing & octreeAddressing() const
Definition: meshOctreeAutomaticRefinement.C:49
meshOctreeAutomaticRefinement.H
Foam::meshOctreeAutomaticRefinement::createOctreeAddressing
void createOctreeAddressing() const
calculate octree addresing
Definition: meshOctreeAutomaticRefinement.C:43
Foam::meshOctreeAutomaticRefinement::maxRefLevel_
direction maxRefLevel_
maximum allowed refinement level
Definition: meshOctreeAutomaticRefinement.H:95
Foam::meshOctreeAutomaticRefinement::createCurvatureEstimator
void createCurvatureEstimator() const
calculate curvaturePtr_
Definition: meshOctreeAutomaticRefinement.C:93
Foam::meshOctreeAutomaticRefinement::useDATABoxes_
bool useDATABoxes_
use DATA boxes
Definition: meshOctreeAutomaticRefinement.H:66
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
Foam::meshOctreeAutomaticRefinement::setMaxRefLevel
void setMaxRefLevel()
set maxRefLevel_
Definition: meshOctreeAutomaticRefinement.C:118
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::Info
messageStream Info
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
Foam::meshOctreeAutomaticRefinement::partitionerPtr_
triSurfacePartitioner * partitionerPtr_
surface partitioner pointer
Definition: meshOctreeAutomaticRefinement.H:80
Foam::pow
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Definition: dimensionedScalar.C:73
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam::meshOctreeAutomaticRefinement::curvaturePtr_
triSurfaceCurvatureEstimator * curvaturePtr_
curvature estimator pointer
Definition: meshOctreeAutomaticRefinement.H:87
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
meshOctreeAddressing.H
IOdictionary.H
Foam::meshOctreeAddressing
Definition: meshOctreeAddressing.H:59
Foam::meshOctree::rootBox
const boundBox & rootBox() const
return rootBox
Definition: meshOctreeI.H:135
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
Foam::meshOctree
Definition: meshOctree.H:55
Foam::meshOctreeAutomaticRefinement::partitioner
const triSurfacePartitioner & partitioner() const
Definition: meshOctreeAutomaticRefinement.C:74
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::readBool
bool readBool(Istream &)
Definition: boolIO.C:60
Foam::meshOctreeAutomaticRefinement::createSurfacePartitioner
void createSurfacePartitioner() const
calculate partitionerPtr_
Definition: meshOctreeAutomaticRefinement.C:69
Foam::meshOctree::surface
const triSurf & surface() const
return a reference to the surface
Definition: meshOctreeI.H:130
Foam::triSurfaceCurvatureEstimator
Definition: triSurfaceCurvatureEstimator.H:51