perifit 2.0.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.
- perifit/__init__.py +184 -0
- perifit/cli.py +289 -0
- perifit/config.py +87 -0
- perifit/core/__init__.py +90 -0
- perifit/core/local_system.py +218 -0
- perifit/core/local_system_2d.py +149 -0
- perifit/core/moments.py +84 -0
- perifit/core/moments_2d.py +77 -0
- perifit/core/targets.py +122 -0
- perifit/core/targets_2d.py +78 -0
- perifit/core/weights.py +157 -0
- perifit/core/weights_2d.py +120 -0
- perifit/data/__init__.py +0 -0
- perifit/data/test_mesh_cube_1000.csv +1003 -0
- perifit/io/__init__.py +0 -0
- perifit/io/writers.py +533 -0
- perifit/mesh/__init__.py +0 -0
- perifit/mesh/readers.py +399 -0
- perifit/quality/__init__.py +2 -0
- perifit/quality/cleaning.py +58 -0
- perifit/quality/diagnostics.py +67 -0
- perifit-2.0.0.dist-info/METADATA +292 -0
- perifit-2.0.0.dist-info/RECORD +26 -0
- perifit-2.0.0.dist-info/WHEEL +5 -0
- perifit-2.0.0.dist-info/entry_points.txt +2 -0
- perifit-2.0.0.dist-info/top_level.txt +1 -0
perifit/__init__.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"""
|
|
2
|
+
perifit -- Peridynamic surface correction via optimised nodal influence weights.
|
|
3
|
+
==============================================================================
|
|
4
|
+
|
|
5
|
+
Authors: Arman Shojaei & Alexander Hermann
|
|
6
|
+
Institute of Material Systems Modeling,
|
|
7
|
+
Helmholtz-Zentrum Hereon, Geesthacht, Germany.
|
|
8
|
+
|
|
9
|
+
Purpose
|
|
10
|
+
-------
|
|
11
|
+
Compute per-node scalar influence weights w_i that restore derivative and
|
|
12
|
+
energy consistency of the discrete PD operators near free surfaces, cracks,
|
|
13
|
+
and voids. Each bond (i, j) is then scaled by the symmetric factor
|
|
14
|
+
(w_i + w_j) / 2, preserving pairwise reciprocity and global stiffness symmetry.
|
|
15
|
+
|
|
16
|
+
Supported models (3-D):
|
|
17
|
+
- "bb" : Bond-Based PD (PMB / linearised BB), kernel exponent q = 3
|
|
18
|
+
- "osb" : Ordinary State-Based PD (LPS), kernel exponent q = 2
|
|
19
|
+
|
|
20
|
+
Supported models (2-D):
|
|
21
|
+
- BB-PD via compute_weights_2d
|
|
22
|
+
|
|
23
|
+
Usage
|
|
24
|
+
-----
|
|
25
|
+
import perifit
|
|
26
|
+
|
|
27
|
+
# 1. Build neighbour families (or supply your own)
|
|
28
|
+
families = perifit.build_families(coords, horizon)
|
|
29
|
+
|
|
30
|
+
# 2. Compute weights (one-shot, load-independent)
|
|
31
|
+
w = perifit.compute_weights(coords, volumes, horizon,
|
|
32
|
+
model="bb", families=families)
|
|
33
|
+
|
|
34
|
+
# 3. Apply in solver: bond weight = (w[i] + w[j]) / 2
|
|
35
|
+
|
|
36
|
+
Input:
|
|
37
|
+
coords -- (N, 3) array of nodal coordinates
|
|
38
|
+
volumes -- (N,) array of cell volumes
|
|
39
|
+
horizon -- scalar, peridynamic horizon delta
|
|
40
|
+
|
|
41
|
+
Output:
|
|
42
|
+
w -- (N,) array of nodal influence weights
|
|
43
|
+
|
|
44
|
+
The weights are purely geometric: material constants (micro-modulus c,
|
|
45
|
+
LPS parameters a, b) cancel after per-row normalisation and need not be
|
|
46
|
+
specified.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
# ---------------------------------------------------------------------------
|
|
50
|
+
# 3-D public API
|
|
51
|
+
# ---------------------------------------------------------------------------
|
|
52
|
+
from .core.moments import (
|
|
53
|
+
ball_moment,
|
|
54
|
+
ball_moment_over_r2,
|
|
55
|
+
ball_moment_over_r3,
|
|
56
|
+
full_ball_volume,
|
|
57
|
+
full_ball_weighted_volume,
|
|
58
|
+
full_ball_shape_tensor_diag,
|
|
59
|
+
)
|
|
60
|
+
from .core.targets import (
|
|
61
|
+
build_targets_bb,
|
|
62
|
+
build_targets_osb,
|
|
63
|
+
build_targets_nosb,
|
|
64
|
+
)
|
|
65
|
+
from .core.local_system import (
|
|
66
|
+
build_local_system_bb,
|
|
67
|
+
build_local_system_osb,
|
|
68
|
+
build_local_system_nosb,
|
|
69
|
+
)
|
|
70
|
+
from .core.weights import compute_weights, build_families
|
|
71
|
+
|
|
72
|
+
# ---------------------------------------------------------------------------
|
|
73
|
+
# 2-D public API
|
|
74
|
+
# ---------------------------------------------------------------------------
|
|
75
|
+
from .core.moments_2d import (
|
|
76
|
+
disc_moment,
|
|
77
|
+
disc_moment_over_r2,
|
|
78
|
+
disc_moment_over_r3,
|
|
79
|
+
full_disc_area,
|
|
80
|
+
full_disc_weighted_volume,
|
|
81
|
+
full_disc_shape_tensor_diag,
|
|
82
|
+
)
|
|
83
|
+
from .core.targets_2d import build_targets_bb_2d
|
|
84
|
+
from .core.local_system_2d import build_local_system_bb_2d
|
|
85
|
+
from .core.weights_2d import compute_weights_2d, build_families_2d
|
|
86
|
+
|
|
87
|
+
# ---------------------------------------------------------------------------
|
|
88
|
+
# Existing package modules (mesh I/O, quality diagnostics, etc.)
|
|
89
|
+
# ---------------------------------------------------------------------------
|
|
90
|
+
from .mesh.readers import load_mesh
|
|
91
|
+
from .io.writers import write_weights
|
|
92
|
+
from .config import CorrectionConfig
|
|
93
|
+
from .quality.diagnostics import diagnose_weights, WeightDiagnostics
|
|
94
|
+
from .quality.cleaning import clean_mesh, CleaningResult
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def get_example_mesh() -> "pathlib.Path":
|
|
98
|
+
"""
|
|
99
|
+
Return the path to the bundled test mesh file.
|
|
100
|
+
|
|
101
|
+
The file is a structured Cartesian cube [0,1]^3 with 1000 nodes
|
|
102
|
+
(10x10x10, dx=0.1). Recommended horizon: delta=0.3 (m=3).
|
|
103
|
+
|
|
104
|
+
Example
|
|
105
|
+
-------
|
|
106
|
+
>>> from perifit import get_example_mesh, load_mesh, compute_weights
|
|
107
|
+
>>> coords, volumes = load_mesh(get_example_mesh())
|
|
108
|
+
>>> weights = compute_weights(coords, volumes, 0.3, model="bb")
|
|
109
|
+
"""
|
|
110
|
+
import pathlib
|
|
111
|
+
return pathlib.Path(__file__).parent / "data" / "test_mesh_cube_1000.csv"
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# ---------------------------------------------------------------------------
|
|
115
|
+
# Branding
|
|
116
|
+
# ---------------------------------------------------------------------------
|
|
117
|
+
|
|
118
|
+
_LOGO = r"""
|
|
119
|
+
____ _ _____ _ _
|
|
120
|
+
| _ \ ___ _ __(_) ___(_) |_
|
|
121
|
+
| |_) / _ \ '__| | |_ | | __|
|
|
122
|
+
| __/ __/ | | | _| | | |_
|
|
123
|
+
|_| \___|_| |_|_| |_|\__|
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def show_version() -> None:
|
|
128
|
+
"""Print the perifit version banner with ASCII logo and credits."""
|
|
129
|
+
print(_LOGO.lstrip("\n"))
|
|
130
|
+
print(f"perifit v{__version__}")
|
|
131
|
+
print("Peridynamic Surface Correction via Optimised Nodal Influence Weights")
|
|
132
|
+
print()
|
|
133
|
+
print("Developers: Arman Shojaei & Alexander Hermann")
|
|
134
|
+
print(" Helmholtz-Zentrum Hereon, Germany")
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# ---------------------------------------------------------------------------
|
|
138
|
+
# Exports
|
|
139
|
+
# ---------------------------------------------------------------------------
|
|
140
|
+
|
|
141
|
+
__all__ = [
|
|
142
|
+
# Main 3-D API
|
|
143
|
+
"compute_weights",
|
|
144
|
+
"build_families",
|
|
145
|
+
# 3-D targets
|
|
146
|
+
"build_targets_bb",
|
|
147
|
+
"build_targets_osb",
|
|
148
|
+
"build_targets_nosb",
|
|
149
|
+
# 3-D local systems
|
|
150
|
+
"build_local_system_bb",
|
|
151
|
+
"build_local_system_osb",
|
|
152
|
+
"build_local_system_nosb",
|
|
153
|
+
# 3-D moment utilities
|
|
154
|
+
"ball_moment",
|
|
155
|
+
"ball_moment_over_r2",
|
|
156
|
+
"ball_moment_over_r3",
|
|
157
|
+
"full_ball_volume",
|
|
158
|
+
"full_ball_weighted_volume",
|
|
159
|
+
"full_ball_shape_tensor_diag",
|
|
160
|
+
# 2-D API
|
|
161
|
+
"compute_weights_2d",
|
|
162
|
+
"build_families_2d",
|
|
163
|
+
"build_targets_bb_2d",
|
|
164
|
+
"build_local_system_bb_2d",
|
|
165
|
+
"disc_moment",
|
|
166
|
+
"disc_moment_over_r2",
|
|
167
|
+
"disc_moment_over_r3",
|
|
168
|
+
"full_disc_area",
|
|
169
|
+
"full_disc_weighted_volume",
|
|
170
|
+
"full_disc_shape_tensor_diag",
|
|
171
|
+
# I/O and utilities
|
|
172
|
+
"load_mesh",
|
|
173
|
+
"write_weights",
|
|
174
|
+
"get_example_mesh",
|
|
175
|
+
"CorrectionConfig",
|
|
176
|
+
"diagnose_weights",
|
|
177
|
+
"WeightDiagnostics",
|
|
178
|
+
"clean_mesh",
|
|
179
|
+
"CleaningResult",
|
|
180
|
+
# Branding
|
|
181
|
+
"show_version",
|
|
182
|
+
]
|
|
183
|
+
|
|
184
|
+
__version__ = "2.0.0"
|
perifit/cli.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Command-line interface for perifit.
|
|
3
|
+
|
|
4
|
+
Usage
|
|
5
|
+
-----
|
|
6
|
+
# Minimal: auto-infer dx and horizon (m=3 default)
|
|
7
|
+
perifit --mesh cube.csv
|
|
8
|
+
|
|
9
|
+
# Explicit horizon-to-spacing ratio
|
|
10
|
+
perifit --mesh cube.csv --m 4
|
|
11
|
+
|
|
12
|
+
# Explicit horizon
|
|
13
|
+
perifit --mesh cube.csv --horizon 0.06 --output csv,vtk
|
|
14
|
+
|
|
15
|
+
# Bond-based PD model
|
|
16
|
+
perifit --mesh cube.csv --model bb
|
|
17
|
+
|
|
18
|
+
# Exodus mesh for Peridigm
|
|
19
|
+
perifit --mesh solid.exo --output peridigm --outdir ./peridigm_run
|
|
20
|
+
|
|
21
|
+
# Diagnose mesh quality
|
|
22
|
+
perifit --mesh cube.csv --diagnose
|
|
23
|
+
|
|
24
|
+
# Clean mesh (remove flagged nodes)
|
|
25
|
+
perifit --mesh cube.csv --clean --threshold-sigma 2.0
|
|
26
|
+
|
|
27
|
+
# Built-in demo (no mesh needed)
|
|
28
|
+
perifit --demo
|
|
29
|
+
|
|
30
|
+
perifit --help
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
from __future__ import annotations
|
|
34
|
+
|
|
35
|
+
import argparse
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Map CLI model names to the core API model codes
|
|
39
|
+
_MODEL_MAP = {
|
|
40
|
+
'bb': 'bb',
|
|
41
|
+
'osb': 'osb',
|
|
42
|
+
'bb_pd': 'bb',
|
|
43
|
+
'osb_pd': 'osb',
|
|
44
|
+
'bond_based': 'bb',
|
|
45
|
+
'state_based': 'osb',
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _infer_dx(coords):
|
|
50
|
+
"""Estimate nodal spacing as the median nearest-neighbour distance."""
|
|
51
|
+
from scipy.spatial import KDTree
|
|
52
|
+
import numpy as np
|
|
53
|
+
tree = KDTree(coords)
|
|
54
|
+
dists, _ = tree.query(coords, k=2)
|
|
55
|
+
return float(np.median(dists[:, 1]))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
59
|
+
p = argparse.ArgumentParser(
|
|
60
|
+
prog='perifit',
|
|
61
|
+
description=(
|
|
62
|
+
'Compute peridynamic surface correction weights for any 3-D mesh '
|
|
63
|
+
'and export to CSV, DAT, VTK, Peridigm, or PeriLab format.\n\n'
|
|
64
|
+
'Supports bond-based (BB) and ordinary state-based (OSB) PD models.\n\n'
|
|
65
|
+
'Nodal spacing (dx) and volumes are inferred automatically from '
|
|
66
|
+
'the median nearest-neighbour distance (assumes a regular grid). '
|
|
67
|
+
'The horizon is delta = m * dx when --horizon is not given.'
|
|
68
|
+
),
|
|
69
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
70
|
+
epilog="""
|
|
71
|
+
Examples
|
|
72
|
+
--------
|
|
73
|
+
# Minimal -- auto-infer everything (m=3 default)
|
|
74
|
+
perifit --mesh cube.csv
|
|
75
|
+
|
|
76
|
+
# Bond-based PD
|
|
77
|
+
perifit --mesh cube.csv --model bb
|
|
78
|
+
|
|
79
|
+
# Specify horizon-to-spacing ratio
|
|
80
|
+
perifit --mesh cube.csv --m-ratio 4 --output csv,vtk
|
|
81
|
+
|
|
82
|
+
# Provide explicit horizon
|
|
83
|
+
perifit --mesh solid.exo --horizon 0.005 --output peridigm
|
|
84
|
+
|
|
85
|
+
# Gmsh mesh (requires meshio) for PeriLab
|
|
86
|
+
perifit --mesh part.msh --output perilab,csv --stem part_weights
|
|
87
|
+
|
|
88
|
+
# Diagnose mesh quality after computing weights
|
|
89
|
+
perifit --mesh cube.csv --diagnose
|
|
90
|
+
|
|
91
|
+
# Clean mesh (remove negative/outlier weight nodes)
|
|
92
|
+
perifit --mesh cube.csv --clean --threshold-sigma 2.0
|
|
93
|
+
|
|
94
|
+
# Built-in 1000-node cube demo
|
|
95
|
+
perifit --demo
|
|
96
|
+
""",
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
# Input
|
|
100
|
+
p.add_argument('--mesh', required=False, default=None,
|
|
101
|
+
help='Path to the mesh file. Supported extensions: '
|
|
102
|
+
'.csv, .dat, .txt, .npy, .npz, .vtk, .vtu, '
|
|
103
|
+
'.exo, .g, .msh, .inp')
|
|
104
|
+
|
|
105
|
+
# Model selection
|
|
106
|
+
p.add_argument('--model', default='osb',
|
|
107
|
+
choices=['osb', 'bb', 'osb_pd', 'bb_pd',
|
|
108
|
+
'state_based', 'bond_based'],
|
|
109
|
+
help='PD model: osb (LPS/state-based), bb (bond-based). '
|
|
110
|
+
'Legacy aliases: osb_pd, bb_pd, state_based, bond_based. '
|
|
111
|
+
'Default: osb.')
|
|
112
|
+
|
|
113
|
+
# Horizon / discretisation
|
|
114
|
+
g = p.add_argument_group('horizon / discretisation')
|
|
115
|
+
g.add_argument('--horizon', type=float, default=None,
|
|
116
|
+
help='Peridynamic horizon radius delta. '
|
|
117
|
+
'Auto-computed as m*dx when not given.')
|
|
118
|
+
g.add_argument('--m-ratio', type=float, default=3.0, dest='m_ratio',
|
|
119
|
+
help='Horizon-to-spacing ratio m = delta/dx. '
|
|
120
|
+
'Used only when --horizon is not given. Default: 3.')
|
|
121
|
+
|
|
122
|
+
# Column overrides for text-based meshes
|
|
123
|
+
g2 = p.add_argument_group('text-format column mapping (CSV/DAT/TXT only)')
|
|
124
|
+
g2.add_argument('--x-col', type=int, default=0,
|
|
125
|
+
help='Column index for x coordinate (default: 0).')
|
|
126
|
+
g2.add_argument('--y-col', type=int, default=1,
|
|
127
|
+
help='Column index for y coordinate (default: 1).')
|
|
128
|
+
g2.add_argument('--z-col', type=int, default=2,
|
|
129
|
+
help='Column index for z coordinate (default: 2).')
|
|
130
|
+
g2.add_argument('--delimiter', default=None,
|
|
131
|
+
help='Field delimiter for text files (default: auto).')
|
|
132
|
+
g2.add_argument('--comment', default='#',
|
|
133
|
+
help='Comment character for text files (default: #).')
|
|
134
|
+
|
|
135
|
+
# Output
|
|
136
|
+
g3 = p.add_argument_group('output')
|
|
137
|
+
g3.add_argument('--output', default='csv',
|
|
138
|
+
help='Comma-separated list of output formats: '
|
|
139
|
+
'csv, dat, vtk, peridigm, perilab (default: csv).')
|
|
140
|
+
g3.add_argument('--outdir', default='./perifit_output',
|
|
141
|
+
help='Output directory (created if needed).')
|
|
142
|
+
g3.add_argument('--stem', default='perifit_weights',
|
|
143
|
+
help='Base filename stem (without extension).')
|
|
144
|
+
|
|
145
|
+
# Solver
|
|
146
|
+
g4 = p.add_argument_group('solver')
|
|
147
|
+
g4.add_argument('--tol', type=float, default=1e-10,
|
|
148
|
+
help='BiCGSTAB relative tolerance (default: 1e-10).')
|
|
149
|
+
g4.add_argument('--max-iter', type=int, default=5000,
|
|
150
|
+
help='Maximum BiCGSTAB iterations (default: 5000).')
|
|
151
|
+
|
|
152
|
+
# Quality / cleaning
|
|
153
|
+
g5 = p.add_argument_group('mesh quality')
|
|
154
|
+
g5.add_argument('--diagnose', action='store_true',
|
|
155
|
+
help='Print weight diagnostics (negative/outlier detection).')
|
|
156
|
+
g5.add_argument('--clean', action='store_true',
|
|
157
|
+
help='Remove flagged nodes and output a cleaned mesh.')
|
|
158
|
+
g5.add_argument('--threshold-sigma', type=float, default=2.0,
|
|
159
|
+
dest='threshold_sigma',
|
|
160
|
+
help='Outlier detection threshold in standard deviations '
|
|
161
|
+
'(default: 2.0).')
|
|
162
|
+
|
|
163
|
+
p.add_argument('--quiet', action='store_true',
|
|
164
|
+
help='Suppress progress output.')
|
|
165
|
+
|
|
166
|
+
p.add_argument('--demo', action='store_true',
|
|
167
|
+
help='Run a self-contained demo on the bundled 1000-node '
|
|
168
|
+
'cube mesh and exit. No other arguments needed.')
|
|
169
|
+
|
|
170
|
+
p.add_argument('--version', action='store_true',
|
|
171
|
+
help='Print the version banner and exit.')
|
|
172
|
+
|
|
173
|
+
return p
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def main(argv=None):
|
|
177
|
+
import numpy as np
|
|
178
|
+
|
|
179
|
+
parser = _build_parser()
|
|
180
|
+
args = parser.parse_args(argv)
|
|
181
|
+
|
|
182
|
+
from perifit import load_mesh, write_weights, get_example_mesh
|
|
183
|
+
from perifit.core.weights import compute_weights, build_families
|
|
184
|
+
|
|
185
|
+
# Resolve model name to core API code
|
|
186
|
+
model = _MODEL_MAP.get(args.model, args.model)
|
|
187
|
+
|
|
188
|
+
# --- Version mode ---
|
|
189
|
+
if args.version:
|
|
190
|
+
from perifit import show_version
|
|
191
|
+
show_version()
|
|
192
|
+
return
|
|
193
|
+
|
|
194
|
+
# --- Demo mode ---
|
|
195
|
+
if args.demo:
|
|
196
|
+
model_label = 'BB-PD' if model == 'bb' else 'OSB-PD'
|
|
197
|
+
print("=" * 60)
|
|
198
|
+
print("perifit -- built-in demo (1000-node cube)")
|
|
199
|
+
print(" Mesh : structured [0,1]^3, dx=0.1, 1000 nodes")
|
|
200
|
+
print(" Horizon: delta = 0.30 (m = 3, auto-inferred)")
|
|
201
|
+
print(f" Model : {model_label}")
|
|
202
|
+
print("=" * 60)
|
|
203
|
+
mesh_path = get_example_mesh()
|
|
204
|
+
coords, volumes = load_mesh(mesh_path)
|
|
205
|
+
dx = _infer_dx(coords)
|
|
206
|
+
horizon = args.m_ratio * dx
|
|
207
|
+
weights = compute_weights(coords, volumes, horizon,
|
|
208
|
+
model=model, verbose=not args.quiet)
|
|
209
|
+
outdir = args.outdir
|
|
210
|
+
paths = write_weights(
|
|
211
|
+
coords, volumes, weights,
|
|
212
|
+
outdir=outdir,
|
|
213
|
+
stem="demo_cube",
|
|
214
|
+
formats=["csv", "dat", "vtk"],
|
|
215
|
+
)
|
|
216
|
+
print("\nOutput files:")
|
|
217
|
+
for fmt, path in paths.items():
|
|
218
|
+
print(f" [{fmt:6s}] {path}")
|
|
219
|
+
print(f"\nOpen {outdir}/demo_cube.vtk in ParaView to visualise the weights.")
|
|
220
|
+
return
|
|
221
|
+
|
|
222
|
+
if args.mesh is None:
|
|
223
|
+
parser.error("--mesh is required (or use --demo for the built-in example)")
|
|
224
|
+
|
|
225
|
+
# --- Load mesh ---
|
|
226
|
+
print(f"Loading mesh: {args.mesh}")
|
|
227
|
+
coords, volumes = load_mesh(
|
|
228
|
+
args.mesh,
|
|
229
|
+
x_col=args.x_col,
|
|
230
|
+
y_col=args.y_col,
|
|
231
|
+
z_col=args.z_col,
|
|
232
|
+
delimiter=args.delimiter,
|
|
233
|
+
comment=args.comment,
|
|
234
|
+
horizon=args.horizon,
|
|
235
|
+
)
|
|
236
|
+
print(f" {len(coords):,d} nodes loaded.")
|
|
237
|
+
|
|
238
|
+
# --- Infer horizon if not given ---
|
|
239
|
+
if args.horizon is not None:
|
|
240
|
+
horizon = args.horizon
|
|
241
|
+
else:
|
|
242
|
+
dx = _infer_dx(coords)
|
|
243
|
+
horizon = args.m_ratio * dx
|
|
244
|
+
if not args.quiet:
|
|
245
|
+
print(f" Auto-inferred dx={dx:.4g}, horizon={horizon:.4g} (m={args.m_ratio})")
|
|
246
|
+
|
|
247
|
+
# --- Compute weights ---
|
|
248
|
+
weights = compute_weights(
|
|
249
|
+
coords, volumes, horizon,
|
|
250
|
+
model=model,
|
|
251
|
+
tol=args.tol,
|
|
252
|
+
max_iter=args.max_iter,
|
|
253
|
+
verbose=not args.quiet,
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
# --- Diagnose ---
|
|
257
|
+
if args.diagnose:
|
|
258
|
+
from perifit.quality.diagnostics import diagnose_weights
|
|
259
|
+
diag = diagnose_weights(weights, threshold_sigma=args.threshold_sigma)
|
|
260
|
+
print(f"\n{diag.summary}")
|
|
261
|
+
|
|
262
|
+
# --- Clean ---
|
|
263
|
+
if args.clean:
|
|
264
|
+
from perifit.quality.cleaning import clean_mesh
|
|
265
|
+
result = clean_mesh(coords, volumes, weights,
|
|
266
|
+
threshold_sigma=args.threshold_sigma)
|
|
267
|
+
print(f"\nCleaning: {result.original_n} -> {result.cleaned_n} nodes "
|
|
268
|
+
f"({result.original_n - result.cleaned_n} removed)")
|
|
269
|
+
coords = result.coords
|
|
270
|
+
volumes = result.volumes
|
|
271
|
+
weights = result.weights
|
|
272
|
+
|
|
273
|
+
# --- Write output ---
|
|
274
|
+
formats = [f.strip() for f in args.output.split(',')]
|
|
275
|
+
paths = write_weights(
|
|
276
|
+
coords, volumes, weights,
|
|
277
|
+
outdir=args.outdir,
|
|
278
|
+
stem=args.stem,
|
|
279
|
+
formats=formats,
|
|
280
|
+
horizon=weights.mean(), # informational only
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
print("\nOutput files:")
|
|
284
|
+
for fmt, path in paths.items():
|
|
285
|
+
print(f" [{fmt:10s}] {path}")
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
if __name__ == '__main__':
|
|
289
|
+
main()
|
perifit/config.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Configuration dataclass for the peridynamic surface correction computation.
|
|
3
|
+
|
|
4
|
+
This consolidates all tunable parameters in one place and provides
|
|
5
|
+
human-readable defaults with brief explanations.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from typing import List, Optional
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class CorrectionConfig:
|
|
16
|
+
"""
|
|
17
|
+
All parameters for a peridynamic surface correction run.
|
|
18
|
+
|
|
19
|
+
Note: The correction weights are purely geometric — independent of
|
|
20
|
+
material constants E and nu. Only the mesh geometry and horizon
|
|
21
|
+
(or equivalently, the horizon-to-spacing ratio m) are needed.
|
|
22
|
+
|
|
23
|
+
Model
|
|
24
|
+
-----
|
|
25
|
+
model : PD model type: 'state_based' (LPS, 109 operators) or
|
|
26
|
+
'bond_based' (54 operators). Default: 'state_based'.
|
|
27
|
+
|
|
28
|
+
Discretisation
|
|
29
|
+
---------------
|
|
30
|
+
horizon : Peridynamic horizon radius delta. If None, it is
|
|
31
|
+
computed as m_ratio * dx where dx is the inferred
|
|
32
|
+
median nearest-neighbour nodal spacing.
|
|
33
|
+
m_ratio : Horizon-to-spacing ratio m = delta / dx. Default: 3.
|
|
34
|
+
Used only when horizon is None.
|
|
35
|
+
|
|
36
|
+
Solver parameters
|
|
37
|
+
-----------------
|
|
38
|
+
tol : Relative residual tolerance for the global BiCGSTAB solve.
|
|
39
|
+
max_iter : Maximum BiCGSTAB iterations.
|
|
40
|
+
|
|
41
|
+
Regularisation (local pseudoinverse)
|
|
42
|
+
------------------------------------
|
|
43
|
+
tikhonov_rel : Regularisation factor relative to max(diag(M^T M)).
|
|
44
|
+
tikhonov_abs : Absolute floor for the regularisation parameter.
|
|
45
|
+
|
|
46
|
+
Output
|
|
47
|
+
------
|
|
48
|
+
formats : List of output format strings. Supported: 'csv', 'dat',
|
|
49
|
+
'vtk', 'peridigm', 'perilab'.
|
|
50
|
+
outdir : Directory where output files are written.
|
|
51
|
+
stem : Base filename stem (without extension).
|
|
52
|
+
|
|
53
|
+
Miscellaneous
|
|
54
|
+
-------------
|
|
55
|
+
verbose : Print progress information.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
# Model
|
|
59
|
+
model: str = 'state_based'
|
|
60
|
+
|
|
61
|
+
# Discretisation
|
|
62
|
+
horizon: float | None = None
|
|
63
|
+
m_ratio: float = 3.0
|
|
64
|
+
|
|
65
|
+
# Solver
|
|
66
|
+
tol: float = 1e-10
|
|
67
|
+
max_iter: int = 1000
|
|
68
|
+
|
|
69
|
+
# Regularisation
|
|
70
|
+
tikhonov_rel: float = 1.0e-8
|
|
71
|
+
tikhonov_abs: float = 1.0e-12
|
|
72
|
+
|
|
73
|
+
# Output
|
|
74
|
+
formats: List[str] = field(default_factory=lambda: ['csv'])
|
|
75
|
+
outdir: str = './perifit_output'
|
|
76
|
+
stem: str = 'perifit_weights'
|
|
77
|
+
|
|
78
|
+
# Misc
|
|
79
|
+
verbose: bool = True
|
|
80
|
+
|
|
81
|
+
def __post_init__(self):
|
|
82
|
+
if self.horizon is not None and self.horizon <= 0.0:
|
|
83
|
+
raise ValueError(f"Horizon delta={self.horizon} must be positive.")
|
|
84
|
+
if self.m_ratio <= 0.0:
|
|
85
|
+
raise ValueError(f"m_ratio={self.m_ratio} must be positive.")
|
|
86
|
+
if self.model not in ('state_based', 'bond_based'):
|
|
87
|
+
raise ValueError(f"model={self.model!r} must be 'state_based' or 'bond_based'.")
|
perifit/core/__init__.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""
|
|
2
|
+
perifit.core -- Core computation modules for peridynamic surface correction.
|
|
3
|
+
|
|
4
|
+
3-D modules:
|
|
5
|
+
moments, targets, local_system, weights
|
|
6
|
+
|
|
7
|
+
2-D modules:
|
|
8
|
+
moments_2d, targets_2d, local_system_2d, weights_2d
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
# 3-D moments
|
|
12
|
+
from .moments import (
|
|
13
|
+
ball_moment,
|
|
14
|
+
ball_moment_over_r2,
|
|
15
|
+
ball_moment_over_r3,
|
|
16
|
+
full_ball_volume,
|
|
17
|
+
full_ball_weighted_volume,
|
|
18
|
+
full_ball_shape_tensor_diag,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
# 3-D targets
|
|
22
|
+
from .targets import (
|
|
23
|
+
build_targets_bb,
|
|
24
|
+
build_targets_osb,
|
|
25
|
+
build_targets_nosb,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
# 3-D local systems
|
|
29
|
+
from .local_system import (
|
|
30
|
+
build_local_system_bb,
|
|
31
|
+
build_local_system_osb,
|
|
32
|
+
build_local_system_nosb,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
# 3-D weights (public API)
|
|
36
|
+
from .weights import compute_weights, build_families
|
|
37
|
+
|
|
38
|
+
# 2-D moments
|
|
39
|
+
from .moments_2d import (
|
|
40
|
+
disc_moment,
|
|
41
|
+
disc_moment_over_r2,
|
|
42
|
+
disc_moment_over_r3,
|
|
43
|
+
full_disc_area,
|
|
44
|
+
full_disc_weighted_volume,
|
|
45
|
+
full_disc_shape_tensor_diag,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# 2-D targets
|
|
49
|
+
from .targets_2d import build_targets_bb_2d
|
|
50
|
+
|
|
51
|
+
# 2-D local systems
|
|
52
|
+
from .local_system_2d import build_local_system_bb_2d
|
|
53
|
+
|
|
54
|
+
# 2-D weights
|
|
55
|
+
from .weights_2d import compute_weights_2d, build_families_2d
|
|
56
|
+
|
|
57
|
+
__all__ = [
|
|
58
|
+
# 3-D main API
|
|
59
|
+
"compute_weights",
|
|
60
|
+
"build_families",
|
|
61
|
+
# 3-D targets
|
|
62
|
+
"build_targets_bb",
|
|
63
|
+
"build_targets_osb",
|
|
64
|
+
"build_targets_nosb",
|
|
65
|
+
# 3-D local systems
|
|
66
|
+
"build_local_system_bb",
|
|
67
|
+
"build_local_system_osb",
|
|
68
|
+
"build_local_system_nosb",
|
|
69
|
+
# 3-D moments
|
|
70
|
+
"ball_moment",
|
|
71
|
+
"ball_moment_over_r2",
|
|
72
|
+
"ball_moment_over_r3",
|
|
73
|
+
"full_ball_volume",
|
|
74
|
+
"full_ball_weighted_volume",
|
|
75
|
+
"full_ball_shape_tensor_diag",
|
|
76
|
+
# 2-D main API
|
|
77
|
+
"compute_weights_2d",
|
|
78
|
+
"build_families_2d",
|
|
79
|
+
# 2-D targets
|
|
80
|
+
"build_targets_bb_2d",
|
|
81
|
+
# 2-D local systems
|
|
82
|
+
"build_local_system_bb_2d",
|
|
83
|
+
# 2-D moments
|
|
84
|
+
"disc_moment",
|
|
85
|
+
"disc_moment_over_r2",
|
|
86
|
+
"disc_moment_over_r3",
|
|
87
|
+
"full_disc_area",
|
|
88
|
+
"full_disc_weighted_volume",
|
|
89
|
+
"full_disc_shape_tensor_diag",
|
|
90
|
+
]
|