pub enum Grid1D<Domain1D: IntervalFinitePositiveLengthTrait> {
Uniform(Grid1DUniform<Domain1D>),
NonUniform(Grid1DNonUniform<Domain1D>),
}Expand description
An enum representing a one-dimensional grid, which defines a partition of a bounded interval with positive length.
The Grid1D enum models a set of points that partition a bounded interval into adjacent, non-overlapping subintervals.
It supports both uniform grids, where all subintervals have the same length, and non-uniform grids, where
subintervals can have varying lengths.
§Type Parameters
Point1DType: The type of the points in the grid. It must implement theRealScalartrait, ensuring that the points are real numbers with additional mathematical properties.
§Variants
Uniform: Represents a grid where all subintervals have the same length. This is modeled by theGrid1DUniformstruct.NonUniform: Represents a grid where subintervals can have varying lengths. This is modeled by theGrid1DNonUniformstruct.
§Features
- Uniform Grids: All subintervals have the same length, making them suitable for evenly spaced computations.
- Non-Uniform Grids: Subintervals can have varying lengths, allowing for more flexibility in grid design.
- Integration with IntervalPartition: The
Grid1Denum implements theIntervalPartitiontrait, providing methods for accessing intervals and performing operations on the grid.
§Examples
§Creating a Uniform Grid
use grid1d::{
Grid1D, HasCoords1D, IntervalPartition,
intervals::IntervalClosed,
scalars::NumIntervals,
};
use std::ops::Deref;
use try_create::TryNew;
let domain = IntervalClosed::new(0.0, 1.0);
let grid = Grid1D::uniform(domain, NumIntervals::try_new(4).unwrap());
assert_eq!(grid.coords().deref(), &[0.0, 0.25, 0.5, 0.75, 1.0]);
assert_eq!(grid.num_intervals().as_ref(), &4);§Creating a Non-Uniform Grid
use grid1d::{
Coords1D, Grid1D, HasCoords1D,
intervals::IntervalClosed,
};
use sorted_vec::partial::SortedSet;
use std::ops::Deref;
let coords = SortedSet::from_unsorted(vec![0.0, 0.5, 1.0, 2.0]);
let domain = IntervalClosed::new(0.0, 2.0);
let grid = Grid1D::try_from_sorted(domain, coords).unwrap();
assert_eq!(grid.coords().deref(), &[0.0, 0.5, 1.0, 2.0]);§Handling Errors
use grid1d::{
Grid1D, ErrorsGrid1D,
intervals::IntervalClosed,
};
use sorted_vec::partial::SortedSet;
let coords = SortedSet::from_unsorted(vec![0.0]); // Only one point provided
let domain = IntervalClosed::new(0.0, 1.0);
let err = Grid1D::try_from_sorted(domain, coords).unwrap_err();
assert!(matches!(err, ErrorsGrid1D::RequiredAtLeastTwoDistinctPoints { .. }));Variants§
Uniform(Grid1DUniform<Domain1D>)
All the intervals defined by the Grid1D object have the same length.
NonUniform(Grid1DNonUniform<Domain1D>)
The intervals defined by the Grid1D object have not the same length.
Implementations§
Source§impl<Domain1D: IntervalFinitePositiveLengthTrait> Grid1D<Domain1D>
impl<Domain1D: IntervalFinitePositiveLengthTrait> Grid1D<Domain1D>
Sourcepub fn uniform(domain: Domain1D, num_intervals: NumIntervals) -> Self
pub fn uniform(domain: Domain1D, num_intervals: NumIntervals) -> Self
Creates a new uniform grid over the specified domain with the given number of intervals.
§Parameters
domain: The closed interval over which the grid is defined.num_intervals: The number of subintervals in the grid.
§Returns
A Grid1D instance representing a uniform grid.
§Example
use grid1d::{
Grid1D, HasCoords1D, IntervalPartition,
intervals::IntervalClosed,
scalars::NumIntervals,
};
use std::ops::Deref;
use try_create::TryNew;
let domain = IntervalClosed::new(0., 1.);
let grid = Grid1D::uniform(domain, NumIntervals::try_new(4).unwrap());
assert_eq!(grid.coords().deref(), &[0., 0.25, 0.5, 0.75, 1.]);Sourcepub fn try_from_sorted(
domain: Domain1D,
values: SortedSet<Domain1D::RealType>,
) -> Result<Self, ErrorsGrid1D<Domain1D>>
pub fn try_from_sorted( domain: Domain1D, values: SortedSet<Domain1D::RealType>, ) -> Result<Self, ErrorsGrid1D<Domain1D>>
Creates a new grid from a sorted set of points (at least 2).
§Parameters
values: A sorted set of points defining the grid.
§Returns
Ok(Self): If at least two points are provided.Err<ErrorsGrid1D>: If fewer than two points are provided.
§Errors
- Returns
ErrorsGrid1D::RequiredAtLeastTwoDistinctPointsif fewer than two points are provided.
§Example
use grid1d::{
Grid1D, HasCoords1D,
intervals::IntervalClosed,
};
use sorted_vec::partial::SortedSet;
use std::ops::Deref;
let coords = SortedSet::from_unsorted(vec![0., 0.5, 1., 2.]);
let domain = IntervalClosed::new(0.0, 2.0);
let grid = Grid1D::try_from_sorted(domain, coords).unwrap();
assert_eq!(grid.coords().deref(), &[0., 0.5, 1., 2.]);pub fn try_from_coords( domain: Domain1D, coords: Coords1D<Domain1D::RealType>, ) -> Result<Self, ErrorsGrid1D<Domain1D>>
Trait Implementations§
Source§impl<Domain1D: IntervalFinitePositiveLengthTrait> HasCoords1D for Grid1D<Domain1D>
impl<Domain1D: IntervalFinitePositiveLengthTrait> HasCoords1D for Grid1D<Domain1D>
Source§type Point1DType = <Domain1D as IntervalOperations>::RealType
type Point1DType = <Domain1D as IntervalOperations>::RealType
The type of the 1D points.
Source§fn coords(&self) -> &Coords1D<Domain1D::RealType>
fn coords(&self) -> &Coords1D<Domain1D::RealType>
Get the coordinates of the 1D points. Read more
Source§fn num_points(&self) -> PositiveNumPoints1D
fn num_points(&self) -> PositiveNumPoints1D
Get the number of points. Read more
Source§impl<Domain1D: IntervalFinitePositiveLengthTrait> HasDomain1D for Grid1D<Domain1D>
impl<Domain1D: IntervalFinitePositiveLengthTrait> HasDomain1D for Grid1D<Domain1D>
Source§impl<Domain1D: IntervalInPartitionBuilder> IntervalPartition for Grid1D<Domain1D>
impl<Domain1D: IntervalInPartitionBuilder> IntervalPartition for Grid1D<Domain1D>
type UniformlyRefinedGrid1DType = Grid1D<Domain1D>
fn refine_uniform( self, num_extra_points_each_interval: &PositiveNumPoints1D, ) -> Grid1DUniformRefinement<Self>
fn refine( self, intervals_to_refine: &[(IntervalId, PositiveNumPoints1D)], ) -> Grid1DNonUniformRefinement<Self>
Source§fn num_intervals(&self) -> NumIntervals
fn num_intervals(&self) -> NumIntervals
Get the number of intervals defining the partition. Read more
Source§fn interval(&self, i: &IntervalId) -> SubIntervalInPartition<Self::Point1DType>
fn interval(&self, i: &IntervalId) -> SubIntervalInPartition<Self::Point1DType>
Returns the
i-th interval as SubIntervalInPartition.Source§fn iter_intervals(
&self,
) -> impl Iterator<Item = (IntervalId, SubIntervalInPartition<Self::Point1DType>)> + '_
fn iter_intervals( &self, ) -> impl Iterator<Item = (IntervalId, SubIntervalInPartition<Self::Point1DType>)> + '_
Returns an iterator over all intervals in the partition. Read more
Source§fn interval_length(
&self,
interval_id: &IntervalId,
) -> PositiveRealScalar<Self::Point1DType>
fn interval_length( &self, interval_id: &IntervalId, ) -> PositiveRealScalar<Self::Point1DType>
Returns the interval length at the specified index. Read more
Source§fn find_interval_id_of_point(&self, x: &Self::Point1DType) -> IntervalId
fn find_interval_id_of_point(&self, x: &Self::Point1DType) -> IntervalId
Returns the id of the interval that contains_point the value
x. Read moreSource§fn try_find_interval_id_of_point(
&self,
x: &Self::Point1DType,
) -> Option<IntervalId>
fn try_find_interval_id_of_point( &self, x: &Self::Point1DType, ) -> Option<IntervalId>
Finds the ID of the interval containing the point
x, returning None if the point is outside the domain. Read moreSource§fn find_intervals_for_points(
&self,
points: &[Self::Point1DType],
) -> Vec<Option<IntervalId>>
fn find_intervals_for_points( &self, points: &[Self::Point1DType], ) -> Vec<Option<IntervalId>>
Finds all intervals that contain any of the given points. Read more
Source§fn max_interval_length(&self) -> PositiveRealScalar<Self::Point1DType>
fn max_interval_length(&self) -> PositiveRealScalar<Self::Point1DType>
Returns the maximum interval length in the partition. Read more
Source§fn min_interval_length(&self) -> PositiveRealScalar<Self::Point1DType>
fn min_interval_length(&self) -> PositiveRealScalar<Self::Point1DType>
Returns the minimum interval length in the partition. Read more
Source§fn uniformity_ratio(&self) -> PositiveRealScalar<Self::Point1DType>
fn uniformity_ratio(&self) -> PositiveRealScalar<Self::Point1DType>
Returns the ratio between maximum and minimum interval lengths. Read more
Source§fn intervals_in_intersection<IntervalType: IntervalFinitePositiveLengthTrait<RealType = Self::Point1DType>>(
&self,
domain_in: &IntervalType,
) -> Vec<(IntervalId, IntervalFinitePositiveLength<Self::Point1DType>)>
fn intervals_in_intersection<IntervalType: IntervalFinitePositiveLengthTrait<RealType = Self::Point1DType>>( &self, domain_in: &IntervalType, ) -> Vec<(IntervalId, IntervalFinitePositiveLength<Self::Point1DType>)>
impl<Domain1D: IntervalFinitePositiveLengthTrait> StructuralPartialEq for Grid1D<Domain1D>
Auto Trait Implementations§
impl<Domain1D> Freeze for Grid1D<Domain1D>
impl<Domain1D> RefUnwindSafe for Grid1D<Domain1D>
impl<Domain1D> Send for Grid1D<Domain1D>where
Domain1D: Send,
impl<Domain1D> Sync for Grid1D<Domain1D>where
Domain1D: Sync,
impl<Domain1D> Unpin for Grid1D<Domain1D>
impl<Domain1D> UnwindSafe for Grid1D<Domain1D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.