1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "refinementFeatures.H"
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 Foam::refinementFeatures::refinementFeatures
33 const objectRegistry& io,
34 const PtrList<dictionary>& featDicts
37 PtrList<featureEdgeMesh>(featDicts.size()),
38 levels_(featDicts.size()),
39 edgeTrees_(featDicts.size()),
40 pointTrees_(featDicts.size())
46 const dictionary& dict = featDicts[i];
48 fileName featFileName(dict.lookup("file"));
58 io.time().constant(), // instance
59 "triSurface", // local
60 io.time(), // registry
68 const featureEdgeMesh& eMesh = operator[](i);
70 //eMesh.mergePoints(meshRefiner_.mergeDistance());
71 levels_[i] = readLabel(dict.lookup("level"));
73 Info<< "Refinement level " << levels_[i]
74 << " for all cells crossed by feature " << featFileName
75 << " (" << eMesh.points().size() << " points, "
76 << eMesh.edges().size() << " edges)." << endl;
84 const featureEdgeMesh& eMesh = operator[](i);
85 const pointField& points = eMesh.points();
86 const edgeList& edges = eMesh.edges();
88 // Calculate bb of all points
89 treeBoundBox bb(points);
91 // Random number generator. Bit dodgy since not exactly random ;-)
94 // Slightly extended bb. Slightly off-centred just so on symmetric
95 // geometry there are less face/edge aligned items.
96 bb = bb.extend(rndGen, 1E-4);
97 bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
98 bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
103 new indexedOctree<treeDataEdge>
107 false, // do not cache bb
110 identity(edges.size())
112 bb, // overall search domain
120 // Detect feature points from edges.
121 const labelListList& pointEdges = eMesh.pointEdges();
122 DynamicList<label> featurePoints;
123 forAll(pointEdges, pointI)
125 if (pointEdges[pointI].size() > 2)
127 featurePoints.append(pointI);
131 Info<< "Detected " << featurePoints.size()
132 << " featurePoints out of " << points.size()
133 << " on feature " << eMesh.name() << endl;
138 new indexedOctree<treeDataPoint>
140 treeDataPoint(points, featurePoints),
141 bb, // overall search domain
151 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
153 void Foam::refinementFeatures::findNearestEdge
155 const pointField& samples,
156 const scalarField& nearestDistSqr,
157 labelList& nearFeature,
158 List<pointIndexHit>& nearInfo
161 nearFeature.setSize(samples.size());
163 nearInfo.setSize(samples.size());
165 forAll(edgeTrees_, featI)
167 const indexedOctree<treeDataEdge>& tree = edgeTrees_[featI];
169 if (tree.shapes().size() > 0)
171 forAll(samples, sampleI)
173 const point& sample = samples[sampleI];
176 if (nearInfo[sampleI].hit())
178 distSqr = magSqr(nearInfo[sampleI].hitPoint()-sample);
182 distSqr = nearestDistSqr[sampleI];
185 pointIndexHit info = tree.findNearest(sample, distSqr);
189 nearInfo[sampleI] = info;
190 nearFeature[sampleI] = featI;
198 void Foam::refinementFeatures::findNearestPoint
200 const pointField& samples,
201 const scalarField& nearestDistSqr,
202 labelList& nearFeature,
206 nearFeature.setSize(samples.size());
208 nearIndex.setSize(samples.size());
211 forAll(pointTrees_, featI)
213 const indexedOctree<treeDataPoint>& tree = pointTrees_[featI];
215 if (tree.shapes().pointLabels().size() > 0)
217 forAll(samples, sampleI)
219 const point& sample = samples[sampleI];
222 if (nearFeature[sampleI] != -1)
224 label nearFeatI = nearFeature[sampleI];
225 const indexedOctree<treeDataPoint>& nearTree =
226 pointTrees_[nearFeatI];
228 nearTree.shapes().pointLabels()[nearIndex[sampleI]];
229 const point& featPt =
230 operator[](nearFeatI).points()[featPointI];
231 distSqr = magSqr(featPt-sample);
235 distSqr = nearestDistSqr[sampleI];
238 pointIndexHit info = tree.findNearest(sample, distSqr);
242 nearFeature[sampleI] = featI;
243 nearIndex[sampleI] = info.index();
251 // ************************************************************************* //