compgen 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.
- compgen/__init__.py +29 -0
- compgen/exoutil.py +43 -0
- compgen/filters.py +120 -0
- compgen/gen.py +612 -0
- compgen/hdfwriter.py +57 -0
- compgen/materials.py +78 -0
- compgen/mesh.py +507 -0
- compgen/moose.py +365 -0
- compgen/physics/2d/elastic/settings.json +56 -0
- compgen/physics/2d/elastic/template.i +209 -0
- compgen/physics/2d/plastic/settings.json +95 -0
- compgen/physics/2d/plastic/template.i +558 -0
- compgen/physics/2d/thermal_conductivity/settings.json +49 -0
- compgen/physics/2d/thermal_conductivity/template.i +215 -0
- compgen/physics/2d/thermal_conductivity_with_interface/settings.json +53 -0
- compgen/physics/2d/thermal_conductivity_with_interface/template.i +229 -0
- compgen/physics/2d/thermal_expansion/settings.json +55 -0
- compgen/physics/2d/thermal_expansion/template.i +233 -0
- compgen/physics/3d/elastic/settings.json +68 -0
- compgen/physics/3d/elastic/template.i +281 -0
- compgen/physics/3d/plastic/settings.json +245 -0
- compgen/physics/3d/plastic/template.i +658 -0
- compgen/physics/3d/thermal_conductivity/settings.json +53 -0
- compgen/physics/3d/thermal_conductivity/template.i +245 -0
- compgen/physics/3d/thermal_conductivity_with_interface/settings.json +57 -0
- compgen/physics/3d/thermal_conductivity_with_interface/template.i +259 -0
- compgen/physics/3d/thermal_expansion/settings.json +61 -0
- compgen/physics/3d/thermal_expansion/template.i +276 -0
- compgen/runner.py +407 -0
- compgen/temp.py +56 -0
- compgen/tensors.py +65 -0
- compgen/utils.py +180 -0
- compgen-0.1.0.dist-info/METADATA +105 -0
- compgen-0.1.0.dist-info/RECORD +37 -0
- compgen-0.1.0.dist-info/WHEEL +5 -0
- compgen-0.1.0.dist-info/licenses/LICENSE +23 -0
- compgen-0.1.0.dist-info/top_level.txt +1 -0
compgen/__init__.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Copyright 2026, UChicago Argonne, LLC
|
|
2
|
+
# All Rights Reserved
|
|
3
|
+
# Software Name: compgen
|
|
4
|
+
# By: Argonne National Laboratory
|
|
5
|
+
# OPEN SOURCE LICENSE (MIT)
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in
|
|
15
|
+
# all copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
# THE SOFTWARE.
|
|
24
|
+
|
|
25
|
+
"""Top-level package for composite structure generation and simulation workflows."""
|
|
26
|
+
|
|
27
|
+
from importlib.metadata import version
|
|
28
|
+
|
|
29
|
+
__version__ = version("compgen")
|
compgen/exoutil.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Copyright 2026, UChicago Argonne, LLC
|
|
2
|
+
# All Rights Reserved
|
|
3
|
+
# Software Name: compgen
|
|
4
|
+
# By: Argonne National Laboratory
|
|
5
|
+
# OPEN SOURCE LICENSE (MIT)
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in
|
|
15
|
+
# all copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
# THE SOFTWARE.
|
|
24
|
+
|
|
25
|
+
"""Various helpers for reading Exodus II files."""
|
|
26
|
+
|
|
27
|
+
import numpy as np
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_element_field(exo, field):
|
|
31
|
+
"""Retrieve an element field from an Exodus mesh.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
exo (exodusii.File): Open Exodus file object.
|
|
35
|
+
field (str): Name of the element field to retrieve.
|
|
36
|
+
"""
|
|
37
|
+
var_names = list(exo.get_element_variable_names())
|
|
38
|
+
if field not in var_names:
|
|
39
|
+
raise ValueError(f"Field '{field}' not found in output Exodus file.")
|
|
40
|
+
|
|
41
|
+
return np.concatenate(
|
|
42
|
+
[exo.get_element_variable_values(blk, field) for blk in [1, 2]], axis=-1
|
|
43
|
+
)
|
compgen/filters.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Copyright 2026, UChicago Argonne, LLC
|
|
2
|
+
# All Rights Reserved
|
|
3
|
+
# Software Name: compgen
|
|
4
|
+
# By: Argonne National Laboratory
|
|
5
|
+
# OPEN SOURCE LICENSE (MIT)
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in
|
|
15
|
+
# all copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
# THE SOFTWARE.
|
|
24
|
+
|
|
25
|
+
"""Image filtering utilities for preprocessing generated microstructures."""
|
|
26
|
+
|
|
27
|
+
import numpy as np
|
|
28
|
+
import skimage
|
|
29
|
+
from compgen import utils
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def mean_filter(img, radius=3, periodic=True):
|
|
33
|
+
"""Apply a mean filter to an image.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
img (np.ndarray): 2D or 3D image.
|
|
37
|
+
radius (int): Radius of disk/ball footprint.
|
|
38
|
+
periodic (bool): If True, use periodic wrapping at the boundaries.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
np.ndarray: Smoothed binary image.
|
|
42
|
+
"""
|
|
43
|
+
ndim = img.ndim
|
|
44
|
+
|
|
45
|
+
if ndim == 3:
|
|
46
|
+
footprint = skimage.morphology.ball(radius)
|
|
47
|
+
elif ndim == 2:
|
|
48
|
+
footprint = skimage.morphology.disk(radius)
|
|
49
|
+
else:
|
|
50
|
+
raise ValueError("mean_filter only supports 2D and 3D images")
|
|
51
|
+
|
|
52
|
+
def smooth(i):
|
|
53
|
+
i_u8 = skimage.util.img_as_ubyte(i.astype(float))
|
|
54
|
+
|
|
55
|
+
if periodic:
|
|
56
|
+
pad_width = [(radius, radius)] * ndim
|
|
57
|
+
i_u8 = np.pad(i_u8, pad_width=pad_width, mode="wrap")
|
|
58
|
+
|
|
59
|
+
out = skimage.filters.rank.mean(i_u8, footprint=footprint)
|
|
60
|
+
out = skimage.util.img_as_float(out)
|
|
61
|
+
|
|
62
|
+
if periodic:
|
|
63
|
+
slices = tuple(slice(radius, -radius) for _ in range(ndim))
|
|
64
|
+
out = out[slices]
|
|
65
|
+
|
|
66
|
+
return out
|
|
67
|
+
|
|
68
|
+
return utils.binary_smoother(img, smooth)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def make_orthogonal(img):
|
|
72
|
+
"""Mirror and tile the input array to give it orthogonal periodicity.
|
|
73
|
+
|
|
74
|
+
This works for arrays of arbitrary dimensionality by concatenating the
|
|
75
|
+
array with its flipped version along each axis (processing axes from
|
|
76
|
+
last to first).
|
|
77
|
+
"""
|
|
78
|
+
arr = np.asarray(img)
|
|
79
|
+
for axis in reversed(range(arr.ndim)):
|
|
80
|
+
arr = np.concatenate([arr, np.flip(arr, axis=axis)], axis=axis)
|
|
81
|
+
return arr
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def make_periodic(img: np.ndarray, margin: int = 2) -> np.ndarray:
|
|
85
|
+
"""
|
|
86
|
+
Make periodic for Sculpt/MOOSE workflow.
|
|
87
|
+
|
|
88
|
+
Overwrite the first and last `margin` layers of each axis with the layer at
|
|
89
|
+
index `margin`, for 2D or 3D arrays.
|
|
90
|
+
|
|
91
|
+
A value `margin` = 2 seems to work consistently with Sculpt/MOOSE.
|
|
92
|
+
"""
|
|
93
|
+
arr = np.array(img, copy=True)
|
|
94
|
+
|
|
95
|
+
if arr.ndim not in (2, 3):
|
|
96
|
+
raise RuntimeError(f"Expected 2D or 3D array, got {arr.ndim}D")
|
|
97
|
+
|
|
98
|
+
if not isinstance(margin, int) or margin < 1:
|
|
99
|
+
raise ValueError(f"margin must be a positive integer, got {margin}")
|
|
100
|
+
|
|
101
|
+
if any(2 * margin >= s for s in arr.shape):
|
|
102
|
+
raise ValueError(f"margin={margin} is too large for shape {arr.shape}")
|
|
103
|
+
|
|
104
|
+
# Loop over each axis
|
|
105
|
+
for ax in range(arr.ndim):
|
|
106
|
+
# Slice selecting the master layer at index = margin
|
|
107
|
+
master = [slice(None)] * arr.ndim
|
|
108
|
+
master[ax] = slice(margin, margin + 1)
|
|
109
|
+
|
|
110
|
+
# Slice for lower and upper boundary block
|
|
111
|
+
lo = [slice(None)] * arr.ndim
|
|
112
|
+
lo[ax] = slice(0, margin)
|
|
113
|
+
hi = [slice(None)] * arr.ndim
|
|
114
|
+
hi[ax] = slice(-margin, None)
|
|
115
|
+
|
|
116
|
+
# Overwrite both boundary blocks using the master layer
|
|
117
|
+
arr[tuple(lo)] = arr[tuple(master)]
|
|
118
|
+
arr[tuple(hi)] = arr[tuple(master)]
|
|
119
|
+
|
|
120
|
+
return arr
|