Skip to content

Commit 91b963f

Browse files
authored
Combine 2D and 3D Python modules (#128)
* Use new python stub generator * Bindings with dim submodules * Correct bindings order * Add common module and fix setup * Adjust examples * Remove common module * Improve material map * Fix examples * Small improvements * Reuse ViennaCore test assert * Improve SLLF scheme * Wrap SLLF prepare and finalize function * Bump dependencies * Update Python stubs * Add Python doc * Format * Fix actions Python test * Bump VTK version and remove macOS deployment target * Downgrade to previous VTK, use macOS fixes * Add version header * Format * Fix Windows init path
1 parent 74b8223 commit 91b963f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4680
-2863
lines changed

.github/actions/setup/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ runs:
2222
shell: bash
2323
if: ${{ inputs.os == 'macos-latest' }}
2424
run: |
25-
brew reinstall --build-from-source libomp
25+
brew install libomp
2626
echo "OpenMP_ROOT=$(brew --prefix)/opt/libomp" >> $GITHUB_ENV
2727
2828
- name: 💻 Setup Deployment Target
2929
shell: bash
3030
if: ${{ inputs.os == 'macos-latest' }}
3131
run: |
32-
echo "MACOSX_DEPLOYMENT_TARGET=14.0" >> $GITHUB_ENV
32+
echo "MACOSX_DEPLOYMENT_TARGET=15.0" >> $GITHUB_ENV

.github/workflows/python.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ jobs:
5858
python -m venv venv
5959
./venv/Scripts/activate.bat
6060
pip install .
61-
python -c "import viennals2d; print(viennals2d.__doc__)"
61+
python -c "import viennals; print(viennals.__doc__)"
6262
6363
- name: 🐍 Build and check Python Module (Other)
6464
if: ${{ matrix.os != 'windows-latest' }}
6565
run: |
6666
python -m venv venv
6767
CMAKE_ARGS=-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF ./venv/bin/pip install . # Alpine does not like LTO
68-
./venv/bin/python -c "import viennals2d; print(viennals2d.__doc__)"
68+
./venv/bin/python -c "import viennals; print(viennals.__doc__)"
6969
7070
- name: 📦 Upload Artifact
7171
uses: actions/upload-artifact@v4

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ _generate/
2222
*.egg-info
2323
*env*
2424
.mypy_cache/
25-
.eggs/
25+
.eggs/
26+
test.ipynb

CMakeLists.txt

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
22
project(
33
ViennaLS
44
LANGUAGES CXX
5-
VERSION 4.5.0)
5+
VERSION 5.0.0)
66

77
# --------------------------------------------------------------------------------------------------------
88
# Library options
@@ -90,6 +90,10 @@ endif()
9090
# Include directories
9191
# --------------------------------------------------------------------------------------------------------
9292

