runmat-meshing-core 0.6.0

Deterministic meshing preparation contracts for RunMat
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
use super::*;
use crate::contracts::AnalysisMeshArtifact;
use fixtures::*;

#[test]
fn rejects_solid_mesh_without_plc_input_evidence() {
    let mut mesh = valid_tetrahedron_mesh();
    mesh.backend.backend = "solid".to_string();
    mesh.backend.algorithm = "plc_tetrahedron/v1".to_string();

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("solid Tetrahedron artifacts must prove PLC input evidence");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "missing_plc_nodes".to_string(),
        }
    );
    assert_eq!(
        analysis_mesh_validation_error_code(&err),
        "missing_plc_input_evidence"
    );
}

#[test]
fn accepts_solid_mesh_with_classified_plc_input_evidence() {
    let mesh = solid_tetrahedron_mesh_with_plc_input_evidence();

    validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect("classified PLC input evidence should satisfy solid validation");
}

#[test]
fn rejects_solid_mesh_without_plc_surface_boundary_node_evidence() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.plc_input_surface_boundary_node_count = 0;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("solid PLC-fed meshes must expose consumed surface boundary nodes");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "missing_plc_surface_boundary_nodes".to_string(),
        }
    );
}

#[test]
fn rejects_solid_mesh_with_inconsistent_plc_surface_boundary_node_evidence() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.plc_input_surface_boundary_node_count = mesh.backend.plc_input_node_count + 1;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("surface boundary node evidence must be bounded by PLC node count");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "inconsistent_plc_surface_boundary_nodes".to_string(),
        }
    );
}

#[test]
fn accepts_solid_mesh_with_nested_shell_generation_evidence() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    configure_nested_shell_generation_evidence(&mut mesh);

    validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect("nested-shell generation evidence should satisfy solid validation");
}

#[test]
fn rejects_solid_mesh_without_tetrahedron_generation_family() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.tetrahedron_generation_family = "unknown".to_string();

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("solid Tetrahedron artifacts must identify the selected generation family");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "missing_tetrahedron_generation_family".to_string(),
        }
    );
}

#[test]
fn rejects_solid_mesh_without_tetrahedron_generation_attempts() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.tetrahedron_generation_attempted_family_count = 0;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("solid Tetrahedron artifacts must report attempted generation families");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "missing_tetrahedron_generation_family_attempts".to_string(),
        }
    );
}

#[test]
fn rejects_solid_mesh_without_selected_tetrahedron_generation_family_index() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.tetrahedron_generation_selected_family_index = 0;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("solid Tetrahedron artifacts must report the selected generation family index");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "missing_tetrahedron_generation_selected_family".to_string(),
        }
    );
}

#[test]
fn rejects_selected_tetrahedron_generation_family_index_beyond_attempts() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.tetrahedron_generation_attempted_family_count = 2;
    mesh.backend.tetrahedron_generation_rejected_family_count = 1;
    mesh.backend.tetrahedron_generation_selected_family_index = 3;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("selected generation family index must be bounded by attempted families");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "inconsistent_tetrahedron_generation_selected_family_index".to_string(),
        }
    );
}

#[test]
fn rejects_tetrahedron_generation_rejected_family_count_mismatch() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.tetrahedron_generation_attempted_family_count = 3;
    mesh.backend.tetrahedron_generation_rejected_family_count = 1;
    mesh.backend.tetrahedron_generation_selected_family_index = 2;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("attempted generation families must reconcile with one selected family");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "inconsistent_tetrahedron_generation_rejected_family_count".to_string(),
        }
    );
}

#[test]
fn rejects_tetrahedron_generation_support_acceptance_without_candidates() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend
        .tetrahedron_generation_interior_support_candidate_count = 0;
    mesh.backend
        .tetrahedron_generation_interior_support_accepted_count = 1;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("accepted support points must be backed by candidate evidence");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "inconsistent_tetrahedron_generation_interior_support_count".to_string(),
        }
    );
}

#[test]
fn rejects_tetrahedron_generation_multiple_accepted_support_points() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend
        .tetrahedron_generation_interior_support_candidate_count = 3;
    mesh.backend
        .tetrahedron_generation_interior_support_accepted_count = 2;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("native support-point generation selects at most one support point");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "unsupported_tetrahedron_generation_interior_support_count".to_string(),
        }
    );
}

