34 #include "MeshKernel/Definitions.hpp"
35 #include <MeshKernel/Entities.hpp>
36 #include <MeshKernel/Mesh.hpp>
37 #include <MeshKernel/Polygon.hpp>
38 #include <MeshKernel/UndoActions/CompoundUndoAction.hpp>
39 #include <MeshKernel/UndoActions/SphericalCoordinatesOffsetAction.hpp>
40 #include <MeshKernel/UndoActions/UndoAction.hpp>
47 class CurvilinearGrid;
65 InsideNotIntersected = 0,
66 InsideAndIntersected = 1,
67 FacesWithIncludedCircumcenters = 2
91 Mesh2D(
const std::vector<Edge>& edges,
92 const std::vector<Point>& nodes,
101 Mesh2D(
const std::vector<Edge>& edges,
102 const std::vector<Point>& nodes,
103 const std::vector<std::vector<UInt>>& faceNodes,
104 const std::vector<std::uint8_t>& numFaceNodes,
114 void Administrate(CompoundUndoAction* undoAction =
nullptr)
override;
126 const std::vector<std::uint8_t>& numFaceNodes);
134 void CommitAction(
const SphericalCoordinatesOffsetAction& undoAction);
139 void RestoreAction(
const SphericalCoordinatesOffsetAction& undoAction);
147 std::vector<Point>& polygonNodesCache,
148 std::vector<UInt>& localNodeIndicesCache,
149 std::vector<UInt>& globalEdgeIndicesCache)
const;
161 const std::vector<UInt>& edgesNumFaces)
const;
175 [[nodiscard]] std::vector<Point>
GetFlowEdgesCenters(
const std::vector<UInt>& edges)
const;
199 [[nodiscard]] std::unique_ptr<meshkernel::UndoAction>
DeleteSmallFlowEdges(
double smallFlowEdgesThreshold);
234 void GetNodeTypes(std::vector<MeshNodeType>& nodeTypes)
const { nodeTypes = m_nodesTypes; }
247 void MakeDualFace(
const std::span<const Point> edgeCentres,
249 double enlargementFactor,
250 std::vector<Point>& dualFace)
const;
268 std::vector<bool>& isVisited,
270 std::vector<Point>& meshBoundaryPolygon)
const;
282 [[nodiscard]] std::vector<UInt>
PointFaceIndices(
const std::vector<Point>& points);
343 static std::unique_ptr<Mesh2D>
Merge(
const std::span<const Point>& mesh1Nodes,
344 const std::span<const Edge>& mesh1Edges,
345 const std::span<const Point>& mesh2Nodes,
346 const std::span<const Edge>& mesh2Edges,
377 void FindNodesSharedByFaces(
UInt nodeIndex,
const std::vector<UInt>& sharedFaces, std::vector<UInt>& connectedNodes, std::vector<std::vector<UInt>>& faceNodeMapping)
const;
398 static constexpr
double m_minimumEdgeLength = 1e-4;
399 static constexpr
double m_curvilinearToOrthogonalRatio = 0.5;
400 static constexpr
double m_minimumCellArea = 1e-12;
401 static constexpr
double m_weightCircumCenter = 1.0;
402 static constexpr
UInt m_maximumNumberOfHangingNodesAlongEdge = 5;
405 using HangingNodeIndexArray = std::array<UInt, m_maximumNumberOfHangingNodesAlongEdge>;
408 void ComputeAverageAreOfNeighbouringFaces(
const UInt faceId,
UInt& numNonBoundaryFaces,
double& averageOtherFacesArea)
const;
411 void FindSmallestCornerAngle(
const UInt faceId,
412 double& minCosPhiSmallTriangle,
413 UInt& nodeToPreserve,
414 UInt& firstNodeToMerge,
415 UInt& secondNodeToMerge,
416 UInt& thirdEdgeSmallTriangle)
const;
419 void DeleteSmallTriangle(
const UInt nodeToPreserve,
420 const UInt firstNodeToMerge,
421 const UInt secondNodeToMerge,
423 CompoundUndoAction& undoAction);
426 void FindNodesToDelete(
const Polygons& polygon,
427 const bool invertDeletion,
428 std::vector<bool>& isNodeInsidePolygon,
429 std::vector<bool>& deleteNode)
const;
432 void DeletedMeshNodesAndEdges(
const std::function<
bool(
UInt)>& excludedFace,
433 std::vector<bool>& deleteNode,
434 CompoundUndoAction& deleteMeshAction);
437 std::vector<int> ComputeNodeMask(
const Polygons& polygons)
const;
440 std::vector<int> ComputeEdgeMask(
const std::vector<int>& nodeMask,
441 bool includeIntersected)
const;
444 void RemoveIntersected(
const std::vector<int>& edgeMask,
445 std::vector<int>& secondEdgeMask)
const;
448 void InvertSelection(
const std::vector<int>& edgeMask,
449 std::vector<int>& secondEdgeMask)
const;
452 std::vector<bool> FindFacesEntirelyInsidePolygon(
const std::vector<bool>& isNodeInsidePolygon)
const;
458 [[nodiscard]] std::unique_ptr<UndoAction> DeleteMeshFaces(
const Polygons& polygon,
bool invertDeletion);
470 void FindFacesRecursive(
UInt startNode,
473 UInt numClosingEdges,
474 std::vector<UInt>& edges,
475 std::vector<UInt>& nodes,
476 std::vector<UInt>& sortedEdges,
477 std::vector<UInt>& sortedNodes,
478 std::vector<Point>& nodalValues);
484 [[nodiscard]]
bool HasTriangleNoAcuteAngles(
const std::vector<UInt>& faceNodes,
const std::vector<Point>& nodes)
const;
489 bool HasDuplicateNodes(
const UInt numClosingEdges,
const std::vector<UInt>& node, std::vector<UInt>& sortedNodes)
const;
494 bool HasDuplicateEdgeFaces(
const UInt numClosingEdges,
const std::vector<UInt>& edges, std::vector<UInt>& sortedEdgesFaces)
const;
497 void ResizeAndInitializeFaceVectors();
502 void DoAdministrationGivenFaceNodesMapping(
const std::vector<std::vector<UInt>>& faceNodes,
503 const std::vector<std::uint8_t>& numFaceNodes);
507 void DoAdministration(CompoundUndoAction* undoAction =
nullptr);
510 void InitialiseBoundaryNodeClassification(std::vector<int>& intNodeType)
const;
516 UInt CountNumberOfValidEdges(
const std::vector<UInt>& edgesNumFaces,
const UInt numNodes)
const;
519 void ComputeMidPointsAndNormals(
const std::vector<Point>& polygon,
520 const std::vector<UInt>& edgesNumFaces,
522 std::array<Point, m_maximumNumberOfNodesPerFace>& middlePoints,
523 std::array<Point, m_maximumNumberOfNodesPerFace>& normals,
524 UInt& pointCount)
const;
527 Point ComputeCircumCentre(
const Point& centerOfMass,
528 const UInt pointCount,
529 const std::array<Point, m_maximumNumberOfNodesPerFace>& middlePoints,
530 const std::array<Point, m_maximumNumberOfNodesPerFace>& normals)
const;
533 void ComputeAverageFlowEdgesLength(std::vector<double>& edgesLength,
534 std::vector<double>& averageFlowEdgesLength)
const;
537 void ComputeAverageEdgeLength(
const std::vector<double>& edgesLength,
538 const std::vector<double>& averageFlowEdgesLength,
539 std::vector<bool>& curvilinearGridIndicator,
540 std::vector<std::array<double, 2>>& averageEdgesLength,
541 std::vector<double>& aspectRatios)
const;
543 std::vector<MeshNodeType> m_nodesTypes;