Skip to content

Commit

Permalink
WIP: Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tbetcke committed Jan 11, 2025
1 parent b2c2029 commit a36a478
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/evaluator_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::{collections::HashMap, marker::PhantomData};

use bempp_distributed_tools::GhostCommunicator;
use bempp_distributed_tools::{GhostCommunicator, IndexLayoutFromLocalCounts};

Check failure on line 5 in src/evaluator_tools.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

unused import: `IndexLayoutFromLocalCounts`

Check failure on line 5 in src/evaluator_tools.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, openmpi, --features "strict")

unused import: `IndexLayoutFromLocalCounts`
use green_kernels::{traits::Kernel, types::GreenKernelEvalType};
use itertools::{izip, Itertools};
use mpi::traits::{Communicator, Equivalence};
Expand All @@ -14,8 +14,13 @@ use ndgrid::{

use rayon::prelude::*;
use rlst::{
operator::interface::{
distributed_sparse_operator::DistributedCsrMatrixOperator, DistributedArrayVectorSpace,
operator::{
interface::{
distributed_array_vector_space,

Check failure on line 19 in src/evaluator_tools.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

unused import: `distributed_array_vector_space`

Check failure on line 19 in src/evaluator_tools.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, openmpi, --features "strict")

unused import: `distributed_array_vector_space`
distributed_sparse_operator::DistributedCsrMatrixOperatorImpl,
DistributedArrayVectorSpace,
},
Operator,
},
rlst_array_from_slice2, rlst_dynamic_array1, rlst_dynamic_array2, rlst_dynamic_array3,
rlst_dynamic_array4, Array, AsApply, DefaultIterator, DistributedCsrMatrix, DistributedVector,
Expand All @@ -35,11 +40,9 @@ pub fn basis_to_point_map<
Space: FunctionSpaceTrait<T = T>,
>(
function_space: &Space,
domain_space: &'a DistributedArrayVectorSpace<'a, DomainLayout, T>,
range_space: &'a DistributedArrayVectorSpace<'a, RangeLayout, T>,
quadrature_points: &[T::Real],
quadrature_weights: &[T::Real],
) -> DistributedCsrMatrixOperator<'a, DomainLayout, RangeLayout, T, C>
) -> Operator<DistributedCsrMatrixOperatorImpl<'a, DomainLayout, RangeLayout, T, C>>

Check failure on line 45 in src/evaluator_tools.rs

View workflow job for this annotation

GitHub Actions / Build docs

struct takes 0 lifetime arguments but 1 lifetime argument was supplied
where
T::Real: Equivalence,
{
Expand Down Expand Up @@ -69,14 +72,10 @@ where
assert_eq!(quadrature_points.len() % tdim, 0);
assert_eq!(quadrature_points.len() / tdim, n_quadrature_points);

// Check that domain space and function space are compatible.

let n_domain_dofs = domain_space.index_layout().number_of_global_indices();
let n_range_dofs = range_space.index_layout().number_of_global_indices();

assert_eq!(function_space.local_size(), n_domain_dofs,);
// Assign number of domain and range dofs.

assert_eq!(n_cells * n_quadrature_points, n_range_dofs);
let n_domain_dofs = function_space.local_size();
let n_range_dofs = n_cells * n_quadrature_points;

// All the dimensions are OK. Let's get to work. We need to iterate through the elements,
// get the attached global dofs and the corresponding jacobian map.
Expand Down
27 changes: 27 additions & 0 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//mod function_space;

use bempp_distributed_tools::IndexLayoutFromLocalCounts;
use mpi::request::WaitGuard;
use mpi::traits::{Communicator, Destination, Source};
use ndelement::ciarlet::CiarletElement;
Expand All @@ -13,6 +14,7 @@ use ndgrid::{traits::Grid, types::Ownership};
use rlst::{MatrixInverse, RlstScalar};
use std::collections::HashMap;
use std::marker::PhantomData;
use std::ops::Index;

Check failure on line 17 in src/function.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

unused import: `std::ops::Index`

Check failure on line 17 in src/function.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, openmpi, --features "strict")

unused import: `std::ops::Index`

type DofList = Vec<Vec<usize>>;
type OwnerData = Vec<(usize, usize, usize, usize)>;
Expand Down Expand Up @@ -58,6 +60,12 @@ pub trait LocalFunctionSpaceTrait {

/// Get ownership of a local DOF
fn ownership(&self, local_dof_index: usize) -> Ownership;

/// Get the local indices of the support cells associated with this space.
///
/// The vector of support cells is sorted in ascending order and may contain
/// ghost cells who are not owned by the current process.
fn support_cells(&self) -> &[usize];
}

/// A function space
Expand All @@ -79,6 +87,9 @@ pub trait FunctionSpaceTrait: LocalFunctionSpaceTrait {

/// Get the local function space
fn local_space(&self) -> &Self::LocalFunctionSpace;

/// Return the index layout associated with the function space.
fn index_layout(&self) -> &IndexLayoutFromLocalCounts<'_, Self::C>;
}

/// Definition of a local function space.
Expand All @@ -95,6 +106,7 @@ pub struct LocalFunctionSpace<
global_size: usize,
global_dof_numbers: Vec<usize>,
ownership: Vec<Ownership>,
support_cells: Vec<usize>,
}

impl<
Expand Down Expand Up @@ -124,6 +136,7 @@ impl<
global_size,
global_dof_numbers,
ownership,
support_cells: (0..local_size).collect(),
}
}
}
Expand Down Expand Up @@ -245,6 +258,10 @@ impl<
fn ownership(&self, local_dof_index: usize) -> Ownership {
self.ownership[local_dof_index]
}

fn support_cells(&self) -> &[usize] {
self.support_cells.as_slice()
}
}

/// Implementation of a general function space.
Expand All @@ -256,6 +273,7 @@ pub struct FunctionSpace<
> {
grid: &'a GridImpl,
local_space: LocalFunctionSpace<'a, T, GridImpl::LocalGrid>,
index_layout: IndexLayoutFromLocalCounts<'a, C>,
_marker: PhantomData<(C, T)>,
}

Expand Down Expand Up @@ -401,6 +419,7 @@ where
global_dof_numbers,
ownership,
),
index_layout: IndexLayoutFromLocalCounts::new(dofmap_size, comm),
_marker: PhantomData,
}

Expand Down Expand Up @@ -471,6 +490,10 @@ impl<
// Syntactical workaround as rust-analyzer mixed up this ownership with entity ownership.
LocalFunctionSpaceTrait::ownership(&self.local_space, local_dof_index)
}

fn support_cells(&self) -> &[usize] {
self.local_space.support_cells()
}
}

impl<
Expand All @@ -493,6 +516,10 @@ impl<
fn local_space(&self) -> &Self::LocalFunctionSpace {
&self.local_space
}

fn index_layout(&self) -> &IndexLayoutFromLocalCounts<'_, Self::C> {
&self.index_layout
}
}

/// Assign DOFs to entities.
Expand Down

0 comments on commit a36a478

Please sign in to comment.