Get the source-code of this example.
See also the Borland Delphi version,
the C# version, the native (direct) C++ version.
' Very simple VB program to mesh a square with triangles or quadrangles.
' Uses CM2 TriaMesh and CM2 QuadMesh through the COM interface.
' Import the necessary CM2 MeshTools TLB components.
Imports CCM2MATH1Lib
Imports cm2meshtools = CCM2MESHTOOLSLib
Imports cm2meshtools1d = CCM2MESHTOOLS1DLib
Imports cm2triamesh = CCM2TRIAMESHLib
Imports cm2quadmesh = CCM2QUADMESHLib
Module Module1
Sub Main()
Dim msg1 As String ' For error messages.
Try
Dim pos As New DoubleMat ' To store the coordinates matrix.
Dim indices As New UIntVec ' To store the indices of the boundary nodes.
Dim connectB As New UIntMat ' To store the connectivity matrix of the boundary edges.
Dim connectM As New UIntMat ' To store the connectivity of the 2-D mesh.
Dim MT As New cm2meshtools.MeshTools ' To use the procedures in the meshtools lib.
Dim MT1D As New cm2meshtools1d.MeshTools1D ' To use the procedures in the meshtools1D lib.
Dim mesherT3 As New cm2triamesh.mesher ' Instance of triangle mesher.
Dim mesherQ4 As New cm2quadmesh.mesher ' Instance of quadrangle mesher.
Dim dataT3 As New cm2triamesh.data_type ' Data record for a triangle mesher.
Dim dataQ4 As New cm2quadmesh.data_type ' Data record for a quadrangle mesher.
' DLL REGISTRATION. REPLACE WITH YOUR COMPANY'S KEYS.
mesherT3.registration ("Licensed to DEMO.", "B36C4016CA0B") ' All cm2triamesh.mesher are now runnable.
mesherQ4.registration ("Licensed to DEMO.", "52E503F92365") ' All cm2quadmesh.mesher are now runnable.
' THE FOUR VERTICES OF THE SQUARE.
pos.push_back2 (0.0, 0.0)
pos.push_back2 (4.0, 0.0)
pos.push_back2 (4.0, 4.0)
pos.push_back2 (0.0, 4.0)
' MESH THE FOUR SEGMENTS (10 ELEMENTS ON EACH SEGMENT).
MT1D.mesh_straight1 (pos, 0, 1, 10, indices)
indices.pop_back()
MT1D.mesh_straight1 (pos, 1, 2, 10, indices)
indices.pop_back()
MT1D.mesh_straight1 (pos, 2, 3, 10, indices)
indices.pop_back()
MT1D.mesh_straight1 (pos, 3, 0, 10, indices)
MT1D.indices_to_connectE2(indices, connectB)
' DO THE TRIANGLE MESH.
dataT3.pos = pos ' The coordinates.
dataT3.connectB = connectB ' The boundary.
mesherT3.run (dataT3) ' Run the mesher.
If dataT3.error_code <> 0 Then
msg1 = dataT3.msg1 ' Error reporting (license error, boundary error...)
Throw New Exception(msg1)
End If
pos = dataT3.pos ' The coordinate matrix has been extended with new nodes.
connectM = dataT3.connectM ' The triangle connectivity matrix.
dataT3.print_info() ' Print some info on console about the generated mesh.
' MEDIT OUTPUT OF THE TRIANGLE MESH.
MT.medit_output ("T3.mesh", pos, connectM, cm2meshtools.Celement_type.CM2_FACET3)
' DO THE SAME WITH THE QUAD MESHER.
dataQ4.pos = pos
dataQ4.connectB = connectB
mesherQ4.run (dataQ4)
If dataQ4.error_code <> 0 Then
msg1 = dataQ4.msg1
Throw New Exception(msg1)
End If
pos = dataQ4.pos
connectM = dataQ4.connectM
dataQ4.print_info()
MT.medit_output ("Q4.mesh", pos, connectM, cm2meshtools.Celement_type.CM2_FACEQ4)
Catch ex As Exception
Console.WriteLine (msg1)
End Try
End Sub
End Module
© 1999-2006 Computing Objects. All rights reserved.