#[test]
fn rejects_nested_shell_generation_without_refill_strategy_evidence() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    configure_nested_shell_generation_evidence(&mut mesh);
    mesh.backend
        .tetrahedron_generation_nested_shell_barycentric_partition_refill_count = 0;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("nested-shell generation must identify the accepted refill strategy");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "inconsistent_nested_tetrahedron_shell_refill_strategy_count".to_string(),
        }
    );
}

#[test]
fn rejects_nested_shell_generation_with_multiple_refill_strategies() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    configure_nested_shell_generation_evidence(&mut mesh);
    mesh.backend
        .tetrahedron_generation_nested_shell_boundary_exact_cover_refill_count = 1;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("nested-shell generation can accept exactly one refill strategy");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "inconsistent_nested_tetrahedron_shell_refill_strategy_count".to_string(),
        }
    );
}

#[test]
fn rejects_nested_shell_generation_with_inconsistent_refinement_attempts() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    configure_nested_shell_generation_evidence(&mut mesh);
    mesh.backend
        .tetrahedron_generation_nested_shell_barycentric_partition_refill_count = 0;
    mesh.backend
        .tetrahedron_generation_nested_shell_boundary_exact_cover_refill_count = 1;
    mesh.backend
        .tetrahedron_generation_nested_shell_boundary_centroid_refinement_attempt_count = 0;
    mesh.backend
        .tetrahedron_generation_nested_shell_boundary_centroid_refinement_rejected_count = 1;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("exact-cover fallback requires rejected boundary refinement evidence");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "inconsistent_nested_tetrahedron_shell_refinement_rejection_count".to_string(),
        }
    );
}

#[test]
fn rejects_non_nested_generation_with_nested_shell_evidence() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend
        .tetrahedron_generation_nested_shell_outer_node_count = 4;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("non-nested generation must not carry nested-shell strategy evidence");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "unexpected_nested_tetrahedron_shell_generation_evidence".to_string(),
        }
    );
}

#[test]
fn rejects_nested_plc_shell_without_nested_generation_family() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.plc_input_boundary_component_count = 2;
    mesh.backend.plc_input_boundary_component_node_count = 8;
    mesh.backend.plc_input_nested_shell_count = 1;
    mesh.backend.plc_input_max_shell_nesting_depth = 1;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("nested PLC evidence requires matching generation family");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "unsupported_plc_boundary_component_count".to_string(),
        }
    );
}

fn configure_nested_shell_generation_evidence(mesh: &mut AnalysisMeshArtifact) {
    mesh.backend.tetrahedron_generation_family = "nested_tetrahedron_shell".to_string();
    mesh.backend.plc_input_node_count = 8;
    mesh.backend.plc_input_facet_count = 8;
    mesh.backend.plc_input_boundary_component_count = 2;
    mesh.backend.plc_input_boundary_component_node_count = 8;
    mesh.backend.plc_input_max_boundary_component_node_count = 4;
    mesh.backend.plc_input_nested_shell_count = 1;
    mesh.backend.plc_input_max_shell_nesting_depth = 1;
    mesh.backend
        .tetrahedron_generation_nested_shell_outer_node_count = 4;
    mesh.backend
        .tetrahedron_generation_nested_shell_inner_node_count = 4;
    mesh.backend
        .tetrahedron_generation_nested_shell_generated_node_count = 1;
    mesh.backend
        .tetrahedron_generation_nested_shell_refill_boundary_face_count = 8;
    mesh.backend
        .tetrahedron_generation_nested_shell_barycentric_partition_refill_count = 1;
    mesh.backend
        .tetrahedron_generation_nested_shell_outer_facet_count = 4;
    mesh.backend
        .tetrahedron_generation_nested_shell_inner_facet_count = 4;
}

