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
//! Python wrappers for [`crate::ops::model`] — the physics declarations,
//! which produce a `Model`.
//!
//! Each one spans the **whole** support it is given (one zone per subspace);
//! heterogeneous physics compose with `|`.
use crateRelationSense;
use cratemodel;
use cratePyFiniteElementSpace;
use cratePyMesh;
use cratePyModel;
use cratePyNodeField;
use *;
use py_op;
/// Exchange `j·n = h(c₁ − c₂)` across an interface whose two sides share no node.
///
/// This is what lets the field **jump** across the interface: with a shared node
/// it could not. The jump is `q/h` for a flux density `q`. The coefficient
/// `h_<variable>` is supplied at assembly time.
///
/// # Parameters
///
/// - `side_a`, `side_b`: the two facing **boundary** FE spaces. They must be
/// conforming — same element type, same cell count, and local node `k` of a
/// cell facing local node `k` of its counterpart, within `tol`. A non-matching
/// interface raises rather than being projected.
/// - `target`: the model it couples into; the dual row of each variable and the
/// nature are read from it.
/// - `variables`: the exchanged unknowns of `target`, each coupling into the
/// dual row `target` pairs it with: `["c_H2"]` on a `fick` model for a
/// coating, `["T"]` on a `heat_conduction` for a contact resistance, the
/// displacements on an `elasticity` for a bonded joint of finite stiffness.
/// - `tol`: the matching tolerance, a **distance** in the length unit of the
/// mesh.
///
/// # Returns
///
/// A `Model` coupling the two sides.
///
/// # Raises
///
/// `RuntimeError` if the two sides do not match, for a variable `target` does
/// not declare, or for variables of two natures.
/// Hold `variable` at imposed values on the nodes of `imposed_mesh`.
///
/// A Dirichlet constraint, a single sub-model, through Lagrange multipliers. Each
/// relation, one per node, gets a multiplier node of its own, minted beside its
/// constrained node (`Model.multiplier_mesh()` gives them back), with the names
/// of every constraint relation, `lambda` and `imposed`. The imposed value `u_d`
/// is written in the load field at the multiplier node's `imposed` component —
/// `Model.constraint_rhs` does it from the constrained node. One variable, and
/// one only — compose for a clamp:
/// `dirichlet(nodes, m, "u_x") | dirichlet(nodes, m, "u_y")`.
///
/// # Parameters
///
/// - `imposed_mesh`: the mesh of the constrained nodes, of any element type —
/// an edge, a face, a selection of points. Its distinct nodes, all zones
/// together, are held, each once: a node that two zones share gets one
/// relation. A single zone is held through its POI1 companion,
/// `SubMesh.to_poi1()`, so the solution on that support pairs node by node
/// with the fields on that zone; several zones are fused into a new POI1 zone.
/// - `target`: the model being constrained; the dual row of `variable` is read
/// from it.
/// - `variable`: the unknown of `target` to hold, one of its primals.
/// - `sense`: `"="` (the default), `">="` or `"<="`. The last two make the
/// constraint unilateral (`u ≥ u_d`, `u ≤ u_d`): the matrix carries the sense,
/// and `pyrucast.solver.solve` runs its active-set loop.
///
/// # Returns
///
/// A `Model` of one constraint sub-model.
///
/// # Raises
///
/// - `ValueError` for an unknown `sense`.
/// - `RuntimeError` if `imposed_mesh` holds no node, or if `variable` is not a
/// primal of `target`.
/// Impose a linear relation `Σₖ aₖ·u(nodeₖ, varₖ) = g` between nodes, per relation.
///
/// A multi-point constraint, a single sub-model, through Lagrange multipliers.
/// Each relation gets a multiplier node of its own, minted beside the node of the
/// first term; `g` is written in the load field at its `imposed` component
/// (default `0`).
///
/// # Parameters
///
/// - `terms`: a list of `(mesh, variable, coefficient)` tuples. Each `mesh` is a
/// POI1 mesh, one node per relation, paired cell for cell with the others
/// (relation `r` = cell `r` of every mesh); each `variable` is a primal of
/// `target`.
/// - `target`: the model being constrained — the union of two models to tie two
/// bodies —; the dual rows are read from it.
/// - `sense`: `"="` (the default), `">="` or `"<="`. The last two make the
/// relations unilateral (`Σ aₖ·uₖ ≥ g`, `≤ g`): the matrix carries the sense,
/// and `pyrucast.solver.solve` runs its active-set loop.
///
/// # Returns
///
/// A `Model` of one constraint sub-model.
///
/// # Raises
///
/// - `ValueError` for an unknown `sense`.
/// - `RuntimeError` if the meshes of `terms` do not hold the same number of
/// nodes, or if a variable is not a primal of `target`.
/// Tie each node of `immersed` to the interpolation of `host` at that node.
///
/// An embedded constraint, a single sub-model, through Lagrange multipliers — a
/// bar embedded in a volume, for instance. The coupling weights are the host
/// shape functions at each immersed node, computed once at build by locating the
/// node in the host. Each relation — one per immersed node and variable — gets a
/// multiplier node of its own; the right-hand side defaults to `0`, a rigid tie.
///
/// # Parameters
///
/// - `immersed`: the immersed nodes' mesh, on the same `Coords` as `host`.
/// - `host`: the mesh they are immersed in.
/// - `target`: the model being constrained; the dual rows are read from it.
/// - `variables`: the primals of `target` to tie, `["u_x", "u_y", "u_z"]` for
/// instance.
/// - `tol`: the location tolerance, a gap in the host's **reference** element,
/// without dimension.
///
/// # Returns
///
/// A `Model` of one constraint sub-model.
///
/// # Raises
///
/// `RuntimeError` if an immersed node lies outside the host, or if a variable is
/// not a primal of `target`.
/// Node-to-surface contact: keep the nodes of `slave` out of the `master` surface.
///
/// One **unilateral** relation (`≥`) per slave node, a single sub-model. Each
/// slave node is paired at build with its closest master facet (projection
/// weights, facet normal, initial signed gap); the pairing is then fixed
/// (linearized, frictionless contact) until `pyrucast.model.update_contact`
/// pairs it again. Each relation gets a multiplier node of its own, minted
/// beside its slave node. The initial-gap right-hand side `-g0` is a load the
/// contact carries: `pyrucast.node_field.external_forces` returns it with the
/// other loads of the model. Solve with `pyrucast.solver.solve`, which runs its
/// active-set loop.
///
/// # Parameters
///
/// - `slave`: the nodes that must not penetrate.
/// - `master`: the surface mesh, consistently oriented, its normal pointing
/// toward the slave body.
/// - `target`: the model being constrained; the dual rows are read from it.
/// - `variables`: the displacement primals of `target`, one per spatial axis in
/// ambient order (`["u_x", "u_y"]`).
///
/// # Returns
///
/// A `Model` of one constraint sub-model.
///
/// # Raises
///
/// `RuntimeError` if a variable is not a primal of `target`.
/// The model with its contacts paired again on the positions `X + u`.
///
/// Each slave node is paired again with its closest master facet on `X + u`, and
/// its relation becomes the gap linearized there, written in total displacement
/// from `X`: the right-hand side the contact carries is `-g~`, the gap of the new
/// pairing measured on `X`. The multiplier nodes are kept, so the unknowns
/// `lambda` and the rows `imposed` stay the same; at `u = 0`, the contact as it
/// was built. What large displacements call for: the step-by-step loop updates
/// its contacts each time it rebuilds its operator.
///
/// # Parameters
///
/// - `model`: the model whose contacts to update. Every other sub-model is
/// shared as it is; a model without contact comes back unchanged.
/// - `displacement`: `u`, read on each contact's variables (`u_x`, `u_y`,
/// `u_z`); a node or a component it lacks reads zero. `X` is the active
/// configuration.
///
/// # Returns
///
/// A new `Model`.
///
/// # Notes
///
/// A master facet collapsed by the displacement is not detected.