I am trying to get the diameter of a circle inscribing all elements of the mesh. The Circumradius(submesh) call works perfectly well to get the diameter of the circumscribed circle to an element. I tried using the nradius and radius_ratio (to get a measure of the inscribed circle) calls, but I got an error stating that these functions could not be found.
from dolfin import *
mesh = UnitSquareMesh(3, 5)
x = SpatialCoordinate(mesh)
f = project(as_vector((x[0], 0.2*cos(pi*x[0]))), VectorFunctionSpace(mesh, "CG", 1))
ALE.move(mesh, f)
plot(mesh)
import matplotlib.patches
import matplotlib.pyplot as plt
ax = plt.gca()
for k, cell in enumerate(cells(mesh)):
Ai = [cell.facet_area(i) for i in range(cell.num_entities(cell.dim()-1))]
vertices = [Vertex(mesh, vertex).point().array() for vertex in cell.entities(0)]
in_center = 1/sum(Ai)*sum([Ai[i]*vertices[i] for i in range(len(vertices))])
in_radius = cell.inradius()
print(k, in_center, in_radius)
ax.add_patch(matplotlib.patches.Circle(in_center, radius=in_radius))
plt.savefig("mesh.png")
Put the in_radius variable in the appropriate entries of a DG0 space and you can use it in a variational form. Or you could create your own custom UserExpression.