I think the change I suggested will generally improve the quality of the solution, unless the code gets trapped bashing its head against a numerical wall. If everything works OK in practice, it's worth making the change.
This led me to wonder again about other cases of negative populations. I tried running the problem from the Q&A with atom_leveln generating -ve values. Printing the matrix, it looks like levels 8 and 11 in "Ca 1" are essentially decoupled from the rest of the atom when this crashes:
DEBUG CADIAG 522.92974 1108.3665 3735.6191 1197.9489 5700.5829 4737.2109 4523.364 8.3498699e-14 2.1800017e+08 86003501 6.2165053e-13 52343413 52903316 10400641 53003219
DEBUG CAPOPS 0.0017379473 1.2833655e-07 3.7452746e-07 5.8998924e-07 -8.5090887e-05 -0.00014084687 -0.00019502307 -1.1175061e-05 4.1644486e-09 1.4816506e-11 -2.4985778e-07 -9.2374405e-09 -1.2343215e-08 -8.7321066e-09 -1.5227635e-08
-- CADIAG is the diagonal of amat[][], without the conservation constraint, CAPOPS the predicted populations
Using either
species "Ca" levels=7
species "Ca" levels=all
the crash goes away; adding in bogus coupling terms to the higher levels also prevents the crash. With levels=all, at the same stage in the solution as the default case crashes,
DEBUG CADIAG 522.93494 1503.8349 4140.3657 1611.3346 7673.1449 6683.0953 6478.9437 996.96366 2.1800425e+08 86003501 1.8313503e-12 52343413 52903316 10400641 53003219 22000926 22600954 etc...
DEBUG CAPOPS 0.0013013374 9.6093542e-08 2.8043806e-07 4.4181226e-07 7.6715361e-08 1.2697692e-07 1.7575469e-07 5.7120155e-08 3.118249e-09 1.1094825e-11 1.6425583e-07 8.3281159e-12 1.1127265e-11 7.8725493e-12 1.3723136e-11 1.0765004e-12 etc...
the coupling of level 11 still looks dubiously low, but 8 looks more sensible. Most of the low-lying levels between this and the ground state have significant changes in their diagonal coefficients. The correct populations are low enough that these dodgy rates may not have a major effect on the model output, but they don't leave you feeling particularly happy either.
So yes, it would be good if the numerical methods coped with the initial setup -- which is ill-conditioned, but looks like it should have a realizable solution.
But it also looks like the truncated solvers are being asked to solve rather unphysical models. It would seem better if level 8 in the default model were coupled to *something* with a realistic sink rate (either the continuum, or an aggregate state), rather than being left to blow in the wind.
Robin