34#include <MeshKernel/Constants.hpp>
35#include <MeshKernel/Definitions.hpp>
36#include <MeshKernel/Entities.hpp>
37#include <MeshKernel/Mesh.hpp>
38#include <MeshKernel/Polygon.hpp>
39#include <MeshKernel/UndoActions/CompoundUndoAction.hpp>
40#include <MeshKernel/UndoActions/SphericalCoordinatesOffsetAction.hpp>
41#include <MeshKernel/UndoActions/UndoAction.hpp>
48 class CurvilinearGrid;
66 InsideNotIntersected = 0,
67 InsideAndIntersected = 1,
68 FacesWithIncludedCircumcenters = 2
85 Mesh2D(
const std::vector<Edge>& edges,
86 const std::vector<Point>& nodes,
95 Mesh2D(
const std::vector<Edge>& edges,
96 const std::vector<Point>& nodes,
97 const std::vector<std::vector<UInt>>& faceNodes,
98 const std::vector<std::uint8_t>& numFaceNodes,
120 const std::vector<std::uint8_t>& numFaceNodes);
141 std::vector<Point>& polygonNodesCache,
142 std::vector<UInt>& localNodeIndicesCache,
143 std::vector<UInt>& globalEdgeIndicesCache)
const;
216 void GetNodeTypes(std::vector<MeshNodeType>& nodeTypes)
const { nodeTypes = m_nodesTypes; }
234 double enlargementFactor,
235 std::vector<Point>& dualFace)
const;
253 std::vector<bool>& isVisited,
255 std::vector<Point>& meshBoundaryPolygon)
const;
328 static std::unique_ptr<Mesh2D>
Merge(
const std::span<const Point>& mesh1Nodes,
329 const std::span<const Edge>& mesh1Edges,
330 const std::span<const Point>& mesh2Nodes,
331 const std::span<const Edge>& mesh2Edges,
362 void FindNodesSharedByFaces(
UInt nodeIndex,
const std::vector<UInt>& sharedFaces, std::vector<UInt>& connectedNodes, std::vector<std::vector<UInt>>& faceNodeMapping)
const;
383 static constexpr double m_minimumEdgeLength = 1e-4;
384 static constexpr double m_curvilinearToOrthogonalRatio = 0.5;
385 static constexpr double m_minimumCellArea = 1e-12;
386 static constexpr UInt m_maximumNumberOfHangingNodesAlongEdge = 5;
389 using HangingNodeIndexArray = std::array<UInt, m_maximumNumberOfHangingNodesAlongEdge>;
392 void ComputeAverageAreOfNeighbouringFaces(
const UInt faceId,
UInt& numNonBoundaryFaces,
double& averageOtherFacesArea)
const;
395 void FindSmallestCornerAngle(
const UInt faceId,
396 double& minCosPhiSmallTriangle,
397 UInt& nodeToPreserve,
398 UInt& firstNodeToMerge,
399 UInt& secondNodeToMerge,
400 UInt& thirdEdgeSmallTriangle)
const;
403 void DeleteSmallTriangle(
const UInt nodeToPreserve,
404 const UInt firstNodeToMerge,
405 const UInt secondNodeToMerge,
407 CompoundUndoAction& undoAction);
410 void FindNodesToDelete(
const Polygons& polygon,
411 const bool invertDeletion,
412 std::vector<bool>& isNodeInsidePolygon,
413 std::vector<bool>& deleteNode)
const;
416 void DeletedMeshNodesAndEdges(
const std::function<
bool(
UInt)>& excludedFace,
417 std::vector<bool>& deleteNode,
418 CompoundUndoAction& deleteMeshAction);
421 std::vector<int> ComputeNodeMask(
const Polygons& polygons)
const;
424 std::vector<int> ComputeEdgeMask(
const std::vector<int>& nodeMask,
425 bool includeIntersected)
const;
428 void RemoveIntersected(
const std::vector<int>& edgeMask,
429 std::vector<int>& secondEdgeMask)
const;
432 void InvertSelection(
const std::vector<int>& edgeMask,
433 std::vector<int>& secondEdgeMask)
const;
436 std::vector<bool> FindFacesEntirelyInsidePolygon(
const std::vector<bool>& isNodeInsidePolygon)
const;
442 [[nodiscard]] std::unique_ptr<UndoAction> DeleteMeshFaces(
const Polygons& polygon,
bool invertDeletion);
454 void FindFacesRecursive(
UInt startNode,
457 UInt numClosingEdges,
458 std::vector<UInt>& edges,
459 std::vector<UInt>& nodes,
460 std::vector<UInt>& sortedEdges,
461 std::vector<UInt>& sortedNodes,
462 std::vector<Point>& nodalValues);
468 [[nodiscard]]
bool HasTriangleNoAcuteAngles(
const std::vector<UInt>& faceNodes,
const std::vector<Point>& nodes)
const;
473 bool HasDuplicateNodes(
const UInt numClosingEdges,
const std::vector<UInt>& node, std::vector<UInt>& sortedNodes)
const;
478 bool HasDuplicateEdgeFaces(
const UInt numClosingEdges,
const std::vector<UInt>& edges, std::vector<UInt>& sortedEdgesFaces)
const;
481 void ResizeAndInitializeFaceVectors();
486 void DoAdministrationGivenFaceNodesMapping(
const std::vector<std::vector<UInt>>& faceNodes,
487 const std::vector<std::uint8_t>& numFaceNodes);
491 void DoAdministration(CompoundUndoAction* undoAction =
nullptr);
494 void InitialiseBoundaryNodeClassification(std::vector<int>& intNodeType)
const;
500 void ComputeAverageFlowEdgesLength(std::vector<double>& edgesLength,
501 std::vector<double>& averageFlowEdgesLength)
const;
504 void ComputeAverageEdgeLength(
const std::vector<double>& edgesLength,
505 const std::vector<double>& averageFlowEdgesLength,
506 std::vector<bool>& curvilinearGridIndicator,
507 std::vector<std::array<double, 2>>& averageEdgesLength,
508 std::vector<double>& aspectRatios)
const;
512 UInt InvalidateEdgesWithNoFace();
514 std::vector<MeshNodeType> m_nodesTypes;
A class defining a bounding box.
Definition BoundingBox.hpp:40
A class derived from Mesh, which describes unstructures 2d meshes.
Definition Mesh2D.hpp:58
Mesh2D()
Default constructor.
Mesh2D(const std::vector< Edge > &edges, const std::vector< Point > &nodes, const std::vector< std::vector< UInt > > &faceNodes, const std::vector< std::uint8_t > &numFaceNodes, Projection projection)
Construct a mesh2d from face nodes and num face nodes.
~Mesh2D() override=default
Default destructor.
std::vector< int > NodeMaskFromEdgeMask(std::vector< int > const &edgeMask) const
From the edge mask compute the node mask.
static std::unique_ptr< Mesh2D > Merge(const std::span< const Point > &mesh1Nodes, const std::span< const Edge > &mesh1Edges, const std::span< const Point > &mesh2Nodes, const std::span< const Edge > &mesh2Edges, const Projection projection)
Merges mesh node and edge connectivity into a single mesh.
std::unique_ptr< meshkernel::UndoAction > DeleteSmallFlowEdges(double smallFlowEdgesThreshold)
Deletes small flow edges (removesmallflowlinks, part 1)
void ComputeFaceClosedPolygonWithLocalMappings(UInt faceIndex, std::vector< Point > &polygonNodesCache, std::vector< UInt > &localNodeIndicesCache, std::vector< UInt > &globalEdgeIndicesCache) const
For a face create a closed polygon and fill local mapping caches (get_cellpolygon)
UInt NextFace(const UInt faceId, const UInt edgeId) const
Get the next face adjacent to the edge on the opposite side.
MeshNodeType GetNodeType(const UInt nodeId) const
Get the node type.
Definition Mesh2D.hpp:213
DeleteMeshOptions
Enumerator describing the different options to delete a mesh.
Definition Mesh2D.hpp:65
std::vector< BoundingBox > GetEdgesBoundingBoxes() const
Get the bounding boxes of the mesh edges.
void FindNodesSharedByFaces(UInt nodeIndex, const std::vector< UInt > &sharedFaces, std::vector< UInt > &connectedNodes, std::vector< std::vector< UInt > > &faceNodeMapping) const
Find all unique nodes.
UInt FindOppositeEdge(const UInt faceId, const UInt edgeId) const
Find edge on the opposite side of the element.
std::vector< UInt > SortedFacesAroundNode(UInt node) const
Sorts the faces around a node, sorted in counter clock wise order.
std::vector< UInt > GetHangingEdges() const
Gets the hanging edges.
std::vector< int > MaskEdgesOfFacesInPolygon(const Polygons &polygons, bool invertSelection, bool includeIntersected) const
Masks the edges of all faces entirely included in all polygons.
void MakeDualFace(const std::span< const Point > edgeCentres, UInt node, double enlargementFactor, std::vector< Point > &dualFace) const
Make a dual face around the node, enlarged by a factor.
void FindFaces()
Constructs the face nodes mapping, face mass centers and areas.
void RestoreAction(const SphericalCoordinatesOffsetAction &undoAction)
Undo the coordinate offset action.
void CommitAction(const SphericalCoordinatesOffsetAction &undoAction)
Apply the coordinate offset action.
std::tuple< UInt, UInt > IsSegmentCrossingABoundaryEdge(const Point &firstPoint, const Point &secondPoint) const
Inquire if a segment is crossing a face.
void ComputeAspectRatios(std::vector< double > &aspectRatios) const
Gets the aspect ratios (the ratios edges lengths to flow edges lengths)
UInt FindCommonFace(const UInt edge1, const UInt edge2) const
Find the id of the element that is common to both edges.
std::unique_ptr< UndoAction > DeleteSmallTrianglesAtBoundaries(double minFractionalAreaTriangles)
Deletes small triangles at the boundaries (removesmallflowlinks, part 2)
void Administrate(CompoundUndoAction *undoAction=nullptr) override
Perform complete administration.
std::vector< Point > ComputeBoundaryPolygons(const std::vector< Point > &polygon)
Convert all mesh boundaries to a vector of polygon nodes, including holes (copynetboundstopol)
std::vector< UInt > PointFaceIndices(const std::vector< Point > &points)
For a collection of points, compute the face indices including them.
UInt IsStartOrEnd(const UInt edgeId, const UInt nodeId) const
Determine if the node is at the start or end of the edge.
std::vector< UInt > GetEdgesCrossingSmallFlowEdges(double smallFlowEdgesThreshold)
Gets the edges crossing the small flow edges.
void WalkBoundaryFromNode(const Polygon &polygon, std::vector< bool > &isVisited, UInt ¤tNode, std::vector< Point > &meshBoundaryPolygon) const
Constructs a polygon from the meshboundary, by walking through the mesh.
void ComputeFaceAreaAndMassCenters(bool computeMassCenters=false)
Compute face mass center.
std::unique_ptr< UndoAction > DeleteDegeneratedTriangles()
Deletes coinciding triangles.
Mesh2D(const std::vector< Point > &nodes, const Polygons &polygons, Projection projection)
Create triangular grid from nodes (triangulatesamplestonetwork)
std::vector< Point > GetFlowEdgesCenters(const std::vector< UInt > &edges) const
Gets the flow edges centers from the crossing edges.
Mesh2D(Projection projection)
Construct a mesh2d using only the projection.
static std::unique_ptr< Mesh2D > Merge(const Mesh2D &mesh1, const Mesh2D &mesh2)
Merges mesh connectivity.
std::unique_ptr< UndoAction > DeleteMesh(const Polygons &polygon, DeleteMeshOptions deletionOption, bool invertDeletion)
Deletes a mesh in a polygon, using several options (delnet)
void GetConnectingNodes(UInt nodeIndex, std::vector< UInt > &connectedNodes) const
Get indices of all nodes that are connected directly to a give node along connected edges.
Mesh2D(const std::vector< Edge > &edges, const std::vector< Point > &nodes, Projection projection)
Construct a mesh2d starting from the edges and nodes.
std::vector< int > NodeMaskFromPolygon(const Polygons &polygons, bool inside) const
Mask all nodes included in all polygons.
UInt IsLeftOrRight(const UInt elementId, const UInt edgeId) const
Determine if the element lies on the left or right side of the edge.
std::vector< Point > GetObtuseTrianglesCenters()
Gets the mass centers of obtuse triangles.
void ComputeNodeNeighbours(std::vector< std::vector< UInt > > &nodesNodes, UInt &maxNumNeighbours) const
Computes node neighbours.
BoundingBox GetBoundingBox() const
Get the mesh bounding box.
std::unique_ptr< UndoAction > TriangulateFaces(const Polygons &polygon)
Transform non-triangular faces inside a polygon to triangular faces.
void ClassifyNodes()
Classifies the nodes (makenetnodescoding)
std::vector< bool > FilterBasedOnMetric(Location location, Property property, double minValue, double maxValue) const
This method generates a mask indicating which locations are within the specified range of the given m...
void FindFacesConnectedToNode(UInt nodeIndex, std::vector< UInt > &sharedFaces) const
Find all faces that have the given node as a vertex.
void GetNodeTypes(std::vector< MeshNodeType > &nodeTypes) const
Get the node type.
Definition Mesh2D.hpp:216
std::unique_ptr< SphericalCoordinatesOffsetAction > OffsetSphericalCoordinates(double minx, double maxx)
Offset the x coordinates if m_projection is spherical.
std::unique_ptr< UndoAction > DeleteHangingEdges()
Deletes the hanging edges.
void FindFacesGivenFaceNodesMapping(const std::vector< std::vector< UInt > > &faceNodes, const std::vector< std::uint8_t > &numFaceNodes)
Find remaining face information given the face nodes mapping.
std::unique_ptr< UndoAction > TriangulateFaces()
Transform non-triangular faces to triangular faces.
A class describing an unstructured mesh. This class contains the shared functionality between 1d or 2...
Definition Mesh.hpp:99
void RestoreAction(const ResetNodeAction &undoAction)
Undo the reset node action.
void CommitAction(const ResetNodeAction &undoAction)
Apply the reset node action.
A struct describing a point in a two-dimensional space.
Definition Point.hpp:41
A closed polygon.
Definition Polygon.hpp:46
A class containing a list of polygonaly enclosed regions.
Definition Polygons.hpp:45
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37
Projection
Enumerator describing the supported projections.
Definition Definitions.hpp:43
MeshNodeType
Possible unstructured node types.
Definition Definitions.hpp:148
Location
Mesh locations enumeration.
Definition Definitions.hpp:76
Property
Enumerator for different properties on a 2D mesh.
Definition Definitions.hpp:158
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition Definitions.hpp:39