How to receive automatic notifications when your FE simulations are done

If you are a regular Abaqus user, I am sure that eventually you will need to run models for long periods of time. It can be quite annoying to go back to the office just to check if the simulation has finished to then find out that it is still running. For that reason, I’ve coded a simple python script that sends an automatic e-mail to the user once the simulation is completed or aborts due to errors.


While you run FE models that take a huge amount of computational time to finish, it is likely that you will be working on other things, such as experimental tests, reports, meetings and so on. Obviously, we want to check our results as soon as they are ready, but in order to do so we need to be checking our computer every now and then. This can be particularly annoying when you leave a simulation running for a few days and you are doing things out of the office. Hence you need to go and check if the model is done… and then you realise it’s still there, calculating more stresses and strains and that your trip to the office was a waste of time. To overcome this problem, I decided to create a python script to send a notification directly to my e-mail every time my analyses finish. I will try to explain you the basics so you can use this code on your computer.

First of all, you need to install Python on your workstation. You shouldn’t have any problem with this, since it is quite easy to find online. Once it is installed you can check that your computer recognises it by typing the following commands:

  1. Press the “Start” button.
  2. Type: cmd
  3. Type: python

Then you should see something like this:Capture

After that, you will need to create the python script using a text editor, such as Notepad++. The code is illustrated below with colours, so it is easier for you to follow. Basically the things that you need to modify are the name of your input file and your e-mail address.

aux = 1
while (aux == 1):
         f1 = open(“NameOfYourInputFile.log”, “r”)
         last_line = f1.readlines()[-1]
         if ‘COMPLETED’ in last_line:
              import smtplib              gmail_user = ‘youremail@gmail.com’
              gmail_password = ‘yourpassword’
              sent_from = gmail_user
              to = [‘otheremail@@gmail.com’]
              subject = ‘Simulation is finished’
              body = ‘The FE model is finished\n\n- Nacho’
              email_text = “””\
              From: %s
              To: %s
              Subject: %s              %s
              “”” % (sent_from, “, “.join(to), subject, body)
              try:
                      server = smtplib.SMTP_SSL(‘smtp.gmail.com’, 465)
                      server.ehlo()
                      server.login(gmail_user, gmail_password)
                      server.sendmail(sent_from, to, email_text)
                      server.close()
                      print(‘Email sent!’)
                      aux = 0
                      f1.close()
              except:
                      print(‘Something went wrong…’)
                      aux = 0
                      f1.close()
         elif ‘errors’ in last_line:
              import smtplib
              gmail_user = ‘youremail@gmail.com’
              gmail_password = ‘yourpassword’
              sent_from = gmail_user
              to = [‘otheremail@gmail.com’]
              subject = ‘Simulation is finished’
              body = ‘The FE model aborted due to errors\n\n- Nacho’
              email_text = “””\
              From: %s
              To: %s
              Subject: %s

              %s
              “”” % (sent_from, “, “.join(to), subject, body)
              try:
                      server = smtplib.SMTP_SSL(‘smtp.gmail.com’, 465)
                      server.ehlo()
                      server.login(gmail_user, gmail_password)
                      server.sendmail(sent_from, to, email_text)
                      server.close()
                      print(‘Email sent!’)
                      aux = 0
                      f1.close()
              except:
                      print(‘Something went wrong…’)
                      aux = 0
                      f1.close()
         else:
              f1.close()

The log file is a simple text document where Abaqus writes when the simulation starts and finishes. If it finishes without any problem, the last line of the file will have the word COMPLETE in it. On the other hand, if it aborts, it will contain the word ERRORS. Therefore, the code basically reads the files over and over again until the simulation stops. Then, based on the last line of the file, it will generate an email stating if the analysis was completed successfully or not.

It is more than probable that this script is not the best written, but I did it myself in a couple hours and it does the trick. Hope you find this post useful and have a great time while waiting for your simulations to finish!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s