Using Command Snippets in Solution (And a cool new ACT Extension to make life easier)

So you have results for a job that took several hours to run, or several days, and now you realize that you need to use a post-processing command snippet. In the past, prior to version 14.5, this would be a huge problem, because just adding the command snippet in the Solution branch would trigger a resolve. So, in those cases, we would usually just jump over to MAPDL to do the post-processing.  In version 14.5, however, ANSYS allowed you to add the snippet to the Solution branch without triggering a resolve.

When you hit “Evaluate All Results”, Mechanical will copy the files to a scratch directory and start a separate MAPDL session. This leads to a secondary problem. Often you need to select nodes or elements to use during your snippet. This is usually done with a Named Selection, or a material ID that you saved to a parameter in a Geometry command snippet.  The problem is that the Named Selections, or components in MAPDL, are not saved in the RST file, neither are parameters. They are stored in the DB file. If you thought ahead, then in the Analysis Settings, you set the ‘Save DB file’ option to ‘Yes’ before you solved. In your post-processing command snippet you could then use the RESUME command to bring the database back to the state that it was just before the solve – having all your Named Selections and parameters. But since the default is to not save the DB file, odds are that you don’t have it.  It’s okay, though. There are still some options.

The first thing I recommend is that you save the solved project, and then do a ‘Save As’ to make a copy from which to work, just in case something goes wrong.

Method 1:

When you hit the Solve button in Mechanical, it writes out a ‘ds.dat’ file that then gets run in a batch MAPDL run.

If you have all of your needed Named Selections setup prior to the Solve, then you can open an MAPDL session and use the File>Read Input From… command to read in the ds.dat file.  In interactive mode, the file stops just before the Solve command, so you can then save the database file at that point.  You then need to right-click on the Solution branch in Mechanical and hit “Open Solution Directory”, in to which you need to copy the new “file.db” file.  Then you can resume the file.db in your post-processing command snippet. 

If you need to add a new Named  Selection, you can add a new one, even in 14.5, without triggering a resolve, but then you will have to write out a new input file. To do this, highlight the Solution branch in the tree, go to Tools>Write Input File…, and then follow the procedure above.  

Method 2:

If you are using version 17.1 or later, you have another option. You can Right-click on a Name Selection and choose “Create a Nodal Named Selection”. Then right-click that new nodal named selection and hit “Export Selections to CDB File”.  You can select several Nodal Named Selections to export, and the export will all go to one file. Include that text in your snippet.

Method 3:

In R19.2, the Named Selections are now stored in the RST file. If you don’t need to add a new Named Selection, then can you access the Named Selections that were created prior to the solution run.  After a SET command in your snippet, you can just use the name in the NSEL command, as I did in the picture above, with no need to include the CMBLOCK from the CDB file.  If you need a new Named Selection, however, then you have to use Methods 1 or 2 above.


Now that all sounds somewhat difficult, and it actually gets worse. With Method 1, you have to know at least enough MAPDL to open it and read in the input file, and then save the database file.

With Method 2 and 3, the parameters are still not saved in the RST file. So if you need parameters that were created in earlier command snippets, then you have to go back to Method 1.

But there’s hope!!

Method 4:  Oh, Joy!!!

There is one other thing that you can do, and this is my favorite method. (Probably because I wrote it. J)  There is now a new free ACT extension in the ANSYS App store. It is called SAVE_DB, and was written because yours truly got tired of dealing with the other three methods above.  SAVE_DB allows you to save the MAPDL database file without having to solve the Mechanical model, or cause a resolve. SAVE_DB will automatically change the Analysis Settings > Analysis Data Management > Save MAPDL DB value to “Yes” so that future resolves are also saved. MAPDL will be run in the background on the same version as the Workbench project, and the “file.db” will be saved to the Solver Files Directory.  Now any new Named Selections that you add will be ready at the push of a button. This one:

This is the first of many helpful tools planned for a PADT_Toolkit. I will post another plug, I mean ‘blog’, when I get more tools added and the PADT_Toolkit uploaded to the APP Store.  Until then enjoy SAVE_DB!