#[test]
fn accepts_solid_mesh_with_consistent_plc_cad_curve_evidence() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.plc_input_protected_edge_count = 3;
    mesh.backend.plc_input_cad_curve_boundary_source_edge_count = 2;
    mesh.backend.plc_input_cad_curve_boundary_segment_count = 3;
    mesh.backend.plc_input_cad_curve_imported_edge_count = 1;
    mesh.backend.plc_input_cad_curve_evaluator_edge_count = 1;
    mesh.backend.plc_input_cad_curve_evaluator_sample_count = 4;
    mesh.backend.plc_input_cad_curve_live_query_edge_count = 1;
    mesh.backend.plc_input_cad_curve_live_query_sample_count = 2;
    mesh.backend
        .plc_input_cad_curve_rejected_evaluator_sample_count = 1;
    mesh.backend.plc_input_cad_curve_curvature_sized_edge_count = 1;
    mesh.backend.plc_input_cad_curve_curvature_sample_count = 2;

    validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect("consistent CAD curve PLC input evidence should satisfy validation");
}

#[test]
fn rejects_plc_cad_curve_evidence_without_source_edge_count() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.plc_input_cad_curve_boundary_segment_count = 1;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("CAD curve PLC evidence must identify source edges");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "missing_plc_cad_curve_boundary_source_edges".to_string(),
        }
    );
}

#[test]
fn rejects_plc_cad_curve_source_edges_exceeding_protected_edges() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.plc_input_protected_edge_count = 1;
    mesh.backend.plc_input_cad_curve_boundary_source_edge_count = 2;
    mesh.backend.plc_input_cad_curve_boundary_segment_count = 2;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("CAD curve source edges must be bounded by protected PLC edges");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "inconsistent_plc_cad_curve_source_edge_count".to_string(),
        }
    );
}

#[test]
fn rejects_plc_cad_curve_boundary_segments_below_source_edges() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.plc_input_protected_edge_count = 2;
    mesh.backend.plc_input_cad_curve_boundary_source_edge_count = 2;
    mesh.backend.plc_input_cad_curve_boundary_segment_count = 1;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("each CAD curve source edge must contribute a boundary segment");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "inconsistent_plc_cad_curve_boundary_segment_count".to_string(),
        }
    );
}

#[test]
fn rejects_plc_cad_curve_live_query_edges_without_evaluator_edges() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.plc_input_protected_edge_count = 2;
    mesh.backend.plc_input_cad_curve_boundary_source_edge_count = 2;
    mesh.backend.plc_input_cad_curve_boundary_segment_count = 2;
    mesh.backend.plc_input_cad_curve_live_query_edge_count = 1;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("live CAD curve queries must be backed by evaluator edges");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "inconsistent_plc_cad_curve_live_query_edge_count".to_string(),
        }
    );
}

#[test]
fn rejects_plc_cad_curve_samples_without_imported_or_evaluator_edges() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.plc_input_protected_edge_count = 2;
    mesh.backend.plc_input_cad_curve_boundary_source_edge_count = 2;
    mesh.backend.plc_input_cad_curve_boundary_segment_count = 2;
    mesh.backend.plc_input_cad_curve_evaluator_sample_count = 1;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("CAD curve samples must be backed by imported or evaluator edges");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "missing_plc_cad_curve_sample_edge_evidence".to_string(),
        }
    );
}

#[test]
fn rejects_solid_mesh_with_unclassified_plc_shell_evidence() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.plc_input_shell_nesting_classified = false;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("unclassified PLC shell evidence should fail");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "unclassified_plc_shell_nesting".to_string(),
        }
    );
}

#[test]
fn rejects_solid_mesh_without_tetrahedron_material_region_evidence() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.tetrahedron_material_region_count = 0;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("solid Tetrahedron artifacts must prove material ownership evidence");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "missing_tetrahedron_material_region_evidence".to_string(),
        }
    );
}

#[test]
fn rejects_solid_mesh_with_unclassified_tetrahedron_material_ownership_evidence() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.tetrahedron_unclassified_material_element_count = 1;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("solid Tetrahedron artifacts must not carry unclassified ownership evidence");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "unclassified_tetrahedron_material_ownership".to_string(),
        }
    );
}

#[test]
fn rejects_single_material_plc_with_multiple_generated_material_regions() {
    let mut mesh = solid_tetrahedron_mesh_with_plc_input_evidence();
    mesh.backend.tetrahedron_material_region_count = 2;

    let err = validate_analysis_mesh(&mesh, QualityThresholds::default())
        .expect_err("single-material PLC evidence should preserve one generated material region");

    assert_eq!(
        err,
        AnalysisMeshValidationError::MissingPlcInputEvidence {
            reason: "inconsistent_single_material_region_ownership".to_string(),
        }
    );
}