93+
# Generate version header
94+
configure_file("${PROJECT_SOURCE_DIR}/cmake/lsVersion.hpp.in"
95+
"${PROJECT_SOURCE_DIR}/include/viennals/lsVersion.hpp" @ONLY)
96+
9397
target_include_directories(
9498
${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/viennals>
9599
$<INSTALL_INTERFACE:include/viennals-${PROJECT_VERSION}>)
@@ -103,7 +107,7 @@ include(cmake/vtk.cmake)
103107

104108
CPMAddPackage(
105109
NAME ViennaCore
106-
VERSION 1.5.0
110+
VERSION 1.6.0
107111
GIT_REPOSITORY "https://github.com/ViennaTools/ViennaCore"
108112
OPTIONS "VIENNACORE_FORMAT_EXCLUDE docs/ build/"
109113
EXCLUDE_FROM_ALL ${VIENNALS_BUILD_PYTHON})
@@ -116,7 +120,7 @@ CPMAddPackage(
116120

117121
CPMFindPackage(
118122
NAME ViennaHRLE
119-
VERSION 0.6.1
123+
VERSION 0.7.0
120124
GIT_REPOSITORY "https://github.com/ViennaTools/ViennaHRLE"
121125
EXCLUDE_FROM_ALL ${VIENNALS_BUILD_PYTHON})
122126

@@ -128,37 +132,46 @@ if(VIENNALS_USE_VTK AND VIENNALS_VTK_PYTHON_LIBS)
128132
elseif(VIENNALS_USE_VTK)
129133
enable_language(C)
130134

135+
# Common VTK build options
136+
set(VTK_OPTIONS
137+
"VTK_LEGACY_REMOVE ON"
138+
"VTK_SMP_IMPLEMENTATION_TYPE OpenMP"
139+
"VTK_GROUP_ENABLE_Rendering NO"
140+
"VTK_GROUP_ENABLE_Imaging NO"
141+
"VTK_GROUP_ENABLE_Views NO"
142+
"VTK_GROUP_ENABLE_Web NO"
143+
"VTK_GROUP_ENABLE_Qt NO"
144+
"VTK_GROUP_ENABLE_MPI NO"
145+
"VTK_ENABLE_WRAPPING NO"
146+
"VTK_MODULE_ENABLE_VTK_libproj NO"
147+
"VTK_MODULE_ENABLE_VTK_CommonExecutionModel YES"
148+
"VTK_MODULE_ENABLE_VTK_CommonMisc YES"
149+
"VTK_MODULE_ENABLE_VTK_CommonSystem YES"
150+
"VTK_MODULE_ENABLE_VTK_CommonMath YES"
151+
"VTK_MODULE_ENABLE_VTK_CommonCore YES"
152+
"VTK_MODULE_ENABLE_VTK_CommonTransforms YES"
153+
"VTK_MODULE_ENABLE_VTK_CommonComputationalGeometry YES"
154+
"VTK_MODULE_ENABLE_VTK_IOCore YES"
155+
"VTK_MODULE_ENABLE_VTK_IOXMLParser YES"
156+
"VTK_MODULE_ENABLE_VTK_IOXML YES"
157+
"VTK_MODULE_ENABLE_VTK_FiltersCore YES"
158+
"VTK_MODULE_ENABLE_VTK_FiltersGeneral YES"
159+
"VTK_MODULE_ENABLE_VTK_FiltersGeometry YES"
160+
"CMAKE_PROJECT_NAME VTK")
161+
162+
# macOS-specific adds
163+
if(APPLE)
164+
list(APPEND VTK_OPTIONS "VTK_MODULE_USE_EXTERNAL_VTK_png ON"
165+
"VTK_MODULE_USE_EXTERNAL_VTK_zlib ON")
166+
endif()
167+
131168
CPMFindPackage(
132169
NAME VTK
133170
GIT_TAG v9.3.1
134171
VERSION 9.0.0
135172
GIT_REPOSITORY "https://gitlab.kitware.com/vtk/vtk"
136173
EXCLUDE_FROM_ALL ${VIENNALS_BUILD_PYTHON}
137-
OPTIONS "VTK_LEGACY_REMOVE ON"
138-
"VTK_SMP_IMPLEMENTATION_TYPE \"OpenMP\""
139-
"VTK_GROUP_ENABLE_Rendering NO"
140-
"VTK_GROUP_ENABLE_Imaging NO"
141-
"VTK_GROUP_ENABLE_Views NO"
142-
"TK_GROUP_ENABLE_Web NO"
143-
"VTK_GROUP_ENABLE_Qt NO"
144-
"VTK_GROUP_ENABLE_MPI NO"
145-
"VTK_ENABLE_WRAPPING NO"
146-
"VTK_MODULE_ENABLE_VTK_libproj NO"
147-
"VTK_MODULE_ENABLE_VTK_CommonExecutionModel YES"
148-
"VTK_MODULE_ENABLE_VTK_CommonMisc YES"
149-
"VTK_MODULE_ENABLE_VTK_CommonSystem YES"
150-
"VTK_MODULE_ENABLE_VTK_CommonMath YES"
151-
"VTK_MODULE_ENABLE_VTK_CommonCore YES"
152-
"VTK_MODULE_ENABLE_VTK_CommonTransforms YES"
153-
"VTK_MODULE_ENABLE_VTK_CommonComputationalGeometry YES"
154-
"VTK_MODULE_ENABLE_VTK_IOCore YES"
155-
"VTK_MODULE_ENABLE_VTK_IOXMLParser YES"
156-
"VTK_MODULE_ENABLE_VTK_IOXML YES"
157-
"VTK_MODULE_ENABLE_VTK_FiltersCore YES"
158-
"VTK_MODULE_ENABLE_VTK_FiltersGeneral YES"
159-
"VTK_MODULE_ENABLE_VTK_FiltersGeometry YES"
160-
# This fixes an issue with the install script that causes find_package to fail.
161-
"CMAKE_PROJECT_NAME VTK")
174+
OPTIONS ${VTK_OPTIONS})
162175

163176
target_compile_definitions(${PROJECT_NAME} INTERFACE VIENNALS_USE_VTK=1)
164177

PythonAPI.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# ViennaLS Python API
2+
3+
This document lists all functions, classes, and enums available in the **ViennaLS** Python package.
4+
Functions are grouped into **dimension-bound** and **dimension-independent** components.
5+
6+
---
7+
8+
## **Dimension-Bound Functions**
9+
10+
These functions are tied to either the **2D** or **3D** version of the library.
11+
They must be imported from either `viennals.d2` or `viennals.d3`.
12+
13+
### **Core Classes and Operations**
14+
- `Domain`
15+
- `Advect`
16+
- `BooleanOperation`
17+
- `CalculateCurvatures`
18+
- `CalculateNormalVectors`
19+
- `CalculateVisibilities`
20+
- `Check`
21+
- `PointCloud`
22+
- `ConvexHull`
23+
- `DetectFeatures`
24+
- `GeometricAdvect`
25+
- `GeometricAdvectDistributions`
26+
- `SphereDistribution`
27+
- `BoxDistribution`
28+
- `Expand`
29+
- `FromSurfaceMesh`
30+
- `FromVolumeMesh`
31+
- `FromMesh`
32+
- `Sphere`
33+
- `Plane`
34+
- `Box`
35+
- `Cylinder`
36+
- `MakeGeometry`
37+
- `MarkVoidPoints`
38+
- `Prune`
39+
- `Reader`
40+
- `Reduce`
41+
- `RemoveStrayPoints`
42+
- `ToDiskMesh`
43+
- `ToMesh`
44+
- `ToSurfaceMesh`
45+
- `ToVoxelMesh`
46+
- `Writer`
47+
- `WriteVisualizationMesh`
48+
49+
### **2D-Only Functions**
50+
- `CompareArea`
51+
- `CompareNarrowBand`
52+
- `CompareSparseField`
53+
54+
---
55+
56+
## **Dimension-Independent Components**
57+
58+
These are imported directly from the **root** `viennals` module.
59+
60+
### **Enums**
61+
- `LogLevel`
62+
- `IntegrationSchemeEnum`
63+
- `BooleanOperationEnum`
64+
- `CurvatureEnum`
65+
- `FeatureDetectionEnum`
66+
- `BoundaryConditionEnum`
67+
- `FileFormatEnum`
68+
- `VoidTopSurfaceEnum`
69+
- `TransformEnum`
70+
71+
### **Mesh and I/O Classes**
72+
- `Mesh`
73+
- `PointData`
74+
- `TransformMesh`
75+
- `VTKReader`
76+
- `VTKWriter`
77+
78+
### **Utilities**
79+
- `Logger`
80+
- `MaterialMap`
81+
- `VelocityField`
82+
83+
---
84+
85+
## **Transformations Between Dimensions**
86+
87+
These functions enable conversion between 2D and 3D representations and are also imported from the root `viennals` module:
88+
- `Slice`
89+
- `Extrude`
90+
91+
---
92+
93+
## **Example Imports**
94+
95+
```python
96+
# 2D functions and domain-specific operations
97+
import viennals.d2 as vls
98+
99+
domain = vls.Domain()
100+
vls.Advect(domain, ...)
101+
102+
# Common functions and enums
103+
import viennals
104+
105+
mesh = viennals.Mesh()
106+
enum = viennals.BooleanOperationEnum.UNION

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,22 @@ pip install .
111111

112112
All functions which are available in C++ are also available in Python. The 2D version of the library can be imported as follows:
113113
```python
114-
import viennals2d as vls
114+
import viennals.d2 as vls
115+
import viennals # for common functions
115116
```
116117

117-
In order to switch to three dimensions, only the import needs to be changed:
118+
To switch to 3D, only the import changes:
118119

119120
```python
120-
import viennals3d as vls
121+
import viennals.d3 as vls
121122
```
123+
Functions that operate on a domain object (e.g. `Advect`, `ToSurfaceMesh`, ...) are provided in the respective `d2` or `d3` modules.
124+
Common functions, enums, and dimension-independent utilities (such as `Mesh`) are available directly in the `viennals` namespace.
125+
126+
A complete list of functions and their locations can be found in the [API documentation](PythonAPI.md).
127+
128+
For examples on how to use the Python package, please have a look at these examples: [Air Gap Deposition](https://github.com/ViennaTools/ViennaLS/blob/master/examples/AirGapDeposition/AirGapDeposition.py), [Deposition](https://github.com/ViennaTools/ViennaLS/blob/master/examples/Deposition/Deposition.py), [Geometric Advection](https://github.com/ViennaTools/ViennaLS/blob/master/examples/GeometricAdvection/GeometricAdvection.py).
129+
122130

123131
## Running the Tests
124132

@@ -149,7 +157,7 @@ We recommend using [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) to consum
149157

150158
* Installation with CPM
151159
```cmake
152-
CPMAddPackage("gh:viennatools/viennals@4.5.0")
160+
CPMAddPackage("gh:viennatools/viennals@5.0.0")
153161
```
154162

155163
* With a local installation

cmake/lsVersion.hpp.in

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
5+
namespace viennals {
6+
7+
// Version information generated by CMake
8+
inline constexpr const char *version = "@PROJECT_VERSION@";
9+
inline constexpr int versionMajor = @PROJECT_VERSION_MAJOR@;
10+
inline constexpr int versionMinor = @PROJECT_VERSION_MINOR@;
11+
inline constexpr int versionPatch = @PROJECT_VERSION_PATCH@;
12+
13+
// Utility functions for version comparison
14+
inline constexpr uint32_t versionAsInteger() {
15+
// Encode as MMmmpppp (2 digits major, 2 digits minor, 4 digits patch)
16+
return static_cast<uint32_t>(versionMajor) * 1000000 +
17+
static_cast<uint32_t>(versionMinor) * 10000 +
18+
static_cast<uint32_t>(versionPatch);
19+
}
20+
21+
inline constexpr bool isVersionAtLeast(int major, int minor = 0,
22+
int patch = 0) {
23+
if (versionMajor > major)
24+
return true;
25+
if (versionMajor < major)
26+
return false;
27+
if (versionMinor > minor)
28+
return true;
29+
if (versionMinor < minor)
30+
return false;
31+
return versionPatch >= patch;
32+
}
33+
34+
// Version as string for display purposes
35+
inline constexpr const char *versionString() { return version; }
36+
37+
} // namespace viennals

examples/AirGapDeposition/AirGapDeposition.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import viennals2d as vls
1+
import viennals.d2 as vls
2+
from viennals import VelocityField, Mesh, VTKWriter, BooleanOperationEnum
23

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

89

9-
class velocityField(vls.VelocityField):
10+
class velocityField(VelocityField):
1011
# coord and normalVec are lists with 3 elements
1112
# in 2D coord[2] and normalVec[2] are zero
1213
# getScalarVelocity must return a scalar
@@ -33,9 +34,9 @@ def getVectorVelocity(self, coord, material, normal, pointId):
3334
vls.MakeGeometry(substrate, vls.Plane(origin, planeNormal)).apply()
3435

3536
print("Extracting")
36-
mesh = vls.Mesh()
37+
mesh = Mesh()
3738
vls.ToSurfaceMesh(substrate, mesh).apply()
38-
vls.VTKWriter(mesh, "plane.vtp").apply()
39+
VTKWriter(mesh, "plane.vtp").apply()
3940

4041
# create layer used for booling
4142
print("Creating box...")
@@ -46,12 +47,12 @@ def getVectorVelocity(self, coord, material, normal, pointId):
4647

4748
print("Extracting")
4849
vls.ToMesh(trench, mesh).apply()
49-
vls.VTKWriter(mesh, "box.vtp").apply()
50+
VTKWriter(mesh, "box.vtp").apply()
5051

5152
# Create trench geometry
5253
print("Booling trench")
5354
vls.BooleanOperation(
54-
substrate, trench, vls.BooleanOperationEnum.RELATIVE_COMPLEMENT
55+
substrate, trench, BooleanOperationEnum.RELATIVE_COMPLEMENT
5556
).apply()
5657

5758
# Now grow new material
@@ -86,7 +87,7 @@ def getVectorVelocity(self, coord, material, normal, pointId):
8687
print("Advection step {} / {}".format(i, numberOfSteps))
8788

8889
vls.ToSurfaceMesh(newLayer, mesh).apply()
89-
writer = vls.VTKWriter(mesh, "trench{}.vtp".format(i))
90+
writer = VTKWriter(mesh, "trench{}.vtp".format(i))
9091
writer.addMetaData("time", passedTime)
9192
writer.apply()
9293

0 commit comments

Comments
 (0)