Make use of residual_weight consistent.
- Dominant language
- Fortran
- Stars
- 249
- Forks
- 82
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 3
Description
Per Bill P (mildly edited into an issue):
In MESA we scale equations. Currently this does two jobs:
1. It makes the equations dimensionless.
2. 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.
Contributor guide
Research direction
Start with hydro_chem_eqns and inspect how residual_weight is assigned, then read solver_support/sizequ to understand how it affects max and norm residuals. Use sizeB and correction_weight as the stated template, and search for other residual calculations that should follow the same convention. Done means residual weighting is applied consistently for solution acceptance without changing equation scaling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- hpc
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100