def load_state(filename):
    state = FluidSimulationSaveState();
    success = state.load_state(filename)

    if not success:
        raise RuntimeError("Unable to load savestate: " + filename)

    fluidsim = FluidSimulation.from_save_state(state)

     # After constructing the FluidSimulation object, the save state is
     # no longer needed and can be closed. Closing the state will
     # clean up any temporary files that were created during loading
     # the state and initializing the fluid simulation.
    state.close_state()

    # The save state feature only saves the following data:
    #     - grid dimensions and cell size
    #     - current frame
    #     - marker particles
    #     - diffuse particles
    #     - solid cells
    #     - FluidBrickGrid data
    # 
    # The save state will not load any changed settings, body forces,
    # or fluid sources, so these attributes/objects will need to be re-added
    # manually if desired once the state is loaded.

    # The initialize() method does not need to be called when loading a simulation
    # from a save state. The simulation is initialized within the constructor.

    fluidsim.add_body_force(0.0, -25.0, 0.0)
    fluidsim.enable_autosave = False
    
    timestep = 1.0 / 30.0
    num_frames = 5
    for i in range(num_frames):
        fluidsim.update(timestep)
def save_state(filename):
    isize = 64
    jsize = 64
    ksize = 64
    dx = 0.125
    fluidsim = FluidSimulation(isize, jsize, ksize, dx)

    width, height, depth = fluidsim.get_simulation_dimensions()
    fluidsim.add_implicit_fluid_point(width/2, 0.0, depth/2, 7.0)

    fluidsim.add_body_force(0.0, -25.0, 0.0)
    fluidsim.enable_autosave = False
    fluidsim.initialize()

    timestep = 1.0 / 30.0
    num_frames = 5
    for i in range(num_frames):
        fluidsim.update(timestep)

    fluidsim.save_state(filename)
Exemple #3
0
        for j in range(jsize):
            for i in range(isize):
                vx = (i + 0.5) * dx - position.x
                vz = (k + 0.5) * dx - position.z
                distsq = vx * vx + vz * vz
                if distsq < rsq:
                    cells.append(GridIndex(i, j, k))

    return cells


isize = 128
jsize = 64
ksize = 64
dx = 0.125
fluidsim = FluidSimulation(isize, jsize, ksize, dx)

width, height, depth = fluidsim.get_simulation_dimensions()

# initialize fluid sources
inflow_bbox = AABB()
inflow_bbox.position = Vector3(0.0, 0.0, 0.0)
inflow_bbox.width = 5 * dx
inflow_bbox.height = 15 * dx
inflow_bbox.depth = 30 * dx
inflow_velocity = Vector3(10.0, 0.0, 0.0)
fluid_inflow = CuboidFluidSource(inflow_bbox, inflow_velocity)
fluid_inflow.is_inflow = True

outflow_bbox = AABB()
outflow_bbox.position = Vector3(width - 5 * dx, 0.0, 0.0)
    errmsg = ("Could not find the pyfluid package. Pass the directory that contains the " +
              "pyfluid package as a command line argument and try again. " + 
              "For example, if the package is located at 'build/fluidsim/pyfluid', " +
              "then pass the directory 'build/fluidsim/'\n\n" +
              "Usage:\tpython example_sphere_drop.py path/to/directory\n")
    raise ImportError(errmsg)

# This example will drop a ball of fluid in the center
# of a rectangular fluid simulation domain.
from pyfluid import FluidSimulation

isize = 256
jsize = 128
ksize = 128
dx = 0.0625
fluidsim = FluidSimulation(isize, jsize, ksize, dx)

# Increase subdivision level to increase the resolution that
# the output meshes are generated at.
fluidsim.surface_subdivision_level = 1

if fluidsim.surface_subdivision_level >= 2:
    # Helps reduce output filesize by removing polyhedrons
    # that do not meet a minimum triangle count threshold.
    fluidsim.minimum_polyhedron_triangle_count = 64

width, height, depth = fluidsim.get_simulation_dimensions()
fluidsim.add_implicit_fluid_point(width/2, height/2, depth/2, 7.0)

fluidsim.add_body_force(0.0, -25.0, 0.0)
fluidsim.initialize()
        for j in range(jsize):
            for i in range(isize):
                vx = (i + 0.5)*dx - position.x
                vz = (k + 0.5)*dx - position.z
                distsq = vx*vx + vz*vz
                if distsq < rsq:
                    cells.append(GridIndex(i, j, k))

    return cells


isize = 256
jsize = 128
ksize = 128
dx = 0.0625
fluidsim = FluidSimulation(isize, jsize, ksize, dx)

# This option enables the diffuse particle simulation
fluidsim.enable_diffuse_material_output = True

