ndmesh/mesh/
parallel_mesh.rs1#[cfg(feature = "serde")]
3use crate::traits::{ConvertToSerializable, RONImportParallel};
4use crate::{
5 mesh::local_mesh::LocalMesh,
6 traits::{Mesh, ParallelMesh},
7 types::{Ownership, Scalar},
8};
9use mpi::traits::Communicator;
10use rlst::distributed_tools::IndexLayout;
11#[cfg(feature = "serde")]
12use std::hash::Hash;
13use std::{collections::HashMap, fmt::Debug};
14
15#[derive(Debug)]
17pub struct ParallelMeshImpl<'a, C: Communicator, G: Mesh + Sync> {
18 comm: &'a C,
19 local_mesh: LocalMesh<G>,
20 cell_layout: std::rc::Rc<IndexLayout<'a, C>>,
21}
22
23impl<'a, C: Communicator, G: Mesh + Sync> ParallelMeshImpl<'a, C, G> {
24 pub fn new(
26 comm: &'a C,
27 serial_mesh: G,
28 ownership: HashMap<G::EntityDescriptor, Vec<Ownership>>,
29 global_indices: HashMap<G::EntityDescriptor, Vec<usize>>,
30 ) -> Self {
31 let local_mesh = LocalMesh::new(serial_mesh, ownership, global_indices);
32 let owned_cell_count = local_mesh.owned_cell_count();
33 Self {
34 comm,
35 local_mesh,
36 cell_layout: std::rc::Rc::new(IndexLayout::from_local_counts(owned_cell_count, comm)),
37 }
38 }
39}
40
41#[cfg(feature = "serde")]
42impl<
43 'a,
44 EntityDescriptor: Debug + PartialEq + Eq + Clone + Copy + Hash + serde::Serialize,
45 C: Communicator + 'a,
46 G: Mesh<EntityDescriptor = EntityDescriptor> + Sync + ConvertToSerializable,
47> RONImportParallel<'a, C> for ParallelMeshImpl<'a, C, G>
48where
49 for<'de2> <G as ConvertToSerializable>::SerializableType: serde::Deserialize<'de2>,
50 for<'de2> EntityDescriptor: serde::Deserialize<'de2>,
51 Self: 'a,
52{
53 fn create_from_ron_info(comm: &'a C, local_mesh: LocalMesh<G>) -> Self {
54 let owned_cell_count = local_mesh.owned_cell_count();
55 Self {
56 comm,
57 local_mesh,
58 cell_layout: std::rc::Rc::new(IndexLayout::from_local_counts(owned_cell_count, comm)),
59 }
60 }
61}
62
63impl<T: Scalar, C: Communicator, G: Mesh<T = T> + Sync> ParallelMesh
64 for ParallelMeshImpl<'_, C, G>
65{
66 type LocalMesh = LocalMesh<G>;
67
68 type C = C;
69
70 type T = T;
71 fn comm(&self) -> &C {
72 self.comm
73 }
74 fn local_mesh(&self) -> &Self::LocalMesh {
75 &self.local_mesh
76 }
77
78 fn cell_layout(&self) -> std::rc::Rc<IndexLayout<'_, C>> {
79 self.cell_layout.clone()
80 }
81}