Inscribed diameter of an element

Hello,

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.

Thank you.

Have you tried inradius, as illustrated below:

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")

producing:
mesh
and

0 [ 0.58001903  0.21040681  0.        ] 0.0866476344147409
1 [ 0.08489818  0.31847627  0.        ] 0.08489818020317372
2 [ 1.24720071  0.0073444   0.        ] 0.08613262635439059
3 [ 0.75223957  0.1911881   0.        ] 0.08557290042011083
4 [ 1.91615492 -0.11556556  0.        ] 0.0838450750292337
5 [ 1.42056823 -0.01151569  0.        ] 0.08723489936746424
6 [ 0.58040448  0.41071269  0.        ] 0.0862621851307255
7 [ 0.08625982  0.51727716  0.        ] 0.08625981604861797
8 [ 1.24864511  0.208154    0.        ] 0.08468821873196429
9 [ 0.75181641  0.39196253  0.        ] 0.08514974030649528
10 [ 1.91379241  0.0824004   0.        ] 0.08620758884569725
11 [ 1.41911596  0.18947733  0.        ] 0.0857826299462477
12 [ 0.58058316  0.61091072  0.        ] 0.08608350852374855
13 [ 0.08618931  0.71752879  0.        ] 0.08618931097831321
14 [ 1.24836467  0.40786445  0.        ] 0.08496866054101737
15 [ 0.75163533  0.59213555  0.        ] 0.08496866054101723
16 [ 1.91381069  0.28247121  0.        ] 0.0861893109783131
17 [ 1.41941684  0.38908928  0.        ] 0.08608350852374876
18 [ 0.58088404  0.81052267  0.        ] 0.08578262994624765
19 [ 0.08620759  0.9175996   0.        ] 0.0862075888456972
20 [ 1.24818359  0.60803747  0.        ] 0.08514974030649511
21 [ 0.75135489  0.791846    0.        ] 0.08468821873196425
22 [ 1.91374018  0.48272284  0.        ] 0.08625981604861775
23 [ 1.41959552  0.58928731  0.        ] 0.08626218513072578
24 [ 0.57943177  1.01151569  0.        ] 0.08723489936746431
25 [ 0.08384508  1.11556556  0.        ] 0.08384507502923377
26 [ 1.24776043  0.8088119   0.        ] 0.0855729004201108
27 [ 0.75279929  0.9926556   0.        ] 0.08613262635439078
28 [ 1.91510182  0.68152373  0.        ] 0.08489818020317355
29 [ 1.41998097  0.78959319  0.        ] 0.08664763441474055
2 Likes

Thank you. No haven’t tried it. But would I be able to use the in_radius variable in my variational form?

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.

Sounds good, thank you.