precice 3.4.0

Rust bindinds for precice
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
#[cxx::bridge(namespace = "precice::rust")]
mod ffi {
    unsafe extern "C++" {
        include!("precice/src/precice-bridge.hpp");
        type Participant;

        fn create_participant(
            participant: &str,
            config: &str,
            rank: i32,
            size: i32,
        ) -> Result<UniquePtr<Participant>>;

        // Steering Methods
        fn initialize(self: Pin<&mut Participant>) -> Result<()>;
        fn advance(self: Pin<&mut Participant>, dt: f64) -> Result<()>;
        fn finalize(self: Pin<&mut Participant>) -> Result<()>;

        // Implicit coupling
        fn requires_reading_checkpoint(self: Pin<&mut Participant>) -> Result<bool>;
        fn requires_writing_checkpoint(self: Pin<&mut Participant>) -> Result<bool>;

        // Status Queries
        fn get_mesh_dimensions(self: &Participant, mesh_name: &str) -> Result<i32>;
        fn get_data_dimensions(self: &Participant, mesh_name: &str, data_name: &str)
            -> Result<i32>;
        fn is_coupling_ongoing(self: &Participant) -> Result<bool>;
        fn is_time_window_complete(self: &Participant) -> Result<bool>;
        fn get_max_time_step_size(self: &Participant) -> Result<f64>;

        // Mesh Access

        fn requires_mesh_connectivity_for(self: &Participant, mesh_name: &str) -> Result<bool>;
        fn reset_mesh(self: Pin<&mut Participant>, mesh_name: &str) -> Result<()>;
        fn set_mesh_vertex(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            position: &[f64],
        ) -> Result<i32>;
        fn get_mesh_vertex_size(self: &Participant, mesh_name: &str) -> Result<i32>;
        fn set_mesh_vertices(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            positions: &[f64],
            ids: &mut [i32],
        ) -> Result<()>;
        fn set_mesh_edge(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            first_vertex_id: i32,
            second_vertex_id: i32,
        ) -> Result<()>;
        fn set_mesh_edges(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            vertices: &[i32],
        ) -> Result<()>;
        fn set_mesh_triangle(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            first_vertex_id: i32,
            second_vertex_id: i32,
            third_vertex_id: i32,
        ) -> Result<()>;
        fn set_mesh_triangles(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            vertices: &[i32],
        ) -> Result<()>;
        fn set_mesh_quad(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            first_vertex_id: i32,
            second_vertex_id: i32,
            third_vertex_id: i32,
            fourth_vertex_id: i32,
        ) -> Result<()>;
        fn set_mesh_quads(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            vertices: &[i32],
        ) -> Result<()>;
        fn set_mesh_tetrahedron(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            first_vertex_id: i32,
            second_vertex_id: i32,
            third_vertex_id: i32,
            fourth_vertex_id: i32,
        ) -> Result<()>;
        fn set_mesh_tetrahedra(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            vertices: &[i32],
        ) -> Result<()>;

        // Data Access

        fn requires_initial_data(self: Pin<&mut Participant>) -> Result<bool>;

        fn write_data(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            data_name: &str,
            vertices: &[i32],
            values: &[f64],
        ) -> Result<()>;
        fn read_data(
            self: &Participant,
            mesh_name: &str,
            data_name: &str,
            vertices: &[i32],
            relative_read_dt: f64,
            values: &mut [f64],
        ) -> Result<()>;

        // User profiling

        pub fn start_profiling_section(
            self: Pin<&mut Participant>,
            section_name: &str,
        ) -> Result<()>;

        pub fn stop_last_profiling_section(self: Pin<&mut Participant>) -> Result<()>;

        // Direct Access

        fn set_mesh_access_region(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            bounding_box: &[f64],
        ) -> Result<()>;
        fn get_mesh_vertex_ids_and_coordinates(
            self: &Participant,
            mesh_name: &str,
            ids: &mut [i32],
            coordinates: &mut [f64],
        ) -> Result<()>;

        // experimental: Gradient Data

        fn requires_gradient_data_for(
            self: &Participant,
            mesh_name: &str,
            data_name: &str,
        ) -> Result<bool>;
        fn write_gradient_data(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            data_name: &str,
            vertices: &[i32],
            gradients: &[f64],
        ) -> Result<()>;

        // experimental: JIT mapping

        fn write_and_map_data(
            self: Pin<&mut Participant>,
            mesh_name: &str,
            data_name: &str,
            coordinates: &[f64],
            values: &[f64],
        ) -> Result<()>;

        fn map_and_read_data(
            self: &Participant,
            mesh_name: &str,
            data_name: &str,
            coordinates: &[f64],
            relative_read_dt: f64,
            values: &mut [f64],
        ) -> Result<()>;
    }
}

