tum-pbs / PhiFlow

A differentiable PDE solving framework for machine learning
MIT License
1.43k stars 193 forks source link

How to properly define extrapolations for a velocity field? #87

Closed aypee19 closed 1 year ago

aypee19 commented 1 year ago

I'm strugling to set the extrapolations of a velocity field. For example, how to set an inflow boundary condition on the left side, and neumann conditions on the others?

Among other things, I tried this:

inflow_tensor = pf.math.tensor([1., 0.], pf.channel(vector='x,y'))
extrapolations = pf.extrapolation.combine_sides(x=(pf.extrapolation.ConstantExtrapolation(inflow_tensor), pf.extrapolation.BOUNDARY),
                                                y=(pf.extrapolation.BOUNDARY, pf.extrapolation.BOUNDARY))

But it has no effect when doing my simple fluid simulation (advect and make_incompressible) Moreover I can't compile a function using this velocity field like this.

I know I can bypass this issue by setting a BOUNDARY extrapolation on each side and setting the velocity on the lower x at each step, like in the pipe demo, but physically it is not the same, especially in the make_incompressible step. I've been trying to dig into how extrapolations are used in calculations, but I'm not yet comfortable enough with phiflow to understand it all. ^^

What is the correct way to set extrapolations?

holl- commented 1 year ago

Hi, the proper way to do this would be

INFLOW_LEFT = extrapolation.combine_by_direction(normal=v_inflow, tangential=0)
velocity = StaggeredGrid(0, extrapolation.combine_sides(x=(INFLOW_LEFT, extrapolation.BOUNDARY), y=0), x=50, y=32)

This is not yet supported, though. I'll work on a fix and let you know when it's ready.

holl- commented 1 year ago

I've pushed a fix to develop which you can install with pip install git+https://github.com/tum-pbs/PhiFlow@develop. I also updated the pipe demo to use the boundary conditions to drive the flow.