Lion sleep (or hibernate) closes all applications [Disclaimer: I'm not an avid OS X user so I don't probably use the exact terminology or language]

I had a Mac Pro with Snow Leopard at work and I usually don't turn it off when going home. The next day, I always found my applications in the exact state where I had left them.
Now, I have a new Mac Pro with Lion and every time I come back to work in the morning the system is locked down (i.e. I have to put my password), which is fine, and all applications are closed. They do however re-start and try to recover the state as I left them the day before. Alas, some applications crash (e.g. Mendeley, Quicksilver, Word), others don't succeed but let you recover the previous state (Chrome, Firefox), others simply dissappear (Emacs, scripts running).
The thing that worries me the most is that when I leave work, I usually leave some simulations running that can take more than 12h to finish. I have lost work when I come back in the morning.

Question: what is going on here and how can I disable this "sleep/hibernate/???" behaviour.

I have already tried to change System Settings - Energy Saver - Computer and Display sleep to Never.

Update
It turns out that this had nothing to do with resume. My mac is randomly shutting down sometimes and it happens almost every night. Now it has happened to me while working a couple of times and now I realize why I had a login screen every morning: it was just that the machine was turned off and back on. This is why some apps crashed (they were shut down incorrectly) and some others dissappeared (Emacs, scripts and simulation do not restart when logging back in).
I think this is the feature of logging out after inactivity that can be set in System Preferences. This is in the General tab of the Security pane with the option of "Log out after ... minutes of inactivity".

An Apple page describing this feature is available here.

Additionally, this issue is described in another Stack Exchange question that I saw recently.

I'm only on my iPad so can't check this out at the moment but seems like it might be responsible.