40 const extendedFeatureEdgeMesh& feMesh,
45 if (foamyHexMeshControls().circulateEdges())
47 createEdgePointGroupByCirculating(feMesh, edHit, pts);
51 label edgeI = edHit.index();
54 feMesh.getEdgeStatus(edgeI);
60 createExternalEdgePointGroup(feMesh, edHit, pts);
65 createInternalEdgePointGroup(feMesh, edHit, pts);
70 createFlatEdgePointGroup(feMesh, edHit, pts);
75 createOpenEdgePointGroup(feMesh, edHit, pts);
80 createMultipleEdgePointGroup(feMesh, edHit, pts);
92 bool Foam::conformalVoronoiMesh::meshableRegion
124 bool Foam::conformalVoronoiMesh::regionIsInside
143 const bool meshableRegionA = meshableRegion(sideA, volTypeA);
144 const bool meshableRegionB = meshableRegion(sideB, volTypeB);
146 if (meshableRegionA == meshableRegionB)
148 return meshableRegionA;
161 void Foam::conformalVoronoiMesh::createEdgePointGroupByCirculating
163 const extendedFeatureEdgeMesh& feMesh,
172 const label edgeI = edHit.index();
174 scalar ppDist = pointPairDistance(edgePt);
177 const vector& edDir = feMesh.edgeDirections()[edgeI];
178 const labelList& edNormalIs = feMesh.edgeNormals()[edgeI];
179 const labelList& feNormalDirections = feMesh.normalDirections()[edgeI];
181 const List<sideVolumeType>& normalVolumeTypes = feMesh.normalVolumeTypes();
183 ConstCirculator<labelList> circ(edNormalIs);
184 ConstCirculator<labelList> circNormalDirs(feNormalDirections);
186 Map<Foam::point> masterPoints;
187 Map<vertexType> masterPointsTypes;
188 Map<plane> masterPointReflectionsPrev;
189 Map<plane> masterPointReflectionsNext;
194 bool addedMasterPreviously =
false;
195 label initialRegion = -1;
199 const sideVolumeType volType = normalVolumeTypes[circ()];
200 const sideVolumeType nextVolType = normalVolumeTypes[circ.next()];
202 const vector& normal = feNormals[circ()];
203 const vector& nextNormal = feNormals[circ.next()];
205 vector normalDir = (normal ^ edDir);
206 normalDir *= circNormalDirs()/
mag(normalDir);
208 vector nextNormalDir = (nextNormal ^ edDir);
209 nextNormalDir *= circNormalDirs.next()/
mag(nextNormalDir);
223 vector masterPtVec(normalDir + nextNormalDir);
224 masterPtVec /=
mag(masterPtVec) + small;
228 ((normalDir ^ nextNormalDir) & edDir) < small
229 ||
mag(masterPtVec) < small
233 addedMasterPreviously =
false;
238 &&
mag((normal & nextNormal) - 1) < small
241 const vector n = 0.5*(normal + nextNormal);
243 const vector s = ppDist*(edDir ^
n);
247 createBafflePointPair(ppDist, edgePt + s, n,
true, pts);
248 createBafflePointPair(ppDist, edgePt - s, n,
true, pts);
253 <<
"Failed to insert flat/open edge as volType is " 267 const Foam::point masterPt = edgePt + ppDist*masterPtVec;
281 if (
mag((normalDir & nextNormalDir) - 1) < small)
287 vector s = ppDist*(edDir ^ normal);
289 plane facePlane(edgePt, normal);
307 <<
"Faces are parallel but master point is not inside" 312 if (!addedMasterPreviously)
314 if (initialRegion == -1)
316 initialRegion = circ.nRotations();
319 addedMasterPreviously =
true;
321 masterPoints.insert(circ.nRotations(), masterPt);
322 masterPointsTypes.insert
330 masterPointReflectionsPrev.insert
333 plane(edgePt, normal)
336 masterPointReflectionsNext.insert
339 plane(edgePt, nextNormal)
342 else if (addedMasterPreviously)
344 addedMasterPreviously =
true;
346 masterPointReflectionsNext.erase(circ.nRotations() - 1);
353 plane
p(masterPoints[circ.nRotations() - 1], normalDir);
354 plane::ray r(edgePt, masterPt - edgePt);
356 scalar cutPoint =
p.normalIntersect(r);
361 edgePt + cutPoint*(masterPt - edgePt)
364 masterPointsTypes.insert
372 masterPointReflectionsNext.insert
375 plane(edgePt, nextNormal)
381 masterPoints.size() > 1
383 && circ.nRotations() == circ.size() - 1
386 if (initialRegion == 0)
388 plane
p(masterPoints[initialRegion], nextNormalDir);
389 plane::ray r(edgePt, masterPt - edgePt);
391 scalar cutPoint =
p.normalIntersect(r);
393 masterPoints[circ.nRotations()] =
394 edgePt + cutPoint*(masterPt - edgePt);
399 masterPointReflectionsPrev.erase(initialRegion);
400 masterPointReflectionsNext.erase(circ.nRotations());
418 const vertexType ptType = masterPointsTypes[iter.key()];
423 pts.append(
Vb(pt, ptType));
425 const vertexType reflectedPtType =
432 if (masterPointReflectionsPrev.found(iter.key()))
435 masterPointReflectionsPrev[iter.key()].mirror(pt);
441 pts.append(
Vb(reflectedPt, reflectedPtType));
444 if (masterPointReflectionsNext.found(iter.key()))
447 masterPointReflectionsNext[iter.key()].mirror(pt);
453 pts.append(
Vb(reflectedPt, reflectedPtType));
461 void Foam::conformalVoronoiMesh::createExternalEdgePointGroup
463 const extendedFeatureEdgeMesh& feMesh,
470 scalar ppDist = pointPairDistance(edgePt);
473 const labelList& edNormalIs = feMesh.edgeNormals()[edHit.index()];
474 const List<extendedFeatureEdgeMesh::sideVolumeType>& normalVolumeTypes =
475 feMesh.normalVolumeTypes();
478 const vector& nA = feNormals[edNormalIs[0]];
479 const vector& nB = feNormals[edNormalIs[1]];
482 normalVolumeTypes[edNormalIs[0]];
485 normalVolumeTypes[edNormalIs[1]];
495 vector refVec((nA + nB)/(1 + (nA & nB)));
500 ppDist *= 5.0/
mag(refVec);
518 if (!geometryToConformTo_.inside(refPt))
528 vertexCount() + pts.
size(),
543 vertexCount() + pts.
size(),
559 vertexCount() + pts.
size(),
569 ptPairs_.addPointPair
571 pts[pts.size() - 3].index(),
572 pts[pts.size() - 1].index()
575 ptPairs_.addPointPair
577 pts[pts.size() - 3].index(),
578 pts[pts.size() - 2].index()
583 void Foam::conformalVoronoiMesh::createInternalEdgePointGroup
585 const extendedFeatureEdgeMesh& feMesh,
592 scalar ppDist = pointPairDistance(edgePt);
595 const labelList& edNormalIs = feMesh.edgeNormals()[edHit.index()];
596 const List<extendedFeatureEdgeMesh::sideVolumeType>& normalVolumeTypes =
597 feMesh.normalVolumeTypes();
600 const vector& nA = feNormals[edNormalIs[0]];
601 const vector& nB = feNormals[edNormalIs[1]];
604 normalVolumeTypes[edNormalIs[0]];
617 vector refVec((nA + nB)/(1 + (nA & nB)));
622 ppDist *= 5.0/
mag(refVec);
639 Foam::point reflMasterPt = refPt + 2*(edgePt - refPt);
642 Foam::point reflectedA = reflMasterPt - 2*ppDist*nA;
644 Foam::point reflectedB = reflMasterPt - 2*ppDist*nB;
650 int nQuads = int(totalAngle/foamyHexMeshControls().maxQuadAngle()) + 1;
654 int nAddPoints =
min(
max(nQuads - 2, 0), 2);
680 !geometryToConformTo_.inside(reflectedA)
681 || !geometryToConformTo_.inside(reflectedB)
693 vertexCount() + pts.size(),
705 vertexCount() + pts.
size(),
717 vertexCount() + pts.
size(),
727 ptPairs_.addPointPair
729 pts[pts.size() - 2].index(),
730 pts[pts.size() - 1].index()
733 ptPairs_.addPointPair
735 pts[pts.size() - 3].index(),
736 pts[pts.size() - 1].index()
748 vertexCount() + pts.
size(),
754 else if (nAddPoints == 2)
762 vertexCount() + pts.
size(),
774 vertexCount() + pts.
size(),
783 void Foam::conformalVoronoiMesh::createFlatEdgePointGroup
785 const extendedFeatureEdgeMesh& feMesh,
792 const scalar ppDist = pointPairDistance(edgePt);
795 const labelList& edNormalIs = feMesh.edgeNormals()[edHit.index()];
796 const List<extendedFeatureEdgeMesh::sideVolumeType>& normalVolumeTypes =
797 feMesh.normalVolumeTypes();
800 const vector& nA = feNormals[edNormalIs[0]];
801 const vector& nB = feNormals[edNormalIs[1]];
805 const vector n = 0.5*(nA + nB);
810 vector s = ppDist*(feMesh.edgeDirections()[edHit.index()] ^
n);
814 createPointPair(ppDist, edgePt + s, -n,
true, pts);
815 createPointPair(ppDist, edgePt - s, -n,
true, pts);
819 createBafflePointPair(ppDist, edgePt + s, n,
true, pts);
820 createBafflePointPair(ppDist, edgePt - s, n,
true, pts);
824 createPointPair(ppDist, edgePt + s, n,
true, pts);
825 createPointPair(ppDist, edgePt - s, n,
true, pts);
830 void Foam::conformalVoronoiMesh::createOpenEdgePointGroup
832 const extendedFeatureEdgeMesh& feMesh,
840 const scalar ppDist = pointPairDistance(edgePt);
843 const labelList& edNormalIs = feMesh.edgeNormals()[edHit.index()];
845 if (edNormalIs.size() == 1)
852 const vector& n = feNormals[edNormalIs[0]];
854 vector s = ppDist*(feMesh.edgeDirections()[edHit.index()] ^
n);
856 plane facePlane(edgePt, n);
858 const label initialPtsSize = pts.size();
862 !geometryToConformTo_.inside(edgePt)
868 createBafflePointPair(ppDist, edgePt - s, n,
true, pts);
869 createBafflePointPair(ppDist, edgePt + s, n,
false, pts);
871 for (
label ptI = initialPtsSize; ptI < pts.size(); ++ptI)
878 Info<<
"NOT INSERTING OPEN EDGE POINT GROUP WITH MORE THAN 1 " 879 <<
"EDGE NORMAL, NOT IMPLEMENTED" <<
endl;
884 void Foam::conformalVoronoiMesh::createMultipleEdgePointGroup
886 const extendedFeatureEdgeMesh& feMesh,
895 const scalar ppDist = pointPairDistance(edgePt);
897 const vector edDir = feMesh.edgeDirections()[edHit.index()];
900 const labelList& edNormalIs = feMesh.edgeNormals()[edHit.index()];
901 const labelList& normalDirs = feMesh.normalDirections()[edHit.index()];
903 const List<extendedFeatureEdgeMesh::sideVolumeType>& normalVolumeTypes =
904 feMesh.normalVolumeTypes();
908 forAll(edNormalIs, edgeNormalI)
911 normalVolumeTypes[edNormalIs[edgeNormalI]];
913 nNormalTypes[sType]++;
918 label masterEdgeNormalIndex = -1;
920 forAll(edNormalIs, edgeNormalI)
923 normalVolumeTypes[edNormalIs[edgeNormalI]];
927 masterEdgeNormalIndex = edgeNormalI;
932 const vector& n = feNormals[edNormalIs[masterEdgeNormalIndex]];
934 label nDir = normalDirs[masterEdgeNormalIndex];
937 (feNormals[edNormalIs[masterEdgeNormalIndex]] ^ edDir);
938 normalDir *= nDir/
mag(normalDir);
943 plane plane3(edgePt, normalDir);
953 vertexCount() + pts.
size(),
963 vertexCount() + pts.
size(),
969 ptPairs_.addPointPair
971 pts[pts.size() - 2].index(),
972 pts[pts.size() - 1].index()
980 vertexCount() + pts.
size(),
986 ptPairs_.addPointPair
988 pts[pts.size() - 3].index(),
989 pts[pts.size() - 1].index()
997 vertexCount() + pts.
size(),
1003 ptPairs_.addPointPair
1005 pts[pts.size() - 3].index(),
1006 pts[pts.size() - 1].index()
1009 ptPairs_.addPointPair
1011 pts[pts.size() - 2].index(),
1012 pts[pts.size() - 1].index()
1021 label masterEdgeNormalIndex = -1;
1023 forAll(edNormalIs, edgeNormalI)
1026 normalVolumeTypes[edNormalIs[edgeNormalI]];
1030 masterEdgeNormalIndex = edgeNormalI;
1035 const vector& n = feNormals[edNormalIs[masterEdgeNormalIndex]];
1037 label nDir = normalDirs[masterEdgeNormalIndex];
1040 (feNormals[edNormalIs[masterEdgeNormalIndex]] ^ edDir);
1041 normalDir *= nDir/
mag(normalDir);
1043 const label nextNormalI =
1044 (masterEdgeNormalIndex + 1) % edNormalIs.size();
1045 if ((normalDir & feNormals[edNormalIs[nextNormalI]]) > 0)
1050 Foam::point pt1 = edgePt + ppDist*normalDir + ppDist*
n;
1051 Foam::point pt2 = edgePt + ppDist*normalDir - ppDist*
n;
1053 plane plane3(edgePt, normalDir);
1063 vertexCount() + pts.
size(),
1073 vertexCount() + pts.
size(),
1079 ptPairs_.addPointPair
1081 pts[pts.size() - 2].index(),
1082 pts[pts.size() - 1].index()
1090 vertexCount() + pts.
size(),
1096 ptPairs_.addPointPair
1098 pts[pts.size() - 3].index(),
1099 pts[pts.size() - 1].index()
1107 vertexCount() + pts.
size(),
1113 ptPairs_.addPointPair
1115 pts[pts.size() - 3].index(),
1116 pts[pts.size() - 1].index()
1139 void Foam::conformalVoronoiMesh::insertFeaturePoints(
bool distribute)
1142 <<
"Inserting feature points" <<
endl;
1144 const label preFeaturePointSize(number_of_vertices());
1148 ftPtConformer_.distribute(decomposition());
1151 const List<Vb>& ftPtVertices = ftPtConformer_.featurePointVertices();
1154 Map<label> oldToNewIndices =
1157 ftPtConformer_.reIndexPointPairs(oldToNewIndices);
1159 label nFeatureVertices = number_of_vertices() - preFeaturePointSize;
1160 reduce(nFeatureVertices, sumOp<label>());
1162 Info<<
" Inserted " << nFeatureVertices <<
" feature vertices" <<
endl;
#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.
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
static const Foam::NamedEnum< sideVolumeType, 4 > sideVolumeTypeNames_
Ostream & endl(Ostream &os)
Add newline and flush stream.
PointIndexHit< point > pointIndexHit
Vector< scalar > vector
A scalar version of the templated Vector.
An indexed form of CGAL::Triangulation_vertex_base_3<K> used to keep track of the Delaunay vertices i...
CGAL::indexedVertex< K > Vb
sideVolumeType
Normals point to the outside.
List< label > labelList
A List of labels.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
static direction size()
Return the number of elements in the VectorSpace = Ncmpts.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
static bool & parRun()
Is this a parallel run?
#define WarningInFunction
Report a warning using Foam::Warning.
dimensioned< scalar > mag(const dimensioned< Type > &)
Field< vector > vectorField
Specialisation of Field<T> for vector.
Map< label > insertPoints(const List< Vb > &vertices, const bool reIndex)
Insert the list of vertices (calls rangeInsertWithInfo)