### calculate boundary mesh facet area cell by cell. Currently getting error message

192

views

1

Hey I am trying to calculate the the facet areas of each cell on the boundary and store these values in an array. This is my short code below:

```
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 = []
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))
#**problem calculate area of boundary faces cell by cell
for i, cell in enumerate(cells(bmesh)):
area = cell.facet_area().array()
f_area.append(list(area))
```

Error message:

`TypeError: Cell_facet_area expected 2 arguments, got 1`

I am unsure as to the second argument required.

The end goal is to have an array of boundary areas stored to correspond with the array of normals so I can push these to a C function

Thanks in advance!

Community: FEniCS Project

### 1 Answer

4

From the docs, cell.facet_area() wants an integer saying which facet you're requesting the area of. However, that's probably not what you're looking for. Replacing the last loop with

```
#**problem calculate area of boundary faces cell by cell
for i, cell in enumerate(cells(bmesh)):
area = cell.volume()
f_area += [area,]
print f_area
```

seems to work for me, and give the correct answer of all 0.5s for the 12 outer triangular facets of the 1x1x1 box mesh. Since it's already a boundary mesh, you want the "generalized volume" of the cells, which is area for 2D boundary facets.
Thank you so much this works great!

written
6 months ago by
Terrence

Please login to add an answer/comment or follow this question.