AMCAX Kernel 1.0.0.0
Loading...
Searching...
No Matches
HyperBlock Example

Overview

This tutorial provides the basic usage of HyperBlock (block-structured meshing), including importing geometric files for generating structured meshes, initializing and editing mesh blocks based on geometric models, and finally discretizing the mesh to achieve structured mesh generation based on geometric models. The NMBlock API includes mesh block initialization, block editing, association constraints, projection transformations, movement operations, edge matching, node distribution control, mesh discretization, quality optimization, and data query.

Functional Categories

Initialization Operations

  • Init - Initialize mesh blocks

Block Editing Operations

  • SplitEdge - Edge splitting
  • SplitEdgeByProject - Edge splitting by projection points
  • SplitEdgeUniform - Uniform edge splitting
  • OSplit - O-type splitting operation
  • JoinHex - Connect hexahedrons
  • DeleteHex - Delete hexahedrons

Association Operations

  • AssociateVertex - Vertex association
  • AssociateEdge - Edge association
  • AssociateFace - Face association
  • DisassociateVertex - Cancel vertex association
  • DisassociateEdge - Cancel edge association
  • DisassociateFace - Cancel face association

Projection Transformation Operations

  • ProjectNode - Project nodes
  • ProjectEdge - Project edges
  • MoveNodes - Move nodes
  • MoveEdges - Move edges
  • MoveFaces - Move faces

Edge Matching Operations

  • MatchEdgeToEdge - Edge-to-edge matching
  • MatchEdgeToCurve - Edge-to-curve matching
  • MatchEdgeToPoints - Edge-to-points matching

Distribution Control Operations

  • SetEdgesDistribution - Set edge distribution
  • RevertEdgesDistribution - Revert edge distribution

Discretization Operations

  • DiscreteHyperFaces - Discretize all block faces
  • DiscreteFace - Discretize block faces
  • DiscreteHyperBlock - Discretize all blocks
  • DiscreteBlock - Discretize blocks

Smoothing Operations

  • SmoothFaces - Smooth faces
  • SmoothBlocks - Smooth blocks

Data Query

  • GetVertexCount - Get vertex count
  • GetEdgeCount - Get edge count
  • GetFaceCount - Get face count
  • GetBlockCount - Get block count
  • GetEdgeVertexs - Get edge vertices
  • GetFaceVertexs - Get face vertices
  • GetBlockVertexs - Get block vertices
  • GetFaceEdges - Get face edges
  • GetBlockEdges - Get block edges
  • GetBlockFaces - Get block faces
  • GetVertexRepresentation - Get vertex geometric representation
  • GetEdgeRepresentation - Get edge geometric representation
  • GetFaceRepresentation - Get face geometric representation
  • GetAllMeshNodes - Get all mesh nodes
  • GetEdgeMesh - Get edge mesh
  • GetFaceMesh - Get face quadrilateral mesh
  • GetBlockMesh - Get block hexahedral mesh

Namespace

For clear example code, use namespace.

using namespace AMCAX::NextMesh;
using namespace AMCAX;
Namespace of all interface in the AMCAX NextMesh module.
Definition misc.docu:42
Namespace of all interface in the AMCAX kernel.
Definition misc.docu:8

Import Geometric Model

Import geometric file.

const std::string filedir = "./data/7.brep";
OCCTIO::OCCTTool::Read(shape, filedir);
NMAPIModel nmapi;
nmapi.ImportModel({ shape });
std::vector<NMEntity> ents0, ents1, ents2;
nmapi.GetEntities(ents0, DimType::D0);
nmapi.GetEntities(ents1, DimType::D1);
nmapi.GetEntities(ents2, DimType::D2);
Class of model in NextMesh.
Definition NMAPIModel.hpp:22
AMCAX_API void ImportModel(const std::vector< NMShape > &shapes, const bool replace=true)
Load a cad model represented by AMCAX TopoShape. Note: this import method does not specify any entity...
AMCAX_API void GetEntities(std::vector< NMEntity > &ents, const DimType dim)
get all the entities in the specified dim
static AMCAX_API bool Read(TopoShape &s, std::istream &is)
Read a shape from a stream.
Base class of shape, containing an underlying shape with a location and an orientation.
Definition TopoShape.hpp:15

The geometric model is shown below:

Edit Mesh Blocks

Get mesh block operation object

NMBlock &blockapi = nmapi.GetNMBlock();
AMCAX_API NMBlock & GetNMBlock()
Get the mesh block handle.
Class of Block in NextMesh.
Definition NMBlock.hpp:20

Initialize mesh blocks

blockapi.Init();
AMCAX_API void Init()
Initializes the NMBlock with bounding box from the geometric model.

Mesh block initialization result:

Edge splitting

// Split edge with ID 0 at 30% and 70% positions, dividing into 3 segments
blockapi.SplitEdge(0, {0.3, 0.7});
AMCAX_API void SplitEdge(const Indext eid, const std::vector< double > &ratios)
Splits an edge at specified ratios.

Based on mesh block initialization, edge splitting result:

Projection point edge splitting

// Split edge by projecting spatial point onto edge
NMPoint3 projectionPoint = {1.5, 2.0, 3.0};
blockapi.SplitEdgeByProject(1, projectionPoint);
AMCAX_API void SplitEdgeByProject(const Indext eid, const NMPoint3 &pos, double tol=1e-2)
Splits an edge by projecting a point onto it.
AMCAX::Coord3d NMPoint3
Type of point/vector.
Definition Macros.hpp:25

Based on mesh block initialization, projection point edge splitting result:

Uniform edge splitting

// Uniformly split edge into 5 segments
blockapi.SplitEdgeUniform(1, 5);
AMCAX_API void SplitEdgeUniform(const Indext eid, const Indext segNum)
Splits an edge into uniform segments.

Based on mesh block initialization, uniform edge splitting result:

O-type splitting operation

// Perform O-type splitting on specified hexahedral blocks
std::vector<Indext> blockIds = {0};
std::vector<Indext> faceIds = {0, 5};
double offset = 0.5;
blockapi.OSplit(blockIds, faceIds, offset);
AMCAX_API void OSplit(const std::vector< Indext > &hids, const std::vector< Indext > &fids, const double &offset)
Performs offset split on specified hexes and faces.

Based on mesh block initialization, O-type splitting result:

Connect hexahedrons

// Connect hexahedrons through specified faces
std::vector<Indext> connectFaces = {8, 9, 10};
bool success = blockapi.JoinHex(connectFaces);
AMCAX_API bool JoinHex(const std::vector< Indext > &fids)
Joins hex elements along specified faces.

Based on projection point edge splitting, hexahedron connection result:

Delete hexahedrons

// Delete specified hexahedrons
std::vector<Indext> hexToDelete = {1, 3};
blockapi.DeleteHex(hexToDelete);
AMCAX_API void DeleteHex(const std::vector< Indext > &hids)
Deletes specified hex elements.

Based on uniform edge splitting, hexahedron deletion result:

Vertex association

// Associate vertices to geometric points
std::vector<Indext> vertexIds = { 5 };
std::vector<NMEntity> NMEnts = { ents0[0]};
bool success = blockapi.AssociateVertex(vertexIds, DimType::D0, NMEnts);
AMCAX_API bool AssociateVertex(const std::vector< Indext > &vids, DimType dim, const std::vector< NMEntity > &NMEnts, bool translate=false)
Associates vertices with geometric entities.

Based on mesh block initialization, vertex association to geometric points result:

vertexIds = { 1 };
NMEnts = { ents1[1] };
success = blockapi.AssociateVertex(vertexIds, DimType::D1, NMEnts);

Based on previous operation, vertex association to geometric edges result:

vertexIds = { 2 };
NMEnts = { ents2[0] };
success = blockapi.AssociateVertex(vertexIds, DimType::D2, NMEnts);

Based on previous operation, vertex association to geometric faces result:

Edge association

// Associate mesh edges to geometric edges
std::vector<Indext> edgeIds = { 8, 9, 10, 11 };
std::vector<NMEntity> NMEnts = { ents1[0] };
bool success = blockapi.AssociateEdge(edgeIds, DimType::D1, NMEnts);
AMCAX_API bool AssociateEdge(const std::vector< Indext > &eids, DimType dim, const std::vector< NMEntity > &NMEnts, bool translate=false)
Associates edges with geometric entities.

