34 void Foam::refinementFeatures::read
36 const objectRegistry& io,
37 const PtrList<dictionary>& featDicts
42 const dictionary& dict = featDicts[featI];
44 fileName featFileName(dict.lookup(
"file"));
53 "extendedFeatureEdgeMesh",
60 const fileName fName(typeFilePath<extendedFeatureEdgeMesh>(extFeatObj));
69 Info<<
"Read extendedFeatureEdgeMesh " << extFeatObj.name()
71 eMeshPtr().writeStats(
Info);
74 set(featI,
new extendedFeatureEdgeMesh(extFeatObj, eMeshPtr()));
91 const fileName fName(typeFilePath<featureEdgeMesh>(featObj));
98 ) <<
"Could not open " << featObj.objectPath()
105 const edgeMesh& eMesh = eMeshPtr();
107 Info<<
"Read edgeMesh " << featObj.name() <<
nl 109 eMesh.writeStats(
Info);
117 labelList oldToNew(eMesh.points().size(), -1);
118 DynamicField<point> newPoints(eMesh.points().size());
119 forAll(pointEdges, pointi)
121 if (pointEdges[pointi].
size() > 2)
123 oldToNew[pointi] = newPoints.size();
124 newPoints.append(eMesh.points()[pointi]);
129 label nFeatures = newPoints.size();
132 if (oldToNew[pointi] == -1)
134 oldToNew[pointi] = newPoints.size();
135 newPoints.append(eMesh.points()[pointi]);
140 const edgeList& edges = eMesh.edges();
144 const edge&
e = edges[edgeI];
145 newEdges[edgeI] = edge
156 extendedEdgeMesh eeMesh
168 List<extendedEdgeMesh::sideVolumeType>(0),
182 set(featI,
new extendedFeatureEdgeMesh(featObj, eeMesh));
185 const extendedEdgeMesh& eMesh =
operator[](featI);
187 if (dict.found(
"levels"))
189 List<Tuple2<scalar, label>> distLevels(dict[
"levels"]);
194 <<
" : levels should be at least size 1" << endl
195 <<
"levels : " << dict[
"levels"]
199 distances_[featI].
setSize(distLevels.size());
200 levels_[featI].
setSize(distLevels.size());
204 distances_[featI][j] = distLevels[j].
first();
205 levels_[featI][j] = distLevels[j].second();
212 (distances_[featI][j] <= distances_[featI][j-1])
213 || (levels_[featI][j] > levels_[featI][j-1])
217 <<
" : Refinement should be specified in order" 218 <<
" of increasing distance" 219 <<
" (and decreasing refinement level)." << endl
220 <<
"Distance:" << distances_[featI][j]
221 <<
" refinementLevel:" << levels_[featI][j]
234 Info<<
"Refinement level according to distance to " 235 << featFileName <<
" (" << eMesh.points().size() <<
" points, " 236 << eMesh.edges().size() <<
" edges)." <<
endl;
239 Info<<
" level " << levels_[featI][j]
240 <<
" for all cells within " << distances_[featI][j]
241 <<
" metre." <<
endl;
247 void Foam::refinementFeatures::buildTrees(
const label featI)
249 const extendedEdgeMesh& eMesh =
operator[](featI);
251 const edgeList& edges = eMesh.edges();
254 treeBoundBox bb(points);
258 bb = bb.extend(1
e-4);
263 new indexedOctree<treeDataEdge>
285 new indexedOctree<treeDataPoint>
287 treeDataPoint(points, featurePoints),
298 void Foam::refinementFeatures::findHigherLevel
305 const labelList& levels = levels_[featI];
316 label candidateI = 0;
322 if (levels[levelI] > maxLevel[pointi])
324 candidates[candidateI] = pt[pointi];
325 candidateMap[candidateI] = pointi;
326 candidateDistSqr[candidateI] =
sqr(distances[levelI]);
332 candidates.setSize(candidateI);
333 candidateMap.setSize(candidateI);
334 candidateDistSqr.setSize(candidateI);
337 const indexedOctree<treeDataEdge>& tree = edgeTrees_[featI];
339 List<pointIndexHit>
nearInfo(candidates.size());
340 forAll(candidates, candidateI)
342 nearInfo[candidateI] = tree.findNearest
344 candidates[candidateI],
345 candidateDistSqr[candidateI]
350 forAll(nearInfo, candidateI)
352 if (nearInfo[candidateI].hit())
358 mag(nearInfo[candidateI].hitPoint()-candidates[candidateI])
361 label pointi = candidateMap[candidateI];
364 maxLevel[pointi] = levels[minDistI+1];
375 if (!regionEdgeTreesPtr_.valid())
377 regionEdgeTreesPtr_.reset
416 return regionEdgeTreesPtr_();
429 distances_(featDicts.
size()),
430 levels_(featDicts.
size()),
431 edgeTrees_(featDicts.
size()),
432 pointTrees_(featDicts.
size())
537 if (tree.
shapes().size() > 0)
541 const point& sample = samples[sampleI];
544 if (nearInfo[sampleI].hit())
546 distSqr =
magSqr(nearInfo[sampleI].hitPoint()-sample);
550 distSqr = nearestDistSqr[sampleI];
557 nearFeature[sampleI] = featI;
566 const edge&
e = td.edges()[nearInfo[sampleI].index()];
567 nearNormal[sampleI] = e.
vec(td.points());
568 nearNormal[sampleI] /=
mag(nearNormal[sampleI])+vSmall;
596 forAll(regionTrees, featI)
602 const point& sample = samples[sampleI];
605 if (nearInfo[sampleI].hit())
607 distSqr =
magSqr(nearInfo[sampleI].hitPoint()-sample);
611 distSqr = nearestDistSqr[sampleI];
615 pointIndexHit info = regionTree.findNearest(sample, distSqr);
621 nearFeature[sampleI] = featI;
629 const edge&
e = td.
edges()[nearInfo[sampleI].index()];
630 nearNormal[sampleI] = e.vec(td.
points());
631 nearNormal[sampleI] /=
mag(nearNormal[sampleI])+vSmall;
704 forAll(pointTrees_, featI)
708 if (tree.
shapes().pointLabels().size() > 0)
712 const point& sample = samples[sampleI];
715 if (nearFeature[sampleI] != -1)
717 distSqr =
magSqr(nearInfo[sampleI].hitPoint()-sample);
721 distSqr = nearestDistSqr[sampleI];
728 nearFeature[sampleI] = featI;
742 void Foam::refinementFeatures::findHigherLevel
754 findHigherLevel(pt, featI, maxLevel);
761 scalar overallMax = -great;
764 overallMax =
max(overallMax,
max(distances_[featI]));
List< labelList > labelListList
A List of labelList.
static autoPtr< extendedEdgeMesh > New(const fileName &, const word &ext)
Select constructed from filename (explicit extension)
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const pointField & points() const
bool set(const label) const
Is element set.
errorManipArg< error, int > exit(error &err, const int errNo=1)
refinementFeatures(const objectRegistry &io, const PtrList< dictionary > &featDicts)
Construct from description.
scalar maxDistance() const
Highest distance of all features.
void findNearestPoint(const pointField &samples, const scalarField &nearestDistSqr, labelList &nearFeature, List< pointIndexHit > &nearInfo) const
Find nearest feature point. Sets:
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static autoPtr< edgeMesh > New(const fileName &, const word &ext)
Select constructed from filename (explicit extension)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void size(const label)
Override size to be inconsistent with allocated storage.
Description of feature edges and points.
const T & operator[](const label) const
Return element const reference.
Ostream & endl(Ostream &os)
Add newline and flush stream.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Holds data for octree to work on an edges subset.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Tuple2< scalar, label > nearInfo
Private class for finding nearest.
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
PointIndexHit< point > pointIndexHit
const labelList & regionEdges() const
Return the feature edges which are on the boundary between.
T & first()
Return the first element of the list.
const Point & hitPoint() const
Return hit point.
vectorField pointField
pointField is a vectorField.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
static const word & geometryDir()
Return the geometry directory name.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const edgeList & edges() const
Return edges.
bool hit() const
Is there a hit.
const Type & shapes() const
Reference to shape.
List< label > labelList
A List of labels.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
vector vec(const pointField &) const
Return the vector (end - start)
const pointField & points() const
Return points.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
label size() const
Return the number of elements in the UPtrList.
void setSize(const label)
Reset size of List.
void findNearestRegionEdge(const pointField &samples, const scalarField &nearestDistSqr, labelList &nearFeature, List< pointIndexHit > &nearInfo, vectorField &nearNormal) const
Find nearest point on nearest region edge. Sets:
const edgeList & edges() const
Non-pointer based hierarchical recursive searching.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
static bool canRead(const fileName &, const bool verbose=false)
Can we read this file format?
const PtrList< indexedOctree< treeDataEdge > > & regionEdgeTrees() const
void findNearestEdge(const pointField &samples, const scalarField &nearestDistSqr, labelList &nearFeature, List< pointIndexHit > &nearInfo, vectorField &nearNormal) const
Find nearest point on nearest feature edge. Sets:
Standard boundBox + extra functionality for use in octree.
label findLower(const ListType &, typename ListType::const_reference, const label stary, const BinaryOp &bop)
Find last element < given value in sorted list and return index,.
dimensioned< scalar > mag(const dimensioned< Type > &)
Field< vector > vectorField
Specialisation of Field<T> for vector.
const doubleScalar e
Elementary charge.
Registry of regIOobjects.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
label index() const
Return index.
treeBoundBox extend(const scalar s) const
Return asymetrically extended bounding box, with guaranteed.