Find the Global nodes that correspond to a cell face of the boundary mesh


109
views
0
6 months ago by
Hello I am calculating the flux in a c function (already have cell area,normal vector,and centroidal coordinates) I now need the global index of the 3 nodes making up each 2-d element. Essentially I need a connectiveity map to tell me for each cell on the boundary what are the global indexes of the nodes making it up so I can assign 1/3 of the flux. Short working code:
from dolfin import *
import time
import numpy as np
import neumann

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

#define number of elements
nx = ny = 10
nz = 5



#create mesh
mesh = BoxMesh(Point(x_min, y_min, z_min), Point(x_max, y_max, z_max), nx, ny, nz)
coordinates = mesh.coordinates()
print('coordinates',len(coordinates))
# define function space
V = FunctionSpace(mesh, 'P', 1)



face_numbers=mesh.num_faces()
bmesh = BoundaryMesh(mesh, 'exterior')
cell_map = bmesh.entity_map(2)
norm_x0 = []
norm_x1 = []
norm_x2 = []
coord_x0 = []
coord_x1 = []
coord_x2 = []
area_array = []
msg = 'Cell %d in bmesh(%d in mesh) has normal %r'
for bci, cell in enumerate(cells(bmesh)):
    # calculate normal vectors
    x = cell.cell_normal().x()
    y = cell.cell_normal().y()
    z = cell.cell_normal().z()
    norm_x0.append(x)
    norm_x1.append(y)
    norm_x2.append(z)
    # calculate areas
    area = cell.volume()
    area_array.append(area)
    # calc centroid coordinates
    cent_x0 = cell.midpoint().x()
    cent_x1 = cell.midpoint().y()
    cent_x2 = cell.midpoint().z()
    coord_x0.append(cent_x0)
    coord_x1.append(cent_x1)
    coord_x2.append(cent_x2)

coord_x0 = np.array(coord_x0)
coord_x1 = np.array(coord_x1)
coord_x2 = np.array(coord_x2)
norm_x0 = np.array(norm_x0)
norm_x1 = np.array(norm_x1)
norm_x2 = np.array(norm_x2)
area_array = np.array(area_array)


# need a loop to find the three index of the threee nodes of each cell and store in an 
#array                                          ​


Best,
Terrence

Community: FEniCS Project
Please login to add an answer/comment or follow this question.

Similar posts:
Search »