Skip to content

Commit c27a00c

Browse files
committed
Expose reference moment fitting systems to Python
1 parent bc527ab commit c27a00c

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

bindings/pypbat/math/MomentFitting.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,53 @@ void BindMomentFitting(pybind11::module& m)
5252
"of X1. S2 is the same for columns of X2. w2 are the quadrature weights "
5353
"associated with X2. If with_error==True, the polynomial integration error "
5454
"is computed and returned.");
55+
56+
m.def(
57+
"reference_moment_fitting_systems",
58+
[](Eigen::Ref<IndexVectorX const> const& S1,
59+
Eigen::Ref<MatrixX const> const& X1,
60+
Eigen::Ref<IndexVectorX const> const& S2,
61+
Eigen::Ref<MatrixX const> const& X2,
62+
Eigen::Ref<VectorX const> const& w2,
63+
Index order) {
64+
MatrixX M, B;
65+
IndexVectorX P;
66+
common::ForRange<1, 4>([&]<auto Order>() {
67+
if (order == Order)
68+
{
69+
std::tie(M, B, P) =
70+
pbat::math::ReferenceMomentFittingSystems<Order>(S1, X1, S2, X2, w2);
71+
}
72+
});
73+
if (M.size() == 0)
74+
throw std::invalid_argument("transfer_quadrature only accepts 1 <= order <= 4.");
75+
return std::make_tuple(M, B, P);
76+
},
77+
pyb::arg("S1"),
78+
pyb::arg("X1"),
79+
pyb::arg("S2"),
80+
pyb::arg("X2"),
81+
pyb::arg("w2"),
82+
pyb::arg("order") = 1,
83+
"Obtain a collection of reference moment fitting systems (M, B, P), where M[:, "
84+
"P[s]:P[s+1]] is the reference moment fitting matrix for simplex s, and b[:,s] is its "
85+
"corresponding right-hand side. X1, S1 are the |#dims|x|#quad.pts.| array of quadrature "
86+
"points and corresponding simplices, and X2,w2,S2 are the |#dims|x|#old quad.pts.| array "
87+
"of existing quadrature points and corresponding simplices, with weights w2. order "
88+
"specifies the polynomial order of integration that we wish to reproduce exactly.");
89+
90+
m.def(
91+
"block_diagonalize_moment_fitting",
92+
[](Eigen::Ref<MatrixX const> const& M,
93+
Eigen::Ref<MatrixX const> const& B,
94+
Eigen::Ref<IndexVectorX const> const& P) {
95+
return pbat::math::BlockDiagonalReferenceMomentFittingSystem(M, B, P);
96+
},
97+
pyb::arg("M"),
98+
pyb::arg("B"),
99+
pyb::arg("P"),
100+
"Assemble the block diagonal row sparse matrix GM, such that GM @ w = B.flatten(order='F') "
101+
"contains all the reference moment fitting systems in (M,B,P).");
55102
}
56103

57104
} // namespace math

0 commit comments

Comments
 (0)