Based on mesh block initialization, block edge association to geometric edges result:

Face association

// Associate mesh faces to geometric faces
std::vector<Indext> faceIds = {0, 2, 5, 8};
std::vector<NMEntity> geoFaces = { ents2[0] };
bool success = blockapi.AssociateFace(faceIds, geoFaces);
AMCAX_API bool AssociateFace(const std::vector< Indext > &fids, const std::vector< NMEntity > &NMEnts, bool translate=false)
Associates faces with geometric entities.

Based on O-type splitting, block face association to geometric faces result:

Cancel vertex association

// Cancel geometric association of specified vertices
std::vector<Indext> vertexIds = {1, 2, 3};
bool success = blockapi.DisassociateVertex(vertexIds);
AMCAX_API bool DisassociateVertex(const std::vector< Indext > &vids)
Disassociates specified vertices from geometric entities.

Canceling block vertex association does not cause vertex position changes.

Cancel edge association

// Cancel geometric association of specified edges
std::vector<Indext> edgeIds = {5, 6};
bool success = blockapi.DisassociateEdge(edgeIds);
AMCAX_API bool DisassociateEdge(const std::vector< Indext > &eids)
Disassociates specified edges from geometric entities.

Canceling block edge association does not cause vertex position changes.

Cancel face association

// Cancel geometric association of specified faces
std::vector<Indext> faceIds = {3, 4};
bool success = blockapi.DisassociateFace(faceIds);
AMCAX_API bool DisassociateFace(const std::vector< Indext > &fids)
Disassociates specified faces from geometric entities.

Canceling block face association does not cause vertex position changes.

Project nodes

// Project nodes to geometric faces
std::vector<Indext> vertexIds = { 5 };
std::vector<NMEntity> NMEnts = { ents0[0]};
bool success = blockapi.ProjectNode(vertexIds, NodeType::Vertex, DimType::D0, NMEnts);
AMCAX_API bool ProjectNode(const std::vector< Indext > &nids, NodeType type, DimType dim, const std::vector< NMEntity > &NMEnts, bool translate=false)
Projects nodes onto geometric entities.

Based on mesh block initialization, node projection to geometric points result:

Project edges

// Project edges to geometric curves
std::vector<Indext> edgeIds = { 3, 5 };
std::vector<NMEntity> NMEnts = { ents1[2] };
bool success = blockapi.ProjectEdge(edgeIds, DimType::D1, NMEnts);
AMCAX_API bool ProjectEdge(const std::vector< Indext > &eids, DimType dim, const std::vector< NMEntity > &NMEnts, bool translate=false)
Projects edges onto geometric entities.

Based on mesh block initialization, edge projection to geometric curves result:

Move nodes

Currently only supports moving vertices

// Move nodes along specified direction
std::vector<Indext> nodeIds = { 5, 7 };
NMVector3 moveVector = { 0., 0.0, 5.0 };
bool success = blockapi.MoveNodes(nodeIds, NodeType::Vertex, moveVector);
AMCAX_API bool MoveNodes(const std::vector< Indext > &nids, NodeType type, const NMVector3 &dir, bool translate=false)
Moves nodes in a specified direction.

Based on mesh block initialization, node movement result:

Move edges

// Move edges along specified direction
std::vector<Indext> edgeIds = { 10, 11 };
NMVector3 moveVector = { 0.0, 5.0, 0.0 };
bool success = blockapi.MoveEdges(edgeIds, moveVector, true);
AMCAX_API bool MoveEdges(const std::vector< Indext > &eids, const NMVector3 &dir, bool translate=false)
Moves edges in a specified direction.

Based on mesh block initialization, edge movement result:

Move faces

// Move faces along specified direction
std::vector<Indext> faceIds = { 0, 4 };
NMVector3 moveVector = { 0.0, 5.0, 0.0 };
bool success = blockapi.MoveFaces(faceIds, moveVector);
AMCAX_API bool MoveFaces(const std::vector< Indext > &fids, const NMVector3 &dir, bool translate=false)
Moves faces in a specified direction.

Based on mesh block initialization, face movement result:

