I think that I have understood your problem. Finally I have looked at your
files more carefully.
So you need a mininum on the Gibbs energy for reaction
3N2 + N2 = 2NH3
The problem is that TDLIB computes the mole Gibbs energy of the phase and
in this case you need the total Gibbs energy, that is
G = n*Gm
n is not constant during the reaction. The minimum should be for G, not
for Gm. In this case, Gmix does not matter.
Well, it is still possible to compute it with assess. Look at the attached
file and just run it. Then you see the minimum.
My notation is as follows. nH2 is the mole number of H2, nH2_0 is the
initial mole number, xi is the chemical variable and xH2 is the mole
fraction of H2.
I should confess that the syntax does not look too nice. I will think it
over how to simplify it - I have to remember how these objects are
working. In general the sublibrary td_algo is not that developed as phase.
If you can suggest the better design, we can discuss it.
Best wishes,
Evgenii
Yes, the total Gibbs energy was what I was looking for. Thank you for
the file. I didn't realise that TDLIB compute only the molar Gibbs
energy. The codes worked well, and till now I cannot think of
something better.
>In this case, Gmix does not matter.
Why doesnt Gmix play a role here? In my opinion, in order to get the
total Gibbs energy we also need Gmix. The equation for the total molar
Gibbs Energy is
Gm = Σxi*RT*ln(p/p0) + Σμi*xi + Σxi*RT*ln(xi)
Does TDLIB compute Gm according to this equation in the file
"minimum.mod"? I know the last summand is Gmix in TDLIB and the first
two should be Gref.
Best wishes,
Wee Nien
>I didn't realise that TDLIB compute only the molar Gibbs
>energy.
The logic here is that
G = n Gm
So, is enough to keep in the database the mode Gibbs energy only. It is
quite common practice among software for chemical thermodynamics.
>> In this case, Gmix does not matter.
>
> Why doesnt Gmix play a role here? In my opinion, in order to get the
> total Gibbs energy we also need Gmix. The equation for the total molar
> Gibbs Energy is
> Gm = Σxi*RT*ln(p/p0) + Σμi*xi + Σxi*RT*ln(xi)
>
> Does TDLIB compute Gm according to this equation in the file
> "minimum.mod"? I know the last summand is Gmix in TDLIB and the first
> two should be Gref.
I have meant only that in this case we should not look at the minimum in
Gmix.
Gmix by itself is definitely a part in Gm. This is described by Eq 2.5
to 2.8 in the manual. Also look at Eq 3.2.
You equation is correct, but in SimpleSolution the first two terms are
within the Reference object and the the last one in the IdealMixing.
Best wishes,
Evgenii
If TDLIB00 compute only the molar Gibbs energy, then shouldn't the
Objects under the category func_Tp be labeled as Gm(T,p) instead of
G(T,p)? I am refering to Table 3.2 in the manual.
Best wishes,
Wee Nien
Hallo Wee Nien,
You are completely right. It would be good to write Gm explicitly. Well,
the Gibbs energy as such should also depend on the mole number.
I have thought once more how to simplify the calculation of the total
Gibbs energy along the chemical variable. It seems that the simplest is
just to use TDLIB as a library.
If you want it to, I can prepare for you a sample code. However, it
requires some knowledge of C++. If you are interested in this, please
let me know.
Best wishes,
Evgeny
yes I am would like to have a look at the sample codes for the TDLIB
library. Please show me the sampe file. Thank you.
Best wishes,
Wee Nien
Hi Wee Nien,
Please find enclosed minimum.cpp and search_minimum.cpp. They both use
phase.mod. They need only the PHASE library (and the libraries it depends
on). The makefile is also enclosed but you have to change the variables in
the beginning.
minimum.cpp prints the Gibbs energy as a function of the chemical variable.
search_minimum.cpp uses rroot to find the minimum (actually it solves
Del_mu = 0).
You can also look at phs.cpp at lib/phase/ex and other examples in this
directory.
If you have questions, please ask.
Best wishes,
Evgenii
thank you very much for the samples. I have looked into the codes and
now I have a few questions. Does putting minimum.cpp and
search_minimum.cpp means that the amount of N2, H2 and NH3 is fixed,
i.e. nH2_0 = 3, nN2_0 = 1 and NH3_0 = 0? Is search_minimum.cpp similar
to the associated_solution object that you have posted here? And a
general question referring to the file minimum.mod, how can I
determine if tdlib00 computes the Gibbs Energy correctly?
Best wishes,
Wee Nien
> thank you very much for the samples. I have looked into the codes and
> now I have a few questions. Does putting minimum.cpp and
> search_minimum.cpp means that the amount of N2, H2 and NH3 is fixed,
> i.e. nH2_0 = 3, nN2_0 = 1 and NH3_0 = 0?
Yes, this is exactly the case.
> Is search_minimum.cpp similar
> to the associated_solution object that you have posted here?
In a way. The main difference is that the associated_solution object
uses internally a subroutine VCS from the book
Chemical Reaction Equilibrium Analysis: Theory and Algorithms"
http://www.mathtrek.com/contents/Missen.html
It is a very robust algorithm and it is possible consider many
reactions. You can look at Fig 4 and 5 in
http://evgenii.rudnyi.ru/doc/ru/papers/98tvt_kf.pdf
Well, the paper is in Russian, but when you look at these pictures at
the end of the paper, you understand my point. The computation has been
done with VCS.
The code to make this pictures is there
http://evgenii.rudnyi.ru/soft/plasma/
But now one can use associated_solution to this end.
>And a
> general question referring to the file minimum.mod, how can I
> determine if tdlib00 computes the Gibbs Energy correctly?
Well, basically to compute it by hand and then compare. I have to say
that I have debugged the library quite a lot with many examples. The
PHASE library is developed most and I would say that SimpleSolution
should be good. Yet, presumably there are still bugs.
If you suspect something wrong, please let me know.
Best wishes,
Evgenii
> Well, basically to compute it by hand and then compare. I have to say
> that I have debugged the library quite a lot with many examples. The
> PHASE library is developed most and I would say that SimpleSolution
> should be good. Yet, presumably there are still bugs.
well, I must admit that I am not really sure of how to calculate the
compositions at the equilibrium by hand. This is because I don't know
how to get the correct Equilibrium constant, K based on the Gibbs
energy from the IVT_Tp equations (heat capacity is not constant).
However I have compared the values from tdlib with the literature
reference from the Ullmann's Encyclopedia, and I noticed there is some
great deviations between the values:
internal
T xNH3 (tdlib) xNH3 (Reference)
300 0.997418 0.8872
400 0.973241 0.6999
500 0.888743 0.4646
600 0.723228 0.2722
Both values are obtained with a pressure of 700 bars and initial mole
amount of N2 : H2 = 1 : 3. Is there a problem here? I used the file
composition.mod to compute the values above. Is there a fault in the
file? Please help. Thank you.
Best wishes,
Wee Nien
> well, I must admit that I am not really sure of how to calculate the
> compositions at the equilibrium by hand. This is because I don't know
> how to get the correct Equilibrium constant, K based on the Gibbs
> energy from the IVT_Tp equations (heat capacity is not constant).
You can do it according to
Kp = exp(-Del G0/(RT))
I have inserted the code to compute the equilibrium constant from the
standard Gibbs energies. It is necessary to
1) To insert id for species in order to be able to refer to them,
2) Use a reaction object to group different output values of different
algorithms,
3) Use a convert object to program equation above.
The syntax may be a bit cryptic but I hope that you understand it. If you
have questions here, please ask.
Also what happens here is implicit promotion. There is no algorithm N2.
Then TDLIB looks for a phase N2. It is also not available. Then TDLIB
promotes species N2 to the point phase N2 and promotes this phase to the
algorithm PhaseProperties. One can use -m switch to see what happens. With
this switch access prints the internal representation - what happened
after all the processing.
It is possible to compute the equilibrium composition from the equilibrium
constant by solving one algebraic equation but for the comparison it is
simpler just to compute the equlibrium constant from the equilibrium
composition. I have inserted this as well. As you see, there is reasonable
match. Presumably one can do it better by playing with tolerances in VCS
but it is already quite good.
So, it seems that everything is correct.
> However I have compared the values from tdlib with the literature
> reference from the Ullmann's Encyclopedia, and I noticed there is some
> great deviations between the values:
>
> internal
> T xNH3 (tdlib) xNH3 (Reference)
> 300 0.997418 0.8872
> 400 0.973241 0.6999
> 500 0.888743 0.4646
> 600 0.723228 0.2722
>
> Both values are obtained with a pressure of 700 bars and initial mole
> amount of N2 : H2 = 1 : 3. Is there a problem here? I used the file
> composition.mod to compute the values above. Is there a fault in the
> file? Please help. Thank you.
As you will see from the enclosed file, the computed equilibrium
composition is in accordance with the input thermodynamics data. So, the
disagreement could be because of
1) Different thermodynamics values for the species,
2) At 700 bars this is not an ideal gas anymore.
What are values from this book? Are they experimental? Or they are also
computed under the assumption of the ideal gas law?
Best wishes,
Evgenii
> It is possible to compute the equilibrium composition from the equilibrium
> constant by solving one algebraic equation but for the comparison it is
> simpler just to compute the equlibrium constant from the equilibrium
> composition. I have inserted this as well. As you see, there is reasonable
> match. Presumably one can do it better by playing with tolerances in VCS
> but it is already quite good.
> As you will see from the enclosed file, the computed equilibrium
> composition is in accordance with the input thermodynamics data. So, the
> disagreement could be because of
in the part where tdlib computes the equilibrium constant from the the
equilibrium compositions (inside the element <OutputFile ext=Kp>), you
have entered the value 1 for pressure:
<input name=T> T </input>
<input once value=1> p </input>
But in the element <OutputFile ext=T>, the value for pressure is 700:
<input name=T> T </input>
<input once value=700> p </input>
<input once value=0.25> x(2) </input>
Shouldn't we use the same value for pressure in order to compare both
equilibrium constants? The Kp values are surprisingly similar, is this
just a coincidence or is there an explanation to this?
Regards,
Wee Nien
> in the part where tdlib computes the equilibrium constant from the the
> equilibrium compositions (inside the element <OutputFile ext=Kp>), you
> have entered the value 1 for pressure:
>
> <input name=T> T </input>
> <input once value=1> p </input>
>
> But in the element <OutputFile ext=T>, the value for pressure is 700:
>
> <input name=T> T </input>
> <input once value=700> p </input>
> <input once value=0.25> x(2) </input>
>
> Shouldn't we use the same value for pressure in order to compare both
> equilibrium constants? The Kp values are surprisingly similar, is this
> just a coincidence or is there an explanation to this?
Yes, there an explanation - it was done correctly. Let us try to write
it down.
It is possible to introduce different equilibrium constants. I have
computed Kp. So,
DelG^o_m = -RT ln Kp
where we should compute the difference of standard molar Gibbs energies
for the reaction in question. Standard means that they are computed for
the standard state, that is for 1 bar in our case. Kp by itself does not
depend on pressure for the ideal gas approximation. Hence, 1 bar was
correct to compute Kp and if one uses the Gibbs energies for another
pressure, then it will be wrong.
The second time I have computed Kp by definition, that is, as ratio of
partial pressures. Well, some people say that Kp in the equation above
is dimensionless, that is, it is written trough p/p^o, but as p^o in out
case is 1, then it is does not matter too much.
You can find some formulas about Kp at
http://evgenii.rudnyi.ru/doc/papers1/93deltaG.pdf
It could be good to discuss it before going further. Software, after
all, just make computation but we should write it down what should be
computed.
Best wishes,
Evgenii