1.4. Reading a 2D .obj file

Reading a 2D .obj file with material IDs and boundary IDs.

Click here for more information on WaveFront objects, aka obj

1.4.1. Create an Unstructured Mesh

We have created an unstructured triangular mesh with the Triangle Mesh Generator. Triangle is also accessible via Meshpy in python. Then, one needs to convert the data generated by Triangle into the Wavefront (obj) format.

1.4.2. Read the Mesh

We use the FromFileMeshGenerator and pass the path to the obj file. We also partition the 2D mesh into 2x2 subdomains using Parmetis. Finally, we export the mesh to a VTU file.

The resulting mesh and material layout is shown below:

Mesh_Material

When using the Parmetis partitioner, we obtain:

Mesh_Partition

FYI, had we chosen the KBA partitioner, the partition would have been:

Mesh_Partition

-- Setup the mesh
meshgen = mesh.MeshGenerator.Create({
  inputs = {
    mesh.FromFileMeshGenerator.Create({
      filename = "./tri_2mat_bc_1542.obj",
    }),
  },
  partitioner = mesh.PETScGraphPartitioner.Create({ type = "parmetis" }),
})
mesh.MeshGenerator.Execute(meshgen)
mesh.ExportToPVTU("Triangle_1542_mesh_only")

1.4.3. The complete input is below:

You can copy/paste the text below or look in the file named tutorials/meshing/read_2D_obj.lua:

-- Setup the mesh
meshgen = mesh.MeshGenerator.Create({
  inputs = {
    mesh.FromFileMeshGenerator.Create({
      filename = "./tri_2mat_bc_1542.obj",
    }),
  },
  partitioner = mesh.PETScGraphPartitioner.Create({ type = "parmetis" }),
})
mesh.MeshGenerator.Execute(meshgen)

mesh.ExportToPVTU("Triangle_1542_mesh_only")