forked from 1b-agent/fieldcraft-upstream
explicit: deformable contact and friction, verified by bars, sliding blocks, the patch test and Hertz
Segment-to-segment penalty contact between element faces: each secondary face and each main face facing it are projected onto the secondary face's plane, split into triangles, clipped (Sutherland–Hodgman) and integrated with a three-point rule per sub-triangle (Puso–Laursen segmentation, the penalty at the integration points as Fischer–Wriggers), so a uniform pressure gives the consistent nodal forces on both meshes and the contact patch test passes on non-matching meshes. Every contact runs both ways at half the penalty: pairs with each surface as the secondary, general and self contact face against face. A bucket grid of face boxes every increment, faces integrated in parallel and their forces added in face order: the same numbers on any thread count. The penalty per area ε = s γ min(m/A)/Δt² comes from the lumped masses, each node's directional area and the stable increment, bounded by Gershgorin's row sums so contact never shortens the increment. Coulomb friction with exponential decay by a regularised return map at the secondary nodes; rigid walls take Coulomb impulses. Contact work and friction dissipation join the energy balance; each contact reports its peak force, first and last contact, deepest penetration, friction and the nodes adjusted at the start (initial penetrations adjusted strain-free or refused with the node, face and depth); a cap on contact faces. Verified (crates/explicit/tests/contact.rs, tests/oracle/explicit-*): colliding bars (2L/c +1.2%, ρcAv₀/2, KE kept to 0.005%, contact energy back to 8e-5 of it), blocks sliding to a stop on a rigid wall and on a plate under constant and decaying friction (0.005–0.2%), the patch test (σ_zz uniform to 0.06%), two spheres colliding against Hertz (peak +2.3%, duration −0.4%; the oracle case waits for a graded sphere mesher), a free body untouched by general contact, determinism across threads. Oracle measures gain `over` (ratios). Existing fixtures do not move. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm
This commit is contained in:
1 parent
ecf947c090
commit
a30d0b5c5b
37 files changed
+2459
-55
No files matched your search
@@ -263,7 +263,8 @@ pub fn run_case(dir: &Path, expected: &Expected) -> Result<Vec<Result<f64, Strin
|
||||
}
|
||||
|
||||
/// Read one number: from a recipe step's output (`"from": id`) or a command run now
|
||||
/// (`"command"`, `"params"`), at a JSON pointer.
|
||||
/// (`"command"`, `"params"`), at a JSON pointer, times `scale`; with `"over"` (a measure of its
|
||||
/// own), divided by that measure's number.
|
||||
fn measure(session: &mut Session, outputs: &BTreeMap<String, Value>, m: &Value) -> Result<f64, String> {
|
||||
let pointer = m.get("pointer").and_then(Value::as_str).ok_or("no `pointer`")?;
|
||||
let fresh;
|
||||
@@ -278,7 +279,15 @@ fn measure(session: &mut Session, outputs: &BTreeMap<String, Value>, m: &Value)
|
||||
};
|
||||
let v = out.pointer(pointer).ok_or_else(|| format!("nothing at `{pointer}`"))?;
|
||||
let x = v.as_f64().ok_or_else(|| format!("`{pointer}` is {v}, not a number"))?;
|
||||
let x = x * m.get("scale").and_then(Value::as_f64).unwrap_or(1.0);
|
||||
let mut x = x * m.get("scale").and_then(Value::as_f64).unwrap_or(1.0);
|
||||
// A ratio: this value over another measure's (both from the same run).
|
||||
if let Some(over) = m.get("over") {
|
||||
let y = measure(session, outputs, over)?;
|
||||
if y == 0.0 {
|
||||
return Err(format!("`{pointer}` is measured over a zero"));
|
||||
}
|
||||
x /= y;
|
||||
}
|
||||
if x.is_finite() { Ok(x) } else { Err(format!("`{pointer}` is not finite")) }
|
||||
}
|
||||
|
||||
@@ -730,6 +739,18 @@ mod tests {
|
||||
assert_eq!(fixture_band(1e-16, 0.0, a, FIXTURE_RELATIVE), 1e-9, "a zero reference keeps its tolerance as the band");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn measures_read_pointers_scale_and_divide() {
|
||||
let mut session = Session::default();
|
||||
let outputs: BTreeMap<String, Value> = [("s".to_string(), json!({"a": 6.0, "b": -2.0, "z": 0.0}))].into_iter().collect();
|
||||
let m = |v: Value| measure(&mut Session::default(), &outputs, &v);
|
||||
assert_eq!(m(json!({"from": "s", "pointer": "/a", "scale": 0.5})), Ok(3.0));
|
||||
assert_eq!(m(json!({"from": "s", "pointer": "/a", "over": {"from": "s", "pointer": "/b", "scale": -1.0}})), Ok(3.0));
|
||||
assert!(m(json!({"from": "s", "pointer": "/a", "over": {"from": "s", "pointer": "/z"}})).is_err());
|
||||
assert!(m(json!({"from": "s", "pointer": "/a", "over": {"from": "s", "pointer": "/nope"}})).is_err());
|
||||
assert!(measure(&mut session, &outputs, &json!({"from": "t", "pointer": "/a"})).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expected_files_are_checked() {
|
||||
let good = json!({"title": "t", "kind": "theory", "source": "s", "quantities": [
|
||||
|
||||
Reference in new issue
Block a user