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
//! Traits for boundary assembly
mod integrands;
pub use integrands::{Access1D, Access2D, BoundaryIntegrand, GeometryAccess};

use super::CellGeometry;
use crate::assembly::common::RlstArray;
use crate::traits::FunctionSpace;
#[cfg(feature = "mpi")]
use crate::traits::ParallelFunctionSpace;
#[cfg(feature = "mpi")]
use mpi::traits::Communicator;
use ndelement::types::ReferenceCellType;
use rlst::{CsrMatrix, RandomAccessMut, RawAccessMut, RlstScalar, Shape};
use std::collections::HashMap;

pub trait CellPairAssembler {
    //! Assembler for the contributions from a pair of cells
    /// Scalar type
    type T: RlstScalar;

    /// Assemble contributions into `local_mat`
    fn assemble(&mut self, local_mat: &mut RlstArray<Self::T, 2>);
    /// Set the test cell
    fn set_test_cell(&mut self, test_cell: usize);
    /// Set the trial cell
    fn set_trial_cell(&mut self, trial_cell: usize);
}

pub trait BoundaryAssembly {
    //! Functions for boundary assembly
    /// Scalar type
    type T: RlstScalar;

    /// Assemble the singular contributions into a dense matrix
    fn assemble_singular_into_dense<
        Space: FunctionSpace<T = Self::T> + Sync,
        Array2: RandomAccessMut<2, Item = Self::T> + Shape<2> + RawAccessMut<Item = Self::T>,
    >(
        &self,
        output: &mut Array2,
        trial_space: &Space,
        test_space: &Space,
    );

    /// Assemble the singular contributions into a CSR sparse matrix
    fn assemble_singular_into_csr<Space: FunctionSpace<T = Self::T> + Sync>(
        &self,
        trial_space: &Space,
        test_space: &Space,
    ) -> CsrMatrix<Self::T>;

    /// Assemble the singular correction into a dense matrix
    ///
    /// The singular correction is the contribution is the terms for adjacent cells are assembled using an (incorrect) non-singular quadrature rule
    fn assemble_singular_correction_into_dense<
        Space: FunctionSpace<T = Self::T> + Sync,
        Array2: RandomAccessMut<2, Item = Self::T> + Shape<2> + RawAccessMut<Item = Self::T>,
    >(
        &self,
        output: &mut Array2,
        trial_space: &Space,
        test_space: &Space,
    );

    /// Assemble the singular correction into a CSR matrix
    ///
    /// The singular correction is the contribution is the terms for adjacent cells are assembled using an (incorrect) non-singular quadrature rule
    fn assemble_singular_correction_into_csr<Space: FunctionSpace<T = Self::T> + Sync>(
        &self,
        trial_space: &Space,
        test_space: &Space,
    ) -> CsrMatrix<Self::T>;

    /// Assemble into a dense matrix
    fn assemble_into_dense<
        Space: FunctionSpace<T = Self::T> + Sync,
        Array2: RandomAccessMut<2, Item = Self::T> + Shape<2> + RawAccessMut<Item = Self::T>,
    >(
        &self,
        output: &mut Array2,
        trial_space: &Space,
        test_space: &Space,
    );

    /// Assemble the non-singular contributions into a dense matrix
    fn assemble_nonsingular_into_dense<
        Space: FunctionSpace<T = Self::T> + Sync,
        Array2: RandomAccessMut<2, Item = Self::T> + Shape<2> + RawAccessMut<Item = Self::T>,
    >(
        &self,
        output: &mut Array2,
        trial_space: &Space,
        test_space: &Space,
        trial_colouring: &HashMap<ReferenceCellType, Vec<Vec<usize>>>,
        test_colouring: &HashMap<ReferenceCellType, Vec<Vec<usize>>>,
    );
}

#[cfg(feature = "mpi")]
pub trait ParallelBoundaryAssembly: BoundaryAssembly {
    //! Functions for parallel boundary assembly

    /// Assemble the singular contributions into a CSR sparse matrix, indexed by global DOF numbers
    fn parallel_assemble_singular_into_csr<
        C: Communicator,
        Space: ParallelFunctionSpace<C, T = Self::T>,
    >(
        &self,
        trial_space: &Space,
        test_space: &Space,
    ) -> CsrMatrix<Self::T>;

    /// Assemble the singular contributions into a CSR sparse matrix, indexed by global DOF numbers
    fn parallel_assemble_singular_correction_into_csr<
        C: Communicator,
        Space: ParallelFunctionSpace<C, T = Self::T>,
    >(
        &self,
        trial_space: &Space,
        test_space: &Space,
    ) -> CsrMatrix<Self::T>;
}