forked from 1b-agent/fieldcraft-upstream
mesh: strong relaxation morphs round the bad elements (harmonic interpolation within a reach)
The owner's direction: bad nodes move to better places, the nodes within a reach follow by the graph Laplacian's harmonic extension, edges held, nothing outside the reach moves. mesh.node.relax strong mode takes below and reach and reports each round. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UhhZMBTviDQxZvwnyP89fo
This commit is contained in:
1 parent
6f94346253
commit
4908f5679c
8 files changed
+430
-253
No files matched your search
@@ -267,22 +267,23 @@ fn on_box_edge(p: [f64; 3]) -> bool {
|
||||
p.iter().filter(|c| c.abs() < 1e-6 || (**c - 20.0).abs() < 1e-6).count() >= 2
|
||||
}
|
||||
|
||||
/// Strong mode on the whole filleted box: the smallest and the mean scaled Jacobian do not drop,
|
||||
/// Strong mode on the whole filleted box: the smallest scaled Jacobian does not drop, the mean rises,
|
||||
/// nothing inverts, the fillet's nodes stay on its cylinder, the plane faces' nodes on their
|
||||
/// planes, and the nodes on the box's edges and the fillet's tangent lines do not move. The
|
||||
/// reply carries the objective, min and mean per sweep.
|
||||
/// reply carries each round's region and quality.
|
||||
#[test]
|
||||
fn strong_relaxation_of_a_filleted_box_keeps_faces_and_edges() {
|
||||
let (_d, mut s, _) = filleted_box();
|
||||
let before = s.model.clone();
|
||||
let r = s.execute("mesh.node.relax", &json!({"mode": "strong", "bodies": ["B"], "iterations": 40})).unwrap();
|
||||
let r = s.execute("mesh.node.relax", &json!({"mode": "strong", "bodies": ["B"], "below": 0.3})).unwrap();
|
||||
let (b, a) = (&r["before"], &r["after"]);
|
||||
assert!(a["min_scaled_jacobian"].as_f64().unwrap() > b["min_scaled_jacobian"].as_f64().unwrap(), "{r}");
|
||||
// The worst tets may not improve: their corners can all be held on the box's edges.
|
||||
assert!(a["min_scaled_jacobian"].as_f64().unwrap() >= b["min_scaled_jacobian"].as_f64().unwrap(), "{r}");
|
||||
assert!(a["mean_scaled_jacobian"].as_f64().unwrap() > b["mean_scaled_jacobian"].as_f64().unwrap(), "{r}");
|
||||
assert_eq!(a["invalid"], 0, "{r}");
|
||||
assert_eq!(invalid(&mut s), 0);
|
||||
let history = r["history"].as_array().unwrap();
|
||||
assert!(history.len() > 2 && history.iter().all(|h| h["objective"].is_number() && h["min"].is_number() && h["mean"].is_number()), "{r}");
|
||||
let rounds = r["rounds"].as_array().unwrap();
|
||||
assert!(!rounds.is_empty() && rounds.iter().all(|k| k["region_nodes"].as_u64() >= k["bad_nodes"].as_u64() && k["min"].is_number()), "{r}");
|
||||
for (n, p) in s.model.nodes() {
|
||||
let (old, new) = (before.node(*n).unwrap().xyz, p.xyz);
|
||||
if on_box_edge(old) {
|
||||
@@ -302,9 +303,8 @@ fn strong_relaxation_of_a_filleted_box_keeps_faces_and_edges() {
|
||||
}
|
||||
|
||||
/// Strong mode on a distorted hex plate: over the guarded mode's sphere it lifts the smallest
|
||||
/// scaled Jacobian as far as the guarded mode (to the elements on the sphere's rim, which
|
||||
/// neither moves) (with nodes on edges held, where the guarded mode slides
|
||||
/// them); by quality threshold (the elements below 0.5 and two layers round them) it untangles
|
||||
/// scaled Jacobian past the threshold, close to the guarded mode (which also slides the edge nodes) (with nodes on edges held, where the guarded mode slides
|
||||
/// them); by quality threshold (the elements below 0.5, morphed 4 mm round) it untangles
|
||||
/// every element. Nothing inverts, nodes on the hole stay on its cylinder and the caps' on their
|
||||
/// planes, nodes on the hole's edges do not move.
|
||||
#[test]
|
||||
@@ -316,13 +316,12 @@ fn strong_relaxation_untangles_a_distorted_plate() {
|
||||
let sphere = json!({"center": ON_HOLE, "radius": 7.0, "iterations": 20});
|
||||
let guarded = s.execute("mesh.node.relax", &sphere).unwrap();
|
||||
let min = |r: &Value, at: &str| r[at]["min_scaled_jacobian"].as_f64().unwrap();
|
||||
for strong in [json!({"mode": "strong", "center": ON_HOLE, "radius": 7.0}), json!({"mode": "strong", "below": 0.5, "layers": 2})] {
|
||||
for strong in [json!({"mode": "strong", "center": ON_HOLE, "radius": 7.0}), json!({"mode": "strong", "below": 0.5, "reach": 4.0})] {
|
||||
s.model = perturbed.clone();
|
||||
let r = s.execute("mesh.node.relax", &strong).unwrap();
|
||||
assert!(min(&r, "after") > 0.5 && min(&r, "before") < 0.0, "{strong}: {r}");
|
||||
if strong.get("center").is_some() {
|
||||
assert!(min(&r, "after") >= min(&guarded, "after") - 1e-9, "strong {r}\nguarded {guarded}");
|
||||
}
|
||||
assert!(min(&r, "after") > strong["below"].as_f64().unwrap_or(0.7) && min(&r, "before") < 0.0, "{strong}: {r}");
|
||||
// Close to the guarded mode, which also slides the hole's edge nodes.
|
||||
assert!(strong.get("below").is_some() || min(&r, "after") > min(&guarded, "after") - 0.05, "strong {r}\nguarded {guarded}");
|
||||
assert_eq!(r["after"]["invalid"], 0, "{r}");
|
||||
assert_eq!(invalid(&mut s), 0);
|
||||
check_on_geometry(&perturbed, &s.model);
|
||||
@@ -340,20 +339,21 @@ fn strong_mode_parameters_are_checked() {
|
||||
let mut s = plate();
|
||||
s.execute("mesh.hex.generate", &json!({"size": 4.0})).unwrap();
|
||||
for p in [
|
||||
json!({"mode": "strong"}),
|
||||
json!({"mode": "wild", "nodes": [1]}),
|
||||
json!({"mode": "strong", "below": 0}),
|
||||
json!({"mode": "strong", "below": 1.5}),
|
||||
json!({"mode": "strong", "below": 0.5, "layers": 21}),
|
||||
json!({"mode": "strong", "below": 0.5, "layers": -1}),
|
||||
json!({"mode": "strong", "below": 0.5, "reach": 0}),
|
||||
json!({"mode": "strong", "below": 0.5, "reach": -1}),
|
||||
json!({"mode": "strong", "bodies": ["nope"]}),
|
||||
json!({"mode": "strong", "nodes": [1], "iterations": 0}),
|
||||
json!({"mode": "strong", "nodes": [1], "iterations": 2001}),
|
||||
json!({"mode": "strong", "nodes": [1], "iterations": 201}),
|
||||
json!({"below": 0.5}),
|
||||
json!({"nodes": [1], "layers": 1}),
|
||||
json!({"nodes": [1], "reach": 1}),
|
||||
json!({"nodes": [1], "mode": "strong", "layers": 1}),
|
||||
] {
|
||||
assert!(s.execute("mesh.node.relax", &p).is_err(), "{p}");
|
||||
}
|
||||
// An undistorted mesh above the threshold: nothing to relax.
|
||||
assert!(s.execute("mesh.node.relax", &json!({"mode": "strong", "below": 0.01})).is_err());
|
||||
// Nothing below the threshold: nothing moves.
|
||||
let r = s.execute("mesh.node.relax", &json!({"mode": "strong", "below": 0.01})).unwrap();
|
||||
assert_eq!(r["moved"], 0, "{r}");
|
||||
}
|
||||
Reference in new issue
Block a user