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
//! Node-to-surface unilateral contact.
use single;
use crateMesh;
use crate;
use crateNodeField;
use crateResult;
/// Node-to-surface contact `Model` (a single sub-model) preventing the
/// nodes of `slave` from penetrating the oriented `master` surface.
/// Parent-level operator — see [`SubModel::contact`] and
/// [`contact::Contact::new`](crate::models::contact::Contact::new) for the
/// pairing, the normal coupling and the errors. Solve with
/// [`solve`](crate::ops::solver::solve).
///
/// The supports come first — `slave`, which carries the relations, then
/// `master`, onto which it projects — and the model they constrain after them.
///
/// ```
/// # use pyrucast::ops::element_field::StrainMeasure;
/// # use pyrucast::aggregate::Aggregate;
/// # use pyrucast::atoms::{ElementType, Node};
/// # use pyrucast::containers::finite_element_space::FiniteElementSpace;
/// # use pyrucast::containers::mesh::{Mesh, SubMesh};
/// # use pyrucast::containers::model::{Model, SubModel};
/// # use pyrucast::coords::Coords;
/// # use pyrucast::handle::Handle;
/// # use pyrucast::models::tensor::Kinematics;
/// # use pyrucast::models::symmetry::MaterialSymmetry;
/// # use pyrucast::models::{Physics, RelationSense};
/// # use pyrucast::ops::mesh;
/// # use pyrucast::ops::model;
/// # let coords = Handle::new(Coords::new(2).unwrap());
/// # let n: Vec<Node> = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]]
/// # .iter().map(|p| Node::create_in(coords.clone(), p).unwrap()).collect();
/// # let mut sm = SubMesh::new(coords.clone(), ElementType::TRI3);
/// # sm.add_cell(&[n[0].id(), n[1].id(), n[2].id()]).unwrap();
/// # let maillage = Mesh::from_submesh(sm);
/// # let fes = FiniteElementSpace::lagrange1(&maillage).unwrap();
/// # let zone = fes.get(0).unwrap();
/// # let impose = mesh::poi1_from_nodes(&n[..1]).unwrap();
/// # let mut maitre = SubMesh::new(coords.clone(), ElementType::SEG2);
/// # maitre.add_cell(&[n[0].id(), n[1].id()])?;
/// # let master = Mesh::from_submesh(maitre);
/// # let slave = mesh::poi1_from_nodes(&n[2..3])?;
/// # let cible = pyrucast::ops::model::elasticity(
/// # &FiniteElementSpace::lagrange1(&maillage)?,
/// # pyrucast::models::tensor::Kinematics::PlaneStress, MaterialSymmetry::Isotropic, StrainMeasure::Linear)?;
/// let m = model::contact(&slave, &master, &cible,
/// vec!["u_x".into(), "u_y".into()])?;
/// assert_eq!(m.len(), 1);
/// # Ok::<(), pyrucast::PyrucastError>(())
/// ```
/// The model with its contacts **updated** to the positions `X + u` — `X` the
/// active configuration, `u` read in `displacement` on each contact's
/// variables (a node or a component it lacks reads zero). Every other
/// sub-model is shared as it is; a model without contact comes back unchanged.
///
/// Each slave node is paired again with its closest master facet on `X + u`
/// (projection weights, normal), and the relation becomes the gap linearised
/// there: its right-hand side, the load the contact carries, is
/// `−g̃ = −n·(X_s − Σ Nᵢ X_mᵢ)`, the gap of the new pairing measured on `X`,
/// so that `C·u ≥ −g̃` is written in total displacement from `X` like every
/// other relation. The slave mesh and the **multiplier nodes** are kept: the
/// unknowns `lambda` and the rows `imposed` stay the same, only the
/// coefficients of the rows and their right-hand side change. At `u = 0`, the
/// contact as it was built.
///
/// Its coefficients are the exact derivative of the gap at `X + u`: for a
/// closest-point projection, `δg = n·(δx_s − Σ Nᵢ δx_mᵢ)` — the projected
/// point slides along the facet, orthogonally to `n`, and `n` stays unit.
/// What is neglected is the second order, the geometric stiffness of the
/// contact. A master facet collapsed by the displacement is not detected here:
/// its normal is non-finite.
///
/// ```
/// # use pyrucast::ops::element_field::StrainMeasure;
/// # use pyrucast::aggregate::Aggregate;
/// # use pyrucast::atoms::{ElementType, Node};
/// # use pyrucast::containers::finite_element_space::FiniteElementSpace;
/// # use pyrucast::containers::mesh::{Mesh, SubMesh};
/// # use pyrucast::containers::node_field::NodeField;
/// # use pyrucast::coords::Coords;
/// # use pyrucast::handle::Handle;
/// # use pyrucast::models::{Constraint, IMPOSED};
/// # use pyrucast::ops::{mesh, model, node_field};
/// # let coords = Handle::new(Coords::new(2).unwrap());
/// // A floor of two segments, A(0,0)–B(1,0)–C(2,0), its normal up (each
/// // segment run right to left), and a slave node above A–B.
/// # let p = |x: f64, y: f64| Node::create_in(coords.clone(), &[x, y]).unwrap();
/// # let (a, b, c, s) = (p(0.0, 0.0), p(1.0, 0.0), p(2.0, 0.0), p(0.5, 1.0));
/// # let mut floor = SubMesh::new(coords.clone(), ElementType::SEG2);
/// # floor.add_cell(&[b.id(), a.id()])?;
/// # floor.add_cell(&[c.id(), b.id()])?;
/// # let master = Mesh::from_submesh(floor);
/// # let slave = mesh::poi1_from_nodes(&[s.clone()])?;
/// # let mut bars = SubMesh::new(coords.clone(), ElementType::SEG2);
/// # bars.add_cell(&[a.id(), s.id()])?;
/// # let cible = model::truss(&FiniteElementSpace::lagrange1(&Mesh::from_submesh(bars))?,
/// # StrainMeasure::Linear)?;
/// let contact = model::contact(&slave, &master, &cible, vec!["u_x".into(), "u_y".into()])?;
/// # let gap = |m: &pyrucast::containers::model::Model| -> f64 {
/// # let mult = m.multiplier_mesh().unwrap().node(0, 0, 0).unwrap().id();
/// # node_field::external_forces(m, &pyrucast::containers::element_field::ElementField::empty())
/// # .unwrap().value(mult, IMPOSED).unwrap()
/// # };
/// # let terms = |m: &pyrucast::containers::model::Model| -> Vec<_> {
/// # m.get(0).unwrap().read().as_kind().as_constraint().unwrap().relations().unwrap()[0]
/// # .terms.iter().filter(|t| t.coefficient != 0.0).map(|t| t.node).collect()
/// # };
/// // At u = 0, the contact as it was built: the gap is 1, on A–B.
/// let rest = NodeField::empty();
/// assert_eq!(gap(&model::update_contact(&contact, &rest)), gap(&contact));
/// // The slave slid by (1, −0.7), to (1.5, 0.3): it now projects on B–C, and
/// // the relation reads the gap of that pairing on the positions at rest.
/// let mut u = NodeField::new(&mesh::poi1_from_nodes(&[s.clone()])?,
/// vec!["u_x".into(), "u_y".into()])?;
/// u.get(0)?.write().set_value(s.id(), "u_x", 1.0)?;
/// u.get(0)?.write().set_value(s.id(), "u_y", -0.7)?;
/// let moved = model::update_contact(&contact, &u);
/// assert!(terms(&moved).contains(&c.id()) && !terms(&moved).contains(&a.id()));
/// assert!((gap(&moved) + 1.0).abs() < 1e-12);
/// // The same multiplier: the same unknown.
/// assert_eq!(moved.multiplier_mesh()?.node(0, 0, 0)?.id(),
/// contact.multiplier_mesh()?.node(0, 0, 0)?.id());
/// # Ok::<(), pyrucast::PyrucastError>(())
/// ```