Dynamic modeling and reaction invariant control of pH