Skip to main content

Defining Ansys Superelement SUB File Manually

Photo by  James Owen  on  Unsplash A surprisingly popular blog-post written here is Exporting Stiffness Matrix from Ansys . A sensible follow up question is what can one do with the exported stiffness matrix? In a recent Xansys Forum post, a question was raised on how we can edit the stiffness matrix of a superelement and use it for our model.  An approach presented below is to first create a superelement that has the same number of DOF and nodal location that will serve as a template. An APDL script can then be written to edit the stiffness matrix entries as desired before exporting to a new superelement *.SUB file for use in future models. The self-contained script below demonstrates this.  /prep7 et ,1, 185 mp , ex, 1, 200e3 mp , prxy, 1, 0.33 w = 0.1 ! single element (note nodal locations) n , 1, w, -w, -w n , 2, w, w, -w n , 3, -w, w, -w n , 4, -w, -w, -w n , 5, w, -w, w n , 6, w, w, w n , 7, -w, w, w n , 8, -w, -w, w e , 1, 2, 3, 4, 5, 6, 7, 8 /solu antype , substr     ! analy

Magnetic Forces Between Two Permanent Magnets

Magnetic Field of 2 Cylindreical Permanent Magnets

Background & Model Setup
Many years back, part of my MS degree required me to do some modeling of some permanent magnets to get magnetic stiffness and magnetic flux. The code is based on the work done then. Other related ANSYS resources I found:
  • CozyWork's 2D single magnet model. 
  • Ansys Help archive. Newer Ansys v18 has much of it undocumented. 
K&J Magnetics has a really cool website calculator that computes the magnetic force of a few simple cases. The ANSYS script below computes the magnetic force between two magnets of N52, 10 mm diameter, 5 mm thick magnets. It is assumed the magnets have relative permeability of 1.05 and Coercive Force of >11.2 kOe (>89,1267 A/m).

The model consists of the two cylindrical shaped magnets at a small distance from each other. Surrounding them is another cylinder that represents the air. Both are polarized in the positive Z direction thus the magnets will be in attraction.

Side View of Two Cylindrical Magnet and Air

Another View of the Magnets and Air Volume

APDL Script
!! Magnetic Force Between Two Magnets Script

! Sze Kwan (Jason) Cheah
! April 13, 2017
! Not verified. Use at own risk! 

emunit, mks ! mks units

!! Element Properties
et, 1, solid98, 10 
mp, murx, 1, 1 ! air relative permeability
mp, murx, 2, 1.05 ! magnet relative permeability magnet
mp, mgzz, 2, 892000     ! coercieve force neodynium
mp, murx, 3, 1.05 
mp, mgzz, 3, 892000 

!! Geometry
u = 1e-3 ! mm conversion
myoffset = 2.5*u ! magnet offset
cylind, 5*u, 0, 0, -5*u
cylind, 5*u,0,myoffset, myoffset+5*u
cylind, 9*u, 0, -12*u, 12*u+myoffset

vsbv, 3, 1,, delete,keep
vsbv, 4, 2,, delete,keep
vsel, all
vglue, all

!! Attributes

vsel, s, volu,, 3 ! Air
vatt, 1,, 1 
vsel, s, volu,, 1 ! Lower magnet
vatt, 2,, 1
vsel, s, volu,, 2 ! Upper magnet
vatt, 3,, 1

!! Mesh
esize, 1.5*u ! 1mm 
vmesh, all

!! Boundary Conditions
! calculates magnetic force at lower magnet
vsel, s, volu,, 1
cm, magnetL, elem
fmagbc, 'magnetL' ! flag lower magnet to calculate force

! outer boundary
nsel, s, ext
d, all, mag, 0

! solves & save
outres, all, all

! Calculates Data

set, last
etable, FVWZ, NMISC, 6

Results & Discussion
Simulation results came in at 9.2 N while the K&J website calculator had 9.8 N. Increasing mesh density and tweaking the coercive force values could be done to tweak the results though actual test results would be preferred.

The script could be modified to account for magnets of different shapes that isn't available on a web calculator (e.g. counter sunk, star etc). If misaligned magnets are of interest, take a look at TORQSUM which calculates torque for 2D planar analysis.