1
+ #include " MomentFitting.h"
2
+
3
+ #include < exception>
4
+ #include < pbat/common/ConstexprFor.h>
5
+ #include < pbat/math/MomentFitting.h>
6
+ #include < pybind11/eigen.h>
7
+
8
+ namespace pbat {
9
+ namespace py {
10
+ namespace math {
11
+
12
+ void BindMomentFitting (pybind11::module & m)
13
+ {
14
+ namespace pyb = pybind11;
15
+ m.def (
16
+ " transfer_quadrature" ,
17
+ [](Eigen::Ref<IndexVectorX const > const & S1,
18
+ Eigen::Ref<MatrixX const > const & X1,
19
+ Eigen::Ref<IndexVectorX const > const & S2,
20
+ Eigen::Ref<MatrixX const > const & X2,
21
+ Eigen::Ref<VectorX const > const & w2,
22
+ Index order,
23
+ bool bEvaluateError,
24
+ Index maxIterations,
25
+ Scalar precision) {
26
+ VectorX w1, err;
27
+ common::ForRange<1 , 4 >([&]<auto Order>() {
28
+ if (order == Order)
29
+ {
30
+ std::tie (w1, err) = pbat::math::TransferQuadrature<
31
+ Order>(S1, X1, S2, X2, w2, bEvaluateError, maxIterations, precision);
32
+ }
33
+ });
34
+ if (w1.size () == 0 )
35
+ throw std::invalid_argument (" transfer_quadrature only accepts 1 <= order <= 4." );
36
+ return std::make_pair (w1, err);
37
+ },
38
+ pyb::arg (" S1" ),
39
+ pyb::arg (" X1" ),
40
+ pyb::arg (" S2" ),
41
+ pyb::arg (" X2" ),
42
+ pyb::arg (" w2" ),
43
+ pyb::arg (" order" ) = 1 ,
44
+ pyb::arg (" with_error" ) = false ,
45
+ pyb::arg (" max_iters" ) = 20 ,
46
+ pyb::arg (" precision" ) = std::numeric_limits<Scalar>::epsilon (),
47
+ " Obtain weights w1 by transferring an existing quadrature rule (X2,w2) "
48
+ " defined on a domain composed of simplices onto a new quadrature rule "
49
+ " (X1,w1) defined on the same domain, given fixed quadrature points X1. "
50
+ " S1 is a |X1.shape[1]| array of simplex indices associated with the "
51
+ " corresponding quadrature point in columns (i.e. the quadrature points) "
52
+ " of X1. S2 is the same for columns of X2. w2 are the quadrature weights "
53
+ " associated with X2. If with_error==True, the polynomial integration error "
54
+ " is computed and returned." );
55
+ }
56
+
57
+ } // namespace math
58
+ } // namespace py
59
+ } // namespace pbat
0 commit comments