phasesmith_core/lib.rs
1//! Numerical kernels for powder diffraction profile calculation.
2//!
3//! `phasesmith-core` is the lowest numerical layer. It operates on explicit
4//! parameters and flat borrowed slices and is deliberately unaware of files,
5//! phases, refinement projects, Python, and GUI state. Most applications should
6//! depend on the [`phasesmith` facade](https://docs.rs/phasesmith/) and reach
7//! this crate through `phasesmith::core`.
8//!
9//! # Capabilities
10//!
11//! - symmetric pseudo-Voigt and Thompson–Cox–Hastings profiles;
12//! - constant-wavelength U/V/W/X/Y broadening;
13//! - Finger–Cox–Jephcoat axial asymmetry;
14//! - fixed wavelength components and neutron time-of-flight profiles;
15//! - smooth Bruckner background estimation;
16//! - fused pattern values and analytical derivative storage.
17//!
18//! # Quick start
19//!
20//! ```
21//! use phasesmith_core::{Peak, accumulate_peaks};
22//!
23//! let x = [23.9, 24.0, 24.1];
24//! let peaks = [Peak {
25//! position: 24.0,
26//! intensity: 100.0,
27//! fwhm: 0.1,
28//! eta: 0.4,
29//! }];
30//! let result = accumulate_peaks(&x, &peaks, 20.0)?;
31//!
32//! assert_eq!(result.y.len(), x.len());
33//! assert_eq!(result.derivatives.local.parameter_count, 4);
34//! # Ok::<(), Box<dyn std::error::Error>>(())
35//! ```
36//!
37//! [`GridView`] and the various `*BatchView` types validate borrowed arrays
38//! once before entering hot kernels. Local derivatives use sparse finite-support
39//! storage; call [`SupportJacobian::to_dense`] only when a dense allocation is
40//! actually required. See [`profile`] for support and derivative conventions.
41//! The facade's
42//! [profile mathematics guide](https://docs.rs/phasesmith/latest/phasesmith/guide/mathematics/peak_profiles/)
43//! derives every implemented profile and broadening equation together.
44
45pub mod background;
46pub mod cw;
47pub mod cw_components;
48pub mod cw_contributions;
49pub mod cw_fcj;
50pub mod fcj;
51pub mod profile;
52pub mod radiation;
53pub mod tch;
54pub mod tof;
55
56pub use background::{BackgroundError, smooth_bruckner};
57pub use cw::{
58 ConstantWavelengthInstrument, CwBatchError, CwError, CwProfileParameters,
59 CwReflectionBatchView, accumulate_cw_batch,
60};
61pub use cw_components::{
62 CwComponentsBatchError, accumulate_cw_components_batch, accumulate_cw_fcj_components_batch,
63};
64pub use cw_contributions::{
65 CwContributionArrays, CwContributionsError, CwContributionsView, OwnedCwContributionArrays,
66 OwnedCwContributions, accumulate_cw_contributions_batch,
67 accumulate_cw_contributions_batch_with_context, accumulate_cw_fcj_contributions_batch,
68 accumulate_cw_fcj_contributions_batch_with_context,
69};
70pub use cw_fcj::{CwFcjBatchError, accumulate_cw_fcj_batch};
71pub use fcj::{FcjError, FcjGeometry, FcjProfile, FcjProfilePoint};
72
73pub use profile::{
74 Accumulation, DenseJacobian, GridView, PatternDerivatives, Peak, PeakBatchView, ProfileError,
75 ProfilePoint, SupportJacobian, SupportPolicy, SupportRange, accumulate_batch, accumulate_peaks,
76 accumulate_values_batch, symmetric_pseudo_voigt,
77};
78pub use radiation::{WavelengthComponentsError, WavelengthComponentsView};
79pub use tch::{
80 TchError, TchPeakBatchView, TchProfilePoint, TchShape, TchWidths, accumulate_tch_batch,
81 tch_pseudo_voigt,
82};
83pub use tof::{
84 TOF_GLOBAL_PARAMETER_COUNT, TOF_GLOBAL_PARAMETER_NAMES,
85 TOF_INCIDENT_SPECTRUM_COEFFICIENT_COUNT, TofBankGeometry, TofError, TofIncidentSpectrum,
86 TofIncidentSpectrumError, TofIncidentSpectrumPoint, TofInstrument, TofInstrumentParameter,
87 TofProfile, TofProfileParameters, TofProfilePoint, accumulate_tof_batch,
88 accumulate_tof_batch_with_context,
89};