import os
import urllib
import firedrake
import numpy as np
/home/firedrake/firedrake/lib/python3.12/site-packages/pytools/persistent_dict.py:52: RecommendedHashNotFoundWarning: Unable to import recommended hash 'siphash24.siphash13', falling back to 'hashlib.sha256'. Run 'python3 -m pip install siphash24' to install the recommended hash. warn("Unable to import recommended hash 'siphash24.siphash13', "
import viskex
Read in and plot mesh
msh_filename = "data/garda.msh"
if not os.path.isfile(msh_filename):
os.makedirs("data", exist_ok=True)
msh_url = (
"https://raw.githubusercontent.com/FEMlium/FEMlium/main/"
"tutorials/01_introduction/data/garda.msh")
with urllib.request.urlopen(msh_url) as response, open(msh_filename, "wb") as msh_file:
msh_file.write(response.read())
mesh = firedrake.Mesh("data/garda.msh")
viskex.firedrake.plot_mesh(mesh)
error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
viskex.firedrake.plot_mesh(mesh, dim=2)
error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
viskex.firedrake.plot_mesh(mesh, dim=1)
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
viskex.firedrake.plot_mesh(mesh, dim=0)
error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
Plot subdomains
viskex.firedrake.plot_mesh_sets(mesh, 2, "subdomains")
error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
Plot boundaries
viskex.firedrake.plot_mesh_sets(mesh, 1, "boundaries")
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
Plot a scalar field
scalar_function_space = firedrake.FunctionSpace(mesh, "CG", 2)
x = firedrake.SpatialCoordinate(mesh)
if np.issubdtype(mesh.coordinates.dat.data_ro.dtype, np.complexfloating):
x = firedrake.real(x)
centroid = np.array([631544.0, 5054515.0])
rho = firedrake.sqrt((x[0] - centroid[0])**2 + (x[1] - centroid[1])**2)
theta = firedrake.atan2(x[1] - centroid[1], x[0] - centroid[0])
scalar_field = firedrake.interpolate(rho / firedrake.sqrt(1 - 0.5 * firedrake.cos(theta)**2), scalar_function_space)
/home/firedrake/firedrake/src/loopy/loopy/schedule/__init__.py:2255: LoopyWarning: in kernel expression_kernel: Falling back to a slow scheduler implementation due to: cannot schedule kernels with priority dependencies between sibling loop nests (add 'v1_scheduler_fallback' to silenced_warnings kernel attribute to disable) warn_with_kernel(
viskex.firedrake.plot_scalar_field(scalar_field, "scalar")
error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
Plot a vector field
vector_function_space = firedrake.VectorFunctionSpace(mesh, "CG", 2)
vector_field = firedrake.interpolate(
firedrake.as_vector((- rho * firedrake.sin(theta), rho * firedrake.cos(theta))), vector_function_space)
/home/firedrake/firedrake/src/loopy/loopy/schedule/__init__.py:2255: LoopyWarning: in kernel expression_kernel: Falling back to a slow scheduler implementation due to: cannot schedule kernels with priority dependencies between sibling loop nests (add 'v1_scheduler_fallback' to silenced_warnings kernel attribute to disable) warn_with_kernel(
viskex.firedrake.plot_vector_field(vector_field, "vector")
error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
viskex.firedrake.plot_vector_field(vector_field, "vector", glyph_factor=0.1)
error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen