Energize Your Ansys Dynamic & Mechanical Analyses

Post processing modal effective mass and potential energy in Ansys Mechanical using MAPDL commands

Steve Kiefer
The Startup
6 min readJul 11, 2020

--

Image by minka2507 from Pixabay

Ansys is a commercial Finite Element Analysis (FEA) package with a robust set of structural analysis tools. One unique feature of the Ansys structural solver is the ability to script commands using simple comma-delimited Mechanical Ansys Parametric Design Language (MAPDL). Whether using the Ansys classic interface or the modern Ansys Mechanical via the Workbench tool, MAPDL can be very useful for pre-processing models and/or post-processing results. This article covers some MAPDL commands to export potential (aka strain energy) and kinetic energy from Ansys.

My use of energy results typically fall into one of the following categories:

  1. Determine which components are the most significant for deflection (quasi-static analysis) or frequency (modal analysis)
  2. Validate and/or determine dominant modes in transient analyses
  3. Load scaling by input energy

Modal (Eigenvalue) Analysis

Modal analysis is used to determine the natural frequencies of a model. It is often the first analysis performed on a dynamic structural model. It can be used to debug the model, since a solution exists even if the model is partially or fully unconstrained. In complicated systems (such as a satellite) components often have minimum or windowed frequency requirements to maintain separation from system primary modes, other nearby component modes, or operational frequencies. Frequency isn’t the only dynamic property to review when evaluating the results of a modal analysis.

Export Relative Effective Mass & Strain Energy by Component for Modal Analyses

Modal effective mass is an important property set of modal analyses. Modal effective mass can identify the important modes that are the most easily excitable and which directions they act. I include relative modal effective mass along with relative component potential energy output when post-processing modal analyses.

The MAPDL commands to extract modal effective mass are straight forward:

Here we are obtaining results for a single mode in the /post1 processor using *get instead of the more typical /post26 processor. We will need to be in the /post1 processor for some energy calculation soon so we will stick with /post1 here. Assuming i is an integer mode number we set the active result set to the mode number, *get the FREQ, EFFM (for each DOF), and total model mass. We then divide the modal effective mass by the model mass to get relative modal effective mass (think %).

Now that we have modal effective mass its time to move to potential (aka strain) energy.

Ok here we have selected all the elements, created an element table of the SENE results and are summing the absolute value of the energy using the sabs and ssum commands. once the sum is complete we can *get the sum.

Another way to get all of the potential energy in the model is to use the PRENERGY command followed by a *get.

That seemed easy! Too easy…. Well we aren’t quite done. While this works for all continuum elements it doesn’t capture potential energy related to specified stiffness on MPC184 elements. MPC184 elements are the default type for defining ‘bushing’ joint elements in Ansys Mechanical. I think they are great and use them often so we need a way of getting their energy. Here is the hack I have come up with. It only works for joints with linear stiffness.

We start by selecting all MPC184 elements, *get the total number of selected elements (COUNT), and the minimum element id in the selected set. Then we initialize the parameter ene to 0.0, then enter a loop over all of the MPC184 elements. Inside the loop we initialize the stiffness terms to 0.0 and *get the material id associated with the element and the stiffness terms for each DOF using that material id. If no stiffness is assigned to a particular DOF Ansys doesn’t assign a value to the parameter so the initialized value of 0.0 is kept. We then initialize displacement parameters to 0.0 and *get the relative joint displacement for each DOF by SMISC result number. using the stiffness and displacement we compute the energy for each DOF and add the result to the ene parameter. We then get the next element in the selected set and it repeats, increasing the ene parameter for every DOF of every MPC184 element. The total potential energy is the sum of the energy SENE_all from the continuum elements obtained with the etable sum (or PRENERGY) . Now we have the potential energy of the full model in the SENE_all parameter!

The potential energy of a full model in a model analysis is not particularly useful, but the relative potential energy of each component is. The relative potential energy tells us which components have the most potential energy and are therefore the most important for a particular mode. If a component has a lot of the total strain energy then the mode will be sensitive to its stiffness. if the strain energy is evenly spread across many components, then it will be difficult to change the mode without changing a lot of the design. Lets get the component strain energy!

The commands to get the potential energy for a component are very similar to getting them for the entire model. We just add a cmsel command to select our component and use the reselect option (esel,r,ename,,184) when selecting the MPC184 elements.

Now that we have the routine to get the total potential energy and the potential energy for each component, we can stitch it together, loop over the modes and write the results to a text file. The trick here is that we can have an arbitrary amount of components. Initializing the file and writing the header is not trivial.

Similar to the method I used for exporting mass properties I create an array of component names. nCMs is the number of components. As a bonus I am getting the data time and active units. Then I build a single string array by looping over the component names, computing the length of each name and keeping track of the position of the ‘cursor’ as we fill out the string. Once all the component names are added to the string (with delimiters) I add the ‘All_comps’ string to the end as a last column header. I then initialize output to the file using the /NOPR and /output commands while using the %<char_param>% variable replace method for the path and filename. I like to combine the relative modal effective mass for each mode with the component relative strain energy so The first part of the header uses a typical *vwrite since these don’t change. I use the \b in the FORTRAN format line to append the next write to this same line to build the full header. We then change the output back to standard and resume printing to the output file with the /output and /GOPR commands.

See this file for a complete script that includes assigning all of the relative modal effective mass and component potential energy properties to an array and writing that array to the file with an *mwrite command. The one thing that I wish I knew how to fix is to programmatically change format specifier when writing the variables. With the arbitrary component count I have to go to the end of the file and change 1 integer in the format specifier to match the nCMs variable.

Here is an example file:

We now have frequency, relative modal effective mass, and relative component potential energy for each mode in 1 file!

In a future post I’ll show how I use python (with the plot.ly, pandas, and a few other libraries) to read in this file, filter out modes with low modal effective mass, and make the interactive visualization below. The table contains the mode number, frequency, and relative modal effective mass with cells darkened based on the percentage of modal effective mass. On the right is a horizontal stacked bar chart of relative potential energy by component with a different color for each component. If the stack of bars don’t reach far to the right, then our components set is missing some important elements for that particular mode. There is a lot of information, but presented in this way I feel it is pretty easy to quickly see a lot of features of the result set and where to focus energy for changing any problematic modes.

Thanks for reading! See below for other posts discussing printing output from Ansys to text files.

--

--

Steve Kiefer
The Startup

Aerospace structural analyst and python enthusiast