Skip to content

Commit

Permalink
PyBind pyhton module (#11)
Browse files Browse the repository at this point in the history
* Set up CMake to produce Python modules for 2D and 3D using pybind11

* Changed interface functions to only use standard types

* Prepared release
  • Loading branch information
XaverKlemenschits authored Nov 27, 2019
1 parent e8c318e commit 21bcd67
Show file tree
Hide file tree
Showing 271 changed files with 6,063 additions and 2,788 deletions.
33 changes: 25 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.4)

project(
"ViennaLS"
VERSION 0.1.1)
VERSION 1.0.0)

include(GNUInstallDirs)

Expand All @@ -12,16 +12,33 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET(CMAKE_CXX_STANDARD "17")
endif()

# tell VS to export all symbols to its dll files
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE CACHE BOOL "Export all symbols")
endif()

# set whether to build static versions
option(VIENNALS_STATIC_BUILD "Build all targets with static links." OFF)
if(VIENNALS_STATIC_BUILD)
set(VTK_DIR $ENV{VTK_STATIC_DIR})
list(APPEND VIENNALS_LIBRARIES "-static")
endif(VIENNALS_STATIC_BUILD)

# VTK File type support
option(VIENNALS_USE_VTK "Build with VTK file support." ON)
if(VIENNALS_USE_VTK)
set(VTK_DIR $ENV{VTK_DIR})
if(NOT VTK_DIR)
set(VTK_DIR $ENV{VTK_DIR})
endif(NOT VTK_DIR)
find_package(VTK QUIET)
if(VTK_FOUND)
message(STATUS "Found VTK")
add_definitions(-DVIENNALS_USE_VTK)
include(${VTK_USE_FILE})
# only link needed vtk libraries
set(VTK_LIBRARIES vtksys;vtkIOCore;vtkexpat;vtklz4;vtkzlib;vtklzma;vtkdoubleconversion;vtkCommonMisc;vtkCommonSystem;vtkIOXML)
list(APPEND VIENNALS_LIBRARIES ${VTK_LIBRARIES})
list(APPEND VIENNALS_PYTHON_LIBRARIES ${VTK_LIBRARIES})
else(VTK_FOUND)
message(STATUS "No VTK install found: Building without VTK.")
endif(VTK_FOUND)
Expand All @@ -40,12 +57,6 @@ if(VIENNALS_BUILD_SHARED_LIBS)
find_package(ViennaHRLE REQUIRED)
file(GLOB SPECIALISATION_CPPS "lib/*.cpp")
add_library(${PROJECT_NAME} SHARED ${SPECIALISATION_CPPS})

# tell VS to export all symbols to the dll file
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE CACHE BOOL "Export all symbols")
endif()

