Skip to main content

differential_equations_tableau_macros/
lib.rs

1//! Compile-time validation and expansion of declarative solver tableau resources.
2
3mod algorithms;
4mod expansion;
5mod input;
6mod static_tableaus;
7
8use proc_macro::TokenStream;
9
10/// Defines a zero-sized explicit Runge--Kutta algorithm from a JSON resource.
11///
12/// The path is relative to the invoking package's `CARGO_MANIFEST_DIR`. The
13/// file is parsed and validated while compiling. The expansion embeds the
14/// source text and parses it lazily when the algorithm is first used; it does
15/// not generate Rust coefficient arrays.
16#[proc_macro]
17pub fn define_explicit_rk_from_file(input: TokenStream) -> TokenStream {
18    static_tableaus::define_explicit_rk_from_file(input)
19}
20
21/// Defines a lazy implicit Runge--Kutta tableau static from a JSON resource.
22///
23/// The resource is parsed and validated during macro expansion. The emitted
24/// static embeds only its source text and materializes coefficients on first
25/// use, allowing specialized implicit kernels to share the canonical serde
26/// representation without generated Rust constants.
27#[proc_macro]
28pub fn define_implicit_rk_tableau_from_file(input: TokenStream) -> TokenStream {
29    static_tableaus::define_implicit_rk_tableau_from_file(input)
30}
31
32/// Defines a lazy explicit Runge--Kutta tableau static from a JSON resource.
33///
34/// This form is intended for public compatibility aliases and specialized
35/// kernels that cannot use the zero-sized algorithm generated by
36/// [`define_explicit_rk_from_file!`].
37#[proc_macro]
38pub fn define_explicit_rk_tableau_from_file(input: TokenStream) -> TokenStream {
39    static_tableaus::define_explicit_rk_tableau_from_file(input)
40}
41
42/// Defines a lazy canonical linear multistep tableau from a JSON resource.
43///
44/// Accepts `visibility STATIC_NAME, "MethodName", "resource.json"` and an
45/// optional `crate = local_name`. Validates coefficients and polynomial order
46/// conditions at compile time, then embeds only source text for lazy parsing.
47#[proc_macro]
48pub fn define_multistep_tableau_from_file(input: TokenStream) -> TokenStream {
49    static_tableaus::define_multistep_tableau_from_file(input)
50}
51
52/// Defines a lazy variable-step two-step tableau from a JSON resource.
53///
54/// Coefficient functions, the startup formula, and the local-defect estimator
55/// are validated during macro expansion. Only source text is embedded and the
56/// tableau is materialized on first inspection or use.
57#[proc_macro]
58pub fn define_variable_multistep_tableau_from_file(input: TokenStream) -> TokenStream {
59    static_tableaus::define_variable_multistep_tableau_from_file(input)
60}
61
62/// Defines a lazy MRI-GARK tableau validated from a JSON resource.
63#[proc_macro]
64pub fn define_mri_tableau_from_file(input: TokenStream) -> TokenStream {
65    static_tableaus::define_mri_tableau_from_file(input)
66}
67
68/// Defines a lazy MIS coupling tableau validated from a JSON resource.
69#[proc_macro]
70pub fn define_mis_tableau_from_file(input: TokenStream) -> TokenStream {
71    static_tableaus::define_mis_tableau_from_file(input)
72}
73
74/// Defines a lazy Rosenbrock or hybrid tableau, validated at compile time.
75///
76/// Accepts `visibility STATIC, "MethodName", "resource.json", crate = local_name`.
77/// Only source text is embedded; coefficient arrays are parsed on first use.
78#[proc_macro]
79pub fn define_rosenbrock_tableau_from_file(input: TokenStream) -> TokenStream {
80    static_tableaus::define_rosenbrock_tableau_from_file(input)
81}
82
83/// Defines the lazy low-storage Rosenbrock 2/3 pair from a JSON resource.
84///
85/// The resource is validated during macro expansion and embedded as source
86/// text, then materialized only when one of the pair's solvers is first used.
87#[proc_macro]
88pub fn define_rosenbrock_pair_tableau_from_file(input: TokenStream) -> TokenStream {
89    static_tableaus::define_rosenbrock_pair_tableau_from_file(input)
90}
91
92/// Defines one lazily materialized RKN tableau from a validated JSON resource.
93///
94/// The resource is parsed during macro expansion for compile-time diagnostics.
95/// The expansion embeds only its source text and parses it once on first use.
96#[proc_macro]
97pub fn define_rkn_tableau_from_file(input: TokenStream) -> TokenStream {
98    static_tableaus::define_rkn_tableau_from_file(input)
99}
100
101/// Defines one lazily materialized improved RKN tableau from validated JSON.
102#[proc_macro]
103pub fn define_irkn_tableau_from_file(input: TokenStream) -> TokenStream {
104    static_tableaus::define_irkn_tableau_from_file(input)
105}
106
107/// Defines one lazily materialized low-storage Runge--Kutta tableau.
108///
109/// The resource is parsed and validated during macro expansion. The emitted
110/// static embeds only its source text and materializes coefficients on first
111/// inspection or use.
112#[proc_macro]
113pub fn define_low_storage_rk_tableau_from_file(input: TokenStream) -> TokenStream {
114    static_tableaus::define_low_storage_rk_tableau_from_file(input)
115}
116
117/// Defines one independently lazy, degree-specific ROCK2 tableau.
118///
119/// The JSON resource is fully parsed and validated during macro expansion.
120/// The expansion embeds the original source with `include_str!` and parses it
121/// once, only when this particular degree is inspected or selected.
122#[proc_macro]
123pub fn define_rock2_tableau_from_file(input: TokenStream) -> TokenStream {
124    static_tableaus::define_rock2_tableau_from_file(input)
125}
126
127/// Defines one independently lazy, degree-specific ROCK4 tableau.
128///
129/// The shared parser validates the recurrence, finishing tableau, fourth-order
130/// primary method, and third-order embedded companion during macro expansion.
131#[proc_macro]
132pub fn define_rock4_tableau_from_file(input: TokenStream) -> TokenStream {
133    static_tableaus::define_rock4_tableau_from_file(input)
134}
135
136/// Defines one independently lazy, degree-specific SERK2 tableau.
137///
138/// The shared parser reconstructs the recurrence and validates its second-order
139/// conditions during macro expansion. The emitted static embeds only the JSON
140/// source and parses it on first use.
141#[proc_macro]
142pub fn define_serk2_tableau_from_file(input: TokenStream) -> TokenStream {
143    static_tableaus::define_serk2_tableau_from_file(input)
144}
145
146/// Defines one independently lazy, degree-specific ESERK tableau.
147///
148/// The shared parser validates the stabilized recurrence and extrapolation
149/// moments during macro expansion. The expansion embeds only the source JSON
150/// and parses it when this particular degree is first selected or inspected.
151#[proc_macro]
152pub fn define_eserk_tableau_from_file(input: TokenStream) -> TokenStream {
153    static_tableaus::define_eserk_tableau_from_file(input)
154}
155
156/// Defines a named fixed or adaptive RKN solver from one JSON resource.
157///
158/// The generated zero-sized type implements `SecondOrderOdeAlgorithm` and
159/// exposes its independently lazy tableau through `tableau()`.
160#[proc_macro]
161pub fn define_rkn_from_file(input: TokenStream) -> TokenStream {
162    algorithms::define_rkn_from_file(input)
163}
164
165/// Defines a named low-storage Runge--Kutta solver from one JSON resource.
166///
167/// The generated zero-sized type implements [`OdeAlgorithm`](https://docs.rs/differential-equations-rs/latest/differential_equations/trait.OdeAlgorithm.html)
168/// and exposes its independently lazy tableau through `tableau()`.
169#[proc_macro]
170pub fn define_low_storage_rk_from_file(input: TokenStream) -> TokenStream {
171    algorithms::define_low_storage_rk_from_file(input)
172}
173
174/// Defines a symplectic composition from a validated JSON resource.
175///
176/// Like [`define_explicit_rk_from_file!`], accepts a visibility, method name,
177/// resource path, and optional `crate = path`. The expansion contains an
178/// `include_str!` resource and a per-method lazy tableau, not coefficient arrays.
179#[proc_macro]
180pub fn define_symplectic_from_file(input: TokenStream) -> TokenStream {
181    algorithms::define_symplectic_from_file(input)
182}