Creating Triangle Meshes

How can I create the triangular mesh using Fenicsx and Dolfix without Gmsh. For example, I created the master triangle element with this code:

import dolfinx
import ufl
from mpi4py import MPI
import numpy as np
gdim = 2
shape = “triangle”
degree = 1
cell = ufl.Cell(shape, geometric_dimension=gdim)
domain = ufl.Mesh(ufl.VectorElement(“Lagrange”, cell, degree))

x = np.array([[0.0, 0.0], # Vertex 0
[1.0, 0.0], # Vertex 1
[0.0, 1.0]]) # Vertex 2

cells = np.array([[0, 1, 2]], dtype=np.int32) # One triangle composed of the above three vertices

mesh = dolfinx.mesh.create_mesh(MPI.COMM_WORLD, cells, x, domain)

and its one-level refined version with this code:

import dolfinx
import ufl
from mpi4py import MPI
import numpy as np
gdim = 2
shape = “triangle”
degree = 1
cell = ufl.Cell(shape, geometric_dimension=gdim)
domain = ufl.Mesh(ufl.VectorElement(“Lagrange”, cell, degree))
x = np.array([[0.0, 0.0], # Vertex 0
[1.0, 0.0], # Vertex 1
[0.0, 1.0], # Vertex 2
[0.5, 0.0], # Vertex 3 (midpoint of edge 0-1)
[0.5, 0.5], # Vertex 4 (midpoint of edge 1-2)
[0.0, 0.5]]) # Vertex 5 (midpoint of edge 2-0)

Define cells for the refined mesh

cells = np.array([[0, 3, 5], # Lower left triangle
[4, 5, 3], # Lower right triangle
[3, 1, 4], # Middle triangle
[5, 4, 2]], # Top triangle
dtype=np.int32)
mesh = dolfinx.mesh.create_mesh(MPI.COMM_WORLD, cells, x, domain)
tdim = mesh.topology.dim
fdim = tdim - 1
mesh.topology.create_connectivity(fdim, tdim)

My question is, triangular mesh Gmsh etc. How can I create it directly automatically without using it? For example,
msh = mesh.create_rectangle(
comm=MPI.COMM_WORLD,
points=((0.0, 0.0), (2.0, 1.0)),
n=(32, 16),
cell_type=mesh.CellType.triangle,
)
V = fem.functionspace(msh, (“Lagrange”, 1))

approximations /codes like this, how can I create triangular mesh and triangular cell?

I dont understand your question.

Do you want to know how to create an arbitrary refined triangular mesh?

You could successively use the red
Fine command to increase the number of cells in your mesh.