95 scalar minDistSqr = GREAT;
98 scalar almostMinDistSqr = GREAT;
99 label almostMinI = -1;
103 label pointI = meshPoints[i];
105 scalar distSqr =
magSqr(nearPoint - points[pointI]);
107 if (distSqr < minDistSqr)
109 almostMinDistSqr = minDistSqr;
112 minDistSqr = distSqr;
115 else if (distSqr < almostMinDistSqr)
117 almostMinDistSqr = distSqr;
124 Info<<
"Found to point " << nearPoint <<
nl
125 <<
" nearest point : " << minI
127 <<
" at " << points[minI] <<
nl
128 <<
" next nearest point : " << almostMinI
129 <<
" distance " <<
Foam::sqrt(almostMinDistSqr)
130 <<
" at " << points[almostMinI] <<
endl;
132 if (almostMinDistSqr < 4*minDistSqr)
134 Info<<
"Next nearest too close to nearest. Aborting" <<
endl;
150 const point& nearPoint
159 scalar minDist = GREAT;
162 scalar almostMinDist = GREAT;
163 label almostMinI = -1;
167 const edge&
e = edges[edgeI];
173 if (pHit.distance() < minDist)
175 almostMinDist = minDist;
186 else if (pHit.distance() < almostMinDist)
188 almostMinDist = pHit.distance();
201 Info<<
"Did not find edge close to point " << nearPoint <<
endl;
208 Info<<
"Found to point " << nearPoint <<
nl
209 <<
" nearest edge : " << minI
210 <<
" distance " << minDist <<
" endpoints "
211 << mesh.
edges()[minI].line(points) <<
nl
212 <<
" next nearest edge : " << almostMinI
213 <<
" distance " << almostMinDist <<
" endpoints "
214 << mesh.
edges()[almostMinI].line(points) <<
nl
217 if (almostMinDist < 2*minDist)
219 Info<<
"Next nearest too close to nearest. Aborting" <<
endl;
235 const point& nearPoint
241 scalar minDist = GREAT;
244 scalar almostMinDist = GREAT;
245 label almostMinI = -1;
249 pointHit pHit(pp[patchFaceI].nearestPoint(nearPoint, points));
253 if (pHit.distance() < minDist)
255 almostMinDist = minDist;
258 minDist = pHit.distance();
261 else if (pHit.distance() < almostMinDist)
263 almostMinDist = pHit.distance();
271 Info<<
"Did not find face close to point " << nearPoint <<
endl;
278 Info<<
"Found to point " << nearPoint <<
nl
279 <<
" nearest face : " << minI
280 <<
" distance " << minDist
282 <<
" next nearest face : " << almostMinI
283 <<
" distance " << almostMinDist
284 <<
" to face centre " << mesh.
faceCentres()[almostMinI] <<
nl
287 if (almostMinDist < 2*minDist)
289 Info<<
"Next nearest too close to nearest. Aborting" <<
endl;
303 label cellI = mesh.
findCell(nearPoint);
312 scalar minDistSqr = GREAT;
316 label pointI = cPoints[i];
318 scalar distSqr =
magSqr(nearPoint - mesh.
points()[pointI]);
320 if (distSqr < minDistSqr)
322 minDistSqr = distSqr;
328 Info<<
"Found to point " << nearPoint <<
nl
329 <<
" nearest cell : " << cellI
332 <<
" nearest mesh point : " << minI
334 <<
" to " << mesh.
points()[minI] <<
nl
337 if (minDistSqr < 4*distToCcSqr)
339 Info<<
"Mesh point too close to nearest cell centre. Aborting"
353 int main(
int argc,
char *argv[])
359 runTime.functionObjects().off();
361 const word oldInstance = mesh.pointsInstance();
365 Info<<
"Reading modifyMeshDict\n" <<
endl;
384 dict.lookup(
"facesToTriangulate")
390 || edgesToSplit.size()
391 || facesToTriangulate.size()
400 bool cellsToSplit = cellsToPyramidise.
size();
405 Info<<
"Read from " << dict.name() <<
nl
406 <<
" Boundary cutting module:" <<
nl
407 <<
" points to move :" << pointsToMove.size() <<
nl
408 <<
" edges to split :" << edgesToSplit.size() <<
nl
409 <<
" faces to triangulate:" << facesToTriangulate.size() <<
nl
410 <<
" Cell splitting module:" <<
nl
411 <<
" cells to split :" << cellsToPyramidise.size() <<
nl
412 <<
" Edge collapsing module:" <<
nl
413 <<
" edges to collapse :" << edgesToCollapse.size() <<
nl
419 (cutBoundary && collapseEdge)
420 || (cutBoundary && cellsToSplit)
421 || (collapseEdge && cellsToSplit)
425 <<
"Used more than one mesh modifying module "
426 <<
"(boundary cutting, cell splitting, edge collapsing)" <<
nl
445 bool validInputs =
true;
448 Info<<
nl <<
"Looking up points to move ..." <<
nl <<
endl;
454 label pointI = findPoint(allBoundary, pts.
first());
456 if (pointI == -1 || !pointToPos.insert(pointI, pts.
second()))
458 Info<<
"Could not insert mesh point " << pointI
459 <<
" for input point " << pts.
first() <<
nl
460 <<
"Perhaps the point is already marked for moving?" <<
endl;
466 Info<<
nl <<
"Looking up edges to split ..." <<
nl <<
endl;
480 Info<<
"Could not insert mesh edge " << edgeI
481 <<
" for input point " << pts.
first() <<
nl
482 <<
"Perhaps the edge is already marked for cutting?" <<
endl;
489 Info<<
nl <<
"Looking up faces to triangulate ..." <<
nl <<
endl;
490 Map<point> faceToDecompose(facesToTriangulate.size());
491 forAll(facesToTriangulate, i)
495 label faceI = findFace(mesh, allBoundary, pts.
first());
497 if (faceI == -1 || !faceToDecompose.insert(faceI, pts.
second()))
499 Info<<
"Could not insert mesh face " << faceI
500 <<
" for input point " << pts.
first() <<
nl
501 <<
"Perhaps the face is already marked for splitting?" <<
endl;
509 Info<<
nl <<
"Looking up cells to convert to pyramids around"
510 <<
" cell centre ..." <<
nl <<
endl;
511 Map<point> cellToPyrCentre(cellsToPyramidise.size());
512 forAll(cellsToPyramidise, i)
516 label cellI = findCell(mesh, pts.
first());
518 if (cellI == -1 || !cellToPyrCentre.insert(cellI, pts.
second()))
520 Info<<
"Could not insert mesh cell " << cellI
521 <<
" for input point " << pts.
first() <<
nl
522 <<
"Perhaps the cell is already marked for splitting?" <<
endl;
529 Info<<
nl <<
"Looking up edges to collapse ..." <<
nl <<
endl;
531 forAll(edgesToCollapse, i)
537 if (edgeI == -1 || !edgeToPos.insert(edgeI, pts.
second()))
539 Info<<
"Could not insert mesh edge " << edgeI
540 <<
" for input point " << pts.
first() <<
nl
541 <<
"Perhaps the edge is already marked for collaping?" <<
endl;
551 Info<<
nl <<
"There was a problem in one of the inputs in the"
552 <<
" dictionary. Not modifying mesh." <<
endl;
554 else if (cellToPyrCentre.size())
556 Info<<
nl <<
"All input cells located. Modifying mesh." <<
endl;
565 cutter.setRefinement(cellToPyrCentre, meshMod);
570 if (morphMap().hasMotionPoints())
572 mesh.
movePoints(morphMap().preMotionPoints());
575 cutter.updateMesh(morphMap());
583 mesh.setInstance(oldInstance);
587 Info <<
"Writing modified mesh to time " << runTime.timeName() <<
endl;
590 else if (edgeToPos.size())
592 Info<<
nl <<
"All input edges located. Modifying mesh." <<
endl;
602 label edgeI = iter.key();
605 cutter.collapseEdge(edgeI, e[0]);
606 newPoints[e[0]] = iter();
616 cutter.setRefinement(meshMod);
621 if (morphMap().hasMotionPoints())
623 mesh.
movePoints(morphMap().preMotionPoints());
636 mesh.setInstance(oldInstance);
640 Info <<
"Writing modified mesh to time " << runTime.timeName() <<
endl;
645 Info<<
nl <<
"All input points located. Modifying mesh." <<
endl;
666 if (morphMap().hasMotionPoints())
668 mesh.
movePoints(morphMap().preMotionPoints());
671 cutter.updateMesh(morphMap());
679 mesh.setInstance(oldInstance);
683 Info <<
"Writing modified mesh to time " << runTime.timeName() <<
endl;