Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
pyshammath.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
22#include "shammath/matrix.hpp"
31#include <fmt/core.h>
32#include <pybind11/cast.h>
33#include <pybind11/functional.h>
34#include <pybind11/numpy.h>
35#include <functional>
36
37Register_pymod(pysham_mathinit) {
38
39 py::module math_module = m.def_submodule("math", "Shamrock math lib");
40
41 shampylib::init_shamrock_math_AABB<f64_3>(math_module, "AABB_f64_3");
42 shampylib::init_shamrock_math_Ray<f64_3>(math_module, "Ray_f64_3");
43 shampylib::init_shamrock_math_RingRay<f64_3>(math_module, "RingRay_f64_3");
44 shampylib::init_shamrock_math_sfc(math_module);
45 shampylib::init_shamrock_math_sphkernels(math_module);
46
47 math_module.def("derivative_upwind", [](f64 x, f64 dx, std::function<f64(f64)> fct) {
48 return shammath::derivative_upwind<f64>(x, dx, [&](f64 x) {
49 return fct(x);
50 });
51 });
52 math_module.def("derivative_centered", [](f64 x, f64 dx, std::function<f64(f64)> fct) {
53 return shammath::derivative_centered<f64>(x, dx, [&](f64 x) {
54 return fct(x);
55 });
56 });
57 math_module.def("derivative_3point_forward", [](f64 x, f64 dx, std::function<f64(f64)> fct) {
58 return shammath::derivative_3point_forward<f64>(x, dx, [&](f64 x) {
59 return fct(x);
60 });
61 });
62 math_module.def("derivative_3point_backward", [](f64 x, f64 dx, std::function<f64(f64)> fct) {
63 return shammath::derivative_3point_backward<f64>(x, dx, [&](f64 x) {
64 return fct(x);
65 });
66 });
67 math_module.def("derivative_5point_midpoint", [](f64 x, f64 dx, std::function<f64(f64)> fct) {
68 return shammath::derivative_5point_midpoint<f64>(x, dx, [&](f64 x) {
69 return fct(x);
70 });
71 });
72 math_module.def(
73 "estim_deriv_step",
74 [](u32 order) {
75 return shammath::estim_deriv_step<f64>(order);
76 },
77 R"pbdoc(
78 Estim the correct step to use for a given order when using derivatives
79 )pbdoc");
80
81 py::class_<shammath::paving_function_periodic_3d<f64_3>>(
82 math_module, "paving_function_periodic_3d")
83 .def(py::init([](f64_3 box_size) {
84 return std::make_unique<shammath::paving_function_periodic_3d<f64_3>>(
86 }))
91 .def(
92 "get_paving_index_intersecting",
94
95 py::class_<shammath::paving_function_general_3d<f64_3>>(
96 math_module, "paving_function_general_3d")
97 .def(
98 py::init([](f64_3 box_size,
99 f64_3 box_center,
100 bool is_x_periodic,
101 bool is_y_periodic,
102 bool is_z_periodic) {
103 return std::make_unique<shammath::paving_function_general_3d<f64_3>>(
105 box_size, box_center, is_x_periodic, is_y_periodic, is_z_periodic});
106 }))
111 .def(
112 "get_paving_index_intersecting",
114
115 py::class_<shammath::paving_function_general_3d_shear_x<f64_3>>(
116 math_module, "paving_function_general_3d_shear_x")
117 .def(
118 py::init([](f64_3 box_size,
119 f64_3 box_center,
120 bool is_x_periodic,
121 bool is_y_periodic,
122 bool is_z_periodic,
123 f64 shear_x) {
124 return std::make_unique<shammath::paving_function_general_3d_shear_x<f64_3>>(
126 box_size,
127 box_center,
128 is_x_periodic,
129 is_y_periodic,
130 is_z_periodic,
131 shear_x});
132 }))
137 .def(
138 "get_paving_index_intersecting",
140
141 py::class_<f64_4x4>(math_module, "f64_4x4")
142 .def(py::init([]() {
143 return std::make_unique<f64_4x4>();
144 }))
145 .def(
146 "__getitem__",
147 [](const f64_4x4 &m, std::pair<int, int> idx) -> double {
148 return m(idx.first, idx.second);
149 })
150 .def(
151 "__setitem__",
152 [](f64_4x4 &m, std::pair<int, int> idx, double value) {
153 m(idx.first, idx.second) = value;
154 })
155 .def(
156 "__repr__",
157 [](const f64_4x4 &m) {
158 std::ostringstream oss;
159 oss << "[";
160 for (size_t i = 0; i < 4; ++i) {
161 oss << "[";
162 for (size_t j = 0; j < 4; ++j) {
163 oss << m(i, j);
164 if (j + 1 < 4)
165 oss << ", ";
166 }
167 oss << "]";
168 if (i + 1 < 4)
169 oss << ",\n ";
170 }
171 oss << "]";
172 return oss.str();
173 })
174 .def(
175 "__matmul__",
176 [](const f64_4x4 &a, const f64_4x4 &b) {
177 f64_4x4 ret;
179 return ret;
180 },
181 py::is_operator())
182 .def("to_pyarray", [](const f64_4x4 &self) {
183 py::array_t<f64> ret({4, 4});
184 for (u32 i = 0; i < 4; i++) {
185 for (u32 j = 0; j < 4; j++) {
186 ret.mutable_at(i, j) = self(i, j);
187 }
188 }
189
190 return ret;
191 });
192
193 math_module.def("get_identity_f64_4x4", []() -> f64_4x4 {
194 return shammath::mat_identity<f64, 4>();
195 });
196
197 math_module.def("mat_mul", [](const f64_4x4 &a, const f64_4x4 &b) -> f64_4x4 {
198 f64_4x4 ret;
200 return ret;
201 });
202
203 math_module.def("mat_set_identity", [](f64_4x4 &a) {
205 });
206
207 // SymTensor3d_1 bindings
208 py::class_<shammath::SymTensor3d_1<f64>>(math_module, "SymTensor3d_1_f64")
209 .def(py::init<f64, f64, f64>(), py::arg("v_0"), py::arg("v_1"), py::arg("v_2"))
210 .def(py::init<>())
211 .def_readwrite("v_0", &shammath::SymTensor3d_1<f64>::v_0)
212 .def_readwrite("v_1", &shammath::SymTensor3d_1<f64>::v_1)
213 .def_readwrite("v_2", &shammath::SymTensor3d_1<f64>::v_2)
214 .def(
215 "inner",
216 py::overload_cast<const shammath::SymTensor3d_1<f64> &>(
218 "Inner product with another SymTensor3d_1")
219 .def(
220 "inner",
221 py::overload_cast<const f64>(&shammath::SymTensor3d_1<f64>::inner, py::const_),
222 "Scalar multiplication")
223 .def("__mul__", &shammath::SymTensor3d_1<f64>::operator*, "Multiply by scalar")
224 .def("__imul__", &shammath::SymTensor3d_1<f64>::operator*=, "In-place multiply by scalar")
225 .def("__add__", &shammath::SymTensor3d_1<f64>::operator+, "Add two tensors")
226 .def("__iadd__", &shammath::SymTensor3d_1<f64>::operator+=, "In-place add")
227 .def("__sub__", &shammath::SymTensor3d_1<f64>::operator-, "Subtract two tensors")
228 .def("__repr__", [](const shammath::SymTensor3d_1<f64> &t) {
229 return fmt::format("SymTensor3d_1(v_0={}, v_1={}, v_2={})", t.v_0, t.v_1, t.v_2);
230 });
231
232 // SymTensor3d_2 bindings
233 py::class_<shammath::SymTensor3d_2<f64>>(math_module, "SymTensor3d_2_f64")
234 .def(
235 py::init<f64, f64, f64, f64, f64, f64>(),
236 py::arg("v_00"),
237 py::arg("v_01"),
238 py::arg("v_02"),
239 py::arg("v_11"),
240 py::arg("v_12"),
241 py::arg("v_22"))
242 .def(py::init<>())
243 .def_readwrite("v_00", &shammath::SymTensor3d_2<f64>::v_00)
244 .def_readwrite("v_01", &shammath::SymTensor3d_2<f64>::v_01)
245 .def_readwrite("v_02", &shammath::SymTensor3d_2<f64>::v_02)
246 .def_readwrite("v_11", &shammath::SymTensor3d_2<f64>::v_11)
247 .def_readwrite("v_12", &shammath::SymTensor3d_2<f64>::v_12)
248 .def_readwrite("v_22", &shammath::SymTensor3d_2<f64>::v_22)
249 .def(
250 "inner",
251 py::overload_cast<const shammath::SymTensor3d_2<f64> &>(
253 "Inner product with another SymTensor3d_2")
254 .def(
255 "inner",
256 py::overload_cast<const shammath::SymTensor3d_1<f64> &>(
258 "Inner product with SymTensor3d_1")
259 .def(
260 "inner",
261 py::overload_cast<const f64>(&shammath::SymTensor3d_2<f64>::inner, py::const_),
262 "Scalar multiplication")
263 .def("__mul__", &shammath::SymTensor3d_2<f64>::operator*, "Multiply by scalar")
264 .def("__imul__", &shammath::SymTensor3d_2<f64>::operator*=, "In-place multiply by scalar")
265 .def("__add__", &shammath::SymTensor3d_2<f64>::operator+, "Add two tensors")
266 .def("__iadd__", &shammath::SymTensor3d_2<f64>::operator+=, "In-place add")
267 .def("__sub__", &shammath::SymTensor3d_2<f64>::operator-, "Subtract two tensors")
268 .def("__repr__", [](const shammath::SymTensor3d_2<f64> &t) {
269 return fmt::format(
270 "SymTensor3d_2(v_00={}, v_01={}, v_02={}, v_11={}, v_12={}, v_22={})",
271 t.v_00,
272 t.v_01,
273 t.v_02,
274 t.v_11,
275 t.v_12,
276 t.v_22);
277 });
278
279 // SymTensor3d_3 bindings
280 py::class_<shammath::SymTensor3d_3<f64>>(math_module, "SymTensor3d_3_f64")
281 .def(
282 py::init<f64, f64, f64, f64, f64, f64, f64, f64, f64, f64>(),
283 py::arg("v_000"),
284 py::arg("v_001"),
285 py::arg("v_002"),
286 py::arg("v_011"),
287 py::arg("v_012"),
288 py::arg("v_022"),
289 py::arg("v_111"),
290 py::arg("v_112"),
291 py::arg("v_122"),
292 py::arg("v_222"))
293 .def(py::init<>())
294 .def_readwrite("v_000", &shammath::SymTensor3d_3<f64>::v_000)
295 .def_readwrite("v_001", &shammath::SymTensor3d_3<f64>::v_001)
296 .def_readwrite("v_002", &shammath::SymTensor3d_3<f64>::v_002)
297 .def_readwrite("v_011", &shammath::SymTensor3d_3<f64>::v_011)
298 .def_readwrite("v_012", &shammath::SymTensor3d_3<f64>::v_012)
299 .def_readwrite("v_022", &shammath::SymTensor3d_3<f64>::v_022)
300 .def_readwrite("v_111", &shammath::SymTensor3d_3<f64>::v_111)
301 .def_readwrite("v_112", &shammath::SymTensor3d_3<f64>::v_112)
302 .def_readwrite("v_122", &shammath::SymTensor3d_3<f64>::v_122)
303 .def_readwrite("v_222", &shammath::SymTensor3d_3<f64>::v_222)
304 .def(
305 "inner",
306 py::overload_cast<const shammath::SymTensor3d_3<f64> &>(
308 "Inner product with another SymTensor3d_3")
309 .def(
310 "inner",
311 py::overload_cast<const shammath::SymTensor3d_2<f64> &>(
313 "Inner product with SymTensor3d_2")
314 .def(
315 "inner",
316 py::overload_cast<const shammath::SymTensor3d_1<f64> &>(
318 "Inner product with SymTensor3d_1")
319 .def(
320 "inner",
321 py::overload_cast<const f64>(&shammath::SymTensor3d_3<f64>::inner, py::const_),
322 "Scalar multiplication")
323 .def("__mul__", &shammath::SymTensor3d_3<f64>::operator*, "Multiply by scalar")
324 .def("__imul__", &shammath::SymTensor3d_3<f64>::operator*=, "In-place multiply by scalar")
325 .def("__add__", &shammath::SymTensor3d_3<f64>::operator+, "Add two tensors")
326 .def("__iadd__", &shammath::SymTensor3d_3<f64>::operator+=, "In-place add")
327 .def("__sub__", &shammath::SymTensor3d_3<f64>::operator-, "Subtract two tensors")
328 .def("__repr__", [](const shammath::SymTensor3d_3<f64> &t) {
329 return fmt::format(
330 "SymTensor3d_3(v_000={}, v_001={}, v_002={}, v_011={}, v_012={}, v_022={}, "
331 "v_111={}, v_112={}, v_122={}, v_222={})",
332 t.v_000,
333 t.v_001,
334 t.v_002,
335 t.v_011,
336 t.v_012,
337 t.v_022,
338 t.v_111,
339 t.v_112,
340 t.v_122,
341 t.v_222);
342 });
343
344 // SymTensor3d_4 bindings
345 py::class_<shammath::SymTensor3d_4<f64>>(math_module, "SymTensor3d_4_f64")
346 .def(
347 py::init<f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64>(),
348 py::arg("v_0000"),
349 py::arg("v_0001"),
350 py::arg("v_0002"),
351 py::arg("v_0011"),
352 py::arg("v_0012"),
353 py::arg("v_0022"),
354 py::arg("v_0111"),
355 py::arg("v_0112"),
356 py::arg("v_0122"),
357 py::arg("v_0222"),
358 py::arg("v_1111"),
359 py::arg("v_1112"),
360 py::arg("v_1122"),
361 py::arg("v_1222"),
362 py::arg("v_2222"))
363 .def(py::init<>())
364 .def_readwrite("v_0000", &shammath::SymTensor3d_4<f64>::v_0000)
365 .def_readwrite("v_0001", &shammath::SymTensor3d_4<f64>::v_0001)
366 .def_readwrite("v_0002", &shammath::SymTensor3d_4<f64>::v_0002)
367 .def_readwrite("v_0011", &shammath::SymTensor3d_4<f64>::v_0011)
368 .def_readwrite("v_0012", &shammath::SymTensor3d_4<f64>::v_0012)
369 .def_readwrite("v_0022", &shammath::SymTensor3d_4<f64>::v_0022)
370 .def_readwrite("v_0111", &shammath::SymTensor3d_4<f64>::v_0111)
371 .def_readwrite("v_0112", &shammath::SymTensor3d_4<f64>::v_0112)
372 .def_readwrite("v_0122", &shammath::SymTensor3d_4<f64>::v_0122)
373 .def_readwrite("v_0222", &shammath::SymTensor3d_4<f64>::v_0222)
374 .def_readwrite("v_1111", &shammath::SymTensor3d_4<f64>::v_1111)
375 .def_readwrite("v_1112", &shammath::SymTensor3d_4<f64>::v_1112)
376 .def_readwrite("v_1122", &shammath::SymTensor3d_4<f64>::v_1122)
377 .def_readwrite("v_1222", &shammath::SymTensor3d_4<f64>::v_1222)
378 .def_readwrite("v_2222", &shammath::SymTensor3d_4<f64>::v_2222)
379 .def(
380 "inner",
381 py::overload_cast<const shammath::SymTensor3d_4<f64> &>(
383 "Inner product with another SymTensor3d_4")
384 .def(
385 "inner",
386 py::overload_cast<const shammath::SymTensor3d_3<f64> &>(
388 "Inner product with SymTensor3d_3")
389 .def(
390 "inner",
391 py::overload_cast<const shammath::SymTensor3d_2<f64> &>(
393 "Inner product with SymTensor3d_2")
394 .def(
395 "inner",
396 py::overload_cast<const shammath::SymTensor3d_1<f64> &>(
398 "Inner product with SymTensor3d_1")
399 .def(
400 "inner",
401 py::overload_cast<const f64>(&shammath::SymTensor3d_4<f64>::inner, py::const_),
402 "Scalar multiplication")
403 .def("__mul__", &shammath::SymTensor3d_4<f64>::operator*, "Multiply by scalar")
404 .def("__imul__", &shammath::SymTensor3d_4<f64>::operator*=, "In-place multiply by scalar")
405 .def("__add__", &shammath::SymTensor3d_4<f64>::operator+, "Add two tensors")
406 .def("__iadd__", &shammath::SymTensor3d_4<f64>::operator+=, "In-place add")
407 .def("__sub__", &shammath::SymTensor3d_4<f64>::operator-, "Subtract two tensors")
408 .def("__repr__", [](const shammath::SymTensor3d_4<f64> &t) {
409 return fmt::format(
410 "SymTensor3d_4(v_0000={}, v_0001={}, v_0002={}, v_0011={}, v_0012={}, v_0022={}, "
411 "v_0111={}, v_0112={}, v_0122={}, v_0222={}, v_1111={}, v_1112={}, v_1122={}, "
412 "v_1222={}, v_2222={})",
413 t.v_0000,
414 t.v_0001,
415 t.v_0002,
416 t.v_0011,
417 t.v_0012,
418 t.v_0022,
419 t.v_0111,
420 t.v_0112,
421 t.v_0122,
422 t.v_0222,
423 t.v_1111,
424 t.v_1112,
425 t.v_1122,
426 t.v_1222,
427 t.v_2222);
428 });
429
430 // SymTensor3d_5 bindings
431 py::class_<shammath::SymTensor3d_5<f64>>(math_module, "SymTensor3d_5_f64")
432 .def(
433 py::init<
434 f64,
435 f64,
436 f64,
437 f64,
438 f64,
439 f64,
440 f64,
441 f64,
442 f64,
443 f64,
444 f64,
445 f64,
446 f64,
447 f64,
448 f64,
449 f64,
450 f64,
451 f64,
452 f64,
453 f64,
454 f64>(),
455 py::arg("v_00000"),
456 py::arg("v_00001"),
457 py::arg("v_00002"),
458 py::arg("v_00011"),
459 py::arg("v_00012"),
460 py::arg("v_00022"),
461 py::arg("v_00111"),
462 py::arg("v_00112"),
463 py::arg("v_00122"),
464 py::arg("v_00222"),
465 py::arg("v_01111"),
466 py::arg("v_01112"),
467 py::arg("v_01122"),
468 py::arg("v_01222"),
469 py::arg("v_02222"),
470 py::arg("v_11111"),
471 py::arg("v_11112"),
472 py::arg("v_11122"),
473 py::arg("v_11222"),
474 py::arg("v_12222"),
475 py::arg("v_22222"))
476 .def(py::init<>())
477 .def_readwrite("v_00000", &shammath::SymTensor3d_5<f64>::v_00000)
478 .def_readwrite("v_00001", &shammath::SymTensor3d_5<f64>::v_00001)
479 .def_readwrite("v_00002", &shammath::SymTensor3d_5<f64>::v_00002)
480 .def_readwrite("v_00011", &shammath::SymTensor3d_5<f64>::v_00011)
481 .def_readwrite("v_00012", &shammath::SymTensor3d_5<f64>::v_00012)
482 .def_readwrite("v_00022", &shammath::SymTensor3d_5<f64>::v_00022)
483 .def_readwrite("v_00111", &shammath::SymTensor3d_5<f64>::v_00111)
484 .def_readwrite("v_00112", &shammath::SymTensor3d_5<f64>::v_00112)
485 .def_readwrite("v_00122", &shammath::SymTensor3d_5<f64>::v_00122)
486 .def_readwrite("v_00222", &shammath::SymTensor3d_5<f64>::v_00222)
487 .def_readwrite("v_01111", &shammath::SymTensor3d_5<f64>::v_01111)
488 .def_readwrite("v_01112", &shammath::SymTensor3d_5<f64>::v_01112)
489 .def_readwrite("v_01122", &shammath::SymTensor3d_5<f64>::v_01122)
490 .def_readwrite("v_01222", &shammath::SymTensor3d_5<f64>::v_01222)
491 .def_readwrite("v_02222", &shammath::SymTensor3d_5<f64>::v_02222)
492 .def_readwrite("v_11111", &shammath::SymTensor3d_5<f64>::v_11111)
493 .def_readwrite("v_11112", &shammath::SymTensor3d_5<f64>::v_11112)
494 .def_readwrite("v_11122", &shammath::SymTensor3d_5<f64>::v_11122)
495 .def_readwrite("v_11222", &shammath::SymTensor3d_5<f64>::v_11222)
496 .def_readwrite("v_12222", &shammath::SymTensor3d_5<f64>::v_12222)
497 .def_readwrite("v_22222", &shammath::SymTensor3d_5<f64>::v_22222)
498 .def(
499 "inner",
500 py::overload_cast<const shammath::SymTensor3d_5<f64> &>(
502 "Inner product with another SymTensor3d_5")
503 .def(
504 "inner",
505 py::overload_cast<const shammath::SymTensor3d_4<f64> &>(
507 "Inner product with SymTensor3d_4")
508 .def(
509 "inner",
510 py::overload_cast<const shammath::SymTensor3d_3<f64> &>(
512 "Inner product with SymTensor3d_3")
513 .def(
514 "inner",
515 py::overload_cast<const shammath::SymTensor3d_2<f64> &>(
517 "Inner product with SymTensor3d_2")
518 .def(
519 "inner",
520 py::overload_cast<const shammath::SymTensor3d_1<f64> &>(
522 "Inner product with SymTensor3d_1")
523 .def(
524 "inner",
525 py::overload_cast<const f64>(&shammath::SymTensor3d_5<f64>::inner, py::const_),
526 "Scalar multiplication")
527 .def("__mul__", &shammath::SymTensor3d_5<f64>::operator*, "Multiply by scalar")
528 .def("__imul__", &shammath::SymTensor3d_5<f64>::operator*=, "In-place multiply by scalar")
529 .def("__add__", &shammath::SymTensor3d_5<f64>::operator+, "Add two tensors")
530 .def("__iadd__", &shammath::SymTensor3d_5<f64>::operator+=, "In-place add")
531 .def("__sub__", &shammath::SymTensor3d_5<f64>::operator-, "Subtract two tensors")
532 .def("__repr__", [](const shammath::SymTensor3d_5<f64> &t) {
533 return fmt::format(
534 "SymTensor3d_5(v_00000={}, v_00001={}, v_00002={}, v_00011={}, v_00012={}, "
535 "v_00022={}, v_00111={}, v_00112={}, v_00122={}, v_00222={}, v_01111={}, "
536 "v_01112={}, v_01122={}, v_01222={}, v_02222={}, v_11111={}, v_11112={}, "
537 "v_11122={}, v_11222={}, v_12222={}, v_22222={})",
538 t.v_00000,
539 t.v_00001,
540 t.v_00002,
541 t.v_00011,
542 t.v_00012,
543 t.v_00022,
544 t.v_00111,
545 t.v_00112,
546 t.v_00122,
547 t.v_00222,
548 t.v_01111,
549 t.v_01112,
550 t.v_01122,
551 t.v_01222,
552 t.v_02222,
553 t.v_11111,
554 t.v_11112,
555 t.v_11122,
556 t.v_11222,
557 t.v_12222,
558 t.v_22222);
559 });
560
561 // SymTensorCollection bindings
562 // SymTensorCollection<f64, 0, 5>
563 py::class_<shammath::SymTensorCollection<f64, 0, 5>>(math_module, "SymTensorCollection_f64_0_5")
564 .def(py::init<>())
565 .def(
566 py::init<
567 f64,
573 py::arg("t0"),
574 py::arg("t1"),
575 py::arg("t2"),
576 py::arg("t3"),
577 py::arg("t4"),
578 py::arg("t5"))
586 .def_static("from_vec", &shammath::SymTensorCollection<f64, 0, 5>::from_vec, py::arg("v"))
590 .def("__repr__", [](const shammath::SymTensorCollection<f64, 0, 5> &c) {
591 return fmt::format(
592 "SymTensorCollection_f64_0_5(\n t0={},\n t1={},\n t2={},\n t3={},\n t4={},\n "
593 "t5={}\n)",
594 c.t0,
595 py::str(py::cast(c.t1)).cast<std::string>(),
596 py::str(py::cast(c.t2)).cast<std::string>(),
597 py::str(py::cast(c.t3)).cast<std::string>(),
598 py::str(py::cast(c.t4)).cast<std::string>(),
599 py::str(py::cast(c.t5)).cast<std::string>());
600 });
601
602 // SymTensorCollection<f64, 0, 4>
603 py::class_<shammath::SymTensorCollection<f64, 0, 4>>(math_module, "SymTensorCollection_f64_0_4")
604 .def(py::init<>())
605 .def(
606 py::init<
607 f64,
612 py::arg("t0"),
613 py::arg("t1"),
614 py::arg("t2"),
615 py::arg("t3"),
616 py::arg("t4"))
623 .def_static("from_vec", &shammath::SymTensorCollection<f64, 0, 4>::from_vec, py::arg("v"))
627 .def("__repr__", [](const shammath::SymTensorCollection<f64, 0, 4> &c) {
628 return fmt::format(
629 "SymTensorCollection_f64_0_4(\n t0={},\n t1={},\n t2={},\n t3={},\n t4={}\n)",
630 c.t0,
631 py::str(py::cast(c.t1)).cast<std::string>(),
632 py::str(py::cast(c.t2)).cast<std::string>(),
633 py::str(py::cast(c.t3)).cast<std::string>(),
634 py::str(py::cast(c.t4)).cast<std::string>());
635 });
636
637 // SymTensorCollection<f64, 0, 3>
638 py::class_<shammath::SymTensorCollection<f64, 0, 3>>(math_module, "SymTensorCollection_f64_0_3")
639 .def(py::init<>())
640 .def(
641 py::init<
642 f64,
646 py::arg("t0"),
647 py::arg("t1"),
648 py::arg("t2"),
649 py::arg("t3"))
655 .def_static("from_vec", &shammath::SymTensorCollection<f64, 0, 3>::from_vec, py::arg("v"))
659 .def("__repr__", [](const shammath::SymTensorCollection<f64, 0, 3> &c) {
660 return fmt::format(
661 "SymTensorCollection_f64_0_3(\n t0={},\n t1={},\n t2={},\n t3={}\n)",
662 c.t0,
663 py::str(py::cast(c.t1)).cast<std::string>(),
664 py::str(py::cast(c.t2)).cast<std::string>(),
665 py::str(py::cast(c.t3)).cast<std::string>());
666 });
667
668 // SymTensorCollection<f64, 0, 2>
669 py::class_<shammath::SymTensorCollection<f64, 0, 2>>(math_module, "SymTensorCollection_f64_0_2")
670 .def(py::init<>())
671 .def(
673 py::arg("t0"),
674 py::arg("t1"),
675 py::arg("t2"))
680 .def_static("from_vec", &shammath::SymTensorCollection<f64, 0, 2>::from_vec, py::arg("v"))
684 .def("__repr__", [](const shammath::SymTensorCollection<f64, 0, 2> &c) {
685 return fmt::format(
686 "SymTensorCollection_f64_0_2(\n t0={},\n t1={},\n t2={}\n)",
687 c.t0,
688 py::str(py::cast(c.t1)).cast<std::string>(),
689 py::str(py::cast(c.t2)).cast<std::string>());
690 });
691
692 // SymTensorCollection<f64, 0, 1>
693 py::class_<shammath::SymTensorCollection<f64, 0, 1>>(math_module, "SymTensorCollection_f64_0_1")
694 .def(py::init<>())
695 .def(py::init<f64, shammath::SymTensor3d_1<f64>>(), py::arg("t0"), py::arg("t1"))
699 .def_static("from_vec", &shammath::SymTensorCollection<f64, 0, 1>::from_vec, py::arg("v"))
703 .def("__repr__", [](const shammath::SymTensorCollection<f64, 0, 1> &c) {
704 return fmt::format(
705 "SymTensorCollection_f64_0_1(\n t0={},\n t1={}\n)",
706 c.t0,
707 py::str(py::cast(c.t1)).cast<std::string>());
708 });
709
710 // SymTensorCollection<f64, 0, 0>
711 py::class_<shammath::SymTensorCollection<f64, 0, 0>>(math_module, "SymTensorCollection_f64_0_0")
712 .def(py::init<>())
713 .def(py::init<f64>(), py::arg("t0"))
716 .def_static("from_vec", &shammath::SymTensorCollection<f64, 0, 0>::from_vec, py::arg("v"))
720 .def("__repr__", [](const shammath::SymTensorCollection<f64, 0, 0> &c) {
721 return fmt::format("SymTensorCollection_f64_0_0(t0={})", c.t0);
722 });
723
724 // SymTensorCollection<f64, 1, 5>
725 py::class_<shammath::SymTensorCollection<f64, 1, 5>>(math_module, "SymTensorCollection_f64_1_5")
726 .def(py::init<>())
727 .def(
728 py::init<
734 py::arg("t1"),
735 py::arg("t2"),
736 py::arg("t3"),
737 py::arg("t4"),
738 py::arg("t5"))
745 .def_static("from_vec", &shammath::SymTensorCollection<f64, 1, 5>::from_vec, py::arg("v"))
749 .def("__repr__", [](const shammath::SymTensorCollection<f64, 1, 5> &c) {
750 return fmt::format(
751 "SymTensorCollection_f64_1_5(\n t1={},\n t2={},\n t3={},\n t4={},\n t5={}\n)",
752 py::str(py::cast(c.t1)).cast<std::string>(),
753 py::str(py::cast(c.t2)).cast<std::string>(),
754 py::str(py::cast(c.t3)).cast<std::string>(),
755 py::str(py::cast(c.t4)).cast<std::string>(),
756 py::str(py::cast(c.t5)).cast<std::string>());
757 });
758
759 // SymTensorCollection<f64, 1, 4>
760 py::class_<shammath::SymTensorCollection<f64, 1, 4>>(math_module, "SymTensorCollection_f64_1_4")
761 .def(py::init<>())
762 .def(
763 py::init<
768 py::arg("t1"),
769 py::arg("t2"),
770 py::arg("t3"),
771 py::arg("t4"))
777 .def_static("from_vec", &shammath::SymTensorCollection<f64, 1, 4>::from_vec, py::arg("v"))
781 .def("__repr__", [](const shammath::SymTensorCollection<f64, 1, 4> &c) {
782 return fmt::format(
783 "SymTensorCollection_f64_1_4(\n t1={},\n t2={},\n t3={},\n t4={}\n)",
784 py::str(py::cast(c.t1)).cast<std::string>(),
785 py::str(py::cast(c.t2)).cast<std::string>(),
786 py::str(py::cast(c.t3)).cast<std::string>(),
787 py::str(py::cast(c.t4)).cast<std::string>());
788 });
789
790 // SymTensorCollection<f64, 1, 3>
791 py::class_<shammath::SymTensorCollection<f64, 1, 3>>(math_module, "SymTensorCollection_f64_1_3")
792 .def(py::init<>())
793 .def(
794 py::init<
798 py::arg("t1"),
799 py::arg("t2"),
800 py::arg("t3"))
805 .def_static("from_vec", &shammath::SymTensorCollection<f64, 1, 3>::from_vec, py::arg("v"))
809 .def("__repr__", [](const shammath::SymTensorCollection<f64, 1, 3> &c) {
810 return fmt::format(
811 "SymTensorCollection_f64_1_3(\n t1={},\n t2={},\n t3={}\n)",
812 py::str(py::cast(c.t1)).cast<std::string>(),
813 py::str(py::cast(c.t2)).cast<std::string>(),
814 py::str(py::cast(c.t3)).cast<std::string>());
815 });
816
817 // SymTensorCollection<f64, 1, 2>
818 py::class_<shammath::SymTensorCollection<f64, 1, 2>>(math_module, "SymTensorCollection_f64_1_2")
819 .def(py::init<>())
820 .def(
822 py::arg("t1"),
823 py::arg("t2"))
827 .def_static("from_vec", &shammath::SymTensorCollection<f64, 1, 2>::from_vec, py::arg("v"))
831 .def("__repr__", [](const shammath::SymTensorCollection<f64, 1, 2> &c) {
832 return fmt::format(
833 "SymTensorCollection_f64_1_2(\n t1={},\n t2={}\n)",
834 py::str(py::cast(c.t1)).cast<std::string>(),
835 py::str(py::cast(c.t2)).cast<std::string>());
836 });
837
838 // SymTensorCollection<f64, 1, 1>
839 py::class_<shammath::SymTensorCollection<f64, 1, 1>>(math_module, "SymTensorCollection_f64_1_1")
840 .def(py::init<>())
841 .def(py::init<shammath::SymTensor3d_1<f64>>(), py::arg("t1"))
844 .def_static("from_vec", &shammath::SymTensorCollection<f64, 1, 1>::from_vec, py::arg("v"))
848 .def("__repr__", [](const shammath::SymTensorCollection<f64, 1, 1> &c) {
849 return fmt::format(
850 "SymTensorCollection_f64_1_1(\n t1={}\n)",
851 py::str(py::cast(c.t1)).cast<std::string>());
852 });
853}
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
Matrix class based on std::array storage and mdspan.
Definition matrix.hpp:36
constexpr auto get_mdspan()
Get the matrix data as a mdspan.
Definition matrix.hpp:42
void mat_set_identity(const std::mdspan< T, Extents, Layout, Accessor > &input1)
Set the content of a matrix to the identity matrix.
Definition matrix_op.hpp:93
void mat_prod(const std::mdspan< Ta, Extents1, Layout1, Accessor1 > &input1, const std::mdspan< Ta, Extents2, Layout2, Accessor2 > &input2, const std::mdspan< Tb, Extents3, Layout3, Accessor3 > &output)
Compute the product of two matrices.
Pybind11 include and definitions.
#define Register_pymod(placeholdername)
Register a python module init function using static initialisation.
A structure for 3D paving functions with shearing along the x-axis and general boundary conditions.
A structure for 3D paving functions with general boundary conditions (periodic or reflective per dire...
A structure for 3D paving functions with periodic boundary conditions.