Make use of residual_weight consistent.
Per Bill P (mildly edited into an issue):
In MESA we scale equations. Currently this does two jobs:
- It makes the equations dimensionless.
- It decreases the magnitude of the equation to reduce residuals in cases where they would be too restrictive for convergence.
The problem is that in doing (2) we can make the largest term in the partials very small with bad effects on the conditioning.
There is now a simple solution to this conflict. The equation scale can just deal with making the max magnitude partial be of order unity.
The second job of modifying the residual for convergence reasons can now be done using “residual_weight”. Here’s an example for hydro_chem_eqns
resid_scale = max(1d-16, s% x_scale(i,k)/s% dt)
eqn_scale = max(s% min_chem_eqn_scale, s% x_scale(i,k)/s% dt)
s% residual_weight(j,k) = resid_scale/eqn_scale ! multiply residual by this for testing convergence
residual = (dxdt_expected - dxdt_actual)/eqn_scale
s% equ(i,k) = residual
The residual_weight is used in solver_support/sizequ for computing the max and norm residuals to determine whether or not to accept a trial solution.
Consistent use of residual_weight would be a good step toward clarifying the weighting of residuals for accepting solutions. That is very opaque at the moment. There is a similar term, correction_weight, used in sizeB for computing max_correction and correction_norm, and that can be used as a template.