diff --git a/src/assembly/boundary/assemblers.rs b/src/assembly/boundary/assemblers.rs index 4d5d9f33..7453a0c7 100644 --- a/src/assembly/boundary/assemblers.rs +++ b/src/assembly/boundary/assemblers.rs @@ -212,8 +212,8 @@ fn assemble_batch_singular< a.set_trial_cell(*trial_cell); a.assemble(&mut local_mat); - let test_dofs = test_space.cell_dofs(*test_cell).unwrap(); - let trial_dofs = trial_space.cell_dofs(*trial_cell).unwrap(); + let test_dofs = unsafe { test_space.cell_dofs_unchecked(*test_cell) }; + let trial_dofs = unsafe { trial_space.cell_dofs_unchecked(*trial_cell) }; for (trial_dof, col) in izip!(trial_dofs, local_mat.col_iter()) { for (test_dof, entry) in izip!(test_dofs, col.iter()) { @@ -292,7 +292,7 @@ fn assemble_batch_nonadjacent< for trial_cell in trial_cells { a.set_trial_cell(*trial_cell); - let trial_dofs = trial_space.cell_dofs(*trial_cell).unwrap(); + let trial_dofs = unsafe { trial_space.cell_dofs_unchecked(*trial_cell) }; for (i, test_cell) in test_cells.iter().enumerate() { if neighbours(test_grid, trial_grid, *test_cell, *trial_cell) { continue; @@ -301,7 +301,7 @@ fn assemble_batch_nonadjacent< a.set_test_cell_from_index(i); a.assemble(&mut local_mat); - let test_dofs = test_space.cell_dofs(*test_cell).unwrap(); + let test_dofs = unsafe { test_space.cell_dofs_unchecked(*test_cell) }; for (trial_dof, col) in izip!(trial_dofs, local_mat.col_iter()) { for (test_dof, entry) in izip!(test_dofs, col.iter()) { @@ -384,8 +384,8 @@ fn assemble_batch_singular_correction< a.assemble(&mut local_mat); - let test_dofs = test_space.cell_dofs(*test_cell).unwrap(); - let trial_dofs = trial_space.cell_dofs(*trial_cell).unwrap(); + let test_dofs = unsafe { test_space.cell_dofs_unchecked(*test_cell) }; + let trial_dofs = unsafe { trial_space.cell_dofs_unchecked(*trial_cell) }; for (trial_dof, col) in izip!(trial_dofs, local_mat.col_iter()) { for (test_dof, entry) in izip!(test_dofs, col.iter()) { diff --git a/src/function/function_space/parallel.rs b/src/function/function_space/parallel.rs index f6bd11ce..c22becf1 100644 --- a/src/function/function_space/parallel.rs +++ b/src/function/function_space/parallel.rs @@ -55,6 +55,9 @@ impl< fn global_size(&self) -> usize { self.global_size } + unsafe fn cell_dofs_unchecked(&self, cell: usize) -> &[usize] { + self.serial_space.cell_dofs_unchecked(cell) + } fn cell_dofs(&self, cell: usize) -> Option<&[usize]> { self.serial_space.cell_dofs(cell) } @@ -278,6 +281,9 @@ impl< fn global_size(&self) -> usize { self.local_space.global_size() } + unsafe fn cell_dofs_unchecked(&self, cell: usize) -> &[usize] { + self.local_space.cell_dofs_unchecked(cell) + } fn cell_dofs(&self, cell: usize) -> Option<&[usize]> { self.local_space.cell_dofs(cell) } diff --git a/src/function/function_space/serial.rs b/src/function/function_space/serial.rs index 76041767..a1d0312c 100644 --- a/src/function/function_space/serial.rs +++ b/src/function/function_space/serial.rs @@ -82,9 +82,12 @@ impl< fn global_size(&self) -> usize { self.size } + unsafe fn cell_dofs_unchecked(&self, cell: usize) -> &[usize] { + self.cell_dofs.get_unchecked(cell) + } fn cell_dofs(&self, cell: usize) -> Option<&[usize]> { if cell < self.cell_dofs.len() { - Some(&self.cell_dofs[cell]) + Some(unsafe { self.cell_dofs_unchecked(cell) }) } else { None } diff --git a/src/traits/function.rs b/src/traits/function.rs index 56a9f3ae..e167466c 100644 --- a/src/traits/function.rs +++ b/src/traits/function.rs @@ -41,6 +41,12 @@ pub trait FunctionSpace { /// Get the local DOF numbers associated with a cell fn cell_dofs(&self, cell: usize) -> Option<&[usize]>; + /// Get the local DOF numbers associated with a cell + /// + /// # Safety + /// The function uses unchecked array access + unsafe fn cell_dofs_unchecked(&self, cell: usize) -> &[usize]; + /// Compute a colouring of the cells so that no two cells that share an entity with DOFs associated with it are assigned the same colour fn cell_colouring(&self) -> HashMap>>;