Skip to content

Commit ff97912

Browse files
authored
update (#8)
1 parent 66d1964 commit ff97912

File tree

2 files changed

+73
-67
lines changed

2 files changed

+73
-67
lines changed

MSUtils/general/vtk2h5.py

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -162,67 +162,3 @@ def vtk2h5(
162162
h5.attrs["num_files"] = len(root)
163163

164164
print(f"Done → {h5_file_path}")
165-
166-
167-
def main():
168-
# Example usage
169-
vti_files = [
170-
"data/spinodoid_network_np_isotropic_x192_30pi_dens50_0001.vti",
171-
"data/spinodoid_network_np_isotropic_x192_30pi_dens50_0002.vti",
172-
"data/spinodoid_network_np_isotropic_x192_30pi_dens50_0003.vti",
173-
]
174-
h5_file_path = "data/spinodoid_collection.h5"
175-
vtk2h5(
176-
vtk_files=vti_files,
177-
h5_file_path=h5_file_path,
178-
grp_name="/spinodoids/isotropic",
179-
overwrite=True,
180-
)
181-
182-
183-
if __name__ == "__main__":
184-
# If no arguments provided, run the example in main()
185-
if len(sys.argv) == 1:
186-
main()
187-
else:
188-
# Parse command line arguments
189-
parser = argparse.ArgumentParser(description="Convert VTI files to HDF5 format")
190-
parser.add_argument(
191-
"--vti-files", nargs="+", required=True, help="List of VTI files to convert"
192-
)
193-
parser.add_argument(
194-
"--output", "-o", required=True, help="Output HDF5 file path"
195-
)
196-
parser.add_argument(
197-
"--group",
198-
"-g",
199-
default="images",
200-
help="Group name within H5 file (default: images)",
201-
)
202-
parser.add_argument(
203-
"--data-field", "-d", help="Specific data field to extract (optional)"
204-
)
205-
parser.add_argument(
206-
"--overwrite", action="store_true", help="Overwrite existing datasets"
207-
)
208-
209-
args = parser.parse_args()
210-
211-
vtk2h5(
212-
vtk_files=args.vti_files,
213-
h5_file_path=args.output,
214-
grp_name=args.group,
215-
data_fields=[args.data_field] if args.data_field else None,
216-
overwrite=args.overwrite,
217-
)
218-
219-
# CLI examples:
220-
221-
# Convert multiple VTI files to
222-
# python vti2h5.py --vti-files data/file1.vti data/file2.vti data/file3.vti --output output.h5 --group /spinodoids/isotropic --overwrite
223-
224-
# Extract a specific data field
225-
# python vti2h5.py --vti-files data/*.vti --output collection.h5 --group images --data-field density
226-
227-
# Basic usage with default group name
228-
# python vti2h5.py --vti-files data/spinodoid_*.vti --output spinodoids.h5

README.md

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,75 @@
1-
# MSUtils
1+
# MSUtils - Microstructure Utilities
22

3-
[![Pixi Badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/prefix-dev/pixi/main/assets/badge/v0.json)](https://pixi.sh)
3+
<!-- Status & links -->
4+
[![License](https://img.shields.io/badge/license-LGPL--3.0-blue)](LICENSE)[![Pixi Badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/prefix-dev/pixi/main/assets/badge/v0.json)](https://pixi.sh)
45

5-
Powered by [Pixi](https://pixi.sh/latest/). Download and run ``pixi install``.
6+
7+
MSUtils is a collection of utilities and scripts for creating, processing and exporting voxelized microstructure data which can be readily used in FFT-based solvers such as [FANS](https://github.com/DataAnalyticsEngineering/FANS).
8+
9+
## Installation
10+
11+
We use [Pixi](https://pixi.sh/latest/) for package management. If you don't have Pixi installed, install pixi via:
12+
13+
```bash
14+
curl -fsSL https://pixi.sh/install.sh | sh
15+
```
16+
17+
Clone the repository and install the required packages:
18+
19+
```bash
20+
git clone https://github.com/DataAnalyticsEngineering/MSUtils.git
21+
cd MSUtils/
22+
pixi shell
23+
```
24+
25+
## Microstructure generation
26+
27+
These modules produce periodic voxelized microstructures (numpy arrays / HDF5 datasets) of heterogeneous materials which can be readily used in FFT-based solvers such as [FANS](https://github.com/DataAnalyticsEngineering/FANS).
28+
29+
- Voronoi based microstructures: ([MSUtils/voronoi/](MSUtils/voronoi/))
30+
- [VoronoiSeeds.py](MSUtils/voronoi/VoronoiSeeds.py): Sampling strategies for Voronoi seed placement (sobol, halton, lhs-lloyd, lattice/honeycomb) and lattice vectors.
31+
- [VoronoiTessellation.py](MSUtils/voronoi/VoronoiTessellation.py): Build periodic Voronoi tessellations, compute analytical crystal volumes, interface areas, structure tensors and export to VTU.
32+
- [voronoi_foam.py](MSUtils/voronoi/voronoi_foam.py): Rasterize Voronoi edges into strut-based foam microstructures.
33+
- [VoronoiImage.py](MSUtils/voronoi/VoronoiImage.py): Rasterize seeds into a labelled voxel image using a periodic KDTree (nearest-seed labelling).
34+
- [VoronoiGBErosion.py](MSUtils/voronoi/VoronoiGBErosion.py): Erode Voronoi images to identify grain-boundary voxels, tag grain-boundary IDs and save grain-boundary metadata.
35+
36+
- Triply periodic minimal surface (TPMS) based microstructures: ([MSUtils/TPMS/](MSUtils/TPMS/))
37+
- [tpms.py](MSUtils/TPMS/tpms.py): Generate TPMS (Gyroid, Schwarz P, Diamond, Neovius, IWP, Lidinoid, etc.) based microstructures. Supports binarization modes (`solid`/`shell`) and threshold-finding for target volume fractions.
38+
- [tpms_functions.py](MSUtils/TPMS/tpms_functions.py): The raw implicit functions used by the TPMS generator.
39+
40+
- Spinodal microstructures: ([MSUtils/spinodoids/](MSUtils/spinodoids/))
41+
- [generate_spinodal_microstructure.py](MSUtils/spinodoids/generate_spinodal_microstructure.py): Spectral filtering method to synthesize spinodal-like microstructures with control over volume fraction, feature size and anisotropy.
42+
43+
- Lattice based microstructures: ([MSUtils/lattices/](MSUtils/lattices/))
44+
- [lattice_definitions.py](MSUtils/lattices/lattice_definitions.py): Unit-cell vertex + edge definitions for many lattices (BCC, FCC, octet, auxetic, etc.).
45+
- [lattice_image.py](MSUtils/lattices/lattice_image.py): Draw struts for lattice unit-cells onto a voxel grid.
46+
47+
- Textile based microstructures: ([MSUtils/TexGen/](MSUtils/TexGen/))
48+
- Example scripts demonstrating how to generate and export [TexGen](https://texgen.sourceforge.io/index.php/Main_Page) models to VTU, then use [vtk2h5.py](MSUtils/general/vtk2h5.py) to get HDF5 datasets of textile based microstructures.
49+
50+
## Microstructure utilities
51+
52+
Utilities for file I/O, conversions, and practical helpers.
53+
54+
- [MSUtils/general/](MSUtils/general/)
55+
- [MicrostructureImage.py](MSUtils/general/MicrostructureImage.py) - Core class for microstructure data: read/write HDF5 datasets with permute-order handling, metadata, and volume fraction calculation.
56+
- [ComBoMicrostructureImage.py](MSUtils/general/ComBoMicrostructureImage.py) - Morphologically sound coarse-graining via composite boxels (ComBo) as described in our [paper](https://doi.org/10.1007/s00466-022-02232-4).
57+
- [resize_image.py](MSUtils/general/resize_image.py) - Resize and smooth 3D labelled voxelized microstructure images to any target image resolution.
58+
- [vtk2h5.py](MSUtils/general/vtk2h5.py) - Convert VTI/VTU cell-centered meshes into HDF5 datasets inferred on a regular cell-center grid.
59+
- [h52xdmf.py](MSUtils/general/h52xdmf.py) - Convert HDF5 datasets into XDMF XML for ParaView. Supports scalar/vector/tensor attributes and time-series handling.
60+
- [merge_h5_files.py](MSUtils/general/merge_h5_files.py) - Merge multiple HDF5 files into one by recursively copying groups/datasets.
61+
62+
- [MSUtils/sampling/](MSUtils/sampling/)
63+
- [generate_loadpaths.py](MSUtils/sampling/generate_loadpaths.py) - Samples quasi-uniform equal-area directions on the unit hypersphere using the [`LeopardiSampler`](https://github.com/FlorianPfaff/pyRecEst/blob/main/pyrecest/sampling/leopardi_sampler.py) (See [paper](https://ftp.gwdg.de/pub/EMIS/journals/ETNA/vol.25.2006/pp309-327.dir/pp309-327.pdf) for further details). Using the sampled directions, produce linear strain ramps to user limits on deviatoric and volumetric strain magnitude and exporting the load paths to JSON that can be used in the input file for [FANS](https://github.com/DataAnalyticsEngineering/FANS).
64+
65+
## Acknowledgements
66+
67+
Funded by Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) under Germany’s Excellence Strategy - EXC 2075 – 390740016. Contributions by Felix Fritzen are funded by Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) within the Heisenberg program - DFG-FR2702/8 - 406068690; DFG-FR2702/10 - 517847245 and through NFDI-MatWerk - NFDI 38/1 - 460247524. We acknowledge the support of the Stuttgart Center for Simulation Science ([SimTech](https://www.simtech.uni-stuttgart.de/)).
68+
69+
70+
## Contact
71+
72+
If you have questions or need support, please open an [issue](https://github.com/DataAnalyticsEngineering/MSUtils/issues).
73+
You can contact [Sanath Keshav](https://github.com/sanathkeshav) (keshav.@mib.uni-stuttgart.de) with any other inquiries.
74+
75+
---

0 commit comments

Comments
 (0)