Edge-to-edge matching

// Match source edge shape to target edge's optimal shape
std::vector<Indext> sourceEdges = { 20 };
std::vector<Indext> targetEdges = { 0 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 23 };
targetEdges = { 4 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 25 };
targetEdges = { 7 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 21 };
targetEdges = { 1 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 28 };
targetEdges = { 12 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 30 };
targetEdges = { 15 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 31 };
targetEdges = { 17 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 29 };
targetEdges = { 13 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
AMCAX_API bool MatchEdgeToEdge(const std::vector< Indext > &sourceEIds, const std::vector< Indext > &targetEIds, double matchFactor, bool translate=false)
Matches source edges to target edges.

Based on face association, edge-to-edge matching result:

Edge-to-curve matching

// Adjust edge shape to match geometric curve
std::vector<Indext> edgeIds = { 10, 11 };
std::vector<NMEntity> NMEnts = { ents1[2] };
double matchFactor = 0.8;
bool success = blockapi.MatchEdgeToCurve(edgeIds, NMEnts, matchFactor, true);
AMCAX_API bool MatchEdgeToCurve(const std::vector< Indext > &sourceEIds, const std::vector< NMEntity > &NMEnts, double matchFactor, bool translate=false)
Matches edges to curves.

Based on edge projection, edge-to-curve matching result:

Edge-to-points matching

// Adjust edge shape to pass through specified geometric points
std::vector<Indext> edgeIds = { 10, 11 };
std::vector<NMEntity> NMEnts = { ents0[0], ents0[1]};
double matchFactor = 0.5;
bool success = blockapi.MatchEdgeToPoints(edgeIds, NMEnts, matchFactor);
AMCAX_API bool MatchEdgeToPoints(const std::vector< Indext > &sourceEIds, const std::vector< NMEntity > &NMEnts, double matchFactor, bool translate=false)
Matches edges to points.

Based on edge projection, edge-to-points matching result:

Set edge distribution

Uniform node count distribution

// Associate mesh faces to geometric faces
std::vector<Indext> faceIds = {1, 2, 3, 4};
std::vector<NMEntity> geoFaces = { ents2[0] };
bool success = blockapi.AssociateFace(faceIds, geoFaces);
param._type = SpacingType::Number;
param._num = 10;
param._reverse = false;
param._parallel = false;
std::vector<Indext> edgeIds = { 0, 1 };;
bool success = blockapi.SetEdgesDistribution(edgeIds, param, true);
AMCAX_API bool SetEdgesDistribution(const std::vector< Indext > &eids, const SpacingParam &param)
Sets the point distribution along edges.
Control parameters for edge distribution.
Definition BlockMacros.hpp:48
bool _parallel
Apply distribution to parallel edges.
Definition BlockMacros.hpp:56
SpacingType _type
Distribution type.
Definition BlockMacros.hpp:49
bool _reverse
Reverse distribution direction.
Definition BlockMacros.hpp:55
unsigned _num
Number of nodes/segments.
Definition BlockMacros.hpp:52

Based on block initialization, first associate faces, then set Number distribution result:

Fixed length distribution

// Associate mesh faces to geometric faces
std::vector<Indext> faceIds = {1, 2, 3, 4};
std::vector<NMEntity> geoFaces = { ents2[0] };
bool success = blockapi.AssociateFace(faceIds, geoFaces);
param._type = SpacingType::Length;
param._startLen = 1.2;
param._reverse = false;
param._parallel = false;
std::vector<Indext> edgeIds = { 0, 1 };;
bool success = blockapi.SetEdgesDistribution(edgeIds, param, true);
double _startLen
Starting spacing length.
Definition BlockMacros.hpp:53

Based on block initialization, first associate faces, then set Length distribution result:

Linear distribution

// Associate mesh faces to geometric faces
std::vector<Indext> faceIds = {1, 2, 3, 4};
std::vector<NMEntity> geoFaces = { ents2[0] };
bool success = blockapi.AssociateFace(faceIds, geoFaces);
param._type = SpacingType::Linear;
param._mode = 0;
param._factor = 3;
param._num = 10;
param._reverse = false;
param._parallel = false;
std::vector<Indext> edgeIds = { 8, 9 };
bool success = blockapi.SetEdgesDistribution(edgeIds, param, true);
double _factor
Spacing ratio factor.
Definition BlockMacros.hpp:51
unsigned _mode
0=count factor, 1=size control
Definition BlockMacros.hpp:50

Based on block initialization, first associate faces, then set Linear distribution result:

Geometric progression distribution

// Associate mesh faces to geometric faces
std::vector<Indext> faceIds = {1, 2, 3, 4};
std::vector<NMEntity> geoFaces = { ents2[0] };
bool success = blockapi.AssociateFace(faceIds, geoFaces);
param._type = SpacingType::Geometric;
param._mode = 1;
param._startLen = 1.5;
param._endLen = 7.5;
param._reverse = false;
param._parallel = false;
std::vector<Indext> edgeIds = { 8, 9 };
bool success = blockapi.SetEdgesDistribution(edgeIds, param, true);
double _endLen
Ending spacing length.
Definition BlockMacros.hpp:54

Based on block initialization, first associate faces, then set Geometric distribution result:

Bell curve distribution

// Associate mesh faces to geometric faces
std::vector<Indext> faceIds = {1, 2, 3, 4};
std::vector<NMEntity> geoFaces = { ents2[0] };
bool success = blockapi.AssociateFace(faceIds, geoFaces);
param._type = SpacingType::BellCurve;
param._mode = 0;
param._num = 10;
param._factor = 5.0;
param._reverse = false;
param._parallel = false;
std::vector<Indext> edgeIds = { 8, 9 };
bool success = blockapi.SetEdgesDistribution(edgeIds, param, true);

Based on block initialization, first associate faces, then set BellCurve distribution result:

Auto CFD distribution

// Associate mesh faces to geometric faces
std::vector<Indext> faceIds = {1, 2, 3, 4};
std::vector<NMEntity> geoFaces = { ents2[0] };
bool success = blockapi.AssociateFace(faceIds, geoFaces);
param._type = SpacingType::AutoCFD;
param._growthRate = 1.5;
param._maxLength = 5.0;
param._minLength = 1.0;
param._distortionAngle = 15.0;
param._reverse = false;
param._parallel = false;
std::vector<Indext> edgeIds = { 8, 9 };
bool success = blockapi.SetEdgesDistribution(edgeIds, param, true);
double _minLength
Minimum spacing.
Definition BlockMacros.hpp:61
double _maxLength
Maximum spacing.
Definition BlockMacros.hpp:60
double _distortionAngle
Distortion angle (degrees)
Definition BlockMacros.hpp:62
double _growthRate
Growth rate.
Definition BlockMacros.hpp:59

Based on block initialization, first associate faces, then set AutoCFD distribution result (for curves):

Note: For edges with no significant curvature change, uniform distribution is used.

Revert edge distribution

// Associate mesh faces to geometric faces
std::vector<Indext> faceIds = {1, 2, 3, 4};
std::vector<NMEntity> geoFaces = { ents2[0] };
bool success = blockapi.AssociateFace(faceIds, geoFaces);
// Number
param._type = SpacingType::Number;
param._num = 10;
param._reverse = false;
param._parallel = false;
edgeIds = { 0, 1 };
blockapi.SetEdgesDistribution(edgeIds, param);
// Length
param._type = SpacingType::Length;
param._startLen = 1.2;
param._reverse = false;
param._parallel = false;
edgeIds = { 0, 1 };
blockapi.SetEdgesDistribution(edgeIds, param);
// Revert distribution settings for specified edges
blockapi.RevertEdgesDistribution(edgeIds);
AMCAX_API bool RevertEdgesDistribution(const std::vector< Indext > &eids, bool parallel=false)
Reverts edges to their original distribution.

Based on block initialization, first associate faces, then set Number distribution, then set Length distribution, finally revert edge distribution result:

Discretize all block faces

// Set edge distribution
param._type = SpacingType::Length;
param._startLen = 2;
param._reverse = false;
param._parallel = false;
edgeIds = {0, 1, 2, 3};
// Discretize all faces
if(blockapi.DiscreteHyperFaces())
{
std::cout << "Discrete all faces." << std::endl;
}
AMCAX_API bool DiscreteHyperFaces()
Discretizes all hyper faces into mesh elements.

Based on edge-to-edge matching, first set edge distribution, then discretize all block faces result:

Discretize block faces

// Set edge distribution
param._type = SpacingType::Length;
param._startLen = 2;
param._reverse = false;
param._parallel = false;
edgeIds = {0, 1, 2, 3};
// Discretize specified faces
faceIds = { 21 };
if(blockapi.DiscreteFace(faceIds))
{
std::cout << "Discrete face : " ;
for(auto id : faceIds)
{
std::cout << id << " ";
}
std::cout << std::endl;
}
AMCAX_API bool DiscreteFace(const std::vector< Indext > &fids)
Discretizes specified faces.

Based on edge-to-edge matching, first set edge distribution, then discretize block faces result:

Discretize all blocks

// Set edge distribution
param._type = SpacingType::Length;
param._startLen = 2;
param._reverse = false;
param._parallel = false;
edgeIds = {0, 1, 2, 3};
// Discretize all blocks to generate 3D mesh
if(blockapi.DiscreteHyperBlocks())
{
std::cout << "Discrete all blocks." << std::endl;
}

Based on edge-to-edge matching, first set edge distribution, then discretize all blocks result:

Discretize blocks

// Set edge distribution
param._type = SpacingType::Length;
param._startLen = 2;
param._reverse = false;
param._parallel = false;
edgeIds = {0, 1, 2, 3};
// Discretize specified blocks
blockIds = { 0 };
if(blockapi.DiscreteBlock(blockIds))
{
std::cout << "Discrete block : " ;
for(auto id : blockIds)
{
std::cout << id << " ";
}
std::cout << std::endl;
}
AMCAX_API bool DiscreteBlock(const std::vector< Indext > &hids)
Discretizes specified blocks.

Based on edge-to-edge matching, first set edge distribution, then discretize blocks result:

Smooth faces

// Smooth face mesh
SmoothParam smoothParam;
smoothParam.faceIds = {21};
smoothParam._optimizerType = SmoothType::LAPLACIAN;
smoothParam._maxIteration = 20;
smoothParam._relaxationFactor = 0.3;
blockapi.SmoothFaces(smoothParam);
AMCAX_API bool SmoothFaces(SmoothParam &param)
Smooths faces according to specified parameters.
Control parameters for mesh smooth.
Definition BlockMacros.hpp:85

Based on discretized block faces, face smoothing result (green lines: before smoothing, blue lines: after smoothing):

Note: Since block face boundaries need constraints, smoothing only optimizes discrete points inside the mesh face, so boundary discrete points don't change.

Smooth blocks

// Smooth 3D block mesh
SmoothParam smoothParam;
smoothParam._blockIds = {0, 1, 2}; // Block IDs to smooth
smoothParam._optimizerType = SoothType::ENERGY_BASED;
smoothParam._maxIteration = 15;
smoothParam._relaxationFactor = 0.3f;
bool success = blockapi.SmoothBlocks(smoothParam);
AMCAX_API bool SmoothBlocks(SmoothParam &param)
Smooths blocks according to specified parameters.

Based on discretized all blocks, block smoothing result:

Note: Since block boundaries need constraints, smoothing only optimizes discrete points inside the mesh block, so boundary discrete points don't change.

Get vertex count

// Get vertex count in mesh
Indext vertexCount = blockapi.GetVertexCount();
std::cout << "Mesh vertex count: " << vertexCount << std::endl;
AMCAX_API Indext GetVertexCount()
Gets the total number of vertices.

Get edge count

// Get edge count in mesh
Indext edgeCount = blockapi.GetEdgeCount();
std::cout << "Mesh edge count: " << edgeCount << std::endl;
AMCAX_API Indext GetEdgeCount()
Gets the total number of edges.

Get face count

// Get face count in mesh
Indext faceCount = blockapi.GetFaceCount();
std::cout << "Mesh face count: " << faceCount << std::endl;
AMCAX_API Indext GetFaceCount()
Gets the total number of faces.

Get block count

// Get block count in mesh
Indext blockCount = blockapi.GetBlockCount();
std::cout << "Mesh block count: " << blockCount << std::endl;
AMCAX_API Indext GetBlockCount()
Gets the total number of blocks.

Get edge vertices

// Get edge vertices
std::vector<Indext> vertexIds;
blockapi.GetEdgeVertexs(10, vertexIds);
std::cout << "Edge " << 10 << " connected vertices: ";
for (auto vid : vertexIds)
{
std::cout << vid << " ";
}
std::cout << std::endl;
AMCAX_API void GetEdgeVertexs(Indext eid, std::vector< Indext > &vids)
Gets vertices of an edge.

Get face vertices

// Get face vertices
std::vector<Indext> vertexIds;
blockapi.GetFaceVertexs(5, vertexIds);
std::cout << "Face " << 5 << " contains " << vertexIds.size() << " vertices" << std::endl;
AMCAX_API void GetFaceVertexs(Indext fid, std::vector< Indext > &vids)
Gets vertices of a face.

Get block vertices

// Get block vertices
std::vector<Indext> vertexIds;
blockapi.GetBlockVertexs(3, vertexIds);
std::cout << "Block " << 3 << " contains " << vertexIds.size() << " vertices" << std::endl;
AMCAX_API void GetBlockVertexs(Indext hid, std::vector< Indext > &vids)
Gets vertices of a block.

Get face edges

// Get face edges
std::vector<Indext> edgeIds;
blockapi.GetFaceEdges(8, edgeIds);
std::cout << "Face " << 8 << " consists of " << edgeIds.size() << " edges" << std::endl;
AMCAX_API void GetFaceEdges(Indext fid, std::vector< Indext > &eids)
Gets edges of a face.

Get block edges

// Get block edges
std::vector<Indext> edgeIds;
blockapi.GetBlockEdges(2, edgeIds);
std::cout << "Block " << 2 " contains " << edgeIds.size() << " edges" << std::endl;
AMCAX_API void GetBlockEdges(Indext hid, std::vector< Indext > &eids)
Gets edges of a block.

Get block faces

// Get block faces
std::vector<Indext> faceIds;
blockapi.GetBlockFaces(1, faceIds);
std::cout << "Block " << 1 << " contains " << faceIds.size() << " faces" << std::endl;
AMCAX_API void GetBlockFaces(Indext hid, std::vector< Indext > &fids)
Gets faces of a block.

Get vertex geometric representation

// Get vertex geometric representation
NMPoint3 vertexPos;
blockapi.GetVertexRepresentation(15, vertexPos);
std::cout << "Vertex position: (" << vertexPos.x() << ", " << vertexPos.y() << ", " << vertexPos.z() << ")" << std::endl;
AMCAX_API void GetVertexRepresentation(Indext vid, NMPoint3 &pos)
Gets the geometric position of a vertex.

Get edge geometric representation

// Get edge geometric representation
std::vector<NMPoint3> edgePoints;
blockapi.GetEdgeRepresentation(20, edgePoints);
std::cout << "Edge contains " << edgePoints.size() << " geometric points" << std::endl;
AMCAX_API void GetEdgeRepresentation(Indext eid, std::vector< NMPoint3 > &edgesPnts)
Gets the geometric representation of an edge.

Get face geometric representation

// Get face geometric representation
std::vector<NMPoint3> meshPoints;
std::vector<std::array<Indext, 3>> triangles;
blockapi.GetFaceRepresentation(12, meshPoints, triangles);
std::cout << "Face contains " << meshPoints.size() << " points and " << triangles.size() << " triangles" << std::endl;
AMCAX_API void GetFaceRepresentation(Indext fid, std::vector< NMPoint3 > &meshPnts, std::vector< std::array< Indext, 3 > > &meshfvs)
Gets the geometric representation of a face.

Get all mesh nodes

// Get all mesh nodes
std::vector<NMPoint3> allNodes;
blockapi.GetAllMeshNodes(allNodes);
std::cout << "Mesh contains " << allNodes.size() << " nodes in total" << std::endl;
AMCAX_API void GetAllMeshNodes(std::vector< NMPoint3 > &meshPnts)
Gets all mesh nodes.

Get edge mesh

// Get edge mesh connections
std::vector<std::array<Indext, 2>> lineElements;
blockapi.GetEdgeMesh(25, lineElements);
std::cout << "Edge contains " << lineElements.size() << " line elements" << std::endl;
AMCAX_API void GetEdgeMesh(Indext eid, std::vector< std::array< Indext, 2 > > &mlines)
Gets mesh connectivity for an edge.

Get face quadrilateral mesh

// Get face mesh connections
std::vector<std::array<Indext, 4>> quadElements;
blockapi.GetFaceMesh(18, quadElements);
std::cout << "Face contains " << quadElements.size() << " quadrilateral elements" << std::endl;
AMCAX_API void GetFaceMesh(Indext fid, std::vector< std::array< Indext, 4 > > &mquads)
Gets mesh connectivity for a face.

Get block hexahedral mesh

// Get block mesh connections
std::vector<std::array<Indext, 8>> hexElements;
blockapi.GetBlockMesh(7, hexElements);
std::cout << "Block contains " << hexElements.size() << " hexahedral elements" << std::endl;
AMCAX_API void GetBlockMesh(Indext hid, std::vector< std::array< Indext, 8 > > &mhexs)
Gets mesh connectivity for a block.

Complete Example

The following is a complete example demonstrating how to import a geometric model, initialize mesh blocks, edit mesh blocks, associate geometry, discretize mesh blocks, and smooth the mesh. The specific code is as follows:

using namespace AMCAX::NextMesh;
using namespace AMCAX;
int main()
{
// import geometry and get instance of NMBlock
const std::string filedir = "./data/7.brep";
OCCTIO::OCCTTool::Read(shape, filedir);
NMAPIModel nmapi;
nmapi.ImportModel({ shape });
std::vector<NMEntity> ents0, ents1, ents2;
nmapi.GetEntities(ents0, DimType::D0);
nmapi.GetEntities(ents1, DimType::D1);
nmapi.GetEntities(ents2, DimType::D2);
NMBlock& blockapi = nmapi.GetNMBlock();
std::vector<Indext> vertexIds;
std::vector<Indext> edgeIds;
std::vector<Indext> faceIds;
std::vector<Indext> blockIds;
std::vector<Indext> sourceEdges;
std::vector<Indext> targetEdges;
std::vector<NMEntity> NMEnts;
bool success;
double matchFactor = 0.0;
NMVector3 moveVector = { 0., .0, .0 };
// init
blockapi.Init();
// edit
blockIds = { 0 };
faceIds = { 0, 5 };
double offset = 0.5;
blockapi.OSplit(blockIds, faceIds, offset);
// associate
faceIds = { 0, 2, 5, 8 };
NMEnts = { ents2[0] };
success = blockapi.AssociateFace(faceIds, NMEnts);
// match
sourceEdges = { 20 };
targetEdges = { 0 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 23 };
targetEdges = { 4 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 25 };
targetEdges = { 7 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 21 };
targetEdges = { 1 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 28 };
targetEdges = { 12 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 30 };
targetEdges = { 15 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 31 };
targetEdges = { 17 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
sourceEdges = { 29 };
targetEdges = { 13 };
matchFactor = 0.5;
success = blockapi.MatchEdgeToEdge(sourceEdges, targetEdges, matchFactor);
// distribution
SpacingParam param;
param._type = SpacingType::Length;
param._startLen = 2;
param._reverse = false;
param._parallel = false;
edgeIds = { 0, 1, 2, 3 };
blockapi.SetEdgesDistribution(edgeIds, param);
// Discrete block
if (blockapi.DiscreteHyperBlock())
{
std::cout << "Discrete all blocks." << std::endl;
}
SmoothParam smoothParam;
smoothParam._blockIds = { 0 };
smoothParam._optimizerType = SmoothType::ENERGY_BASED;
smoothParam._maxIteration = 5;
smoothParam._relaxationFactor = 0.3;
blockapi.SmoothBlocks(smoothParam);
return 0;
}
Class of NextMesh Model.
Class of read and write shapes from OCCT BRep files.
AMCAX_API bool DiscreteHyperBlock()
Discretizes the entire hyper block.

Click here example06 to get the full source code of the complete example. Everyone can download it as needed.