1use std::fmt;
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7pub enum Error {
8 ZeroK,
10 BadBox,
12 Empty,
14 BufferSize,
16 Overflow,
18 MaskLen,
20 TooManyCells,
22 BadCutoff,
24 TooManyImages,
26 Partial,
28 Device,
30 Padded,
32 NonFinite,
34 BadPartition,
36 BadGraph,
38 NoDevice,
40 DeviceMismatch,
42 ScotchDisabled,
44 ScotchFailed,
46}
47
48impl fmt::Display for Error {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 match self {
51 Error::ZeroK => write!(f, "k must be at least 1"),
52 Error::BadBox => write!(f, "singular or non-positive cell"),
53 Error::Empty => write!(f, "no points"),
54 Error::BufferSize => write!(f, "out buffer length must be n * k"),
55 Error::Overflow => write!(f, "n * k overflows"),
56 Error::MaskLen => write!(f, "mask length must be n"),
57 Error::TooManyCells => write!(f, "linked-cell mesh is too fine"),
58 Error::BadCutoff => write!(f, "cutoff must be finite and positive"),
59 Error::TooManyImages => write!(f, "periodic image count exceeds 2^24"),
60 Error::Partial => write!(
61 f,
62 "partial periodicity needs libvesin.so on the loader path"
63 ),
64 Error::Device => write!(f, "this device needs libvesin.so on the loader path"),
65 Error::Padded => write!(f, "a point has more neighbours than padded_to"),
66 Error::NonFinite => write!(f, "a coordinate is not finite"),
67 Error::BadPartition => {
68 write!(f, "part count must be positive and balance at least 1")
69 }
70 Error::BadGraph => write!(f, "cell graph is not a square CSR"),
71 Error::NoDevice => write!(f, "CUDA curve split is not available"),
72 Error::DeviceMismatch => {
73 write!(f, "device curve split disagreed with the host weights")
74 }
75 Error::ScotchDisabled => write!(f, "Scotch support is compiled out"),
76 Error::ScotchFailed => write!(f, "Scotch returned an error"),
77 }
78 }
79}
80
81impl std::error::Error for Error {}
82
83impl From<minimage::Error> for Error {
84 fn from(err: minimage::Error) -> Self {
85 match err {
86 minimage::Error::BadBox => Error::BadBox,
87 minimage::Error::BufferSize => Error::BufferSize,
88 minimage::Error::Empty => Error::Empty,
89 }
90 }
91}