Phase stability analysis for tight porous media by minimization of the Helmholtz free energy