I try to plot some points on function follow this tutorial.But I meet follow error messages :
[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see https://petsc.org/release/faq/#valgrind
[0]PETSC ERROR: or try http://valgrind.org on GNU/linux and Apple MacOS to find memory corruption errors
[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run
[0]PETSC ERROR: to get more information on the crash.
[0]PETSC ERROR: Run with -malloc_debug to check if memory corruption is causing the crash.
application called MPI_Abort(MPI_COMM_WORLD, 59) - process 0
[unset]: write_line error; fd=-1 buf=:cmd=abort exitcode=59
:
system msg for write_line failure : Bad file descriptor
Here are my codes,errors happened after I add some codes about matplotlib
:
import numpy as np
import dolfinx.plot as plot
from dolfinx.fem import Function, FunctionSpace, VectorFunctionSpace
from dolfinx.mesh import (CellType, compute_midpoints, create_unit_cube,
create_unit_square, meshtags)
from mpi4py import MPI
import matplotlib.pyplot as plt
try:
import pyvista
except ModuleNotFoundError:
print("pyvista is required for this demo")
exit(0)
def plot_higher_order():
msh = create_unit_square(MPI.COMM_WORLD, 12, 12, cell_type=CellType.quadrilateral)
# We continue using the mesh from the previous section, and find all
# cells satisfying the condition below
def in_circle(x):
"""Mark sphere with radius < sqrt(2)"""
return np.array((x.T[0] - 0.5)**2 + (x.T[1] - 0.5)**2 < 0.2**2, dtype=np.int32)
# Create mesh tags for all cells. If midpoint is inside the
# circle, it gets value 1, otherwise 0.
num_cells = msh.topology.index_map(msh.topology.dim).size_local
midpoints = compute_midpoints(msh, msh.topology.dim, list(np.arange(num_cells, dtype=np.int32)))
cell_tags = meshtags(msh, msh.topology.dim, np.arange(num_cells), in_circle(midpoints))
# We start by interpolating a discontinuous function into a second order
# discontinuous Lagrange space. Note that we use the `cell_tags` from
# the previous section to get the cells for each of the regions
V = FunctionSpace(msh, ("Discontinuous Lagrange", 2))
u = Function(V, dtype=np.float64)
u.interpolate(lambda x: x[0], cell_tags.find(0))
u.interpolate(lambda x: x[1] + 1, cell_tags.find(1))
u.x.scatter_forward()
x = [0]
y = [1]
plt.scatter(x,y)
# To get a topology that has a 1-1 correspondence with the
# degrees-of-freedom in the function space, we call
# `dolfinx.plot.create_vtk_mesh`.
cells, types, x = plot.create_vtk_mesh(V)
# Create a pyvista mesh from the topology and geometry, and attach
# the coefficients of the degrees of freedom
grid = pyvista.UnstructuredGrid(cells, types, x)
grid.point_data["u"] = u.x.array
grid.set_active_scalars("u")
# We would also like to visualize the underlying mesh and obtain
# that as we have done previously
num_cells = msh.topology.index_map(msh.topology.dim).size_local
cell_entities = np.arange(num_cells, dtype=np.int32)
cells, types, x = plot.create_vtk_mesh(msh, entities=cell_entities)
org_grid = pyvista.UnstructuredGrid(cells, types, x)
# We visualize the data
plotter = pyvista.Plotter()
plotter.add_text("Second-order (P2) discontinuous elements",
position="upper_edge", font_size=14, color="black")
sargs = dict(height=0.1, width=0.8, vertical=False, position_x=0.1, position_y=0, color="black")
plotter.add_mesh(grid, show_edges=False, scalar_bar_args=sargs, line_width=0)
plotter.add_mesh(org_grid, color="white", style="wireframe", line_width=5)
plotter.add_mesh(grid.copy(), style="points", point_size=15, render_points_as_spheres=True, line_width=0)
plotter.view_xy()
if pyvista.OFF_SCREEN:
plotter.screenshot(f"DG_{MPI.COMM_WORLD.rank}.png",
transparent_background=transparent, window_size=[figsize, figsize])
else:
plotter.show()
plot_higher_order()
By the way,what should I do to change the font to Times new roman and plot the isopleth as follow figure shown: