Skip to content

Commit

Permalink
Fix python examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tobre1 committed May 25, 2024
1 parent 655ec5b commit f21e19c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 52 deletions.
37 changes: 19 additions & 18 deletions examples/AirGapDeposition/AirGapDeposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# then grown directionally on top.


class velocityField(vls.lsVelocityField):
class velocityField(vls.VelocityField):
# coord and normalVec are lists with 3 elements
# in 2D coord[2] and normalVec[2] are zero
# getScalarVelocity must return a scalar
Expand All @@ -24,46 +24,47 @@ def getVectorVelocity(self, coord, material, normal, pointId):
boundaryCons = (0, 1, 0) # 0 = reflective, 1 = infinite, 2 = periodic

# create level set
substrate = vls.lsDomain(bounds, boundaryCons, gridDelta)
substrate = vls.Domain(bounds, boundaryCons, gridDelta)

# create plane
origin = (0, 0, 0)
planeNormal = (0, 1, 0)

vls.lsMakeGeometry(substrate, vls.lsPlane(origin, planeNormal)).apply()
vls.MakeGeometry(substrate, vls.Plane(origin, planeNormal)).apply()

print("Extracting")
mesh = vls.lsMesh()
vls.lsToSurfaceMesh(substrate, mesh).apply()
vls.lsVTKWriter(mesh, "plane.vtk").apply()
mesh = vls.Mesh()
vls.ToSurfaceMesh(substrate, mesh).apply()
vls.VTKWriter(mesh, "plane.vtp").apply()

# create layer used for booling
print("Creating box...")
trench = vls.lsDomain(bounds, boundaryCons, gridDelta)
minCorner = (-extent / 6., -25.)
maxCorner = (extent / 6., 1.)
vls.lsMakeGeometry(trench, vls.lsBox(minCorner, maxCorner)).apply()
trench = vls.Domain(bounds, boundaryCons, gridDelta)
minCorner = (-extent / 6.0, -25.0)
maxCorner = (extent / 6.0, 1.0)
vls.MakeGeometry(trench, vls.Box(minCorner, maxCorner)).apply()

print("Extracting")
vls.lsToMesh(trench, mesh).apply()
vls.lsVTKWriter(mesh, "box.vtk").apply()
vls.ToMesh(trench, mesh).apply()
vls.VTKWriter(mesh, "box.vtp").apply()

# Create trench geometry
print("Booling trench")
vls.lsBooleanOperation(substrate, trench,
vls.lsBooleanOperationEnum.RELATIVE_COMPLEMENT).apply()
vls.BooleanOperation(
substrate, trench, vls.BooleanOperationEnum.RELATIVE_COMPLEMENT
).apply()

# Now grow new material

# create new levelset for new material, which will be grown
# since it has to wrap around the substrate, just copy it
print("Creating new layer...")
newLayer = vls.lsDomain(substrate)
newLayer = vls.Domain(substrate)

velocities = velocityField()

print("Advecting")
advectionKernel = vls.lsAdvect()
advectionKernel = vls.Advect()

# the level set to be advected has to be inserted last
# the other could be taken as a mask layer for advection
Expand All @@ -84,7 +85,7 @@ def getVectorVelocity(self, coord, material, normal, pointId):

print("Advection step {} / {}".format(i, numberOfSteps))

vls.lsToSurfaceMesh(newLayer, mesh).apply()
vls.lsVTKWriter(mesh, "trench{}.vtk".format(i)).apply()
vls.ToSurfaceMesh(newLayer, mesh).apply()
vls.VTKWriter(mesh, "trench{}.vtp".format(i)).apply()

print("Time passed during advection: {}".format(passedTime))
33 changes: 17 additions & 16 deletions examples/Deposition/Deposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# layer of a different material is then grown on top.


class velocityField(vls.lsVelocityField):
class velocityField(vls.VelocityField):
# coord and normalVec are lists with 3 elements
# in 2D coord[2] and normalVec[2] are zero
# getScalarVelocity must return a scalar
Expand All @@ -27,37 +27,38 @@ def getVectorVelocity(self, coord, material, normal, pointId):
boundaryCons = (0, 0, 1) # 0 = reflective, 1 = infinite, 2 = periodic

# create level set
substrate = vls.lsDomain(bounds, boundaryCons, gridDelta)
substrate = vls.Domain(bounds, boundaryCons, gridDelta)

# create plane
origin = (0, 0, 0)
planeNormal = (0, 0, 1)

vls.lsMakeGeometry(substrate, vls.lsPlane(origin, planeNormal)).apply()
vls.MakeGeometry(substrate, vls.Plane(origin, planeNormal)).apply()

# create layer used for booling
print("Creating box...")
trench = vls.lsDomain(bounds, boundaryCons, gridDelta)
minCorner = (-extent - 1, -extent / 4., -15.)
maxCorner = (extent + 1, extent / 4., 1.)
vls.lsMakeGeometry(trench, vls.lsBox(minCorner, maxCorner)).apply()
trench = vls.Domain(bounds, boundaryCons, gridDelta)
minCorner = (-extent - 1, -extent / 4.0, -15.0)
maxCorner = (extent + 1, extent / 4.0, 1.0)
vls.MakeGeometry(trench, vls.Box(minCorner, maxCorner)).apply()

