Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge length evaluator #45

Closed
jorgensd opened this issue Sep 7, 2023 · 1 comment
Closed

Edge length evaluator #45

jorgensd opened this issue Sep 7, 2023 · 1 comment

Comments

@jorgensd
Copy link
Collaborator

jorgensd commented Sep 7, 2023

Averages edge length for all edges of a cell

from dolfin import *
import numpy as np

mesh = UnitSquareMesh(10, 10)
mesh.init(1)
ALE.move(mesh, Expression(("x[0]", "cos(x[1])"),degree=1))
num_cells = mesh.num_cells()
V = FunctionSpace(mesh, "DG", 0)
u = Function(V)
values = np.zeros(num_cells, dtype=np.float64)

for cell in cells(mesh):
    edges = cell.entities(1)
    
    value = 0
    for edge in edges:
        value += Edge(mesh, edge).length()
    values[cell.index()] = value / len(edges)
u.vector().set_local(values)
u.vector().apply("local")
with XDMFFile("edge_length.xdmf") as xdmf:
    xdmf.write(u)
@jorgensd
Copy link
Collaborator Author

jorgensd commented Sep 7, 2023

With this funky deformation field the edge lengths are:

ALE.move(mesh, Expression(("x[0]", "0.3*x[1]*cos(2*x[0])"),degree=1))

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants