tum-pbs/PhiFlow

object rotation do not work in branch 2.3-develop

KarlisFre opened this issue · 2 comments

Thanks for fixing jit-compile in branch 2.3. Unfortunately object rotation does not work there. This program crashes in branch 2.3-develop

from phi.tf.flow import *
DOMAIN = dict(x=30, y=30)
DT = 0.1

def move_obstacle(obs: Obstacle):
    new_geometry = obs.geometry.shifted([1. * DT, 0])
    new_geometry = new_geometry.rotated(0.1*DT)
    return obs.copied_with(geometry=new_geometry)


obstacle = Obstacle(Box(x=(5, 11), y=(10, 16)), velocity=[0., 0], angular_velocity=tensor(0.1,))
velocity = StaggeredGrid(0, extrapolation.ZERO, **DOMAIN)
obstacle_mask = CenteredGrid(HardGeometryMask(obstacle.geometry), extrapolation.BOUNDARY, **DOMAIN)
pressure = None

@math.jit_compile
def step(velocity, obstacle):
    velocity = advect.mac_cormack(velocity, velocity, DT)
    velocity, pressure = fluid.make_incompressible(velocity, (obstacle,))
    return velocity, pressure

for _ in view(velocity, obstacle_mask, play=True, namespace=globals(), port=6006).range():
    obstacle = move_obstacle(obstacle)
    velocity, pressure = step(velocity, obstacle)
    obstacle_mask = HardGeometryMask(obstacle.geometry) @ pressure

File "/home/flow_control/obstacle_rotate.py", line 23, in
obstacle = move_obstacle(obstacle)
File "/home/flow_control/obstacle_rotate.py", line 6, in move_obstacle
new_geometry = obs.geometry.shifted([1. * DT, 0])
File "/usr/local/lib/python3.8/dist-packages/phi/geom/_geom.py", line 233, in shifted
return self.at(self.center + delta)
File "/usr/local/lib/python3.8/dist-packages/phi/geom/_transform.py", line 78, in at
return RotatedGeometry(self._geometry.at(center), self._angle)
File "/usr/local/lib/python3.8/dist-packages/phi/geom/_box.py", line 36, in at
return Cuboid(center, self._half_size)
File "/usr/local/lib/python3.8/dist-packages/phi/geom/_geom.py", line 357, in getattr
return BoundDim(self, name)
File "/usr/local/lib/python3.8/dist-packages/phi/math/magic.py", line 461, in init
raise AttributeError(f"'{type(self)}' object has no attribute '{name}'")
AttributeError: '<class 'phi.math.magic.BoundDim'>' object has no attribute '_half_size'

holl- commented

Yeah, this is a bug. I'll look into it.

holl- commented

I've pushed a fix to 2.3-develop. To upgrade to the new version, you'll have to uninstall phiflow first or use --force-reinstall.