# Create trench geometry
print("Booling trench")
vls.lsBooleanOperation(substrate, trench,
vls.lsBooleanOperationEnum.RELATIVE_COMPLEMENT).apply()
vls.BooleanOperation(
substrate, trench, vls.BooleanOperationEnum.RELATIVE_COMPLEMENT
).apply()

# Now grow new material

# create new levelset for new material, which will be grown
# since it has to wrap around the substrate, just copy it
print("Creating new layer...")
newLayer = vls.lsDomain(substrate)
newLayer = vls.Domain(substrate)

velocities = velocityField()

print("Advecting")
advectionKernel = vls.lsAdvect()
advectionKernel = vls.Advect()

# the level set to be advected has to be inserted last
# the other could be taken as a mask layer for advection
Expand All @@ -70,16 +71,16 @@ def getVectorVelocity(self, coord, material, normal, pointId):
counter = 1
passedTime = 0

mesh = vls.lsMesh()
mesh = vls.Mesh()
while passedTime < 4:
advectionKernel.apply()
passedTime += advectionKernel.getAdvectedTime()

vls.lsToSurfaceMesh(newLayer, mesh).apply()
vls.lsVTKWriter(mesh, "trench-{}.vtk".format(counter)).apply()
vls.ToSurfaceMesh(newLayer, mesh).apply()
vls.VTKWriter(mesh, "trench-{}.vtp".format(counter)).apply()

vls.lsToMesh(newLayer, mesh).apply()
vls.lsVTKWriter(mesh, "LS-{}.vtk".format(counter)).apply()
vls.ToMesh(newLayer, mesh).apply()
vls.VTKWriter(mesh, "LS-{}.vtp".format(counter)).apply()

counter = counter + 1

Expand Down
33 changes: 17 additions & 16 deletions examples/GeometricAdvection/GeometricAdvection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,42 @@
boundaryCons = (0, 0, 1) # 0 = reflective, 1 = infinite, 2 = periodic

# create level set
substrate = vls.lsDomain(bounds, boundaryCons, gridDelta)
substrate = vls.Domain(bounds, boundaryCons, gridDelta)

# create plane
origin = (0, 0, 0)
planeNormal = (0, 0, 1)

vls.lsMakeGeometry(substrate, vls.lsPlane(origin, planeNormal)).apply()
vls.MakeGeometry(substrate, vls.Plane(origin, planeNormal)).apply()

# create layer used for booling
print("Creating box...")
trench = vls.lsDomain(bounds, boundaryCons, gridDelta)
minCorner = (-extent - 1, -extent / 4., -15.)
maxCorner = (extent + 1, extent / 4., 1.)
vls.lsMakeGeometry(trench, vls.lsBox(minCorner, maxCorner)).apply()
trench = vls.Domain(bounds, boundaryCons, gridDelta)
minCorner = (-extent - 1, -extent / 4.0, -15.0)
maxCorner = (extent + 1, extent / 4.0, 1.0)
vls.MakeGeometry(trench, vls.Box(minCorner, maxCorner)).apply()

# Create trench geometry
print("Booling trench")
vls.lsBooleanOperation(substrate, trench,
vls.lsBooleanOperationEnum.RELATIVE_COMPLEMENT).apply()
vls.BooleanOperation(
substrate, trench, vls.BooleanOperationEnum.RELATIVE_COMPLEMENT
).apply()

mesh = vls.lsMesh()
vls.lsToSurfaceMesh(substrate, mesh).apply()
vls.lsVTKWriter(mesh, "trench-initial.vtk").apply()
mesh = vls.Mesh()
vls.ToSurfaceMesh(substrate, mesh).apply()
vls.VTKWriter(mesh, "trench-initial.vtp").apply()

# Now grow new material

# create new levelset for new material, which will be grown
# since it has to wrap around the substrate, just copy it
print("Creating new layer...")
newLayer = vls.lsDomain(substrate)
newLayer = vls.Domain(substrate)

print("Advecting")
# Advect the level set
dist = vls.lsSphereDistribution(4.0, gridDelta)
vls.lsGeometricAdvect(newLayer, dist).apply()
dist = vls.SphereDistribution(4.0, gridDelta)
vls.GeometricAdvect(newLayer, dist).apply()

vls.lsToSurfaceMesh(newLayer, mesh).apply()
vls.lsVTKWriter(mesh, "trench-final.vtk").apply()
vls.ToSurfaceMesh(newLayer, mesh).apply()
vls.VTKWriter(mesh, "trench-final.vtp").apply()
4 changes: 2 additions & 2 deletions include/viennals/lsPointData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class PointData {
// identifier: "PointData"
// 4 byte: number of scalar data sets
// 4 byte: number of vector data sets
stream << "PointData";
stream << "lsPointData";
uint32_t numberOfScalarData = scalarData.size();
uint32_t numberOfVectorData = vectorData.size();
stream.write(reinterpret_cast<const char *>(&numberOfScalarData),
Expand Down Expand Up @@ -318,7 +318,7 @@ class PointData {
std::istream &deserialize(std::istream &stream) {
char identifier[11];
stream.read(identifier, 11);
if (std::string(identifier).compare(0, 11, "PointData")) {
if (std::string(identifier).compare(0, 11, "lsPointData")) {
Logger::getInstance()
.addWarning("Reading PointData from stream failed. Header could "
"not be found.")
Expand Down

0 comments on commit f21e19c

Please sign in to comment.