-
Notifications
You must be signed in to change notification settings - Fork 1
/
Frosty.py
85 lines (63 loc) · 2.3 KB
/
Frosty.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
import viennals3d as vls
# Implement own velocity field
class velocityField(vls.VelocityField):
def getScalarVelocity(self, coord, material, normal, pointId):
# Some arbitrary velocity function of your liking
# (try changing it and see what happens :)
velocity = 0.0
if material == 0:
velocity = -1.8 # -1.8 per second
elif material == 1:
velocity = -1.3
else:
velocity = -1.0
return velocity
gridDelta = 0.25
extent = 30
bounds = (-extent, extent, -extent, extent)
boundaryCons = (0, 1, 0) # 0 = reflective, 1 = infinite, 2 = periodic
sphere1 = vls.Domain(gridDelta)
sphere2 = vls.Domain(gridDelta)
sphere3 = vls.Domain(gridDelta)
origin = [0.0, 0.0, 0.0]
radius = 10.0
vls.MakeGeometry(sphere1, vls.Sphere(origin, radius)).apply()
origin[2] = 12.0
radius = 7.2
vls.MakeGeometry(sphere2, vls.Sphere(origin, radius)).apply()
origin[2] = 20.0
radius = 5.0
vls.MakeGeometry(sphere3, vls.Sphere(origin, radius)).apply()
# Perform boolean operations
vls.BooleanOperation(sphere2, sphere3, vls.BooleanOperationEnum.UNION).apply()
vls.BooleanOperation(sphere1, sphere2, vls.BooleanOperationEnum.UNION).apply()
print("Extracting...")
mesh = vls.Mesh()
vls.ToSurfaceMesh(sphere1, mesh).apply()
vls.VTKWriter(mesh, "sphere1-0.vtp").apply()
vls.ToSurfaceMesh(sphere2, mesh).apply()
vls.VTKWriter(mesh, "sphere2-0.vtp").apply()
vls.ToSurfaceMesh(sphere3, mesh).apply()
vls.VTKWriter(mesh, "sphere3-0.vtp").apply()
velocities = velocityField()
print("Advecting")
advectionKernel = vls.Advect()
# set velocity field
advectionKernel.setVelocityField(velocities)
# insert all used level sets
advectionKernel.insertNextLevelSet(sphere3)
advectionKernel.insertNextLevelSet(sphere2)
advectionKernel.insertNextLevelSet(sphere1)
# Advect the snowman to have 1 second pass in real time
advectionKernel.setAdvectionTime(1.0)
advectionKernel.apply()
advectionSteps = advectionKernel.getNumberOfTimeSteps()
print("Number of Advection steps taken:", advectionSteps)
print("Extracting...")
mesh = vls.Mesh()
vls.ToSurfaceMesh(sphere1, mesh).apply()
vls.VTKWriter(mesh, "sphere1-1.vtp").apply()
vls.ToSurfaceMesh(sphere2, mesh).apply()
vls.VTKWriter(mesh, "sphere2-1.vtp").apply()
vls.ToSurfaceMesh(sphere3, mesh).apply()
vls.VTKWriter(mesh, "sphere3-1.vtp").apply()