How to compute the x,y,z coordinates of the centroid of a cell and the UFL corresponding node indices


223
views
0
6 months ago by
Hello all,
So far I have computed the normals and area of the boundary cells now I need to extract the xyz coordinates of the center of these 2-D cells so I can calculate an analytic function (c function) with them. I also need to store the corresponding node indices so I can apply the function value to these nodes. I honestly don't know how to start I assume this will involve finding the integration point at the center?
Below is my working code for the normals and areas:
from dolfin import *
import time
import numpy as np

#define domain
x_min = y_min = z_min = 0.0
x_max = y_max = z_max = 1.0

#define number of elements
nx = ny = 1
nz = 1

#create mesh
mesh = BoxMesh(Point(x_min, y_min, z_min), Point(x_max, y_max, z_max), nx, ny, nz)

# define function space
V = FunctionSpace(mesh, 'P', 1)

#define boundary
def boundary_sides(x, on_boundary):
    return near(x[0],x_min) or near(x[0],x_max) or near(x[1],y_max) or near(x[1],y_min)

bmesh = BoundaryMesh(mesh, 'exterior')

# calculate array of boundary faces normal vectors
cell_map = bmesh.entity_map(2)
norm_array = []
f_area = []
normal_array=[]
Area_array = []
msg = 'Cell %d in bmesh(%d in mesh) has normal %r'
for bci, cell in enumerate(cells(bmesh)):
    n = cell.cell_normal().array()
    print(msg % (bci, cell_map[bci], list(n)))
    norm_array.append(list(n))
normal_array = np.array(norm_array)
​


Thanks in advance!

Cheers,
-Terrence

Community: FEniCS Project

1 Answer


3
6 months ago by
for the centroid:
for cell in cells(mesh):
    centroid = cell.midpoint()​
sorry for the delayed response this works great!
written 6 months ago by Terrence  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »