tpmslab 0.3.0__tar.gz
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.
- tpmslab-0.3.0/.zenodo.json +24 -0
- tpmslab-0.3.0/CHANGELOG.md +32 -0
- tpmslab-0.3.0/CITATION.cff +13 -0
- tpmslab-0.3.0/LICENSE +21 -0
- tpmslab-0.3.0/MANIFEST.in +12 -0
- tpmslab-0.3.0/PKG-INFO +220 -0
- tpmslab-0.3.0/README.md +188 -0
- tpmslab-0.3.0/THIRD_PARTY_NOTICES.md +22 -0
- tpmslab-0.3.0/benchmarks/density_study.py +84 -0
- tpmslab-0.3.0/benchmarks/release_reference.py +109 -0
- tpmslab-0.3.0/benchmarks/revision_study.py +151 -0
- tpmslab-0.3.0/benchmarks/run_benchmarks.py +85 -0
- tpmslab-0.3.0/benchmarks/verify_comsol.py +30 -0
- tpmslab-0.3.0/benchmarks/verify_solid_fluid.py +28 -0
- tpmslab-0.3.0/docs/METHOD.md +81 -0
- tpmslab-0.3.0/docs/QUICKSTART_EN.md +95 -0
- tpmslab-0.3.0/docs/QUICKSTART_ZH.md +53 -0
- tpmslab-0.3.0/docs/RELEASE_NOTES_v0.3.0.md +24 -0
- tpmslab-0.3.0/docs/SOLID_FLUID.md +31 -0
- tpmslab-0.3.0/docs/VALIDATION.md +28 -0
- tpmslab-0.3.0/docs/VERIFICATION.md +110 -0
- tpmslab-0.3.0/docs/VERSION_0.3.0.md +67 -0
- tpmslab-0.3.0/docs/lattgen_reference.m +72 -0
- tpmslab-0.3.0/examples/graded_gyroid.json +32 -0
- tpmslab-0.3.0/examples/graded_gyroid.py +13 -0
- tpmslab-0.3.0/examples/gyroid_graded.json +31 -0
- tpmslab-0.3.0/examples/primitive_graded.json +31 -0
- tpmslab-0.3.0/examples/solid_fluid.json +33 -0
- tpmslab-0.3.0/examples/solid_fluid_api.py +38 -0
- tpmslab-0.3.0/licenses/LattGen-MIT.txt +21 -0
- tpmslab-0.3.0/pyproject.toml +46 -0
- tpmslab-0.3.0/setup.cfg +4 -0
- tpmslab-0.3.0/src/tpmslab/__init__.py +30 -0
- tpmslab-0.3.0/src/tpmslab/__main__.py +3 -0
- tpmslab-0.3.0/src/tpmslab/cli.py +63 -0
- tpmslab-0.3.0/src/tpmslab/comsol.py +250 -0
- tpmslab-0.3.0/src/tpmslab/comsol_audit.py +128 -0
- tpmslab-0.3.0/src/tpmslab/comsol_dual.py +165 -0
- tpmslab-0.3.0/src/tpmslab/families.json +119 -0
- tpmslab-0.3.0/src/tpmslab/io.py +72 -0
- tpmslab-0.3.0/src/tpmslab/model.py +258 -0
- tpmslab-0.3.0/src/tpmslab/multidomain.py +196 -0
- tpmslab-0.3.0/src/tpmslab/py.typed +0 -0
- tpmslab-0.3.0/src/tpmslab/quality.py +46 -0
- tpmslab-0.3.0/src/tpmslab/static/app.js +30 -0
- tpmslab-0.3.0/src/tpmslab/static/index.html +16 -0
- tpmslab-0.3.0/src/tpmslab/static/style.css +3 -0
- tpmslab-0.3.0/src/tpmslab/static/vendor/OrbitControls.js +1523 -0
- tpmslab-0.3.0/src/tpmslab/static/vendor/THREE-LICENSE.txt +21 -0
- tpmslab-0.3.0/src/tpmslab/static/vendor/three.module.js +54155 -0
- tpmslab-0.3.0/src/tpmslab/verification.py +57 -0
- tpmslab-0.3.0/src/tpmslab/volume.py +310 -0
- tpmslab-0.3.0/src/tpmslab/web.py +302 -0
- tpmslab-0.3.0/src/tpmslab.egg-info/PKG-INFO +220 -0
- tpmslab-0.3.0/src/tpmslab.egg-info/SOURCES.txt +78 -0
- tpmslab-0.3.0/src/tpmslab.egg-info/dependency_links.txt +1 -0
- tpmslab-0.3.0/src/tpmslab.egg-info/entry_points.txt +2 -0
- tpmslab-0.3.0/src/tpmslab.egg-info/requires.txt +17 -0
- tpmslab-0.3.0/src/tpmslab.egg-info/top_level.txt +1 -0
- tpmslab-0.3.0/tests/test_core.py +117 -0
- tpmslab-0.3.0/tests/test_multidomain.py +92 -0
- tpmslab-0.3.0/tests/test_package.py +96 -0
- tpmslab-0.3.0/tests/test_verification.py +67 -0
- tpmslab-0.3.0/validation/README.md +44 -0
- tpmslab-0.3.0/validation/checksums.json +18 -0
- tpmslab-0.3.0/validation/code_commit.json +4 -0
- tpmslab-0.3.0/validation/density/density_results.json +404 -0
- tpmslab-0.3.0/validation/environment.json +23 -0
- tpmslab-0.3.0/validation/existing_Diamond_audit/audit.json +35 -0
- tpmslab-0.3.0/validation/existing_Gyroid_audit/audit.json +35 -0
- tpmslab-0.3.0/validation/existing_Primitive_Schwartz_audit/audit.json +35 -0
- tpmslab-0.3.0/validation/historical_windows_checksums.json +17 -0
- tpmslab-0.3.0/validation/performance_summary.csv +5 -0
- tpmslab-0.3.0/validation/provenance.json +72 -0
- tpmslab-0.3.0/validation/quality_summary.csv +5 -0
- tpmslab-0.3.0/validation/reference_configs/Diamond.json +33 -0
- tpmslab-0.3.0/validation/reference_configs/Gyroid.json +33 -0
- tpmslab-0.3.0/validation/reference_configs/Primitive_Schwartz.json +33 -0
- tpmslab-0.3.0/validation/refinement_summary.csv +10 -0
- tpmslab-0.3.0/validation/summary.json +606 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "TPMS Lab v0.3.0",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"upload_type": "software",
|
|
5
|
+
"description": "Python package for graded complementary solid and pore-fluid meshes with shared interfaces, connected-domain metadata and optional verified COMSOL workflows. Source, tests, examples and numerical validation records are included.",
|
|
6
|
+
"creators": [
|
|
7
|
+
{
|
|
8
|
+
"name": "Chen, Xin",
|
|
9
|
+
"affiliation": "McGill University"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "Akbarzadeh, Abdolhamid",
|
|
13
|
+
"affiliation": "McGill University"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"TPMS",
|
|
19
|
+
"graded lattices",
|
|
20
|
+
"volume meshes",
|
|
21
|
+
"COMSOL",
|
|
22
|
+
"Python"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
- Package the verified complementary solid/fluid workflow and independent audits.
|
|
6
|
+
- Include density, refinement, interface, channel and performance records with provenance.
|
|
7
|
+
- Retain the validated numerical implementation from commit 686b783e0385.
|
|
8
|
+
- Clarify geometry/solver response stability and local quality-strategy limitations.
|
|
9
|
+
- Add isolated-wheel reference checks, exact-commit release preparation and public version documentation.
|
|
10
|
+
- Preserve historical validation provenance; GitHub publication and DOI registration remain separate records.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## 0.3.0rc1 — solid and pore-fluid domains
|
|
14
|
+
|
|
15
|
+
- Add complementary solid/fluid meshes with shared interface vertices and faces.
|
|
16
|
+
- Preserve independently connected solid and fluid domains, phase arrays and named boundaries.
|
|
17
|
+
- Add fluid preview, domain metadata and optional COMSOL named selections.
|
|
18
|
+
- Verify three fixed-wall pore-flow examples in COMSOL; deformation-coupled FSI is not implemented.
|
|
19
|
+
- Add analytical partition and multi-family interface regression tests.
|
|
20
|
+
|
|
21
|
+
## 0.2.0rc1 — local release candidate
|
|
22
|
+
|
|
23
|
+
- Introduce src-layout packaging, public Python API and command-line commands.
|
|
24
|
+
- Keep Flask and the browser interface optional; COMSOL remains optional.
|
|
25
|
+
- Add conservative interior-fan selection with unchanged external boundary.
|
|
26
|
+
- Add quality-tail diagnostics, deterministic mesh/boundary fingerprints,
|
|
27
|
+
environment records and file-integrity manifests.
|
|
28
|
+
- Normalize configuration lists to immutable tuples and apply phase controls
|
|
29
|
+
consistently in the field helper.
|
|
30
|
+
- Include reproducible comparisons, automated tests and release documentation.
|
|
31
|
+
|
|
32
|
+
No PyPI release has been made; earlier rc entries describe local release candidates.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "Please cite the exact software version used."
|
|
3
|
+
type: software
|
|
4
|
+
title: "TPMS Lab"
|
|
5
|
+
version: "0.3.0"
|
|
6
|
+
authors:
|
|
7
|
+
- family-names: Chen
|
|
8
|
+
given-names: Xin
|
|
9
|
+
- family-names: Akbarzadeh
|
|
10
|
+
given-names: Abdolhamid
|
|
11
|
+
repository-code: "https://github.com/Slight1211/TPMSLab"
|
|
12
|
+
license: MIT
|
|
13
|
+
abstract: "A Python package for graded complementary solid and pore-fluid meshes with connected-domain metadata and optional verified COMSOL workflows."
|
tpmslab-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TPMS Lab contributors
|
|
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,12 @@
|
|
|
1
|
+
include README.md LICENSE CHANGELOG.md THIRD_PARTY_NOTICES.md
|
|
2
|
+
recursive-include licenses *.txt
|
|
3
|
+
recursive-include docs *.md *.m
|
|
4
|
+
recursive-include examples *.json *.py
|
|
5
|
+
recursive-include tests *.py
|
|
6
|
+
recursive-include benchmarks *.py
|
|
7
|
+
|
|
8
|
+
exclude docs/RELEASE_CHECKLIST.md
|
|
9
|
+
prune paper
|
|
10
|
+
|
|
11
|
+
recursive-include validation *.json *.csv *.md
|
|
12
|
+
include CITATION.cff .zenodo.json
|
tpmslab-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tpmslab
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Direct conforming volume meshes for graded implicit TPMS lattices
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Keywords: TPMS,finite-element,meshing,graded-lattice,COMSOL
|
|
7
|
+
Classifier: Development Status :: 4 - Beta
|
|
8
|
+
Classifier: Intended Audience :: Science/Research
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering
|
|
13
|
+
Requires-Python: >=3.11
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
License-File: licenses/LattGen-MIT.txt
|
|
17
|
+
Requires-Dist: numpy<3,>=1.26
|
|
18
|
+
Requires-Dist: scipy<2,>=1.11
|
|
19
|
+
Requires-Dist: trimesh<6,>=4
|
|
20
|
+
Provides-Extra: web
|
|
21
|
+
Requires-Dist: flask<4,>=3.1; extra == "web"
|
|
22
|
+
Provides-Extra: test
|
|
23
|
+
Requires-Dist: pytest<10,>=8; extra == "test"
|
|
24
|
+
Requires-Dist: flask<4,>=3.1; extra == "test"
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest<10,>=8; extra == "dev"
|
|
27
|
+
Requires-Dist: flask<4,>=3.1; extra == "dev"
|
|
28
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
29
|
+
Requires-Dist: twine>=6; extra == "dev"
|
|
30
|
+
Requires-Dist: ruff>=0.12; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# TPMS Lab
|
|
34
|
+
|
|
35
|
+
[English quick start](docs/QUICKSTART_EN.md) | [中文使用说明](docs/QUICKSTART_ZH.md)
|
|
36
|
+
|
|
37
|
+
An installable Python toolkit for graded TPMS-derived **solid and complementary pore-fluid volume meshes**.
|
|
38
|
+
Version 0.3.0. This repository is public. Source, tests, examples and versioned
|
|
39
|
+
reproducibility records are distributed together. Use an exact commit or the
|
|
40
|
+
`v0.3.0` tag, rather than a changing `main`, for reproducible work.
|
|
41
|
+
|
|
42
|
+
[Version and installation details](docs/VERSION_0.3.0.md) |
|
|
43
|
+
[GitHub releases](https://github.com/Slight1211/TPMSLab/releases)
|
|
44
|
+
|
|
45
|
+
A public source repository, a GitHub Release, a Zenodo archive and a PyPI upload
|
|
46
|
+
are separate records. Cite a DOI only after the archive is actually published.
|
|
47
|
+
No PyPI release has been made.
|
|
48
|
+
|
|
49
|
+
## Install
|
|
50
|
+
|
|
51
|
+
Use Python 3.11 or newer. From this source directory:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
python -m pip install .
|
|
55
|
+
# Optional local browser interface
|
|
56
|
+
python -m pip install ".[web]"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Build a wheel locally with `python -m build` (requires the `build` package). The core does not require Flask, COMSOL, MATLAB,
|
|
60
|
+
OpenCascade, a CAD import licence or a graphics display. COMSOL model creation
|
|
61
|
+
and solving require a separate compatible COMSOL installation and licence.
|
|
62
|
+
|
|
63
|
+
## Python API
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from tpmslab import Config, generate, save_model
|
|
67
|
+
|
|
68
|
+
mesh = generate(Config(family="Gyroid", resolution=16,
|
|
69
|
+
density_start=0.25, density_end=0.50,
|
|
70
|
+
gradient="linear", quality_strategy="quality_fan"))
|
|
71
|
+
print(mesh["report"]["actual_density"])
|
|
72
|
+
save_model(mesh, "gyroid_result") # destination must not exist
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`generate` also accepts a dictionary. `list_families()` returns formula metadata.
|
|
76
|
+
Coordinates are millimetres; array connectivity is zero-based. The returned
|
|
77
|
+
mapping contains `points`, `tetra`, `boundary`, `boundary_ids`, `domains`,
|
|
78
|
+
`surface` (a trimesh object) and `report`. This API may change before
|
|
79
|
+
1.0. Configuration objects normalize sequence fields to immutable tuples.
|
|
80
|
+
|
|
81
|
+
## Command line
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
tpmslab init-config params.json
|
|
85
|
+
tpmslab generate --config params.json --out result
|
|
86
|
+
tpmslab families
|
|
87
|
+
tpmslab web --output local_models
|
|
88
|
+
# Requires licensed COMSOL on Windows:
|
|
89
|
+
tpmslab generate --config params.json --out solved_result --solve
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Export includes `mesh.nas` (CTETRA volume elements and labelled boundary
|
|
93
|
+
triangles), `mesh.npz`, `preview.stl`, parameters, diagnostics, environment and a
|
|
94
|
+
SHA-256 manifest. Existing output directories are rejected. A failed export
|
|
95
|
+
can leave a partial directory; choose a new destination after addressing the
|
|
96
|
+
error. STL is only a boundary preview. The optional bridge imports the volume
|
|
97
|
+
mesh, creates an MPH and reopens it to check the embedded element count.
|
|
98
|
+
Set `COMSOL_BIN` to the folder containing `comsolbatch.exe` and
|
|
99
|
+
`comsolcompile.exe` if automatic Windows detection fails.
|
|
100
|
+
|
|
101
|
+
## Method and limits
|
|
102
|
+
|
|
103
|
+
The library samples trigonometric level-set approximations, calibrates density
|
|
104
|
+
against a 56 cubed periodic-cell sample and clips a six-tetrahedra-per-voxel
|
|
105
|
+
background mesh. Sheet structures use two separate interpolated inequalities;
|
|
106
|
+
they do not have constant physical wall thickness. Shared intersections and
|
|
107
|
+
canonical face diagonals form a conforming tetrahedral volume mesh. Material
|
|
108
|
+
volume, boundary closure, face incidence and orientation are checked before
|
|
109
|
+
export. The result is a piecewise-planar solid domain, **not editable smooth
|
|
110
|
+
STEP/NURBS CAD**. Mesh generation can reject difficult parameter combinations.
|
|
111
|
+
|
|
112
|
+
`quality_fan` compares the original pulling fan with an interior-centroid fan
|
|
113
|
+
for poor cut cells and accepts only a better worst mean-ratio quality while
|
|
114
|
+
preserving boundary triangles and volume. This increases element count and can
|
|
115
|
+
reduce median quality. It provides no angle bound, global optimization or
|
|
116
|
+
finite-element convergence guarantee. `pulling` retains the baseline method.
|
|
117
|
+
|
|
118
|
+
There are 29 reference labels (27 distinct expressions, with aliases), eight
|
|
119
|
+
density profiles, sheet and two network modes, phase controls, and a restricted
|
|
120
|
+
custom-formula parser. Built-in formulas are adapted from LattGen; see
|
|
121
|
+
`THIRD_PARTY_NOTICES.md`. They are not claimed as new TPMS families or exact
|
|
122
|
+
minimal surfaces. Density targets are periodic-cell calibrations, not guaranteed
|
|
123
|
+
finite-specimen volume fractions. Current bounds: box domains, 1–6 cells per
|
|
124
|
+
axis, 8–64 samples per cell and at most 200,000 background voxels. The built-in
|
|
125
|
+
static demo is limited to 180,000 tetrahedra and connected material. Top/bottom
|
|
126
|
+
contact, constraints and convergence must be checked for a research model.
|
|
127
|
+
|
|
128
|
+
## Development and reproduction
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
python -m pip install ".[dev]"
|
|
132
|
+
python -m pytest
|
|
133
|
+
python -m ruff check src tests benchmarks
|
|
134
|
+
python -m build
|
|
135
|
+
python -m twine check dist/*
|
|
136
|
+
python benchmarks/run_benchmarks.py --out benchmark_results
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
See `docs/METHOD.md`, `docs/SOLID_FLUID.md` and `docs/VALIDATION.md`.
|
|
140
|
+
The CI matrix is configured for Windows/Linux and Python 3.11/3.12; configuring
|
|
141
|
+
CI does not mean those jobs have run. The measured local environment is Windows
|
|
142
|
+
and Python 3.12. Optional COMSOL validation is separate from the open test suite.
|
|
143
|
+
|
|
144
|
+
## Licence and attribution
|
|
145
|
+
|
|
146
|
+
MIT. See `LICENSE`, `THIRD_PARTY_NOTICES.md` and `licenses/` for the
|
|
147
|
+
package licence and third-party formula and browser-library notices.
|
|
148
|
+
|
|
149
|
+
## Solid and pore-fluid domains (0.3)
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from tpmslab import Config, generate, save_model
|
|
153
|
+
from tpmslab.comsol import build_mph
|
|
154
|
+
|
|
155
|
+
mesh = generate(Config(domain_mode="solid_fluid", family="Gyroid", resolution=12))
|
|
156
|
+
folder = save_model(mesh, "solid_fluid_gyroid")
|
|
157
|
+
# Optional, licensed COMSOL: verifies selections, each domain volume and saved mesh.
|
|
158
|
+
build_mph(folder, mesh["report"], solve=False)
|
|
159
|
+
# solve=True instead runs the fixed-wall pore-flow demonstration described below.
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
In the browser, select **固体 + 孔隙流体(共享界面)** under **计算域**.
|
|
163
|
+
The phase selector switches the preview between solid and pore fluid.
|
|
164
|
+
The default remains solid-only for compatibility. The JSON/CLI parameter is
|
|
165
|
+
`"domain_mode": "solid_fluid"`.
|
|
166
|
+
|
|
167
|
+
Both phases partition the same bounding box. They use shared cut-edge vertices
|
|
168
|
+
and identical interface triangles. For sheet structures the two complementary
|
|
169
|
+
inequalities are meshed separately, allowing disconnected labyrinths to remain
|
|
170
|
+
separate domains. Connectivity is determined by shared tetrahedron faces.
|
|
171
|
+
The combined mesh is checked for positive volumes, opposite adjacent-face
|
|
172
|
+
orientation, complete interface matching and total volume conservation.
|
|
173
|
+
|
|
174
|
+
`phase_ids` is one value per tetrahedron (1=solid, 2=fluid); `domains` identifies
|
|
175
|
+
individual connected domains. `interface` is oriented out of the solid.
|
|
176
|
+
`boundary` includes the outer boundary AND the solid-fluid interface once.
|
|
177
|
+
Additional arrays are `solid_boundary` and `fluid_boundary`. `surface` and
|
|
178
|
+
`preview.stl` continue to show the solid; `fluid_surface` and `fluid_preview.stl`
|
|
179
|
+
show the pore fluid. The NPZ retains all phase and boundary arrays. `domains.json`
|
|
180
|
+
records domain-to-phase and boundary-name mappings. Report `volume_mm3` remains
|
|
181
|
+
solid volume; `total_mesh_volume_mm3` includes both phases.
|
|
182
|
+
|
|
183
|
+
NASTRAN PSOLID property IDs are `100 + domain_id`. Boundary PIDs 2–7 are solid
|
|
184
|
+
xmin/xmax/ymin/ymax/zmin/zmax; 12–17 are the corresponding fluid faces; PID 8
|
|
185
|
+
is the shared interface. PIDs are NOT COMSOL entity numbers. The bridge resolves
|
|
186
|
+
imported PID selections and creates `solid_domains`, `fluid_domains`, individual
|
|
187
|
+
connected-domain selections, `solid_fluid_interface`, and the nonempty exterior
|
|
188
|
+
face selections. It assigns demonstration solid/fluid materials separately.
|
|
189
|
+
An unsolved export requires no CFD physics interface and is a starting point
|
|
190
|
+
for the user's physics setup.
|
|
191
|
+
|
|
192
|
+
For dual-domain models, `solve=True` runs stationary **creeping flow only in the
|
|
193
|
+
fluid**, with fixed no-slip solid walls, pressure 0.01 Pa at fluid_zmin and 0 Pa
|
|
194
|
+
at fluid_zmax, and no-slip on other fluid exterior faces. Density is 1000 kg/m³
|
|
195
|
+
and viscosity 0.001 Pa·s. Every fluid component must reach both Z faces; otherwise
|
|
196
|
+
the automatic demo is refused while unsolved export remains available. This
|
|
197
|
+
requires the corresponding COMSOL physics licence. It reports inlet/outlet
|
|
198
|
+
flow and relative imbalance (the smoke-test threshold is 5%, not an accuracy
|
|
199
|
+
claim). It is **not deformation-coupled FSI**, not conjugate heat transfer, and
|
|
200
|
+
not a validated permeability prediction. Boundary layers, external reservoirs,
|
|
201
|
+
mesh convergence and realistic boundary conditions remain user responsibilities.
|
|
202
|
+
See `docs/SOLID_FLUID.md` for validation and reproducibility.
|
|
203
|
+
|
|
204
|
+
## Solid–fluid quick start
|
|
205
|
+
|
|
206
|
+
Run [the Python example](examples/solid_fluid_api.py). Installation, exported
|
|
207
|
+
files and optional COMSOL calculations are documented in the
|
|
208
|
+
[English quick start](docs/QUICKSTART_EN.md) and
|
|
209
|
+
[中文使用说明](docs/QUICKSTART_ZH.md).
|
|
210
|
+
|
|
211
|
+
## Independent verification
|
|
212
|
+
|
|
213
|
+
See [Verification and reproducible studies](docs/VERIFICATION.md) for density realization, independent interface incidence and area audits, channel-wise COMSOL flux checks, and refinement/performance scripts. `quality_fan` is optional local worst-element mitigation, not a general quality or solver-speed guarantee.
|
|
214
|
+
|
|
215
|
+
## Reproducibility records
|
|
216
|
+
|
|
217
|
+
See [validation/README.md](validation/README.md) for the numerical records,
|
|
218
|
+
configuration provenance and reproduction commands corresponding to the verified
|
|
219
|
+
workflow. The package provides mesh-defined simulation domains, not smooth CAD
|
|
220
|
+
reconstruction or coupled FSI.
|
tpmslab-0.3.0/README.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# TPMS Lab
|
|
2
|
+
|
|
3
|
+
[English quick start](docs/QUICKSTART_EN.md) | [中文使用说明](docs/QUICKSTART_ZH.md)
|
|
4
|
+
|
|
5
|
+
An installable Python toolkit for graded TPMS-derived **solid and complementary pore-fluid volume meshes**.
|
|
6
|
+
Version 0.3.0. This repository is public. Source, tests, examples and versioned
|
|
7
|
+
reproducibility records are distributed together. Use an exact commit or the
|
|
8
|
+
`v0.3.0` tag, rather than a changing `main`, for reproducible work.
|
|
9
|
+
|
|
10
|
+
[Version and installation details](docs/VERSION_0.3.0.md) |
|
|
11
|
+
[GitHub releases](https://github.com/Slight1211/TPMSLab/releases)
|
|
12
|
+
|
|
13
|
+
A public source repository, a GitHub Release, a Zenodo archive and a PyPI upload
|
|
14
|
+
are separate records. Cite a DOI only after the archive is actually published.
|
|
15
|
+
No PyPI release has been made.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
Use Python 3.11 or newer. From this source directory:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
python -m pip install .
|
|
23
|
+
# Optional local browser interface
|
|
24
|
+
python -m pip install ".[web]"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Build a wheel locally with `python -m build` (requires the `build` package). The core does not require Flask, COMSOL, MATLAB,
|
|
28
|
+
OpenCascade, a CAD import licence or a graphics display. COMSOL model creation
|
|
29
|
+
and solving require a separate compatible COMSOL installation and licence.
|
|
30
|
+
|
|
31
|
+
## Python API
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from tpmslab import Config, generate, save_model
|
|
35
|
+
|
|
36
|
+
mesh = generate(Config(family="Gyroid", resolution=16,
|
|
37
|
+
density_start=0.25, density_end=0.50,
|
|
38
|
+
gradient="linear", quality_strategy="quality_fan"))
|
|
39
|
+
print(mesh["report"]["actual_density"])
|
|
40
|
+
save_model(mesh, "gyroid_result") # destination must not exist
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`generate` also accepts a dictionary. `list_families()` returns formula metadata.
|
|
44
|
+
Coordinates are millimetres; array connectivity is zero-based. The returned
|
|
45
|
+
mapping contains `points`, `tetra`, `boundary`, `boundary_ids`, `domains`,
|
|
46
|
+
`surface` (a trimesh object) and `report`. This API may change before
|
|
47
|
+
1.0. Configuration objects normalize sequence fields to immutable tuples.
|
|
48
|
+
|
|
49
|
+
## Command line
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
tpmslab init-config params.json
|
|
53
|
+
tpmslab generate --config params.json --out result
|
|
54
|
+
tpmslab families
|
|
55
|
+
tpmslab web --output local_models
|
|
56
|
+
# Requires licensed COMSOL on Windows:
|
|
57
|
+
tpmslab generate --config params.json --out solved_result --solve
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Export includes `mesh.nas` (CTETRA volume elements and labelled boundary
|
|
61
|
+
triangles), `mesh.npz`, `preview.stl`, parameters, diagnostics, environment and a
|
|
62
|
+
SHA-256 manifest. Existing output directories are rejected. A failed export
|
|
63
|
+
can leave a partial directory; choose a new destination after addressing the
|
|
64
|
+
error. STL is only a boundary preview. The optional bridge imports the volume
|
|
65
|
+
mesh, creates an MPH and reopens it to check the embedded element count.
|
|
66
|
+
Set `COMSOL_BIN` to the folder containing `comsolbatch.exe` and
|
|
67
|
+
`comsolcompile.exe` if automatic Windows detection fails.
|
|
68
|
+
|
|
69
|
+
## Method and limits
|
|
70
|
+
|
|
71
|
+
The library samples trigonometric level-set approximations, calibrates density
|
|
72
|
+
against a 56 cubed periodic-cell sample and clips a six-tetrahedra-per-voxel
|
|
73
|
+
background mesh. Sheet structures use two separate interpolated inequalities;
|
|
74
|
+
they do not have constant physical wall thickness. Shared intersections and
|
|
75
|
+
canonical face diagonals form a conforming tetrahedral volume mesh. Material
|
|
76
|
+
volume, boundary closure, face incidence and orientation are checked before
|
|
77
|
+
export. The result is a piecewise-planar solid domain, **not editable smooth
|
|
78
|
+
STEP/NURBS CAD**. Mesh generation can reject difficult parameter combinations.
|
|
79
|
+
|
|
80
|
+
`quality_fan` compares the original pulling fan with an interior-centroid fan
|
|
81
|
+
for poor cut cells and accepts only a better worst mean-ratio quality while
|
|
82
|
+
preserving boundary triangles and volume. This increases element count and can
|
|
83
|
+
reduce median quality. It provides no angle bound, global optimization or
|
|
84
|
+
finite-element convergence guarantee. `pulling` retains the baseline method.
|
|
85
|
+
|
|
86
|
+
There are 29 reference labels (27 distinct expressions, with aliases), eight
|
|
87
|
+
density profiles, sheet and two network modes, phase controls, and a restricted
|
|
88
|
+
custom-formula parser. Built-in formulas are adapted from LattGen; see
|
|
89
|
+
`THIRD_PARTY_NOTICES.md`. They are not claimed as new TPMS families or exact
|
|
90
|
+
minimal surfaces. Density targets are periodic-cell calibrations, not guaranteed
|
|
91
|
+
finite-specimen volume fractions. Current bounds: box domains, 1–6 cells per
|
|
92
|
+
axis, 8–64 samples per cell and at most 200,000 background voxels. The built-in
|
|
93
|
+
static demo is limited to 180,000 tetrahedra and connected material. Top/bottom
|
|
94
|
+
contact, constraints and convergence must be checked for a research model.
|
|
95
|
+
|
|
96
|
+
## Development and reproduction
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
python -m pip install ".[dev]"
|
|
100
|
+
python -m pytest
|
|
101
|
+
python -m ruff check src tests benchmarks
|
|
102
|
+
python -m build
|
|
103
|
+
python -m twine check dist/*
|
|
104
|
+
python benchmarks/run_benchmarks.py --out benchmark_results
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
See `docs/METHOD.md`, `docs/SOLID_FLUID.md` and `docs/VALIDATION.md`.
|
|
108
|
+
The CI matrix is configured for Windows/Linux and Python 3.11/3.12; configuring
|
|
109
|
+
CI does not mean those jobs have run. The measured local environment is Windows
|
|
110
|
+
and Python 3.12. Optional COMSOL validation is separate from the open test suite.
|
|
111
|
+
|
|
112
|
+
## Licence and attribution
|
|
113
|
+
|
|
114
|
+
MIT. See `LICENSE`, `THIRD_PARTY_NOTICES.md` and `licenses/` for the
|
|
115
|
+
package licence and third-party formula and browser-library notices.
|
|
116
|
+
|
|
117
|
+
## Solid and pore-fluid domains (0.3)
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from tpmslab import Config, generate, save_model
|
|
121
|
+
from tpmslab.comsol import build_mph
|
|
122
|
+
|
|
123
|
+
mesh = generate(Config(domain_mode="solid_fluid", family="Gyroid", resolution=12))
|
|
124
|
+
folder = save_model(mesh, "solid_fluid_gyroid")
|
|
125
|
+
# Optional, licensed COMSOL: verifies selections, each domain volume and saved mesh.
|
|
126
|
+
build_mph(folder, mesh["report"], solve=False)
|
|
127
|
+
# solve=True instead runs the fixed-wall pore-flow demonstration described below.
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
In the browser, select **固体 + 孔隙流体(共享界面)** under **计算域**.
|
|
131
|
+
The phase selector switches the preview between solid and pore fluid.
|
|
132
|
+
The default remains solid-only for compatibility. The JSON/CLI parameter is
|
|
133
|
+
`"domain_mode": "solid_fluid"`.
|
|
134
|
+
|
|
135
|
+
Both phases partition the same bounding box. They use shared cut-edge vertices
|
|
136
|
+
and identical interface triangles. For sheet structures the two complementary
|
|
137
|
+
inequalities are meshed separately, allowing disconnected labyrinths to remain
|
|
138
|
+
separate domains. Connectivity is determined by shared tetrahedron faces.
|
|
139
|
+
The combined mesh is checked for positive volumes, opposite adjacent-face
|
|
140
|
+
orientation, complete interface matching and total volume conservation.
|
|
141
|
+
|
|
142
|
+
`phase_ids` is one value per tetrahedron (1=solid, 2=fluid); `domains` identifies
|
|
143
|
+
individual connected domains. `interface` is oriented out of the solid.
|
|
144
|
+
`boundary` includes the outer boundary AND the solid-fluid interface once.
|
|
145
|
+
Additional arrays are `solid_boundary` and `fluid_boundary`. `surface` and
|
|
146
|
+
`preview.stl` continue to show the solid; `fluid_surface` and `fluid_preview.stl`
|
|
147
|
+
show the pore fluid. The NPZ retains all phase and boundary arrays. `domains.json`
|
|
148
|
+
records domain-to-phase and boundary-name mappings. Report `volume_mm3` remains
|
|
149
|
+
solid volume; `total_mesh_volume_mm3` includes both phases.
|
|
150
|
+
|
|
151
|
+
NASTRAN PSOLID property IDs are `100 + domain_id`. Boundary PIDs 2–7 are solid
|
|
152
|
+
xmin/xmax/ymin/ymax/zmin/zmax; 12–17 are the corresponding fluid faces; PID 8
|
|
153
|
+
is the shared interface. PIDs are NOT COMSOL entity numbers. The bridge resolves
|
|
154
|
+
imported PID selections and creates `solid_domains`, `fluid_domains`, individual
|
|
155
|
+
connected-domain selections, `solid_fluid_interface`, and the nonempty exterior
|
|
156
|
+
face selections. It assigns demonstration solid/fluid materials separately.
|
|
157
|
+
An unsolved export requires no CFD physics interface and is a starting point
|
|
158
|
+
for the user's physics setup.
|
|
159
|
+
|
|
160
|
+
For dual-domain models, `solve=True` runs stationary **creeping flow only in the
|
|
161
|
+
fluid**, with fixed no-slip solid walls, pressure 0.01 Pa at fluid_zmin and 0 Pa
|
|
162
|
+
at fluid_zmax, and no-slip on other fluid exterior faces. Density is 1000 kg/m³
|
|
163
|
+
and viscosity 0.001 Pa·s. Every fluid component must reach both Z faces; otherwise
|
|
164
|
+
the automatic demo is refused while unsolved export remains available. This
|
|
165
|
+
requires the corresponding COMSOL physics licence. It reports inlet/outlet
|
|
166
|
+
flow and relative imbalance (the smoke-test threshold is 5%, not an accuracy
|
|
167
|
+
claim). It is **not deformation-coupled FSI**, not conjugate heat transfer, and
|
|
168
|
+
not a validated permeability prediction. Boundary layers, external reservoirs,
|
|
169
|
+
mesh convergence and realistic boundary conditions remain user responsibilities.
|
|
170
|
+
See `docs/SOLID_FLUID.md` for validation and reproducibility.
|
|
171
|
+
|
|
172
|
+
## Solid–fluid quick start
|
|
173
|
+
|
|
174
|
+
Run [the Python example](examples/solid_fluid_api.py). Installation, exported
|
|
175
|
+
files and optional COMSOL calculations are documented in the
|
|
176
|
+
[English quick start](docs/QUICKSTART_EN.md) and
|
|
177
|
+
[中文使用说明](docs/QUICKSTART_ZH.md).
|
|
178
|
+
|
|
179
|
+
## Independent verification
|
|
180
|
+
|
|
181
|
+
See [Verification and reproducible studies](docs/VERIFICATION.md) for density realization, independent interface incidence and area audits, channel-wise COMSOL flux checks, and refinement/performance scripts. `quality_fan` is optional local worst-element mitigation, not a general quality or solver-speed guarantee.
|
|
182
|
+
|
|
183
|
+
## Reproducibility records
|
|
184
|
+
|
|
185
|
+
See [validation/README.md](validation/README.md) for the numerical records,
|
|
186
|
+
configuration provenance and reproduction commands corresponding to the verified
|
|
187
|
+
workflow. The package provides mesh-defined simulation domains, not smooth CAD
|
|
188
|
+
reconstruction or coupled FSI.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
The formula registry is adapted from Hilda Chris-Amadin and Osezua Ibhadode,
|
|
4
|
+
LattGen: A TPMS lattice generation tool, Software Impacts 21 (2024), 100665,
|
|
5
|
+
https://doi.org/10.1016/j.simpa.2024.100665.
|
|
6
|
+
Source: https://github.com/SoftwareImpacts/SIMPAC-2024-10 .
|
|
7
|
+
The repository MIT notice is preserved in licenses/LattGen-MIT.txt.
|
|
8
|
+
The 29 source labels include two duplicate-expression aliases; the paper's
|
|
9
|
+
reported family count should not be used to claim 29 distinct new families.
|
|
10
|
+
Reference functions are in docs/lattgen_reference.m where available.
|
|
11
|
+
|
|
12
|
+
Three.js r169 and OrbitControls are redistributed under MIT. Full notice:
|
|
13
|
+
src/tpmslab/static/vendor/THREE-LICENSE.txt. Source: https://github.com/mrdoob/three.js .
|
|
14
|
+
|
|
15
|
+
NumPy, SciPy, trimesh and optional Flask are dependencies installed separately;
|
|
16
|
+
their upstream licences remain applicable. COMSOL is proprietary software,
|
|
17
|
+
installed and licensed separately. No COMSOL executable is redistributed.
|
|
18
|
+
|
|
19
|
+
The direct cut-volume workflow was informed by the user's earlier TPMS cut-mesh
|
|
20
|
+
validation scripts. Provenance and contributor authorship require maintainer
|
|
21
|
+
review before public release. No novelty claim is made for clipping,
|
|
22
|
+
pulling triangulation, centroid fans or the supplied level-set functions.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Density realization and exact grid-aligned slab volumes for reference specimens."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from dataclasses import replace
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import numpy as np
|
|
8
|
+
from tpmslab import Config, generate
|
|
9
|
+
from tpmslab.model import raw_field
|
|
10
|
+
from tpmslab.verification import audit_interface
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def load_mesh(folder):
|
|
14
|
+
a = np.load(Path(folder) / "mesh.npz")
|
|
15
|
+
return dict(
|
|
16
|
+
points=a["points_mm"],
|
|
17
|
+
tetra=a["tetrahedra"],
|
|
18
|
+
phase_ids=a["phase_ids"],
|
|
19
|
+
interface=a["interface"],
|
|
20
|
+
domains=a["domain_ids"],
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def geometry_record(model, config):
|
|
25
|
+
p = model["points"][model["tetra"]]
|
|
26
|
+
v = (
|
|
27
|
+
np.abs(
|
|
28
|
+
np.einsum("ij,ij->i", p[:, 1] - p[:, 0], np.cross(p[:, 2] - p[:, 0], p[:, 3] - p[:, 0]))
|
|
29
|
+
)
|
|
30
|
+
/ 6
|
|
31
|
+
)
|
|
32
|
+
solid = model["phase_ids"] == 1
|
|
33
|
+
n = config.resolution * config.cells[2]
|
|
34
|
+
z = np.clip(np.floor(p[:, :, 2].mean(axis=1) / config.size[2] * n).astype(int), 0, n - 1)
|
|
35
|
+
bins = np.bincount(z[solid], weights=v[solid], minlength=n)
|
|
36
|
+
expected = (config.density_start + config.density_end) / 2
|
|
37
|
+
result = dict(
|
|
38
|
+
family=config.family,
|
|
39
|
+
resolution=config.resolution,
|
|
40
|
+
target_average=expected,
|
|
41
|
+
mesh_density=float(v[solid].sum() / np.prod(config.size)),
|
|
42
|
+
slab_z_mm=((np.arange(n) + 0.5) * config.size[2] / n).tolist(),
|
|
43
|
+
slab_density=(bins / (np.prod(config.size) / n)).tolist(),
|
|
44
|
+
audit=audit_interface(model),
|
|
45
|
+
)
|
|
46
|
+
result["relative_target_deviation"] = (result["mesh_density"] - expected) / expected
|
|
47
|
+
return result
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def field_reference(config, n):
|
|
51
|
+
# Independent midpoint integration of the unlinearized implicit field;
|
|
52
|
+
# it uses the same threshold calibration, not the tetrahedral mesh.
|
|
53
|
+
x = (np.arange(n) + 0.5) * config.size[0] / n
|
|
54
|
+
y = (np.arange(n) + 0.5) * config.size[1] / n
|
|
55
|
+
count = 0
|
|
56
|
+
for z in (np.arange(n) + 0.5) * config.size[2] / n:
|
|
57
|
+
count += np.count_nonzero(raw_field(config, x[:, None], y[None, :], z) >= 0)
|
|
58
|
+
return count / n**3
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def main():
|
|
62
|
+
p = argparse.ArgumentParser()
|
|
63
|
+
p.add_argument("--source", type=Path)
|
|
64
|
+
p.add_argument("--out", type=Path, required=True)
|
|
65
|
+
args = p.parse_args()
|
|
66
|
+
args.out.mkdir(parents=True, exist_ok=False)
|
|
67
|
+
records = []
|
|
68
|
+
for family in ["Gyroid", "Primitive Schwartz", "Diamond"]:
|
|
69
|
+
c = Config(family=family, domain_mode="solid_fluid", resolution=12)
|
|
70
|
+
model = load_mesh(args.source / family.replace(" ", "_")) if args.source else generate(c)
|
|
71
|
+
r = geometry_record(model, c)
|
|
72
|
+
r["implicit_midpoint_128"] = field_reference(c, 128)
|
|
73
|
+
r["implicit_midpoint_256"] = field_reference(c, 256)
|
|
74
|
+
records.append(r)
|
|
75
|
+
for lo, hi in [(0.125, 0.375), (0.375, 0.625)]:
|
|
76
|
+
cc = replace(c, density_start=lo, density_end=hi)
|
|
77
|
+
m = generate(cc)
|
|
78
|
+
records.append(geometry_record(m, cc))
|
|
79
|
+
print("DENSITY", family, flush=True)
|
|
80
|
+
(args.out / "density_results.json").write_text(json.dumps(records, indent=2), "utf8")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == "__main__":
|
|
84
|
+
main()
|