我想编写一个使用基于FEniCS的 FEM 求解器作为其步骤之一的Snakemake工作流程。
问题是预处理(加载网格等)很昂贵。因为我不知道如何在工作流程中只做一次,所以我想办法让它更便宜。
目前我的代码如下所示:
# user: 0:55, sys: 0:09, total: 1:04
with XDMFFile(mesh_filename + '.xdmf') as fh:
mesh = Mesh()
fh.read(mesh)
element_type = "CG"
degree = 1
# user: 12:12, sys: 1:35, total: 13:47
V = FunctionSpace(mesh, element_type, degree)
# user: 5:52, sys: 0:56, total: 6:48
with XDMFFile(mesh_filename + '_boundaries.xdmf') as fh:
mvc = MeshValueCollection("size_t", mesh, 2)
fh.read(mvc, "boundaries")
boundaries = cpp.mesh.MeshFunctionSizet(mesh, mvc)
# user: 20:14, sys: 3:00, total: 23:13
with XDMFFile(mesh_filename + '_subdomains.xdmf') as fh:
mvc = MeshValueCollection("size_t", mesh, 3)
fh.read(mvc, "subdomains")
subdomains = cpp.mesh.MeshFunctionSizet(mesh, mvc)
# well below 1s
ds = Measure("ds")(subdomain_data=boundaries)
dx = Measure("dx")(subdomain_data=subdomains)
有没有办法以快速阅读的格式缓存mesh
, V
, ds
and dx
(或boundaries
and )?subdomains