Python子例程在Python中创建1D网格。
mesh-generator的Python项目详细描述
这是Python子例程和示例的集合,它们演示了如何构建 具有自定义网格间距的一维网格。在包中创建的网格可以用于各种应用程序,包括 物理模拟。在
安装
pip install mesh-generator
依赖关系
^{pr2}$使用
这是一个创建一维θ网格的示例。请阅读python脚本中的注释以了解更多详细信息。在
- 在
步骤1:输入网格要求。请确保指定:
网格:
- 在
设置网格的
在lower_bnd
和upper_bnd
限制。在 - 在
设置
在periodic
。在 - 在
在没有ds约束的区域中设置
在DEFAULT_BG_REGION_RATIO
-比率。(可选) - 在
在具有ds约束的区域中设置
在DEFAULT_FG_REGION_RATIO
-比率。(可选)
网格段:
- 在
为段域限制设置
在s0
和s1
。在 - 在
将
在ds
设置为所需的分辨率。在 - 在
将
在var_ds_ratio
设置为段最大单元对单元网格扩展比率。(可选)
- 在
frommesh_generatorimportMeshfrommesh_generatorimportMeshSegmentimportnumpy# ratio in regions you do not care about. (Default is 1.06)MeshSegment.DEFAULT_BG_REGION_RATIO=1.06# ratio in regions you do care about. (Default is 1.03) MeshSegment.DEFAULT_FG_REGION_RATIO=1.03# mesh boundaries and if periodic. mesh=Mesh(lower_bnd=0.00,upper_bnd=numpy.pi,periodic=False)# Mesh segment requirements:# s0 - segment begin, s1- segment end, ds- mesh spacing# (Optional) var_ds_ratio- the maximum ratio between each point in the mesh segment. mesh.insert_mesh_segment(MeshSegment(s0=1.10,s1=1.40,ds=0.01,var_ds_ratio=1.05))mesh.insert_mesh_segment(MeshSegment(s0=1.30,s1=1.90,ds=0.02))mesh.insert_mesh_segment(MeshSegment(s0=0.40,s1=2.80,ds=0.04,var_ds_ratio=1.02))
- 步骤2:获取最终网格并写入结果。在
input_mesh=mesh.json_dict()adjusted_mesh=mesh.resolve_mesh_segments().json_dict()legacy_mesh=mesh.build_legacy_mesh().json_dict()create_psi_mesh(adjusted_mesh,legacy_mesh,mesh_type="t",dir_name=os.getcwd(),output_file_name="tmp_mesh_t.dat",mesh_res_file_name="mesh_res_t.dat",save_plot=True,show_plot=True,save_plot_path=os.getcwd(),plot_file_name="t_mesh_spacing.png",input_mesh=input_mesh)
网格生成器用户界面
frommesh_generatorimportMeshGeneratorUIMeshGeneratorUI()
许可证
作者
- 欧泊伊桑(oissan@predsci.com)
- 库珀唐斯(cdowns@predsci.com)
- 项目
标签: