Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement conversion of Uniform to GeneralQuadratureTable #49

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/assembly/local/quadrature_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,30 @@ where
data: self.data,
}
}

/// Replaces the data of the quadrature table with the given data.
pub fn with_data<NewData>(self, data: NestedVec<NewData>) -> GeneralQuadratureTable<T, GeometryDim, NewData> {
GeneralQuadratureTable::from_points_weights_and_data(self.points, self.weights, data)
}

/// Replaces the data of the quadrature table by calling the given closure with every quadrature
/// point in reference coordinates and its element index.
pub fn with_data_from_fn<NewData>(
self,
mut data_fn: impl FnMut(usize, &OPoint<T, GeometryDim>, &Data) -> NewData,
) -> GeneralQuadratureTable<T, GeometryDim, NewData> {
let mut data = NestedVec::new();

for (element_index, (points, datas)) in self.points.iter().zip(self.data.iter()).enumerate() {
let mut arr = data.begin_array();

for (point, data) in points.iter().zip(datas.iter()) {
arr.push_single(data_fn(element_index, point, data));
}
}

self.with_data(data)
}
}

pub struct GeneralQuadratureParts<T, GeometryDim, Data>
Expand Down Expand Up @@ -266,6 +290,28 @@ where
}
}

impl<T, GeometryDim, Data> UniformQuadratureTable<T, GeometryDim, Data>
where
T: Scalar,
GeometryDim: DimName,
Data: Clone,
Andlon marked this conversation as resolved.
Show resolved Hide resolved
DefaultAllocator: Allocator<T, GeometryDim>,
{
pub fn to_general(&self, num_elements: usize) -> GeneralQuadratureTable<T, GeometryDim, Data> {
let mut points = NestedVec::new();
let mut weights = NestedVec::new();
let mut data = NestedVec::new();

for _ in 0..num_elements {
points.push(&self.points);
weights.push(&self.weights);
data.push(&self.data);
}

GeneralQuadratureTable::from_points_weights_and_data(points, weights, data)
}
}

impl<T, GeometryDim, Data> QuadratureTable<T, GeometryDim> for UniformQuadratureTable<T, GeometryDim, Data>
where
T: Scalar,
Expand Down