Changing mass matrix in DAE with callbacks?

Is there an elegant and efficient way to modify the mass matrix of a DAE upon an event triggered by a ContinuousCallback?

The problem I’m solving is a lumped model for flow in a system. A key parameter is the direction of the mass flow rate in the system (which could reverse). I want to detect the change in direction (change of sign in the mass flow rate variable) and then the lumped system needs to be modified, not only in the RHS but also the mass matrix needs a change (some outlet temperatures become inlet temperatures and that “mixes up/changes” the lumped model). So some lumped temperatures are now bound (equality) to other temperatures in the system.

So in short, I would like to use a ContinuousCallback to trigger the direction of the flow rate and this event triggers a change in both RHS and mass matrix. Doable? Or better to go for an implicit DAE and have two RHS with a boolean in the params that is set based on the sign of the mass flow rate?

You can, and it should just work. I don’t think I’ve tested it, but if you modified integrator.f.mass_matrix then that would modify the internal solve. It would be good to put a nice interface on that though and actually thoroughly test it, but from a quick glance of the code that should work.

1 Like