1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
use crateCoordinateSystem;
use crateget_metric_tensor;
use cratetransform_contravariant_vector;
use cratetransform_covariant_vector;
use cratetransform_curl;
use cratetransform_divergence;
use cratetransform_expression;
use cratetransform_gradient;
use cratetransform_point;
use crateExpr;
/// Transforms a point between coordinate systems and returns its components in the target system.
///
/// The point is represented as a vector of symbolic expressions (e.g., \(x,y,z\)), and the
/// transformation applies the appropriate coordinate mapping (Cartesian, polar, spherical, etc.).
///
/// # Arguments
///
/// * `point` - Pointer to a `Vec<Expr>` containing the point coordinates in the `from` system.
/// * `from` - Source [`CoordinateSystem`] in which `point` is expressed.
/// * `to` - Target [`CoordinateSystem`] to which the point is transformed.
///
/// # Returns
///
/// A newly allocated `Vec<Expr>` pointer with the point coordinates in the `to` system, or
/// null on failure.
///
/// # Safety
///
/// This function is unsafe because it dereferences a raw pointer and returns ownership
/// of a heap-allocated vector to the caller.
pub extern "C"
/// Transforms a scalar expression between coordinate systems.
///
/// This replaces the variables of `expr` according to the mapping between the `from` and
/// `to` coordinate systems, yielding an equivalent symbolic expression in the target system.
///
/// # Arguments
///
/// * `expr` - Pointer to an `Expr` representing the scalar field in the `from` system.
/// * `from` - Source [`CoordinateSystem`] of the variables in `expr`.
/// * `to` - Target [`CoordinateSystem`] to which the expression is transformed.
///
/// # Returns
///
/// A newly allocated `Expr` pointer representing the transformed expression, or null on failure.
///
/// # Safety
///
/// This function is unsafe because it dereferences a raw `Expr` pointer and returns
/// ownership of a heap-allocated `Expr` to the caller.
pub extern "C"
/// Returns the metric tensor for a given coordinate system as a symbolic expression.
///
/// The metric tensor encodes the inner product and volume element for the coordinate
/// system, and is typically represented as a matrix-valued `Expr`.
///
/// # Arguments
///
/// * `system` - [`CoordinateSystem`] for which to compute the metric tensor.
///
/// # Returns
///
/// A newly allocated `Expr` pointer representing the metric tensor, or null on failure.
///
/// # Safety
///
/// This function is unsafe at the FFI boundary; the returned pointer must be eventually
/// freed by the caller using the appropriate deallocation routine.
pub extern "C"
/// Transforms contravariant vector components between coordinate systems.
///
/// Contravariant components transform with the Jacobian of the coordinate change, corresponding
/// to vector components with upper indices.
///
/// # Arguments
///
/// * `comps` - Pointer to a `Vec<Expr>` containing contravariant components in the `from` system.
/// * `from` - Source [`CoordinateSystem`].
/// * `to` - Target [`CoordinateSystem`].
///
/// # Returns
///
/// A newly allocated `Vec<Expr>` pointer with contravariant components in the `to` system, or
/// null on failure.
///
/// # Safety
///
/// This function is unsafe because it dereferences a raw pointer to a vector and returns
/// ownership of a heap-allocated vector to the caller.
pub extern "C"
/// Transforms covariant vector components between coordinate systems.
///
/// Covariant components transform with the inverse Jacobian and correspond to components
/// with lower indices (1-forms).
///
/// # Arguments
///
/// * `comps` - Pointer to a `Vec<Expr>` containing covariant components in the `from` system.
/// * `from` - Source [`CoordinateSystem`].
/// * `to` - Target [`CoordinateSystem`].
///
/// # Returns
///
/// A newly allocated `Vec<Expr>` pointer with covariant components in the `to` system, or
/// null on failure.
///
/// # Safety
///
/// This function is unsafe because it dereferences a raw pointer to a vector and returns
/// ownership of a heap-allocated vector to the caller.
pub extern "C"
/// Computes the divergence of a vector field in a given coordinate system.
///
/// The divergence is computed using the metric and Christoffel symbols associated with
/// `from`, yielding a scalar `Expr` representing \(\nabla \cdot \vec{v}\).
///
/// # Arguments
///
/// * `comps` - Pointer to a `Vec<Expr>` containing the vector components in the `from` system.
/// * `from` - [`CoordinateSystem`] with respect to which the divergence is taken.
///
/// # Returns
///
/// A newly allocated `Expr` pointer representing the divergence, or null on failure.
///
/// # Safety
///
/// This function is unsafe because it dereferences a raw vector pointer and returns
/// ownership of a heap-allocated `Expr` to the caller.
pub extern "C"
/// Computes the curl of a vector field in a given coordinate system.
///
/// The curl is computed using the metric and Levi-Civita tensor of the `from` system,
/// yielding a vector-valued `Expr` representing \(\nabla \times \vec{v}\).
///
/// # Arguments
///
/// * `comps` - Pointer to a `Vec<Expr>` containing the vector components in the `from` system.
/// * `from` - [`CoordinateSystem`] with respect to which the curl is taken.
///
/// # Returns
///
/// A newly allocated `Vec<Expr>` pointer representing the curl, or null on failure.
///
/// # Safety
///
/// This function is unsafe because it dereferences a raw vector pointer and returns
/// ownership of a heap-allocated vector to the caller.
pub extern "C"
/// Computes the gradient of a scalar field and transforms it between coordinate systems.
///
/// The gradient is first formed with respect to the variables `vars` in the `from` system,
/// then mapped into the `to` system as a vector of symbolic components.
///
/// # Arguments
///
/// * `scalar` - Pointer to an `Expr` representing the scalar field.
/// * `vars` - Pointer to a `Vec<String>` listing the coordinate variables.
/// * `from` - Source [`CoordinateSystem`].
/// * `to` - Target [`CoordinateSystem`].
///
/// # Returns
///
/// A newly allocated `Vec<Expr>` pointer representing the gradient components in the `to`
/// system, or null on failure.
///
/// # Safety
///
/// This function is unsafe because it dereferences raw pointers and returns ownership
/// of a heap-allocated vector to the caller.
pub extern "C"