diff --git a/bem/src/assembly/batched.rs b/bem/src/assembly/batched.rs index 26304eb2..9d23af06 100644 --- a/bem/src/assembly/batched.rs +++ b/bem/src/assembly/batched.rs @@ -99,6 +99,14 @@ impl SparseMatrixData { shape, } } + fn new_known_size(shape: [usize; 2], size: usize) -> Self { + Self { + data: Vec::with_capacity(size), + rows: Vec::with_capacity(size), + cols: Vec::with_capacity(size), + shape, + } + } fn add(&mut self, other: SparseMatrixData) { debug_assert!(self.shape[0] == other.shape[0]); debug_assert!(self.shape[1] == other.shape[1]); @@ -136,7 +144,10 @@ fn assemble_batch_singular<'a>( trial_table: &Array, 4>, 4>, test_table: &Array, 4>, 4>, ) -> SparseMatrixData { - let mut output = SparseMatrixData::::new(shape); + let mut output = SparseMatrixData::::new_known_size( + shape, + cell_pairs.len() * trial_space.element().dim() * test_space.element().dim(), + ); let npts = weights.len(); debug_assert!(weights.len() == npts); debug_assert!(test_points.shape()[0] == npts);