Download AV/code/2.mesh_function.py from mapengfei/mesh-cardiology: direct link, hf CLI and curl.
- Browser
- Download file 1.52 kB
-
https://huggingface.co/datasets/mapengfei/mesh-cardiology/resolve/main/AV/code/2.mesh_function.py
- Command line
-
hf download hf://datasets/mapengfei/mesh-cardiology/AV/code/2.mesh_function.py
-
curl -L -o 2.mesh_function.py https://huggingface.co/datasets/mapengfei/mesh-cardiology/resolve/main/AV/code/2.mesh_function.py
1.52 kB
| raw_fiber_file = "../ibamr/fibers.txt.gz" | |
| raw_sheet_file = "" | |
| raw_mesh_file = "../ibamr/mesh.xda.gz" | |
| output_path = "../mesh/" | |
| temp_path = "../trash/" | |
| from fenics import * | |
| mesh_file = XDMFFile(output_path+"mesh.xdmf") | |
| mesh = Mesh() | |
| mesh_file.read(mesh) | |
| mesh_file.close() | |
| fibers = [] | |
| import gzip | |
| file_handler = gzip.open(raw_fiber_file, "rt") | |
| while True: | |
| line = file_handler.readline() | |
| if line == '': | |
| break | |
| else : | |
| line = line.split("\n")[0].split("\t") | |
| fiber = [float(line[1]), float(line[2]), float(line[3])] | |
| fibers.append(fiber) | |
| file_handler.close() | |
| f0 = MeshFunction("double", mesh, 3, 0.0) | |
| f1 = MeshFunction("double", mesh, 3, 0.0) | |
| f2 = MeshFunction("double", mesh, 3, 0.0) | |
| for i in range(f1.size()): | |
| f0[i] = fibers[i][0] | |
| f1[i] = fibers[i][1] | |
| f2[i] = fibers[i][2] | |
| File(output_path + "fibers_0.xml") << f0 | |
| File(output_path + "fibers_1.xml") << f1 | |
| File(output_path + "fibers_2.xml") << f2 | |
| class F1(UserExpression): | |
| def __init__(self, mesh, f0, f1, f2, *arg, **kwargs): | |
| super().__init__(*arg, **kwargs) | |
| self.mesh = mesh | |
| self.f0 = f0 | |
| self.f1 = f1 | |
| self.f2 = f2 | |
| def eval_cell(self, values, x, cell): | |
| values[0] = self.f0[cell.index] | |
| values[1] = self.f1[cell.index] | |
| values[2] = self.f2[cell.index] | |
| def value_shape(self): | |
| return (3,) | |
| V = VectorFunctionSpace(mesh, 'CG', 1) | |
| e1 = F1(mesh, f0, f1, f2, degree=2) | |
| u1 = interpolate(e1, V) | |
| File(temp_path + "fibers.pvd") << u1 |