-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathexample_diffuse_inflow.py
112 lines (94 loc) · 4.14 KB
/
example_diffuse_inflow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright (c) 2016 Ryan L. Guy
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgement in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
import sys, os
if len(sys.argv) >= 2:
sys.path.append(os.path.abspath(sys.argv[1]))
else:
filepath = os.path.dirname(__file__)
guesspath = os.path.abspath(os.path.join(filepath, os.pardir))
guesspath = os.path.abspath(os.path.join(guesspath, os.pardir))
sys.path.append(guesspath)
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_diffuse_inflow.py path/to/directory\n")
raise ImportError(errmsg)
# This example will initialize an inflow fluid source and a
# solid pillar obstacle. Foam/bubble/spray particles will be
# generated by enabling the diffuse particle simulation feature
#
# Diffuse particles are output as a vertex only .PLY meshes
# with the "diffuse" prefix followed by the frame number.
#
# ex: diffuse000000.ply, diffuse000001.ply, diffuse000002.ply
import math
from pyfluid import FluidSimulation, CuboidFluidSource, AABB, Vector3, GridIndex
def get_pillar_cells(position, radius, isize, jsize, ksize, dx):
rsq = radius*radius
cells = []
for k in range(ksize):
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
# Limit the maximum number of particles simulated by the diffuse particle
# simulator.
fluidsim.max_num_diffuse_particles = int(6e6)
width, height, depth = fluidsim.get_simulation_dimensions()
# Initialize inflow fluid source located at one end of the
# of the simulation domain.
inflow_bbox = AABB(Vector3(), 5*dx, 25*dx, 40*dx)
inflow_velocity = Vector3(10.0, 0.0, 0.0)
fluid_inflow = CuboidFluidSource(inflow_bbox, inflow_velocity)
fluid_inflow.center = Vector3(5*dx, 0.5*height, 0.5*depth)
fluid_inflow.is_inflow = True
fluidsim.add_cuboid_fluid_source(fluid_inflow)
# Create a pillar of solid cells in the center of the domain
center = Vector3(0.5*width, 0.5*height, 0.5*depth)
radius = 15*dx
pillar_cells = get_pillar_cells(center, radius, isize, jsize, ksize, dx)
fluidsim.add_solid_cells(pillar_cells)
fluidsim.add_body_force(0.0, -25.0, 0.0)
fluidsim.initialize()
timestep = 1.0/30.0
while True:
fluidsim.update(timestep)