# Cubit Mesh ## Geometry We construct the geometry by taking a horizontal cross-section of a 3D block. Alternatively, we could have constructed the geometry by building it up from points and curves like we did with Gmsh. {numref}`fig:example:strikeslip:2d:geometry:cubit` shows the geometry and variables names of the vertices and curves. :::{figure-md} fig:example:strikeslip:2d:geometry:cubit Geometry created in Cubit for generating the mesh. Geometry created in Cubit for generating the finite-element mesh. The names of the vertices and curves match the ones we use in the Cubit journal files. ::: ## Meshing using Python Script :::{note} New in v4.1.0 ::: We use the Python script `generate_cubit.py` to generate the mesh. The Python script is setup so that it can be run from within Cubit or as a standalone Python script without the Cubit GUI interface. In this example, we will run the script from within Cubit using the Journal editor. Open the Python script `generate_cubit.py` in the Cubit journal editor. Play the selected script or play the lines, making sure you play the first line so that Cubit uses the Python interpreter when running the script. We specify the parameters controlling the geometry, mesh size, and cell shape near the top of the script. :::{important} We reference objects by their centroid so the resulting script should be independent of the version of CUBIT that is being used. ::: :::{note} Examine how we set the discretization size in Gmsh and Cubit. In both cases the discretization size increases at a geometric rate with distance from the fault. For this simple geometry, it required less than 10 lines of Python code in Gmsh and about the same number of lines in Cubit. In Gmsh the code is very general and remains the same even as the domain geometry becomes more complex, whereas in Cubit the number of commands increases with the complexity of the geometry. ::: After running the Python script in Cubit, you will have a corresponding Exodus-II file (`mesh_tri.exo` or `mesh_quad.exo`). These are NetCDF files, and they can be loaded into ParaView. This can be done by either running ParaView and loading the file, or using the script provided in the viz directory. For example, if ParaView is in your path, you can run the following command: ```{code-block} console --- caption: Start paraview and run the `viz/plot_mesh.py` Python script to view the mesh with triangular cells. --- paraview --script=viz/plot_mesh.py ``` :::{figure-md} fig:example:strikeslip:2d:cubit:tri Finite-element mesh with triangular cells generated by Cubit. Finite-element mesh with triangular cells generated by Cubit. ::: To load the mesh with quadrilateral cells, open the Python Shell in ParaView and set the `EXODUS_FILE` variable, and then run the `viz/plot_mesh.py` Python script. See {ref}`sec-paraview-python-scripts` for more information about running ParaView Python scripts. ```{code-block} python --- caption: Load a different Exodus file generated by Cubit by setting the `EXODUS_FILE` variable in the ParaView Python Shell. --- EXODUS_FILE = "mesh_quad.exo" ``` :::{figure-md} fig:example:strikeslip:2d:cubit:quad Finite-element mesh with quadrilateral cells generated by Cubit. Finite-element mesh with quadrilateral cells generated by Cubit. :::