import numpy as np
import sys
import os
sys.path.append(os.getcwd())
from dolfinx.fem import FunctionSpace, assemble_matrix
from dolfinx import mesh
from ufl import dx, grad, inner, TestFunction, TrialFunction
from mpi4py import MPI
import dolfinx
import numpy as np
import ufl
from ufl import Cell
import dolfinx.cpp
def read_node_file(filename):
with open(filename, 'r') as f:
num_nodes = int(f.readline().split()[0])
nodes = np.empty((num_nodes, 3))
for i in range(num_nodes):
line = f.readline().split()
nodes[i] = [float(x) for x in line[1:4]]
return nodes
def read_ele_file(filename):
with open(filename, 'r') as f:
num_elements = int(f.readline().split()[0])
elements = np.empty((num_elements, 4), dtype=int)
for i in range(num_elements):
line = f.readline().split()
elements[i] = [int(x) for x in line[1:5]]
return elements
def read_face_file(filename):
with open(filename, 'r') as f:
num_faces = int(f.readline().split()[0])
faces = np.empty((num_faces, 3), dtype=int)
for i in range(num_faces):
line = f.readline().split()
faces[i] = [int(x) for x in line[1:4]]
return faces
def read_edge_file(filename):
with open(filename, 'r') as f:
num_edges = int(f.readline().split()[0])
edges = np.empty((num_edges, 2), dtype=int)
for i in range(num_edges):
line = f.readline().split()
edges[i] = [int(x) for x in line[1:3]]
return edges
# Usage:
nodes = read_node_file('cylinder.1.node')
elements = read_ele_file('cylinder.1.ele')
faces = read_face_file('cylinder.1.face')
edges = read_edge_file('cylinder.1.edge')
print('nodes~~~')
print(nodes)
print('elements~~~')
print(elements)
print('faces~~~')
print(faces)
print('edges~~~')
print(edges)
A snapshot of the data looks like:
nodes~~~
[[ 4.99378471e+01 2.49229431e+00 1.00000000e+03]
[ 4.97515373e+01 4.97839212e+00 1.00000000e+03]
[ 4.94415398e+01 7.45211315e+00 1.00000000e+03]
[ 4.90086250e+01 9.90730762e+00 0.00000000e+00]
[ 4.84538651e+01 1.23378696e+01 1.00000000e+03]
[ 4.84538651e+01 1.23378696e+01 0.00000000e+00]
...
[ 2.91871834e+01 4.05969009e+01 1.00000000e+03]]
elements~~~
[[223 45 49 47]
[ 6 241 3 4]
[128 173 124 166]
...
[189 196 200 3]
[ 28 35 27 243]
[243 31 28 35]]
faces~~~
[[142 240 1]
[ 2 187 188]
[188 142 1]
...
[ 16 230 25]
[230 40 25]
[ 17 19 16]]
edges~~~
[[240 142]
...
[141 142]]
I tried to create a dolfinx mesh from the data but I was not able to do it yet. Is there a way to compose a dolfinx mesh from the data set that was generated on cylinder.stl from tetgen?