Electronics

Electronics

APDL using FMAGSUM to calculate 3D torques on a body

    • markg0311
      Subscriber

      Hi all,

      I am relatively new to APDL , and I am trying to calculate the torque on a cylindrical rod inside a uniform magnetic field. I am using the magnetic scalar potential method (MSP) with SOLID96 elements. I can solve the solution, however I would like to extract the forces acting on the body and use them to calculate the total toque about the COM of the body. First I use FMAGBC on all the rod elements. In post processing I do this to calculate the x,y, and z components of the torque Tx, Ty, and Tz.


      POST1

      FMAGSUM, ! Summarize the magnetic elemental forces

      PRETAB,FMX_X

      CMSEL,S,rod_volume ! Select the rod volume

      VSUM, ! Calculate geometry statistics of rod

      *GET,Xc,VOLU,,CENT,X ! X, Y, and Z components of centroid of rod

      *GET,Yc,VOLU,,CENT,Y

      *GET,Zc,VOLU,,CENT,Z


      CMSEL,S,rod_elements ! Select the rod elements

      *GET,nrelements,ELEM,,COUNT ! Number of elements in the rod

      selected_element = 0 ! Counter for selected element numbers

      *Do,i,1,nrelements ! Iterate number of selected elements

      elenum = ELNEXT(selected_element) ! Get the next selected element greater than current selected_node value

      forceX = FMX_X(elenum) ! Magnetic force for this element

      forceY = FMX_Y(elenum)

      forceZ = FMX_Z(elenum)

      rx = CENTRX(elenum) ! Store the realtive coordinates to the CoM

      ry = CENTRY(elenum)

      rz = CENTRZ(elenum)

      Tx = Tx + (ry*forceZ - rz*forceY)

      Ty = Ty - (rx*forceZ - rz*forceX)

      Tz = Tz + (rx*forceY - ry*forceX)

      selected_element = elenum ! Set the current node to the just selected one

      *Enddo

      FINISH


      This does not produce the desired results, there are two issues. Xc, Yc, and Zc, the centroid of the body are not retreived. Second I get an error saying FMX_X doesn't have dimensions defined. The calculation does not work. Am I using the FMAGSUM and VSUM functions correctly? My understanding is that FMAGSUM creates the tables FMX_X etc. Am a indexing the tables correctly in the loop?


      Any help would be appreciated,

      Mark

    • markg0311
      Subscriber
      I have changed my approach to the problem and now I am trying to store nodal forces using the *GET command for FMAG:
      /POST1
      SET,LAST

      CMSEL,S,rod_volume ! Select the rod volume
      *GET,Xc,VOLU,,CENT,X ! X, Y, and Z components of centroid of rod
      *GET,Yc,VOLU,,CENT,Y
      *GET,Zc,VOLU,,CENT,Z

      cmsel,,'rod_elements' $nsle,,ext $esln ! Elements with associated foces
      cmsel,u,'rod_elements' $nsle,s,1
      *GET,nrnodes,NODE,,COUNT ! Number of elements in the rod

      selected_node = 0 ! Counter for selected element numbers
      *Do,i,1,nrnodes ! Iterate number of selected elements
      nodenum = ELNEXT(selected_node) ! Get the next selected element greater than current selected_node value
      *GET,forceX,NODE,nodenum,FMAG,X ! Magnetic force for this element
      *GET,forceY,NODE,nodenum,FMAG,Y
      *GET,forceZ,NODE,nodenum,FMAG,Z
      rx = NX(nodenum) - Xc ! Store the realtive coordinates to the CoM
      ry = NY(nodenum) - Yc
      rz = NZ(nodenum) - Zc
      Tx = Tx + (ry*forceZ - rz*forceY)
      Ty = Ty - (rx*forceZ - rz*forceX)
      Tz = Tz + (rx*forceY - ry*forceX)
      FTx = FTx + forceX
      FTy = FTy + forceY
      FTz = FTz + forceZ
      selected_node = nodenum ! Set the current node to the just selected one
      *Enddo
      FINISH

      However now I get the error "The requested data is not stored for node XXX, the get command is ignored"
      Any help in this situation is very much appreciated.
    • Bill Bulat
      Ansys Employee
      Hi Mark This ~20 year old macro of mine used to work - I hope it still does. You may need to make minor editing changes (I only report torque about the global z axis). It looks like I never bothered to use FMAGSUM. It also looks like if you run the macro interactively, it expects a component name assigned to the body you want to calculate torque on.
      Best Bill

      ! MACRO FILE trq_3D.mac CALCULATES TORQUES ON
      ! OBJECTS IN 3D MAGNETIC SCALAR POTENTIAL (MSP)
      ! ANALYSES. THE VALUES ABOUT THE GLOBAL Z AXIS
      ! ARE REPORTED IN A GUI MESSAGE BOX AND A PLOT
      ! OF EITHER MXWF OR MVDI FORCES (EDIT TO SUIT)
      ! IS PRODUCED. TORQUES DUE TO BOTH MXWF AND
      ! MVDI FORCES ARE REPORTED.

      ! BILL BULAT 7/18/00

      /gopr
      cm,temp_e,elem
      cm,temp_n,node
      *get,csysorg_,active,,csys
      *get,rsysorg_,active,,rsys


      *get,intrctv_,active,,int! CHECK FOR INTERACTIVE RUN. IF YES, PROMPT USER.
      *if,intrctv_,eq,2,then
      *get,dfnd,parm,cnm_,type
      *if,dfnd,gt,-1,then
      *ask,'cnm_',the component name of the permeable domain for torque calculation,'%cnm_%'
      *else
      *ask,'cnm_',the component name of the permeable domain for torque calculation,'strpm_e'
      *endif
      *else! IF NOT INTERACTIVE, ASSIGN VALUES OF ARGS TO VARIABLES
      cnm_='arg1'! MAT ID
      *endif

      rsys,0
      csys,0

      ! SELECT ENTITIES FOR TORQUE CALCULATION (EDIT TO SUIT)
      cmse,s,cnm_
      nsel,s,ext
      esln
      cmse,u,cnm_
      nsle

      ! READ MAXWELL STRESS TENSOR FORCES
      etab,fmgx1,fmag,x
      etab,fmgy1,fmag,y
      etab,fmgz1,fmag,z

      ! READ VIRTUAL DISPLACEMENT FORCES
      etab,fmgx2,nmisc,4
      etab,fmgy2,nmisc,5
      etab,fmgz2,nmisc,6

      ! READ CENTROID COORDINATES
      etab,cntrdx,cent,x
      etab,cntrdy,cent,y
      etab,cntrdz,cent,z

      ! CALCULATE TORQUES (CROSS PRODUCTS)
      vcross,trqx1,trqy1,trqz1,cntrdx,cntrdy,cntrdz,fmgx1,fmgy1,fmgz1
      vcross,trqx2,trqy2,trqz2,cntrdx,cntrdy,cntrdz,fmgx2,fmgy2,fmgz2

      ! OBTAIN TOTAL TORQUES ABOUT GLOBAL Z AXIS
      ssum
      *get,trqtot1,ssum,,item,trqz1
      *get,trqtot2,ssum,,item,trqz2

      ! REPORT TORQUE CALCULATION SUMMARY
      *msg,ui,trqtot1,trqtot2
      TOTAL TORQUES ABOUT GLOBAL Z AXIS: %/&
      BASED ON MXWF FORCES: %G N-m %/&
      BASED ON MVDI FORCES: %G N-m


      ! PRODUCE MAGNETIC FORCE VECTOR PLOT (CHOOSE)
      !plve,fmgx1,fmgy1,fmgz1,Fmxwf,vect,,on ! DUE TO MAXWELL STRESS TENSOR
      plve,fmgx2,fmgy2,fmgz2,Fmvdi,vect,,on ! DUE TO VIRTUAL DISPLACEMENT METHOD


      ! RESTORE INITIAL SELECTED SET PRIOR TO MACRO INVOCATION
      cmse,s,temp_e
      cmse,s,temp_n

      ! CLEAN UP - DELETE TEMPORARY COMPONENTS
      cmde,s,temp_e
      cmde,temp_n

      ! RESTORE ACTIVE AND RESULTS COORDINATE SYSTEMS
      csys,csysorg_
      rsys,rsysorg_




    • markg0311
      Subscriber
      Thanks for the reply Bill, this was pretty helpful, but I'm still having the same issue. I think I am using the FMAGBC command correctly, and when I plot the results using the GUI General Postproc results>Vector Plot>Predefined and then nodal force data is plotted. This means force data is being calculated, but maybe I am not selecting the correct nodes. Could the issue be meshing related? Currently I am using tet meshing as the enclusre cannot be map meshed with hex elements (at least I am not able to). Ill put my full script below

      /BATCH

      ! Problem constants
      pi=acos(-1)
      mu0=pi*4e-7 ! Permiability of free space

      ! Enclosure Dimensions
      ezmin = -0.45
      ezmax = 0.45
      eradius = 0.15

      ! Applied uniform magnetic field, units in teslas
      Bx = 50e-6
      By = 0
      Bz = 5e-6

      ! Rod dimensions
      rzmin = -0.15
      rzmax = 0.15
      rradius = 0.015

      ! Torques on rod to be calcualted
      Tx = 0
      Ty = 0
      Tz = 0

      FTz = 0
      FTy = 0
      FTz = 0

      /GRAPHICS, FULL

      ! *****************************************************************************************************!

      /PREP7 ! Enter the preprocessor
      ET,1,SOLID98,10 ! SOLID98 element type with keyoption 10 (MAG DOF)
      MPTEMP,1,0 ! Set material property temp table
      MPDATA,MURX,1,,1 ! Relative permiability to 1 (vacuum)
      MPDATA,MURX,2,,1000 ! Relative permiability to 1000 (inside rod)

      CYLIND,eradius, ,ezmin,ezmax,0,360, ! Create cylindrical encolsure
      VSEL,ALL ! Select the enclosure volume
      CM,enclosure_volume,VOLU ! Create a component of the enclosure
      CYLIND,rradius, ,rzmin,rzmax,0,360, ! Create rod
      CMSEL,S,enclosure_volume ! Select the rod by inverting and make it a component
      VSEL,INVE
      CM,rod_volume,VOLU
      VSUM, ! Calculate geometry statistics of rod
      VSEL,ALL
      VSBV,enclosure_volume,rod_volume,,DELETE,KEEP ! Create a cavity in the enclosure where the rod is
      CMSEL,S,rod_volume ! Select the new enclosure
      VSEL,INVE
      CM,enclosure_volume,VOLU ! Redefine the enclosure to be the one with the cavity
      VSEL,ALL
      VGLUE,ALL

      CMSEL,S,enclosure_volume ! Select and mesh the enclosure
      MAT,1
      SMRT,3 ! Smart mesh with 1 sized mesh
      MSHAPE,1,3D ! Use tetrahedral shape
      MSHKEY,0 ! Free mesh
      VMESH,ALL ! Mesh all volumes
      EREF,ALL,,,1,0,1,1 ! Reine all volumes with level 1 refinement

      CMSEL,S,rod_volume ! Select and mesh the rod
      MAT,2
      SMRT,3 ! Smart mesh with 1 sized mesh
      MSHAPE,1,3D ! Use tetrahedral shape
      MSHKEY,0 ! Free mesh
      VMESH,ALL ! Mesh all volumes
      FINISH

      ! *****************************************************************************************************!

      /SOL
      CSYS,1 ! Go to cylindrical coordinates
      ASEL,S,LOC,X,eradius,,,1 ! Select the outer curved surface of the cylinder
      CM,enclosure_curved,AREA ! Group the outer surface of the cylinder to a component
      ASEL,S,LOC,Z,ezmin ! Select the endcaps of the enclosure
      ASEL,A,LOC,Z,ezmax
      CM,enclosure_ends,AREA ! Group the end surfaces of the cylinder to a component
      CMSEL,S,enclosure_curved ! Select the surfaces
      CMSEL,A,enclosure_ends
      NSLA,S,1 ! Select the associated nodes
      CSYS,0 ! Back to cartesian coordinates

      *GET,nenodes,NODE,,COUNT ! Number of nodes in the selected region
      selected_node = 0 ! Counter for selected node numbers
      *Do,i,1,nenodes ! Iterate number of selected nodes to set the boundary condition at each one
      nodenum = NDNEXT(selected_node) ! Get the next selected node greater than current selected_node value
      MSP = -(1/mu0)*(NX(nodenum)*Bx + NY(nodenum)*By + NZ(nodenum)*Bz) ! Calculate the scalar potential at this node
      D,nodenum,MAG,MSP ! Assign the vector potential to that node
      selected_node = nodenum ! Set the current node to the just selected one
      *Enddo

      CMSEL,S,rod_volume ! Select the rod volume ! Select the areas on the outside of the rod
      ESLV,S ! Select the associated elements with the rod
      CM,rod_elements,ELEM ! Create a component from the rod elements
      FMAGBC,'rod_elements' ! Create magnetic force bcs on the elements

      ALLSEL,ALL
      OUTRES,ALL,ALL
      /STATUS,SOLU
      SOLVE
      FINISH

      ! *****************************************************************************************************!

      /POST1
      SET,LAST

      CMSEL,S,rod_volume ! Select the rod volume
      *GET,Xc,VOLU,,CENT,X ! X, Y, and Z components of centroid of rod
      *GET,Yc,VOLU,,CENT,Y
      *GET,Zc,VOLU,,CENT,Z


      CMSEL,s,'rod_elements' ! Select the air elements adjacent to the rod
      NSEL,S,EXT
      ESLN,S,0,ALL
      CMSEL,U,'rod_elements'
      NSLE,S,ALL

      *GET,nrnodes,NODE,,COUNT ! Number of selected noeds
      selected_node = 0 ! Counter for selected element numbers
      *Do,i,1,nrnodes ! Iterate number of selected elements
      nodenum = ELNEXT(selected_node) ! Get the next selected element greater than current selected_node value
      *GET,forceX,NODE,nodenum,FMAG,X ! Magnetic force for this element
      *GET,forceY,NODE,nodenum,FMAG,Y
      *GET,forceZ,NODE,nodenum,FMAG,Z
      rx = NX(nodenum) - Xc ! Store the realtive coordinates to the CoM
      ry = NY(nodenum) - Yc
      rz = NZ(nodenum) - Zc
      Tx = Tx + (ry*forceZ - rz*forceY)
      Ty = Ty - (rx*forceZ - rz*forceX)
      Tz = Tz + (rx*forceY - ry*forceX)
      FTx = FTx + forceX
      FTy = FTy + forceY
      FTz = FTz + forceZ
      selected_node = nodenum ! Set the current node to the just selected one
      *Enddo
      FINISH

      ! *****************************************************************************************************!

      Thanks
      Mark
    • markg0311
      Subscriber
      Update: I got Bill's macro working. For some reason this:
      ! SELECT ENTITIES FOR TORQUE CALCULATION (EDIT TO SUIT)
      cmse,s,cnm_
      nsel,s,ext
      esln
      cmse,u,cnm_
      nsle

      was not selecting teh correct elements, I had to specify arguments to the NSLE and ESLN commands, even though they are the default arguments:
      CMSEL,s,'rod_elements'
      NSEL,S,EXT
      ESLN,S,0,ALL
      CMSEL,U,'rod_elements'
      NSLE,S,ALL

      I think they should be the same, maybe this is to do with older versions of ANSYS.
Viewing 4 reply threads
  • You must be logged in to reply to this topic.