NewStrangeWorlds / FastChem

An ultra-fast equilibrium chemistry
https://newstrangeworlds.github.io/FastChem/
GNU General Public License v3.0
41 stars 17 forks source link

Problems with condensation convergence, stuck in a loop. #7

Closed zmantas closed 6 months ago

zmantas commented 10 months ago

Hey,

I am running into converge issues for certain compositions when condensation (ce) is enabled, which makes the code loop infinitely. This often happens if the atmosphere contains a large amount of volatiles other than H. Attached monitor file below monitor_low.txt

Perhaps the code is not tuned for non H-dominated cases?

The log output looks something like this with varying elements H, O, C etc.

Too large n_min and n_maj for species H. Switching to backup. Iteration step: 2 Too large n_min and n_maj for species H. Switching to backup. Iteration step: 2 Too large n_min and n_maj for species H. Switching to backup. Iteration step: 2 Too large n_min and n_maj for species H. Switching to backup. Iteration step: 2 Too large n_min and n_maj for species H. Switching to backup. Iteration step: 0 Too large n_min and n_maj for species H. Switching to backup. Iteration step: 0 Too large n_min and n_maj for species H. Switching to backup. Iteration step: 0 Too large n_min and n_maj for species H. Switching to backup. Iteration step: 2

Thanks, Mantas

daniel-kitzmann commented 10 months ago

Could you please send me your input files so I can reproduce your error messages? Thanks!

zmantas commented 10 months ago

Attached. Let me know if anything is missing.

input_daniel.zip

Edit: Added missing TP file

daniel-kitzmann commented 10 months ago

I added an additional check for using a separate backup solver in the gas phase calculations which seem to have solved your problem. However, a few of your p-T points require a more strict convergence criterion to achieve element conservation, as well as a larger number of iteration steps. I needed to set the following FastChem parameters before doing the calculations:

fastchem.setParameter('accuracyChem', 1e-6) fastchem.setParameter('nbIterationsChemCond', 20000)

With those and the updated code everything ran fine on my end. I attached the output of my calculations in a zip-file. output.zip

Let me know if this also works for you.

zmantas commented 10 months ago

Thanks for checking this. Seems to have fixed some of the runs, although I am still running into some issues with other compositions.

Could you quickly take a look at these two runs? I cannot seem to get these to converge. fc_runs.zip

Thanks

daniel-kitzmann commented 10 months ago

I tried to analyse the problem with your scenario. Apparently, this is caused by the gas phase calculations. The condensation actually does run fine. Somehow the convergence speed of the gas phase is extremely low. However, the code does actually converge eventually. It's just that some T-p points require really a large number of iterations.

I already noticed this in the first FastChem paper, where in the p-T plane there were some isolated "islands" that required a large number of iterations. However, for practical calculations of atmospheres I never encountered this as it required some very specific p-T combinations to occur.

Currently, I can only suggest to increase the number of chemistry iterations for your scenario. You can use the adapted version from the "dev" branch, where I made some adjustments in the iterations between the gas and the condensed phase. I also attach the output of my calculations for your scenario. As you can see in the monitor file, some iterations took quite long.

Since this is not a code problem but more an issue on the algorithmic level, I will check back with Joachim who designed the numerical algorithms for the gas phase. I hope that he'll find a solution for these kinds of convergence issues.

output.zip

zmantas commented 10 months ago

I see. I updated to the dev branch. I noticed that a good number of the cases that contain a lot of C and O seem to run into infinite loops, even with the backup solver. As soon as I disable condensation, convergence rate is much higher. Thanks for taking a look at this. If you need more cases where it didn't converge, I'm happy to provide them.

daniel-kitzmann commented 7 months ago

I just pushed an experimental update to the dev branch. This update adds a multi-dimensional Newton solver to the gas-phase chemistry, which should solve convergence issues with several competing elements. Currently, the new Newton solver will be called for all elements that have not yet converged after 400 normal iteration steps. As far as I can see, this dramatically improved the convergence speed for previously challenging scenarios. Could you test the new version and see if it also works you? If it does, I will push the new update to the master branch soon, after some more additional tests.

zmantas commented 7 months ago

Amazing! I just ran about 10 compositions that previously did not converge. They all seem to have converged now. There are some cases where element conservation still fails, but as far as I can see from visually inspecting the atmospheres this seems like a minor issue. Thanks for the update!

daniel-kitzmann commented 7 months ago

Awesome, thanks for testing! With respect to the element conservation, I already noticed that if condensation is used, it is sometimes necessary to increase the accuracy of the chemistry calculations:

fastchem.setParameter('accuracyChem', 1e-5) fastchem.setParameter('accuracyCond', 1e-5)

By default, FastChem currently uses a relative accuracy for the convergence of 1e-4. The same accuracy is also used to determine element conservation. It seems that with condensation the accuracy of convergence sometimes needs to be set a bit higher than the one for element conservation.

daniel-kitzmann commented 6 months ago

All updates from the development branch have now been merged with the master branch for version 3.1 of FastChem. The updated version should hopefully take care of the recently experienced convergence issues in the gas-phase chemistry calculations. In the new version, the default accuracy and convergence criteria have been increased to 1e-5, instead of the old default value of 1e-4.