tum-pbs / PhiFlow

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

random initialized velocity fields #41

Closed bmahlbrand closed 2 years ago

bmahlbrand commented 3 years ago

I see ways to initialize velocity fields with a single shape, but can I generate several simultaneously? I'm looking to replicate some of TempoGAN's dataset with randomly initialized velocities.

holl- commented 3 years ago

I'm not exactly sure what the question is, but the following is an easy way to generate random velocity fields:

from phi.flow import *
CenteredGrid(Noise(vector=2), extrapolation.ZERO, x=32, y=48)
bmahlbrand commented 3 years ago

I think you got to the crux of what I was looking for, totally unclear in retrospect :)

holl- commented 3 years ago

Maybe I should add that to sample a batch of velocity fields, you can add a batch dimension like this:

Noise(batch(batch=10), vector=2)
bmahlbrand commented 2 years ago

What about seeding the Noise? Maybe I'm looking to generate random inflows of velocity - can you show a simple example of one? Adding randomized ones together is trivial enough, but not sure if there's some shortcuts to deal w/velocity inflows. Like can I create noise spheres to act as emitters on the velocity field?

holl- commented 2 years ago

At the moment, there is no explicit seed control in the Noise class, but you can set the global seed using math.seed().

As for the spherical inflow, how about something like this:

velocity = StaggeredGrid(0, extrapolation.PERIODIC, x=100, y=80)
inflow = (Noise() @ velocity) * (Sphere((50, 40), radius=10) @ velocity)
velocity += inflow * dt
bmahlbrand commented 2 years ago

Are all of these operations supported in 3d? Getting TypeError: unsupported operand type(s) for @: 'Noise' and 'StaggeredGrid' when I do something like: VEL_INFLOW = (Noise(vector=3, scale = vel_inflow_magnitude) @ velocity) * (Sphere(pos, radius=vel_inflow_radius) @ velocity)

holl- commented 2 years ago

Yes, it works in 3D. Try

velocity = StaggeredGrid(0, extrapolation.PERIODIC, x=100, y=80, z=10)
VEL_INFLOW = (Noise(vector=3, scale = 10) @ velocity) * (Sphere((50, 40, 4), radius=10) @ velocity)

Maybe check that you are on version 2.0.0 (no rc) using phi.__version__

bmahlbrand commented 2 years ago

Ahhh! I upgraded to 2.0.0 ;) that helped.

Also did you change operators? Is >> valid anymore? Upgraded and now it's complaining about it. I just changed it to @ and it seems to work.

holl- commented 2 years ago

Yes, it was renamed to @ to match at().

bmahlbrand commented 2 years ago

Makes sense to me! Thanks.