Struct lattice_qcd_rs::lattice::LatticeCyclic
source · 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>
impl<const D: usize> LatticeCyclic<D>
sourcepub const fn dim_st() -> usize
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.
sourcepub fn link_canonical(
&self,
pos: LatticePoint<D>,
dir: Direction<D>
) -> LatticeLinkCanonical<D>
pub fn link_canonical( &self, pos: LatticePoint<D>, dir: Direction<D> ) -> LatticeLinkCanonical<D>
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)?
);
sourcepub fn link(&self, pos: LatticePoint<D>, dir: Direction<D>) -> LatticeLink<D>
pub fn link(&self, pos: LatticePoint<D>, dir: Direction<D>) -> LatticeLink<D>
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))
);
sourcepub fn into_canonical(&self, l: LatticeLink<D>) -> LatticeLinkCanonical<D>
pub fn into_canonical(&self, l: LatticeLink<D>) -> LatticeLinkCanonical<D>
Transform a LatticeLink
into a LatticeLinkCanonical
.
sourcepub const fn dim(&self) -> usize
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.
sourcepub fn get_points(&self) -> IteratorLatticePoint<'_, D> ⓘ
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());
}
sourcepub fn get_links(&self) -> IteratorLatticeLinkCanonical<'_, D> ⓘ
pub fn get_links(&self) -> IteratorLatticeLinkCanonical<'_, D> ⓘ
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()
);
}
sourcepub fn new(size: Real, dim: usize) -> Result<Self, LatticeInitializationError>
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.
sourcepub fn number_of_canonical_links_space(&self) -> usize
pub fn number_of_canonical_links_space(&self) -> usize
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);
sourcepub fn number_of_points(&self) -> usize
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));
sourcepub fn add_point_direction(
&self,
point: LatticePoint<D>,
dir: &Direction<D>
) -> LatticePoint<D>
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])
);
sourcepub fn add_point_direction_n(
&self,
point: LatticePoint<D>,
dir: &Direction<D>,
shift_number: usize
) -> LatticePoint<D>
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])
);
sourcepub fn has_compatible_length_links(&self, links: &LinkMatrix) -> bool
pub fn has_compatible_length_links(&self, links: &LinkMatrix) -> bool
Returns whether the number of canonical link is the same as the length of links
.
sourcepub fn has_compatible_length_e_field(&self, e_field: &EField<D>) -> bool
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
.
sourcepub fn has_compatible_length(
&self,
links: &LinkMatrix,
e_field: &EField<D>
) -> bool
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>
impl<const D: usize> Clone for LatticeCyclic<D>
source§fn clone(&self) -> LatticeCyclic<D>
fn clone(&self) -> LatticeCyclic<D>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<const D: usize> Debug for LatticeCyclic<D>
impl<const D: usize> Debug for LatticeCyclic<D>
source§impl<'de, const D: usize> Deserialize<'de> for LatticeCyclic<D>
impl<'de, const D: usize> Deserialize<'de> for LatticeCyclic<D>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<const D: usize> Display for LatticeCyclic<D>
impl<const D: usize> Display for LatticeCyclic<D>
source§impl<const D: usize> PartialEq<LatticeCyclic<D>> for LatticeCyclic<D>
impl<const D: usize> PartialEq<LatticeCyclic<D>> for LatticeCyclic<D>
source§fn eq(&self, other: &LatticeCyclic<D>) -> bool
fn eq(&self, other: &LatticeCyclic<D>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<const D: usize> Serialize for LatticeCyclic<D>
impl<const D: usize> Serialize for LatticeCyclic<D>
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§
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.