tum-pbs / PhiFlow

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

Applying free stream boundary condition #152

Open KarlisFre opened 6 months ago

KarlisFre commented 6 months ago

Hi, Many thanks for implementing Free stream boundary condition #138. It works nicely on scalar fields. But how to use it on the velocity field? I am willing to set up the velocity field and apply advection on it, something like this:

v = StaggeredGrid(Noise(vector='x,y'), InOutConditionalExtrapolation(???),x=32, y=32)
v = advect.semi_lagrangian(v, v, dt=0.1)
v, p = fluid.make_incompressible(v)

Unfortunately there is no way to get velocity values to construct the InOutConditionalExtrapolation. The idea is that when the velocity leaves the boundary, it should be able to do it freely (like zero_gradient), but when is pointed inside, the velocity outside the boundary is treated as zero and the solver inside the make_incompressible decreases the pressure near boundary to be able to drag the flow inwards. Any suggestions how to make it work?

holl- commented 6 months ago

Hi @KarlisFre, that is a bit tricky because in that case the extrapolation requires all values of the field it's used for. I see two ways of doing this:

Let me know what you think! Cheers

KarlisFre commented 6 months ago

If I do v.with_extrapolation(InOutExtrapolation(v)), would it work correctly in v = fluid.make_incompressible(v)? Velocity is changed inside it and will the result correctly conform to boundary condition that is dependent on v?

holl- commented 6 months ago

I think the InOutExtrapolation I sent is not compatible with staggered grids yet. I can look into this but there may be some difficulties when it comes to which values actually need to be stored. Performing the pressure solve on a centered grid may be easier.