# Maximum lifetime of a diffuse particle in seconds. This value controls how 
# quickly/slowly diffuse particles fade from the simulation.
fluidsim.max_diffuse_particle_lifetime = 3.0

# Diffuse particles are generated in areas where the fluid
# is likely to be aerated such as at wavecrests and areas of high
# turbulence. These properties set the wavecrest emission rate
# and turbulence emission rates.
fluidsim.diffuse_particle_wavecrest_emission_rate = 37.0
fluidsim.diffuse_particle_turbulence_emission_rate = 37.0
    import pyfluid
except ImportError:
    errmsg = (
        "Could not find the pyfluid package. Pass the directory that contains the "
        + "pyfluid package as a command line argument and try again. " +
        "For example, if the package is located at 'build/fluidsim/pyfluid', "
        + "then pass the directory 'build/fluidsim/'\n\n" +
        "Usage:\tpython example_dambreak.py path/to/directory\n")
    raise ImportError(errmsg)

# This example will run a dambreak scenario where a cuboid of fluid is released
# at one side of the simulation domain.
from pyfluid import FluidSimulation, AABB, Vector3

isize = 128
jsize = 64
ksize = 64
dx = 0.125
fluidsim = FluidSimulation(isize, jsize, ksize, dx)

width, height, depth = fluidsim.get_simulation_dimensions()
cuboid = AABB(Vector3(0, 0, 0), 0.25 * width, 0.75 * height, depth)
fluidsim.add_fluid_cuboid(cuboid)

fluidsim.add_body_force(0.0, -25.0, 0.0)
fluidsim.initialize()

timestep = 1.0 / 30.0
while True:
    fluidsim.update(timestep)
        "Could not find the pyfluid package. Pass the directory that contains the "
        + "pyfluid package as a command line argument and try again. " +
        "For example, if the package is located at 'build/fluidsim/pyfluid', "
        + "then pass the directory 'build/fluidsim/'\n\n" +
        "Usage:\tpython example_sphere_drop.py path/to/directory\n")
    raise ImportError(errmsg)

# This example will drop a ball of fluid in the center
# of a rectangular fluid simulation domain.
from pyfluid import FluidSimulation

isize = 256
jsize = 128
ksize = 128
dx = 0.0625
fluidsim = FluidSimulation(isize, jsize, ksize, dx)

# Increase subdivision level to increase the resolution that
# the output meshes are generated at.
fluidsim.surface_subdivision_level = 1

if fluidsim.surface_subdivision_level >= 2:
    # Helps reduce output filesize by removing polyhedrons
    # that do not meet a minimum triangle count threshold.
    fluidsim.minimum_polyhedron_triangle_count = 64

width, height, depth = fluidsim.get_simulation_dimensions()
fluidsim.add_implicit_fluid_point(width / 2, height / 2, depth / 2, 7.0)

fluidsim.add_body_force(0.0, -25.0, 0.0)
fluidsim.initialize()
        "Usage:\tpython example_lego_sphere_drop.py path/to/directory\n")
    raise ImportError(errmsg)

# This example will drop a ball of fluid to a pool of resting fluid. The output
# surface mesh will be generated as LEGO bricks.
#
# The brick surface reconstruction method requires data from three consecutive
# frames, so data output will not be written to disk until the third frame.

from pyfluid import FluidSimulation, AABB

isize = 128
jsize = 128
ksize = 128
dx = 0.0625
fluidsim = FluidSimulation(isize, jsize, ksize, dx)

fluidsim.enable_isotropic_surface_reconstruction = False

brick = AABB()
brick.width = 3 * dx
brick.height = 1.2 * brick.width
brick.depth = brick.width
fluidsim.enable_brick_output = (True, brick)

width, height, depth = fluidsim.get_simulation_dimensions()
fluidsim.add_implicit_fluid_point(width / 2, height / 2, depth / 2, 5.0)

cuboid = AABB(0.0, 0.0, 0.0, width, 0.125 * height, depth)
fluidsim.add_fluid_cuboid(cuboid)
              "Usage:\tpython example_lego_sphere_drop.py path/to/directory\n")
    raise ImportError(errmsg)

# This example will drop a ball of fluid to a pool of resting fluid. The output 
# surface mesh will be generated as LEGO bricks.
#
# The brick surface reconstruction method requires data from three consecutive 
# frames, so data output will not be written to disk until the third frame.

from pyfluid import FluidSimulation, AABB

isize = 128
jsize = 128
ksize = 128
dx = 0.0625
fluidsim = FluidSimulation(isize, jsize, ksize, dx)

fluidsim.enable_isotropic_surface_reconstruction = False

brick = AABB()
brick.width = 3*dx
brick.height = 1.2*brick.width
brick.depth = brick.width
fluidsim.enable_brick_output = (True, brick)

