dolfinx_mpc
dolfinx_mpc copied to clipboard
Efficient mpc creation with same dofs, different coefficient
Motivation
Another feature request motivated by wave propagation: to compute a band structure for periodic media, we prescribe the wavevector $k$ through the Bloch boundary conditions, which are applied with a multipoint constraint, then solve the eigenvalue problem to obtain the eigenfrequencies. To produce the entire band structure, we iterate through a range of $k$ and repeatedly construct and solve the eigenvalue problem. Since the multipoint constraint is repeatedly applied to the same set of slave and master dofs, it is desirable to re-use the information about the slave and master dofs, and thus only need to update the coefficients of the mpc at each step of the iteration.
Requested improvement
Make MultiPointConstraint.create_periodic_constraint_topological
(and create_periodic_constraint_geometrical
, etc.) return the mpc_data
object that is generated by the C++ layer. Then it can be saved and the mpc_data.coeffs
array updated at each iteration, e.g.
mpc = MultiPointConstraint(V)
mpc_data = mpc.create_periodic_constraint_topological( ... )
for k in np.linspace(0, 1, N):
mpc_data.coeffs[:] = k
mpc = MultiPointConstraint(V)
mpc.add_constraint_from_mpc_data(mpc_data)
mpc.finalize()
# Solve eigenvalue problem
Note: this is already possible by directly accessing the C++ wrapper layer, i.e. with
mpc_data = dolfinx_mpc.cpp.mpc.create_periodic_constraint_topological( ... )
but the suggested improvement would result in cleaner code and eliminate the need for users to directly call the C++ layer.