def test_fluid_tf_equality(self): tf.reset_default_graph() _sess = tf.InteractiveSession() for domain in [ Domain([8, 6], boundaries=OPEN), Domain([8, 6], boundaries=STICKY), Domain([8, 6], boundaries=SLIPPERY), Domain([8, 6], boundaries=PERIODIC), Domain([8, 6], boundaries=[PERIODIC, [OPEN, STICKY]]) ]: print('Comparing on domain %s' % (domain.boundaries, )) np_fluid = Fluid(domain, density=Noise(), velocity=Noise(), batch_size=10) tf_fluid = constant(np_fluid) physics = IncompressibleFlow(conserve_density=False) for _ in range(3): np_fluid = physics.step(np_fluid, 1.0) tf_fluid = physics.step(tf_fluid, 1.0) for np_tensor, tf_tensor in zip(struct.flatten(np_fluid), struct.flatten(tf_fluid)): tf_eval = tf_tensor.eval() numpy.testing.assert_almost_equal(np_tensor, tf_eval, decimal=5)
def test_tf_worldgraph(self): tf.reset_default_graph() world = World() fluid = world.add(Fluid(Domain([16, 16]))) tf_bake_graph(world, Session(Scene.create('data', copy_calling_script=False))) world.step() self.assertIsInstance(fluid.state, Fluid) self.assertIsInstance(fluid.state.density.data, numpy.ndarray)
def test_fluid_tf(self): tf.reset_default_graph() world = World() fluid = Fluid(Domain([16, 16])) world.add(fluid) world.add(Inflow(Sphere((8, 8), radius=4))) world.add(Obstacle(box[4:16, 0:8])) fluid_in = fluid.copied_with(density=placeholder, velocity=placeholder) fluid_out = world.step(fluid_in) self.assertIsInstance(fluid_out, Fluid) session = Session(Scene.create('data', copy_calling_script=False)) fluid = session.run(fluid_out, {fluid_in: fluid}) fluid = session.run(fluid_out, {fluid_in: fluid}) self.assertIsInstance(fluid, Fluid)