pub struct Participant {
    internal: cxx::UniquePtr<ffi::Participant>,
}

pub type VertexID = i32;
pub type Error = cxx::Exception;

impl Participant {
    pub fn new(participant: &str, config: &str, rank: i32, size: i32) -> Result<Self, Error> {
        Ok(Participant {
            internal: ffi::create_participant(participant, config, rank, size)?,
        })
    }

    // Steering Methods
    pub fn initialize(&mut self) -> Result<(), Error> {
        self.internal.pin_mut().initialize()
    }
    pub fn advance(&mut self, dt: f64) -> Result<(), Error> {
        self.internal.pin_mut().advance(dt)
    }
    pub fn finalize(&mut self) -> Result<(), Error> {
        self.internal.pin_mut().finalize()
    }

    // Implicit coupling
    pub fn requires_reading_checkpoint(&mut self) -> Result<bool, Error> {
        self.internal.pin_mut().requires_reading_checkpoint()
    }
    pub fn requires_writing_checkpoint(&mut self) -> Result<bool, Error> {
        self.internal.pin_mut().requires_writing_checkpoint()
    }

    // Status Queries
    pub fn get_mesh_dimensions(&self, mesh_name: &str) -> Result<i32, Error> {
        self.internal.get_mesh_dimensions(mesh_name)
    }
    pub fn get_data_dimensions(&self, mesh_name: &str, data_name: &str) -> Result<i32, Error> {
        self.internal.get_data_dimensions(mesh_name, data_name)
    }
    pub fn is_coupling_ongoing(&self) -> Result<bool, Error> {
        self.internal.is_coupling_ongoing()
    }
    pub fn is_time_window_complete(&self) -> Result<bool, Error> {
        self.internal.is_time_window_complete()
    }
    pub fn get_max_time_step_size(&self) -> Result<f64, Error> {
        self.internal.get_max_time_step_size()
    }

    // Mesh Access

    pub fn requires_mesh_connectivity_for(&self, mesh_name: &str) -> Result<bool, Error> {
        self.internal.requires_mesh_connectivity_for(mesh_name)
    }
    pub fn reset_mesh(&mut self, mesh_name: &str) -> Result<(), Error> {
        self.internal.pin_mut().reset_mesh(mesh_name)
    }
    pub fn set_mesh_vertex(
        &mut self,
        mesh_name: &str,
        position: &[f64],
    ) -> Result<VertexID, Error> {
        self.internal.pin_mut().set_mesh_vertex(mesh_name, position)
    }
    pub fn get_mesh_vertex_size(&self, mesh_name: &str) -> Result<i32, Error> {
        self.internal.get_mesh_vertex_size(mesh_name)
    }
    pub fn set_mesh_vertices(
        &mut self,
        mesh_name: &str,
        positions: &[f64],
        ids: &mut [VertexID],
    ) -> Result<(), Error> {
        self.internal
            .pin_mut()
            .set_mesh_vertices(mesh_name, positions, ids)
    }
    pub fn set_mesh_edge(
        &mut self,
        mesh_name: &str,
        first_vertex_id: VertexID,
        second_vertex_id: VertexID,
    ) -> Result<(), Error> {
        self.internal
            .pin_mut()
            .set_mesh_edge(mesh_name, first_vertex_id, second_vertex_id)
    }
    pub fn set_mesh_edges(&mut self, mesh_name: &str, vertices: &[VertexID]) -> Result<(), Error> {
        self.internal.pin_mut().set_mesh_edges(mesh_name, vertices)
    }
    pub fn set_mesh_triangle(
        &mut self,
        mesh_name: &str,
        first_vertex_id: VertexID,
        second_vertex_id: VertexID,
        third_vertex_id: VertexID,
    ) -> Result<(), Error> {
        self.internal.pin_mut().set_mesh_triangle(
            mesh_name,
            first_vertex_id,
            second_vertex_id,
            third_vertex_id,
        )
    }
    pub fn set_mesh_triangles(
        &mut self,
        mesh_name: &str,
        vertices: &[VertexID],
    ) -> Result<(), Error> {
        self.internal
            .pin_mut()
            .set_mesh_triangles(mesh_name, vertices)
    }
    pub fn set_mesh_quad(
        &mut self,
        mesh_name: &str,
        first_vertex_id: VertexID,
        second_vertex_id: VertexID,
        third_vertex_id: VertexID,
        fourth_vertex_id: VertexID,
    ) -> Result<(), Error> {
        self.internal.pin_mut().set_mesh_quad(
            mesh_name,
            first_vertex_id,
            second_vertex_id,
            third_vertex_id,
            fourth_vertex_id,
        )
    }
    pub fn set_mesh_quads(&mut self, mesh_name: &str, vertices: &[VertexID]) -> Result<(), Error> {
        self.internal.pin_mut().set_mesh_quads(mesh_name, vertices)
    }
    pub fn set_mesh_tetrahedron(
        &mut self,
        mesh_name: &str,
        first_vertex_id: VertexID,
        second_vertex_id: VertexID,
        third_vertex_id: VertexID,
        fourth_vertex_id: VertexID,
    ) -> Result<(), Error> {
        self.internal.pin_mut().set_mesh_tetrahedron(
            mesh_name,
            first_vertex_id,
            second_vertex_id,
            third_vertex_id,
            fourth_vertex_id,
        )
    }
    pub fn set_mesh_tetrahedra(
        &mut self,
        mesh_name: &str,
        vertices: &[VertexID],
    ) -> Result<(), Error> {
        self.internal
            .pin_mut()
            .set_mesh_tetrahedra(mesh_name, vertices)
    }

