mindflow.cfd

class mindflow.cfd.RunTime(config, mesh_info, material)[源代码]

仿真运行时控制器。

参数:
  • config (dict) - 参数字典。

  • mesh_info (MeshInfo) - 计算网格的信息。

  • material (Material) - 流体材料模型。

支持平台:

GPU

样例:

>>> from mindflow import cfd
>>> config = {'mesh': {'dim': 1, 'nx': 100, 'gamma': 1.4, 'x_range': [0, 1], 'pad_size': 3},
...           'material': {'type': 'IdealGas', 'heat_ratio': 1.4, 'specific_heat_ratio': 1.4,
...           'specific_gas_constant': 1.0}, 'runtime': {'CFL': 0.9, 'current_time': 0.0, 'end_time': 0.2},
...           'integrator': {'type': 'RungeKutta3'}, 'space_solver': {'is_convective_flux': True,
...           'convective_flux': {'reconstructor': 'WENO5', 'riemann_computer': 'Rusanov'},
...           'is_viscous_flux': False}, 'boundary_conditions': {'x_min': {'type': 'Neumann'},
...           'x_max': {'type': 'Neumann'}}}
>>> s = cfd.Simulator(config)
>>> r = cfd.RunTime(c, s.mesh_info, s.material)
advance()[源代码]

根据时间步长向前仿真。

异常:
  • NotImplementedError - 如果 time step 不合法。

compute_timestep(pri_var)[源代码]

计算物理的时间步长。

参数:
  • pri_var (Tensor) - 原始变量。

time_loop(pri_var)[源代码]

是否继续仿真,当前时间达到终值或NAN值时返回False。

参数:
  • pri_var (Tensor) - 原始变量。

返回:

bool,是否继续仿真。

异常:
  • ValueError - 如果 pri_var 值为NAN。

class mindflow.cfd.Simulator(config, net_dict=None)[源代码]

CFD仿真器。MindFlow CFD中最上层的类。

参数:
  • config (dict) - 参数字典。

  • net_dict (dict) - 网络字典, 默认为None。

支持平台:

GPU

样例:

>>> from mindflow import cfd
>>> config = {'mesh': {'dim': 1, 'nx': 100, 'gamma': 1.4, 'x_range': [0, 1], 'pad_size': 3},
...           'material': {'type': 'IdealGas', 'heat_ratio': 1.4, 'specific_heat_ratio': 1.4,
...           'specific_gas_constant': 1.0}, 'runtime': {'CFL': 0.9, 'current_time': 0.0, 'end_time': 0.2},
...           'integrator': {'type': 'RungeKutta3'}, 'space_solver': {'is_convective_flux': True,
...           'convective_flux': {'reconstructor': 'WENO5', 'riemann_computer': 'Rusanov'},
...           'is_viscous_flux': False}, 'boundary_conditions': {'x_min': {'type': 'Neumann'},
...           'x_max': {'type': 'Neumann'}}}
>>> s = cfd.Simulator(config)
integration_step(con_var, timestep)[源代码]

按时间步长积分。

参数:
  • con_var (Tensor) - 守恒量。

  • timestep (float) - 积分的时间步长。

返回:

Tensor,一个时间步长之后的守恒量。

mindflow.cfd.cal_pri_var(con_var, material)[源代码]

从守恒量中计算原始量。

参数:
  • con_var (Tensor) - 守恒量。

  • material (Material) - 流体材料。

返回:

Tensor,shape和 con_var 一致。

支持平台:

GPU

样例:

>>> import numpy as np
>>> from mindspore import Tensor
>>> from mindflow.utils import cal_pri_var
>>> from mindflow import material
>>> config =  {'type': 'IdealGas', 'heat_ratio': 1.4, 'specific_heat_ratio': 1.4, 'specific_gas_constant': 1.0}
>>> m = material.select_material(config)
>>> x1 = Tensor(np.random.randn(5, 32, 32, 1))
>>> x2 = cal_pri_var(x, m)
>>> x2.shape
(5, 32, 32, 1)
mindflow.cfd.cal_con_var(pri_var, material)[源代码]

从原始量中计算守恒量。

参数:
  • pri_var (Tensor) - 原始量。

  • material (Material) - 流体材料。

返回:

Tensor,shape和 pri_var 一致。

支持平台:

GPU

样例:

>>> import numpy as np
>>> from mindspore import Tensor
>>> from mindflow.utils import cal_con_var
>>> from mindflow import material
>>> config =  {'type': 'IdealGas', 'heat_ratio': 1.4, 'specific_heat_ratio': 1.4, 'specific_gas_constant': 1.0}
>>> m = material.select_material(config)
>>> x1 = Tensor(np.random.randn(5, 32, 32, 1))
>>> x2 = cal_con_var(x, m)
>>> x2.shape
(5, 32, 32, 1)
mindflow.cfd.vis_1d(pri_var, file_name='vis.jpg')[源代码]

1d流场可视化。

参数:
  • pri_var (Tensor) - 原始量。

  • file_name (str) - 图片文件名,默认值: “vis.jpg”。

支持平台:

GPU

mindflow.cfd.vis_2d(pri_var, file_name='vis.jpg')[源代码]

2d流场可视化。

参数:
  • pri_var (Tensor) - 原始量。

  • file_name (str) - 图片文件名,默认值: “vis.jpg”。

支持平台:

GPU