Add thermodynamic potentials

Not ready to be merged. Opening for comments/suggestions.
Periodically I will try to rebase from master on this, if you think that is best, Timo