target_link_libraries(${PROJECT_NAME} ViennaHRLE)
target_include_directories(${PROJECT_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/include/")
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
Expand Down Expand Up @@ -101,6 +112,12 @@ if(VIENNALS_BUILD_TESTS)
endif(VIENNALS_BUILD_TESTS)


#################################################
# BUILD PYTHON MODULE
#################################################
add_subdirectory(Wrapping)


#################################################
# INSTALL
#################################################
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Run clang-format on ALL files of the project (use format-project.sh)

* Run make_doxygen.sh in docs/doxygen to update the website
* Delete html folder and run make_doxygen.sh in docs/doxygen to update the website

* Wrap all implemented interface functions for Python in Wrapping/pyWrap.cpp

* IMPORTANT: Check the ReadMe file in / to make sure nothing changed
18 changes: 9 additions & 9 deletions Examples/AirGapDeposition/AirGapDeposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
// implement own velocity field
class velocityField : public lsVelocityField<double> {
public:
double getScalarVelocity(
hrleVectorType<double, 3> /*coordinate*/, int /*material*/,
hrleVectorType<double, 3> normalVector = hrleVectorType<double, 3>(0.)) {
double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> &normalVector) {
// velocity is proportional to the normal vector
double velocity = std::abs(normalVector[0]) + std::abs(normalVector[1]);
return velocity;
}

hrleVectorType<double, 3> getVectorVelocity(
hrleVectorType<double, 3> /*coordinate*/, int /*material*/,
hrleVectorType<double,
3> /*normalVector = hrleVectorType<double, 3>(0.)*/) {
return hrleVectorType<double, 3>(0.);
std::array<double, 3>
getVectorVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
return std::array<double, 3>({});
}
};

Expand Down Expand Up @@ -107,7 +107,7 @@ int main() {
advectionKernel.setIgnoreVoids(true);

// Now advect the level set 50 times, outputting every
// 10th advection step. Save the physical time that
// advection step. Save the physical time that
// passed during the advection.
double passedTime = 0.;
unsigned numberOfSteps = 60;
Expand Down
87 changes: 87 additions & 0 deletions Examples/AirGapDeposition/AirGapDeposition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import viennaLS2d as vls

## @example AirGapDeposition.py
# Example showing how to use the library for topography
# simulation, by creating a trench geometry. A layer of a different material is
# then grown directionally on top.

class velocityField(vls.lsVelocityField):
# coord and normalVec are lists with 3 elements
# in 2D coord[2] and normalVec[2] are zero
# getScalarVelocity must return a scalar
def getScalarVelocity(self, coord, material, normal):
return abs(normal[0]) + abs(normal[1])

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

extent = 30
gridDelta = 0.5

bounds = (-extent, extent, -extent, extent)
boundaryCons = (0, 1, 0) # 0 = reflective, 1 = infinite, 2 = periodic

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

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

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

print("Extracting")
mesh = vls.lsMesh()
vls.lsToSurfaceMesh(substrate, mesh).apply()
vls.lsVTKWriter(mesh, "plane.vtk").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()

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

# Create trench geometry
print("Booling trench")
vls.lsBooleanOperation(substrate, trench, vls.lsBooleanOperationEnum.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)

velocities = velocityField()

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

# the level set to be advected has to be inserted last
# the other could be taken as a mask layer for advection
advectionKernel.insertNextLevelSet(substrate)
advectionKernel.insertNextLevelSet(newLayer)

advectionKernel.setVelocityField(velocities)
advectionKernel.setIgnoreVoids(True)

# Now advect the level set 50 times, outputting every
# advection step. Save the physical time that
# passed during the advection.
passedTime = 0
numberOfSteps = 60
for i in range(numberOfSteps):
advectionKernel.apply()
passedTime += advectionKernel.getAdvectionTime()

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

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

print("Time passed during advection: {}".format(passedTime))
20 changes: 11 additions & 9 deletions Examples/Deposition/Deposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@
// implement own velocity field
class velocityField : public lsVelocityField<double> {
public:
double getScalarVelocity(
hrleVectorType<double, 3> /*coordinate*/, int /*material*/,
hrleVectorType<double,
3> /*normalVector = hrleVectorType<double, 3>(0.)*/) {
double
getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3>
& /*normalVector = hrleVectorType<double, 3>(0.)*/) {
// Some arbitrary velocity function of your liking
// (try changing it and see what happens :)
double velocity = 1.;
return velocity;
}

hrleVectorType<double, 3> getVectorVelocity(
hrleVectorType<double, 3> /*coordinate*/, int /*material*/,
hrleVectorType<double,
3> /*normalVector = hrleVectorType<double, 3>(0.)*/) {
return hrleVectorType<double, 3>(0.);
std::array<double, 3>
getVectorVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3>
& /*normalVector = hrleVectorType<double, 3>(0.)*/) {
return std::array<double, 3>({}); // initialise to zero
}
};

Expand Down
83 changes: 83 additions & 0 deletions Examples/Deposition/Deposition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import viennaLS3d as vls

## @example Deposition.py
# 3D Example showing how to use the library for topography
# simulation, by creating a trench geometry. A uniform
# layer of a different material is then grown on top.

class velocityField(vls.lsVelocityField):
# coord and normalVec are lists with 3 elements
# in 2D coord[2] and normalVec[2] are zero
# getScalarVelocity must return a scalar
def getScalarVelocity(self, coord, material, normal):
# some arbitrary velocity function of your liking
# (try changing it and see what happens :)
velocity = 1
return velocity

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

extent = 30
gridDelta = 0.5

bounds = (-extent, extent, -extent, extent, -extent, extent)
boundaryCons = (0, 0, 1) # 0 = reflective, 1 = infinite, 2 = periodic

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

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

vls.lsMakeGeometry(substrate, vls.lsPlane(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()

# Create trench geometry
print("Booling trench")
vls.lsBooleanOperation(substrate, trench, vls.lsBooleanOperationEnum.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)

velocities = velocityField()

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

# the level set to be advected has to be inserted last
# the other could be taken as a mask layer for advection
advectionKernel.insertNextLevelSet(substrate)
advectionKernel.insertNextLevelSet(newLayer)

advectionKernel.setVelocityField(velocities)

# Advect the level set
counter = 1
passedTime = 0

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

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

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

counter = counter + 1

print("Time passed during advection: {}".format(passedTime))
33 changes: 16 additions & 17 deletions Examples/PatternedSubstrate/PatternedSubstrate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
// implement velocity field describing a directional etch
class directionalEtch : public lsVelocityField<double> {
public:
double getScalarVelocity(
hrleVectorType<double, 3> /*coordinate*/, int material,
hrleVectorType<double, 3> normalVector = hrleVectorType<double, 3>(0.)) {
double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int material,
const std::array<double, 3> &normalVector) {
// etch directionally
if (material > 0) {
return (normalVector[2] > 0.) ? -normalVector[2] : 0;
Expand All @@ -36,30 +36,29 @@ class directionalEtch : public lsVelocityField<double> {
}
}

hrleVectorType<double, 3> getVectorVelocity(
hrleVectorType<double, 3> /*coordinate*/, int /*material*/,
hrleVectorType<double,
3> /*normalVector = hrleVectorType<double, 3>(0.)*/) {
return hrleVectorType<double, 3>(0.);
std::array<double, 3>
getVectorVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
return std::array<double, 3>({});
}
};

// implement velocity field describing an isotropic deposition
class isotropicDepo : public lsVelocityField<double> {
public:
double getScalarVelocity(
hrleVectorType<double, 3> /*coordinate*/, int /*material*/,
hrleVectorType<double,
3> /*normalVector = hrleVectorType<double, 3>(0.)*/) {
double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
// deposit isotropically everywhere
return 1;
}

hrleVectorType<double, 3> getVectorVelocity(
hrleVectorType<double, 3> /*coordinate*/, int /*material*/,
hrleVectorType<double,
3> /*normalVector = hrleVectorType<double, 3>(0.)*/) {
return hrleVectorType<double, 3>(0.);
std::array<double, 3>
getVectorVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
return std::array<double, 3>({});
}
};

Expand Down
Loading

0 comments on commit 21bcd67

Please sign in to comment.