pub struct LatticeCyclic<const D: usize> { /* private fields */ }
Expand description

A Cyclic lattice in space. Does not store point and links but is used to generate them.

The generic parameter D is the dimension.

This lattice is Cyclic more precisely if the lattice has N points in each direction. Then we can move alongside a direction going though point 0, 1, … N-1. The next step in the same direction goes back to the point at 0.

This structure is used for operation on LatticePoint, LatticeLink and LatticeLinkCanonical. access data on the lattice. These data are stored LinkMatrix and EField which are just a wrapper around a Vec. LatticeCyclic is used to convert the lattice element to an index to access these data.

This contain very few data and can be cloned at almost no cost even though it does not implement Copy.

Implementations§

source§

impl<const D: usize> LatticeCyclic<D>

source

pub const fn dim_st() -> usize

Number space + time dimension, this is the D parameter.

Not to confuse with LatticeCyclic::dim which is the number of point per dimension.

see LatticeLinkCanonical, a conical link is a link whose direction is always positive. That means that a link form [x, y, z, t] with direction -x the link return is [x - 1, y, z, t] (modulo the lattice::dim()``) with direction +x`

Example
fn main() -> Result<(), Box<dyn std::error::Error>> {
let lattice = LatticeCyclic::<4>::new(1_f64, 4)?;
let point = LatticePoint::<4>::new([1, 0, 2, 0].into());
assert_eq!(
    lattice.link_canonical(point, DirectionEnum::XNeg.into()),
    LatticeLinkCanonical::new(LatticePoint::new([0, 0, 2, 0].into()), DirectionEnum::XPos.into()).ok_or(ImplementationError::OptionWithUnexpectedNone)?
);
assert_eq!(
    lattice.link_canonical(point, DirectionEnum::XPos.into()),
    LatticeLinkCanonical::new(LatticePoint::new([1, 0, 2, 0].into()), DirectionEnum::XPos.into()).ok_or(ImplementationError::OptionWithUnexpectedNone)?
);
assert_eq!(
    lattice.link_canonical(point, DirectionEnum::YNeg.into()),
    LatticeLinkCanonical::new(LatticePoint::new([1, 3, 2, 0].into()), DirectionEnum::YPos.into()).ok_or(ImplementationError::OptionWithUnexpectedNone)?
);

Return a link build from pos and dir.

It is similar to LatticeLink::new. It however enforce that the point is inside the bounds. If it is not, it will use the modulus of the bound.

Example
fn main() -> Result<(), Box<dyn std::error::Error>> {
let l = LatticeCyclic::<3>::new(1_f64, 4)?;
let dir = Direction::new(0, true).ok_or(ImplementationError::OptionWithUnexpectedNone)?;
let pt = LatticePoint::new(SVector::<_, 3>::new(1, 2, 5));
let link = l.link(pt, dir);
assert_eq!(
    *link.pos(),
    LatticePoint::new(SVector::<_, 3>::new(1, 2, 1))
);
source

pub fn into_canonical(&self, l: LatticeLink<D>) -> LatticeLinkCanonical<D>

source

pub const fn dim(&self) -> usize

Get the number of points in a single direction.

use LatticeCyclic::number_of_points for the total number of points. Not to confuse with LatticeCyclic::dim_st which is the dimension of space-time.

source

pub fn get_points(&self) -> IteratorLatticePoint<'_, D>

Get an Iterator over all points of the lattice.

Example
for i in [4, 8, 16, 32, 64].into_iter() {
    let l = LatticeCyclic::<4>::new(1_f64, i)?;
    assert_eq!(l.get_points().size_hint().0, l.number_of_points());
}

Get an Iterator over all canonical link of the lattice.

Example
for i in [4, 8, 16, 32, 64].into_iter() {
    let l = LatticeCyclic::<4>::new(1_f64, i)?;
    assert_eq!(
        l.get_links().size_hint().0,
        l.number_of_canonical_links_space()
    );
}
source

pub fn new(size: Real, dim: usize) -> Result<Self, LatticeInitializationError>

create a new lattice with size the lattice size parameter, and dim the number of points in each spatial dimension.

Errors

Size should be greater than 0 and dim greater or equal to 2, otherwise return an error.

Total number of canonical links oriented in space for a set time.

Basically the number of element return by LatticeCyclic::get_links.

Example
let l = LatticeCyclic::<4>::new(1_f64, 8)?;
assert_eq!(l.number_of_canonical_links_space(), 8_usize.pow(4) * 4);

let l = LatticeCyclic::<4>::new(1_f64, 16)?;
assert_eq!(l.number_of_canonical_links_space(), 16_usize.pow(4) * 4);

let l = LatticeCyclic::<3>::new(1_f64, 8)?;
assert_eq!(l.number_of_canonical_links_space(), 8_usize.pow(3) * 3);
source

pub fn number_of_points(&self) -> usize

Total number of point in the lattice for a set time.

Example
let l = LatticeCyclic::<4>::new(1_f64, 8)?;
assert_eq!(l.number_of_points(), 8_usize.pow(4));

let l = LatticeCyclic::<4>::new(1_f64, 16)?;
assert_eq!(l.number_of_points(), 16_usize.pow(4));

let l = LatticeCyclic::<3>::new(1_f64, 8)?;
assert_eq!(l.number_of_points(), 8_usize.pow(3));
source

pub const fn size(&self) -> Real

Return the lattice size factor.

source

pub fn add_point_direction( &self, point: LatticePoint<D>, dir: &Direction<D> ) -> LatticePoint<D>

Get the next point in the lattice following the direction dir. It follows the Cyclic property of the lattice.

Example
let lattice = LatticeCyclic::<4>::new(1_f64, 4)?;
let point = LatticePoint::<4>::from([1, 0, 2, 0]);
assert_eq!(
    lattice.add_point_direction(point, &DirectionEnum::XPos.into()),
    LatticePoint::from([2, 0, 2, 0])
);
// In the following case we get [_, 3, _, _] because `dim = 4`, and this lattice is Cyclic.
assert_eq!(
    lattice.add_point_direction(point, &DirectionEnum::YNeg.into()),
    LatticePoint::from([1, 3, 2, 0])
);
source

pub fn add_point_direction_n( &self, point: LatticePoint<D>, dir: &Direction<D>, shift_number: usize ) -> LatticePoint<D>

Returns the point given y moving shift_number times in direction dir from position point. It follows the Cyclic property of the lattice.

It is equivalent of doing Self::add_point_direction n times.

Example
let lattice = LatticeCyclic::<4>::new(1_f64, 4)?;
let point = LatticePoint::<4>::from([1, 0, 2, 0]);
assert_eq!(
    lattice.add_point_direction_n(point, &DirectionEnum::XPos.into(), 2),
    LatticePoint::from([3, 0, 2, 0])
);
// In the following case we get [_, 1, _, _] because `dim = 4`, and this lattice is Cyclic.
assert_eq!(
    lattice.add_point_direction_n(point, &DirectionEnum::YNeg.into(), 3),
    LatticePoint::from([1, 1, 2, 0])
);

Returns whether the number of canonical link is the same as the length of links.

source

pub fn has_compatible_length_e_field(&self, e_field: &EField<D>) -> bool

Returns wether the number of point is the same as the length of e_field.

source

pub fn has_compatible_length( &self, links: &LinkMatrix, e_field: &EField<D> ) -> bool

Returns the length is compatible for both links and e_field. See Self::has_compatible_length_links and Self::has_compatible_length_e_field.

Trait Implementations§

source§

impl<const D: usize> Clone for LatticeCyclic<D>

source§

fn clone(&self) -> LatticeCyclic<D>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const D: usize> Debug for LatticeCyclic<D>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, const D: usize> Deserialize<'de> for LatticeCyclic<D>

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<const D: usize> Display for LatticeCyclic<D>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const D: usize> PartialEq<LatticeCyclic<D>> for LatticeCyclic<D>

source§

fn eq(&self, other: &LatticeCyclic<D>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const D: usize> Serialize for LatticeCyclic<D>

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<const D: usize> StructuralPartialEq for LatticeCyclic<D>

Auto Trait Implementations§

§

impl<const D: usize> RefUnwindSafe for LatticeCyclic<D>

§

impl<const D: usize> Send for LatticeCyclic<D>

§

impl<const D: usize> Sync for LatticeCyclic<D>

§

impl<const D: usize> Unpin for LatticeCyclic<D>

§

impl<const D: usize> UnwindSafe for LatticeCyclic<D>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

source§

impl<T> Scalar for Twhere T: 'static + Clone + PartialEq<T> + Debug,