NewStrangeWorlds / FastChem

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

elemental condensation degree all end up to 0 #8

Closed eazzzon closed 3 months ago

eazzzon commented 3 months ago

Hi Daniel,

I am using fastchem cond to do condensation degree calculation, I found the result sometimes gives reasonable values at high T, then all elemental condensation degrees end up to 0 with a lower T input, then calculates something looks reasonable again by decreasing T. Is that something wrong with the set up of the code? I shall send you the input files so you could have a clue what happened? Thanks in advance!

Kind regards,

Eason

daniel-kitzmann commented 3 months ago

Hi Eason,

Yes, please send me the input files so I can try to replicate your issues.

Best wishes, Daniel

eazzzon commented 3 months ago

Hi Daniel,

Here are the files. By far I only do point calculation, I also attached the results I did for 1e3 K and 2e3K, I fixed the pressure for these 2 calculations. Thanks a lot.

ToDaniel.zip

Best,

Eason

daniel-kitzmann commented 3 months ago

Dear Eason,

I just merged the previous development branch with the master branch for the new version 3.1 of FastChem. This update addresses convergence issues in the gas-phase chemistry calculations. Could you please try out the new version? As far as I have seen, the scenario that you sent me ran fine with version 3.1.

Best , Daniel

eazzzon commented 3 months ago

Hi Daniel,

I just updated to 3.1 and also the pyfastchem updated to the latest too (3.1). I still got all 0 results at T = 1e3K...here are monitor log files and the screen messages if they could give you a clue where the issues could be.

PS I am using a M1 MacBook if that could be a potential issue during compiling fastchem?

Best,

Eason messages.txt logfiles.zip

daniel-kitzmann commented 3 months ago

Hi Eason,

Ah, now I see your problem. It is actually printed in the terminal output:

Phase rule violated! The number of condensing elements equals the total number of elements. FastChem reports: - phase rule violation

Basically, at these low temperatures, all the elements you use will be condensed out to some degree. There is a discussion about this in Sect. 2.3 of the FastChem Cond paper. Essentially, this means that if all the number densities of your elements in atomic form are determined by the saturation vapour pressures of the condensing species, then there is no degree of freedom left for the gas phase to yield the correct pressure that you use as an input. You need at least one element in the gas phase that does not condense and, correspondingly, will then fill up the atmosphere to yield the correct pressure once everything else condenses out.

As for the computer that you use, yes that can also be a problem, though probably not yet at these temperatures. At lower temperatures, and especially if condensation is used, the number densities of some elements can become quite low. Therefore, FastChem internally uses quad precision to resolve these small numbers. Unfortunately, the Apple Silicon CPUs do not have hardware support for quad precision but will only use the normal double precision variables. Thus, at low temperatures, you will see FastChem stop converging on such machines because they lack the computational capabilities to calculate these scenarios. There is, unfortunately, no way for me to address this issue from a coding point of view. It's essentially a limitation of the CPU and you will need to run FastChem on a computer with a proper AMD/Intel CPU that supports higher-precision calculations.

Best, Daniel

eazzzon commented 3 months ago

Thank you Daniel, the phase rule violation might be the cause. Do you have a solution to this? or we could manually assign a gas phase should be present? I have read the manual but didn't find too many information beside mentioning phase rule violation.

Best,

Eason

daniel-kitzmann commented 3 months ago

Hi Eason,

I looked into your issue in more detail. It seems that at the start of the calculation, a carbon and a nitrogen-containing condensate were initially flagged as potential condensates because they had an activity of larger than 1. However, after the condensation calculation, they came out as non-stable. Originally in the code, the phase rule was already checked before the condensation calculation started, assuming that if all elements are contained in potentially stable condensates, they would eventually also condense.

I now shifted the check of the phase rule to after the calculation of the condensates is finished. In your case, this resulted in C and N still being free elements in the gas phase and allowed the combined system to be solved. I uploaded the potential fix to the dev branch. Could you please test it?

You may, however, encounter scenarios where indeed all elements can be found in stable condensates. As pointed out earlier, this would violate the phase rule and you would need an additional, incondensible element in your system that then brings the gas phase to the input pressure.

Best, Daniel

eazzzon commented 3 months ago

Hi Daneil,

Thank you, it works perfectly now. I will let you know if the incondensable element needed case happens. Perhaps the phase rule violation can be a function/parameter turn on/off in the future updates?

Best,

Eason

daniel-kitzmann commented 3 months ago

Hi Eason,

I merged the updates to the master branch (now version 3.1.1). Enforcing the phase rule, unfortunately, is not optional. A violation of the phase rule happens when all available elements condense out to some degree. This means, that the gas-phase calculations will not yield the correct pressure anymore that has been used as an input. The only way to fix such problems is to add another element that does not condense and, therefore, can fill up the gas-phase to result in the correct pressure.

However, I now changed the phase violation behaviour in FastChem slightly. Before, FastChem would just stop the calculation once it encounters a violation of the phase rule. Now, FastChem will actually finish the calculation, including that of the gas phase, and return the densities - in addition to the exit flag that reports the phase rule violation. However, the results for the gas phase will not correspond to the correct pressure!

If you use the example that you sent me and remove C and N from the elements, then you end up with a situation where all elements condense. FastChem will, therefore, exit with the corresponding error message but will also return densities for the condensates and gas-phase species. However, when you sum up all gas-phase species and convert the resulting total number density to the pressure (using the ideal gas law) you will notice that this pressure is not equal to the input pressure, but smaller. The only way for a consistent calculation would be - as mentioned above - to add an element that does not condense.

I hope this helps Best, Daniel

eazzzon commented 2 months ago

Thank you Daniel, this is very clear!