83 scalar minDistSqr = GREAT;
86 scalar almostMinDistSqr = GREAT;
87 label almostMinI = -1;
89 for (
const label pointi : meshPoints)
93 if (distSqr < minDistSqr)
95 almostMinDistSqr = minDistSqr;
101 else if (distSqr < almostMinDistSqr)
103 almostMinDistSqr = distSqr;
110 Info<<
"Found to point " << nearPoint <<
nl
111 <<
" nearest point : " << minI
114 <<
" next nearest point : " << almostMinI
115 <<
" distance " <<
Foam::sqrt(almostMinDistSqr)
118 if (almostMinDistSqr < 4*minDistSqr)
120 Info<<
"Next nearest too close to nearest. Aborting" <<
endl;
136 const point& nearPoint
145 scalar minDist = GREAT;
148 scalar almostMinDist = GREAT;
149 label almostMinI = -1;
151 for (
const edge&
e : edges)
153 pointHit pHit(
e.line(localPoints).nearestDist(nearPoint));
157 if (pHit.distance() < minDist)
159 almostMinDist = minDist;
162 minDist = pHit.distance();
170 else if (pHit.distance() < almostMinDist)
172 almostMinDist = pHit.distance();
185 Info<<
"Did not find edge close to point " << nearPoint <<
endl;
192 Info<<
"Found to point " << nearPoint <<
nl
193 <<
" nearest edge : " << minI
194 <<
" distance " << minDist <<
" endpoints "
196 <<
" next nearest edge : " << almostMinI
197 <<
" distance " << almostMinDist <<
" endpoints "
201 if (almostMinDist < 2*minDist)
203 Info<<
"Next nearest too close to nearest. Aborting" <<
endl;
219 const point& nearPoint
225 scalar minDist = GREAT;
228 scalar almostMinDist = GREAT;
229 label almostMinI = -1;
237 if (pHit.distance() < minDist)
239 almostMinDist = minDist;
242 minDist = pHit.distance();
243 minI = patchFacei +
mesh.nInternalFaces();
245 else if (pHit.distance() < almostMinDist)
247 almostMinDist = pHit.distance();
248 almostMinI = patchFacei +
mesh.nInternalFaces();
255 Info<<
"Did not find face close to point " << nearPoint <<
endl;
262 Info<<
"Found to point " << nearPoint <<
nl
263 <<
" nearest face : " << minI
264 <<
" distance " << minDist
265 <<
" to face centre " <<
mesh.faceCentres()[minI] <<
nl
266 <<
" next nearest face : " << almostMinI
267 <<
" distance " << almostMinDist
268 <<
" to face centre " <<
mesh.faceCentres()[almostMinI] <<
nl
271 if (almostMinDist < 2*minDist)
273 Info<<
"Next nearest too close to nearest. Aborting" <<
endl;
287 label celli =
mesh.findCell(nearPoint);
291 scalar distToCcSqr = nearPoint.
distSqr(
mesh.cellCentres()[celli]);
296 scalar minDistSqr = GREAT;
298 for (
const label pointi : cPoints)
300 scalar distSqr = nearPoint.
distSqr(
mesh.points()[pointi]);
302 if (distSqr < minDistSqr)
304 minDistSqr = distSqr;
310 Info<<
"Found to point " << nearPoint <<
nl
311 <<
" nearest cell : " << celli
313 <<
" to cell centre " <<
mesh.cellCentres()[celli] <<
nl
314 <<
" nearest mesh point : " << minI
316 <<
" to " <<
mesh.points()[minI] <<
nl
319 if (minDistSqr < 4*distToCcSqr)
321 Info<<
"Mesh point too close to nearest cell centre. Aborting"
334int main(
int argc,
char *argv[])
338 "Manipulate mesh elements.\n"
339 "For example, moving points, splitting/collapsing edges etc."
350 const word oldInstance =
mesh.pointsInstance();
352 const bool overwrite =
args.found(
"overwrite");
354 Info<<
"Reading modifyMeshDict\n" <<
endl;
362 List<Pair<point>> pointsToMove(
dict.lookup(
"pointsToMove"));
363 List<Pair<point>> edgesToSplit(
dict.lookup(
"edgesToSplit"));
364 List<Pair<point>> facesToTriangulate
366 dict.lookup(
"facesToTriangulate")
369 List<Pair<point>> facesToSplit;
370 dict.readIfPresent(
"facesToSplit", facesToSplit);
375 || edgesToSplit.
size()
376 || facesToTriangulate.
size()
377 || facesToSplit.
size()
380 List<Pair<point>> edgesToCollapse(
dict.lookup(
"edgesToCollapse"));
384 List<Pair<point>> cellsToPyramidise(
dict.lookup(
"cellsToSplit"));
386 bool cellsToSplit = cellsToPyramidise.
size();
392 <<
" Boundary cutting module:" <<
nl
393 <<
" points to move :" << pointsToMove.
size() <<
nl
394 <<
" edges to split :" << edgesToSplit.
size() <<
nl
395 <<
" faces to split :" << facesToSplit.
size() <<
nl
396 <<
" faces to triangulate:" << facesToTriangulate.
size() <<
nl
397 <<
" Cell splitting module:" <<
nl
398 <<
" cells to split :" << cellsToPyramidise.
size() <<
nl
399 <<
" Edge collapsing module:" <<
nl
400 <<
" edges to collapse :" << edgesToCollapse.
size() <<
nl
407 || (cutBoundary && cellsToSplit)
412 <<
"Used more than one mesh modifying module "
413 <<
"(boundary cutting, cell splitting, edge collapsing)" <<
nl
425 bool validInputs =
true;
428 Info<<
nl <<
"Looking up points to move ..." <<
nl <<
endl;
430 for (
const Pair<point>&
pts : pointsToMove)
432 const label pointi = findPoint(allBoundary,
pts.first());
434 if (pointi == -1 || !pointToPos.insert(pointi,
pts.second()))
436 Info<<
"Could not insert mesh point " << pointi
437 <<
" for input point " <<
pts.first() <<
nl
438 <<
"Perhaps the point is already marked for moving?" <<
endl;
444 Info<<
nl <<
"Looking up edges to split ..." <<
nl <<
endl;
446 for (
const Pair<point>&
pts : edgesToSplit)
453 || !edgeToCuts.insert(edgeI, List<point>(1,
pts.second()))
456 Info<<
"Could not insert mesh edge " << edgeI
457 <<
" for input point " <<
pts.first() <<
nl
458 <<
"Perhaps the edge is already marked for cutting?" <<
endl;
465 Info<<
nl <<
"Looking up faces to triangulate ..." <<
nl <<
endl;
467 for (
const Pair<point>&
pts : facesToTriangulate)
469 label facei = findFace(
mesh, allBoundary,
pts.first());
471 if (facei == -1 || !faceToDecompose.insert(facei,
pts.second()))
473 Info<<
"Could not insert mesh face " << facei
474 <<
" for input point " <<
pts.first() <<
nl
475 <<
"Perhaps the face is already marked for splitting?" <<
endl;
482 Info<<
nl <<
"Looking up faces to split ..." <<
nl <<
endl;
484 for (
const Pair<point>&
pts : facesToSplit)
486 label facei = findFace(
mesh, allBoundary,
pts.first());
489 Info<<
"Could not insert mesh face " << facei
490 <<
" for input point " <<
pts.first() <<
nl
491 <<
"Perhaps the face is already marked for splitting?" <<
endl;
504 const label
p0 = findPoint(
pp,
pts.first());
505 const label p1 = findPoint(
pp,
pts.second());
513 && faceToSplit.insert(facei,
labelPair(
f.find(
p0),
f.find(p1)))
518 Info<<
"Could not insert mesh face " << facei
519 <<
" for input coordinates " <<
pts
520 <<
" with vertices " <<
p0 <<
" and " << p1 <<
nl
521 <<
"Perhaps the face is already marked for splitting?"
529 Info<<
nl <<
"Looking up cells to convert to pyramids around"
530 <<
" cell centre ..." <<
nl <<
endl;
532 for (
const Pair<point>&
pts : cellsToPyramidise)
534 label celli = findCell(
mesh,
pts.first());
536 if (celli == -1 || !cellToPyrCentre.insert(celli,
pts.second()))
538 Info<<
"Could not insert mesh cell " << celli
539 <<
" for input point " <<
pts.first() <<
nl
540 <<
"Perhaps the cell is already marked for splitting?" <<
endl;
547 Info<<
nl <<
"Looking up edges to collapse ..." <<
nl <<
endl;
549 for (
const Pair<point>&
pts : edgesToCollapse)
553 if (edgeI == -1 || !edgeToPos.insert(edgeI,
pts.second()))
555 Info<<
"Could not insert mesh edge " << edgeI
556 <<
" for input point " <<
pts.first() <<
nl
557 <<
"Perhaps the edge is already marked for collaping?" <<
endl;
567 Info<<
nl <<
"There was a problem in one of the inputs in the"
568 <<
" dictionary. Not modifying mesh." <<
endl;
570 else if (cellToPyrCentre.size())
572 Info<<
nl <<
"All input cells located. Modifying mesh." <<
endl;
581 cutter.setRefinement(cellToPyrCentre, meshMod);
586 if (morphMap().hasMotionPoints())
588 mesh.movePoints(morphMap().preMotionPoints());
591 cutter.updateMesh(morphMap());
599 mesh.setInstance(oldInstance);
608 else if (edgeToPos.size())
610 Info<<
nl <<
"All input edges located. Modifying mesh." <<
endl;
626 label edgeI = iter.key();
627 const edge&
e = edges[edgeI];
630 collapsePointToLocation.set(
e[1],
points[
e[0]]);
632 newPoints[
e[0]] = iter.val();
636 mesh.movePoints(newPoints);
638 List<pointEdgeCollapse> allPointInfo;
642 cutter.consistentCollapse
646 collapsePointToLocation,
655 cutter.setRefinement(allPointInfo, meshMod);
660 if (morphMap().hasMotionPoints())
662 mesh.movePoints(morphMap().preMotionPoints());
675 mesh.setInstance(oldInstance);
686 Info<<
nl <<
"All input points located. Modifying mesh." <<
endl;
707 if (morphMap().hasMotionPoints())
709 mesh.movePoints(morphMap().preMotionPoints());
712 cutter.updateMesh(morphMap());
720 mesh.setInstance(oldInstance);
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
static constexpr label size() noexcept
Return the number of elements in the FixedList.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
A HashTable to objects of type <T> with a label key.
A non-owning sub-view of a List (allocated or unallocated storage).
void size(const label n)
Older name for setAddressableSize.
scalar distSqr(const Vector< Cmpt > &v2) const
The L2-norm distance squared from another vector. The magSqr() of the difference.
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
static void addNote(const string ¬e)
Add extra notes for the usage information.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Does modifications to boundary faces.
Does pyramidal decomposition of selected cells. So all faces will become base of pyramid with as top ...
Does polyTopoChanges to remove edges. Can remove faces due to edge collapse but can not remove cells ...
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
A face is a list of labels corresponding to mesh vertices.
Calculates a non-overlapping list of offsets based on an input size (eg, number of cells) from differ...
Calculates points shared by more than two processor patches or cyclic patches.
Direct mesh changes based on v1.3 polyTopoChange syntax.
Cell-face mesh analysis engine.
static void removeFiles(const polyMesh &mesh)
Helper: remove all procAddressing files from mesh instance.
static void removeFiles(const polyMesh &)
Helper: remove all sets files from mesh instance.
A class for handling words, derived from Foam::string.
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
const volScalarField & p0
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const word dictName("faMeshDefinition")
List< edge > edgeList
List of edge.
Pair< label > labelPair
A pair of labels.
PointHit< point > pointHit
A PointHit with a 3D point.
List< label > labelList
A List of labels.
messageStream Info
Information stream (stdout output on master, null elsewhere).
PrimitivePatch< SubList< face >, const pointField & > primitivePatch
A PrimitivePatch with a SubList addressing for the faces, const reference for the point field.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensionedScalar sqrt(const dimensionedScalar &ds)
vector point
Point is a vector.
static constexpr const zero Zero
Global zero (0).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.