Skip to content

Commit

Permalink
Add cell_dofs_unchecked (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
mscroggs authored Aug 31, 2024
1 parent edc96b3 commit 776ea46
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/assembly/boundary/assemblers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
Expand All @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand Down
6 changes: 6 additions & 0 deletions src/function/function_space/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion src/function/function_space/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions src/traits/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReferenceCellType, Vec<Vec<usize>>>;

Expand Down

0 comments on commit 776ea46

Please sign in to comment.