Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PythonAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ These are imported directly from the **root** `viennals` module.

### **Enums**
- `LogLevel`
- `IntegrationSchemeEnum`
- `SpatialSchemeEnum`
- `BooleanOperationEnum`
- `CurvatureEnum`
- `FeatureDetectionEnum`
Expand Down
3 changes: 1 addition & 2 deletions examples/Deposition/Deposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ int main() {
advectionKernel.setVelocityField(velocities);
// advectionKernel.setAdvectionTime(4.);
unsigned counter = 1;
advectionKernel.setIntegrationScheme(
ls::IntegrationSchemeEnum::WENO_5TH_ORDER);
advectionKernel.setSpatialScheme(ls::SpatialSchemeEnum::WENO_5TH_ORDER);
for (NumericType time = 0; time < 4.;
time += advectionKernel.getAdvectedTime()) {
advectionKernel.apply();
Expand Down
6 changes: 3 additions & 3 deletions examples/Epitaxy/Epitaxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class epitaxy final : public VelocityField<T> {
static constexpr double high = 1.0;

public:
epitaxy(std::vector<double> vel) : velocities(vel){};
epitaxy(std::vector<double> vel) : velocities(vel) {};

double getScalarVelocity(const std::array<T, 3> & /*coordinate*/,
int material, const std::array<T, 3> &normal,
Expand Down Expand Up @@ -82,8 +82,8 @@ int main(int argc, char *argv[]) {
auto velocityField = SmartPointer<epitaxy>::New(std::vector<double>{0., -.5});

Advect<T, D> advectionKernel(levelSets, velocityField);
advectionKernel.setIntegrationScheme(
IntegrationSchemeEnum::STENCIL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER);
advectionKernel.setSpatialScheme(
SpatialSchemeEnum::STENCIL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER);
advectionKernel.setAdvectionTime(.5);

Timer timer;
Expand Down
12 changes: 9 additions & 3 deletions examples/Epitaxy/Epitaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
D = 3
vls.setNumThreads(8)


class EpitaxyVelocity(vls.VelocityField):
def __init__(self, velocities):
super().__init__()
Expand All @@ -30,13 +31,15 @@ def getScalarVelocity(self, coord, material, normal, point_id):
return vel * mat_vel

def getVectorVelocity(self, coord, material, normal, point_id):
return (0., 0., 0.)
return (0.0, 0.0, 0.0)


def write_surface(domain, filename):
mesh = vls.Mesh()
vls.ToSurfaceMesh(domain, mesh).apply()
vls.VTKWriter(mesh, filename).apply()


def main():
# Set dimension to 3D
vls.setDimension(D)
Expand All @@ -50,7 +53,7 @@ def main():
boundary_conditions = [
vls.BoundaryConditionEnum.REFLECTIVE_BOUNDARY,
vls.BoundaryConditionEnum.REFLECTIVE_BOUNDARY,
vls.BoundaryConditionEnum.INFINITE_BOUNDARY
vls.BoundaryConditionEnum.INFINITE_BOUNDARY,
]

# Create Geometry
Expand Down Expand Up @@ -80,7 +83,9 @@ def main():
for ls in level_sets:
advection.insertNextLevelSet(ls)
advection.setVelocityField(velocity_field)
advection.setIntegrationScheme(vls.IntegrationSchemeEnum.STENCIL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER)
advection.setSpatialScheme(
vls.SpatialSchemeEnum.STENCIL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER
)
advection.setAdvectionTime(0.5)

start_time = time.time()
Expand All @@ -92,5 +97,6 @@ def main():

write_surface(substrate, "epitaxy.vtp")


if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions examples/PeriodicBoundary/PeriodicBoundary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ int main() {
ls::Advect<double, D> advectionKernel;
advectionKernel.insertNextLevelSet(substrate);
advectionKernel.setVelocityField(velocities);
advectionKernel.setIntegrationScheme(
ls::IntegrationSchemeEnum::ENGQUIST_OSHER_2ND_ORDER);
advectionKernel.setSpatialScheme(
ls::SpatialSchemeEnum::ENGQUIST_OSHER_2ND_ORDER);

// Now advect the level set 50 times, outputting every
// advection step. Save the physical time that
Expand Down
14 changes: 7 additions & 7 deletions examples/SquareEtch/SquareEtch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,21 @@ int main() {
if (useAnalyticalVelocity) {
advectionKernel.setVelocityField(analyticalVelocities);
// Analytical velocity fields and dissipation coefficients
// can only be used with this integration scheme
advectionKernel.setIntegrationScheme(
// ls::IntegrationSchemeEnum::LOCAL_LAX_FRIEDRICHS_ANALYTICAL_1ST_ORDER);
ls::IntegrationSchemeEnum::WENO_5TH_ORDER);
// can only be used with this spatial discretization scheme
advectionKernel.setSpatialScheme(
// ls::SpatialSchemeEnum::LOCAL_LAX_FRIEDRICHS_ANALYTICAL_1ST_ORDER);
ls::SpatialSchemeEnum::WENO_5TH_ORDER);
} else {
// for numerical velocities, just use the default
// integration scheme, which is not accurate for certain
// spatial discretization scheme, which is not accurate for certain
// velocity functions but very fast
advectionKernel.setVelocityField(velocities);

// For coordinate independent velocity functions
// this numerical scheme is superior though.
// However, it is slower.
// advectionKernel.setIntegrationScheme(
// ls::IntegrationSchemeEnum::STENCIL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER);
// advectionKernel.setSpatialScheme(
// ls::SpatialSchemeEnum::STENCIL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER);
}

// advect the level set until 50s have passed
Expand Down
66 changes: 38 additions & 28 deletions examples/SquareEtch/SquareEtch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@

vls.Logger.setLogLevel(vls.LogLevel.INFO)


# 1. Define the Velocity Field
# We inherit from viennals.VelocityField to define custom logic in Python
class EtchingField(vls.VelocityField):
def getScalarVelocity(self, coordinate, material, normalVector, pointId):
if material == 2:
return -0.1
if material == 1:
return -1.
return -1.0
return 0.0

def getVectorVelocity(self, coordinate, material, normalVector, pointId):
return [0.0] * len(coordinate)


# 1. Define the Velocity Field
# We inherit from viennals.VelocityField to define custom logic in Python
class DepositionField(vls.VelocityField):
Expand All @@ -25,25 +27,29 @@ def getScalarVelocity(self, coordinate, material, normalVector, pointId):
def getVectorVelocity(self, coordinate, material, normalVector, pointId):
return [0.0] * len(coordinate)


def main():
# 1. Parse Arguments
parser = argparse.ArgumentParser(description="Run Square Etch simulation in 2D or 3D.")
parser = argparse.ArgumentParser(
description="Run Square Etch simulation in 2D or 3D."
)
parser.add_argument(
"-D", "--dim",
type=int,
default=2,
choices=[2, 3],
help="Dimension of the simulation (2 or 3). Default is 2."
"-D",
"--dim",
type=int,
default=2,
choices=[2, 3],
help="Dimension of the simulation (2 or 3). Default is 2.",
)
args = parser.parse_args()

DIMENSION = args.dim
vls.setDimension(DIMENSION)
vls.setNumThreads(8)

extent = 30.0
gridDelta = 0.47

# Define bounds and boundary conditions
trenchBottom = -2.0
bounds = [-extent, extent, -extent, extent]
Expand Down Expand Up @@ -73,14 +79,14 @@ def main():
# 3. Trench Geometry
# --------------------------------------
trench = vls.Domain(bounds, boundaryCons, gridDelta)

# Define Box Corners based on dimension
minCorner = list(origin)
maxCorner = list(origin)
originMask = list (origin)
originMask = list(origin)
for i in range(DIMENSION - 1):
minCorner[i] = -extent / 1.5
maxCorner[i] = extent / 1.5
maxCorner[i] = extent / 1.5
minCorner[DIMENSION - 1] = trenchBottom
maxCorner[DIMENSION - 1] = 1.0
originMask[DIMENSION - 1] = trenchBottom + 1e-9
Expand All @@ -89,35 +95,36 @@ def main():
vls.MakeGeometry(trench, box).apply()

# Subtract trench from substrate (Relative Complement)
vls.BooleanOperation(substrate, trench, vls.BooleanOperationEnum.RELATIVE_COMPLEMENT).apply()
vls.BooleanOperation(
substrate, trench, vls.BooleanOperationEnum.RELATIVE_COMPLEMENT
).apply()

# 4. Create the Mask Layer
# The mask prevents etching at the bottom of the trench in specific configurations,
# or acts as a hard stop/masking material.
mask = vls.Domain(bounds, boundaryCons, gridDelta)

vls.MakeGeometry(mask, vls.Plane(originMask, downNormal)).apply()

# Intersect with substrate geometry
vls.BooleanOperation(mask, substrate, vls.BooleanOperationEnum.INTERSECT).apply()

# 5. Export Initial State
print(f"Running in {DIMENSION}D.")
print("Extracting initial meshes...")
mesh = vls.Mesh()

# Save substrate
vls.ToSurfaceMesh(substrate, mesh).apply()
vls.VTKWriter(mesh, f"substrate-{DIMENSION}D.vtp").apply()

# Save mask
vls.ToSurfaceMesh(mask, mesh).apply()
vls.VTKWriter(mesh, f"mask-{DIMENSION}D.vtp").apply()

print("Creating new layer...")
polymer = vls.Domain(substrate)


# 6. Setup Advection
deposition = DepositionField()
etching = EtchingField()
Expand All @@ -142,9 +149,9 @@ def main():

advectionKernel.setSaveAdvectionVelocities(True)
advectionKernel.setVelocityField(etching)
# Use default integration scheme (Lax Friedrichs 1st order) as in the C++ else branch
# advectionKernel.setIntegrationScheme(viennals.IntegrationSchemeEnum.LAX_FRIEDRICHS_1ST_ORDER)

# Use default spatial discretization scheme (Lax Friedrichs 1st order) as in the C++ else branch
# advectionKernel.setSpatialScheme(viennals.SpatialSchemeEnum.LAX_FRIEDRICHS_1ST_ORDER)

# 7. Time Loop
finalTime = 10.0
Expand All @@ -153,27 +160,29 @@ def main():

# The advect kernel calculates stable time steps automatically.
# We call apply() repeatedly until we reach finalTime.

# Note: In the C++ example, the loop structure is:
# for (double time = 0.; time < finalTime; time += advectionKernel.getAdvectedTime())
# This implies one step is taken, then time is updated.

# Save initial state
vls.ToSurfaceMesh(polymer, mesh).apply()
vls.VTKWriter(mesh, f"numerical-{DIMENSION}D-0.vtp").apply()

while currentTime < finalTime:
advectionKernel.apply()

stepTime = advectionKernel.getAdvectedTime()
currentTime += stepTime

print(f"Advection step: {counter}, time: {stepTime:.4f} (Total: {currentTime:.4f})")


print(
f"Advection step: {counter}, time: {stepTime:.4f} (Total: {currentTime:.4f})"
)

# Export result
vls.ToSurfaceMesh(polymer, mesh).apply()
vls.VTKWriter(mesh, f"numerical-{DIMENSION}D-{counter}.vtp").apply()

counter += 1

print(f"\nNumber of Advection steps taken: {counter}")
Expand All @@ -182,5 +191,6 @@ def main():
vls.ToSurfaceMesh(polymer, mesh).apply()
vls.VTKWriter(mesh, f"final-{DIMENSION}D.vtp").apply()


if __name__ == "__main__":
main()
main()
Loading