width, height, depth = fluidsim.get_simulation_dimensions()
fluidsim.add_implicit_fluid_point(width/2, height/2, depth/2, 5.0)

cuboid = AABB(0.0, 0.0, 0.0, width, 0.125*height, depth);
fluidsim.add_fluid_cuboid(cuboid)
# fluid in the center of a cube shaped fluid domain. This example is
# relatively quick to compute and can be used to test if the simulation
# program is running correctly.

from pyfluid import FluidSimulation

# The fluid simulator performs its computations on a 3D grid, and because of
# this the simulation domain is shaped like a rectangular prism. The
# FluidSimulation class can be initialized with four parameters: the number
# of grid cells in each direction x, y, and z, and the width of a grid cell.

isize = 32
jsize = 32
ksize = 32
dx = 0.25
fluidsim = FluidSimulation(isize, jsize, ksize, dx)

# We want to add a ball of fluid to the center of the fluid domain, so we will
# need to get the dimensions of the domain by calling getSimulationDimensions.
# Alternatively, the dimensions can be calculated by multiplying the cell
# width by the corresponding number of cells in a direction
# (e.g. width = dx*isize).

width, height, depth = fluidsim.get_simulation_dimensions()

# Now that we have the dimensions of the simulation domain, we can calculate
# the center, and add a ball of fluid by calling addImplicitFluidPoint which
# takes the x, y, and z position and radius as parameters.

centerx = width / 2
centery = height / 2
# relatively quick to compute and can be used to test if the simulation 
# program is running correctly.

from pyfluid import FluidSimulation


# The fluid simulator performs its computations on a 3D grid, and because of 
# this the simulation domain is shaped like a rectangular prism. The 
# FluidSimulation class can be initialized with four parameters: the number 
# of grid cells in each direction x, y, and z, and the width of a grid cell.

isize = 32
jsize = 32
ksize = 32
dx = 0.25
fluidsim = FluidSimulation(isize, jsize, ksize, dx)

# We want to add a ball of fluid to the center of the fluid domain, so we will 
# need to get the dimensions of the domain by calling getSimulationDimensions. 
# Alternatively, the dimensions can be calculated by multiplying the cell 
# width by the corresponding number of cells in a direction 
# (e.g. width = dx*isize).

width, height, depth = fluidsim.get_simulation_dimensions()

# Now that we have the dimensions of the simulation domain, we can calculate 
# the center, and add a ball of fluid by calling addImplicitFluidPoint which 
# takes the x, y, and z position and radius as parameters.

centerx = width / 2;
centery = height / 2;
Exemple #12
0
        for j in range(jsize):
            for i in range(isize):
                vx = (i + 0.5) * dx - position.x
                vz = (k + 0.5) * dx - position.z
                distsq = vx * vx + vz * vz
                if distsq < rsq:
                    cells.append(GridIndex(i, j, k))

    return cells


isize = 256
jsize = 128
ksize = 128
dx = 0.0625
fluidsim = FluidSimulation(isize, jsize, ksize, dx)

# This option enables the diffuse particle simulation
fluidsim.enable_diffuse_material_output = True

# Maximum lifetime of a diffuse particle in seconds. This value controls how
# quickly/slowly diffuse particles fade from the simulation.
fluidsim.max_diffuse_particle_lifetime = 3.0

# Diffuse particles are generated in areas where the fluid
# is likely to be aerated such as at wavecrests and areas of high
# turbulence. These properties set the wavecrest emission rate
# and turbulence emission rates.
fluidsim.diffuse_particle_wavecrest_emission_rate = 37.0
fluidsim.diffuse_particle_turbulence_emission_rate = 37.0
try:
    import pyfluid
except ImportError:
    errmsg = ("Could not find the pyfluid package. Pass the directory that contains the " +
              "pyfluid package as a command line argument and try again. " + 
              "For example, if the package is located at 'build/fluidsim/pyfluid', " +
              "then pass the directory 'build/fluidsim/'\n\n" +
              "Usage:\tpython example_dambreak.py path/to/directory\n")
    raise ImportError(errmsg)

# This example will run a dambreak scenario where a cuboid of fluid is released 
# at one side of the simulation domain.
from pyfluid import FluidSimulation, AABB, Vector3

isize = 128
jsize = 64
ksize = 64
dx = 0.125
fluidsim = FluidSimulation(isize, jsize, ksize, dx)

width, height, depth = fluidsim.get_simulation_dimensions()
cuboid = AABB(Vector3(0, 0, 0), 0.25*width, 0.75*height, depth)
fluidsim.add_fluid_cuboid(cuboid)

fluidsim.add_body_force(0.0, -25.0, 0.0)
fluidsim.initialize()

timestep = 1.0/30.0
while True:
    fluidsim.update(timestep)