tum-pbs / PhiFlow

A differentiable PDE solving framework for machine learning
MIT License
1.39k stars 189 forks source link

Transform numpy array to CenteredGrid #130

Closed HDFengChina closed 1 year ago

HDFengChina commented 1 year ago

Hi,

I hope to use PhiFlow as the env in my model. Thus, I need to calculate the next field with given the certain velocities and pressure.

I can transform the calculated field to array by values.native(), but I met a challenge when I want to transform the given field (array) to CenteredGrid or StaggeredGrid.

Is there any method can transform the numpy array to CeteredGrid in PhiFlow ?

Thank you.

holl- commented 1 year ago

Hi, yes you can construct a CenteredGrid from a math.Tensor which you can create with wrap or tensor.

v_array = np.empty([64, 64, 2])
v_tensor = wrap(v_array, spatial('x,y'), channel('vector'))
grid = CenteredGrid(v_tensor, extrapolation.PERIODIC, bounds=Box(x=(0, 1), y=(0, 1)))

For constructing staggered grids, see here.

HDFengChina commented 1 year ago

Thanks for your answer. Your suggestion is useful.

One more question. In fluid dynamics, we often set the Reynolds number (Re) or viscosity to control the performance of the fluid. Where can I set or change such numbers?

holl- commented 1 year ago

Simulations generally add some amount of numerical viscosity which you can measure. For explicit diffusion, you can use diffuse.explicit.