    // Data Access

    pub fn requires_initial_data(&mut self) -> Result<bool, Error> {
        self.internal.pin_mut().requires_initial_data()
    }

    pub fn write_data(
        &mut self,
        mesh_name: &str,
        data_name: &str,
        vertices: &[VertexID],
        values: &[f64],
    ) -> Result<(), Error> {
        self.internal
            .pin_mut()
            .write_data(mesh_name, data_name, vertices, values)
    }
    pub fn read_data(
        &self,
        mesh_name: &str,
        data_name: &str,
        vertices: &[VertexID],
        relative_read_dt: f64,
        values: &mut [f64],
    ) -> Result<(), Error> {
        self.internal
            .read_data(mesh_name, data_name, vertices, relative_read_dt, values)
    }

    // User Profiling

    pub fn start_profiling_section(&mut self, section_name: &str) -> Result<(), Error> {
        self.internal
            .pin_mut()
            .start_profiling_section(section_name)
    }

    pub fn stop_last_profiling_section(&mut self) -> Result<(), Error> {
        self.internal.pin_mut().stop_last_profiling_section()
    }

    // Direct Access

    pub fn set_mesh_access_region(
        &mut self,
        mesh_name: &str,
        bounding_box: &[f64],
    ) -> Result<(), Error> {
        self.internal
            .pin_mut()
            .set_mesh_access_region(mesh_name, bounding_box)
    }
    pub fn get_mesh_vertex_ids_and_coordinates(
        &self,
        mesh_name: &str,
        ids: &mut [VertexID],
        coordinates: &mut [f64],
    ) -> Result<(), Error> {
        self.internal
            .get_mesh_vertex_ids_and_coordinates(mesh_name, ids, coordinates)
    }

    // experimental: Gradient Data

    pub fn requires_gradient_data_for(
        &self,
        mesh_name: &str,
        data_name: &str,
    ) -> Result<bool, Error> {
        self.internal
            .requires_gradient_data_for(mesh_name, data_name)
    }
    pub fn write_gradient_data(
        &mut self,
        mesh_name: &str,
        data_name: &str,
        vertices: &[VertexID],
        gradients: &[f64],
    ) -> Result<(), Error> {
        self.internal
            .pin_mut()
            .write_gradient_data(mesh_name, data_name, vertices, gradients)
    }

    // experimental: JIT mapping

    pub fn write_and_map_data(
        &mut self,
        mesh_name: &str,
        data_name: &str,
        coordinates: &[f64],
        values: &[f64],
    ) -> Result<(), Error> {
        self.internal
            .pin_mut()
            .write_and_map_data(mesh_name, data_name, coordinates, values)
    }

    pub fn map_and_read_data(
        &self,
        mesh_name: &str,
        data_name: &str,
        coordinates: &[f64],
        relative_read_dt: f64,
        values: &mut [f64],
    ) -> Result<(), Error> {
        self.internal
            .map_and_read_data(mesh_name, data_name, coordinates, relative_read_dt, values)
    }
}