I am used to creating meshes through GMSH (.msh), transform them into XDMF format by meshio-convert and read them in python as follows:
mesh = Mesh() filename = "../meshes/fixed_bed-mesh.xdmf" with XDMFFile(MPI.comm_world, filename) as infile: infile.read(mesh)
This mesh corresponds to a rectangle with dimensions 5.0 x 0.01. I have solved several PDEs systems with FEniCS over this kind of meshes but, given that this rectangle is too thin, I have been visualizing the results with ParaView since I am allowed to scale any direction (X, Y or Z).
For instance: Without Y-axis scaling (top mesh), with Y-axis scaling x 10 (bottom mesh).
However, I want to see the results directly in Python. Accordingly, I found the way to plot triangular grids with MatPlotLib as in the next short example:
from dolfin import * from mshr import * import matplotlib.pyplot as plt import matplotlib.tri as tri import numpy as np # Mesh generation – but I usually create them with GMSH as mentioned above. domain = Rectangle(Point(0.0, 0.0), Point(5.0, 0.01)) mesh = generate_mesh(domain, 20) V = FunctionSpace(mesh, 'CG', 2) f_exp = Expression('sin(2*pi*(x*x+x*x))', degree=2) f = interpolate(f_exp, V) n = mesh.num_vertices() d = mesh.geometry().dim() # Create the triangulation mesh_coordinates = mesh.coordinates().reshape((n, d)) triangles = np.asarray([cell.entities(0) for cell in cells(mesh)]) triangulation = tri.Triangulation(mesh_coordinates[:, 0], mesh_coordinates[:, 1], triangles) # Get the z values for each vertex z = np.asarray([f(point) for point in mesh_coordinates]) # Plot FEniCS solution with tripcolor function cmap = plt.cm.jet plt.figure() plt.tripcolor(triangulation, z, cmap=cmap, shading='gouraud') plt.colorbar()
The problem is that I don´t know how to scale Y-axis or any direction so that I can evidence what I normally see in ParaView. Is there any way to do that either with Matplotlib or FEniCS plots functions ?. Or will I be forced to keep using ParaView to visualize the results of my simulations when working with such thin meshes?
If somebody needs any additional information, I will be heedful.
Thank you very much for your attention and helpful suggestion.