Skip to main content

conspire/geometry/ntree/dual/octree/
mod.rs

1#[cfg(test)]
2#[cfg(feature = "netcdf")]
3mod test;
4
5mod edge;
6mod face;
7mod vertex;
8
9use crate::{
10    geometry::{
11        Coordinate,
12        mesh::{Connectivity, Mesh},
13        ntree::{
14            Octree,
15            dual::{
16                Dualization, Initialize, NodeMap,
17                octree::{
18                    edge::edge_transitions, face::face_transition, vertex::vertex_transitions,
19                },
20            },
21            node::split::Split,
22        },
23    },
24    math::Scalar,
25};
26use std::ops::Add;
27
28const D: usize = 3;
29const L: usize = 4;
30const M: usize = 6;
31const N: usize = 8;
32
33const fn facet_direction(facet: usize) -> Coordinate<D> {
34    match facet {
35        0 => Coordinate::const_from([-1.0, 0.0, 0.0]),
36        1 => Coordinate::const_from([1.0, 0.0, 0.0]),
37        2 => Coordinate::const_from([0.0, -1.0, 0.0]),
38        3 => Coordinate::const_from([0.0, 1.0, 0.0]),
39        4 => Coordinate::const_from([0.0, 0.0, -1.0]),
40        5 => Coordinate::const_from([0.0, 0.0, 1.0]),
41        _ => panic!(),
42    }
43}
44
45impl<T, U> Dualization<D> for Octree<T, U>
46where
47    T: Add<Output = T> + Copy + PartialOrd + Split + Into<Scalar> + Into<usize>,
48    U: Copy + Into<usize>,
49{
50    fn dualize(&mut self) -> Mesh<D> {
51        let (center_nodes, mut coordinates, mut node_index, mut connectivity) = self.initialize();
52        let mut nodes_map = NodeMap::new();
53        face_transition(
54            self,
55            &center_nodes,
56            &mut coordinates,
57            &mut connectivity,
58            &mut node_index,
59            &mut nodes_map,
60        );
61        edge_transitions(
62            self,
63            &center_nodes,
64            &mut coordinates,
65            &mut connectivity,
66            &mut node_index,
67            &mut nodes_map,
68            self.balanced,
69        );
70        vertex_transitions(self, &center_nodes, &mut connectivity, &nodes_map);
71        self.rescale_coordinates(&mut coordinates);
72        (
73            vec![Connectivity::Hexahedral(connectivity.into())],
74            coordinates,
75        )
76            .into()
77    }
78}