evoxels 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- evoxels/__init__.py +13 -0
- evoxels/boundary_conditions.py +138 -0
- evoxels/fd_stencils.py +103 -0
- evoxels/function_approximators.py +97 -0
- evoxels/inversion.py +233 -0
- evoxels/precompiled_solvers/__init__.py +1 -0
- evoxels/precompiled_solvers/allen_cahn.py +50 -0
- evoxels/precompiled_solvers/cahn_hilliard.py +42 -0
- evoxels/problem_definition.py +450 -0
- evoxels/profiler.py +94 -0
- evoxels/solvers.py +134 -0
- evoxels/timesteppers.py +119 -0
- evoxels/utils.py +124 -0
- evoxels/voxelfields.py +318 -0
- evoxels/voxelgrid.py +278 -0
- evoxels-0.1.0.dist-info/METADATA +171 -0
- evoxels-0.1.0.dist-info/RECORD +20 -0
- evoxels-0.1.0.dist-info/WHEEL +5 -0
- evoxels-0.1.0.dist-info/licenses/LICENSE +21 -0
- evoxels-0.1.0.dist-info/top_level.txt +1 -0
evoxels/voxelgrid.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import warnings
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Tuple, Any
|
|
5
|
+
from .fd_stencils import FDStencils
|
|
6
|
+
from .boundary_conditions import CellCenteredBCs, StaggeredXBCs
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class Grid:
|
|
11
|
+
"""Handles most basic properties"""
|
|
12
|
+
shape: Tuple[int, int, int]
|
|
13
|
+
origin: Tuple[float, float, float]
|
|
14
|
+
spacing: Tuple[float, float, float]
|
|
15
|
+
convention: str
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class VoxelGrid(FDStencils):
|
|
20
|
+
"""Abstract backend adapter: handles array conversion and padding."""
|
|
21
|
+
def __init__(self, grid: Grid, lib):
|
|
22
|
+
self.shape = grid.shape
|
|
23
|
+
self.origin = grid.origin
|
|
24
|
+
self.spacing = grid.spacing
|
|
25
|
+
self.convention = grid.convention
|
|
26
|
+
self.lib = lib
|
|
27
|
+
|
|
28
|
+
# Other grid information
|
|
29
|
+
self.div_dx = 1/self.to_backend(np.array(self.spacing))
|
|
30
|
+
self.div_dx2 = 1/self.to_backend(np.array(self.spacing))**2
|
|
31
|
+
|
|
32
|
+
# Boundary conditions
|
|
33
|
+
if self.convention == 'cell_center':
|
|
34
|
+
self.bc = CellCenteredBCs(self)
|
|
35
|
+
elif self.convention == 'staggered_x':
|
|
36
|
+
self.bc = StaggeredXBCs(self)
|
|
37
|
+
|
|
38
|
+
# Operate on fields
|
|
39
|
+
def to_backend(self, field):
|
|
40
|
+
"""Convert a NumPy array to the backend representation."""
|
|
41
|
+
raise NotImplementedError
|
|
42
|
+
|
|
43
|
+
def to_numpy(self, field):
|
|
44
|
+
"""Convert a backend array to ``numpy.ndarray``."""
|
|
45
|
+
raise NotImplementedError
|
|
46
|
+
|
|
47
|
+
def pad_periodic(self, field):
|
|
48
|
+
"""Pad a field with periodic boundary conditions."""
|
|
49
|
+
raise NotImplementedError
|
|
50
|
+
|
|
51
|
+
def pad_zeros(self, field):
|
|
52
|
+
"""Pad a field with zeros."""
|
|
53
|
+
raise NotImplementedError
|
|
54
|
+
|
|
55
|
+
def fftn(self, field, shape):
|
|
56
|
+
"""Compute the n-dimensional discrete Fourier transform."""
|
|
57
|
+
raise NotImplementedError
|
|
58
|
+
|
|
59
|
+
def real_of_ifftn(self, field, shape):
|
|
60
|
+
"""Return the real part of the inverse FFT."""
|
|
61
|
+
raise NotImplementedError
|
|
62
|
+
|
|
63
|
+
def expand_dim(self, field, dim):
|
|
64
|
+
"""Add a singleton dimension to ``field``."""
|
|
65
|
+
raise NotImplementedError
|
|
66
|
+
|
|
67
|
+
def squeeze(self, field, dim):
|
|
68
|
+
"""Remove ``dim`` from ``field``."""
|
|
69
|
+
raise NotImplementedError
|
|
70
|
+
|
|
71
|
+
def concatenate(self, fieldlist, dim):
|
|
72
|
+
"""Concatenate fields in ``fieldlist``."""
|
|
73
|
+
raise NotImplementedError
|
|
74
|
+
|
|
75
|
+
def set(self, field, index, value):
|
|
76
|
+
"""Set ``field[index]`` to ``value`` and return ``field``."""
|
|
77
|
+
raise NotImplementedError
|
|
78
|
+
|
|
79
|
+
def axes(self) -> Tuple[Any, ...]:
|
|
80
|
+
""" Returns the 1D coordinate arrays along each axis. """
|
|
81
|
+
return tuple(self.lib.arange(0, n) * self.spacing[i] + self.origin[i]
|
|
82
|
+
for i, n in enumerate(self.shape))
|
|
83
|
+
|
|
84
|
+
def fft_axes(self) -> Tuple[Any, ...]:
|
|
85
|
+
return tuple(2 * self.lib.pi * self.lib.fft.fftfreq(points, step)
|
|
86
|
+
for points, step in zip(self.shape, self.spacing))
|
|
87
|
+
|
|
88
|
+
def rfft_axes(self) -> Tuple[Any, ...]:
|
|
89
|
+
return tuple(2 * self.lib.pi * self.lib.fft.rfftfreq(points, step)
|
|
90
|
+
for points, step in zip(self.shape, self.spacing))
|
|
91
|
+
|
|
92
|
+
def meshgrid(self) -> Tuple[Any, ...]:
|
|
93
|
+
""" Returns full 3D mesh grids for each axis. """
|
|
94
|
+
ax = self.axes()
|
|
95
|
+
return tuple(self.lib.meshgrid(*ax, indexing='ij'))
|
|
96
|
+
|
|
97
|
+
def fft_mesh(self) -> Tuple[Any, ...]:
|
|
98
|
+
fft_axes = self.fft_axes()
|
|
99
|
+
return tuple(self.lib.meshgrid(*fft_axes, indexing='ij'))
|
|
100
|
+
|
|
101
|
+
# def rfft_mesh(self) -> Tuple[Any, ...]:
|
|
102
|
+
# rfft_axes = self.rfft_axes()
|
|
103
|
+
# return tuple(self.lib.meshgrid(*rfft_axes, indexing='ij'))
|
|
104
|
+
|
|
105
|
+
def fft_k_squared(self):
|
|
106
|
+
fft_axes = self.fft_axes()
|
|
107
|
+
kx, ky, kz = self.lib.meshgrid(*fft_axes, indexing='ij')
|
|
108
|
+
return kx**2 + ky**2 + kz**2
|
|
109
|
+
|
|
110
|
+
def rfft_k_squared(self):
|
|
111
|
+
a_x, a_y, _ = self.fft_axes()
|
|
112
|
+
_, _, a_z = self.rfft_axes()
|
|
113
|
+
kx, ky, kz = self.lib.meshgrid(a_x, a_y, a_z, indexing='ij')
|
|
114
|
+
return kx**2 + ky**2 + kz**2
|
|
115
|
+
|
|
116
|
+
def fft_k_squared_nonperiodic(self):
|
|
117
|
+
if self.convention == 'cell_center':
|
|
118
|
+
a_x = 2*self.lib.pi*self.lib.fft.fftfreq(2*self.shape[0], d=self.spacing[0])
|
|
119
|
+
else:
|
|
120
|
+
a_x = 2*self.lib.pi*self.lib.fft.fftfreq(2*self.shape[0]-2, d=self.spacing[0])
|
|
121
|
+
_, a_y, _ = self.fft_axes()
|
|
122
|
+
_, _, a_z = self.rfft_axes()
|
|
123
|
+
kx, ky, kz = self.lib.meshgrid(a_x, a_y, a_z, indexing='ij')
|
|
124
|
+
return kx**2 + ky**2 + kz**2
|
|
125
|
+
|
|
126
|
+
def init_scalar_field(self, array):
|
|
127
|
+
"""Convert and pad a NumPy array for simulation."""
|
|
128
|
+
field = self.to_backend(array)
|
|
129
|
+
field = self.expand_dim(field, 0)
|
|
130
|
+
return field
|
|
131
|
+
|
|
132
|
+
def export_scalar_field_to_numpy(self, field):
|
|
133
|
+
"""Export backend field back to NumPy."""
|
|
134
|
+
array = self.to_numpy(self.squeeze(field, 0))
|
|
135
|
+
return array
|
|
136
|
+
|
|
137
|
+
def average(self, field):
|
|
138
|
+
"""Return the spatial average of ``field``."""
|
|
139
|
+
if field.shape[1:] == self.shape:
|
|
140
|
+
if self.convention == 'cell_center':
|
|
141
|
+
average = self.lib.mean(field, (1,2,3))
|
|
142
|
+
elif self.convention == 'staggered_x':
|
|
143
|
+
# Count first and last slice as half cells
|
|
144
|
+
average = self.lib.sum(field[:,1:-1,:,:], (1,2,3)) \
|
|
145
|
+
+ 0.5*self.lib.sum(field[:, 0,:,:], (1,2,3)) \
|
|
146
|
+
+ 0.5*self.lib.sum(field[:,-1,:,:], (1,2,3))
|
|
147
|
+
average /= (self.shape[0]-1) * self.shape[1] * self.shape[2]
|
|
148
|
+
else:
|
|
149
|
+
raise ValueError(
|
|
150
|
+
f"The provided field must have the shape {self.shape}."
|
|
151
|
+
)
|
|
152
|
+
return average
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class VoxelGridTorch(VoxelGrid):
|
|
156
|
+
def __init__(self, grid: Grid, precision='float32', device: str='cuda'):
|
|
157
|
+
"""Create a torch backed grid.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
grid: Grid description.
|
|
161
|
+
precision: Floating point precision.
|
|
162
|
+
device: Torch device string.
|
|
163
|
+
"""
|
|
164
|
+
try:
|
|
165
|
+
import torch
|
|
166
|
+
except ImportError:
|
|
167
|
+
raise ImportError("PyTorch backend selected but 'torch' is not installed.")
|
|
168
|
+
self.torch = torch
|
|
169
|
+
|
|
170
|
+
# Handle torch device
|
|
171
|
+
self.device = torch.device(device)
|
|
172
|
+
if torch.device(device).type.startswith("cuda") and not torch.cuda.is_available():
|
|
173
|
+
self.device = torch.device("cpu")
|
|
174
|
+
warnings.warn(
|
|
175
|
+
"CUDA not available, defaulting device to cpu. "
|
|
176
|
+
"To avoid this warning, set device=torch.device('cpu')",
|
|
177
|
+
)
|
|
178
|
+
torch.set_default_device(self.device)
|
|
179
|
+
|
|
180
|
+
# Handle torch precision
|
|
181
|
+
if precision == 'float32':
|
|
182
|
+
self.precision = torch.float32
|
|
183
|
+
if precision == 'float64':
|
|
184
|
+
self.precision = torch.float64
|
|
185
|
+
|
|
186
|
+
super().__init__(grid, torch)
|
|
187
|
+
|
|
188
|
+
def to_backend(self, np_arr):
|
|
189
|
+
return self.torch.tensor(np_arr, dtype=self.precision, device=self.device)
|
|
190
|
+
|
|
191
|
+
def to_numpy(self, field):
|
|
192
|
+
return field.cpu().numpy()
|
|
193
|
+
|
|
194
|
+
def pad_periodic(self, field):
|
|
195
|
+
return self.torch.nn.functional.pad(field, (1,1,1,1,1,1), mode='circular')
|
|
196
|
+
|
|
197
|
+
def pad_zeros(self, field):
|
|
198
|
+
return self.torch.nn.functional.pad(field, (1,1,1,1,1,1), mode='constant', value=0)
|
|
199
|
+
|
|
200
|
+
def fftn(self, field, shape):
|
|
201
|
+
return self.torch.fft.fftn(field, s=shape)
|
|
202
|
+
|
|
203
|
+
def rfftn(self, field, shape):
|
|
204
|
+
return self.torch.fft.rfftn(field, s=shape)
|
|
205
|
+
|
|
206
|
+
def irfftn(self, field, shape):
|
|
207
|
+
return self.torch.fft.irfftn(field, s=shape)
|
|
208
|
+
|
|
209
|
+
def real_of_ifftn(self, field, shape):
|
|
210
|
+
return self.torch.real(self.torch.fft.ifftn(field, s=shape))
|
|
211
|
+
|
|
212
|
+
def expand_dim(self, field, dim):
|
|
213
|
+
return field.unsqueeze(dim)
|
|
214
|
+
|
|
215
|
+
def squeeze(self, field, dim):
|
|
216
|
+
return self.torch.squeeze(field, dim)
|
|
217
|
+
|
|
218
|
+
def concatenate(self, fieldlist, dim):
|
|
219
|
+
return self.torch.cat(fieldlist, dim=dim)
|
|
220
|
+
|
|
221
|
+
def set(self, field, index, value):
|
|
222
|
+
field[index] = value
|
|
223
|
+
return field
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
class VoxelGridJax(VoxelGrid):
|
|
227
|
+
def __init__(self, grid: Grid, precision='float32'):
|
|
228
|
+
"""Create a JAX backed grid.
|
|
229
|
+
|
|
230
|
+
Args:
|
|
231
|
+
grid: Grid description.
|
|
232
|
+
precision: Floating point precision for arrays.
|
|
233
|
+
"""
|
|
234
|
+
try:
|
|
235
|
+
import jax.numpy as jnp
|
|
236
|
+
except ImportError:
|
|
237
|
+
raise ImportError("JAX backend selected but 'jax' is not installed.")
|
|
238
|
+
self.jnp = jnp
|
|
239
|
+
self.precision = precision
|
|
240
|
+
super().__init__(grid, jnp)
|
|
241
|
+
|
|
242
|
+
def to_backend(self, np_arr):
|
|
243
|
+
return self.jnp.array(np_arr, dtype=self.precision)
|
|
244
|
+
|
|
245
|
+
def to_numpy(self, field):
|
|
246
|
+
return np.array(field)
|
|
247
|
+
|
|
248
|
+
def pad_periodic(self, field):
|
|
249
|
+
pad_width = ((0, 0), (1, 1), (1, 1), (1, 1))
|
|
250
|
+
return self.jnp.pad(field, pad_width, mode='wrap')
|
|
251
|
+
|
|
252
|
+
def pad_zeros(self, field):
|
|
253
|
+
pad_width = ((0, 0), (1, 1), (1, 1), (1, 1))
|
|
254
|
+
return self.jnp.pad(field, pad_width, mode='constant', constant_values=0)
|
|
255
|
+
|
|
256
|
+
def fftn(self, field, shape):
|
|
257
|
+
return self.jnp.fft.fftn(field, s=shape)
|
|
258
|
+
|
|
259
|
+
def rfftn(self, field, shape):
|
|
260
|
+
return self.jnp.fft.rfftn(field, s=shape)
|
|
261
|
+
|
|
262
|
+
def irfftn(self, field, shape):
|
|
263
|
+
return self.jnp.fft.irfftn(field, s=shape)
|
|
264
|
+
|
|
265
|
+
def real_of_ifftn(self, field, shape):
|
|
266
|
+
return self.jnp.fft.ifftn(field, s=shape).real
|
|
267
|
+
|
|
268
|
+
def expand_dim(self, field, dim):
|
|
269
|
+
return self.jnp.expand_dims(field, dim)
|
|
270
|
+
|
|
271
|
+
def squeeze(self, field, dim):
|
|
272
|
+
return self.jnp.squeeze(field, axis=dim)
|
|
273
|
+
|
|
274
|
+
def concatenate(self, fieldlist, dim):
|
|
275
|
+
return self.jnp.concatenate(fieldlist, axis=dim)
|
|
276
|
+
|
|
277
|
+
def set(self, field, index, value):
|
|
278
|
+
return field.at[index].set(value)
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: evoxels
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Voxel-based structure simulation solvers
|
|
5
|
+
Author-email: Simon Daubner <s.daubner@imperial.ac.uk>
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Development Status :: 4 - Beta
|
|
8
|
+
Classifier: Intended Audience :: Science/Research
|
|
9
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
10
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Natural Language :: English
|
|
14
|
+
Classifier: Environment :: GPU
|
|
15
|
+
Classifier: Environment :: GPU :: NVIDIA CUDA
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: numpy>=1.21
|
|
25
|
+
Requires-Dist: matplotlib>=3.4
|
|
26
|
+
Requires-Dist: pyvista>=0.38
|
|
27
|
+
Requires-Dist: psutil>=5.9.0
|
|
28
|
+
Requires-Dist: ipython>=7.0.0
|
|
29
|
+
Requires-Dist: sympy>=1.10
|
|
30
|
+
Provides-Extra: torch
|
|
31
|
+
Requires-Dist: torch>=2.1; extra == "torch"
|
|
32
|
+
Provides-Extra: jax
|
|
33
|
+
Requires-Dist: jax>=0.4.14; extra == "jax"
|
|
34
|
+
Requires-Dist: jaxlib>=0.4.14; extra == "jax"
|
|
35
|
+
Requires-Dist: diffrax>=0.6.2; extra == "jax"
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: pytest; extra == "dev"
|
|
38
|
+
Requires-Dist: ruff; extra == "dev"
|
|
39
|
+
Provides-Extra: notebooks
|
|
40
|
+
Requires-Dist: ipywidgets; extra == "notebooks"
|
|
41
|
+
Requires-Dist: ipympl; extra == "notebooks"
|
|
42
|
+
Requires-Dist: notebook; extra == "notebooks"
|
|
43
|
+
Dynamic: license-file
|
|
44
|
+
|
|
45
|
+
[](https://github.com/daubners/evoxels/actions/workflows/python-package.yml)
|
|
46
|
+
|
|
47
|
+
# evoxels
|
|
48
|
+
A differentiable physics framework for voxel-based microstructure simulations
|
|
49
|
+
|
|
50
|
+
For more detailed information about the code [read the docs](https://evoxels.readthedocs.io).
|
|
51
|
+
|
|
52
|
+
<p align="center">
|
|
53
|
+
<img src="evoxels.png" width="90%"></img>
|
|
54
|
+
</p>
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
In a world of cubes and blocks,
|
|
58
|
+
Where reality takes voxel knocks,
|
|
59
|
+
Every shape and form we see,
|
|
60
|
+
Is a pixelated mystery.
|
|
61
|
+
|
|
62
|
+
Mountains rise in jagged peaks,
|
|
63
|
+
Rivers flow in blocky streaks.
|
|
64
|
+
So embrace the charm of this edgy place,
|
|
65
|
+
Where every voxel finds its space
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Description
|
|
69
|
+
**evoxels are not static — they evolve, adapt, and reveal.**
|
|
70
|
+
Whether you're modeling phase transitions, predicting effective properties, or coupling imaging and simulation — evoxels is the GPU-native, differentiable core that keeps pace with your science.
|
|
71
|
+
|
|
72
|
+
Materials science inherently spans disciplines: experimentalists use advanced microscopy to uncover micro- and nanoscale structure, while theorists and computational scientists develop models that link processing, structure, and properties. Bridging these domains is essential for inverse material design where you start from desired performance and work backwards to optimal microstructures and manufacturing routes. Integrating high-resolution imaging with predictive simulations and data‐driven optimization accelerates discovery and deepens understanding of process–structure–property relationships
|
|
73
|
+
|
|
74
|
+
From a high-level perspective, evoxels is organized around two core abstractions: ``VoxelFields`` and ``VoxelGrid``. VoxelFields provides a uniform, NumPy-based container for any number of 3D fields on the same regular grid, maximizing interoperability with image I/O libraries (e.g. tifffile, h5py, napari, scikit-image) and visualization tools (PyVista, VTK). VoxelGrid couples these fields to either a PyTorch or JAX backend, offering pre-defined boundary conditions, finite difference stencils and FFT libraries.
|
|
75
|
+
|
|
76
|
+
The evoxels package enables large-scale forward and inverse simulations on uniform voxel grids, ensuring direct compatibility with microscopy data and harnessing GPU-optimized FFT and tensor operations.
|
|
77
|
+
This design supports forward modeling of transport and phase evolution phenomena, as well as backpropagation-based inverse problems such as parameter estimation and neural surrogate training - tasks which are still difficult to achieve with traditional FEM-based solvers.
|
|
78
|
+
This differentiable‐physics foundation makes it easy to embed voxel‐based solvers as neural‐network layers, train generative models for optimal microstructures, or jointly optimize processing and properties via gradient descent. By keeping each simulation step fast and fully backpropagatable, evoxels enables data‐driven materials discovery and high‐dimensional design‐space exploration.
|
|
79
|
+
|
|
80
|
+
## Installation
|
|
81
|
+
|
|
82
|
+
TL;DR
|
|
83
|
+
```bash
|
|
84
|
+
conda create --name voxenv python=3.12
|
|
85
|
+
conda activate voxenv
|
|
86
|
+
pip install evoxels[torch,jax,dev,notebooks]
|
|
87
|
+
pip install --upgrade "jax[cuda12]"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The package is available on pypi but can also be installed by cloning the repository
|
|
91
|
+
```
|
|
92
|
+
git clone git@github.com:daubners/evoxels.git
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
and then locally installing in editable mode.
|
|
96
|
+
It is recommended to install the package inside a Python virtual environment so
|
|
97
|
+
that the dependencies do not interfere with your system packages. Create and
|
|
98
|
+
activate a virtual environment e.g. using miniconda
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
conda create --name myenv python=3.12
|
|
102
|
+
conda activate myenv
|
|
103
|
+
```
|
|
104
|
+
Navigate to the evoxels folder, then
|
|
105
|
+
```
|
|
106
|
+
pip install -e .[torch] # install with torch backend
|
|
107
|
+
pip install -e .[jax] # install with jax backend
|
|
108
|
+
pip install -e .[dev, notebooks] # install testing and notebooks
|
|
109
|
+
```
|
|
110
|
+
Note that the default `[jax]` installation is only CPU compatible. To install the corresponding CUDA libraries check your CUDA version with
|
|
111
|
+
```bash
|
|
112
|
+
nvidia-smi
|
|
113
|
+
```
|
|
114
|
+
then install the CUDA-enabled JAX backend via (in this case for CUDA version 12)
|
|
115
|
+
```bash
|
|
116
|
+
pip install -U "jax[cuda12]"
|
|
117
|
+
```
|
|
118
|
+
To install both backends within one environment it is important to install torch first and then upgrade the `jax` installation e.g.
|
|
119
|
+
```bash
|
|
120
|
+
pip install evoxels[torch, jax, dev, notebooks]
|
|
121
|
+
pip install --upgrade "jax[cuda12]"
|
|
122
|
+
```
|
|
123
|
+
To work with the example notebooks install Jupyter and all notebook related dependencies via
|
|
124
|
+
```
|
|
125
|
+
pip install -e .[notebooks]
|
|
126
|
+
```
|
|
127
|
+
Launch the notebooks with
|
|
128
|
+
```
|
|
129
|
+
jupyter notebook
|
|
130
|
+
```
|
|
131
|
+
If you are using VSCode open the Command Palette and select
|
|
132
|
+
"Jupyter: Create New Blank Notebook" or open an existing notebook file.
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
## Usage
|
|
136
|
+
|
|
137
|
+
Example of creating a voxel field object and running a Cahn-Hilliard simulation based on a semi-implicit FFT approach
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
import evoxels as evo
|
|
141
|
+
import numpy as np
|
|
142
|
+
|
|
143
|
+
nx, ny, nz = [100, 100, 100]
|
|
144
|
+
|
|
145
|
+
vf = evo.VoxelFields((nx, ny, nz), (nx,ny,nz))
|
|
146
|
+
noise = 0.5 + 0.1*np.random.rand(nx, ny, nz)
|
|
147
|
+
vf.add_field("c", noise)
|
|
148
|
+
|
|
149
|
+
dt = 0.1
|
|
150
|
+
final_time = 100
|
|
151
|
+
steps = int(final_time/dt)
|
|
152
|
+
|
|
153
|
+
evo.run_cahn_hilliard_solver(
|
|
154
|
+
vf, 'c', 'torch', jit=True, device='cuda',
|
|
155
|
+
time_increment=dt, frames=10, max_iters=steps,
|
|
156
|
+
verbose='plot', vtk_out=False, plot_bounds=(0,1)
|
|
157
|
+
)
|
|
158
|
+
```
|
|
159
|
+
As the simulation is running, the "c" field will be overwritten each frame. Therefore, ``vf.fields["c"]`` will give you the last frame of the simulation. This code design has been chosen specifically for large data such that the RAM requirements are rather low.
|
|
160
|
+
For visual inspection of your simulation results, you can plot individual slices (e.g. slice=10) for a given direction (e.g. x)
|
|
161
|
+
```
|
|
162
|
+
vf.plot_slice("c", 10, direction='x', colormap='viridis')
|
|
163
|
+
```
|
|
164
|
+
or use the following code for interactive plotting with a slider to go through the volume
|
|
165
|
+
```
|
|
166
|
+
%matplotlib widget
|
|
167
|
+
vf.plot_field_interactive("c", direction='x', colormap='turbo')
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
This code has been published under the MIT licence.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
evoxels/__init__.py,sha256=LLogj7BjzLNi9voNIQkmDYmj_dT82Aw8ph9RAlaPLuU,376
|
|
2
|
+
evoxels/boundary_conditions.py,sha256=IZbPFvPVknWtTyXdDYEQiWCmw1RhwAlCfx0GBpGt7wg,5129
|
|
3
|
+
evoxels/fd_stencils.py,sha256=kpFszQqjSPuWzRPyscR13uaDM9GWiBvmBVopBRosohs,4581
|
|
4
|
+
evoxels/function_approximators.py,sha256=_WwsypBWSigMlyvT_Qgc8rHN7SsyvyFL9WgB1QqPdHY,2545
|
|
5
|
+
evoxels/inversion.py,sha256=wKRaJ14eLGBWIeJbAk1pSFP6kFmKDeM9OBvSHndUAz4,8694
|
|
6
|
+
evoxels/problem_definition.py,sha256=nfr0M1yH0v16btJoE9_0xlukxjyHx3BmnM1pWyXIsew,14559
|
|
7
|
+
evoxels/profiler.py,sha256=2nGEbQBTaP_FUdA7OojmxQe2npLJwgDC-RVF4DNJ51A,3995
|
|
8
|
+
evoxels/solvers.py,sha256=tA-3bqHApktZnENMNWZIz-bsgX2QKRzW8FzKrwsvQXE,5172
|
|
9
|
+
evoxels/timesteppers.py,sha256=YbaWViKklhZeYKjl4SetWUALS4q6Fm7zCYy6cBesGgw,3509
|
|
10
|
+
evoxels/utils.py,sha256=wp-tL2SkFIjSM3B1IwbMGLcVGPO6T8wr4bGitgn7z1k,4686
|
|
11
|
+
evoxels/voxelfields.py,sha256=e6DEqv1C7MavOqFx9RhEMD-SktVEO1JDLRv43WNiCTU,13300
|
|
12
|
+
evoxels/voxelgrid.py,sha256=r5yoo2J6ogHEOzFbhjikbi4wXQfurmZB4EWf6AEHIK0,9549
|
|
13
|
+
evoxels/precompiled_solvers/__init__.py,sha256=V8oekjyg13ziQ1Gdf0pHHYubZcB6Oec5a8RG0d09Y1c,50
|
|
14
|
+
evoxels/precompiled_solvers/allen_cahn.py,sha256=ZutF6L3LYqyCC3tIEQwHmQchZSbhZFmcLy-UNaN4yH0,1373
|
|
15
|
+
evoxels/precompiled_solvers/cahn_hilliard.py,sha256=Bn2Tbv-kbLwinvVkCr07CT8OrR9im0kvKk0o9ySghFI,1158
|
|
16
|
+
evoxels-0.1.0.dist-info/licenses/LICENSE,sha256=2ScNJCT83dGOKEIpmeO0sq7sf6-Rru3SsnDHJ2UFdcg,1065
|
|
17
|
+
evoxels-0.1.0.dist-info/METADATA,sha256=s4G2NK70_BCfZG9N8dzRXQAEwNrkYHCiLyoaFm-ERMM,7562
|
|
18
|
+
evoxels-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
19
|
+
evoxels-0.1.0.dist-info/top_level.txt,sha256=g6OihMiKjYgojKrMM8ckpmFVh-ExPN8f4MZPWscCbqo,8
|
|
20
|
+
evoxels-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 daubners
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
evoxels
|